diff --git a/404.html b/404.html index 51749dde2..21551ec92 100644 --- a/404.html +++ b/404.html @@ -4,8 +4,8 @@ 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

diff --git a/assets/js/01c9695c.39e499f3.js b/assets/js/01c9695c.2aeac885.js similarity index 99% rename from assets/js/01c9695c.39e499f3.js rename to assets/js/01c9695c.2aeac885.js index 99510718c..1690c8c36 100644 --- a/assets/js/01c9695c.39e499f3.js +++ b/assets/js/01c9695c.2aeac885.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3295],{2339:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>h,frontMatter:()=>l,metadata:()=>d,toc:()=>c});var r=n(5893),a=n(1151),s=n(4866),o=n(5162);const l={title:"http-json-body-parser"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-json-body-parser.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={a:"a",code:"code",em:"em",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["This middleware automatically parses HTTP requests with a JSON body and converts the body into an\nobject. Also handles gracefully broken JSON as ",(0,r.jsx)(t.em,{children:"Unsupported Media Type"})," (415 errors)\nif used in combination with ",(0,r.jsx)(t.code,{children:"httpErrorHandler"}),"."]}),"\n",(0,r.jsx)(t.p,{children:"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."}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(o.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-json-body-parser\n"})})}),(0,r.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-json-body-parser\n"})})}),(0,r.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-json-body-parser\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"reviver"})," (",(0,r.jsx)(t.code,{children:"function"}),") (optional): A ",(0,r.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters",children:"reviver"})," parameter may be passed which will be used ",(0,r.jsx)(t.code,{children:"JSON.parse"}),"ing the body."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"disableContentTypeError"})," (",(0,r.jsx)(t.code,{children:"boolean"}),") (optional): Skip throwing 415 when ",(0,r.jsx)(t.code,{children:"Content-Type"})," is invalid. Default: ",(0,r.jsx)(t.code,{children:"true"}),", will default to ",(0,r.jsx)(t.code,{children:"false"})," in next major version."]}),"\n"]}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpJsonBodyParser from '@middy/http-json-body-parser'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .use(httpHeaderNormalizer())\n .use(httpJsonBodyParser())\n .handler(lambdaHandler)\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"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>o});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,o),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7294),a=n(6010),s=n(2466),o=n(6550),l=n(469),i=n(1980),d=n(7392),u=n(12);function c(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(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 h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),s=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)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=p(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(!h({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:s}))),[d,c]=m({queryString:n,groupId:a}),[b,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,u.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),v=(()=>{const e=d??b;return h({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{v&&i(v)}),[v]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),f(e)}),[c,f,s]),tabValues:s}}var f=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=n(5893);function j(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),u=e=>{const t=e.currentTarget,n=i.indexOf(t),a=l[n].value;a!==r&&(d(t),o(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:c,onClick:u,...s,className:(0,a.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function g(e){const t=b(e);return(0,y.jsxs)("div",{className:(0,a.Z)("tabs-container",v.tabList),children:[(0,y.jsx)(j,{...e,...t}),(0,y.jsx)(x,{...e,...t})]})}function w(e){const t=(0,f.Z)();return(0,y.jsx)(g,{...e,children:c(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>l,a:()=>o});var r=n(7294);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3295],{2339:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>h,frontMatter:()=>l,metadata:()=>d,toc:()=>c});var r=n(5893),a=n(1151),s=n(4866),o=n(5162);const l={title:"http-json-body-parser"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-json-body-parser.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={a:"a",code:"code",em:"em",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["This middleware automatically parses HTTP requests with a JSON body and converts the body into an\nobject. Also handles gracefully broken JSON as ",(0,r.jsx)(t.em,{children:"Unsupported Media Type"})," (415 errors)\nif used in combination with ",(0,r.jsx)(t.code,{children:"httpErrorHandler"}),"."]}),"\n",(0,r.jsx)(t.p,{children:"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."}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(o.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-json-body-parser\n"})})}),(0,r.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-json-body-parser\n"})})}),(0,r.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-json-body-parser\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"reviver"})," (",(0,r.jsx)(t.code,{children:"function"}),") (optional): A ",(0,r.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters",children:"reviver"})," parameter may be passed which will be used ",(0,r.jsx)(t.code,{children:"JSON.parse"}),"ing the body."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"disableContentTypeError"})," (",(0,r.jsx)(t.code,{children:"boolean"}),") (optional): Skip throwing 415 when ",(0,r.jsx)(t.code,{children:"Content-Type"})," is invalid. Default: ",(0,r.jsx)(t.code,{children:"true"}),", will default to ",(0,r.jsx)(t.code,{children:"false"})," in next major version."]}),"\n"]}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpJsonBodyParser from '@middy/http-json-body-parser'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .use(httpHeaderNormalizer())\n .use(httpJsonBodyParser())\n .handler(lambdaHandler)\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"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>o});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,o),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7294),a=n(6010),s=n(2466),o=n(6550),l=n(469),i=n(1980),d=n(7392),u=n(12);function c(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(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 h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),s=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)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=p(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(!h({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:s}))),[d,c]=m({queryString:n,groupId:a}),[b,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,u.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),v=(()=>{const e=d??b;return h({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{v&&i(v)}),[v]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),f(e)}),[c,f,s]),tabValues:s}}var f=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=n(5893);function j(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),u=e=>{const t=e.currentTarget,n=i.indexOf(t),a=l[n].value;a!==r&&(d(t),o(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:c,onClick:u,...s,className:(0,a.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function g(e){const t=b(e);return(0,y.jsxs)("div",{className:(0,a.Z)("tabs-container",v.tabList),children:[(0,y.jsx)(j,{...e,...t}),(0,y.jsx)(x,{...e,...t})]})}function w(e){const t=(0,f.Z)();return(0,y.jsx)(g,{...e,children:c(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>l,a:()=>o});var r=n(7294);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/028754be.0bb6ca4a.js b/assets/js/028754be.dcc6effc.js similarity index 97% rename from assets/js/028754be.0bb6ca4a.js rename to assets/js/028754be.dcc6effc.js index be9ae5da5..cbfffcdf9 100644 --- a/assets/js/028754be.0bb6ca4a.js +++ b/assets/js/028754be.dcc6effc.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6238],{3568:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>m,frontMatter:()=>a,metadata:()=>r,toc:()=>l});var s=n(5893),i=n(1151);const a={title:"SQS"},o=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/sqs.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"SQS"},sidebar:"tutorialSidebar",previous:{title:"SNS",permalink:"/docs/events/sns"},next:{title:"VPC Lattice",permalink:"/docs/events/vpc-lattice"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html",children:"Using AWS Lambda with Amazon SQS"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>o});var s=n(7294);const i={},a=s.createContext(i);function o(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6238],{3568:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>m,frontMatter:()=>a,metadata:()=>r,toc:()=>l});var s=n(5893),i=n(1151);const a={title:"SQS"},o=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/sqs.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"SQS"},sidebar:"tutorialSidebar",previous:{title:"SNS",permalink:"/docs/events/sns"},next:{title:"VPC Lattice",permalink:"/docs/events/vpc-lattice"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html",children:"Using AWS Lambda with Amazon SQS"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>o});var s=n(7294);const i={},a=s.createContext(i);function o(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/0480b142.6b37e640.js b/assets/js/0480b142.583b9b9f.js similarity index 96% rename from assets/js/0480b142.6b37e640.js rename to assets/js/0480b142.583b9b9f.js index f70cc38e5..af77ce89a 100644 --- a/assets/js/0480b142.6b37e640.js +++ b/assets/js/0480b142.583b9b9f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[836],{8976:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>r,contentTitle:()=>a,default:()=>u,frontMatter:()=>d,metadata:()=>s,toc:()=>c});var n=o(5893),i=o(1151);const d={title:"FAQ",sidebar_position:10},a=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/faq.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:10,frontMatter:{title:"FAQ",sidebar_position:10},sidebar:"tutorialSidebar",previous:{title:"Profiling",permalink:"/docs/best-practices/profiling"}},r={},c=[{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}];function p(t){const e={code:"code",h3:"h3",p:"p",...(0,i.a)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h3,{id:"my-lambda-keep-timing-out-without-responding-what-do-i-do",children:"My lambda keep timing out without responding, what do I do?"}),"\n",(0,n.jsxs)(e.p,{children:["Likely your event loop is not empty. This happens when you have a database connect still open for example. Checkout ",(0,n.jsx)(e.code,{children:"@middy/do-not-wait-for-empty-event-loop"}),"."]})]})}function u(t={}){const{wrapper:e}={...(0,i.a)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.jsx)(p,{...t})}):p(t)}},1151:(t,e,o)=>{o.d(e,{Z:()=>s,a:()=>a});var n=o(7294);const i={},d=n.createContext(i);function a(t){const e=n.useContext(d);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function s(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(i):t.components||i:a(t.components),n.createElement(d.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[836],{8976:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>r,contentTitle:()=>a,default:()=>u,frontMatter:()=>d,metadata:()=>s,toc:()=>c});var n=o(5893),i=o(1151);const d={title:"FAQ",sidebar_position:10},a=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/faq.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:10,frontMatter:{title:"FAQ",sidebar_position:10},sidebar:"tutorialSidebar",previous:{title:"Profiling",permalink:"/docs/best-practices/profiling"}},r={},c=[{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}];function p(t){const e={code:"code",h3:"h3",p:"p",...(0,i.a)(),...t.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h3,{id:"my-lambda-keep-timing-out-without-responding-what-do-i-do",children:"My lambda keep timing out without responding, what do I do?"}),"\n",(0,n.jsxs)(e.p,{children:["Likely your event loop is not empty. This happens when you have a database connect still open for example. Checkout ",(0,n.jsx)(e.code,{children:"@middy/do-not-wait-for-empty-event-loop"}),"."]})]})}function u(t={}){const{wrapper:e}={...(0,i.a)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.jsx)(p,{...t})}):p(t)}},1151:(t,e,o)=>{o.d(e,{Z:()=>s,a:()=>a});var n=o(7294);const i={},d=n.createContext(i);function a(t){const e=n.useContext(d);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function s(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(i):t.components||i:a(t.components),n.createElement(d.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/08eadb91.d414cd0e.js b/assets/js/08eadb91.fc66dd4f.js similarity index 98% rename from assets/js/08eadb91.d414cd0e.js rename to assets/js/08eadb91.fc66dd4f.js index 625a7f654..693cea49a 100644 --- a/assets/js/08eadb91.d414cd0e.js +++ b/assets/js/08eadb91.fc66dd4f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1428],{7702:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>o,default:()=>u,frontMatter:()=>s,metadata:()=>d,toc:()=>c});var r=t(5893),i=t(1151);const s={title:"Custom Middlewares",position:1},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/01-intro.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},a={},c=[];function l(e){const n={code:"code",em:"em",li:"li",ol:"ol",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.p,{children:"A middleware is an object that should contain at least 1 of 3 possible keys:"}),"\n",(0,r.jsxs)(n.ol,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"before"}),": a function that is executed in the before phase"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"after"}),": a function that is executed in the after phase"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"onError"}),": a function that is executed in case of errors"]}),"\n"]}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.code,{children:"before"}),", ",(0,r.jsx)(n.code,{children:"after"})," and ",(0,r.jsx)(n.code,{children:"onError"})," functions need to have the following signature:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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"})}),"\n",(0,r.jsx)(n.p,{children:"Where:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"request"}),": is a reference to the current context and allows access to (and modification of)\nthe current ",(0,r.jsx)(n.code,{children:"event"})," (request), the ",(0,r.jsx)(n.code,{children:"response"})," (in the ",(0,r.jsx)(n.em,{children:"after"})," phase), and ",(0,r.jsx)(n.code,{children:"error"}),"\n(in case of an error)."]}),"\n"]})]})}function u(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>d,a:()=>o});var r=t(7294);const i={},s=r.createContext(i);function o(e){const n=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),r.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1428],{7702:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>o,default:()=>u,frontMatter:()=>s,metadata:()=>d,toc:()=>c});var r=t(5893),i=t(1151);const s={title:"Custom Middlewares",position:1},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/01-intro.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},a={},c=[];function l(e){const n={code:"code",em:"em",li:"li",ol:"ol",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.p,{children:"A middleware is an object that should contain at least 1 of 3 possible keys:"}),"\n",(0,r.jsxs)(n.ol,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"before"}),": a function that is executed in the before phase"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"after"}),": a function that is executed in the after phase"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"onError"}),": a function that is executed in case of errors"]}),"\n"]}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.code,{children:"before"}),", ",(0,r.jsx)(n.code,{children:"after"})," and ",(0,r.jsx)(n.code,{children:"onError"})," functions need to have the following signature:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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"})}),"\n",(0,r.jsx)(n.p,{children:"Where:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"request"}),": is a reference to the current context and allows access to (and modification of)\nthe current ",(0,r.jsx)(n.code,{children:"event"})," (request), the ",(0,r.jsx)(n.code,{children:"response"})," (in the ",(0,r.jsx)(n.em,{children:"after"})," phase), and ",(0,r.jsx)(n.code,{children:"error"}),"\n(in case of an error)."]}),"\n"]})]})}function u(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>d,a:()=>o});var r=t(7294);const i={},s=r.createContext(i);function o(e){const n=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),r.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/08f83687.7ceb497d.js b/assets/js/08f83687.0bbea983.js similarity index 97% rename from assets/js/08f83687.7ceb497d.js rename to assets/js/08f83687.0bbea983.js index 197724875..fcbd29f29 100644 --- a/assets/js/08f83687.7ceb497d.js +++ b/assets/js/08f83687.0bbea983.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5409],{2423:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>l,frontMatter:()=>s,metadata:()=>d,toc:()=>r});var o=n(5893),i=n(1151);const s={title:"Code Commit"},a=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/code-commit.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},c={},r=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function m(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-codecommit.html",children:"Using AWS Lambda with AWS CodeCommit"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function l(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(m,{...e})}):m(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>d,a:()=>a});var o=n(7294);const i={},s=o.createContext(i);function a(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5409],{2423:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>l,frontMatter:()=>s,metadata:()=>d,toc:()=>r});var o=n(5893),i=n(1151);const s={title:"Code Commit"},a=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/code-commit.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},c={},r=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function m(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-codecommit.html",children:"Using AWS Lambda with AWS CodeCommit"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function l(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(m,{...e})}):m(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>d,a:()=>a});var o=n(7294);const i={},s=o.createContext(i);function a(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/0976e874.199a929a.js b/assets/js/0976e874.24b1f5cd.js similarity index 99% rename from assets/js/0976e874.199a929a.js rename to assets/js/0976e874.24b1f5cd.js index b7fe0c214..43779dfbf 100644 --- a/assets/js/0976e874.199a929a.js +++ b/assets/js/0976e874.24b1f5cd.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4267],{8369:(e,r,t)=>{t.r(r),t.d(r,{assets:()=>d,contentTitle:()=>i,default:()=>m,frontMatter:()=>s,metadata:()=>u,toc:()=>c});var n=t(5893),a=t(1151),o=t(4866),l=t(5162);const s={title:"error-logger"},i=void 0,u={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/error-logger.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"error-logger"},sidebar:"tutorialSidebar",previous:{title:"dynamodb",permalink:"/docs/middlewares/dynamodb"},next:{title:"event-normalizer",permalink:"/docs/middlewares/event-normalizer"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const r={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r.p,{children:"Logs the error and propagates it to the next middleware."}),"\n",(0,n.jsxs)(r.p,{children:["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.jsx)(r.code,{children:"console.error"})," yourself."]}),"\n",(0,n.jsx)(r.p,{children:"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."}),"\n",(0,n.jsxs)(r.p,{children:["By default, the logging operate by using the ",(0,n.jsx)(r.code,{children:"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."]}),"\n",(0,n.jsx)(r.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(r.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(o.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(l.Z,{value:"npm",children:(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",children:"npm install --save @middy/error-logger\n"})})}),(0,n.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",children:"yarn add @middy/error-logger\n"})})}),(0,n.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",children:"pnpm add @middy/error-logger\n"})})})]}),"\n",(0,n.jsx)(r.h2,{id:"options",children:"Options"}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsxs)(r.li,{children:[(0,n.jsx)(r.code,{children:"logger"})," property: a function (default ",(0,n.jsx)(r.code,{children:"(request) => console.error(request.error)"}),") that is used to define the logging logic. It receives the Error object as first and only parameter."]}),"\n"]}),"\n",(0,n.jsx)(r.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport errorLogger from '@middy/error-logger'\n\nconst lambdaHandler = (event, context) => {\n // your handler logic\n}\n\nexport const handler = middy().use(errorLogger()).handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:r}={...(0,a.a)(),...e.components};return r?(0,n.jsx)(r,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},5162:(e,r,t)=>{t.d(r,{Z:()=>l});t(7294);var n=t(6010);const a={tabItem:"tabItem_Ymn6"};var o=t(5893);function l(e){let{children:r,hidden:t,className:l}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.Z)(a.tabItem,l),hidden:t,children:r})}},4866:(e,r,t)=>{t.d(r,{Z:()=>j});var n=t(7294),a=t(6010),o=t(2466),l=t(6550),s=t(469),i=t(1980),u=t(7392),d=t(12);function c(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:r}=e;return!!r&&"object"==typeof r&&"value"in r}(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)??[]}function h(e){const{values:r,children:t}=e;return(0,n.useMemo)((()=>{const e=r??function(e){return c(e).map((e=>{let{props:{value:r,label:t,attributes:n,default:a}}=e;return{value:r,label:t,attributes:n,default:a}}))}(t);return function(e){const r=(0,u.l)(e,((e,r)=>e.value===r.value));if(r.length>0)throw new Error(`Docusaurus error: Duplicate values "${r.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[r,t])}function m(e){let{value:r,tabValues:t}=e;return t.some((e=>e.value===r))}function p(e){let{queryString:r=!1,groupId:t}=e;const a=(0,l.k6)(),o=function(e){let{queryString:r=!1,groupId:t}=e;if("string"==typeof r)return r;if(!1===r)return null;if(!0===r&&!t)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 t??null}({queryString:r,groupId:t});return[(0,i._X)(o),(0,n.useCallback)((e=>{if(!o)return;const r=new URLSearchParams(a.location.search);r.set(o,e),a.replace({...a.location,search:r.toString()})}),[o,a])]}function g(e){const{defaultValue:r,queryString:t=!1,groupId:a}=e,o=h(e),[l,i]=(0,n.useState)((()=>function(e){let{defaultValue:r,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(r){if(!m({value:r,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${r}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return r}const n=t.find((e=>e.default))??t[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:r,tabValues:o}))),[u,c]=p({queryString:t,groupId:a}),[g,f]=function(e){let{groupId:r}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(r),[a,o]=(0,d.Nk)(t);return[a,(0,n.useCallback)((e=>{t&&o.set(e)}),[t,o])]}({groupId:a}),b=(()=>{const e=u??g;return m({value:e,tabValues:o})?e:null})();(0,s.Z)((()=>{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),c(e),f(e)}),[c,f,o]),tabValues:o}}var f=t(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=t(5893);function y(e){let{className:r,block:t,selectedValue:n,selectValue:l,tabValues:s}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,o.o5)(),d=e=>{const r=e.currentTarget,t=i.indexOf(r),a=s[t].value;a!==n&&(u(r),l(a))},c=e=>{let r=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const t=i.indexOf(e.currentTarget)+1;r=i[t]??i[0];break}case"ArrowLeft":{const t=i.indexOf(e.currentTarget)-1;r=i[t]??i[i.length-1];break}}r?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":t},r),children:s.map((e=>{let{value:r,label:t,attributes:o}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:n===r?0:-1,"aria-selected":n===r,ref:e=>i.push(e),onKeyDown:c,onClick:d,...o,className:(0,a.Z)("tabs__item",b.tabItem,o?.className,{"tabs__item--active":n===r}),children:t??r},r)}))})}function x(e){let{lazy:r,children:t,selectedValue:a}=e;const o=(Array.isArray(t)?t:[t]).filter(Boolean);if(r){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:o.map(((e,r)=>(0,n.cloneElement)(e,{key:r,hidden:e.props.value!==a})))})}function w(e){const r=g(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",b.tabList),children:[(0,v.jsx)(y,{...e,...r}),(0,v.jsx)(x,{...e,...r})]})}function j(e){const r=(0,f.Z)();return(0,v.jsx)(w,{...e,children:c(e.children)},String(r))}},1151:(e,r,t)=>{t.d(r,{Z:()=>s,a:()=>l});var n=t(7294);const a={},o=n.createContext(a);function l(e){const r=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function s(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),n.createElement(o.Provider,{value:r},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4267],{8369:(e,r,t)=>{t.r(r),t.d(r,{assets:()=>d,contentTitle:()=>i,default:()=>m,frontMatter:()=>s,metadata:()=>u,toc:()=>c});var n=t(5893),a=t(1151),o=t(4866),l=t(5162);const s={title:"error-logger"},i=void 0,u={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/error-logger.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"error-logger"},sidebar:"tutorialSidebar",previous:{title:"dynamodb",permalink:"/docs/middlewares/dynamodb"},next:{title:"event-normalizer",permalink:"/docs/middlewares/event-normalizer"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const r={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r.p,{children:"Logs the error and propagates it to the next middleware."}),"\n",(0,n.jsxs)(r.p,{children:["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.jsx)(r.code,{children:"console.error"})," yourself."]}),"\n",(0,n.jsx)(r.p,{children:"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."}),"\n",(0,n.jsxs)(r.p,{children:["By default, the logging operate by using the ",(0,n.jsx)(r.code,{children:"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."]}),"\n",(0,n.jsx)(r.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(r.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(o.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(l.Z,{value:"npm",children:(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",children:"npm install --save @middy/error-logger\n"})})}),(0,n.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",children:"yarn add @middy/error-logger\n"})})}),(0,n.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",children:"pnpm add @middy/error-logger\n"})})})]}),"\n",(0,n.jsx)(r.h2,{id:"options",children:"Options"}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsxs)(r.li,{children:[(0,n.jsx)(r.code,{children:"logger"})," property: a function (default ",(0,n.jsx)(r.code,{children:"(request) => console.error(request.error)"}),") that is used to define the logging logic. It receives the Error object as first and only parameter."]}),"\n"]}),"\n",(0,n.jsx)(r.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport errorLogger from '@middy/error-logger'\n\nconst lambdaHandler = (event, context) => {\n // your handler logic\n}\n\nexport const handler = middy().use(errorLogger()).handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:r}={...(0,a.a)(),...e.components};return r?(0,n.jsx)(r,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},5162:(e,r,t)=>{t.d(r,{Z:()=>l});t(7294);var n=t(6010);const a={tabItem:"tabItem_Ymn6"};var o=t(5893);function l(e){let{children:r,hidden:t,className:l}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,n.Z)(a.tabItem,l),hidden:t,children:r})}},4866:(e,r,t)=>{t.d(r,{Z:()=>j});var n=t(7294),a=t(6010),o=t(2466),l=t(6550),s=t(469),i=t(1980),u=t(7392),d=t(12);function c(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:r}=e;return!!r&&"object"==typeof r&&"value"in r}(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)??[]}function h(e){const{values:r,children:t}=e;return(0,n.useMemo)((()=>{const e=r??function(e){return c(e).map((e=>{let{props:{value:r,label:t,attributes:n,default:a}}=e;return{value:r,label:t,attributes:n,default:a}}))}(t);return function(e){const r=(0,u.l)(e,((e,r)=>e.value===r.value));if(r.length>0)throw new Error(`Docusaurus error: Duplicate values "${r.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[r,t])}function m(e){let{value:r,tabValues:t}=e;return t.some((e=>e.value===r))}function p(e){let{queryString:r=!1,groupId:t}=e;const a=(0,l.k6)(),o=function(e){let{queryString:r=!1,groupId:t}=e;if("string"==typeof r)return r;if(!1===r)return null;if(!0===r&&!t)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 t??null}({queryString:r,groupId:t});return[(0,i._X)(o),(0,n.useCallback)((e=>{if(!o)return;const r=new URLSearchParams(a.location.search);r.set(o,e),a.replace({...a.location,search:r.toString()})}),[o,a])]}function g(e){const{defaultValue:r,queryString:t=!1,groupId:a}=e,o=h(e),[l,i]=(0,n.useState)((()=>function(e){let{defaultValue:r,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(r){if(!m({value:r,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${r}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return r}const n=t.find((e=>e.default))??t[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:r,tabValues:o}))),[u,c]=p({queryString:t,groupId:a}),[g,f]=function(e){let{groupId:r}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(r),[a,o]=(0,d.Nk)(t);return[a,(0,n.useCallback)((e=>{t&&o.set(e)}),[t,o])]}({groupId:a}),b=(()=>{const e=u??g;return m({value:e,tabValues:o})?e:null})();(0,s.Z)((()=>{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),c(e),f(e)}),[c,f,o]),tabValues:o}}var f=t(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=t(5893);function y(e){let{className:r,block:t,selectedValue:n,selectValue:l,tabValues:s}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,o.o5)(),d=e=>{const r=e.currentTarget,t=i.indexOf(r),a=s[t].value;a!==n&&(u(r),l(a))},c=e=>{let r=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const t=i.indexOf(e.currentTarget)+1;r=i[t]??i[0];break}case"ArrowLeft":{const t=i.indexOf(e.currentTarget)-1;r=i[t]??i[i.length-1];break}}r?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":t},r),children:s.map((e=>{let{value:r,label:t,attributes:o}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:n===r?0:-1,"aria-selected":n===r,ref:e=>i.push(e),onKeyDown:c,onClick:d,...o,className:(0,a.Z)("tabs__item",b.tabItem,o?.className,{"tabs__item--active":n===r}),children:t??r},r)}))})}function x(e){let{lazy:r,children:t,selectedValue:a}=e;const o=(Array.isArray(t)?t:[t]).filter(Boolean);if(r){const e=o.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:o.map(((e,r)=>(0,n.cloneElement)(e,{key:r,hidden:e.props.value!==a})))})}function w(e){const r=g(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",b.tabList),children:[(0,v.jsx)(y,{...e,...r}),(0,v.jsx)(x,{...e,...r})]})}function j(e){const r=(0,f.Z)();return(0,v.jsx)(w,{...e,children:c(e.children)},String(r))}},1151:(e,r,t)=>{t.d(r,{Z:()=>s,a:()=>l});var n=t(7294);const a={},o=n.createContext(a);function l(e){const r=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function s(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),n.createElement(o.Provider,{value:r},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/0ce61a91.6c5ba8ab.js b/assets/js/0ce61a91.bab89d05.js similarity index 99% rename from assets/js/0ce61a91.6c5ba8ab.js rename to assets/js/0ce61a91.bab89d05.js index 58ffe8fb2..86a96eef8 100644 --- a/assets/js/0ce61a91.6c5ba8ab.js +++ b/assets/js/0ce61a91.bab89d05.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6540],{8593:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>d,default:()=>p,frontMatter:()=>t,metadata:()=>o,toc:()=>a});var i=s(5893),l=s(1151);const t={title:"Bundling Lambda packages",sidebar_position:5},d=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/05-bundling.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},r={},a=[{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}];function c(e){const n={admonition:"admonition",code:"code",h2:"h2",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,l.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.admonition,{type:"caution",children:(0,i.jsx)(n.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsxs)(n.p,{children:["Always bundle the ",(0,i.jsx)(n.code,{children:"@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."]}),"\n",(0,i.jsx)(n.h2,{id:"compilers",children:"Compilers"}),"\n",(0,i.jsx)(n.h3,{id:"typescript",children:"typescript"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D typescript\nnode_modules/.bin/tsc\n"})}),"\n",(0,i.jsx)(n.h4,{id:"tsconfigjson",children:"tsconfig.json"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\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'})}),"\n",(0,i.jsx)(n.h2,{id:"bundlers",children:"Bundlers"}),"\n",(0,i.jsx)(n.h3,{id:"esbuild",children:"esbuild"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"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"})}),"\n",(0,i.jsx)(n.h3,{id:"rollup",children:"rollup"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D rollup @rollup/plugin-node-resolve @rollup/plugin-commonjs\nnode_modules/.bin/rollup --config\n"})}),"\n",(0,i.jsx)(n.h4,{id:"rollupconfigmjs",children:"rollup.config.mjs"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-javascript",children:"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"})}),"\n",(0,i.jsx)(n.h3,{id:"swcpack",children:"swc/pack"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D @swc/cli @swc/core\nnode_modules/.bin/spack\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"caution",children:(0,i.jsx)(n.p,{children:"Incomplete"})}),"\n",(0,i.jsx)(n.h3,{id:"webpack",children:"webpack"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D webpack-cli webpack\nnode_modules/.bin/webpack\n"})}),"\n",(0,i.jsx)(n.h4,{id:"webpackconfigmjs",children:"webpack.config.mjs"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-javascript",children:"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"})}),"\n",(0,i.jsx)(n.h2,{id:"transpilers",children:"Transpilers"}),"\n",(0,i.jsx)(n.h3,{id:"babel",children:"babel"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D @babel/cli @babel/core @babel/preset-env\nnode_modules/.bin/babel index.js --out-file index.transpile.babel.cjs\n"})}),"\n",(0,i.jsx)(n.h4,{id:"babelconfigjson",children:"babel.config.json"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\n "presets": [\n [\n "@babel/preset-env",\n {\n "targets": {\n "node": "16"\n }\n }\n ]\n ]\n}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"esbuild-1",children:"esbuild"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D esbuild\nnode_modules/.bin/esbuild --platform=node --target=node16 --format=cjs index.js --outfile=index.cjs\n"})}),"\n",(0,i.jsx)(n.h3,{id:"swc",children:"swc"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D @swc/cli @swc/core\nnode_modules/.bin/swc index.js --out-file index.transpile.swc.cjs\n"})}),"\n",(0,i.jsx)(n.h4,{id:"swcrc",children:".swcrc"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\n "jsc": {\n "parser": {\n "syntax": "ecmascript"\n },\n "target": "es2021"\n },\n "module": {\n "type": "commonjs"\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,l.a)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,n,s)=>{s.d(n,{Z:()=>o,a:()=>d});var i=s(7294);const l={},t=i.createContext(l);function d(e){const n=i.useContext(t);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(l):e.components||l:d(e.components),i.createElement(t.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6540],{8593:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>d,default:()=>p,frontMatter:()=>t,metadata:()=>o,toc:()=>a});var i=s(5893),l=s(1151);const t={title:"Bundling Lambda packages",sidebar_position:5},d=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/05-bundling.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},r={},a=[{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}];function c(e){const n={admonition:"admonition",code:"code",h2:"h2",h3:"h3",h4:"h4",p:"p",pre:"pre",...(0,l.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.admonition,{type:"caution",children:(0,i.jsx)(n.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsxs)(n.p,{children:["Always bundle the ",(0,i.jsx)(n.code,{children:"@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."]}),"\n",(0,i.jsx)(n.h2,{id:"compilers",children:"Compilers"}),"\n",(0,i.jsx)(n.h3,{id:"typescript",children:"typescript"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D typescript\nnode_modules/.bin/tsc\n"})}),"\n",(0,i.jsx)(n.h4,{id:"tsconfigjson",children:"tsconfig.json"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\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'})}),"\n",(0,i.jsx)(n.h2,{id:"bundlers",children:"Bundlers"}),"\n",(0,i.jsx)(n.h3,{id:"esbuild",children:"esbuild"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"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"})}),"\n",(0,i.jsx)(n.h3,{id:"rollup",children:"rollup"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D rollup @rollup/plugin-node-resolve @rollup/plugin-commonjs\nnode_modules/.bin/rollup --config\n"})}),"\n",(0,i.jsx)(n.h4,{id:"rollupconfigmjs",children:"rollup.config.mjs"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-javascript",children:"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"})}),"\n",(0,i.jsx)(n.h3,{id:"swcpack",children:"swc/pack"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D @swc/cli @swc/core\nnode_modules/.bin/spack\n"})}),"\n",(0,i.jsx)(n.admonition,{type:"caution",children:(0,i.jsx)(n.p,{children:"Incomplete"})}),"\n",(0,i.jsx)(n.h3,{id:"webpack",children:"webpack"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D webpack-cli webpack\nnode_modules/.bin/webpack\n"})}),"\n",(0,i.jsx)(n.h4,{id:"webpackconfigmjs",children:"webpack.config.mjs"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-javascript",children:"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"})}),"\n",(0,i.jsx)(n.h2,{id:"transpilers",children:"Transpilers"}),"\n",(0,i.jsx)(n.h3,{id:"babel",children:"babel"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D @babel/cli @babel/core @babel/preset-env\nnode_modules/.bin/babel index.js --out-file index.transpile.babel.cjs\n"})}),"\n",(0,i.jsx)(n.h4,{id:"babelconfigjson",children:"babel.config.json"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\n "presets": [\n [\n "@babel/preset-env",\n {\n "targets": {\n "node": "16"\n }\n }\n ]\n ]\n}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"esbuild-1",children:"esbuild"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D esbuild\nnode_modules/.bin/esbuild --platform=node --target=node16 --format=cjs index.js --outfile=index.cjs\n"})}),"\n",(0,i.jsx)(n.h3,{id:"swc",children:"swc"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"npm i -D @swc/cli @swc/core\nnode_modules/.bin/swc index.js --out-file index.transpile.swc.cjs\n"})}),"\n",(0,i.jsx)(n.h4,{id:"swcrc",children:".swcrc"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'{\n "jsc": {\n "parser": {\n "syntax": "ecmascript"\n },\n "target": "es2021"\n },\n "module": {\n "type": "commonjs"\n }\n}\n'})})]})}function p(e={}){const{wrapper:n}={...(0,l.a)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,n,s)=>{s.d(n,{Z:()=>o,a:()=>d});var i=s(7294);const l={},t=i.createContext(l);function d(e){const n=i.useContext(t);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(l):e.components||l:d(e.components),i.createElement(t.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/0d245e6a.c757d31e.js b/assets/js/0d245e6a.4f6acbbc.js similarity index 97% rename from assets/js/0d245e6a.c757d31e.js rename to assets/js/0d245e6a.4f6acbbc.js index 4d2301141..393d236c3 100644 --- a/assets/js/0d245e6a.c757d31e.js +++ b/assets/js/0d245e6a.4f6acbbc.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8481],{9081:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>r,toc:()=>l});var i=t(5893),s=t(1151);const o={title:"Kinesis Firehose"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kinesis-firehose.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.admonition,{type:"caution",children:(0,i.jsx)(n.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(n.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-kinesisfirehose.html",children:"Using AWS Lambda with Amazon Kinesis Data Firehose"})}),"\n"]}),"\n",(0,i.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:n}={...(0,s.a)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>r,a:()=>a});var i=t(7294);const s={},o=i.createContext(s);function a(e){const n=i.useContext(o);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),i.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8481],{9081:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>r,toc:()=>l});var i=t(5893),s=t(1151);const o={title:"Kinesis Firehose"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kinesis-firehose.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.admonition,{type:"caution",children:(0,i.jsx)(n.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(n.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-kinesisfirehose.html",children:"Using AWS Lambda with Amazon Kinesis Data Firehose"})}),"\n"]}),"\n",(0,i.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:n}={...(0,s.a)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>r,a:()=>a});var i=t(7294);const s={},o=i.createContext(s);function a(e){const n=i.useContext(o);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),i.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/0e90e864.08a6bb8d.js b/assets/js/0e90e864.dbb8bae7.js similarity index 99% rename from assets/js/0e90e864.08a6bb8d.js rename to assets/js/0e90e864.dbb8bae7.js index 74ab5f07b..9d051aba3 100644 --- a/assets/js/0e90e864.08a6bb8d.js +++ b/assets/js/0e90e864.dbb8bae7.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1469],{3048:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>o,toc:()=>u});var s=n(5893),r=n(1151),a=n(4866),c=n(5162);const l={title:"secrets-manager"},i=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/secrets-manager.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"secrets-manager"},sidebar:"tutorialSidebar",previous:{title:"s3",permalink:"/docs/middlewares/s3"},next:{title:"service-discovery",permalink:"/docs/middlewares/service-discovery"}},d={},u=[{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},{value:"Usage with TypeScript",id:"usage-with-typescript",level:2}];function h(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["This middleware fetches secrets from ",(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html",children:"AWS Secrets Manager"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["Secrets to fetch can be defined by by name. See AWS docs ",(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/tutorials_basic.html",children:"here"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["Secrets are assigned to the function handler's ",(0,s.jsx)(t.code,{children:"context"})," object."]}),"\n",(0,s.jsxs)(t.p,{children:["The Middleware makes a single ",(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html",children:"API request"})," for each secret as Secrets Manager does not support batch get."]}),"\n",(0,s.jsxs)(t.p,{children:["For each secret, you also provide the name under which its value should be added to ",(0,s.jsx)(t.code,{children:"context"}),"."]}),"\n",(0,s.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(c.Z,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/secrets-manager\nnpm install --save-dev @aws-sdk/client-secrets-manager\n"})})}),(0,s.jsx)(c.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/secrets-manager\nyarn add --dev @aws-sdk/client-secrets-manager\n"})})}),(0,s.jsx)(c.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/secrets-manager\npnpm add --save-dev @aws-sdk/client-secrets-manager\n"})})})]}),"\n",(0,s.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(t.code,{children:"SecretsManagerClient"}),"): SecretsManagerClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(t.code,{children:"@aws-sdk/client-secrets-manager"}),"."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"awsClientOptions"})," (object) (optional): Options to pass to SecretsManagerClient class constructor."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"awsClientAssumeRole"})," (string) (optional): Internal key where secrets are stored. See ",(0,s.jsx)(t.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"awsClientCapture"})," (function) (optional): Enable XRay by passing ",(0,s.jsx)(t.code,{children:"captureAWSv3Client"})," from ",(0,s.jsx)(t.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameter ",(0,s.jsx)(t.code,{children:"SecretId"}),"."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"fetchRotationDate"})," (boolean|object) (default ",(0,s.jsx)(t.code,{children:"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,s.jsx)(t.code,{children:"NextRotationDate"}),"/",(0,s.jsx)(t.code,{children:"LastRotationDate"}),"/",(0,s.jsx)(t.code,{children:"LastChangedDate"}),". ",(0,s.jsx)(t.code,{children:"cacheExpiry"})," of ",(0,s.jsx)(t.code,{children:"-1"})," will use ",(0,s.jsx)(t.code,{children:"NextRotationDate"}),", while any other value will be added to the ",(0,s.jsx)(t.code,{children:"LastRotationDate"})," or ",(0,s.jsx)(t.code,{children:"LastChangedDate"}),", whichever is more recent. If secrets have different rotation schedules, use multiple instances of this middleware."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(t.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(t.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"cacheKey"})," (string) (default ",(0,s.jsx)(t.code,{children:"secrets-manager"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"cacheExpiry"})," (number) (default ",(0,s.jsx)(t.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,s.jsx)(t.code,{children:"-1"}),": cache forever, ",(0,s.jsx)(t.code,{children:"0"}),": never cache, ",(0,s.jsx)(t.code,{children:"n"}),": cache for n ms."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"setToContext"})," (boolean) (default ",(0,s.jsx)(t.code,{children:"false"}),"): Store secrets to ",(0,s.jsx)(t.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(t.code,{children:"secretsmanager:GetSecretValue"}),". If using ",(0,s.jsx)(t.code,{children:"fetchRotationDate"})," add ",(0,s.jsx)(t.code,{children:"secretsmanager:DescribeSecret"})," in as well."]}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport secretsManager from '@middy/secrets-manager'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .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 .handler(lambdaHandler)\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"})}),"\n",(0,s.jsx)(t.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(t.p,{children:["To exclude ",(0,s.jsx)(t.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(t.code,{children:"@aws-sdk/client-secrets-manager"})," to the exclude list."]}),"\n",(0,s.jsx)(t.h2,{id:"usage-with-typescript",children:"Usage with TypeScript"}),"\n",(0,s.jsxs)(t.p,{children:["Data stored in SecretsManager can be stored as arbitrary structured data. It's not possible to know in advance what shape the fetched data will have, so by default the fetched secrets will have type ",(0,s.jsx)(t.code,{children:"unknown"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["You can provide some type hints by leveraging the ",(0,s.jsx)(t.code,{children:"secret"})," utility function. This function allows you to specify what's the expected type that will be fetched for every SecretsManager request."]}),"\n",(0,s.jsxs)(t.p,{children:["The idea is that, for every request specified in the ",(0,s.jsx)(t.code,{children:"fetchData"})," option, rather than just providing the parameter configuration as an object, you can wrap it in a ",(0,s.jsx)(t.code,{children:"secret(key)"})," call. Internally, ",(0,s.jsx)(t.code,{children:"secret"})," is a function that will return ",(0,s.jsx)(t.code,{children:"key"})," as received, but it allows you to use generics to provide type hints for the expected fetched value type for that request."]}),"\n",(0,s.jsx)(t.p,{children:"This way TypeScript can understand how to treat the additional data attached to the context and stored in the internal storage."}),"\n",(0,s.jsxs)(t.p,{children:["The following example illustrates how to use ",(0,s.jsx)(t.code,{children:"secret"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",children:"import middy from '@middy/core'\nimport secretsManager, { secret } from '@middy/secrets-manager'\n\nconst lambdaHandler = (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\nexport const handler = middy()\n.use(\n secretsManager({\n fetchData: {\n someSecret: secret<{User: string, Password: string}>('someHiddenSecret')\n }),\n setToContext: true\n })\n)\n.before(async (request) => {\n const data = await getInternal('someSecret', request)\n // data.someSecret.User (string)\n // data.someSecret.Password (string)\n // or, since we have `setToContext: true`\n // request.context.someSecret.User (string)\n // request.context.someSecret.Password (string)\n})\n.handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>c});n(7294);var s=n(6010);const r={tabItem:"tabItem_Ymn6"};var a=n(5893);function c(e){let{children:t,hidden:n,className:c}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.Z)(r.tabItem,c),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>y});var s=n(7294),r=n(6010),a=n(2466),c=n(6550),l=n(469),i=n(1980),o=n(7392),d=n(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.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)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,o.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 p(e){let{queryString:t=!1,groupId:n}=e;const r=(0,c.k6)(),a=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)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=h(e),[c,i]=(0,s.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 s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[o,u]=p({queryString:n,groupId:r}),[f,x]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,d.Nk)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),g=(()=>{const e=o??f;return m({value:e,tabValues:a})?e:null})();(0,l.Z)((()=>{g&&i(g)}),[g]);return{selectedValue:c,selectValue:(0,s.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),x(e)}),[u,x,a]),tabValues:a}}var x=n(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(5893);function b(e){let{className:t,block:n,selectedValue:s,selectValue:c,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:o}=(0,a.o5)(),d=e=>{const t=e.currentTarget,n=i.indexOf(t),r=l[n].value;r!==s&&(o(t),c(r))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>i.push(e),onKeyDown:u,onClick:d,...a,className:(0,r.Z)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===r));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function w(e){const t=f(e);return(0,j.jsxs)("div",{className:(0,r.Z)("tabs-container",g.tabList),children:[(0,j.jsx)(b,{...e,...t}),(0,j.jsx)(v,{...e,...t})]})}function y(e){const t=(0,x.Z)();return(0,j.jsx)(w,{...e,children:u(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>l,a:()=>c});var s=n(7294);const r={},a=s.createContext(r);function c(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:c(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1469],{3048:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>o,toc:()=>u});var s=n(5893),r=n(1151),a=n(4866),c=n(5162);const l={title:"secrets-manager"},i=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/secrets-manager.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"secrets-manager"},sidebar:"tutorialSidebar",previous:{title:"s3",permalink:"/docs/middlewares/s3"},next:{title:"service-discovery",permalink:"/docs/middlewares/service-discovery"}},d={},u=[{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},{value:"Usage with TypeScript",id:"usage-with-typescript",level:2}];function h(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["This middleware fetches secrets from ",(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html",children:"AWS Secrets Manager"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["Secrets to fetch can be defined by by name. See AWS docs ",(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/tutorials_basic.html",children:"here"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["Secrets are assigned to the function handler's ",(0,s.jsx)(t.code,{children:"context"})," object."]}),"\n",(0,s.jsxs)(t.p,{children:["The Middleware makes a single ",(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html",children:"API request"})," for each secret as Secrets Manager does not support batch get."]}),"\n",(0,s.jsxs)(t.p,{children:["For each secret, you also provide the name under which its value should be added to ",(0,s.jsx)(t.code,{children:"context"}),"."]}),"\n",(0,s.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(c.Z,{value:"npm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/secrets-manager\nnpm install --save-dev @aws-sdk/client-secrets-manager\n"})})}),(0,s.jsx)(c.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/secrets-manager\nyarn add --dev @aws-sdk/client-secrets-manager\n"})})}),(0,s.jsx)(c.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/secrets-manager\npnpm add --save-dev @aws-sdk/client-secrets-manager\n"})})})]}),"\n",(0,s.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(t.code,{children:"SecretsManagerClient"}),"): SecretsManagerClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(t.code,{children:"@aws-sdk/client-secrets-manager"}),"."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"awsClientOptions"})," (object) (optional): Options to pass to SecretsManagerClient class constructor."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"awsClientAssumeRole"})," (string) (optional): Internal key where secrets are stored. See ",(0,s.jsx)(t.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"awsClientCapture"})," (function) (optional): Enable XRay by passing ",(0,s.jsx)(t.code,{children:"captureAWSv3Client"})," from ",(0,s.jsx)(t.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameter ",(0,s.jsx)(t.code,{children:"SecretId"}),"."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"fetchRotationDate"})," (boolean|object) (default ",(0,s.jsx)(t.code,{children:"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,s.jsx)(t.code,{children:"NextRotationDate"}),"/",(0,s.jsx)(t.code,{children:"LastRotationDate"}),"/",(0,s.jsx)(t.code,{children:"LastChangedDate"}),". ",(0,s.jsx)(t.code,{children:"cacheExpiry"})," of ",(0,s.jsx)(t.code,{children:"-1"})," will use ",(0,s.jsx)(t.code,{children:"NextRotationDate"}),", while any other value will be added to the ",(0,s.jsx)(t.code,{children:"LastRotationDate"})," or ",(0,s.jsx)(t.code,{children:"LastChangedDate"}),", whichever is more recent. If secrets have different rotation schedules, use multiple instances of this middleware."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(t.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(t.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"cacheKey"})," (string) (default ",(0,s.jsx)(t.code,{children:"secrets-manager"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"cacheExpiry"})," (number) (default ",(0,s.jsx)(t.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,s.jsx)(t.code,{children:"-1"}),": cache forever, ",(0,s.jsx)(t.code,{children:"0"}),": never cache, ",(0,s.jsx)(t.code,{children:"n"}),": cache for n ms."]}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.code,{children:"setToContext"})," (boolean) (default ",(0,s.jsx)(t.code,{children:"false"}),"): Store secrets to ",(0,s.jsx)(t.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(t.code,{children:"secretsmanager:GetSecretValue"}),". If using ",(0,s.jsx)(t.code,{children:"fetchRotationDate"})," add ",(0,s.jsx)(t.code,{children:"secretsmanager:DescribeSecret"})," in as well."]}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport secretsManager from '@middy/secrets-manager'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .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 .handler(lambdaHandler)\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"})}),"\n",(0,s.jsx)(t.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(t.p,{children:["To exclude ",(0,s.jsx)(t.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(t.code,{children:"@aws-sdk/client-secrets-manager"})," to the exclude list."]}),"\n",(0,s.jsx)(t.h2,{id:"usage-with-typescript",children:"Usage with TypeScript"}),"\n",(0,s.jsxs)(t.p,{children:["Data stored in SecretsManager can be stored as arbitrary structured data. It's not possible to know in advance what shape the fetched data will have, so by default the fetched secrets will have type ",(0,s.jsx)(t.code,{children:"unknown"}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["You can provide some type hints by leveraging the ",(0,s.jsx)(t.code,{children:"secret"})," utility function. This function allows you to specify what's the expected type that will be fetched for every SecretsManager request."]}),"\n",(0,s.jsxs)(t.p,{children:["The idea is that, for every request specified in the ",(0,s.jsx)(t.code,{children:"fetchData"})," option, rather than just providing the parameter configuration as an object, you can wrap it in a ",(0,s.jsx)(t.code,{children:"secret(key)"})," call. Internally, ",(0,s.jsx)(t.code,{children:"secret"})," is a function that will return ",(0,s.jsx)(t.code,{children:"key"})," as received, but it allows you to use generics to provide type hints for the expected fetched value type for that request."]}),"\n",(0,s.jsx)(t.p,{children:"This way TypeScript can understand how to treat the additional data attached to the context and stored in the internal storage."}),"\n",(0,s.jsxs)(t.p,{children:["The following example illustrates how to use ",(0,s.jsx)(t.code,{children:"secret"}),":"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",children:"import middy from '@middy/core'\nimport secretsManager, { secret } from '@middy/secrets-manager'\n\nconst lambdaHandler = (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\nexport const handler = middy()\n.use(\n secretsManager({\n fetchData: {\n someSecret: secret<{User: string, Password: string}>('someHiddenSecret')\n }),\n setToContext: true\n })\n)\n.before(async (request) => {\n const data = await getInternal('someSecret', request)\n // data.someSecret.User (string)\n // data.someSecret.Password (string)\n // or, since we have `setToContext: true`\n // request.context.someSecret.User (string)\n // request.context.someSecret.Password (string)\n})\n.handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>c});n(7294);var s=n(6010);const r={tabItem:"tabItem_Ymn6"};var a=n(5893);function c(e){let{children:t,hidden:n,className:c}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.Z)(r.tabItem,c),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>y});var s=n(7294),r=n(6010),a=n(2466),c=n(6550),l=n(469),i=n(1980),o=n(7392),d=n(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.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)??[]}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:s,default:r}}=e;return{value:t,label:n,attributes:s,default:r}}))}(n);return function(e){const t=(0,o.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 p(e){let{queryString:t=!1,groupId:n}=e;const r=(0,c.k6)(),a=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)(a),(0,s.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(r.location.search);t.set(a,e),r.replace({...r.location,search:t.toString()})}),[a,r])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,a=h(e),[c,i]=(0,s.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 s=n.find((e=>e.default))??n[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:t,tabValues:a}))),[o,u]=p({queryString:n,groupId:r}),[f,x]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,a]=(0,d.Nk)(n);return[r,(0,s.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:r}),g=(()=>{const e=o??f;return m({value:e,tabValues:a})?e:null})();(0,l.Z)((()=>{g&&i(g)}),[g]);return{selectedValue:c,selectValue:(0,s.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),x(e)}),[u,x,a]),tabValues:a}}var x=n(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(5893);function b(e){let{className:t,block:n,selectedValue:s,selectValue:c,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:o}=(0,a.o5)(),d=e=>{const t=e.currentTarget,n=i.indexOf(t),r=l[n].value;r!==s&&(o(t),c(r))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:s===t?0:-1,"aria-selected":s===t,ref:e=>i.push(e),onKeyDown:u,onClick:d,...a,className:(0,r.Z)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":s===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:r}=e;const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===r));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,s.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function w(e){const t=f(e);return(0,j.jsxs)("div",{className:(0,r.Z)("tabs-container",g.tabList),children:[(0,j.jsx)(b,{...e,...t}),(0,j.jsx)(v,{...e,...t})]})}function y(e){const t=(0,x.Z)();return(0,j.jsx)(w,{...e,children:u(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>l,a:()=>c});var s=n(7294);const r={},a=s.createContext(r);function c(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:c(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/1124057e.7d43e3f2.js b/assets/js/1124057e.4c2fc2f3.js similarity index 99% rename from assets/js/1124057e.7d43e3f2.js rename to assets/js/1124057e.4c2fc2f3.js index 5e605719c..305666f36 100644 --- a/assets/js/1124057e.7d43e3f2.js +++ b/assets/js/1124057e.4c2fc2f3.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2308],{8625:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>m,frontMatter:()=>l,metadata:()=>i,toc:()=>u});var a=t(5893),r=t(1151),s=t(4866),d=t(5162);const l={title:"dynamodb"},o=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/dynamodb.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{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},{value:"Usage with TypeScript",id:"usage-with-typescript",level:2}];function h(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.p,{children:"Fetches DynamoDB stored configuration and parses out JSON."}),"\n",(0,a.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,a.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,a.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(d.Z,{value:"npm",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/dynamodb\nnpm install --save-dev @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb\n"})})}),(0,a.jsx)(d.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/dynamodb\nyarn add --dev @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb\n"})})}),(0,a.jsx)(d.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/dynamodb\npnpm add --save-dev @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb\n"})})})]}),"\n",(0,a.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,a.jsx)(n.code,{children:"DynamoDBClient"}),"): DynamoDBClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,a.jsx)(n.code,{children:"@aws-sdk/client-dynamodb"}),"."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"awsClientOptions"})," (object) (default ",(0,a.jsx)(n.code,{children:"undefined"}),"): Options to pass to DynamoDBClient class constructor."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"awsClientAssumeRole"})," (string) (default ",(0,a.jsx)(n.code,{children:"undefined"}),"): Internal key where secrets are stored. See ",(0,a.jsx)(n.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"awsClientCapture"})," (function) (default ",(0,a.jsx)(n.code,{children:"undefined"}),"): Enable XRay by passing ",(0,a.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,a.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameters."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,a.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,a.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"cacheKey"})," (string) (default ",(0,a.jsx)(n.code,{children:"dynamodb"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"cacheExpiry"})," (number) (default ",(0,a.jsx)(n.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,a.jsx)(n.code,{children:"-1"}),": cache forever, ",(0,a.jsx)(n.code,{children:"0"}),": never cache, ",(0,a.jsx)(n.code,{children:"n"}),": cache for n ms."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"setToContext"})," (boolean) (default ",(0,a.jsx)(n.code,{children:"false"}),"): Store credentials to ",(0,a.jsx)(n.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,a.jsx)(n.p,{children:"NOTES:"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,a.jsx)(n.code,{children:"dynamodb:BatchGetItemCommand"})]}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport dynamodb from '@middy/dynamodb'\n\nconst lambdaHandler = (event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n}\n\nexport const handler = middy()\n .use(\n dynamodb({\n fetchData: {\n config: {\n TableName: '...',\n Key: {\n pk: '0000'\n }\n }\n }\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,a.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,a.jsxs)(n.p,{children:["To exclude ",(0,a.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,a.jsx)(n.code,{children:"@aws-sdk/client-dynamodb"})," to the exclude list."]}),"\n",(0,a.jsx)(n.h2,{id:"usage-with-typescript",children:"Usage with TypeScript"}),"\n",(0,a.jsxs)(n.p,{children:["Data in DynamoDB can be stored as arbitrary structured data. It's not possible to know in advance what shape the fetched data will have, so by default the fetched parameters will have type ",(0,a.jsx)(n.code,{children:"Record"}),"."]}),"\n",(0,a.jsxs)(n.p,{children:["You can provide some type hints by leveraging the ",(0,a.jsx)(n.code,{children:"dynamoDbReq"})," utility function. This function allows you to specify what's the expected type that will be fetched for every DynamoDB request."]}),"\n",(0,a.jsxs)(n.p,{children:["The idea is that, for every request specified in the ",(0,a.jsx)(n.code,{children:"fetchData"})," option, rather than just providing the parameter configuration as an object, you can wrap it in a ",(0,a.jsx)(n.code,{children:"dynamoDbReq(config)"})," call. Internally, ",(0,a.jsx)(n.code,{children:"dynamoDbReq"})," is a function that will return ",(0,a.jsx)(n.code,{children:"config"})," as received, but it allows you to use generics to provide type hints for the expected fetched value type for that request."]}),"\n",(0,a.jsx)(n.p,{children:"This way TypeScript can understand how to treat the additional data attached to the context and stored in the internal storage."}),"\n",(0,a.jsxs)(n.p,{children:["The following example illustrates how to use ",(0,a.jsx)(n.code,{children:"dynamoDbReq"}),":"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-typescript",children:"import middy from '@middy/core'\nimport dynamodb, { dynamoDbReq } 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: dynamoDbReq<{field1: string, field2: string, field3: number}>({\n TableName: '...'\n Key: {\n pk: '0000'\n }\n })\n }\n })\n)\n.before(async (request) => {\n const data = await getInternal('config', request)\n // data.config.field1 (string)\n // data.config.field2 (string)\n // data.config.field3 (number)\n})\n"})})]})}function m(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>d});t(7294);var a=t(6010);const r={tabItem:"tabItem_Ymn6"};var s=t(5893);function d(e){let{children:n,hidden:t,className:d}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,a.Z)(r.tabItem,d),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var a=t(7294),r=t(6010),s=t(2466),d=t(6550),l=t(469),o=t(1980),i=t(7392),c=t(12);function u(e){return a.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:t}=e;return(0,a.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:a,default:r}}=e;return{value:n,label:t,attributes:a,default:r}}))}(t);return function(e){const n=(0,i.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function m(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function p(e){let{queryString:n=!1,groupId:t}=e;const r=(0,d.k6)(),s=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(s),(0,a.useCallback)((e=>{if(!s)return;const n=new URLSearchParams(r.location.search);n.set(s,e),r.replace({...r.location,search:n.toString()})}),[s,r])]}function f(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,s=h(e),[d,o]=(0,a.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const a=t.find((e=>e.default))??t[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:n,tabValues:s}))),[i,u]=p({queryString:t,groupId:r}),[f,b]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,s]=(0,c.Nk)(t);return[r,(0,a.useCallback)((e=>{t&&s.set(e)}),[t,s])]}({groupId:r}),y=(()=>{const e=i??f;return m({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{y&&o(y)}),[y]);return{selectedValue:d,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,s]),tabValues:s}}var b=t(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=t(5893);function j(e){let{className:n,block:t,selectedValue:a,selectValue:d,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:i}=(0,s.o5)(),c=e=>{const n=e.currentTarget,t=o.indexOf(n),r=l[t].value;r!==a&&(i(n),d(r))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":t},n),children:l.map((e=>{let{value:n,label:t,attributes:s}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:a===n?0:-1,"aria-selected":a===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...s,className:(0,r.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":a===n}),children:t??n},n)}))})}function g(e){let{lazy:n,children:t,selectedValue:r}=e;const s=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=s.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:s.map(((e,n)=>(0,a.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function v(e){const n=f(e);return(0,x.jsxs)("div",{className:(0,r.Z)("tabs-container",y.tabList),children:[(0,x.jsx)(j,{...e,...n}),(0,x.jsx)(g,{...e,...n})]})}function w(e){const n=(0,b.Z)();return(0,x.jsx)(v,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>l,a:()=>d});var a=t(7294);const r={},s=a.createContext(r);function d(e){const n=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:d(e.components),a.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2308],{8625:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>m,frontMatter:()=>l,metadata:()=>i,toc:()=>u});var a=t(5893),r=t(1151),s=t(4866),d=t(5162);const l={title:"dynamodb"},o=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/dynamodb.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{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},{value:"Usage with TypeScript",id:"usage-with-typescript",level:2}];function h(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.p,{children:"Fetches DynamoDB stored configuration and parses out JSON."}),"\n",(0,a.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,a.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,a.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(d.Z,{value:"npm",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/dynamodb\nnpm install --save-dev @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb\n"})})}),(0,a.jsx)(d.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/dynamodb\nyarn add --dev @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb\n"})})}),(0,a.jsx)(d.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/dynamodb\npnpm add --save-dev @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb\n"})})})]}),"\n",(0,a.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,a.jsx)(n.code,{children:"DynamoDBClient"}),"): DynamoDBClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,a.jsx)(n.code,{children:"@aws-sdk/client-dynamodb"}),"."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"awsClientOptions"})," (object) (default ",(0,a.jsx)(n.code,{children:"undefined"}),"): Options to pass to DynamoDBClient class constructor."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"awsClientAssumeRole"})," (string) (default ",(0,a.jsx)(n.code,{children:"undefined"}),"): Internal key where secrets are stored. See ",(0,a.jsx)(n.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"awsClientCapture"})," (function) (default ",(0,a.jsx)(n.code,{children:"undefined"}),"): Enable XRay by passing ",(0,a.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,a.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameters."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,a.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,a.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"cacheKey"})," (string) (default ",(0,a.jsx)(n.code,{children:"dynamodb"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"cacheExpiry"})," (number) (default ",(0,a.jsx)(n.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,a.jsx)(n.code,{children:"-1"}),": cache forever, ",(0,a.jsx)(n.code,{children:"0"}),": never cache, ",(0,a.jsx)(n.code,{children:"n"}),": cache for n ms."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"setToContext"})," (boolean) (default ",(0,a.jsx)(n.code,{children:"false"}),"): Store credentials to ",(0,a.jsx)(n.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,a.jsx)(n.p,{children:"NOTES:"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,a.jsx)(n.code,{children:"dynamodb:BatchGetItemCommand"})]}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport dynamodb from '@middy/dynamodb'\n\nconst lambdaHandler = (event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n}\n\nexport const handler = middy()\n .use(\n dynamodb({\n fetchData: {\n config: {\n TableName: '...',\n Key: {\n pk: '0000'\n }\n }\n }\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,a.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,a.jsxs)(n.p,{children:["To exclude ",(0,a.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,a.jsx)(n.code,{children:"@aws-sdk/client-dynamodb"})," to the exclude list."]}),"\n",(0,a.jsx)(n.h2,{id:"usage-with-typescript",children:"Usage with TypeScript"}),"\n",(0,a.jsxs)(n.p,{children:["Data in DynamoDB can be stored as arbitrary structured data. It's not possible to know in advance what shape the fetched data will have, so by default the fetched parameters will have type ",(0,a.jsx)(n.code,{children:"Record"}),"."]}),"\n",(0,a.jsxs)(n.p,{children:["You can provide some type hints by leveraging the ",(0,a.jsx)(n.code,{children:"dynamoDbReq"})," utility function. This function allows you to specify what's the expected type that will be fetched for every DynamoDB request."]}),"\n",(0,a.jsxs)(n.p,{children:["The idea is that, for every request specified in the ",(0,a.jsx)(n.code,{children:"fetchData"})," option, rather than just providing the parameter configuration as an object, you can wrap it in a ",(0,a.jsx)(n.code,{children:"dynamoDbReq(config)"})," call. Internally, ",(0,a.jsx)(n.code,{children:"dynamoDbReq"})," is a function that will return ",(0,a.jsx)(n.code,{children:"config"})," as received, but it allows you to use generics to provide type hints for the expected fetched value type for that request."]}),"\n",(0,a.jsx)(n.p,{children:"This way TypeScript can understand how to treat the additional data attached to the context and stored in the internal storage."}),"\n",(0,a.jsxs)(n.p,{children:["The following example illustrates how to use ",(0,a.jsx)(n.code,{children:"dynamoDbReq"}),":"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-typescript",children:"import middy from '@middy/core'\nimport dynamodb, { dynamoDbReq } 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: dynamoDbReq<{field1: string, field2: string, field3: number}>({\n TableName: '...'\n Key: {\n pk: '0000'\n }\n })\n }\n })\n)\n.before(async (request) => {\n const data = await getInternal('config', request)\n // data.config.field1 (string)\n // data.config.field2 (string)\n // data.config.field3 (number)\n})\n"})})]})}function m(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>d});t(7294);var a=t(6010);const r={tabItem:"tabItem_Ymn6"};var s=t(5893);function d(e){let{children:n,hidden:t,className:d}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,a.Z)(r.tabItem,d),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var a=t(7294),r=t(6010),s=t(2466),d=t(6550),l=t(469),o=t(1980),i=t(7392),c=t(12);function u(e){return a.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:t}=e;return(0,a.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:a,default:r}}=e;return{value:n,label:t,attributes:a,default:r}}))}(t);return function(e){const n=(0,i.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function m(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function p(e){let{queryString:n=!1,groupId:t}=e;const r=(0,d.k6)(),s=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(s),(0,a.useCallback)((e=>{if(!s)return;const n=new URLSearchParams(r.location.search);n.set(s,e),r.replace({...r.location,search:n.toString()})}),[s,r])]}function f(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,s=h(e),[d,o]=(0,a.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const a=t.find((e=>e.default))??t[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:n,tabValues:s}))),[i,u]=p({queryString:t,groupId:r}),[f,b]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,s]=(0,c.Nk)(t);return[r,(0,a.useCallback)((e=>{t&&s.set(e)}),[t,s])]}({groupId:r}),y=(()=>{const e=i??f;return m({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{y&&o(y)}),[y]);return{selectedValue:d,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,s]),tabValues:s}}var b=t(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=t(5893);function j(e){let{className:n,block:t,selectedValue:a,selectValue:d,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:i}=(0,s.o5)(),c=e=>{const n=e.currentTarget,t=o.indexOf(n),r=l[t].value;r!==a&&(i(n),d(r))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":t},n),children:l.map((e=>{let{value:n,label:t,attributes:s}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:a===n?0:-1,"aria-selected":a===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...s,className:(0,r.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":a===n}),children:t??n},n)}))})}function g(e){let{lazy:n,children:t,selectedValue:r}=e;const s=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=s.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:s.map(((e,n)=>(0,a.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function v(e){const n=f(e);return(0,x.jsxs)("div",{className:(0,r.Z)("tabs-container",y.tabList),children:[(0,x.jsx)(j,{...e,...n}),(0,x.jsx)(g,{...e,...n})]})}function w(e){const n=(0,b.Z)();return(0,x.jsx)(v,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>l,a:()=>d});var a=t(7294);const r={},s=a.createContext(r);function d(e){const n=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:d(e.components),a.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/171930c3.ec33f3de.js b/assets/js/171930c3.31f00663.js similarity index 98% rename from assets/js/171930c3.ec33f3de.js rename to assets/js/171930c3.31f00663.js index 1c417312e..3be1b412c 100644 --- a/assets/js/171930c3.ec33f3de.js +++ b/assets/js/171930c3.31f00663.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2786],{3158:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>u,frontMatter:()=>s,metadata:()=>a,toc:()=>d});var o=n(5893),r=n(1151);const s={title:"AWS Relational Database Service (RDS)"},i=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/RDS.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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={},d=[];function l(e){const t={admonition:"admonition",code:"code",p:"p",pre:"pre",...(0,r.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsxs)(t.p,{children:["First, you need to pass in a password. In order from most secure to least: ",(0,o.jsx)(t.code,{children:"RDS.Signer"}),", ",(0,o.jsx)(t.code,{children:"SecretsManager"}),", ",(0,o.jsx)(t.code,{children:"SSM"})," using SecureString.\n",(0,o.jsx)(t.code,{children:"SSM"})," can be considered equally secure to ",(0,o.jsx)(t.code,{children:"SecretsManager"})," if you have your own password rotation system."]}),"\n",(0,o.jsx)(t.p,{children:"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:"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"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"})}),"\n",(0,o.jsxs)(t.p,{children:["Corresponding ",(0,o.jsx)(t.code,{children:"RDS.ParameterGroups"})," values should be set to enforce TLS connections."]})]})}function u(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>a,a:()=>i});var o=n(7294);const r={},s=o.createContext(r);function i(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2786],{3158:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>u,frontMatter:()=>s,metadata:()=>a,toc:()=>d});var o=n(5893),r=n(1151);const s={title:"AWS Relational Database Service (RDS)"},i=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/RDS.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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={},d=[];function l(e){const t={admonition:"admonition",code:"code",p:"p",pre:"pre",...(0,r.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsxs)(t.p,{children:["First, you need to pass in a password. In order from most secure to least: ",(0,o.jsx)(t.code,{children:"RDS.Signer"}),", ",(0,o.jsx)(t.code,{children:"SecretsManager"}),", ",(0,o.jsx)(t.code,{children:"SSM"})," using SecureString.\n",(0,o.jsx)(t.code,{children:"SSM"})," can be considered equally secure to ",(0,o.jsx)(t.code,{children:"SecretsManager"})," if you have your own password rotation system."]}),"\n",(0,o.jsx)(t.p,{children:"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:"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"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"})}),"\n",(0,o.jsxs)(t.p,{children:["Corresponding ",(0,o.jsx)(t.code,{children:"RDS.ParameterGroups"})," values should be set to enforce TLS connections."]})]})}function u(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>a,a:()=>i});var o=n(7294);const r={},s=o.createContext(r);function i(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/18dc5a76.443b3252.js b/assets/js/18dc5a76.09a47bce.js similarity index 98% rename from assets/js/18dc5a76.443b3252.js rename to assets/js/18dc5a76.09a47bce.js index e7f2f674e..1923f5ff0 100644 --- a/assets/js/18dc5a76.443b3252.js +++ b/assets/js/18dc5a76.09a47bce.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7566],{9307:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>m,frontMatter:()=>i,metadata:()=>d,toc:()=>p});var n=r(5893),a=r(1151);const i={title:"API Gateway (HTTP)"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-http.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},s={},p=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,n.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html",children:"Using AWS Lambda with Amazon API Gateway"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html",children:"Working with HTTP APIs"})}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>d,a:()=>o});var n=r(7294);const a={},i=n.createContext(a);function o(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7566],{9307:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>m,frontMatter:()=>i,metadata:()=>d,toc:()=>p});var n=r(5893),a=r(1151);const i={title:"API Gateway (HTTP)"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-http.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},s={},p=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,n.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html",children:"Using AWS Lambda with Amazon API Gateway"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html",children:"Working with HTTP APIs"})}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>d,a:()=>o});var n=r(7294);const a={},i=n.createContext(a);function o(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/19606b2d.a301c5d4.js b/assets/js/19606b2d.1c2cf390.js similarity index 99% rename from assets/js/19606b2d.a301c5d4.js rename to assets/js/19606b2d.1c2cf390.js index ec26adc10..bdae0f652 100644 --- a/assets/js/19606b2d.a301c5d4.js +++ b/assets/js/19606b2d.1c2cf390.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1544],{6145:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>o,contentTitle:()=>a,default:()=>x,frontMatter:()=>l,metadata:()=>c,toc:()=>h});var t=n(5893),d=n(1151),s=n(4866),i=n(5162);const l={title:"event-normalizer"},a=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/event-normalizer.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},o={},h=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function u(e){const r={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,d.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(r.p,{children:"Middleware for iterating through an AWS event records, parsing and normalizing nested events."}),"\n",(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.strong,{children:"AWS Events Transformations:"}),"\n",(0,t.jsx)(r.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html",children:"https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html"})]}),"\n",(0,t.jsxs)(r.table,{children:[(0,t.jsx)(r.thead,{children:(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.th,{children:"Event Source"}),(0,t.jsx)(r.th,{children:"Included"}),(0,t.jsx)(r.th,{children:"Comments"})]})}),(0,t.jsxs)(r.tbody,{children:[(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Alexa"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"API Gateway (HTTP)"}),(0,t.jsx)(r.td,{children:"No *"}),(0,t.jsxs)(r.td,{children:["See middleware prefixed with ",(0,t.jsx)(r.code,{children:"@middy/http-"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"API Gateway (REST)"}),(0,t.jsx)(r.td,{children:"No *"}),(0,t.jsxs)(r.td,{children:["See middleware prefixed with ",(0,t.jsx)(r.code,{children:"@middy/http-"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"API Gateway (WS)"}),(0,t.jsx)(r.td,{children:"No *"}),(0,t.jsxs)(r.td,{children:["See middleware ",(0,t.jsx)(r.code,{children:"@middy/ws-json-body-parser"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Application LB"}),(0,t.jsx)(r.td,{children:"No *"}),(0,t.jsxs)(r.td,{children:["See middleware prefixed with ",(0,t.jsx)(r.code,{children:"@middy/http-"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"CloudFormation"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"CloudFront"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"CloudTrail"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"CloudWatch Logs"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Base64 decode and JSON parse ",(0,t.jsx)(r.code,{children:"data"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"CodeCommit"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"CodePipeline"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["JSON parse ",(0,t.jsx)(r.code,{children:"UserParameters"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Cognito"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Config"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["JSON parse ",(0,t.jsx)(r.code,{children:"invokingEvent"})," and ",(0,t.jsx)(r.code,{children:"ruleParameters"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Connect"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"DocumentDB"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"DynamoDB"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Unmarshall ",(0,t.jsx)(r.code,{children:"Keys"}),", ",(0,t.jsx)(r.code,{children:"OldImage"}),", and ",(0,t.jsx)(r.code,{children:"NewImage"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"EC2"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"EventBridge"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"IoT"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"IoT Event"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Kafka"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Base64 decode and JSON parse ",(0,t.jsx)(r.code,{children:"value"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Kafka (MSK)"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Base64 decode and JSON parse ",(0,t.jsx)(r.code,{children:"value"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Kinesis Firehose"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Base64 decode and JSON parse ",(0,t.jsx)(r.code,{children:"data"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Kinesis Stream"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Base64 decode and JSON parse ",(0,t.jsx)(r.code,{children:"data"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Lex"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"MQ"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Base64 decode and JSON parse ",(0,t.jsx)(r.code,{children:"data"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"RDS"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"S3"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["URI decode ",(0,t.jsx)(r.code,{children:"key"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"S3 Batch"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["URI decode ",(0,t.jsx)(r.code,{children:"s3Key"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"S3 Object Lambda"}),(0,t.jsx)(r.td,{children:"No *"}),(0,t.jsxs)(r.td,{children:["See middleware ",(0,t.jsx)(r.code,{children:"@middy/s3-object-response"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Secrets Manager"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"SES"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"SNS"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["JSON parse ",(0,t.jsx)(r.code,{children:"Message"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"SQS"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["JSON parse ",(0,t.jsx)(r.code,{children:"body"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"VPC Lattice"}),(0,t.jsx)(r.td,{children:"No *"}),(0,t.jsxs)(r.td,{children:["See middleware prefixed with ",(0,t.jsx)(r.code,{children:"@middy/http-"})]})]})]})]}),"\n",(0,t.jsx)(r.p,{children:"* Handled in another dedicated middleware(s)"}),"\n",(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.strong,{children:"Test Events"}),"\nSome events send test events after set, you will need to handle these."]}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-js",children:"// 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"})}),"\n",(0,t.jsx)(r.h2,{id:"install",children:"Install"}),"\n",(0,t.jsx)(r.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,t.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,t.jsx)(i.Z,{value:"npm",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"npm install --save @middy/event-normalizer\n"})})}),(0,t.jsx)(i.Z,{value:"yarn",label:"Yarn",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"yarn add @middy/event-normalizer\n"})})}),(0,t.jsx)(i.Z,{value:"pnpm",label:"pnpm",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"pnpm add @middy/event-normalizer\n"})})})]}),"\n",(0,t.jsx)(r.h2,{id:"options",children:"Options"}),"\n",(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.code,{children:"wrapNumbers"})," (boolean) (default ",(0,t.jsx)(r.code,{children:"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."]}),"\n"]}),"\n",(0,t.jsx)(r.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-javascript",children:"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\nexport const handler = middy().use(eventNormalizer()).handler(lambdaHandler)\n"})})]})}function x(e={}){const{wrapper:r}={...(0,d.a)(),...e.components};return r?(0,t.jsx)(r,{...e,children:(0,t.jsx)(u,{...e})}):u(e)}},5162:(e,r,n)=>{n.d(r,{Z:()=>i});n(7294);var t=n(6010);const d={tabItem:"tabItem_Ymn6"};var s=n(5893);function i(e){let{children:r,hidden:n,className:i}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,t.Z)(d.tabItem,i),hidden:n,children:r})}},4866:(e,r,n)=>{n.d(r,{Z:()=>y});var t=n(7294),d=n(6010),s=n(2466),i=n(6550),l=n(469),a=n(1980),c=n(7392),o=n(12);function h(e){return t.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:r}=e;return!!r&&"object"==typeof r&&"value"in r}(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)??[]}function u(e){const{values:r,children:n}=e;return(0,t.useMemo)((()=>{const e=r??function(e){return h(e).map((e=>{let{props:{value:r,label:n,attributes:t,default:d}}=e;return{value:r,label:n,attributes:t,default:d}}))}(n);return function(e){const r=(0,c.l)(e,((e,r)=>e.value===r.value));if(r.length>0)throw new Error(`Docusaurus error: Duplicate values "${r.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[r,n])}function x(e){let{value:r,tabValues:n}=e;return n.some((e=>e.value===r))}function j(e){let{queryString:r=!1,groupId:n}=e;const d=(0,i.k6)(),s=function(e){let{queryString:r=!1,groupId:n}=e;if("string"==typeof r)return r;if(!1===r)return null;if(!0===r&&!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:r,groupId:n});return[(0,a._X)(s),(0,t.useCallback)((e=>{if(!s)return;const r=new URLSearchParams(d.location.search);r.set(s,e),d.replace({...d.location,search:r.toString()})}),[s,d])]}function m(e){const{defaultValue:r,queryString:n=!1,groupId:d}=e,s=u(e),[i,a]=(0,t.useState)((()=>function(e){let{defaultValue:r,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(r){if(!x({value:r,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${r}" 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 r}const t=n.find((e=>e.default))??n[0];if(!t)throw new Error("Unexpected error: 0 tabValues");return t.value}({defaultValue:r,tabValues:s}))),[c,h]=j({queryString:n,groupId:d}),[m,p]=function(e){let{groupId:r}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(r),[d,s]=(0,o.Nk)(n);return[d,(0,t.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:d}),v=(()=>{const e=c??m;return x({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{v&&a(v)}),[v]);return{selectedValue:i,selectValue:(0,t.useCallback)((e=>{if(!x({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);a(e),h(e),p(e)}),[h,p,s]),tabValues:s}}var p=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(5893);function f(e){let{className:r,block:n,selectedValue:t,selectValue:i,tabValues:l}=e;const a=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.o5)(),o=e=>{const r=e.currentTarget,n=a.indexOf(r),d=l[n].value;d!==t&&(c(r),i(d))},h=e=>{let r=null;switch(e.key){case"Enter":o(e);break;case"ArrowRight":{const n=a.indexOf(e.currentTarget)+1;r=a[n]??a[0];break}case"ArrowLeft":{const n=a.indexOf(e.currentTarget)-1;r=a[n]??a[a.length-1];break}}r?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,d.Z)("tabs",{"tabs--block":n},r),children:l.map((e=>{let{value:r,label:n,attributes:s}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:t===r?0:-1,"aria-selected":t===r,ref:e=>a.push(e),onKeyDown:h,onClick:o,...s,className:(0,d.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":t===r}),children:n??r},r)}))})}function g(e){let{lazy:r,children:n,selectedValue:d}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(r){const e=s.find((e=>e.props.value===d));return e?(0,t.cloneElement)(e,{className:"margin-top--md"}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:s.map(((e,r)=>(0,t.cloneElement)(e,{key:r,hidden:e.props.value!==d})))})}function N(e){const r=m(e);return(0,b.jsxs)("div",{className:(0,d.Z)("tabs-container",v.tabList),children:[(0,b.jsx)(f,{...e,...r}),(0,b.jsx)(g,{...e,...r})]})}function y(e){const r=(0,p.Z)();return(0,b.jsx)(N,{...e,children:h(e.children)},String(r))}},1151:(e,r,n)=>{n.d(r,{Z:()=>l,a:()=>i});var t=n(7294);const d={},s=t.createContext(d);function i(e){const r=t.useContext(s);return t.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function l(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(d):e.components||d:i(e.components),t.createElement(s.Provider,{value:r},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1544],{6145:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>o,contentTitle:()=>a,default:()=>x,frontMatter:()=>l,metadata:()=>c,toc:()=>h});var t=n(5893),d=n(1151),s=n(4866),i=n(5162);const l={title:"event-normalizer"},a=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/event-normalizer.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},o={},h=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function u(e){const r={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,d.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(r.p,{children:"Middleware for iterating through an AWS event records, parsing and normalizing nested events."}),"\n",(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.strong,{children:"AWS Events Transformations:"}),"\n",(0,t.jsx)(r.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html",children:"https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html"})]}),"\n",(0,t.jsxs)(r.table,{children:[(0,t.jsx)(r.thead,{children:(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.th,{children:"Event Source"}),(0,t.jsx)(r.th,{children:"Included"}),(0,t.jsx)(r.th,{children:"Comments"})]})}),(0,t.jsxs)(r.tbody,{children:[(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Alexa"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"API Gateway (HTTP)"}),(0,t.jsx)(r.td,{children:"No *"}),(0,t.jsxs)(r.td,{children:["See middleware prefixed with ",(0,t.jsx)(r.code,{children:"@middy/http-"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"API Gateway (REST)"}),(0,t.jsx)(r.td,{children:"No *"}),(0,t.jsxs)(r.td,{children:["See middleware prefixed with ",(0,t.jsx)(r.code,{children:"@middy/http-"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"API Gateway (WS)"}),(0,t.jsx)(r.td,{children:"No *"}),(0,t.jsxs)(r.td,{children:["See middleware ",(0,t.jsx)(r.code,{children:"@middy/ws-json-body-parser"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Application LB"}),(0,t.jsx)(r.td,{children:"No *"}),(0,t.jsxs)(r.td,{children:["See middleware prefixed with ",(0,t.jsx)(r.code,{children:"@middy/http-"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"CloudFormation"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"CloudFront"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"CloudTrail"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"CloudWatch Logs"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Base64 decode and JSON parse ",(0,t.jsx)(r.code,{children:"data"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"CodeCommit"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"CodePipeline"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["JSON parse ",(0,t.jsx)(r.code,{children:"UserParameters"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Cognito"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Config"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["JSON parse ",(0,t.jsx)(r.code,{children:"invokingEvent"})," and ",(0,t.jsx)(r.code,{children:"ruleParameters"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Connect"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"DocumentDB"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"DynamoDB"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Unmarshall ",(0,t.jsx)(r.code,{children:"Keys"}),", ",(0,t.jsx)(r.code,{children:"OldImage"}),", and ",(0,t.jsx)(r.code,{children:"NewImage"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"EC2"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"EventBridge"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"IoT"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"IoT Event"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Kafka"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Base64 decode and JSON parse ",(0,t.jsx)(r.code,{children:"value"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Kafka (MSK)"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Base64 decode and JSON parse ",(0,t.jsx)(r.code,{children:"value"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Kinesis Firehose"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Base64 decode and JSON parse ",(0,t.jsx)(r.code,{children:"data"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Kinesis Stream"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Base64 decode and JSON parse ",(0,t.jsx)(r.code,{children:"data"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Lex"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"MQ"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["Base64 decode and JSON parse ",(0,t.jsx)(r.code,{children:"data"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"RDS"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"S3"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["URI decode ",(0,t.jsx)(r.code,{children:"key"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"S3 Batch"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["URI decode ",(0,t.jsx)(r.code,{children:"s3Key"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"S3 Object Lambda"}),(0,t.jsx)(r.td,{children:"No *"}),(0,t.jsxs)(r.td,{children:["See middleware ",(0,t.jsx)(r.code,{children:"@middy/s3-object-response"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"Secrets Manager"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"SES"}),(0,t.jsx)(r.td,{children:"No"}),(0,t.jsx)(r.td,{children:"Normalization not required"})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"SNS"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["JSON parse ",(0,t.jsx)(r.code,{children:"Message"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"SQS"}),(0,t.jsx)(r.td,{children:"Yes"}),(0,t.jsxs)(r.td,{children:["JSON parse ",(0,t.jsx)(r.code,{children:"body"})]})]}),(0,t.jsxs)(r.tr,{children:[(0,t.jsx)(r.td,{children:"VPC Lattice"}),(0,t.jsx)(r.td,{children:"No *"}),(0,t.jsxs)(r.td,{children:["See middleware prefixed with ",(0,t.jsx)(r.code,{children:"@middy/http-"})]})]})]})]}),"\n",(0,t.jsx)(r.p,{children:"* Handled in another dedicated middleware(s)"}),"\n",(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.strong,{children:"Test Events"}),"\nSome events send test events after set, you will need to handle these."]}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-js",children:"// 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"})}),"\n",(0,t.jsx)(r.h2,{id:"install",children:"Install"}),"\n",(0,t.jsx)(r.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,t.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,t.jsx)(i.Z,{value:"npm",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"npm install --save @middy/event-normalizer\n"})})}),(0,t.jsx)(i.Z,{value:"yarn",label:"Yarn",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"yarn add @middy/event-normalizer\n"})})}),(0,t.jsx)(i.Z,{value:"pnpm",label:"pnpm",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"pnpm add @middy/event-normalizer\n"})})})]}),"\n",(0,t.jsx)(r.h2,{id:"options",children:"Options"}),"\n",(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.code,{children:"wrapNumbers"})," (boolean) (default ",(0,t.jsx)(r.code,{children:"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."]}),"\n"]}),"\n",(0,t.jsx)(r.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-javascript",children:"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\nexport const handler = middy().use(eventNormalizer()).handler(lambdaHandler)\n"})})]})}function x(e={}){const{wrapper:r}={...(0,d.a)(),...e.components};return r?(0,t.jsx)(r,{...e,children:(0,t.jsx)(u,{...e})}):u(e)}},5162:(e,r,n)=>{n.d(r,{Z:()=>i});n(7294);var t=n(6010);const d={tabItem:"tabItem_Ymn6"};var s=n(5893);function i(e){let{children:r,hidden:n,className:i}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,t.Z)(d.tabItem,i),hidden:n,children:r})}},4866:(e,r,n)=>{n.d(r,{Z:()=>y});var t=n(7294),d=n(6010),s=n(2466),i=n(6550),l=n(469),a=n(1980),c=n(7392),o=n(12);function h(e){return t.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:r}=e;return!!r&&"object"==typeof r&&"value"in r}(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)??[]}function u(e){const{values:r,children:n}=e;return(0,t.useMemo)((()=>{const e=r??function(e){return h(e).map((e=>{let{props:{value:r,label:n,attributes:t,default:d}}=e;return{value:r,label:n,attributes:t,default:d}}))}(n);return function(e){const r=(0,c.l)(e,((e,r)=>e.value===r.value));if(r.length>0)throw new Error(`Docusaurus error: Duplicate values "${r.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[r,n])}function x(e){let{value:r,tabValues:n}=e;return n.some((e=>e.value===r))}function j(e){let{queryString:r=!1,groupId:n}=e;const d=(0,i.k6)(),s=function(e){let{queryString:r=!1,groupId:n}=e;if("string"==typeof r)return r;if(!1===r)return null;if(!0===r&&!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:r,groupId:n});return[(0,a._X)(s),(0,t.useCallback)((e=>{if(!s)return;const r=new URLSearchParams(d.location.search);r.set(s,e),d.replace({...d.location,search:r.toString()})}),[s,d])]}function m(e){const{defaultValue:r,queryString:n=!1,groupId:d}=e,s=u(e),[i,a]=(0,t.useState)((()=>function(e){let{defaultValue:r,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(r){if(!x({value:r,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${r}" 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 r}const t=n.find((e=>e.default))??n[0];if(!t)throw new Error("Unexpected error: 0 tabValues");return t.value}({defaultValue:r,tabValues:s}))),[c,h]=j({queryString:n,groupId:d}),[m,p]=function(e){let{groupId:r}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(r),[d,s]=(0,o.Nk)(n);return[d,(0,t.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:d}),v=(()=>{const e=c??m;return x({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{v&&a(v)}),[v]);return{selectedValue:i,selectValue:(0,t.useCallback)((e=>{if(!x({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);a(e),h(e),p(e)}),[h,p,s]),tabValues:s}}var p=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=n(5893);function f(e){let{className:r,block:n,selectedValue:t,selectValue:i,tabValues:l}=e;const a=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.o5)(),o=e=>{const r=e.currentTarget,n=a.indexOf(r),d=l[n].value;d!==t&&(c(r),i(d))},h=e=>{let r=null;switch(e.key){case"Enter":o(e);break;case"ArrowRight":{const n=a.indexOf(e.currentTarget)+1;r=a[n]??a[0];break}case"ArrowLeft":{const n=a.indexOf(e.currentTarget)-1;r=a[n]??a[a.length-1];break}}r?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,d.Z)("tabs",{"tabs--block":n},r),children:l.map((e=>{let{value:r,label:n,attributes:s}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:t===r?0:-1,"aria-selected":t===r,ref:e=>a.push(e),onKeyDown:h,onClick:o,...s,className:(0,d.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":t===r}),children:n??r},r)}))})}function g(e){let{lazy:r,children:n,selectedValue:d}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(r){const e=s.find((e=>e.props.value===d));return e?(0,t.cloneElement)(e,{className:"margin-top--md"}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:s.map(((e,r)=>(0,t.cloneElement)(e,{key:r,hidden:e.props.value!==d})))})}function N(e){const r=m(e);return(0,b.jsxs)("div",{className:(0,d.Z)("tabs-container",v.tabList),children:[(0,b.jsx)(f,{...e,...r}),(0,b.jsx)(g,{...e,...r})]})}function y(e){const r=(0,p.Z)();return(0,b.jsx)(N,{...e,children:h(e.children)},String(r))}},1151:(e,r,n)=>{n.d(r,{Z:()=>l,a:()=>i});var t=n(7294);const d={},s=t.createContext(d);function i(e){const r=t.useContext(s);return t.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function l(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(d):e.components||d:i(e.components),t.createElement(s.Provider,{value:r},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/1c88510b.b5e5e8bb.js b/assets/js/1c88510b.116c86eb.js similarity index 99% rename from assets/js/1c88510b.b5e5e8bb.js rename to assets/js/1c88510b.116c86eb.js index 0110717a1..7c4faf242 100644 --- a/assets/js/1c88510b.b5e5e8bb.js +++ b/assets/js/1c88510b.116c86eb.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7858],{4328:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>d,toc:()=>u});var s=t(5893),r=t(1151),a=t(4866),l=t(5162);const o={title:"s3-object-response"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/s3-object-response.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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={},u=[{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:"JSON",id:"json",level:3},{value:"Bundling",id:"bundling",level:2}];function p(e){const n={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"** This middleware is a Proof of Concept and requires real world testing before use, not recommended for production **"}),"\n",(0,s.jsx)(n.p,{children:"Fetches S3 object as a stream and writes back to s3 object response."}),"\n",(0,s.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(l.Z,{value:"npm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/s3-object-response\nnpm install --save-dev @aws-sdk/client-s3\n"})})}),(0,s.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/s3-object-response\nyarn add --dev @aws-sdk/client-s3\n"})})}),(0,s.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/s3-object-response\npnpm add --save-dev @aws-sdk/client-s3\n"})})})]}),"\n",(0,s.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(n.code,{children:"S3Client"}),"): S3Client class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-s3"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientOptions"})," (object) (optional): Options to pass to S3Client class constructor."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientCapture"})," (function) (optional): Enable XRay by passing ",(0,s.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,s.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["The response from the handler must match the allowed parameters for ",(0,s.jsx)(n.a,{href:"https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#writeGetObjectResponse-property",children:(0,s.jsx)(n.code,{children:"S3.writeGetObjectResponse"})}),", excluding ",(0,s.jsx)(n.code,{children:"RequestRoute"})," and ",(0,s.jsx)(n.code,{children:"RequestToken"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:["XRay doesn't support tracing of ",(0,s.jsx)(n.code,{children:"fetch"}),", you will need a workaround, see ",(0,s.jsx)(n.a,{href:"https://github.com/aws/aws-xray-sdk-node/issues/531#issuecomment-1378562164",children:"https://github.com/aws/aws-xray-sdk-node/issues/531#issuecomment-1378562164"})]}),"\n",(0,s.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(n.code,{children:"s3-object-lambda:WriteGetObjectResponse"})]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(n.h3,{id:"stream",children:"Stream"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import zlib from 'zlib'\nimport middy from '@middy/core'\nimport s3ObjectResponse from '@middy/s3-object-response'\n\nconst lambdaHandler = (event, context) => {\n const readStream = await context.s3ObjectFetch.then(res => res.body)\n const transformStream = zlib.createBrotliCompress()\n return {\n Body: readStream.pipe(transformStream)\n }\n}\n\nexport const handler = middy().use(s3ObjectResponse()).handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h3,{id:"json",children:"JSON"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import zlib from 'zlib'\nimport middy from '@middy/core'\nimport s3ObjectResponse from '@middy/s3-object-response'\n\nconst lambdaHandler = async (event, context) => {\n let body = await context.s3ObjectFetch.then((res) => res.json())\n // change body\n return {\n Body: JSON.stringify(body)\n }\n}\n\nexport const handler = middy().use(s3ObjectResponse()).handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(n.p,{children:["To exclude ",(0,s.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-s3"})," to the exclude list."]})]})}function m(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(p,{...e})}):p(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>l});t(7294);var s=t(6010);const r={tabItem:"tabItem_Ymn6"};var a=t(5893);function l(e){let{children:n,hidden:t,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.Z)(r.tabItem,l),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var s=t(7294),r=t(6010),a=t(2466),l=t(6550),o=t(469),i=t(1980),d=t(7392),c=t(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function p(e){const{values:n,children:t}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:s,default:r}}=e;return{value:n,label:t,attributes:s,default:r}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function m(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function h(e){let{queryString:n=!1,groupId:t}=e;const r=(0,l.k6)(),a=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,i._X)(a),(0,s.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(r.location.search);n.set(a,e),r.replace({...r.location,search:n.toString()})}),[a,r])]}function b(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,a=p(e),[l,i]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const s=t.find((e=>e.default))??t[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:a}))),[d,u]=h({queryString:t,groupId:r}),[b,f]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,a]=(0,c.Nk)(t);return[r,(0,s.useCallback)((e=>{t&&a.set(e)}),[t,a])]}({groupId:r}),j=(()=>{const e=d??b;return m({value:e,tabValues:a})?e:null})();(0,o.Z)((()=>{j&&i(j)}),[j]);return{selectedValue:l,selectValue:(0,s.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),f(e)}),[u,f,a]),tabValues:a}}var f=t(2389);const j={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=t(5893);function v(e){let{className:n,block:t,selectedValue:s,selectValue:l,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,a.o5)(),c=e=>{const n=e.currentTarget,t=i.indexOf(n),r=o[t].value;r!==s&&(d(n),l(r))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=i.indexOf(e.currentTarget)+1;n=i[t]??i[0];break}case"ArrowLeft":{const t=i.indexOf(e.currentTarget)-1;n=i[t]??i[i.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":t},n),children:o.map((e=>{let{value:n,label:t,attributes:a}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>i.push(e),onKeyDown:u,onClick:c,...a,className:(0,r.Z)("tabs__item",j.tabItem,a?.className,{"tabs__item--active":s===n}),children:t??n},n)}))})}function g(e){let{lazy:n,children:t,selectedValue:r}=e;const a=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===r));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function y(e){const n=b(e);return(0,x.jsxs)("div",{className:(0,r.Z)("tabs-container",j.tabList),children:[(0,x.jsx)(v,{...e,...n}),(0,x.jsx)(g,{...e,...n})]})}function w(e){const n=(0,f.Z)();return(0,x.jsx)(y,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>o,a:()=>l});var s=t(7294);const r={},a=s.createContext(r);function l(e){const n=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:l(e.components),s.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7858],{4328:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>d,toc:()=>u});var s=t(5893),r=t(1151),a=t(4866),l=t(5162);const o={title:"s3-object-response"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/s3-object-response.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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={},u=[{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:"JSON",id:"json",level:3},{value:"Bundling",id:"bundling",level:2}];function p(e){const n={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"** This middleware is a Proof of Concept and requires real world testing before use, not recommended for production **"}),"\n",(0,s.jsx)(n.p,{children:"Fetches S3 object as a stream and writes back to s3 object response."}),"\n",(0,s.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(l.Z,{value:"npm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/s3-object-response\nnpm install --save-dev @aws-sdk/client-s3\n"})})}),(0,s.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/s3-object-response\nyarn add --dev @aws-sdk/client-s3\n"})})}),(0,s.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/s3-object-response\npnpm add --save-dev @aws-sdk/client-s3\n"})})})]}),"\n",(0,s.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(n.code,{children:"S3Client"}),"): S3Client class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-s3"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientOptions"})," (object) (optional): Options to pass to S3Client class constructor."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientCapture"})," (function) (optional): Enable XRay by passing ",(0,s.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,s.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["The response from the handler must match the allowed parameters for ",(0,s.jsx)(n.a,{href:"https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#writeGetObjectResponse-property",children:(0,s.jsx)(n.code,{children:"S3.writeGetObjectResponse"})}),", excluding ",(0,s.jsx)(n.code,{children:"RequestRoute"})," and ",(0,s.jsx)(n.code,{children:"RequestToken"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:["XRay doesn't support tracing of ",(0,s.jsx)(n.code,{children:"fetch"}),", you will need a workaround, see ",(0,s.jsx)(n.a,{href:"https://github.com/aws/aws-xray-sdk-node/issues/531#issuecomment-1378562164",children:"https://github.com/aws/aws-xray-sdk-node/issues/531#issuecomment-1378562164"})]}),"\n",(0,s.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(n.code,{children:"s3-object-lambda:WriteGetObjectResponse"})]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(n.h3,{id:"stream",children:"Stream"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import zlib from 'zlib'\nimport middy from '@middy/core'\nimport s3ObjectResponse from '@middy/s3-object-response'\n\nconst lambdaHandler = (event, context) => {\n const readStream = await context.s3ObjectFetch.then(res => res.body)\n const transformStream = zlib.createBrotliCompress()\n return {\n Body: readStream.pipe(transformStream)\n }\n}\n\nexport const handler = middy().use(s3ObjectResponse()).handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h3,{id:"json",children:"JSON"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import zlib from 'zlib'\nimport middy from '@middy/core'\nimport s3ObjectResponse from '@middy/s3-object-response'\n\nconst lambdaHandler = async (event, context) => {\n let body = await context.s3ObjectFetch.then((res) => res.json())\n // change body\n return {\n Body: JSON.stringify(body)\n }\n}\n\nexport const handler = middy().use(s3ObjectResponse()).handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(n.p,{children:["To exclude ",(0,s.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-s3"})," to the exclude list."]})]})}function m(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(p,{...e})}):p(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>l});t(7294);var s=t(6010);const r={tabItem:"tabItem_Ymn6"};var a=t(5893);function l(e){let{children:n,hidden:t,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.Z)(r.tabItem,l),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var s=t(7294),r=t(6010),a=t(2466),l=t(6550),o=t(469),i=t(1980),d=t(7392),c=t(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function p(e){const{values:n,children:t}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:s,default:r}}=e;return{value:n,label:t,attributes:s,default:r}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function m(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function h(e){let{queryString:n=!1,groupId:t}=e;const r=(0,l.k6)(),a=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,i._X)(a),(0,s.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(r.location.search);n.set(a,e),r.replace({...r.location,search:n.toString()})}),[a,r])]}function b(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,a=p(e),[l,i]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const s=t.find((e=>e.default))??t[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:a}))),[d,u]=h({queryString:t,groupId:r}),[b,f]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,a]=(0,c.Nk)(t);return[r,(0,s.useCallback)((e=>{t&&a.set(e)}),[t,a])]}({groupId:r}),j=(()=>{const e=d??b;return m({value:e,tabValues:a})?e:null})();(0,o.Z)((()=>{j&&i(j)}),[j]);return{selectedValue:l,selectValue:(0,s.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),f(e)}),[u,f,a]),tabValues:a}}var f=t(2389);const j={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=t(5893);function v(e){let{className:n,block:t,selectedValue:s,selectValue:l,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,a.o5)(),c=e=>{const n=e.currentTarget,t=i.indexOf(n),r=o[t].value;r!==s&&(d(n),l(r))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=i.indexOf(e.currentTarget)+1;n=i[t]??i[0];break}case"ArrowLeft":{const t=i.indexOf(e.currentTarget)-1;n=i[t]??i[i.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":t},n),children:o.map((e=>{let{value:n,label:t,attributes:a}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>i.push(e),onKeyDown:u,onClick:c,...a,className:(0,r.Z)("tabs__item",j.tabItem,a?.className,{"tabs__item--active":s===n}),children:t??n},n)}))})}function g(e){let{lazy:n,children:t,selectedValue:r}=e;const a=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===r));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function y(e){const n=b(e);return(0,x.jsxs)("div",{className:(0,r.Z)("tabs-container",j.tabList),children:[(0,x.jsx)(v,{...e,...n}),(0,x.jsx)(g,{...e,...n})]})}function w(e){const n=(0,f.Z)();return(0,x.jsx)(y,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>o,a:()=>l});var s=t(7294);const r={},a=s.createContext(r);function l(e){const n=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:l(e.components),s.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/1e42f3f3.82514db2.js b/assets/js/1e42f3f3.762f8ea4.js similarity index 98% rename from assets/js/1e42f3f3.82514db2.js rename to assets/js/1e42f3f3.762f8ea4.js index dcb7f2fd7..7e04dc22c 100644 --- a/assets/js/1e42f3f3.82514db2.js +++ b/assets/js/1e42f3f3.762f8ea4.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8102],{1586:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>i,contentTitle:()=>d,default:()=>p,frontMatter:()=>t,metadata:()=>o,toc:()=>l});var r=n(5893),a=n(1151);const t={title:"ws-json-body-parser"},d=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/ws-json-body-parser.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},i={},l=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function c(e){const s={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.p,{children:"This middleware automatically parses WebSocket requests with a JSON body and converts the body into an\nobject."}),"\n",(0,r.jsx)(s.p,{children:"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."}),"\n",(0,r.jsxs)(s.p,{children:["If the body has been parsed as JSON, you can access the original body through the ",(0,r.jsx)(s.code,{children:"request.event.rawBody"}),"."]}),"\n",(0,r.jsx)(s.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(s.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:"npm install --save @middy/ws-json-body-parser\n"})}),"\n",(0,r.jsx)(s.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"reviver"})," (function) (default ",(0,r.jsx)(s.code,{children:"undefined"}),"): A ",(0,r.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters",children:"reviver"})," parameter may be passed which will be used ",(0,r.jsx)(s.code,{children:"JSON.parse"}),"ing the body."]}),"\n"]}),"\n",(0,r.jsx)(s.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport wsJsonBodyParserMiddleware from '@middy/ws-json-body-parser'\nimport wsResponseMiddleware from '@middy/ws-response'\n\nconst lambdaHandler = (event) => {\n return event.body.message\n}\n\nexport const handler = middy()\n .use(wsJsonBodyParserMiddleware())\n .use(wsResponseMiddleware())\n .handler(lambdaHandler)\n"})})]})}function p(e={}){const{wrapper:s}={...(0,a.a)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},1151:(e,s,n)=>{n.d(s,{Z:()=>o,a:()=>d});var r=n(7294);const a={},t=r.createContext(a);function d(e){const s=r.useContext(t);return r.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function o(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:d(e.components),r.createElement(t.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8102],{1586:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>i,contentTitle:()=>d,default:()=>p,frontMatter:()=>t,metadata:()=>o,toc:()=>l});var r=n(5893),a=n(1151);const t={title:"ws-json-body-parser"},d=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/ws-json-body-parser.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},i={},l=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function c(e){const s={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.p,{children:"This middleware automatically parses WebSocket requests with a JSON body and converts the body into an\nobject."}),"\n",(0,r.jsx)(s.p,{children:"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."}),"\n",(0,r.jsxs)(s.p,{children:["If the body has been parsed as JSON, you can access the original body through the ",(0,r.jsx)(s.code,{children:"request.event.rawBody"}),"."]}),"\n",(0,r.jsx)(s.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(s.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:"npm install --save @middy/ws-json-body-parser\n"})}),"\n",(0,r.jsx)(s.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"reviver"})," (function) (default ",(0,r.jsx)(s.code,{children:"undefined"}),"): A ",(0,r.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters",children:"reviver"})," parameter may be passed which will be used ",(0,r.jsx)(s.code,{children:"JSON.parse"}),"ing the body."]}),"\n"]}),"\n",(0,r.jsx)(s.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport wsJsonBodyParserMiddleware from '@middy/ws-json-body-parser'\nimport wsResponseMiddleware from '@middy/ws-response'\n\nconst lambdaHandler = (event) => {\n return event.body.message\n}\n\nexport const handler = middy()\n .use(wsJsonBodyParserMiddleware())\n .use(wsResponseMiddleware())\n .handler(lambdaHandler)\n"})})]})}function p(e={}){const{wrapper:s}={...(0,a.a)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},1151:(e,s,n)=>{n.d(s,{Z:()=>o,a:()=>d});var r=n(7294);const a={},t=r.createContext(a);function d(e){const s=r.useContext(t);return r.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function o(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:d(e.components),r.createElement(t.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/1ea8ecd6.92667eab.js b/assets/js/1ea8ecd6.125b4215.js similarity index 97% rename from assets/js/1ea8ecd6.92667eab.js rename to assets/js/1ea8ecd6.125b4215.js index cef3d1098..e74d727fa 100644 --- a/assets/js/1ea8ecd6.92667eab.js +++ b/assets/js/1ea8ecd6.125b4215.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5341],{8683:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>s,metadata:()=>r,toc:()=>c});var o=n(5893),i=n(1151);const s={title:"Internet of things (IoT)"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/iot.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-iot.html",children:"Using AWS Lambda with AWS IoT"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var o=n(7294);const i={},s=o.createContext(i);function a(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5341],{8683:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>s,metadata:()=>r,toc:()=>c});var o=n(5893),i=n(1151);const s={title:"Internet of things (IoT)"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/iot.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-iot.html",children:"Using AWS Lambda with AWS IoT"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var o=n(7294);const i={},s=o.createContext(i);function a(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/211396ae.75d36224.js b/assets/js/211396ae.de404557.js similarity index 97% rename from assets/js/211396ae.75d36224.js rename to assets/js/211396ae.de404557.js index dc5238176..a47c666e2 100644 --- a/assets/js/211396ae.75d36224.js +++ b/assets/js/211396ae.de404557.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3616],{394:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>r,contentTitle:()=>a,default:()=>u,frontMatter:()=>s,metadata:()=>d,toc:()=>c});var o=n(5893),i=n(1151);const s={title:"Cloud Watch Logs"},a=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-watch-logs.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},r={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchlogs.html",children:"Using Lambda with CloudWatch Logs"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function u(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>d,a:()=>a});var o=n(7294);const i={},s=o.createContext(i);function a(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3616],{394:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>r,contentTitle:()=>a,default:()=>u,frontMatter:()=>s,metadata:()=>d,toc:()=>c});var o=n(5893),i=n(1151);const s={title:"Cloud Watch Logs"},a=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-watch-logs.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},r={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchlogs.html",children:"Using Lambda with CloudWatch Logs"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function u(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>d,a:()=>a});var o=n(7294);const i={},s=o.createContext(i);function a(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/24a252b9.8e7b66d3.js b/assets/js/24a252b9.11b9a990.js similarity index 99% rename from assets/js/24a252b9.8e7b66d3.js rename to assets/js/24a252b9.11b9a990.js index 478a313bb..7f7df5d5d 100644 --- a/assets/js/24a252b9.8e7b66d3.js +++ b/assets/js/24a252b9.11b9a990.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1098],{8500:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>h,frontMatter:()=>o,metadata:()=>u,toc:()=>d});var r=n(5893),a=n(1151),l=n(4866),s=n(5162);const o={title:"input-output-logger"},i=void 0,u={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/input-output-logger.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.p,{children:"Logs the incoming request (input) and the response (output)."}),"\n",(0,r.jsxs)(t.p,{children:["By default, the logging operate by using the ",(0,r.jsx)(t.code,{children:"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."]}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(s.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/input-output-logger\n"})})}),(0,r.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/input-output-logger\n"})})}),(0,r.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/input-output-logger\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"logger"})," function (default ",(0,r.jsx)(t.code,{children:"console.log"}),"): logging function that accepts an object"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"awsContext"})," boolean (default ",(0,r.jsx)(t.code,{children:"false"}),"): Include ",(0,r.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html",children:"AWS Lambda context object"})," to the logger"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"omitPaths"})," string[] (default ",(0,r.jsx)(t.code,{children:"[]"}),"): 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,r.jsx)(t.code,{children:"name"}),", ",(0,r.jsx)(t.code,{children:"user.name"}),", ",(0,r.jsx)(t.code,{children:"users.[].name"})]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"mask"})," string: String to replace omitted values with. Example: ",(0,r.jsx)(t.code,{children:"***omitted***"})]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"replacer"})," function: stringify ",(0,r.jsx)(t.code,{children:"replacer"})," function"]}),"\n"]}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport inputOutputLogger from '@middy/input-output-logger'\n\nconst lambdaHandler = (event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n return response\n}\n\nexport const handler = middy().use(inputOutputLogger()).handler(lambdaHandler)\n"})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport inputOutputLogger from '@middy/input-output-logger'\nimport pino from 'pino'\n\nconst logger = pino()\n\nconst lambdaHandler = (event, context) => {\n // ...\n return response\n}\n\nexport const handler = middy()\n .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 .handler(lambdaHandler)\n"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>s});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var l=n(5893);function s(e){let{children:t,hidden:n,className:s}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,s),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7294),a=n(6010),l=n(2466),s=n(6550),o=n(469),i=n(1980),u=n(7392),c=n(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(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 h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(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,i._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 g(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(!h({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}))),[u,d]=m({queryString:n,groupId:a}),[g,f]=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}),b=(()=>{const e=u??g;return h({value:e,tabValues:l})?e:null})();(0,o.Z)((()=>{b&&i(b)}),[b]);return{selectedValue:s,selectValue:(0,r.useCallback)((e=>{if(!h({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 f=n(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=n(5893);function v(e){let{className:t,block:n,selectedValue:r,selectValue:s,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,l.o5)(),c=e=>{const t=e.currentTarget,n=i.indexOf(t),a=o[n].value;a!==r&&(u(t),s(a))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:l}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:d,onClick:c,...l,className:(0,a.Z)("tabs__item",b.tabItem,l?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function j(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(0,x.jsx)("div",{className:"margin-top--md",children:l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=g(e);return(0,x.jsxs)("div",{className:(0,a.Z)("tabs-container",b.tabList),children:[(0,x.jsx)(v,{...e,...t}),(0,x.jsx)(j,{...e,...t})]})}function w(e){const t=(0,f.Z)();return(0,x.jsx)(y,{...e,children:d(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>o,a:()=>s});var r=n(7294);const a={},l=r.createContext(a);function s(e){const t=r.useContext(l);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:s(e.components),r.createElement(l.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1098],{8500:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>h,frontMatter:()=>o,metadata:()=>u,toc:()=>d});var r=n(5893),a=n(1151),l=n(4866),s=n(5162);const o={title:"input-output-logger"},i=void 0,u={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/input-output-logger.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.p,{children:"Logs the incoming request (input) and the response (output)."}),"\n",(0,r.jsxs)(t.p,{children:["By default, the logging operate by using the ",(0,r.jsx)(t.code,{children:"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."]}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(s.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/input-output-logger\n"})})}),(0,r.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/input-output-logger\n"})})}),(0,r.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/input-output-logger\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"logger"})," function (default ",(0,r.jsx)(t.code,{children:"console.log"}),"): logging function that accepts an object"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"awsContext"})," boolean (default ",(0,r.jsx)(t.code,{children:"false"}),"): Include ",(0,r.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html",children:"AWS Lambda context object"})," to the logger"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"omitPaths"})," string[] (default ",(0,r.jsx)(t.code,{children:"[]"}),"): 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,r.jsx)(t.code,{children:"name"}),", ",(0,r.jsx)(t.code,{children:"user.name"}),", ",(0,r.jsx)(t.code,{children:"users.[].name"})]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"mask"})," string: String to replace omitted values with. Example: ",(0,r.jsx)(t.code,{children:"***omitted***"})]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"replacer"})," function: stringify ",(0,r.jsx)(t.code,{children:"replacer"})," function"]}),"\n"]}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport inputOutputLogger from '@middy/input-output-logger'\n\nconst lambdaHandler = (event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n return response\n}\n\nexport const handler = middy().use(inputOutputLogger()).handler(lambdaHandler)\n"})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport inputOutputLogger from '@middy/input-output-logger'\nimport pino from 'pino'\n\nconst logger = pino()\n\nconst lambdaHandler = (event, context) => {\n // ...\n return response\n}\n\nexport const handler = middy()\n .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 .handler(lambdaHandler)\n"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>s});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var l=n(5893);function s(e){let{children:t,hidden:n,className:s}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,s),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7294),a=n(6010),l=n(2466),s=n(6550),o=n(469),i=n(1980),u=n(7392),c=n(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(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 h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(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,i._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 g(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(!h({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}))),[u,d]=m({queryString:n,groupId:a}),[g,f]=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}),b=(()=>{const e=u??g;return h({value:e,tabValues:l})?e:null})();(0,o.Z)((()=>{b&&i(b)}),[b]);return{selectedValue:s,selectValue:(0,r.useCallback)((e=>{if(!h({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 f=n(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=n(5893);function v(e){let{className:t,block:n,selectedValue:r,selectValue:s,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,l.o5)(),c=e=>{const t=e.currentTarget,n=i.indexOf(t),a=o[n].value;a!==r&&(u(t),s(a))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:l}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:d,onClick:c,...l,className:(0,a.Z)("tabs__item",b.tabItem,l?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function j(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(0,x.jsx)("div",{className:"margin-top--md",children:l.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=g(e);return(0,x.jsxs)("div",{className:(0,a.Z)("tabs-container",b.tabList),children:[(0,x.jsx)(v,{...e,...t}),(0,x.jsx)(j,{...e,...t})]})}function w(e){const t=(0,f.Z)();return(0,x.jsx)(y,{...e,children:d(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>o,a:()=>s});var r=n(7294);const a={},l=r.createContext(a);function s(e){const t=r.useContext(l);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:s(e.components),r.createElement(l.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/28b74e92.a703bf53.js b/assets/js/28b74e92.bb238143.js similarity index 97% rename from assets/js/28b74e92.a703bf53.js rename to assets/js/28b74e92.bb238143.js index 6840dc40e..3d4246208 100644 --- a/assets/js/28b74e92.a703bf53.js +++ b/assets/js/28b74e92.bb238143.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3839],{7978:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>u,frontMatter:()=>a,metadata:()=>r,toc:()=>l});var o=n(5893),i=n(1151);const a={title:"CloudTrail"},s=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-trail.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-cloudtrail.html",children:"Using AWS Lambda with AWS CloudTrail"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>s});var o=n(7294);const i={},a=o.createContext(i);function s(e){const t=o.useContext(a);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),o.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3839],{7978:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>u,frontMatter:()=>a,metadata:()=>r,toc:()=>l});var o=n(5893),i=n(1151);const a={title:"CloudTrail"},s=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-trail.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-cloudtrail.html",children:"Using AWS Lambda with AWS CloudTrail"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>s});var o=n(7294);const i={},a=o.createContext(i);function s(e){const t=o.useContext(a);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),o.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2b234cfe.881f7894.js b/assets/js/2b234cfe.debebe6c.js similarity index 97% rename from assets/js/2b234cfe.881f7894.js rename to assets/js/2b234cfe.debebe6c.js index ec7e2715b..8e1020343 100644 --- a/assets/js/2b234cfe.881f7894.js +++ b/assets/js/2b234cfe.debebe6c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9158],{1910:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>r,metadata:()=>o,toc:()=>d});var s=n(5893),a=n(1151);const r={title:"Secrets Manager"},i=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/secrets-manager.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Secrets Manager"},sidebar:"tutorialSidebar",previous:{title:"S3",permalink:"/docs/events/s3"},next:{title:"SES",permalink:"/docs/events/ses"}},c={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-secrets-manager.html",children:"Using AWS Lambda with Secrets Manager"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>o,a:()=>i});var s=n(7294);const a={},r=s.createContext(a);function i(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:i(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9158],{1910:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>r,metadata:()=>o,toc:()=>d});var s=n(5893),a=n(1151);const r={title:"Secrets Manager"},i=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/secrets-manager.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Secrets Manager"},sidebar:"tutorialSidebar",previous:{title:"S3",permalink:"/docs/events/s3"},next:{title:"SES",permalink:"/docs/events/ses"}},c={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-secrets-manager.html",children:"Using AWS Lambda with Secrets Manager"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>o,a:()=>i});var s=n(7294);const a={},r=s.createContext(a);function i(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:i(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2e6cdb22.ba5d7686.js b/assets/js/2e6cdb22.6bf171b7.js similarity index 99% rename from assets/js/2e6cdb22.ba5d7686.js rename to assets/js/2e6cdb22.6bf171b7.js index f2dd2c816..756365fb0 100644 --- a/assets/js/2e6cdb22.ba5d7686.js +++ b/assets/js/2e6cdb22.6bf171b7.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5774],{4919:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>m,frontMatter:()=>i,metadata:()=>d,toc:()=>u});var s=t(5893),a=t(1151),r=t(4866),l=t(5162);const i={title:"ws-response"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/ws-response.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{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}];function p(e){const n={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Post message to WebSocket connection."}),"\n",(0,s.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(r.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(l.Z,{value:"npm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/ws-response\nnpm install --save-dev @aws-sdk/client-apigatewaymanagementapi\n"})})}),(0,s.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/ws-response\nyarn add --dev @aws-sdk/client-apigatewaymanagementapi\n"})})}),(0,s.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/ws-response\npnpm add --save-dev @aws-sdk/client-apigatewaymanagementapi\n"})})})]}),"\n",(0,s.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(n.code,{children:"ApiGatewayManagementApiClient"}),"): ApiGatewayManagementApi class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-apigatewaymanagementapi"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientOptions"})," (object) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Options to pass to ApiGatewayManagementApiClient class constructor."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," (string) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Internal key where secrets are stored. See ",(0,s.jsx)(n.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientCapture"})," (function) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Enable XRay by passing ",(0,s.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,s.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(n.code,{children:"execute-api:ManageConnections"})]}),"\n",(0,s.jsxs)(n.li,{children:["If ",(0,s.jsx)(n.code,{children:"awsClientOptions.endpoint"})," is not set it will be set using ",(0,s.jsx)(n.code,{children:"event.requestContext.{domainName,stage}"})]}),"\n",(0,s.jsxs)(n.li,{children:["If response does not contain ",(0,s.jsx)(n.code,{children:"ConnectId"}),", it will be set from ",(0,s.jsx)(n.code,{children:"event.requestContext.connectionId"})]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(n.h3,{id:"api-gateway",children:"API Gateway"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"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"})}),"\n",(0,s.jsx)(n.h3,{id:"general",children:"General"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport wsResponse from '@middy/ws-response'\n\nconst lambdaHandler = (event, context) => {\n return {\n ConnectionId: '...',\n Data: 'message'\n }\n}\n\nexport const handler = middy()\n .use(\n wsResponse({\n awsClientOptions: {\n endpoint: '...'\n }\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(n.p,{children:["To exclude ",(0,s.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-apigatewaymanagementapi"})," to the exclude list."]})]})}function m(e={}){const{wrapper:n}={...(0,a.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(p,{...e})}):p(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>l});t(7294);var s=t(6010);const a={tabItem:"tabItem_Ymn6"};var r=t(5893);function l(e){let{children:n,hidden:t,className:l}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.Z)(a.tabItem,l),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>y});var s=t(7294),a=t(6010),r=t(2466),l=t(6550),i=t(469),o=t(1980),d=t(7392),c=t(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function p(e){const{values:n,children:t}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:s,default:a}}=e;return{value:n,label:t,attributes:s,default:a}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function m(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function h(e){let{queryString:n=!1,groupId:t}=e;const a=(0,l.k6)(),r=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(r),(0,s.useCallback)((e=>{if(!r)return;const n=new URLSearchParams(a.location.search);n.set(r,e),a.replace({...a.location,search:n.toString()})}),[r,a])]}function f(e){const{defaultValue:n,queryString:t=!1,groupId:a}=e,r=p(e),[l,o]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const s=t.find((e=>e.default))??t[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:r}))),[d,u]=h({queryString:t,groupId:a}),[f,b]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[a,r]=(0,c.Nk)(t);return[a,(0,s.useCallback)((e=>{t&&r.set(e)}),[t,r])]}({groupId:a}),x=(()=>{const e=d??f;return m({value:e,tabValues:r})?e:null})();(0,i.Z)((()=>{x&&o(x)}),[x]);return{selectedValue:l,selectValue:(0,s.useCallback)((e=>{if(!m({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,r]),tabValues:r}}var b=t(2389);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var w=t(5893);function g(e){let{className:n,block:t,selectedValue:s,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,r.o5)(),c=e=>{const n=e.currentTarget,t=o.indexOf(n),a=i[t].value;a!==s&&(d(n),l(a))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,w.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":t},n),children:i.map((e=>{let{value:n,label:t,attributes:r}=e;return(0,w.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...r,className:(0,a.Z)("tabs__item",x.tabItem,r?.className,{"tabs__item--active":s===n}),children:t??n},n)}))})}function v(e){let{lazy:n,children:t,selectedValue:a}=e;const r=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=r.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,w.jsx)("div",{className:"margin-top--md",children:r.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==a})))})}function j(e){const n=f(e);return(0,w.jsxs)("div",{className:(0,a.Z)("tabs-container",x.tabList),children:[(0,w.jsx)(g,{...e,...n}),(0,w.jsx)(v,{...e,...n})]})}function y(e){const n=(0,b.Z)();return(0,w.jsx)(j,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>l});var s=t(7294);const a={},r=s.createContext(a);function l(e){const n=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),s.createElement(r.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5774],{4919:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>m,frontMatter:()=>i,metadata:()=>d,toc:()=>u});var s=t(5893),a=t(1151),r=t(4866),l=t(5162);const i={title:"ws-response"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/ws-response.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{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}];function p(e){const n={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Post message to WebSocket connection."}),"\n",(0,s.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(r.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(l.Z,{value:"npm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/ws-response\nnpm install --save-dev @aws-sdk/client-apigatewaymanagementapi\n"})})}),(0,s.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/ws-response\nyarn add --dev @aws-sdk/client-apigatewaymanagementapi\n"})})}),(0,s.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/ws-response\npnpm add --save-dev @aws-sdk/client-apigatewaymanagementapi\n"})})})]}),"\n",(0,s.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(n.code,{children:"ApiGatewayManagementApiClient"}),"): ApiGatewayManagementApi class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-apigatewaymanagementapi"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientOptions"})," (object) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Options to pass to ApiGatewayManagementApiClient class constructor."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," (string) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Internal key where secrets are stored. See ",(0,s.jsx)(n.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientCapture"})," (function) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Enable XRay by passing ",(0,s.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,s.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(n.code,{children:"execute-api:ManageConnections"})]}),"\n",(0,s.jsxs)(n.li,{children:["If ",(0,s.jsx)(n.code,{children:"awsClientOptions.endpoint"})," is not set it will be set using ",(0,s.jsx)(n.code,{children:"event.requestContext.{domainName,stage}"})]}),"\n",(0,s.jsxs)(n.li,{children:["If response does not contain ",(0,s.jsx)(n.code,{children:"ConnectId"}),", it will be set from ",(0,s.jsx)(n.code,{children:"event.requestContext.connectionId"})]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(n.h3,{id:"api-gateway",children:"API Gateway"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"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"})}),"\n",(0,s.jsx)(n.h3,{id:"general",children:"General"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport wsResponse from '@middy/ws-response'\n\nconst lambdaHandler = (event, context) => {\n return {\n ConnectionId: '...',\n Data: 'message'\n }\n}\n\nexport const handler = middy()\n .use(\n wsResponse({\n awsClientOptions: {\n endpoint: '...'\n }\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(n.p,{children:["To exclude ",(0,s.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-apigatewaymanagementapi"})," to the exclude list."]})]})}function m(e={}){const{wrapper:n}={...(0,a.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(p,{...e})}):p(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>l});t(7294);var s=t(6010);const a={tabItem:"tabItem_Ymn6"};var r=t(5893);function l(e){let{children:n,hidden:t,className:l}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.Z)(a.tabItem,l),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>y});var s=t(7294),a=t(6010),r=t(2466),l=t(6550),i=t(469),o=t(1980),d=t(7392),c=t(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function p(e){const{values:n,children:t}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:s,default:a}}=e;return{value:n,label:t,attributes:s,default:a}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function m(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function h(e){let{queryString:n=!1,groupId:t}=e;const a=(0,l.k6)(),r=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(r),(0,s.useCallback)((e=>{if(!r)return;const n=new URLSearchParams(a.location.search);n.set(r,e),a.replace({...a.location,search:n.toString()})}),[r,a])]}function f(e){const{defaultValue:n,queryString:t=!1,groupId:a}=e,r=p(e),[l,o]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const s=t.find((e=>e.default))??t[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:r}))),[d,u]=h({queryString:t,groupId:a}),[f,b]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[a,r]=(0,c.Nk)(t);return[a,(0,s.useCallback)((e=>{t&&r.set(e)}),[t,r])]}({groupId:a}),x=(()=>{const e=d??f;return m({value:e,tabValues:r})?e:null})();(0,i.Z)((()=>{x&&o(x)}),[x]);return{selectedValue:l,selectValue:(0,s.useCallback)((e=>{if(!m({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,r]),tabValues:r}}var b=t(2389);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var w=t(5893);function g(e){let{className:n,block:t,selectedValue:s,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,r.o5)(),c=e=>{const n=e.currentTarget,t=o.indexOf(n),a=i[t].value;a!==s&&(d(n),l(a))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,w.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":t},n),children:i.map((e=>{let{value:n,label:t,attributes:r}=e;return(0,w.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...r,className:(0,a.Z)("tabs__item",x.tabItem,r?.className,{"tabs__item--active":s===n}),children:t??n},n)}))})}function v(e){let{lazy:n,children:t,selectedValue:a}=e;const r=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=r.find((e=>e.props.value===a));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,w.jsx)("div",{className:"margin-top--md",children:r.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==a})))})}function j(e){const n=f(e);return(0,w.jsxs)("div",{className:(0,a.Z)("tabs-container",x.tabList),children:[(0,w.jsx)(g,{...e,...n}),(0,w.jsx)(v,{...e,...n})]})}function y(e){const n=(0,b.Z)();return(0,w.jsx)(j,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>l});var s=t(7294);const a={},r=s.createContext(a);function l(e){const n=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),s.createElement(r.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2f4f2e7a.ef75f68a.js b/assets/js/2f4f2e7a.7f1b6a60.js similarity index 97% rename from assets/js/2f4f2e7a.ef75f68a.js rename to assets/js/2f4f2e7a.7f1b6a60.js index 04a334422..1077b35ef 100644 --- a/assets/js/2f4f2e7a.ef75f68a.js +++ b/assets/js/2f4f2e7a.7f1b6a60.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5222],{1950:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>s,default:()=>u,frontMatter:()=>o,metadata:()=>r,toc:()=>d});var a=n(5893),i=n(1151);const o={title:"Alexa"},s=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/alexa.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},l={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(t.admonition,{type:"caution",children:(0,a.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,a.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsx)(t.li,{children:(0,a.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-alexa.html",children:"Using AWS Lambda with Alexa"})}),"\n"]}),"\n",(0,a.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>s});var a=n(7294);const i={},o=a.createContext(i);function s(e){const t=a.useContext(o);return a.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),a.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5222],{1950:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>s,default:()=>u,frontMatter:()=>o,metadata:()=>r,toc:()=>d});var a=n(5893),i=n(1151);const o={title:"Alexa"},s=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/alexa.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},l={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(t.admonition,{type:"caution",children:(0,a.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,a.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsx)(t.li,{children:(0,a.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-alexa.html",children:"Using AWS Lambda with Alexa"})}),"\n"]}),"\n",(0,a.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>s});var a=n(7294);const i={},o=a.createContext(i);function s(e){const t=a.useContext(o);return a.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),a.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/340d0816.b964de2f.js b/assets/js/340d0816.812eb84b.js similarity index 97% rename from assets/js/340d0816.b964de2f.js rename to assets/js/340d0816.812eb84b.js index de6bc2a45..01df973e0 100644 --- a/assets/js/340d0816.b964de2f.js +++ b/assets/js/340d0816.812eb84b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8729],{9571:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>s,metadata:()=>r,toc:()=>l});var i=n(5893),o=n(1151);const s={title:"MQ"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/mq.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"MQ"},sidebar:"tutorialSidebar",previous:{title:"Lex",permalink:"/docs/events/lex"},next:{title:"RDS",permalink:"/docs/events/rds"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.admonition,{type:"caution",children:(0,i.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:(0,i.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-mq.html",children:"Using Lambda with Amazon MQ"})}),"\n"]}),"\n",(0,i.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var i=n(7294);const o={},s=i.createContext(o);function a(e){const t=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),i.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8729],{9571:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>s,metadata:()=>r,toc:()=>l});var i=n(5893),o=n(1151);const s={title:"MQ"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/mq.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"MQ"},sidebar:"tutorialSidebar",previous:{title:"Lex",permalink:"/docs/events/lex"},next:{title:"RDS",permalink:"/docs/events/rds"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.admonition,{type:"caution",children:(0,i.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:(0,i.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-mq.html",children:"Using Lambda with Amazon MQ"})}),"\n"]}),"\n",(0,i.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var i=n(7294);const o={},s=i.createContext(o);function a(e){const t=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),i.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/34ad80cb.2d1ee7d2.js b/assets/js/34ad80cb.8affa5e4.js similarity index 97% rename from assets/js/34ad80cb.2d1ee7d2.js rename to assets/js/34ad80cb.8affa5e4.js index e4f013c29..6d3954eb6 100644 --- a/assets/js/34ad80cb.2d1ee7d2.js +++ b/assets/js/34ad80cb.8affa5e4.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4662],{9061:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>d,default:()=>u,frontMatter:()=>i,metadata:()=>r,toc:()=>l});var o=n(5893),a=n(1151);const i={title:"CloudFront Lambda@Edge"},d=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-front.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"CloudFront Lambda@Edge"},sidebar:"tutorialSidebar",previous:{title:"CloudFormation",permalink:"/docs/events/cloud-formation"},next:{title:"CloudTrail",permalink:"/docs/events/cloud-trail"}},s={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html",children:"Using AWS Lambda with CloudFront Lambda@Edge"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function u(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>d});var o=n(7294);const a={},i=o.createContext(a);function d(e){const t=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:d(e.components),o.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4662],{9061:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>d,default:()=>u,frontMatter:()=>i,metadata:()=>r,toc:()=>l});var o=n(5893),a=n(1151);const i={title:"CloudFront Lambda@Edge"},d=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-front.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"CloudFront Lambda@Edge"},sidebar:"tutorialSidebar",previous:{title:"CloudFormation",permalink:"/docs/events/cloud-formation"},next:{title:"CloudTrail",permalink:"/docs/events/cloud-trail"}},s={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html",children:"Using AWS Lambda with CloudFront Lambda@Edge"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function u(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>d});var o=n(7294);const a={},i=o.createContext(a);function d(e){const t=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:d(e.components),o.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/34ebece8.76fec6af.js b/assets/js/34ebece8.aeb8ae42.js similarity index 97% rename from assets/js/34ebece8.76fec6af.js rename to assets/js/34ebece8.aeb8ae42.js index 80cfdc10d..6e95ba948 100644 --- a/assets/js/34ebece8.76fec6af.js +++ b/assets/js/34ebece8.aeb8ae42.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5853],{2900:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>m,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var i=n(5893),o=n(1151);const a={title:"WorkMail"},r=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/workmail.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"WorkMail"},sidebar:"tutorialSidebar",previous:{title:"VPC Lattice",permalink:"/docs/events/vpc-lattice"},next:{title:"Integrations",permalink:"/docs/category/integrations"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.admonition,{type:"caution",children:(0,i.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:(0,i.jsx)(t.a,{href:"https://docs.aws.amazon.com/workmail/latest/adminguide/lambda.html",children:"Configuring AWS Lambda for Amazon WorkMail"})}),"\n"]}),"\n",(0,i.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>s,a:()=>r});var i=n(7294);const o={},a=i.createContext(o);function r(e){const t=i.useContext(a);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),i.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5853],{2900:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>m,frontMatter:()=>a,metadata:()=>s,toc:()=>l});var i=n(5893),o=n(1151);const a={title:"WorkMail"},r=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/workmail.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"WorkMail"},sidebar:"tutorialSidebar",previous:{title:"VPC Lattice",permalink:"/docs/events/vpc-lattice"},next:{title:"Integrations",permalink:"/docs/category/integrations"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.admonition,{type:"caution",children:(0,i.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:(0,i.jsx)(t.a,{href:"https://docs.aws.amazon.com/workmail/latest/adminguide/lambda.html",children:"Configuring AWS Lambda for Amazon WorkMail"})}),"\n"]}),"\n",(0,i.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>s,a:()=>r});var i=n(7294);const o={},a=i.createContext(o);function r(e){const t=i.useContext(a);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),i.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/3673b941.491936f4.js b/assets/js/3673b941.88ac9ec8.js similarity index 99% rename from assets/js/3673b941.491936f4.js rename to assets/js/3673b941.88ac9ec8.js index 018470fed..80f96ab27 100644 --- a/assets/js/3673b941.491936f4.js +++ b/assets/js/3673b941.88ac9ec8.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2344],{7017:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>p,frontMatter:()=>i,metadata:()=>d,toc:()=>u});var s=r(5893),t=r(1151),a=r(4866),l=r(5162);const i={title:"rds-signer"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/rds-signer.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{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}];function h(e){const n={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,t.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Fetches RDS credentials to be used when connecting to RDS with IAM roles."}),"\n",(0,s.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(l.Z,{value:"npm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/rds-signer\nnpm install --save-dev @aws-sdk/rds-signer\n"})})}),(0,s.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/rds-signer\nyarn add --dev @aws-sdk/rds-signer\n"})})}),(0,s.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/rds-signer\npnpm add --save-dev @aws-sdk/rds-signer\n"})})})]}),"\n",(0,s.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(n.code,{children:"Signer"}),"): Signer class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(n.code,{children:"@aws-sdk/rds-signer"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientOptions"})," (object) (optional): Options to pass to Signer class constructor."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameters."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheKey"})," (string) (default ",(0,s.jsx)(n.code,{children:"rds-signer"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheExpiry"})," (number) (default ",(0,s.jsx)(n.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,s.jsx)(n.code,{children:"-1"}),": cache forever, ",(0,s.jsx)(n.code,{children:"0"}),": never cache, ",(0,s.jsx)(n.code,{children:"n"}),": cache for n ms."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"setToContext"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): Store role tokens to ",(0,s.jsx)(n.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(n.code,{children:"rds-db:connect"})," with a resource like ",(0,s.jsx)(n.code,{children:"arn:aws:rds-db:#{AWS::Region}:#{AWS::AccountId}:dbuser:${database_resource}/${iam_role}"})]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport rdsSigner from '@middy/rds-signer'\n\nconst lambdaHandler = (event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n}\n\nexport const handler = middy()\n .use(\n rdsSigner({\n fetchData: {\n rdsToken: {\n region: 'ca-central-1',\n hostname: '***.rds.amazonaws.com',\n username: 'iam_role',\n port: 5432\n }\n }\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(n.p,{children:["To exclude ",(0,s.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(n.code,{children:"@aws-sdk/rds-signer"})," to the exclude list."]})]})}function p(e={}){const{wrapper:n}={...(0,t.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},5162:(e,n,r)=>{r.d(n,{Z:()=>l});r(7294);var s=r(6010);const t={tabItem:"tabItem_Ymn6"};var a=r(5893);function l(e){let{children:n,hidden:r,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.Z)(t.tabItem,l),hidden:r,children:n})}},4866:(e,n,r)=>{r.d(n,{Z:()=>y});var s=r(7294),t=r(6010),a=r(2466),l=r(6550),i=r(469),o=r(1980),d=r(7392),c=r(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:r}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:r,attributes:s,default:t}}=e;return{value:n,label:r,attributes:s,default:t}}))}(r);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,r])}function p(e){let{value:n,tabValues:r}=e;return r.some((e=>e.value===n))}function m(e){let{queryString:n=!1,groupId:r}=e;const t=(0,l.k6)(),a=function(e){let{queryString:n=!1,groupId:r}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!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:n,groupId:r});return[(0,o._X)(a),(0,s.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(t.location.search);n.set(a,e),t.replace({...t.location,search:n.toString()})}),[a,t])]}function b(e){const{defaultValue:n,queryString:r=!1,groupId:t}=e,a=h(e),[l,o]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" 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 n}const s=r.find((e=>e.default))??r[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:a}))),[d,u]=m({queryString:r,groupId:t}),[b,f]=function(e){let{groupId:n}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(n),[t,a]=(0,c.Nk)(r);return[t,(0,s.useCallback)((e=>{r&&a.set(e)}),[r,a])]}({groupId:t}),g=(()=>{const e=d??b;return p({value:e,tabValues:a})?e:null})();(0,i.Z)((()=>{g&&o(g)}),[g]);return{selectedValue:l,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),f(e)}),[u,f,a]),tabValues:a}}var f=r(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=r(5893);function j(e){let{className:n,block:r,selectedValue:s,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,a.o5)(),c=e=>{const n=e.currentTarget,r=o.indexOf(n),t=i[r].value;t!==s&&(d(n),l(t))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const r=o.indexOf(e.currentTarget)+1;n=o[r]??o[0];break}case"ArrowLeft":{const r=o.indexOf(e.currentTarget)-1;n=o[r]??o[o.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,t.Z)("tabs",{"tabs--block":r},n),children:i.map((e=>{let{value:n,label:r,attributes:a}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...a,className:(0,t.Z)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":s===n}),children:r??n},n)}))})}function v(e){let{lazy:n,children:r,selectedValue:t}=e;const a=(Array.isArray(r)?r:[r]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===t));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==t})))})}function w(e){const n=b(e);return(0,x.jsxs)("div",{className:(0,t.Z)("tabs-container",g.tabList),children:[(0,x.jsx)(j,{...e,...n}),(0,x.jsx)(v,{...e,...n})]})}function y(e){const n=(0,f.Z)();return(0,x.jsx)(w,{...e,children:u(e.children)},String(n))}},1151:(e,n,r)=>{r.d(n,{Z:()=>i,a:()=>l});var s=r(7294);const t={},a=s.createContext(t);function l(e){const n=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:l(e.components),s.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2344],{7017:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>p,frontMatter:()=>i,metadata:()=>d,toc:()=>u});var s=r(5893),t=r(1151),a=r(4866),l=r(5162);const i={title:"rds-signer"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/rds-signer.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{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}];function h(e){const n={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,t.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Fetches RDS credentials to be used when connecting to RDS with IAM roles."}),"\n",(0,s.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(l.Z,{value:"npm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/rds-signer\nnpm install --save-dev @aws-sdk/rds-signer\n"})})}),(0,s.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/rds-signer\nyarn add --dev @aws-sdk/rds-signer\n"})})}),(0,s.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/rds-signer\npnpm add --save-dev @aws-sdk/rds-signer\n"})})})]}),"\n",(0,s.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(n.code,{children:"Signer"}),"): Signer class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(n.code,{children:"@aws-sdk/rds-signer"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientOptions"})," (object) (optional): Options to pass to Signer class constructor."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameters."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheKey"})," (string) (default ",(0,s.jsx)(n.code,{children:"rds-signer"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheExpiry"})," (number) (default ",(0,s.jsx)(n.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,s.jsx)(n.code,{children:"-1"}),": cache forever, ",(0,s.jsx)(n.code,{children:"0"}),": never cache, ",(0,s.jsx)(n.code,{children:"n"}),": cache for n ms."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"setToContext"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): Store role tokens to ",(0,s.jsx)(n.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(n.code,{children:"rds-db:connect"})," with a resource like ",(0,s.jsx)(n.code,{children:"arn:aws:rds-db:#{AWS::Region}:#{AWS::AccountId}:dbuser:${database_resource}/${iam_role}"})]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport rdsSigner from '@middy/rds-signer'\n\nconst lambdaHandler = (event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n}\n\nexport const handler = middy()\n .use(\n rdsSigner({\n fetchData: {\n rdsToken: {\n region: 'ca-central-1',\n hostname: '***.rds.amazonaws.com',\n username: 'iam_role',\n port: 5432\n }\n }\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(n.p,{children:["To exclude ",(0,s.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(n.code,{children:"@aws-sdk/rds-signer"})," to the exclude list."]})]})}function p(e={}){const{wrapper:n}={...(0,t.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},5162:(e,n,r)=>{r.d(n,{Z:()=>l});r(7294);var s=r(6010);const t={tabItem:"tabItem_Ymn6"};var a=r(5893);function l(e){let{children:n,hidden:r,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.Z)(t.tabItem,l),hidden:r,children:n})}},4866:(e,n,r)=>{r.d(n,{Z:()=>y});var s=r(7294),t=r(6010),a=r(2466),l=r(6550),i=r(469),o=r(1980),d=r(7392),c=r(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:r}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:r,attributes:s,default:t}}=e;return{value:n,label:r,attributes:s,default:t}}))}(r);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,r])}function p(e){let{value:n,tabValues:r}=e;return r.some((e=>e.value===n))}function m(e){let{queryString:n=!1,groupId:r}=e;const t=(0,l.k6)(),a=function(e){let{queryString:n=!1,groupId:r}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!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:n,groupId:r});return[(0,o._X)(a),(0,s.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(t.location.search);n.set(a,e),t.replace({...t.location,search:n.toString()})}),[a,t])]}function b(e){const{defaultValue:n,queryString:r=!1,groupId:t}=e,a=h(e),[l,o]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" 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 n}const s=r.find((e=>e.default))??r[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:a}))),[d,u]=m({queryString:r,groupId:t}),[b,f]=function(e){let{groupId:n}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(n),[t,a]=(0,c.Nk)(r);return[t,(0,s.useCallback)((e=>{r&&a.set(e)}),[r,a])]}({groupId:t}),g=(()=>{const e=d??b;return p({value:e,tabValues:a})?e:null})();(0,i.Z)((()=>{g&&o(g)}),[g]);return{selectedValue:l,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),f(e)}),[u,f,a]),tabValues:a}}var f=r(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=r(5893);function j(e){let{className:n,block:r,selectedValue:s,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,a.o5)(),c=e=>{const n=e.currentTarget,r=o.indexOf(n),t=i[r].value;t!==s&&(d(n),l(t))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const r=o.indexOf(e.currentTarget)+1;n=o[r]??o[0];break}case"ArrowLeft":{const r=o.indexOf(e.currentTarget)-1;n=o[r]??o[o.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,t.Z)("tabs",{"tabs--block":r},n),children:i.map((e=>{let{value:n,label:r,attributes:a}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...a,className:(0,t.Z)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":s===n}),children:r??n},n)}))})}function v(e){let{lazy:n,children:r,selectedValue:t}=e;const a=(Array.isArray(r)?r:[r]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===t));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==t})))})}function w(e){const n=b(e);return(0,x.jsxs)("div",{className:(0,t.Z)("tabs-container",g.tabList),children:[(0,x.jsx)(j,{...e,...n}),(0,x.jsx)(v,{...e,...n})]})}function y(e){const n=(0,f.Z)();return(0,x.jsx)(w,{...e,children:u(e.children)},String(n))}},1151:(e,n,r)=>{r.d(n,{Z:()=>i,a:()=>l});var s=r(7294);const t={},a=s.createContext(t);function l(e){const n=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:l(e.components),s.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/3a74057e.9b8516e3.js b/assets/js/3a74057e.369850a5.js similarity index 96% rename from assets/js/3a74057e.9b8516e3.js rename to assets/js/3a74057e.369850a5.js index 095800e8e..8bb93684b 100644 --- a/assets/js/3a74057e.9b8516e3.js +++ b/assets/js/3a74057e.369850a5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[517],{8740:(t,e,n)=>{n.r(e),n.d(e,{assets:()=>d,contentTitle:()=>s,default:()=>u,frontMatter:()=>r,metadata:()=>a,toc:()=>c});var o=n(5893),i=n(1151);const r={title:"Pino"},s=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/pino.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[];function p(t){const e={admonition:"admonition",p:"p",...(0,i.a)(),...t.components};return(0,o.jsx)(e.admonition,{type:"caution",children:(0,o.jsx)(e.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})})}function u(t={}){const{wrapper:e}={...(0,i.a)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},1151:(t,e,n)=>{n.d(e,{Z:()=>a,a:()=>s});var o=n(7294);const i={},r=o.createContext(i);function s(t){const e=o.useContext(r);return o.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function a(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(i):t.components||i:s(t.components),o.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[517],{8740:(t,e,n)=>{n.r(e),n.d(e,{assets:()=>d,contentTitle:()=>s,default:()=>u,frontMatter:()=>r,metadata:()=>a,toc:()=>c});var o=n(5893),i=n(1151);const r={title:"Pino"},s=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/pino.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[];function p(t){const e={admonition:"admonition",p:"p",...(0,i.a)(),...t.components};return(0,o.jsx)(e.admonition,{type:"caution",children:(0,o.jsx)(e.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})})}function u(t={}){const{wrapper:e}={...(0,i.a)(),...t.components};return e?(0,o.jsx)(e,{...t,children:(0,o.jsx)(p,{...t})}):p(t)}},1151:(t,e,n)=>{n.d(e,{Z:()=>a,a:()=>s});var o=n(7294);const i={},r=o.createContext(i);function s(t){const e=o.useContext(r);return o.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function a(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(i):t.components||i:s(t.components),o.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/3db93d31.cc672540.js b/assets/js/3db93d31.42797b04.js similarity index 99% rename from assets/js/3db93d31.cc672540.js rename to assets/js/3db93d31.42797b04.js index 138a09ebb..ec346aa56 100644 --- a/assets/js/3db93d31.cc672540.js +++ b/assets/js/3db93d31.42797b04.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3631],{3252:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>h,frontMatter:()=>l,metadata:()=>d,toc:()=>c});var r=n(5893),a=n(1151),s=n(4866),o=n(5162);const l={title:"http-multipart-body-parser"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-multipart-body-parser.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={a:"a",br:"br",code:"code",em:"em",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["Automatically parses HTTP requests with content type ",(0,r.jsx)(t.code,{children:"multipart/form-data"})," and converts the body into an\nobject. Also handles gracefully broken JSON as ",(0,r.jsx)(t.em,{children:"Unsupported Media Type"})," (415 errors)\nif used in combination with ",(0,r.jsx)(t.code,{children:"httpErrorHandler"}),"."]}),"\n",(0,r.jsx)(t.p,{children:"It can also be used in combination with validator so that the content can be validated."}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.strong,{children:"Note"}),": by default this is going to parse only events that contain the header ",(0,r.jsx)(t.code,{children:"Content-Type"})," (or ",(0,r.jsx)(t.code,{children:"content-type"}),") set to ",(0,r.jsx)(t.code,{children:"multipart/form-data"}),". If you want to support different casing for the header name (e.g. ",(0,r.jsx)(t.code,{children:"Content-type"}),") then you should use the ",(0,r.jsx)(t.a,{href:"#httpheadernormalizer",children:(0,r.jsx)(t.code,{children:"httpHeaderNormalizer"})})," middleware before this middleware."]}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(o.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-multipart-body-parser\n"})})}),(0,r.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-multipart-body-parser\n"})})}),(0,r.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-multipart-body-parser\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"busboy"})," (",(0,r.jsx)(t.code,{children:"object"}),") (optional): defaults to ",(0,r.jsx)(t.code,{children:"{}"})," and it can be used to pass extraparameters to the internal ",(0,r.jsx)(t.code,{children:"busboy"})," instance at creation time. Checkout ",(0,r.jsx)(t.a,{href:"https://www.npmjs.com/package/busboy#busboy-methods",children:"the official documentation"})," for more information on the supported options."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"charset"})," (string) (default ",(0,r.jsx)(t.code,{children:"utf8"}),"): it can be used to change default charset."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"disableContentTypeError"})," (",(0,r.jsx)(t.code,{children:"boolean"}),") (optional): Skip throwing 415 when ",(0,r.jsx)(t.code,{children:"Content-Type"})," is invalid. Default: ",(0,r.jsx)(t.code,{children:"true"}),", will default to ",(0,r.jsx)(t.code,{children:"false"})," in next major version."]}),"\n"]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.strong,{children:"Note"}),": this middleware will buffer all the data as it is processed internally by ",(0,r.jsx)(t.code,{children:"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,r.jsx)(t.br,{}),"\n","If you really have to deal with big files, then you might also want to consider to allowing your users to ",(0,r.jsx)(t.a,{href:"https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-UsingHTTPPOST.html",children:"directly upload files to S3"})]}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpMultipartBodyParser from '@middy/http-multipart-body-parser'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .use(httpHeaderNormalizer())\n .use(httpMultipartBodyParser())\n .handler(lambdaHandler)\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"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>o});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,o),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7294),a=n(6010),s=n(2466),o=n(6550),l=n(469),i=n(1980),d=n(7392),u=n(12);function c(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(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 h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),s=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)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=p(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(!h({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:s}))),[d,c]=m({queryString:n,groupId:a}),[b,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,u.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),y=(()=>{const e=d??b;return h({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{y&&i(y)}),[y]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),f(e)}),[c,f,s]),tabValues:s}}var f=n(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(5893);function x(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),u=e=>{const t=e.currentTarget,n=i.indexOf(t),a=l[n].value;a!==r&&(d(t),o(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:c,onClick:u,...s,className:(0,a.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function j(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function g(e){const t=b(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",y.tabList),children:[(0,v.jsx)(x,{...e,...t}),(0,v.jsx)(j,{...e,...t})]})}function w(e){const t=(0,f.Z)();return(0,v.jsx)(g,{...e,children:c(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>l,a:()=>o});var r=n(7294);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3631],{3252:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>h,frontMatter:()=>l,metadata:()=>d,toc:()=>c});var r=n(5893),a=n(1151),s=n(4866),o=n(5162);const l={title:"http-multipart-body-parser"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-multipart-body-parser.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={a:"a",br:"br",code:"code",em:"em",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["Automatically parses HTTP requests with content type ",(0,r.jsx)(t.code,{children:"multipart/form-data"})," and converts the body into an\nobject. Also handles gracefully broken JSON as ",(0,r.jsx)(t.em,{children:"Unsupported Media Type"})," (415 errors)\nif used in combination with ",(0,r.jsx)(t.code,{children:"httpErrorHandler"}),"."]}),"\n",(0,r.jsx)(t.p,{children:"It can also be used in combination with validator so that the content can be validated."}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.strong,{children:"Note"}),": by default this is going to parse only events that contain the header ",(0,r.jsx)(t.code,{children:"Content-Type"})," (or ",(0,r.jsx)(t.code,{children:"content-type"}),") set to ",(0,r.jsx)(t.code,{children:"multipart/form-data"}),". If you want to support different casing for the header name (e.g. ",(0,r.jsx)(t.code,{children:"Content-type"}),") then you should use the ",(0,r.jsx)(t.a,{href:"#httpheadernormalizer",children:(0,r.jsx)(t.code,{children:"httpHeaderNormalizer"})})," middleware before this middleware."]}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(o.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-multipart-body-parser\n"})})}),(0,r.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-multipart-body-parser\n"})})}),(0,r.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-multipart-body-parser\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"busboy"})," (",(0,r.jsx)(t.code,{children:"object"}),") (optional): defaults to ",(0,r.jsx)(t.code,{children:"{}"})," and it can be used to pass extraparameters to the internal ",(0,r.jsx)(t.code,{children:"busboy"})," instance at creation time. Checkout ",(0,r.jsx)(t.a,{href:"https://www.npmjs.com/package/busboy#busboy-methods",children:"the official documentation"})," for more information on the supported options."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"charset"})," (string) (default ",(0,r.jsx)(t.code,{children:"utf8"}),"): it can be used to change default charset."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"disableContentTypeError"})," (",(0,r.jsx)(t.code,{children:"boolean"}),") (optional): Skip throwing 415 when ",(0,r.jsx)(t.code,{children:"Content-Type"})," is invalid. Default: ",(0,r.jsx)(t.code,{children:"true"}),", will default to ",(0,r.jsx)(t.code,{children:"false"})," in next major version."]}),"\n"]}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.strong,{children:"Note"}),": this middleware will buffer all the data as it is processed internally by ",(0,r.jsx)(t.code,{children:"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,r.jsx)(t.br,{}),"\n","If you really have to deal with big files, then you might also want to consider to allowing your users to ",(0,r.jsx)(t.a,{href:"https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-UsingHTTPPOST.html",children:"directly upload files to S3"})]}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpMultipartBodyParser from '@middy/http-multipart-body-parser'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .use(httpHeaderNormalizer())\n .use(httpMultipartBodyParser())\n .handler(lambdaHandler)\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"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>o});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,o),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7294),a=n(6010),s=n(2466),o=n(6550),l=n(469),i=n(1980),d=n(7392),u=n(12);function c(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(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 h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),s=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)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=p(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(!h({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:s}))),[d,c]=m({queryString:n,groupId:a}),[b,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,u.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),y=(()=>{const e=d??b;return h({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{y&&i(y)}),[y]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),f(e)}),[c,f,s]),tabValues:s}}var f=n(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(5893);function x(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),u=e=>{const t=e.currentTarget,n=i.indexOf(t),a=l[n].value;a!==r&&(d(t),o(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:c,onClick:u,...s,className:(0,a.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function j(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function g(e){const t=b(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",y.tabList),children:[(0,v.jsx)(x,{...e,...t}),(0,v.jsx)(j,{...e,...t})]})}function w(e){const t=(0,f.Z)();return(0,v.jsx)(g,{...e,children:c(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>l,a:()=>o});var r=n(7294);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/3f569cdf.559ba438.js b/assets/js/3f569cdf.9545b373.js similarity index 99% rename from assets/js/3f569cdf.559ba438.js rename to assets/js/3f569cdf.9545b373.js index fbfda3174..9de2034dc 100644 --- a/assets/js/3f569cdf.559ba438.js +++ b/assets/js/3f569cdf.9545b373.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3775],{4775:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>c,contentTitle:()=>o,default:()=>h,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var t=n(5893),a=n(1151),s=n(4866),l=n(5162);const i={title:"warmup"},o=void 0,u={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/warmup.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const r={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(r.p,{children:["Warmup middleware that helps to reduce the ",(0,t.jsx)(r.a,{href:"https://serverless.com/blog/keep-your-lambdas-warm/",children:"cold-start issue"}),". Compatible by default with ",(0,t.jsx)(r.a,{href:"https://www.npmjs.com/package/serverless-plugin-warmup",children:(0,t.jsx)(r.code,{children:"serverless-plugin-warmup"})}),", but it can be configured to suit your implementation."]}),"\n",(0,t.jsx)(r.p,{children:"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."}),"\n",(0,t.jsxs)(r.p,{children:["If you use ",(0,t.jsx)(r.a,{href:"https://www.npmjs.com/package/serverless-plugin-warmup",children:(0,t.jsx)(r.code,{children:"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,t.jsx)(r.code,{children:"isWarmingUp"})," function to define whether the current event is a warmup event or an actual business logic execution."]}),"\n",(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.strong,{children:"Important:"})," AWS recently announced Lambda ",(0,t.jsx)(r.a,{href:"https://aws.amazon.com/about-aws/whats-new/2019/12/aws-lambda-announces-provisioned-concurrency/",children:"Provisioned Concurrency"}),". If you have this enabled, you do not need this middleware."]}),"\n",(0,t.jsx)(r.p,{children:"To update your code to use Provisioned Concurrency see:"}),"\n",(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsx)(r.li,{children:(0,t.jsx)(r.a,{href:"https://aws.amazon.com/blogs/compute/new-for-aws-lambda-predictable-start-up-times-with-provisioned-concurrency/",children:"AWS Console"})}),"\n",(0,t.jsx)(r.li,{children:(0,t.jsx)(r.a,{href:"https://serverless.com/blog/aws-lambda-provisioned-concurrency/",children:"Serverless"})}),"\n",(0,t.jsx)(r.li,{children:(0,t.jsx)(r.a,{href:"https://www.terraform.io/docs/providers/aws/r/lambda_provisioned_concurrency_config.html",children:"Terraform"})}),"\n"]}),"\n",(0,t.jsx)(r.h2,{id:"install",children:"Install"}),"\n",(0,t.jsx)(r.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,t.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,t.jsx)(l.Z,{value:"npm",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"npm install --save @middy/warmup\n"})})}),(0,t.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"yarn add @middy/warmup\n"})})}),(0,t.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"pnpm add @middy/warmup\n"})})})]}),"\n",(0,t.jsx)(r.h2,{id:"options",children:"Options"}),"\n",(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.code,{children:"isWarmingUp"}),": a function that accepts the ",(0,t.jsx)(r.code,{children:"event"})," object as a parameter\nand returns ",(0,t.jsx)(r.code,{children:"true"})," if the current event is a warmup event and ",(0,t.jsx)(r.code,{children:"false"})," if it's a regular execution. The default function will check if the ",(0,t.jsx)(r.code,{children:"event"})," object has a ",(0,t.jsx)(r.code,{children:"source"})," property set to ",(0,t.jsx)(r.code,{children:"serverless-plugin-warmup"}),"."]}),"\n"]}),"\n",(0,t.jsx)(r.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-javascript",children:"const middy = require('@middy/core')\nconst warmup = require('@middy/warmup')\n\nconst lambdaHandler = (event, context, cb) => {\n /* ... */\n}\n\nconst isWarmingUp = (event) => event.isWarmingUp === true\n\nexport const handler = middy()\n .use(warmup({ isWarmingUp }))\n .handler(lambdaHandler)\n"})})]})}function h(e={}){const{wrapper:r}={...(0,a.a)(),...e.components};return r?(0,t.jsx)(r,{...e,children:(0,t.jsx)(p,{...e})}):p(e)}},5162:(e,r,n)=>{n.d(r,{Z:()=>l});n(7294);var t=n(6010);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function l(e){let{children:r,hidden:n,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,t.Z)(a.tabItem,l),hidden:n,children:r})}},4866:(e,r,n)=>{n.d(r,{Z:()=>j});var t=n(7294),a=n(6010),s=n(2466),l=n(6550),i=n(469),o=n(1980),u=n(7392),c=n(12);function d(e){return t.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:r}=e;return!!r&&"object"==typeof r&&"value"in r}(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)??[]}function p(e){const{values:r,children:n}=e;return(0,t.useMemo)((()=>{const e=r??function(e){return d(e).map((e=>{let{props:{value:r,label:n,attributes:t,default:a}}=e;return{value:r,label:n,attributes:t,default:a}}))}(n);return function(e){const r=(0,u.l)(e,((e,r)=>e.value===r.value));if(r.length>0)throw new Error(`Docusaurus error: Duplicate values "${r.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[r,n])}function h(e){let{value:r,tabValues:n}=e;return n.some((e=>e.value===r))}function m(e){let{queryString:r=!1,groupId:n}=e;const a=(0,l.k6)(),s=function(e){let{queryString:r=!1,groupId:n}=e;if("string"==typeof r)return r;if(!1===r)return null;if(!0===r&&!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:r,groupId:n});return[(0,o._X)(s),(0,t.useCallback)((e=>{if(!s)return;const r=new URLSearchParams(a.location.search);r.set(s,e),a.replace({...a.location,search:r.toString()})}),[s,a])]}function b(e){const{defaultValue:r,queryString:n=!1,groupId:a}=e,s=p(e),[l,o]=(0,t.useState)((()=>function(e){let{defaultValue:r,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(r){if(!h({value:r,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${r}" 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 r}const t=n.find((e=>e.default))??n[0];if(!t)throw new Error("Unexpected error: 0 tabValues");return t.value}({defaultValue:r,tabValues:s}))),[u,d]=m({queryString:n,groupId:a}),[b,f]=function(e){let{groupId:r}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(r),[a,s]=(0,c.Nk)(n);return[a,(0,t.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),v=(()=>{const e=u??b;return h({value:e,tabValues:s})?e:null})();(0,i.Z)((()=>{v&&o(v)}),[v]);return{selectedValue:l,selectValue:(0,t.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),f(e)}),[d,f,s]),tabValues:s}}var f=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var w=n(5893);function g(e){let{className:r,block:n,selectedValue:t,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.o5)(),c=e=>{const r=e.currentTarget,n=o.indexOf(r),a=i[n].value;a!==t&&(u(r),l(a))},d=e=>{let r=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=o.indexOf(e.currentTarget)+1;r=o[n]??o[0];break}case"ArrowLeft":{const n=o.indexOf(e.currentTarget)-1;r=o[n]??o[o.length-1];break}}r?.focus()};return(0,w.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},r),children:i.map((e=>{let{value:r,label:n,attributes:s}=e;return(0,w.jsx)("li",{role:"tab",tabIndex:t===r?0:-1,"aria-selected":t===r,ref:e=>o.push(e),onKeyDown:d,onClick:c,...s,className:(0,a.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":t===r}),children:n??r},r)}))})}function y(e){let{lazy:r,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(r){const e=s.find((e=>e.props.value===a));return e?(0,t.cloneElement)(e,{className:"margin-top--md"}):null}return(0,w.jsx)("div",{className:"margin-top--md",children:s.map(((e,r)=>(0,t.cloneElement)(e,{key:r,hidden:e.props.value!==a})))})}function x(e){const r=b(e);return(0,w.jsxs)("div",{className:(0,a.Z)("tabs-container",v.tabList),children:[(0,w.jsx)(g,{...e,...r}),(0,w.jsx)(y,{...e,...r})]})}function j(e){const r=(0,f.Z)();return(0,w.jsx)(x,{...e,children:d(e.children)},String(r))}},1151:(e,r,n)=>{n.d(r,{Z:()=>i,a:()=>l});var t=n(7294);const a={},s=t.createContext(a);function l(e){const r=t.useContext(s);return t.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function i(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),t.createElement(s.Provider,{value:r},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3775],{4775:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>c,contentTitle:()=>o,default:()=>h,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var t=n(5893),a=n(1151),s=n(4866),l=n(5162);const i={title:"warmup"},o=void 0,u={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/warmup.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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={},d=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const r={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(r.p,{children:["Warmup middleware that helps to reduce the ",(0,t.jsx)(r.a,{href:"https://serverless.com/blog/keep-your-lambdas-warm/",children:"cold-start issue"}),". Compatible by default with ",(0,t.jsx)(r.a,{href:"https://www.npmjs.com/package/serverless-plugin-warmup",children:(0,t.jsx)(r.code,{children:"serverless-plugin-warmup"})}),", but it can be configured to suit your implementation."]}),"\n",(0,t.jsx)(r.p,{children:"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."}),"\n",(0,t.jsxs)(r.p,{children:["If you use ",(0,t.jsx)(r.a,{href:"https://www.npmjs.com/package/serverless-plugin-warmup",children:(0,t.jsx)(r.code,{children:"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,t.jsx)(r.code,{children:"isWarmingUp"})," function to define whether the current event is a warmup event or an actual business logic execution."]}),"\n",(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.strong,{children:"Important:"})," AWS recently announced Lambda ",(0,t.jsx)(r.a,{href:"https://aws.amazon.com/about-aws/whats-new/2019/12/aws-lambda-announces-provisioned-concurrency/",children:"Provisioned Concurrency"}),". If you have this enabled, you do not need this middleware."]}),"\n",(0,t.jsx)(r.p,{children:"To update your code to use Provisioned Concurrency see:"}),"\n",(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsx)(r.li,{children:(0,t.jsx)(r.a,{href:"https://aws.amazon.com/blogs/compute/new-for-aws-lambda-predictable-start-up-times-with-provisioned-concurrency/",children:"AWS Console"})}),"\n",(0,t.jsx)(r.li,{children:(0,t.jsx)(r.a,{href:"https://serverless.com/blog/aws-lambda-provisioned-concurrency/",children:"Serverless"})}),"\n",(0,t.jsx)(r.li,{children:(0,t.jsx)(r.a,{href:"https://www.terraform.io/docs/providers/aws/r/lambda_provisioned_concurrency_config.html",children:"Terraform"})}),"\n"]}),"\n",(0,t.jsx)(r.h2,{id:"install",children:"Install"}),"\n",(0,t.jsx)(r.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,t.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,t.jsx)(l.Z,{value:"npm",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"npm install --save @middy/warmup\n"})})}),(0,t.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"yarn add @middy/warmup\n"})})}),(0,t.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"pnpm add @middy/warmup\n"})})})]}),"\n",(0,t.jsx)(r.h2,{id:"options",children:"Options"}),"\n",(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.code,{children:"isWarmingUp"}),": a function that accepts the ",(0,t.jsx)(r.code,{children:"event"})," object as a parameter\nand returns ",(0,t.jsx)(r.code,{children:"true"})," if the current event is a warmup event and ",(0,t.jsx)(r.code,{children:"false"})," if it's a regular execution. The default function will check if the ",(0,t.jsx)(r.code,{children:"event"})," object has a ",(0,t.jsx)(r.code,{children:"source"})," property set to ",(0,t.jsx)(r.code,{children:"serverless-plugin-warmup"}),"."]}),"\n"]}),"\n",(0,t.jsx)(r.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-javascript",children:"const middy = require('@middy/core')\nconst warmup = require('@middy/warmup')\n\nconst lambdaHandler = (event, context, cb) => {\n /* ... */\n}\n\nconst isWarmingUp = (event) => event.isWarmingUp === true\n\nexport const handler = middy()\n .use(warmup({ isWarmingUp }))\n .handler(lambdaHandler)\n"})})]})}function h(e={}){const{wrapper:r}={...(0,a.a)(),...e.components};return r?(0,t.jsx)(r,{...e,children:(0,t.jsx)(p,{...e})}):p(e)}},5162:(e,r,n)=>{n.d(r,{Z:()=>l});n(7294);var t=n(6010);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function l(e){let{children:r,hidden:n,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,t.Z)(a.tabItem,l),hidden:n,children:r})}},4866:(e,r,n)=>{n.d(r,{Z:()=>j});var t=n(7294),a=n(6010),s=n(2466),l=n(6550),i=n(469),o=n(1980),u=n(7392),c=n(12);function d(e){return t.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:r}=e;return!!r&&"object"==typeof r&&"value"in r}(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)??[]}function p(e){const{values:r,children:n}=e;return(0,t.useMemo)((()=>{const e=r??function(e){return d(e).map((e=>{let{props:{value:r,label:n,attributes:t,default:a}}=e;return{value:r,label:n,attributes:t,default:a}}))}(n);return function(e){const r=(0,u.l)(e,((e,r)=>e.value===r.value));if(r.length>0)throw new Error(`Docusaurus error: Duplicate values "${r.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[r,n])}function h(e){let{value:r,tabValues:n}=e;return n.some((e=>e.value===r))}function m(e){let{queryString:r=!1,groupId:n}=e;const a=(0,l.k6)(),s=function(e){let{queryString:r=!1,groupId:n}=e;if("string"==typeof r)return r;if(!1===r)return null;if(!0===r&&!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:r,groupId:n});return[(0,o._X)(s),(0,t.useCallback)((e=>{if(!s)return;const r=new URLSearchParams(a.location.search);r.set(s,e),a.replace({...a.location,search:r.toString()})}),[s,a])]}function b(e){const{defaultValue:r,queryString:n=!1,groupId:a}=e,s=p(e),[l,o]=(0,t.useState)((()=>function(e){let{defaultValue:r,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(r){if(!h({value:r,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${r}" 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 r}const t=n.find((e=>e.default))??n[0];if(!t)throw new Error("Unexpected error: 0 tabValues");return t.value}({defaultValue:r,tabValues:s}))),[u,d]=m({queryString:n,groupId:a}),[b,f]=function(e){let{groupId:r}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(r),[a,s]=(0,c.Nk)(n);return[a,(0,t.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),v=(()=>{const e=u??b;return h({value:e,tabValues:s})?e:null})();(0,i.Z)((()=>{v&&o(v)}),[v]);return{selectedValue:l,selectValue:(0,t.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),f(e)}),[d,f,s]),tabValues:s}}var f=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var w=n(5893);function g(e){let{className:r,block:n,selectedValue:t,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.o5)(),c=e=>{const r=e.currentTarget,n=o.indexOf(r),a=i[n].value;a!==t&&(u(r),l(a))},d=e=>{let r=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=o.indexOf(e.currentTarget)+1;r=o[n]??o[0];break}case"ArrowLeft":{const n=o.indexOf(e.currentTarget)-1;r=o[n]??o[o.length-1];break}}r?.focus()};return(0,w.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},r),children:i.map((e=>{let{value:r,label:n,attributes:s}=e;return(0,w.jsx)("li",{role:"tab",tabIndex:t===r?0:-1,"aria-selected":t===r,ref:e=>o.push(e),onKeyDown:d,onClick:c,...s,className:(0,a.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":t===r}),children:n??r},r)}))})}function y(e){let{lazy:r,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(r){const e=s.find((e=>e.props.value===a));return e?(0,t.cloneElement)(e,{className:"margin-top--md"}):null}return(0,w.jsx)("div",{className:"margin-top--md",children:s.map(((e,r)=>(0,t.cloneElement)(e,{key:r,hidden:e.props.value!==a})))})}function x(e){const r=b(e);return(0,w.jsxs)("div",{className:(0,a.Z)("tabs-container",v.tabList),children:[(0,w.jsx)(g,{...e,...r}),(0,w.jsx)(y,{...e,...r})]})}function j(e){const r=(0,f.Z)();return(0,w.jsx)(x,{...e,children:d(e.children)},String(r))}},1151:(e,r,n)=>{n.d(r,{Z:()=>i,a:()=>l});var t=n(7294);const a={},s=t.createContext(a);function l(e){const r=t.useContext(s);return t.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function i(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),t.createElement(s.Provider,{value:r},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4149078a.2278715d.js b/assets/js/4149078a.a4d946d5.js similarity index 99% rename from assets/js/4149078a.2278715d.js rename to assets/js/4149078a.a4d946d5.js index 00fc78d4d..c72a87224 100644 --- a/assets/js/4149078a.2278715d.js +++ b/assets/js/4149078a.a4d946d5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4183],{3171:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>t,contentTitle:()=>i,default:()=>h,frontMatter:()=>d,metadata:()=>o,toc:()=>a});var s=n(5893),l=n(1151);const d={title:"Upgrade 2.x -> 3.x",sidebar_position:100},i=void 0,o={id:"upgrade/2-3",title:"Upgrade 2.x -> 3.x",description:'aka "The onError Reversal Update"',source:"@site/docs/upgrade/2-3.md",sourceDirName:"upgrade",slug:"/upgrade/2-3",permalink:"/docs/upgrade/2-3",draft:!1,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/2-3.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},t={},a=[{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}];function c(e){const r={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,l.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.p,{children:'aka "The onError Reversal Update"'}),"\n",(0,s.jsx)(r.p,{children:"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."}),"\n",(0,s.jsx)(r.h2,{id:"notable-changes",children:"Notable changes"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"New WebSocket middlewares"}),"\n",(0,s.jsx)(r.li,{children:"HTTP & WebSocket Routers!"}),"\n",(0,s.jsx)(r.li,{children:"Better error handling"}),"\n",(0,s.jsx)(r.li,{children:"Timeout error handling"}),"\n",(0,s.jsxs)(r.li,{children:["Errors now use ",(0,s.jsx)(r.code,{children:"{ cause }"})," for better context"]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"core",children:"Core"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"onError"})," middleware stack order reversed to match ",(0,s.jsx)(r.code,{children:"after"})," ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["If you only use ",(0,s.jsx)(r.code,{children:"@middy/*"})," middlewares no change should be required"]}),"\n",(0,s.jsxs)(r.li,{children:["This change has trickle down effects on middlewares with ",(0,s.jsx)(r.code,{children:"onError"})," (see below for details)"]}),"\n",(0,s.jsxs)(r.li,{children:["If you're handling errors yourself here are some things to review:","\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"Attach near the end so it is triggered first (likely already done)"}),"\n",(0,s.jsxs)(r.li,{children:["Remove ",(0,s.jsx)(r.code,{children:"return response"}),", this will short circuit the response and block later middleware from modifying the response"]}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(r.li,{children:["lambdaHandler now passes ",(0,s.jsx)(r.code,{children:"{signal}"})," from ",(0,s.jsx)(r.code,{children:"AbortController"})," to allow for ending lambda early to handle timeout errors"]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"plugin"})," argument now supports:","\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"internal"}),": Allow the use of ",(0,s.jsx)(r.code,{children:"new Proxy()"})," for smarter triggering in advanced use cases."]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"timeoutEarlyInMillis"}),": When before lambda timeout to trigger early exit. Default ",(0,s.jsx)(r.code,{children:"5"})]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"timeoutEarlyResponse"}),": Function to throw a custom error or return a pre-set value. Default ",(0,s.jsx)(r.code,{children:"() => { throw new Error('Timeout') }"})]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(r.li,{children:["Added ",(0,s.jsx)(r.code,{children:".handler()"})," method to allow easier understanding of the execution cycle"]}),"\n",(0,s.jsxs)(r.li,{children:["Deprecate ",(0,s.jsx)(r.code,{children:"applyMiddleware()"})," and ",(0,s.jsx)(r.code,{children:"__middlewares"})," ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"util",children:"Util"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"getInternal"})," error now includes ",(0,s.jsx)(r.code,{children:"cause"})," set to an array of Errors"]}),"\n",(0,s.jsxs)(r.li,{children:["Catch when ",(0,s.jsx)(r.code,{children:"X-Ray"})," is applied outside of handler invocation scope"]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"normalizeHttpResponse"})," now takes ",(0,s.jsx)(r.code,{children:"request"})," and mutates response ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"getCache"})," will return ",(0,s.jsx)(r.code,{children:"{}"})," instead of ",(0,s.jsx)(r.code,{children:"undefined"})," when not found ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"middleware",children:"Middleware"}),"\n",(0,s.jsx)(r.h3,{id:"cloudwatch-metrics",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/cloudwatch-metrics",children:"cloudwatch-metrics"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"do-not-wait-for-empty-event-loop",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/do-not-wait-for-empty-event-loop",children:"do-not-wait-for-empty-event-loop"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"error-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/error-logger",children:"error-logger"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/event-normalizer",children:"event-normalizer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"Add support for all missing AWS events"}),"\n",(0,s.jsx)(r.li,{children:"Refactored for performance improvements"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-content-encoding",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-encoding",children:"http-content-encoding"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["[New] Applies ",(0,s.jsx)(r.code,{children:"brotli"}),", ",(0,s.jsx)(r.code,{children:"gzip"}),", ands ",(0,s.jsx)(r.code,{children:"deflate"})," compression to response body"]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-content-negotiation",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-negotiation",children:"http-content-negotiation"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Add in ",(0,s.jsx)(r.code,{children:"defaultToFirstLanguage"})," to allow fallback to a safe language to use"]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-cors",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-cors",children:"http-cors"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"onError"})," will not modify response unless error has been handled"]}),"\n",(0,s.jsx)(r.li,{children:"Small refactor for performance improvements"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-error-handler",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-error-handler",children:"http-error-handler"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["No longer returns the response to short circuit the middleware stack to allow for easier use now that ",(0,s.jsx)(r.code,{children:"onError"})," is called in reverse order."]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-event-normalizer",children:"http-event-normalizer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Option ",(0,s.jsx)(r.code,{children:"payloadFormatVersion"})," no longer needed"]}),"\n",(0,s.jsxs)(r.li,{children:["Will now throw error if not an http event ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-header-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-header-normalizer",children:"http-header-normalizer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Modified so that all headers are set to lowercase when ",(0,s.jsx)(r.code,{children:"canonical:false"})," ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-json-body-parser",children:"http-json-body-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-multipart-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-multipart-body-parser",children:"http-multipart-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Change default charset from ",(0,s.jsx)(r.code,{children:"binary"}),"/",(0,s.jsx)(r.code,{children:"latin1"})," to ",(0,s.jsx)(r.code,{children:"utf-8"}),". ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-partial-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-partial-response",children:"http-partial-response"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-response-serializer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-response-serializer",children:"http-response-serializer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Renamed ",(0,s.jsx)(r.code,{children:"default"})," option to ",(0,s.jsx)(r.code,{children:"defaultContentType"})," to improve maintainability ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"onError"})," will not modify response unless error has been handled"]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-router",children:(0,s.jsx)(r.a,{href:"/docs/routers/http-router",children:"http-router"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"[New] Allow re-routing of events to different handlers"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-security-headers",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-security-headers",children:"http-security-headers"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"onError"})," will not modify response unless error has been handled"]}),"\n",(0,s.jsxs)(r.li,{children:["Complete rewrite of options and inclusion of new HTML only headers ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-body-parser",children:"http-urlencode-body-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-path-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-path-parser",children:"http-urlencode-path-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"input-output-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/input-output-logger",children:"input-output-logger"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"Add in new option to mask instead of omit a path."}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"rds-signer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/rds-signer",children:"rds-signer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecated ",(0,s.jsx)(r.code,{children:"setToEnv"})," option due to possible security misuse ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"s3-key-normalizer",children:"s3-key-normalizer"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecated in favour of ",(0,s.jsx)(r.a,{href:"/docs/middlewares/event-normalizer",children:(0,s.jsx)(r.code,{children:"event-normalizer"})}),", v2.x compatible with v3"]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"s3-object-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/s3-object-response",children:"s3-object-response"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"secrets-manager",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/secrets-manager",children:"secrets-manager"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecated ",(0,s.jsx)(r.code,{children:"setToEnv"})," option due to possible security misuse ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"service-discovery",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/service-discovery",children:"service-discovery"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"[New] Allow easy access to discoveryInstances"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"sqs-json-body-parser",children:"sqs-json-body-parser"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecated in favour of ",(0,s.jsx)(r.a,{href:"/docs/middlewares/event-normalizer",children:(0,s.jsx)(r.code,{children:"event-normalizer"})}),", v2.x compatible with v3"]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"sqs-partial-batch-failure",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sqs-partial-batch-failure",children:"sqs-partial-batch-failure"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Complete rewrite to take advantage of ",(0,s.jsx)(r.a,{href:"https://aws.amazon.com/about-aws/whats-new/2021/11/aws-lambda-partial-batch-response-sqs-event-source/",children:"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,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"ssm",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ssm",children:"ssm"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecated ",(0,s.jsx)(r.code,{children:"setToEnv"})," option ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"sts",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sts",children:"sts"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"validator",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/validator",children:"validator"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Change where errors are stored, from ",(0,s.jsx)(r.code,{children:"request.error.details"})," to ",(0,s.jsx)(r.code,{children:"request.error.cause"})," ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n",(0,s.jsxs)(r.li,{children:["Add new options ",(0,s.jsx)(r.code,{children:"eventSchema"}),", ",(0,s.jsx)(r.code,{children:"contextSchema"}),", ",(0,s.jsx)(r.code,{children:"responseSchema"}),". ",(0,s.jsx)(r.code,{children:"inputSchema"})," and ",(0,s.jsx)(r.code,{children:"outputSchema"})," become aliases."]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"warmup",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/warmup",children:"warmup"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"ws-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ws-json-body-parser",children:"ws-json-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"[New] Parse body from WebSocket event"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"ws-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ws-response",children:"ws-response"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"[New] Post responses to WebSocket API Gateway"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"ws-router",children:(0,s.jsx)(r.a,{href:"/docs/routers/ws-router",children:"ws-router"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"[New] Allow re-routing of events to different handlers"}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"notes",children:"Notes"}),"\n",(0,s.jsxs)(r.p,{children:["If you still need ",(0,s.jsx)(r.code,{children:"setToEnv"})," you can do something like so:"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-javascript",children:"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"})})]})}function h(e={}){const{wrapper:r}={...(0,l.a)(),...e.components};return r?(0,s.jsx)(r,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,r,n)=>{n.d(r,{Z:()=>o,a:()=>i});var s=n(7294);const l={},d=s.createContext(l);function i(e){const r=s.useContext(d);return s.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function o(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(l):e.components||l:i(e.components),s.createElement(d.Provider,{value:r},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4183],{3171:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>t,contentTitle:()=>i,default:()=>h,frontMatter:()=>d,metadata:()=>o,toc:()=>a});var s=n(5893),l=n(1151);const d={title:"Upgrade 2.x -> 3.x",sidebar_position:100},i=void 0,o={id:"upgrade/2-3",title:"Upgrade 2.x -> 3.x",description:'aka "The onError Reversal Update"',source:"@site/docs/upgrade/2-3.md",sourceDirName:"upgrade",slug:"/upgrade/2-3",permalink:"/docs/upgrade/2-3",draft:!1,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/2-3.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},t={},a=[{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}];function c(e){const r={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,l.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.p,{children:'aka "The onError Reversal Update"'}),"\n",(0,s.jsx)(r.p,{children:"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."}),"\n",(0,s.jsx)(r.h2,{id:"notable-changes",children:"Notable changes"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"New WebSocket middlewares"}),"\n",(0,s.jsx)(r.li,{children:"HTTP & WebSocket Routers!"}),"\n",(0,s.jsx)(r.li,{children:"Better error handling"}),"\n",(0,s.jsx)(r.li,{children:"Timeout error handling"}),"\n",(0,s.jsxs)(r.li,{children:["Errors now use ",(0,s.jsx)(r.code,{children:"{ cause }"})," for better context"]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"core",children:"Core"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"onError"})," middleware stack order reversed to match ",(0,s.jsx)(r.code,{children:"after"})," ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["If you only use ",(0,s.jsx)(r.code,{children:"@middy/*"})," middlewares no change should be required"]}),"\n",(0,s.jsxs)(r.li,{children:["This change has trickle down effects on middlewares with ",(0,s.jsx)(r.code,{children:"onError"})," (see below for details)"]}),"\n",(0,s.jsxs)(r.li,{children:["If you're handling errors yourself here are some things to review:","\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"Attach near the end so it is triggered first (likely already done)"}),"\n",(0,s.jsxs)(r.li,{children:["Remove ",(0,s.jsx)(r.code,{children:"return response"}),", this will short circuit the response and block later middleware from modifying the response"]}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(r.li,{children:["lambdaHandler now passes ",(0,s.jsx)(r.code,{children:"{signal}"})," from ",(0,s.jsx)(r.code,{children:"AbortController"})," to allow for ending lambda early to handle timeout errors"]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"plugin"})," argument now supports:","\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"internal"}),": Allow the use of ",(0,s.jsx)(r.code,{children:"new Proxy()"})," for smarter triggering in advanced use cases."]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"timeoutEarlyInMillis"}),": When before lambda timeout to trigger early exit. Default ",(0,s.jsx)(r.code,{children:"5"})]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"timeoutEarlyResponse"}),": Function to throw a custom error or return a pre-set value. Default ",(0,s.jsx)(r.code,{children:"() => { throw new Error('Timeout') }"})]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(r.li,{children:["Added ",(0,s.jsx)(r.code,{children:".handler()"})," method to allow easier understanding of the execution cycle"]}),"\n",(0,s.jsxs)(r.li,{children:["Deprecate ",(0,s.jsx)(r.code,{children:"applyMiddleware()"})," and ",(0,s.jsx)(r.code,{children:"__middlewares"})," ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"util",children:"Util"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"getInternal"})," error now includes ",(0,s.jsx)(r.code,{children:"cause"})," set to an array of Errors"]}),"\n",(0,s.jsxs)(r.li,{children:["Catch when ",(0,s.jsx)(r.code,{children:"X-Ray"})," is applied outside of handler invocation scope"]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"normalizeHttpResponse"})," now takes ",(0,s.jsx)(r.code,{children:"request"})," and mutates response ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"getCache"})," will return ",(0,s.jsx)(r.code,{children:"{}"})," instead of ",(0,s.jsx)(r.code,{children:"undefined"})," when not found ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"middleware",children:"Middleware"}),"\n",(0,s.jsx)(r.h3,{id:"cloudwatch-metrics",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/cloudwatch-metrics",children:"cloudwatch-metrics"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"do-not-wait-for-empty-event-loop",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/do-not-wait-for-empty-event-loop",children:"do-not-wait-for-empty-event-loop"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"error-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/error-logger",children:"error-logger"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/event-normalizer",children:"event-normalizer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"Add support for all missing AWS events"}),"\n",(0,s.jsx)(r.li,{children:"Refactored for performance improvements"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-content-encoding",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-encoding",children:"http-content-encoding"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["[New] Applies ",(0,s.jsx)(r.code,{children:"brotli"}),", ",(0,s.jsx)(r.code,{children:"gzip"}),", ands ",(0,s.jsx)(r.code,{children:"deflate"})," compression to response body"]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-content-negotiation",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-negotiation",children:"http-content-negotiation"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Add in ",(0,s.jsx)(r.code,{children:"defaultToFirstLanguage"})," to allow fallback to a safe language to use"]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-cors",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-cors",children:"http-cors"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"onError"})," will not modify response unless error has been handled"]}),"\n",(0,s.jsx)(r.li,{children:"Small refactor for performance improvements"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-error-handler",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-error-handler",children:"http-error-handler"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["No longer returns the response to short circuit the middleware stack to allow for easier use now that ",(0,s.jsx)(r.code,{children:"onError"})," is called in reverse order."]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-event-normalizer",children:"http-event-normalizer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Option ",(0,s.jsx)(r.code,{children:"payloadFormatVersion"})," no longer needed"]}),"\n",(0,s.jsxs)(r.li,{children:["Will now throw error if not an http event ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-header-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-header-normalizer",children:"http-header-normalizer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Modified so that all headers are set to lowercase when ",(0,s.jsx)(r.code,{children:"canonical:false"})," ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-json-body-parser",children:"http-json-body-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-multipart-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-multipart-body-parser",children:"http-multipart-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Change default charset from ",(0,s.jsx)(r.code,{children:"binary"}),"/",(0,s.jsx)(r.code,{children:"latin1"})," to ",(0,s.jsx)(r.code,{children:"utf-8"}),". ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-partial-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-partial-response",children:"http-partial-response"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-response-serializer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-response-serializer",children:"http-response-serializer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Renamed ",(0,s.jsx)(r.code,{children:"default"})," option to ",(0,s.jsx)(r.code,{children:"defaultContentType"})," to improve maintainability ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"onError"})," will not modify response unless error has been handled"]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-router",children:(0,s.jsx)(r.a,{href:"/docs/routers/http-router",children:"http-router"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"[New] Allow re-routing of events to different handlers"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-security-headers",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-security-headers",children:"http-security-headers"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"onError"})," will not modify response unless error has been handled"]}),"\n",(0,s.jsxs)(r.li,{children:["Complete rewrite of options and inclusion of new HTML only headers ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-body-parser",children:"http-urlencode-body-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-path-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-path-parser",children:"http-urlencode-path-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"input-output-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/input-output-logger",children:"input-output-logger"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"Add in new option to mask instead of omit a path."}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"rds-signer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/rds-signer",children:"rds-signer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecated ",(0,s.jsx)(r.code,{children:"setToEnv"})," option due to possible security misuse ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"s3-key-normalizer",children:"s3-key-normalizer"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecated in favour of ",(0,s.jsx)(r.a,{href:"/docs/middlewares/event-normalizer",children:(0,s.jsx)(r.code,{children:"event-normalizer"})}),", v2.x compatible with v3"]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"s3-object-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/s3-object-response",children:"s3-object-response"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"secrets-manager",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/secrets-manager",children:"secrets-manager"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecated ",(0,s.jsx)(r.code,{children:"setToEnv"})," option due to possible security misuse ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"service-discovery",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/service-discovery",children:"service-discovery"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"[New] Allow easy access to discoveryInstances"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"sqs-json-body-parser",children:"sqs-json-body-parser"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecated in favour of ",(0,s.jsx)(r.a,{href:"/docs/middlewares/event-normalizer",children:(0,s.jsx)(r.code,{children:"event-normalizer"})}),", v2.x compatible with v3"]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"sqs-partial-batch-failure",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sqs-partial-batch-failure",children:"sqs-partial-batch-failure"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Complete rewrite to take advantage of ",(0,s.jsx)(r.a,{href:"https://aws.amazon.com/about-aws/whats-new/2021/11/aws-lambda-partial-batch-response-sqs-event-source/",children:"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,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"ssm",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ssm",children:"ssm"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecated ",(0,s.jsx)(r.code,{children:"setToEnv"})," option ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"sts",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sts",children:"sts"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"validator",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/validator",children:"validator"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Change where errors are stored, from ",(0,s.jsx)(r.code,{children:"request.error.details"})," to ",(0,s.jsx)(r.code,{children:"request.error.cause"})," ",(0,s.jsx)(r.strong,{children:"[Breaking Change]"})]}),"\n",(0,s.jsxs)(r.li,{children:["Add new options ",(0,s.jsx)(r.code,{children:"eventSchema"}),", ",(0,s.jsx)(r.code,{children:"contextSchema"}),", ",(0,s.jsx)(r.code,{children:"responseSchema"}),". ",(0,s.jsx)(r.code,{children:"inputSchema"})," and ",(0,s.jsx)(r.code,{children:"outputSchema"})," become aliases."]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"warmup",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/warmup",children:"warmup"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"ws-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ws-json-body-parser",children:"ws-json-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"[New] Parse body from WebSocket event"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"ws-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ws-response",children:"ws-response"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"[New] Post responses to WebSocket API Gateway"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"ws-router",children:(0,s.jsx)(r.a,{href:"/docs/routers/ws-router",children:"ws-router"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"[New] Allow re-routing of events to different handlers"}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"notes",children:"Notes"}),"\n",(0,s.jsxs)(r.p,{children:["If you still need ",(0,s.jsx)(r.code,{children:"setToEnv"})," you can do something like so:"]}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-javascript",children:"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"})})]})}function h(e={}){const{wrapper:r}={...(0,l.a)(),...e.components};return r?(0,s.jsx)(r,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,r,n)=>{n.d(r,{Z:()=>o,a:()=>i});var s=n(7294);const l={},d=s.createContext(l);function i(e){const r=s.useContext(d);return s.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function o(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(l):e.components||l:i(e.components),s.createElement(d.Provider,{value:r},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/41b3f383.27922243.js b/assets/js/41b3f383.2b46a48c.js similarity index 99% rename from assets/js/41b3f383.27922243.js rename to assets/js/41b3f383.2b46a48c.js index 6502202a5..ef4ffaa8a 100644 --- a/assets/js/41b3f383.27922243.js +++ b/assets/js/41b3f383.2b46a48c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[479],{4379:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>o,contentTitle:()=>c,default:()=>m,frontMatter:()=>l,metadata:()=>d,toc:()=>u});var s=r(5893),t=r(1151),a=r(4866),i=r(5162);const l={title:"service-discovery"},c=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/service-discovery.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},o={},u=[{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}];function h(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,t.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Fetches Service Discovery instances to be used when connecting to other AWS services."}),"\n",(0,s.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(i.Z,{value:"npm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/service-discovery\nnpm install --save-dev @aws-sdk/client-servicediscovery\n"})})}),(0,s.jsx)(i.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/service-discovery\nyarn add --dev @aws-sdk/client-servicediscovery\n"})})}),(0,s.jsx)(i.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/service-discovery\npnpm add --save-dev @aws-sdk/client-servicediscovery\n"})})})]}),"\n",(0,s.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(n.code,{children:"ServiceDiscoveryClient"}),"): ServiceDiscoveryClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-servicediscovery"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientOptions"})," (object) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Options to pass to ServiceDiscoveryClient class constructor."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," (string) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Internal key where secrets are stored. See ",(0,s.jsx)(n.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientCapture"})," (function) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Enable XRay by passing ",(0,s.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,s.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameters."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheKey"})," (string) (default ",(0,s.jsx)(n.code,{children:"sts"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheExpiry"})," (number) (default ",(0,s.jsx)(n.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,s.jsx)(n.code,{children:"-1"}),": cache forever, ",(0,s.jsx)(n.code,{children:"0"}),": never cache, ",(0,s.jsx)(n.code,{children:"n"}),": cache for n ms."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"setToContext"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): Store credentials to ",(0,s.jsx)(n.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(n.code,{children:"servicediscovery:DiscoverInstances"})]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport serviceDiscovery from '@middy/service-discovery'\n\nconst lambdaHandler = (event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n}\n\nexport const handler = middy()\n .use(\n serviceDiscovery({\n fetchData: {\n instances: {\n NamespaceName: '...',\n ServiceName: '...'\n }\n }\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(n.p,{children:["To exclude ",(0,s.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-servicediscovery"})," to the exclude list."]})]})}function m(e={}){const{wrapper:n}={...(0,t.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},5162:(e,n,r)=>{r.d(n,{Z:()=>i});r(7294);var s=r(6010);const t={tabItem:"tabItem_Ymn6"};var a=r(5893);function i(e){let{children:n,hidden:r,className:i}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.Z)(t.tabItem,i),hidden:r,children:n})}},4866:(e,n,r)=>{r.d(n,{Z:()=>w});var s=r(7294),t=r(6010),a=r(2466),i=r(6550),l=r(469),c=r(1980),d=r(7392),o=r(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:r}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:r,attributes:s,default:t}}=e;return{value:n,label:r,attributes:s,default:t}}))}(r);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,r])}function m(e){let{value:n,tabValues:r}=e;return r.some((e=>e.value===n))}function v(e){let{queryString:n=!1,groupId:r}=e;const t=(0,i.k6)(),a=function(e){let{queryString:n=!1,groupId:r}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!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:n,groupId:r});return[(0,c._X)(a),(0,s.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(t.location.search);n.set(a,e),t.replace({...t.location,search:n.toString()})}),[a,t])]}function p(e){const{defaultValue:n,queryString:r=!1,groupId:t}=e,a=h(e),[i,c]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" 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 n}const s=r.find((e=>e.default))??r[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:a}))),[d,u]=v({queryString:r,groupId:t}),[p,f]=function(e){let{groupId:n}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(n),[t,a]=(0,o.Nk)(r);return[t,(0,s.useCallback)((e=>{r&&a.set(e)}),[r,a])]}({groupId:t}),b=(()=>{const e=d??p;return m({value:e,tabValues:a})?e:null})();(0,l.Z)((()=>{b&&c(b)}),[b]);return{selectedValue:i,selectValue:(0,s.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);c(e),u(e),f(e)}),[u,f,a]),tabValues:a}}var f=r(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=r(5893);function y(e){let{className:n,block:r,selectedValue:s,selectValue:i,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,a.o5)(),o=e=>{const n=e.currentTarget,r=c.indexOf(n),t=l[r].value;t!==s&&(d(n),i(t))},u=e=>{let n=null;switch(e.key){case"Enter":o(e);break;case"ArrowRight":{const r=c.indexOf(e.currentTarget)+1;n=c[r]??c[0];break}case"ArrowLeft":{const r=c.indexOf(e.currentTarget)-1;n=c[r]??c[c.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,t.Z)("tabs",{"tabs--block":r},n),children:l.map((e=>{let{value:n,label:r,attributes:a}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>c.push(e),onKeyDown:u,onClick:o,...a,className:(0,t.Z)("tabs__item",b.tabItem,a?.className,{"tabs__item--active":s===n}),children:r??n},n)}))})}function j(e){let{lazy:n,children:r,selectedValue:t}=e;const a=(Array.isArray(r)?r:[r]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===t));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==t})))})}function g(e){const n=p(e);return(0,x.jsxs)("div",{className:(0,t.Z)("tabs-container",b.tabList),children:[(0,x.jsx)(y,{...e,...n}),(0,x.jsx)(j,{...e,...n})]})}function w(e){const n=(0,f.Z)();return(0,x.jsx)(g,{...e,children:u(e.children)},String(n))}},1151:(e,n,r)=>{r.d(n,{Z:()=>l,a:()=>i});var s=r(7294);const t={},a=s.createContext(t);function i(e){const n=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:i(e.components),s.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[479],{4379:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>o,contentTitle:()=>c,default:()=>m,frontMatter:()=>l,metadata:()=>d,toc:()=>u});var s=r(5893),t=r(1151),a=r(4866),i=r(5162);const l={title:"service-discovery"},c=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/service-discovery.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},o={},u=[{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}];function h(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,t.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Fetches Service Discovery instances to be used when connecting to other AWS services."}),"\n",(0,s.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(i.Z,{value:"npm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/service-discovery\nnpm install --save-dev @aws-sdk/client-servicediscovery\n"})})}),(0,s.jsx)(i.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/service-discovery\nyarn add --dev @aws-sdk/client-servicediscovery\n"})})}),(0,s.jsx)(i.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/service-discovery\npnpm add --save-dev @aws-sdk/client-servicediscovery\n"})})})]}),"\n",(0,s.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(n.code,{children:"ServiceDiscoveryClient"}),"): ServiceDiscoveryClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-servicediscovery"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientOptions"})," (object) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Options to pass to ServiceDiscoveryClient class constructor."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," (string) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Internal key where secrets are stored. See ",(0,s.jsx)(n.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientCapture"})," (function) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Enable XRay by passing ",(0,s.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,s.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameters."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheKey"})," (string) (default ",(0,s.jsx)(n.code,{children:"sts"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheExpiry"})," (number) (default ",(0,s.jsx)(n.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,s.jsx)(n.code,{children:"-1"}),": cache forever, ",(0,s.jsx)(n.code,{children:"0"}),": never cache, ",(0,s.jsx)(n.code,{children:"n"}),": cache for n ms."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"setToContext"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): Store credentials to ",(0,s.jsx)(n.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(n.code,{children:"servicediscovery:DiscoverInstances"})]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport serviceDiscovery from '@middy/service-discovery'\n\nconst lambdaHandler = (event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n}\n\nexport const handler = middy()\n .use(\n serviceDiscovery({\n fetchData: {\n instances: {\n NamespaceName: '...',\n ServiceName: '...'\n }\n }\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(n.p,{children:["To exclude ",(0,s.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-servicediscovery"})," to the exclude list."]})]})}function m(e={}){const{wrapper:n}={...(0,t.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},5162:(e,n,r)=>{r.d(n,{Z:()=>i});r(7294);var s=r(6010);const t={tabItem:"tabItem_Ymn6"};var a=r(5893);function i(e){let{children:n,hidden:r,className:i}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.Z)(t.tabItem,i),hidden:r,children:n})}},4866:(e,n,r)=>{r.d(n,{Z:()=>w});var s=r(7294),t=r(6010),a=r(2466),i=r(6550),l=r(469),c=r(1980),d=r(7392),o=r(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:r}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:r,attributes:s,default:t}}=e;return{value:n,label:r,attributes:s,default:t}}))}(r);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,r])}function m(e){let{value:n,tabValues:r}=e;return r.some((e=>e.value===n))}function v(e){let{queryString:n=!1,groupId:r}=e;const t=(0,i.k6)(),a=function(e){let{queryString:n=!1,groupId:r}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!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:n,groupId:r});return[(0,c._X)(a),(0,s.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(t.location.search);n.set(a,e),t.replace({...t.location,search:n.toString()})}),[a,t])]}function p(e){const{defaultValue:n,queryString:r=!1,groupId:t}=e,a=h(e),[i,c]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" 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 n}const s=r.find((e=>e.default))??r[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:a}))),[d,u]=v({queryString:r,groupId:t}),[p,f]=function(e){let{groupId:n}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(n),[t,a]=(0,o.Nk)(r);return[t,(0,s.useCallback)((e=>{r&&a.set(e)}),[r,a])]}({groupId:t}),b=(()=>{const e=d??p;return m({value:e,tabValues:a})?e:null})();(0,l.Z)((()=>{b&&c(b)}),[b]);return{selectedValue:i,selectValue:(0,s.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);c(e),u(e),f(e)}),[u,f,a]),tabValues:a}}var f=r(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=r(5893);function y(e){let{className:n,block:r,selectedValue:s,selectValue:i,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:d}=(0,a.o5)(),o=e=>{const n=e.currentTarget,r=c.indexOf(n),t=l[r].value;t!==s&&(d(n),i(t))},u=e=>{let n=null;switch(e.key){case"Enter":o(e);break;case"ArrowRight":{const r=c.indexOf(e.currentTarget)+1;n=c[r]??c[0];break}case"ArrowLeft":{const r=c.indexOf(e.currentTarget)-1;n=c[r]??c[c.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,t.Z)("tabs",{"tabs--block":r},n),children:l.map((e=>{let{value:n,label:r,attributes:a}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>c.push(e),onKeyDown:u,onClick:o,...a,className:(0,t.Z)("tabs__item",b.tabItem,a?.className,{"tabs__item--active":s===n}),children:r??n},n)}))})}function j(e){let{lazy:n,children:r,selectedValue:t}=e;const a=(Array.isArray(r)?r:[r]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===t));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==t})))})}function g(e){const n=p(e);return(0,x.jsxs)("div",{className:(0,t.Z)("tabs-container",b.tabList),children:[(0,x.jsx)(y,{...e,...n}),(0,x.jsx)(j,{...e,...n})]})}function w(e){const n=(0,f.Z)();return(0,x.jsx)(g,{...e,children:u(e.children)},String(n))}},1151:(e,n,r)=>{r.d(n,{Z:()=>l,a:()=>i});var s=r(7294);const t={},a=s.createContext(t);function i(e){const n=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:i(e.components),s.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/436b299f.c2d57882.js b/assets/js/436b299f.ac3af9b8.js similarity index 99% rename from assets/js/436b299f.c2d57882.js rename to assets/js/436b299f.ac3af9b8.js index 4c09217d3..32da0d68c 100644 --- a/assets/js/436b299f.c2d57882.js +++ b/assets/js/436b299f.ac3af9b8.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5077],{8230:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>o,metadata:()=>d,toc:()=>c});var n=r(5893),a=r(1151),s=r(4866),l=r(5162);const o={title:"http-error-handler"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-error-handler.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["Automatically handles uncaught errors that contain the properties ",(0,n.jsx)(t.code,{children:"statusCode"})," (number) and ",(0,n.jsx)(t.code,{children:"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,n.jsx)(t.code,{children:"expose"})," is included with a default value of ",(0,n.jsx)(t.code,{children:"statusCode < 500"}),".\nWe recommend generating these HTTP errors with the npm module ",(0,n.jsx)(t.a,{href:"https://npm.im/http-errors",children:(0,n.jsx)(t.code,{children:"http-errors"})}),". When manually catching and setting errors with ",(0,n.jsx)(t.code,{children:"statusCode >= 500"})," setting ",(0,n.jsx)(t.code,{children:"{expose: true}"}),"\nis needed for them to be handled."]}),"\n",(0,n.jsxs)(t.p,{children:["This middleware should be set as the last error handler attached, first to execute. When non-http errors (those without ",(0,n.jsx)(t.code,{children:"statusCode"}),") occur they will be returned with a 500 status code."]}),"\n",(0,n.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(l.Z,{value:"npm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-error-handler\n"})})}),(0,n.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-error-handler\n"})})}),(0,n.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-error-handler\n"})})})]}),"\n",(0,n.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"logger"})," (defaults to ",(0,n.jsx)(t.code,{children:"console.error"}),") - a logging function that is invoked with the current error as an argument. You can pass ",(0,n.jsx)(t.code,{children:"false"})," if you don't want the logging to happen."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"fallbackMessage"})," (default ",(0,n.jsx)(t.code,{children:"undefined"}),") - When non-http errors (those without ",(0,n.jsx)(t.code,{children:"statusCode"}),") occur you can set a fallback message to be used. These will be returned with a 500 status code."]}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpErrorHandler from '@middy/http-error-handler'\n\nconst lambdaHandler = (event, context) => {\n throw new createError.UnprocessableEntity()\n}\nexport const handler = middy().use(httpErrorHandler()).handler(lambdaHandler)\n\n// when Lambda runs the handler...\nhandler({}, {}, (_, response) => {\n t.deepEqual(response, {\n statusCode: 422,\n body: 'Unprocessable Entity'\n })\n})\n"})})]})}function p(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},5162:(e,t,r)=>{r.d(t,{Z:()=>l});r(7294);var n=r(6010);const a={tabItem:"tabItem_Ymn6"};var s=r(5893);function l(e){let{children:t,hidden:r,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,n.Z)(a.tabItem,l),hidden:r,children:t})}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var n=r(7294),a=r(6010),s=r(2466),l=r(6550),o=r(469),i=r(1980),d=r(7392),u=r(12);function c(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function h(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}(r);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,r])}function p(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:r}=e;const a=(0,l.k6)(),s=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)(s),(0,n.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,s=h(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 n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:s}))),[d,c]=m({queryString:r,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,u.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&s.set(e)}),[r,s])]}({groupId:a}),g=(()=>{const e=d??f;return p({value:e,tabValues:s})?e:null})();(0,o.Z)((()=>{g&&i(g)}),[g]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),b(e)}),[c,b,s]),tabValues:s}}var b=r(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=r(5893);function x(e){let{className:t,block:r,selectedValue:n,selectValue:l,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),u=e=>{const t=e.currentTarget,r=i.indexOf(t),a=o[r].value;a!==n&&(d(t),l(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const r=i.indexOf(e.currentTarget)+1;t=i[r]??i[0];break}case"ArrowLeft":{const r=i.indexOf(e.currentTarget)-1;t=i[r]??i[i.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":r},t),children:o.map((e=>{let{value:t,label:r,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:c,onClick:u,...s,className:(0,a.Z)("tabs__item",g.tabItem,s?.className,{"tabs__item--active":n===t}),children:r??t},t)}))})}function j(e){let{lazy:t,children:r,selectedValue:a}=e;const s=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=f(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",g.tabList),children:[(0,v.jsx)(x,{...e,...t}),(0,v.jsx)(j,{...e,...t})]})}function w(e){const t=(0,b.Z)();return(0,v.jsx)(y,{...e,children:c(e.children)},String(t))}},1151:(e,t,r)=>{r.d(t,{Z:()=>o,a:()=>l});var n=r(7294);const a={},s=n.createContext(a);function l(e){const t=n.useContext(s);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),n.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5077],{8230:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>p,frontMatter:()=>o,metadata:()=>d,toc:()=>c});var n=r(5893),a=r(1151),s=r(4866),l=r(5162);const o={title:"http-error-handler"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-error-handler.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["Automatically handles uncaught errors that contain the properties ",(0,n.jsx)(t.code,{children:"statusCode"})," (number) and ",(0,n.jsx)(t.code,{children:"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,n.jsx)(t.code,{children:"expose"})," is included with a default value of ",(0,n.jsx)(t.code,{children:"statusCode < 500"}),".\nWe recommend generating these HTTP errors with the npm module ",(0,n.jsx)(t.a,{href:"https://npm.im/http-errors",children:(0,n.jsx)(t.code,{children:"http-errors"})}),". When manually catching and setting errors with ",(0,n.jsx)(t.code,{children:"statusCode >= 500"})," setting ",(0,n.jsx)(t.code,{children:"{expose: true}"}),"\nis needed for them to be handled."]}),"\n",(0,n.jsxs)(t.p,{children:["This middleware should be set as the last error handler attached, first to execute. When non-http errors (those without ",(0,n.jsx)(t.code,{children:"statusCode"}),") occur they will be returned with a 500 status code."]}),"\n",(0,n.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(l.Z,{value:"npm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-error-handler\n"})})}),(0,n.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-error-handler\n"})})}),(0,n.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-error-handler\n"})})})]}),"\n",(0,n.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"logger"})," (defaults to ",(0,n.jsx)(t.code,{children:"console.error"}),") - a logging function that is invoked with the current error as an argument. You can pass ",(0,n.jsx)(t.code,{children:"false"})," if you don't want the logging to happen."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"fallbackMessage"})," (default ",(0,n.jsx)(t.code,{children:"undefined"}),") - When non-http errors (those without ",(0,n.jsx)(t.code,{children:"statusCode"}),") occur you can set a fallback message to be used. These will be returned with a 500 status code."]}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpErrorHandler from '@middy/http-error-handler'\n\nconst lambdaHandler = (event, context) => {\n throw new createError.UnprocessableEntity()\n}\nexport const handler = middy().use(httpErrorHandler()).handler(lambdaHandler)\n\n// when Lambda runs the handler...\nhandler({}, {}, (_, response) => {\n t.deepEqual(response, {\n statusCode: 422,\n body: 'Unprocessable Entity'\n })\n})\n"})})]})}function p(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},5162:(e,t,r)=>{r.d(t,{Z:()=>l});r(7294);var n=r(6010);const a={tabItem:"tabItem_Ymn6"};var s=r(5893);function l(e){let{children:t,hidden:r,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,n.Z)(a.tabItem,l),hidden:r,children:t})}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var n=r(7294),a=r(6010),s=r(2466),l=r(6550),o=r(469),i=r(1980),d=r(7392),u=r(12);function c(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function h(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}(r);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,r])}function p(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:r}=e;const a=(0,l.k6)(),s=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)(s),(0,n.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,s=h(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 n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:s}))),[d,c]=m({queryString:r,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,u.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&s.set(e)}),[r,s])]}({groupId:a}),g=(()=>{const e=d??f;return p({value:e,tabValues:s})?e:null})();(0,o.Z)((()=>{g&&i(g)}),[g]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),b(e)}),[c,b,s]),tabValues:s}}var b=r(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=r(5893);function x(e){let{className:t,block:r,selectedValue:n,selectValue:l,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),u=e=>{const t=e.currentTarget,r=i.indexOf(t),a=o[r].value;a!==n&&(d(t),l(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const r=i.indexOf(e.currentTarget)+1;t=i[r]??i[0];break}case"ArrowLeft":{const r=i.indexOf(e.currentTarget)-1;t=i[r]??i[i.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":r},t),children:o.map((e=>{let{value:t,label:r,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:c,onClick:u,...s,className:(0,a.Z)("tabs__item",g.tabItem,s?.className,{"tabs__item--active":n===t}),children:r??t},t)}))})}function j(e){let{lazy:t,children:r,selectedValue:a}=e;const s=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=f(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",g.tabList),children:[(0,v.jsx)(x,{...e,...t}),(0,v.jsx)(j,{...e,...t})]})}function w(e){const t=(0,b.Z)();return(0,v.jsx)(y,{...e,children:c(e.children)},String(t))}},1151:(e,t,r)=>{r.d(t,{Z:()=>o,a:()=>l});var n=r(7294);const a={},s=n.createContext(a);function l(e){const t=n.useContext(s);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),n.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/447662a1.aeee1bc5.js b/assets/js/447662a1.21fb6959.js similarity index 98% rename from assets/js/447662a1.aeee1bc5.js rename to assets/js/447662a1.21fb6959.js index e3ad38b06..1d1918f83 100644 --- a/assets/js/447662a1.aeee1bc5.js +++ b/assets/js/447662a1.21fb6959.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1768],{2912:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>o,default:()=>u,frontMatter:()=>d,metadata:()=>s,toc:()=>l});var r=t(5893),i=t(1151);const d={title:"Configurable Middlewares",position:2},o=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/02-configurable-middlewares.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},a={},l=[];function c(e){const n={code:"code",p:"p",pre:"pre",...(0,i.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.p,{children:["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,r.jsx)(n.code,{children:"before"}),",\n",(0,r.jsx)(n.code,{children:"after"}),", and ",(0,r.jsx)(n.code,{children:"onError"})," as keys."]}),"\n",(0,r.jsx)(n.p,{children:"E.g."}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"// 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"})}),"\n",(0,r.jsx)(n.p,{children:"With this convention in mind, using a middleware will always look like the following example:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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()\n .use(\n customMiddleware({\n option1: 'foo',\n option2: 'bar'\n })\n )\n .handler(lambdaHandler)\n"})})]})}function u(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>s,a:()=>o});var r=t(7294);const i={},d=r.createContext(i);function o(e){const n=r.useContext(d);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function s(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),r.createElement(d.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1768],{2912:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>o,default:()=>u,frontMatter:()=>d,metadata:()=>s,toc:()=>l});var r=t(5893),i=t(1151);const d={title:"Configurable Middlewares",position:2},o=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/02-configurable-middlewares.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},a={},l=[];function c(e){const n={code:"code",p:"p",pre:"pre",...(0,i.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.p,{children:["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,r.jsx)(n.code,{children:"before"}),",\n",(0,r.jsx)(n.code,{children:"after"}),", and ",(0,r.jsx)(n.code,{children:"onError"})," as keys."]}),"\n",(0,r.jsx)(n.p,{children:"E.g."}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"// 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"})}),"\n",(0,r.jsx)(n.p,{children:"With this convention in mind, using a middleware will always look like the following example:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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()\n .use(\n customMiddleware({\n option1: 'foo',\n option2: 'bar'\n })\n )\n .handler(lambdaHandler)\n"})})]})}function u(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>s,a:()=>o});var r=t(7294);const i={},d=r.createContext(i);function o(e){const n=r.useContext(d);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function s(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),r.createElement(d.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4924cac4.cf1fb87d.js b/assets/js/4924cac4.4a207ccf.js similarity index 99% rename from assets/js/4924cac4.cf1fb87d.js rename to assets/js/4924cac4.4a207ccf.js index 3eb6e41ff..ed34ddba8 100644 --- a/assets/js/4924cac4.cf1fb87d.js +++ b/assets/js/4924cac4.4a207ccf.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5270],{6535:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>d,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>c,toc:()=>u});var t=r(5893),s=r(1151),l=r(4866),o=r(5162);const a={title:"http-cors"},i=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-cors.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const n={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:["This middleware sets HTTP CORS headers (",(0,t.jsx)(n.code,{children:"Access-Control-Allow-Origin"}),", ",(0,t.jsx)(n.code,{children:"Access-Control-Allow-Headers"}),", ",(0,t.jsx)(n.code,{children:"Access-Control-Allow-Credentials"}),"), necessary for making cross-origin requests, to the response object."]}),"\n",(0,t.jsxs)(n.p,{children:["Sets headers in ",(0,t.jsx)(n.code,{children:"after"})," and ",(0,t.jsx)(n.code,{children:"onError"})," phases."]}),"\n",(0,t.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,t.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,t.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,t.jsx)(o.Z,{value:"npm",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/http-cors\n"})})}),(0,t.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/http-cors\n"})})}),(0,t.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/http-cors\n"})})})]}),"\n",(0,t.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"credentials"})," (bool) (optional): if true, sets ",(0,t.jsx)(n.code,{children:"Access-Control-Allow-Credentials"})," (default ",(0,t.jsx)(n.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"disableBeforePreflightResponse"})," (bool) (optional): if false, replies automatically to cors preflight requests. Set to true if handling the response in a custom way (default ",(0,t.jsx)(n.code,{children:"true"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"headers"})," (string) (optional): value to put in ",(0,t.jsx)(n.code,{children:"Access-Control-Allow-Headers"})," (default: ",(0,t.jsx)(n.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"methods"})," (string) (optional): value to put in ",(0,t.jsx)(n.code,{children:"Access-Control-Allow-Methods"})," (default: ",(0,t.jsx)(n.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"getOrigin"})," (function(incomingOrigin",":string",", options)) (optional): take full control of the generating the returned origin. Defaults to using the origin or origins option."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"origin"}),' (string) (optional): origin to put in the header (default: "',(0,t.jsx)(n.code,{children:"*"}),'")']}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"origins"})," (array) (optional): An array of allowed origins. The incoming origin is matched against the list and is returned if present."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"exposeHeaders"})," (string) (optional): value to put in ",(0,t.jsx)(n.code,{children:"Access-Control-Expose-Headers"})," (default: ",(0,t.jsx)(n.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"maxAge"})," (string) (optional): value to put in Access-Control-Max-Age header (default: ",(0,t.jsx)(n.code,{children:"null"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"requestHeaders"})," (string) (optional): value to put in ",(0,t.jsx)(n.code,{children:"Access-Control-Request-Headers"})," (default: ",(0,t.jsx)(n.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"requestMethods"})," (string) (optional): value to put in ",(0,t.jsx)(n.code,{children:"Access-Control-Request-Methods"})," (default: ",(0,t.jsx)(n.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"cacheControl"})," (string) (optional): value to put in Cache-Control header on pre-flight (OPTIONS) requests (default: ",(0,t.jsx)(n.code,{children:"null"}),")"]}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpErrorHandler from '@middy/http-error-handler'\nimport cors from '@middy/http-cors'\n\nconst lambdaHandler = (event, context) => {\n throw new createError.UnprocessableEntity()\n}\nexport const handler = middy()\n .use(httpErrorHandler())\n .use(cors())\n .handler(lambdaHandler)\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"})}),"\n",(0,t.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport cors from '@middy/http-cors'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\nexport const handler = middy().use(cors()).handler(lambdaHandler)\n\n// when Lambda runs the handler...\nhandler({}, {}, (_, response) => {\n t.is(response.headers['Access-Control-Allow-Origin'], '*')\n})\n"})})]})}function p(e={}){const{wrapper:n}={...(0,s.a)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(h,{...e})}):h(e)}},5162:(e,n,r)=>{r.d(n,{Z:()=>o});r(7294);var t=r(6010);const s={tabItem:"tabItem_Ymn6"};var l=r(5893);function o(e){let{children:n,hidden:r,className:o}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,t.Z)(s.tabItem,o),hidden:r,children:n})}},4866:(e,n,r)=>{r.d(n,{Z:()=>w});var t=r(7294),s=r(6010),l=r(2466),o=r(6550),a=r(469),i=r(1980),c=r(7392),d=r(12);function u(e){return t.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:r}=e;return(0,t.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:r,attributes:t,default:s}}=e;return{value:n,label:r,attributes:t,default:s}}))}(r);return function(e){const n=(0,c.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,r])}function p(e){let{value:n,tabValues:r}=e;return r.some((e=>e.value===n))}function m(e){let{queryString:n=!1,groupId:r}=e;const s=(0,o.k6)(),l=function(e){let{queryString:n=!1,groupId:r}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!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:n,groupId:r});return[(0,i._X)(l),(0,t.useCallback)((e=>{if(!l)return;const n=new URLSearchParams(s.location.search);n.set(l,e),s.replace({...s.location,search:n.toString()})}),[l,s])]}function f(e){const{defaultValue:n,queryString:r=!1,groupId:s}=e,l=h(e),[o,i]=(0,t.useState)((()=>function(e){let{defaultValue:n,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" 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 n}const t=r.find((e=>e.default))??r[0];if(!t)throw new Error("Unexpected error: 0 tabValues");return t.value}({defaultValue:n,tabValues:l}))),[c,u]=m({queryString:r,groupId:s}),[f,x]=function(e){let{groupId:n}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(n),[s,l]=(0,d.Nk)(r);return[s,(0,t.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:s}),g=(()=>{const e=c??f;return p({value:e,tabValues:l})?e:null})();(0,a.Z)((()=>{g&&i(g)}),[g]);return{selectedValue:o,selectValue:(0,t.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),x(e)}),[u,x,l]),tabValues:l}}var x=r(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=r(5893);function j(e){let{className:n,block:r,selectedValue:t,selectValue:o,tabValues:a}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,l.o5)(),d=e=>{const n=e.currentTarget,r=i.indexOf(n),s=a[r].value;s!==t&&(c(n),o(s))},u=e=>{let n=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const r=i.indexOf(e.currentTarget)+1;n=i[r]??i[0];break}case"ArrowLeft":{const r=i.indexOf(e.currentTarget)-1;n=i[r]??i[i.length-1];break}}n?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":r},n),children:a.map((e=>{let{value:n,label:r,attributes:l}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:t===n?0:-1,"aria-selected":t===n,ref:e=>i.push(e),onKeyDown:u,onClick:d,...l,className:(0,s.Z)("tabs__item",g.tabItem,l?.className,{"tabs__item--active":t===n}),children:r??n},n)}))})}function v(e){let{lazy:n,children:r,selectedValue:s}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(n){const e=l.find((e=>e.props.value===s));return e?(0,t.cloneElement)(e,{className:"margin-top--md"}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:l.map(((e,n)=>(0,t.cloneElement)(e,{key:n,hidden:e.props.value!==s})))})}function y(e){const n=f(e);return(0,b.jsxs)("div",{className:(0,s.Z)("tabs-container",g.tabList),children:[(0,b.jsx)(j,{...e,...n}),(0,b.jsx)(v,{...e,...n})]})}function w(e){const n=(0,x.Z)();return(0,b.jsx)(y,{...e,children:u(e.children)},String(n))}},1151:(e,n,r)=>{r.d(n,{Z:()=>a,a:()=>o});var t=r(7294);const s={},l=t.createContext(s);function o(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5270],{6535:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>d,contentTitle:()=>i,default:()=>p,frontMatter:()=>a,metadata:()=>c,toc:()=>u});var t=r(5893),s=r(1151),l=r(4866),o=r(5162);const a={title:"http-cors"},i=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-cors.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const n={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:["This middleware sets HTTP CORS headers (",(0,t.jsx)(n.code,{children:"Access-Control-Allow-Origin"}),", ",(0,t.jsx)(n.code,{children:"Access-Control-Allow-Headers"}),", ",(0,t.jsx)(n.code,{children:"Access-Control-Allow-Credentials"}),"), necessary for making cross-origin requests, to the response object."]}),"\n",(0,t.jsxs)(n.p,{children:["Sets headers in ",(0,t.jsx)(n.code,{children:"after"})," and ",(0,t.jsx)(n.code,{children:"onError"})," phases."]}),"\n",(0,t.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,t.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,t.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,t.jsx)(o.Z,{value:"npm",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/http-cors\n"})})}),(0,t.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/http-cors\n"})})}),(0,t.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/http-cors\n"})})})]}),"\n",(0,t.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"credentials"})," (bool) (optional): if true, sets ",(0,t.jsx)(n.code,{children:"Access-Control-Allow-Credentials"})," (default ",(0,t.jsx)(n.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"disableBeforePreflightResponse"})," (bool) (optional): if false, replies automatically to cors preflight requests. Set to true if handling the response in a custom way (default ",(0,t.jsx)(n.code,{children:"true"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"headers"})," (string) (optional): value to put in ",(0,t.jsx)(n.code,{children:"Access-Control-Allow-Headers"})," (default: ",(0,t.jsx)(n.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"methods"})," (string) (optional): value to put in ",(0,t.jsx)(n.code,{children:"Access-Control-Allow-Methods"})," (default: ",(0,t.jsx)(n.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"getOrigin"})," (function(incomingOrigin",":string",", options)) (optional): take full control of the generating the returned origin. Defaults to using the origin or origins option."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"origin"}),' (string) (optional): origin to put in the header (default: "',(0,t.jsx)(n.code,{children:"*"}),'")']}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"origins"})," (array) (optional): An array of allowed origins. The incoming origin is matched against the list and is returned if present."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"exposeHeaders"})," (string) (optional): value to put in ",(0,t.jsx)(n.code,{children:"Access-Control-Expose-Headers"})," (default: ",(0,t.jsx)(n.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"maxAge"})," (string) (optional): value to put in Access-Control-Max-Age header (default: ",(0,t.jsx)(n.code,{children:"null"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"requestHeaders"})," (string) (optional): value to put in ",(0,t.jsx)(n.code,{children:"Access-Control-Request-Headers"})," (default: ",(0,t.jsx)(n.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"requestMethods"})," (string) (optional): value to put in ",(0,t.jsx)(n.code,{children:"Access-Control-Request-Methods"})," (default: ",(0,t.jsx)(n.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"cacheControl"})," (string) (optional): value to put in Cache-Control header on pre-flight (OPTIONS) requests (default: ",(0,t.jsx)(n.code,{children:"null"}),")"]}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpErrorHandler from '@middy/http-error-handler'\nimport cors from '@middy/http-cors'\n\nconst lambdaHandler = (event, context) => {\n throw new createError.UnprocessableEntity()\n}\nexport const handler = middy()\n .use(httpErrorHandler())\n .use(cors())\n .handler(lambdaHandler)\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"})}),"\n",(0,t.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport cors from '@middy/http-cors'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\nexport const handler = middy().use(cors()).handler(lambdaHandler)\n\n// when Lambda runs the handler...\nhandler({}, {}, (_, response) => {\n t.is(response.headers['Access-Control-Allow-Origin'], '*')\n})\n"})})]})}function p(e={}){const{wrapper:n}={...(0,s.a)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(h,{...e})}):h(e)}},5162:(e,n,r)=>{r.d(n,{Z:()=>o});r(7294);var t=r(6010);const s={tabItem:"tabItem_Ymn6"};var l=r(5893);function o(e){let{children:n,hidden:r,className:o}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,t.Z)(s.tabItem,o),hidden:r,children:n})}},4866:(e,n,r)=>{r.d(n,{Z:()=>w});var t=r(7294),s=r(6010),l=r(2466),o=r(6550),a=r(469),i=r(1980),c=r(7392),d=r(12);function u(e){return t.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:r}=e;return(0,t.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:r,attributes:t,default:s}}=e;return{value:n,label:r,attributes:t,default:s}}))}(r);return function(e){const n=(0,c.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,r])}function p(e){let{value:n,tabValues:r}=e;return r.some((e=>e.value===n))}function m(e){let{queryString:n=!1,groupId:r}=e;const s=(0,o.k6)(),l=function(e){let{queryString:n=!1,groupId:r}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!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:n,groupId:r});return[(0,i._X)(l),(0,t.useCallback)((e=>{if(!l)return;const n=new URLSearchParams(s.location.search);n.set(l,e),s.replace({...s.location,search:n.toString()})}),[l,s])]}function f(e){const{defaultValue:n,queryString:r=!1,groupId:s}=e,l=h(e),[o,i]=(0,t.useState)((()=>function(e){let{defaultValue:n,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" 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 n}const t=r.find((e=>e.default))??r[0];if(!t)throw new Error("Unexpected error: 0 tabValues");return t.value}({defaultValue:n,tabValues:l}))),[c,u]=m({queryString:r,groupId:s}),[f,x]=function(e){let{groupId:n}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(n),[s,l]=(0,d.Nk)(r);return[s,(0,t.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:s}),g=(()=>{const e=c??f;return p({value:e,tabValues:l})?e:null})();(0,a.Z)((()=>{g&&i(g)}),[g]);return{selectedValue:o,selectValue:(0,t.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),x(e)}),[u,x,l]),tabValues:l}}var x=r(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=r(5893);function j(e){let{className:n,block:r,selectedValue:t,selectValue:o,tabValues:a}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,l.o5)(),d=e=>{const n=e.currentTarget,r=i.indexOf(n),s=a[r].value;s!==t&&(c(n),o(s))},u=e=>{let n=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const r=i.indexOf(e.currentTarget)+1;n=i[r]??i[0];break}case"ArrowLeft":{const r=i.indexOf(e.currentTarget)-1;n=i[r]??i[i.length-1];break}}n?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":r},n),children:a.map((e=>{let{value:n,label:r,attributes:l}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:t===n?0:-1,"aria-selected":t===n,ref:e=>i.push(e),onKeyDown:u,onClick:d,...l,className:(0,s.Z)("tabs__item",g.tabItem,l?.className,{"tabs__item--active":t===n}),children:r??n},n)}))})}function v(e){let{lazy:n,children:r,selectedValue:s}=e;const l=(Array.isArray(r)?r:[r]).filter(Boolean);if(n){const e=l.find((e=>e.props.value===s));return e?(0,t.cloneElement)(e,{className:"margin-top--md"}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:l.map(((e,n)=>(0,t.cloneElement)(e,{key:n,hidden:e.props.value!==s})))})}function y(e){const n=f(e);return(0,b.jsxs)("div",{className:(0,s.Z)("tabs-container",g.tabList),children:[(0,b.jsx)(j,{...e,...n}),(0,b.jsx)(v,{...e,...n})]})}function w(e){const n=(0,x.Z)();return(0,b.jsx)(y,{...e,children:u(e.children)},String(n))}},1151:(e,n,r)=>{r.d(n,{Z:()=>a,a:()=>o});var t=r(7294);const s={},l=t.createContext(s);function o(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/49fe1afb.0a61e2bb.js b/assets/js/49fe1afb.f3a64d86.js similarity index 98% rename from assets/js/49fe1afb.0a61e2bb.js rename to assets/js/49fe1afb.f3a64d86.js index 32901ebe9..46fc91d01 100644 --- a/assets/js/49fe1afb.0a61e2bb.js +++ b/assets/js/49fe1afb.f3a64d86.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9076],{4451:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>l,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var i=r(5893),n=r(1151);const o={title:"With TypeScript",position:7},a=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/07-with-typescript.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[];function p(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,n.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.p,{children:"here's an example of how you can write a custom middleware for a Lambda receiving events from API Gateway:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-typescript",children:"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"})}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.strong,{children:"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"]}),"\n",(0,i.jsxs)(t.p,{children:["See ",(0,i.jsx)(t.code,{children:"devDependencies"})," for each middleware for list of dependencies that may be required with transpiling TypeScript."]})]})}function l(e={}){const{wrapper:t}={...(0,n.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(p,{...e})}):p(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>s,a:()=>a});var i=r(7294);const n={},o=i.createContext(n);function a(e){const t=i.useContext(o);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:a(e.components),i.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9076],{4451:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>l,frontMatter:()=>o,metadata:()=>s,toc:()=>c});var i=r(5893),n=r(1151);const o={title:"With TypeScript",position:7},a=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/07-with-typescript.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[];function p(e){const t={code:"code",p:"p",pre:"pre",strong:"strong",...(0,n.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.p,{children:"here's an example of how you can write a custom middleware for a Lambda receiving events from API Gateway:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-typescript",children:"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"})}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.strong,{children:"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"]}),"\n",(0,i.jsxs)(t.p,{children:["See ",(0,i.jsx)(t.code,{children:"devDependencies"})," for each middleware for list of dependencies that may be required with transpiling TypeScript."]})]})}function l(e={}){const{wrapper:t}={...(0,n.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(p,{...e})}):p(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>s,a:()=>a});var i=r(7294);const n={},o=i.createContext(n);function a(e){const t=i.useContext(o);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:a(e.components),i.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4f3a9363.4298b16b.js b/assets/js/4f3a9363.a207c258.js similarity index 97% rename from assets/js/4f3a9363.4298b16b.js rename to assets/js/4f3a9363.a207c258.js index 7258efedf..10a16c573 100644 --- a/assets/js/4f3a9363.4298b16b.js +++ b/assets/js/4f3a9363.a207c258.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8852],{3238:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>m,frontMatter:()=>s,metadata:()=>d,toc:()=>r});var o=n(5893),i=n(1151);const s={title:"DocumentDB"},a=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/documentdb.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"DocumentDB"},sidebar:"tutorialSidebar",previous:{title:"Connect",permalink:"/docs/events/connect"},next:{title:"DynamoDB",permalink:"/docs/events/dynamodb"}},c={},r=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb.html",children:"Using AWS Lambda with Amazon DocumentDB"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>d,a:()=>a});var o=n(7294);const i={},s=o.createContext(i);function a(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8852],{3238:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>m,frontMatter:()=>s,metadata:()=>d,toc:()=>r});var o=n(5893),i=n(1151);const s={title:"DocumentDB"},a=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/documentdb.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"DocumentDB"},sidebar:"tutorialSidebar",previous:{title:"Connect",permalink:"/docs/events/connect"},next:{title:"DynamoDB",permalink:"/docs/events/dynamodb"}},c={},r=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb.html",children:"Using AWS Lambda with Amazon DocumentDB"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>d,a:()=>a});var o=n(7294);const i={},s=o.createContext(i);function a(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/5018e04c.ea56202a.js b/assets/js/5018e04c.88b6cdb3.js similarity index 98% rename from assets/js/5018e04c.ea56202a.js rename to assets/js/5018e04c.88b6cdb3.js index f60f5a664..b44141fbe 100644 --- a/assets/js/5018e04c.ea56202a.js +++ b/assets/js/5018e04c.88b6cdb3.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9862],{2258:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>l,frontMatter:()=>s,metadata:()=>o,toc:()=>c});var i=n(5893),r=n(1151);const s={title:"Use with TypeScript",position:6},a=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/06-typescript.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[];function p(e){const t={a:"a",code:"code",em:"em",p:"p",pre:"pre",...(0,r.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.p,{children:"Middy can be used with TypeScript with typings built in in every official package."}),"\n",(0,i.jsx)(t.p,{children:"Here's an example of how you might be using Middy with TypeScript for a Lambda receiving events from API Gateway and fetching secrets from Secrets Manager:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-typescript",children:"import middy from '@middy/core'\nimport secretsManager from '@middy/secrets-manager'\nimport { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'\n\nexport const handler = middy()\n .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 .handler(async (req, context) => {\n // The context type gets augmented here by the secretsManager middleware.\n // This is just an example, obviously don't ever log your secret in real life!\n console.log(context.apiToken)\n return {\n statusCode: 200,\n body: JSON.stringify({\n message: `Hello from ${event.path}`,\n req\n }),\n }\n })\n"})}),"\n",(0,i.jsxs)(t.p,{children:["Note that when using TypeScript, you should use what we call the ",(0,i.jsx)(t.em,{children:"Middleware-first, Handler-last"})," approach, which means that you should always call the ",(0,i.jsx)(t.code,{children:"handler"})," method last, after you have attached all the middlewares you need."]}),"\n",(0,i.jsxs)(t.p,{children:["This approach makes sure that, as you attach middlewares, the type system understands how the ",(0,i.jsx)(t.code,{children:"event"})," and the ",(0,i.jsx)(t.code,{children:"context"})," arguments are augmented by the various middlewares and inside your handler code you can have a nice type-checking and auto-completion experience."]}),"\n",(0,i.jsxs)(t.p,{children:["You can also ",(0,i.jsx)(t.a,{href:"/docs/writing-middlewares/intro",children:"write custom middlewares with TypeScript"}),"."]})]})}function l(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(p,{...e})}):p(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>o,a:()=>a});var i=n(7294);const r={},s=i.createContext(r);function a(e){const t=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),i.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9862],{2258:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>l,frontMatter:()=>s,metadata:()=>o,toc:()=>c});var i=n(5893),r=n(1151);const s={title:"Use with TypeScript",position:6},a=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/06-typescript.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[];function p(e){const t={a:"a",code:"code",em:"em",p:"p",pre:"pre",...(0,r.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.p,{children:"Middy can be used with TypeScript with typings built in in every official package."}),"\n",(0,i.jsx)(t.p,{children:"Here's an example of how you might be using Middy with TypeScript for a Lambda receiving events from API Gateway and fetching secrets from Secrets Manager:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-typescript",children:"import middy from '@middy/core'\nimport secretsManager from '@middy/secrets-manager'\nimport { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'\n\nexport const handler = middy()\n .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 .handler(async (req, context) => {\n // The context type gets augmented here by the secretsManager middleware.\n // This is just an example, obviously don't ever log your secret in real life!\n console.log(context.apiToken)\n return {\n statusCode: 200,\n body: JSON.stringify({\n message: `Hello from ${event.path}`,\n req\n }),\n }\n })\n"})}),"\n",(0,i.jsxs)(t.p,{children:["Note that when using TypeScript, you should use what we call the ",(0,i.jsx)(t.em,{children:"Middleware-first, Handler-last"})," approach, which means that you should always call the ",(0,i.jsx)(t.code,{children:"handler"})," method last, after you have attached all the middlewares you need."]}),"\n",(0,i.jsxs)(t.p,{children:["This approach makes sure that, as you attach middlewares, the type system understands how the ",(0,i.jsx)(t.code,{children:"event"})," and the ",(0,i.jsx)(t.code,{children:"context"})," arguments are augmented by the various middlewares and inside your handler code you can have a nice type-checking and auto-completion experience."]}),"\n",(0,i.jsxs)(t.p,{children:["You can also ",(0,i.jsx)(t.a,{href:"/docs/writing-middlewares/intro",children:"write custom middlewares with TypeScript"}),"."]})]})}function l(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(p,{...e})}):p(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>o,a:()=>a});var i=n(7294);const r={},s=i.createContext(r);function a(e){const t=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),i.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/52912c74.167c51c0.js b/assets/js/52912c74.c70a3684.js similarity index 97% rename from assets/js/52912c74.167c51c0.js rename to assets/js/52912c74.c70a3684.js index f9611dc19..45d79f652 100644 --- a/assets/js/52912c74.167c51c0.js +++ b/assets/js/52912c74.c70a3684.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7452],{949:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>u,frontMatter:()=>s,metadata:()=>a,toc:()=>c});var i=n(5893),o=n(1151);const s={title:"EventBridge"},r=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/event-bridge.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"EventBridge"},sidebar:"tutorialSidebar",previous:{title:"EC2",permalink:"/docs/events/ec2"},next:{title:"Function URL",permalink:"/docs/events/function-url"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.admonition,{type:"caution",children:(0,i.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:(0,i.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html",children:"Using AWS Lambda with Amazon EventBridge (CloudWatch Events)"})}),"\n"]}),"\n",(0,i.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n"})})]})}function u(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>a,a:()=>r});var i=n(7294);const o={},s=i.createContext(o);function r(e){const t=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),i.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7452],{949:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>u,frontMatter:()=>s,metadata:()=>a,toc:()=>c});var i=n(5893),o=n(1151);const s={title:"EventBridge"},r=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/event-bridge.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"EventBridge"},sidebar:"tutorialSidebar",previous:{title:"EC2",permalink:"/docs/events/ec2"},next:{title:"Function URL",permalink:"/docs/events/function-url"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.admonition,{type:"caution",children:(0,i.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:(0,i.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html",children:"Using AWS Lambda with Amazon EventBridge (CloudWatch Events)"})}),"\n"]}),"\n",(0,i.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n"})})]})}function u(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>a,a:()=>r});var i=n(7294);const o={},s=i.createContext(o);function r(e){const t=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),i.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/53f1e98a.4aba1086.js b/assets/js/53f1e98a.2b2f7dd3.js similarity index 97% rename from assets/js/53f1e98a.4aba1086.js rename to assets/js/53f1e98a.2b2f7dd3.js index 2658f6146..09062dbf9 100644 --- a/assets/js/53f1e98a.4aba1086.js +++ b/assets/js/53f1e98a.2b2f7dd3.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2469],{3099:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>r,toc:()=>c});var s=n(5893),i=n(1151);const o={title:"S3"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/s3.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"S3"},sidebar:"tutorialSidebar",previous:{title:"S3 Object",permalink:"/docs/events/s3-object"},next:{title:"Secrets Manager",permalink:"/docs/events/secrets-manager"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html",children:"Using AWS Lambda with Amazon S3"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var s=n(7294);const i={},o=s.createContext(i);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2469],{3099:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>r,toc:()=>c});var s=n(5893),i=n(1151);const o={title:"S3"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/s3.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"S3"},sidebar:"tutorialSidebar",previous:{title:"S3 Object",permalink:"/docs/events/s3-object"},next:{title:"Secrets Manager",permalink:"/docs/events/secrets-manager"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html",children:"Using AWS Lambda with Amazon S3"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var s=n(7294);const i={},o=s.createContext(i);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/54ed1cf2.5990bf7a.js b/assets/js/54ed1cf2.8dcf3088.js similarity index 99% rename from assets/js/54ed1cf2.5990bf7a.js rename to assets/js/54ed1cf2.8dcf3088.js index 383de7145..0e2330d60 100644 --- a/assets/js/54ed1cf2.5990bf7a.js +++ b/assets/js/54ed1cf2.8dcf3088.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6827],{5837:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>h,frontMatter:()=>s,metadata:()=>i,toc:()=>l});var r=n(5893),o=n(1151);const s={title:"Profiling",sidebar_position:7},a=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/07-profiling.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[{value:"Time",id:"time",level:2},{value:"Memory",id:"memory",level:2}];function c(e){const t={code:"code",h2:"h2",p:"p",pre:"pre",...(0,o.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["Inside of ",(0,r.jsx)(t.code,{children:"@middy/core"})," we've added some hook before and after every middleware called, the handler and from start to end of it's execution."]}),"\n",(0,r.jsx)(t.h2,{id:"time",children:"Time"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"\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"})}),"\n",(0,r.jsx)(t.p,{children:"This will log out something this:"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-shell",children:"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"})}),"\n",(0,r.jsxs)(t.p,{children:["From this everything looks good. Sub 1ms for every middleware and the handler. But wait, that ",(0,r.jsx)(t.code,{children:"total"})," doesn't look right.\nYou're correct, ",(0,r.jsx)(t.code,{children:"total"})," includes the initial setup time (or cold start time) for all middlewares. In this case ",(0,r.jsx)(t.code,{children:"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,r.jsx)(t.code,{children:"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."]}),"\n",(0,r.jsxs)(t.p,{children:["There is also a ",(0,r.jsx)(t.code,{children:"beforeRequest"})," hook, but was left out of the example for dramatic effect."]}),"\n",(0,r.jsx)(t.p,{children:"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."}),"\n",(0,r.jsx)(t.h2,{id:"memory",children:"Memory"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function h(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>i,a:()=>a});var r=n(7294);const o={},s=r.createContext(o);function a(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6827],{5837:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>h,frontMatter:()=>s,metadata:()=>i,toc:()=>l});var r=n(5893),o=n(1151);const s={title:"Profiling",sidebar_position:7},a=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/07-profiling.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[{value:"Time",id:"time",level:2},{value:"Memory",id:"memory",level:2}];function c(e){const t={code:"code",h2:"h2",p:"p",pre:"pre",...(0,o.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["Inside of ",(0,r.jsx)(t.code,{children:"@middy/core"})," we've added some hook before and after every middleware called, the handler and from start to end of it's execution."]}),"\n",(0,r.jsx)(t.h2,{id:"time",children:"Time"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"\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"})}),"\n",(0,r.jsx)(t.p,{children:"This will log out something this:"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-shell",children:"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"})}),"\n",(0,r.jsxs)(t.p,{children:["From this everything looks good. Sub 1ms for every middleware and the handler. But wait, that ",(0,r.jsx)(t.code,{children:"total"})," doesn't look right.\nYou're correct, ",(0,r.jsx)(t.code,{children:"total"})," includes the initial setup time (or cold start time) for all middlewares. In this case ",(0,r.jsx)(t.code,{children:"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,r.jsx)(t.code,{children:"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."]}),"\n",(0,r.jsxs)(t.p,{children:["There is also a ",(0,r.jsx)(t.code,{children:"beforeRequest"})," hook, but was left out of the example for dramatic effect."]}),"\n",(0,r.jsx)(t.p,{children:"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."}),"\n",(0,r.jsx)(t.h2,{id:"memory",children:"Memory"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function h(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>i,a:()=>a});var r=n(7294);const o={},s=r.createContext(o);function a(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/54fc444e.0c797511.js b/assets/js/54fc444e.79332862.js similarity index 97% rename from assets/js/54fc444e.0c797511.js rename to assets/js/54fc444e.79332862.js index f7b94ad8f..604ed30d6 100644 --- a/assets/js/54fc444e.0c797511.js +++ b/assets/js/54fc444e.79332862.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1790],{737:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=n(5893),o=n(1151);const i={title:"Connection reuse",sidebar_position:2},r=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/02-connection-reuse.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},a={},d=[];function l(e){const t={a:"a",code:"code",p:"p",pre:"pre",...(0,o.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.p,{children:"Be sure to set the following environment variable when connecting to AWS services:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-plain",children:"AWS_NODEJS_CONNECTION_REUSE_ENABLED=1\n"})}),"\n",(0,s.jsx)(t.p,{children:"This allows you to reuse the first connection established across lambda invocations."}),"\n",(0,s.jsxs)(t.p,{children:["See ",(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/node-reusing-connections.html",children:"Reusing Connections with Keep-Alive in Node.js"})]})]})}function p(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>c,a:()=>r});var s=n(7294);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1790],{737:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=n(5893),o=n(1151);const i={title:"Connection reuse",sidebar_position:2},r=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/02-connection-reuse.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},a={},d=[];function l(e){const t={a:"a",code:"code",p:"p",pre:"pre",...(0,o.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.p,{children:"Be sure to set the following environment variable when connecting to AWS services:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-plain",children:"AWS_NODEJS_CONNECTION_REUSE_ENABLED=1\n"})}),"\n",(0,s.jsx)(t.p,{children:"This allows you to reuse the first connection established across lambda invocations."}),"\n",(0,s.jsxs)(t.p,{children:["See ",(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/node-reusing-connections.html",children:"Reusing Connections with Keep-Alive in Node.js"})]})]})}function p(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>c,a:()=>r});var s=n(7294);const o={},i=s.createContext(o);function r(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/56ed1c64.6a27c727.js b/assets/js/56ed1c64.e00611d3.js similarity index 98% rename from assets/js/56ed1c64.6a27c727.js rename to assets/js/56ed1c64.e00611d3.js index a0428b3ad..17b59435c 100644 --- a/assets/js/56ed1c64.6a27c727.js +++ b/assets/js/56ed1c64.e00611d3.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4097],{8928:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>i,contentTitle:()=>d,default:()=>m,frontMatter:()=>s,metadata:()=>o,toc:()=>c});var r=t(5893),a=t(1151);const s={title:"All AWS Events",position:1},d=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/01-intro.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},i={},c=[{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}];function l(e){const n={code:"code",h2:"h2",p:"p",pre:"pre",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.p,{children:"Middy is built to help with all AWS Events that can connect with AWS Lambda."}),"\n",(0,r.jsx)(n.h2,{id:"middlewares-that-can-benefit-any-lambda",children:"Middlewares that can benefit any Lambda"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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"})}),"\n",(0,r.jsx)(n.h2,{id:"need-secrets-we-have-you-covered-there-too",children:"Need secrets? We have you covered there too"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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 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"})}),"\n",(0,r.jsx)(n.h2,{id:"how-about-configs-we-have-you-covered-there-as-well",children:"How about configs? We have you covered there as well"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:n}={...(0,a.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>o,a:()=>d});var r=t(7294);const a={},s=r.createContext(a);function d(e){const n=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:d(e.components),r.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4097],{8928:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>i,contentTitle:()=>d,default:()=>m,frontMatter:()=>s,metadata:()=>o,toc:()=>c});var r=t(5893),a=t(1151);const s={title:"All AWS Events",position:1},d=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/01-intro.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},i={},c=[{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}];function l(e){const n={code:"code",h2:"h2",p:"p",pre:"pre",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.p,{children:"Middy is built to help with all AWS Events that can connect with AWS Lambda."}),"\n",(0,r.jsx)(n.h2,{id:"middlewares-that-can-benefit-any-lambda",children:"Middlewares that can benefit any Lambda"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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"})}),"\n",(0,r.jsx)(n.h2,{id:"need-secrets-we-have-you-covered-there-too",children:"Need secrets? We have you covered there too"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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 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"})}),"\n",(0,r.jsx)(n.h2,{id:"how-about-configs-we-have-you-covered-there-as-well",children:"How about configs? We have you covered there as well"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:n}={...(0,a.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>o,a:()=>d});var r=t(7294);const a={},s=r.createContext(a);function d(e){const n=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:d(e.components),r.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/58ba397f.7c21f350.js b/assets/js/58ba397f.442facd5.js similarity index 99% rename from assets/js/58ba397f.7c21f350.js rename to assets/js/58ba397f.442facd5.js index 4f9a27922..b5690dd74 100644 --- a/assets/js/58ba397f.7c21f350.js +++ b/assets/js/58ba397f.442facd5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1497],{7095:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>u,default:()=>h,frontMatter:()=>o,metadata:()=>i,toc:()=>c});var r=n(5893),a=n(1151),s=n(4866),l=n(5162);const o={title:"http-urlencode-path-parser"},u=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-urlencode-path-parser.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={code:"code",h2:"h2",p:"p",pre:"pre",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["This middleware automatically parses HTTP requests with URL-encoded paths. This can happen when using path variables (ie ",(0,r.jsx)(t.code,{children:"/{name}/"}),") for an endpoint and the UI ",(0,r.jsx)(t.code,{children:"encodeURIComponent"})," the values before making the request."]}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(l.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-urlencode-path-parser\n"})})}),(0,r.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-urlencode-path-parser\n"})})}),(0,r.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-urlencode-path-parser\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsx)(t.p,{children:"None"}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>l});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function l(e){let{children:t,hidden:n,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,l),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>j});var r=n(7294),a=n(6010),s=n(2466),l=n(6550),o=n(469),u=n(1980),i=n(7392),d=n(12);function c(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);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,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.k6)(),s=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)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=p(e),[l,u]=(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(!h({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:s}))),[i,c]=m({queryString:n,groupId:a}),[b,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,d.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),v=(()=>{const e=i??b;return h({value:e,tabValues:s})?e:null})();(0,o.Z)((()=>{v&&u(v)}),[v]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);u(e),c(e),f(e)}),[c,f,s]),tabValues:s}}var f=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=n(5893);function y(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:o}=e;const u=[],{blockElementScrollPositionUntilNextRender:i}=(0,s.o5)(),d=e=>{const t=e.currentTarget,n=u.indexOf(t),a=o[n].value;a!==r&&(i(t),l(a))},c=e=>{let t=null;switch(e.key){case"Enter":d(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(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:c,onClick:d,...s,className:(0,a.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=b(e);return(0,g.jsxs)("div",{className:(0,a.Z)("tabs-container",v.tabList),children:[(0,g.jsx)(y,{...e,...t}),(0,g.jsx)(x,{...e,...t})]})}function j(e){const t=(0,f.Z)();return(0,g.jsx)(w,{...e,children:c(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>o,a:()=>l});var r=n(7294);const a={},s=r.createContext(a);function l(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1497],{7095:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>u,default:()=>h,frontMatter:()=>o,metadata:()=>i,toc:()=>c});var r=n(5893),a=n(1151),s=n(4866),l=n(5162);const o={title:"http-urlencode-path-parser"},u=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-urlencode-path-parser.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={code:"code",h2:"h2",p:"p",pre:"pre",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["This middleware automatically parses HTTP requests with URL-encoded paths. This can happen when using path variables (ie ",(0,r.jsx)(t.code,{children:"/{name}/"}),") for an endpoint and the UI ",(0,r.jsx)(t.code,{children:"encodeURIComponent"})," the values before making the request."]}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(l.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-urlencode-path-parser\n"})})}),(0,r.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-urlencode-path-parser\n"})})}),(0,r.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-urlencode-path-parser\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsx)(t.p,{children:"None"}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>l});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function l(e){let{children:t,hidden:n,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,l),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>j});var r=n(7294),a=n(6010),s=n(2466),l=n(6550),o=n(469),u=n(1980),i=n(7392),d=n(12);function c(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);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,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.k6)(),s=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)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=p(e),[l,u]=(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(!h({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:s}))),[i,c]=m({queryString:n,groupId:a}),[b,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,d.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),v=(()=>{const e=i??b;return h({value:e,tabValues:s})?e:null})();(0,o.Z)((()=>{v&&u(v)}),[v]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);u(e),c(e),f(e)}),[c,f,s]),tabValues:s}}var f=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=n(5893);function y(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:o}=e;const u=[],{blockElementScrollPositionUntilNextRender:i}=(0,s.o5)(),d=e=>{const t=e.currentTarget,n=u.indexOf(t),a=o[n].value;a!==r&&(i(t),l(a))},c=e=>{let t=null;switch(e.key){case"Enter":d(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(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:c,onClick:d,...s,className:(0,a.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=b(e);return(0,g.jsxs)("div",{className:(0,a.Z)("tabs-container",v.tabList),children:[(0,g.jsx)(y,{...e,...t}),(0,g.jsx)(x,{...e,...t})]})}function j(e){const t=(0,f.Z)();return(0,g.jsx)(w,{...e,children:c(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>o,a:()=>l});var r=n(7294);const a={},s=r.createContext(a);function l(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/590578cb.2e0473b3.js b/assets/js/590578cb.ca5d51d5.js similarity index 98% rename from assets/js/590578cb.2e0473b3.js rename to assets/js/590578cb.ca5d51d5.js index e02c7ddb2..54afb3d5c 100644 --- a/assets/js/590578cb.2e0473b3.js +++ b/assets/js/590578cb.ca5d51d5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3181],{1115:(e,i,t)=>{t.r(i),t.d(i,{assets:()=>l,contentTitle:()=>o,default:()=>h,frontMatter:()=>r,metadata:()=>d,toc:()=>a});var s=t(5893),n=t(1151);const r={title:"History"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/08-history.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:8,frontMatter:{title:"History"},sidebar:"tutorialSidebar",previous:{title:"Hooks",permalink:"/docs/intro/hooks"},next:{title:"Influence",permalink:"/docs/intro/influence"}},l={},a=[{value:"A brief history of Middy",id:"a-brief-history-of-middy",level:2}];function c(e){const i={a:"a",h2:"h2",li:"li",p:"p",strong:"strong",ul:"ul",...(0,n.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.h2,{id:"a-brief-history-of-middy",children:"A brief history of Middy"}),"\n",(0,s.jsxs)(i.ul,{children:["\n",(0,s.jsx)(i.li,{children:"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."}),"\n",(0,s.jsx)(i.li,{children:"2017-08-03: First commit"}),"\n",(0,s.jsx)(i.li,{children:"2017-09-04: v0.2.1 First release"}),"\n",(0,s.jsxs)(i.li,{children:["2020-04-25: ",(0,s.jsx)(i.a,{href:"https://loige.co/middy-1-is-here/",children:"v1.0.0"})," Released"]}),"\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.a,{href:"https://loige.co/2020-a-year-in-review/#middy",children:"2020 Review"})," by ",(0,s.jsx)(i.a,{href:"https://github.com/lmammino",children:"@lmammino"})]}),"\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.a,{href:"https://github.com/middyjs/middy/issues/590",children:"2020 Review"})," by ",(0,s.jsx)(i.a,{href:"https://github.com/willfarrell",children:"@willfarrell"})]}),"\n",(0,s.jsxs)(i.li,{children:["2021: ",(0,s.jsx)(i.a,{href:"https://github.com/middyjs/middy/issues/585",children:"v2.0.0 Coming soon"})]}),"\n",(0,s.jsx)(i.li,{children:"2021-04-01: v2.0.0 Released"}),"\n",(0,s.jsxs)(i.li,{children:["2021-02-02: ",(0,s.jsx)(i.a,{href:"https://loige.co/2021-a-year-in-review#middy",children:"2021 Review"})," from ",(0,s.jsx)(i.a,{href:"https://github.com/lmammino",children:"@lmammino"})]}),"\n",(0,s.jsx)(i.li,{children:"2022-05-12: v3.0.0 Released"}),"\n",(0,s.jsx)(i.li,{children:"2022-11-24: v4.0.0 Released"}),"\n",(0,s.jsxs)(i.li,{children:["2023-08-22: ",(0,s.jsx)(i.a,{href:"https://www.linkedin.com/posts/jsdayie_javascript-nodejs-activity-7099445347520757760-hsUQ",children:"JSAwardsIE 2023 Most valued JavaScript open source project"})]}),"\n",(0,s.jsx)(i.li,{children:"2023-11-??: v5.0.0 Released"}),"\n",(0,s.jsx)(i.li,{children:"2024-11-??: v6.0.0 Released"}),"\n"]}),"\n",(0,s.jsxs)(i.p,{children:[(0,s.jsx)(i.strong,{children:"Fun Fact"}),": The adding of the emoji-icon was the ",(0,s.jsx)(i.a,{href:"https://github.com/middyjs/middy/commit/a0acf430bb72f6f6f604e38cfd8a571912b6b4d7",children:"2nd commit"})," to the project."]})]})}function h(e={}){const{wrapper:i}={...(0,n.a)(),...e.components};return i?(0,s.jsx)(i,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,i,t)=>{t.d(i,{Z:()=>d,a:()=>o});var s=t(7294);const n={},r=s.createContext(n);function o(e){const i=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(i):{...i,...e}}),[i,e])}function d(e){let i;return i=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:o(e.components),s.createElement(r.Provider,{value:i},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3181],{1115:(e,i,t)=>{t.r(i),t.d(i,{assets:()=>l,contentTitle:()=>o,default:()=>h,frontMatter:()=>r,metadata:()=>d,toc:()=>a});var s=t(5893),n=t(1151);const r={title:"History"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/08-history.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:8,frontMatter:{title:"History"},sidebar:"tutorialSidebar",previous:{title:"Hooks",permalink:"/docs/intro/hooks"},next:{title:"Influence",permalink:"/docs/intro/influence"}},l={},a=[{value:"A brief history of Middy",id:"a-brief-history-of-middy",level:2}];function c(e){const i={a:"a",h2:"h2",li:"li",p:"p",strong:"strong",ul:"ul",...(0,n.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.h2,{id:"a-brief-history-of-middy",children:"A brief history of Middy"}),"\n",(0,s.jsxs)(i.ul,{children:["\n",(0,s.jsx)(i.li,{children:"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."}),"\n",(0,s.jsx)(i.li,{children:"2017-08-03: First commit"}),"\n",(0,s.jsx)(i.li,{children:"2017-09-04: v0.2.1 First release"}),"\n",(0,s.jsxs)(i.li,{children:["2020-04-25: ",(0,s.jsx)(i.a,{href:"https://loige.co/middy-1-is-here/",children:"v1.0.0"})," Released"]}),"\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.a,{href:"https://loige.co/2020-a-year-in-review/#middy",children:"2020 Review"})," by ",(0,s.jsx)(i.a,{href:"https://github.com/lmammino",children:"@lmammino"})]}),"\n",(0,s.jsxs)(i.li,{children:[(0,s.jsx)(i.a,{href:"https://github.com/middyjs/middy/issues/590",children:"2020 Review"})," by ",(0,s.jsx)(i.a,{href:"https://github.com/willfarrell",children:"@willfarrell"})]}),"\n",(0,s.jsxs)(i.li,{children:["2021: ",(0,s.jsx)(i.a,{href:"https://github.com/middyjs/middy/issues/585",children:"v2.0.0 Coming soon"})]}),"\n",(0,s.jsx)(i.li,{children:"2021-04-01: v2.0.0 Released"}),"\n",(0,s.jsxs)(i.li,{children:["2021-02-02: ",(0,s.jsx)(i.a,{href:"https://loige.co/2021-a-year-in-review#middy",children:"2021 Review"})," from ",(0,s.jsx)(i.a,{href:"https://github.com/lmammino",children:"@lmammino"})]}),"\n",(0,s.jsx)(i.li,{children:"2022-05-12: v3.0.0 Released"}),"\n",(0,s.jsx)(i.li,{children:"2022-11-24: v4.0.0 Released"}),"\n",(0,s.jsxs)(i.li,{children:["2023-08-22: ",(0,s.jsx)(i.a,{href:"https://www.linkedin.com/posts/jsdayie_javascript-nodejs-activity-7099445347520757760-hsUQ",children:"JSAwardsIE 2023 Most valued JavaScript open source project"})]}),"\n",(0,s.jsx)(i.li,{children:"2023-11-??: v5.0.0 Released"}),"\n",(0,s.jsx)(i.li,{children:"2024-11-??: v6.0.0 Released"}),"\n"]}),"\n",(0,s.jsxs)(i.p,{children:[(0,s.jsx)(i.strong,{children:"Fun Fact"}),": The adding of the emoji-icon was the ",(0,s.jsx)(i.a,{href:"https://github.com/middyjs/middy/commit/a0acf430bb72f6f6f604e38cfd8a571912b6b4d7",children:"2nd commit"})," to the project."]})]})}function h(e={}){const{wrapper:i}={...(0,n.a)(),...e.components};return i?(0,s.jsx)(i,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,i,t)=>{t.d(i,{Z:()=>d,a:()=>o});var s=t(7294);const n={},r=s.createContext(n);function o(e){const i=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(i):{...i,...e}}),[i,e])}function d(e){let i;return i=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:o(e.components),s.createElement(r.Provider,{value:i},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/59ac4306.a60dbbe2.js b/assets/js/59ac4306.68b61429.js similarity index 99% rename from assets/js/59ac4306.a60dbbe2.js rename to assets/js/59ac4306.68b61429.js index fc079dd30..d560fefd9 100644 --- a/assets/js/59ac4306.a60dbbe2.js +++ b/assets/js/59ac4306.68b61429.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3151],{487:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>h,frontMatter:()=>o,metadata:()=>d,toc:()=>c});var n=r(5893),a=r(1151),l=r(4866),s=r(5162);const o={title:"http-urlencode-body-parser"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-urlencode-body-parser.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={code:"code",em:"em",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["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,n.jsx)(t.em,{children:"Unsupported Media Type"})," (415 errors)"]}),"\n",(0,n.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(s.Z,{value:"npm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-urlencode-body-parser\n"})})}),(0,n.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-urlencode-body-parser\n"})})}),(0,n.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-urlencode-body-parser\n"})})})]}),"\n",(0,n.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"disableContentTypeError"})," (",(0,n.jsx)(t.code,{children:"boolean"}),") (optional): Skip throwing 415 when ",(0,n.jsx)(t.code,{children:"Content-Type"})," is invalid. Default: ",(0,n.jsx)(t.code,{children:"true"}),", will default to ",(0,n.jsx)(t.code,{children:"false"})," in next major version."]}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpUrlEncodeBodyParser from '@middy/http-urlencode-body-parser'\n\nconst lambdaHandler = (event, context) => {\n return event.body // propagates the body as response\n}\n\nexport const handler = middy()\n .use(httpHeaderNormalizer())\n .use(httpUrlEncodeBodyParser())\n .handler(lambdaHandler)\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"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(p,{...e})}):p(e)}},5162:(e,t,r)=>{r.d(t,{Z:()=>s});r(7294);var n=r(6010);const a={tabItem:"tabItem_Ymn6"};var l=r(5893);function s(e){let{children:t,hidden:r,className:s}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,n.Z)(a.tabItem,s),hidden:r,children:t})}},4866:(e,t,r)=>{r.d(t,{Z:()=>j});var n=r(7294),a=r(6010),l=r(2466),s=r(6550),o=r(469),i=r(1980),d=r(7392),u=r(12);function c(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}(r);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,r])}function h(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:r}=e;const a=(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,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 b(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,l=p(e),[s,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(!h({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}))),[d,c]=m({queryString:r,groupId:a}),[b,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,u.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:a}),y=(()=>{const e=d??b;return h({value:e,tabValues:l})?e:null})();(0,o.Z)((()=>{y&&i(y)}),[y]);return{selectedValue:s,selectValue:(0,n.useCallback)((e=>{if(!h({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),f(e)}),[c,f,l]),tabValues:l}}var f=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=r(5893);function g(e){let{className:t,block:r,selectedValue:n,selectValue:s,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.o5)(),u=e=>{const t=e.currentTarget,r=i.indexOf(t),a=o[r].value;a!==n&&(d(t),s(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const r=i.indexOf(e.currentTarget)+1;t=i[r]??i[0];break}case"ArrowLeft":{const r=i.indexOf(e.currentTarget)-1;t=i[r]??i[i.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":r},t),children:o.map((e=>{let{value:t,label:r,attributes:l}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:c,onClick:u,...l,className:(0,a.Z)("tabs__item",y.tabItem,l?.className,{"tabs__item--active":n===t}),children:r??t},t)}))})}function x(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(0,v.jsx)("div",{className:"margin-top--md",children:l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=b(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",y.tabList),children:[(0,v.jsx)(g,{...e,...t}),(0,v.jsx)(x,{...e,...t})]})}function j(e){const t=(0,f.Z)();return(0,v.jsx)(w,{...e,children:c(e.children)},String(t))}},1151:(e,t,r)=>{r.d(t,{Z:()=>o,a:()=>s});var n=r(7294);const a={},l=n.createContext(a);function s(e){const t=n.useContext(l);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:s(e.components),n.createElement(l.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3151],{487:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>h,frontMatter:()=>o,metadata:()=>d,toc:()=>c});var n=r(5893),a=r(1151),l=r(4866),s=r(5162);const o={title:"http-urlencode-body-parser"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-urlencode-body-parser.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={code:"code",em:"em",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["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,n.jsx)(t.em,{children:"Unsupported Media Type"})," (415 errors)"]}),"\n",(0,n.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(s.Z,{value:"npm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-urlencode-body-parser\n"})})}),(0,n.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-urlencode-body-parser\n"})})}),(0,n.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-urlencode-body-parser\n"})})})]}),"\n",(0,n.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"disableContentTypeError"})," (",(0,n.jsx)(t.code,{children:"boolean"}),") (optional): Skip throwing 415 when ",(0,n.jsx)(t.code,{children:"Content-Type"})," is invalid. Default: ",(0,n.jsx)(t.code,{children:"true"}),", will default to ",(0,n.jsx)(t.code,{children:"false"})," in next major version."]}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\nimport httpUrlEncodeBodyParser from '@middy/http-urlencode-body-parser'\n\nconst lambdaHandler = (event, context) => {\n return event.body // propagates the body as response\n}\n\nexport const handler = middy()\n .use(httpHeaderNormalizer())\n .use(httpUrlEncodeBodyParser())\n .handler(lambdaHandler)\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"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(p,{...e})}):p(e)}},5162:(e,t,r)=>{r.d(t,{Z:()=>s});r(7294);var n=r(6010);const a={tabItem:"tabItem_Ymn6"};var l=r(5893);function s(e){let{children:t,hidden:r,className:s}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,n.Z)(a.tabItem,s),hidden:r,children:t})}},4866:(e,t,r)=>{r.d(t,{Z:()=>j});var n=r(7294),a=r(6010),l=r(2466),s=r(6550),o=r(469),i=r(1980),d=r(7392),u=r(12);function c(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}(r);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,r])}function h(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:r}=e;const a=(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,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 b(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,l=p(e),[s,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(!h({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}))),[d,c]=m({queryString:r,groupId:a}),[b,f]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,u.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:a}),y=(()=>{const e=d??b;return h({value:e,tabValues:l})?e:null})();(0,o.Z)((()=>{y&&i(y)}),[y]);return{selectedValue:s,selectValue:(0,n.useCallback)((e=>{if(!h({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),f(e)}),[c,f,l]),tabValues:l}}var f=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=r(5893);function g(e){let{className:t,block:r,selectedValue:n,selectValue:s,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.o5)(),u=e=>{const t=e.currentTarget,r=i.indexOf(t),a=o[r].value;a!==n&&(d(t),s(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const r=i.indexOf(e.currentTarget)+1;t=i[r]??i[0];break}case"ArrowLeft":{const r=i.indexOf(e.currentTarget)-1;t=i[r]??i[i.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":r},t),children:o.map((e=>{let{value:t,label:r,attributes:l}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:c,onClick:u,...l,className:(0,a.Z)("tabs__item",y.tabItem,l?.className,{"tabs__item--active":n===t}),children:r??t},t)}))})}function x(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(0,v.jsx)("div",{className:"margin-top--md",children:l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=b(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",y.tabList),children:[(0,v.jsx)(g,{...e,...t}),(0,v.jsx)(x,{...e,...t})]})}function j(e){const t=(0,f.Z)();return(0,v.jsx)(w,{...e,children:c(e.children)},String(t))}},1151:(e,t,r)=>{r.d(t,{Z:()=>o,a:()=>s});var n=r(7294);const a={},l=n.createContext(a);function s(e){const t=n.useContext(l);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:s(e.components),n.createElement(l.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/5a01598e.205a3971.js b/assets/js/5a01598e.71978b99.js similarity index 99% rename from assets/js/5a01598e.205a3971.js rename to assets/js/5a01598e.71978b99.js index a42321023..afdfbac38 100644 --- a/assets/js/5a01598e.205a3971.js +++ b/assets/js/5a01598e.71978b99.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4297],{1627:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>a,contentTitle:()=>l,default:()=>c,frontMatter:()=>i,metadata:()=>t,toc:()=>o});var s=n(5893),d=n(1151);const i={title:"Upgrade 3.x -> 4.x",sidebar_position:10},l=void 0,t={id:"upgrade/3-4",title:"Upgrade 3.x -> 4.x",description:'aka "The AWS SDK v3 Update"',source:"@site/docs/upgrade/3-4.md",sourceDirName:"upgrade",slug:"/upgrade/3-4",permalink:"/docs/upgrade/3-4",draft:!1,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/3-4.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:10,frontMatter:{title:"Upgrade 3.x -> 4.x",sidebar_position:10},sidebar:"tutorialSidebar",previous:{title:"Upgrade 4.x -> 5.x",permalink:"/docs/upgrade/4-5"},next:{title:"Upgrade 2.x -> 3.x",permalink:"/docs/upgrade/2-3"}},a={},o=[{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}];function h(e){const r={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,d.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.p,{children:'aka "The AWS SDK v3 Update"'}),"\n",(0,s.jsx)(r.p,{children:"Version 4.x of Middy no longer supports Node.js versions 14.x. You are highly encouraged to move to Node.js 18.x."}),"\n",(0,s.jsx)(r.h2,{id:"notable-changes",children:"Notable changes"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"Middy now uses AWS SDK v3 by default."}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"core",children:"Core"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Remove polyfill for ",(0,s.jsx)(r.code,{children:"AbortControler"})]}),"\n",(0,s.jsxs)(r.li,{children:["Remove polyfill for ",(0,s.jsx)(r.code,{children:"timers/promises"})]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"util",children:"Util"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"normalizeResponse"})," now will set the ",(0,s.jsx)(r.code,{children:"statusCode"})," to ",(0,s.jsx)(r.code,{children:"200"})," when casting to a new object or ",(0,s.jsx)(r.code,{children:"500"})," when missing ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"middleware",children:"Middleware"}),"\n",(0,s.jsx)(r.h3,{id:"cloudwatch-metrics",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/cloudwatch-metrics",children:"cloudwatch-metrics"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"do-not-wait-for-empty-event-loop",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/do-not-wait-for-empty-event-loop",children:"do-not-wait-for-empty-event-loop"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"error-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/error-logger",children:"error-logger"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/event-normalizer",children:"event-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-content-encoding",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-encoding",children:"http-content-encoding"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Removed body as stream support, will be brought back as a new middleware in a future middleware ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-content-negotiation",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-negotiation",children:"http-content-negotiation"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-cors",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-cors",children:"http-cors"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-error-handler",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-error-handler",children:"http-error-handler"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-event-normalizer",children:"http-event-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-header-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-header-normalizer",children:"http-header-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-json-body-parser",children:"http-json-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecate ",(0,s.jsx)(r.code,{children:"event.rawBody"})," ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.p,{children:"You can add in an inline middleware as a workaround."}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-javascript",children:" .before((request) => {\n request.event.rawBody = request.event.body\n })\n .use(httpJSONBodyParserMiddleware())\n"})}),"\n",(0,s.jsxs)(r.p,{children:["See ",(0,s.jsx)(r.a,{href:"https://github.com/middyjs/middy/issues/945",children:"https://github.com/middyjs/middy/issues/945"})," for discussion and reasoning."]}),"\n",(0,s.jsx)(r.h3,{id:"http-multipart-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-multipart-body-parser",children:"http-multipart-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Add new option to set ",(0,s.jsx)(r.code,{children:"charset"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-partial-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-partial-response",children:"http-partial-response"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-response-serializer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-response-serializer",children:"http-response-serializer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-router",children:(0,s.jsx)(r.a,{href:"/docs/routers/http-router",children:"http-router"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-security-headers",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-security-headers",children:"http-security-headers"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-body-parser",children:"http-urlencode-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Now throws 422 when unable to parse JSON ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-path-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-path-parser",children:"http-urlencode-path-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"input-output-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/input-output-logger",children:"input-output-logger"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"rds-signer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/rds-signer",children:"rds-signer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"s3-object-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/s3-object-response",children:"s3-object-response"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"secrets-manager",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/secrets-manager",children:"secrets-manager"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"service-discovery",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/service-discovery",children:"service-discovery"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"sqs-partial-batch-failure",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sqs-partial-batch-failure",children:"sqs-partial-batch-failure"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"ssm",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ssm",children:"ssm"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"sts",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sts",children:"sts"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"validator",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/validator",children:"validator"})}),"\n",(0,s.jsx)(r.p,{children:"We've put a lot of work into making this middleware bundle smaller and faster by default, while allowing for opting into more functionality."}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecate ",(0,s.jsx)(r.code,{children:"inputSchema"})," and ",(0,s.jsx)(r.code,{children:"outputSchema"})," options ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n",(0,s.jsxs)(r.li,{children:["Deprecated ",(0,s.jsx)(r.code,{children:"i18nEnabled"})," ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n",(0,s.jsxs)(r.li,{children:["Must now pass in ",(0,s.jsx)(r.code,{children:"defaultLanguage"})," localizations to ",(0,s.jsx)(r.code,{children:"languages"})," ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n",(0,s.jsxs)(r.li,{children:["Added in ",(0,s.jsx)(r.code,{children:"ajv-error"})," support"]}),"\n",(0,s.jsxs)(r.li,{children:["Pulled ",(0,s.jsx)(r.code,{children:"transpileSchema"})," out of middleware to allow for tree shaking and pre-compile option ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n",(0,s.jsxs)(r.li,{children:["Added in ",(0,s.jsx)(r.code,{children:"transpileLocale"})," to allow for custom internationalization of error messages including ",(0,s.jsx)(r.code,{children:"errorMessage"})]}),"\n"]}),"\n",(0,s.jsx)(r.p,{children:"How to update use of middleware"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-javascript",children:"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"})}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-javascript",children:"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"})}),"\n",(0,s.jsx)(r.h3,{id:"warmup",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/warmup",children:"warmup"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"ws-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ws-json-body-parser",children:"ws-json-body-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"ws-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ws-response",children:"ws-response"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"ws-router",children:(0,s.jsx)(r.a,{href:"/docs/routers/ws-router",children:"ws-router"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h2,{id:"notes",children:"Notes"}),"\n",(0,s.jsx)(r.p,{children:"None"})]})}function c(e={}){const{wrapper:r}={...(0,d.a)(),...e.components};return r?(0,s.jsx)(r,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},1151:(e,r,n)=>{n.d(r,{Z:()=>t,a:()=>l});var s=n(7294);const d={},i=s.createContext(d);function l(e){const r=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function t(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(d):e.components||d:l(e.components),s.createElement(i.Provider,{value:r},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4297],{1627:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>a,contentTitle:()=>l,default:()=>c,frontMatter:()=>i,metadata:()=>t,toc:()=>o});var s=n(5893),d=n(1151);const i={title:"Upgrade 3.x -> 4.x",sidebar_position:10},l=void 0,t={id:"upgrade/3-4",title:"Upgrade 3.x -> 4.x",description:'aka "The AWS SDK v3 Update"',source:"@site/docs/upgrade/3-4.md",sourceDirName:"upgrade",slug:"/upgrade/3-4",permalink:"/docs/upgrade/3-4",draft:!1,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/3-4.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:10,frontMatter:{title:"Upgrade 3.x -> 4.x",sidebar_position:10},sidebar:"tutorialSidebar",previous:{title:"Upgrade 4.x -> 5.x",permalink:"/docs/upgrade/4-5"},next:{title:"Upgrade 2.x -> 3.x",permalink:"/docs/upgrade/2-3"}},a={},o=[{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}];function h(e){const r={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,d.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.p,{children:'aka "The AWS SDK v3 Update"'}),"\n",(0,s.jsx)(r.p,{children:"Version 4.x of Middy no longer supports Node.js versions 14.x. You are highly encouraged to move to Node.js 18.x."}),"\n",(0,s.jsx)(r.h2,{id:"notable-changes",children:"Notable changes"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"Middy now uses AWS SDK v3 by default."}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"core",children:"Core"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Remove polyfill for ",(0,s.jsx)(r.code,{children:"AbortControler"})]}),"\n",(0,s.jsxs)(r.li,{children:["Remove polyfill for ",(0,s.jsx)(r.code,{children:"timers/promises"})]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"util",children:"Util"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"normalizeResponse"})," now will set the ",(0,s.jsx)(r.code,{children:"statusCode"})," to ",(0,s.jsx)(r.code,{children:"200"})," when casting to a new object or ",(0,s.jsx)(r.code,{children:"500"})," when missing ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"middleware",children:"Middleware"}),"\n",(0,s.jsx)(r.h3,{id:"cloudwatch-metrics",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/cloudwatch-metrics",children:"cloudwatch-metrics"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"do-not-wait-for-empty-event-loop",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/do-not-wait-for-empty-event-loop",children:"do-not-wait-for-empty-event-loop"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"error-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/error-logger",children:"error-logger"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/event-normalizer",children:"event-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-content-encoding",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-encoding",children:"http-content-encoding"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Removed body as stream support, will be brought back as a new middleware in a future middleware ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-content-negotiation",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-negotiation",children:"http-content-negotiation"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-cors",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-cors",children:"http-cors"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-error-handler",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-error-handler",children:"http-error-handler"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-event-normalizer",children:"http-event-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-header-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-header-normalizer",children:"http-header-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-json-body-parser",children:"http-json-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecate ",(0,s.jsx)(r.code,{children:"event.rawBody"})," ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.p,{children:"You can add in an inline middleware as a workaround."}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-javascript",children:" .before((request) => {\n request.event.rawBody = request.event.body\n })\n .use(httpJSONBodyParserMiddleware())\n"})}),"\n",(0,s.jsxs)(r.p,{children:["See ",(0,s.jsx)(r.a,{href:"https://github.com/middyjs/middy/issues/945",children:"https://github.com/middyjs/middy/issues/945"})," for discussion and reasoning."]}),"\n",(0,s.jsx)(r.h3,{id:"http-multipart-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-multipart-body-parser",children:"http-multipart-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Add new option to set ",(0,s.jsx)(r.code,{children:"charset"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-partial-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-partial-response",children:"http-partial-response"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-response-serializer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-response-serializer",children:"http-response-serializer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-router",children:(0,s.jsx)(r.a,{href:"/docs/routers/http-router",children:"http-router"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-security-headers",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-security-headers",children:"http-security-headers"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-body-parser",children:"http-urlencode-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Now throws 422 when unable to parse JSON ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-path-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-path-parser",children:"http-urlencode-path-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"input-output-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/input-output-logger",children:"input-output-logger"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"rds-signer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/rds-signer",children:"rds-signer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"s3-object-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/s3-object-response",children:"s3-object-response"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"secrets-manager",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/secrets-manager",children:"secrets-manager"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"service-discovery",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/service-discovery",children:"service-discovery"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"sqs-partial-batch-failure",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sqs-partial-batch-failure",children:"sqs-partial-batch-failure"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"ssm",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ssm",children:"ssm"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"sts",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sts",children:"sts"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"validator",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/validator",children:"validator"})}),"\n",(0,s.jsx)(r.p,{children:"We've put a lot of work into making this middleware bundle smaller and faster by default, while allowing for opting into more functionality."}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Deprecate ",(0,s.jsx)(r.code,{children:"inputSchema"})," and ",(0,s.jsx)(r.code,{children:"outputSchema"})," options ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n",(0,s.jsxs)(r.li,{children:["Deprecated ",(0,s.jsx)(r.code,{children:"i18nEnabled"})," ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n",(0,s.jsxs)(r.li,{children:["Must now pass in ",(0,s.jsx)(r.code,{children:"defaultLanguage"})," localizations to ",(0,s.jsx)(r.code,{children:"languages"})," ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n",(0,s.jsxs)(r.li,{children:["Added in ",(0,s.jsx)(r.code,{children:"ajv-error"})," support"]}),"\n",(0,s.jsxs)(r.li,{children:["Pulled ",(0,s.jsx)(r.code,{children:"transpileSchema"})," out of middleware to allow for tree shaking and pre-compile option ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n",(0,s.jsxs)(r.li,{children:["Added in ",(0,s.jsx)(r.code,{children:"transpileLocale"})," to allow for custom internationalization of error messages including ",(0,s.jsx)(r.code,{children:"errorMessage"})]}),"\n"]}),"\n",(0,s.jsx)(r.p,{children:"How to update use of middleware"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-javascript",children:"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"})}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-javascript",children:"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"})}),"\n",(0,s.jsx)(r.h3,{id:"warmup",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/warmup",children:"warmup"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"ws-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ws-json-body-parser",children:"ws-json-body-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"ws-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ws-response",children:"ws-response"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use AWS SDK v3 ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"ws-router",children:(0,s.jsx)(r.a,{href:"/docs/routers/ws-router",children:"ws-router"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h2,{id:"notes",children:"Notes"}),"\n",(0,s.jsx)(r.p,{children:"None"})]})}function c(e={}){const{wrapper:r}={...(0,d.a)(),...e.components};return r?(0,s.jsx)(r,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},1151:(e,r,n)=>{n.d(r,{Z:()=>t,a:()=>l});var s=n(7294);const d={},i=s.createContext(d);function l(e){const r=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function t(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(d):e.components||d:l(e.components),s.createElement(i.Provider,{value:r},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/5afe45f2.a47a34d1.js b/assets/js/5afe45f2.dfb9079c.js similarity index 99% rename from assets/js/5afe45f2.a47a34d1.js rename to assets/js/5afe45f2.dfb9079c.js index 6a5af4f58..ed65d403f 100644 --- a/assets/js/5afe45f2.a47a34d1.js +++ b/assets/js/5afe45f2.dfb9079c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5938],{770:(e,n,a)=>{a.r(n),a.d(n,{assets:()=>c,contentTitle:()=>d,default:()=>h,frontMatter:()=>i,metadata:()=>o,toc:()=>u});var r=a(5893),t=a(1151),l=a(4866),s=a(5162);const i={title:"Getting started",position:2},d=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/02-getting-started.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{value:"Install",id:"install",level:2},{value:"Usage",id:"usage",level:2},{value:"Example",id:"example",level:2}];function m(e){const n={a:"a",code:"code",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",...(0,t.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(n.p,{children:"To install middy, you can use NPM:"}),"\n",(0,r.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(s.Z,{value:"npm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/core\n"})})}),(0,r.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/core\n"})})}),(0,r.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/core\n"})})})]}),"\n",(0,r.jsxs)(n.p,{children:["If you are using TypeScript, you will also want to make sure that you have installed the ",(0,r.jsx)(n.code,{children:"@types/aws-lambda"})," peer-dependency:"]}),"\n",(0,r.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(s.Z,{value:"npm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"npm install --save-dev @types/aws-lambda\n"})})}),(0,r.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"yarn add --dev @types/aws-lambda\n"})})}),(0,r.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"pnpm add --save-dev @types/aws-lambda\n"})})})]}),"\n",(0,r.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,r.jsx)(n.p,{children:"As you will see in the next example, using middy is very\nsimple and requires just few steps:"}),"\n",(0,r.jsxs)(n.ol,{children:["\n",(0,r.jsx)(n.li,{children:"Write your Lambda handlers as usual, focusing mostly on implementing the bare\nbusiness logic for them."}),"\n",(0,r.jsxs)(n.li,{children:["Import ",(0,r.jsx)(n.code,{children:"middy"})," and all the middlewares you want to use."]}),"\n",(0,r.jsxs)(n.li,{children:["Wrap your handler in the ",(0,r.jsx)(n.code,{children:"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."]}),"\n",(0,r.jsxs)(n.li,{children:["Attach all the middlewares you need using the function ",(0,r.jsx)(n.code,{children:".use(somemiddleware())"})]}),"\n"]}),"\n",(0,r.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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()\n .use(middleware1())\n .use(middleware2())\n .use(middleware3())\n .handler(lambdaHandler)\n"})}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.code,{children:".use()"})," takes a single middleware or an array of middlewares, so you can attach multiple middlewares in a single call:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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()\n .use([middleware1(), middleware2(), middleware3()])\n .handler(lambdaHandler)\n"})}),"\n",(0,r.jsxs)(n.p,{children:["You can also attach ",(0,r.jsx)(n.a,{href:"#inline-middlewares",children:"inline middlewares"})," by using the functions ",(0,r.jsx)(n.code,{children:".before"}),", ",(0,r.jsx)(n.code,{children:".after"})," and ",(0,r.jsx)(n.code,{children:".onError"}),"."]}),"\n",(0,r.jsxs)(n.p,{children:["For a more detailed use case and examples check the ",(0,r.jsx)(n.a,{href:"#writing-a-middleware",children:"Writing a middleware section"}),"."]})]})}function h(e={}){const{wrapper:n}={...(0,t.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},5162:(e,n,a)=>{a.d(n,{Z:()=>s});a(7294);var r=a(6010);const t={tabItem:"tabItem_Ymn6"};var l=a(5893);function s(e){let{children:n,hidden:a,className:s}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,r.Z)(t.tabItem,s),hidden:a,children:n})}},4866:(e,n,a)=>{a.d(n,{Z:()=>j});var r=a(7294),t=a(6010),l=a(2466),s=a(6550),i=a(469),d=a(1980),o=a(7392),c=a(12);function u(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function m(e){const{values:n,children:a}=e;return(0,r.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:a,attributes:r,default:t}}=e;return{value:n,label:a,attributes:r,default:t}}))}(a);return function(e){const n=(0,o.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,a])}function h(e){let{value:n,tabValues:a}=e;return a.some((e=>e.value===n))}function p(e){let{queryString:n=!1,groupId:a}=e;const t=(0,s.k6)(),l=function(e){let{queryString:n=!1,groupId:a}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!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:n,groupId:a});return[(0,d._X)(l),(0,r.useCallback)((e=>{if(!l)return;const n=new URLSearchParams(t.location.search);n.set(l,e),t.replace({...t.location,search:n.toString()})}),[l,t])]}function b(e){const{defaultValue:n,queryString:a=!1,groupId:t}=e,l=m(e),[s,d]=(0,r.useState)((()=>function(e){let{defaultValue:n,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!h({value:n,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" 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 n}const r=a.find((e=>e.default))??a[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:n,tabValues:l}))),[o,u]=p({queryString:a,groupId:t}),[b,f]=function(e){let{groupId:n}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(n),[t,l]=(0,c.Nk)(a);return[t,(0,r.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:t}),g=(()=>{const e=o??b;return h({value:e,tabValues:l})?e:null})();(0,i.Z)((()=>{g&&d(g)}),[g]);return{selectedValue:s,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);d(e),u(e),f(e)}),[u,f,l]),tabValues:l}}var f=a(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=a(5893);function y(e){let{className:n,block:a,selectedValue:r,selectValue:s,tabValues:i}=e;const d=[],{blockElementScrollPositionUntilNextRender:o}=(0,l.o5)(),c=e=>{const n=e.currentTarget,a=d.indexOf(n),t=i[a].value;t!==r&&(o(n),s(t))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const a=d.indexOf(e.currentTarget)+1;n=d[a]??d[0];break}case"ArrowLeft":{const a=d.indexOf(e.currentTarget)-1;n=d[a]??d[d.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,t.Z)("tabs",{"tabs--block":a},n),children:i.map((e=>{let{value:n,label:a,attributes:l}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:r===n?0:-1,"aria-selected":r===n,ref:e=>d.push(e),onKeyDown:u,onClick:c,...l,className:(0,t.Z)("tabs__item",g.tabItem,l?.className,{"tabs__item--active":r===n}),children:a??n},n)}))})}function v(e){let{lazy:n,children:a,selectedValue:t}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(n){const e=l.find((e=>e.props.value===t));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:l.map(((e,n)=>(0,r.cloneElement)(e,{key:n,hidden:e.props.value!==t})))})}function w(e){const n=b(e);return(0,x.jsxs)("div",{className:(0,t.Z)("tabs-container",g.tabList),children:[(0,x.jsx)(y,{...e,...n}),(0,x.jsx)(v,{...e,...n})]})}function j(e){const n=(0,f.Z)();return(0,x.jsx)(w,{...e,children:u(e.children)},String(n))}},1151:(e,n,a)=>{a.d(n,{Z:()=>i,a:()=>s});var r=a(7294);const t={},l=r.createContext(t);function s(e){const n=r.useContext(l);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:s(e.components),r.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5938],{770:(e,n,a)=>{a.r(n),a.d(n,{assets:()=>c,contentTitle:()=>d,default:()=>h,frontMatter:()=>i,metadata:()=>o,toc:()=>u});var r=a(5893),t=a(1151),l=a(4866),s=a(5162);const i={title:"Getting started",position:2},d=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/02-getting-started.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{value:"Install",id:"install",level:2},{value:"Usage",id:"usage",level:2},{value:"Example",id:"example",level:2}];function m(e){const n={a:"a",code:"code",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",...(0,t.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(n.p,{children:"To install middy, you can use NPM:"}),"\n",(0,r.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(s.Z,{value:"npm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/core\n"})})}),(0,r.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/core\n"})})}),(0,r.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/core\n"})})})]}),"\n",(0,r.jsxs)(n.p,{children:["If you are using TypeScript, you will also want to make sure that you have installed the ",(0,r.jsx)(n.code,{children:"@types/aws-lambda"})," peer-dependency:"]}),"\n",(0,r.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(s.Z,{value:"npm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"npm install --save-dev @types/aws-lambda\n"})})}),(0,r.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"yarn add --dev @types/aws-lambda\n"})})}),(0,r.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"pnpm add --save-dev @types/aws-lambda\n"})})})]}),"\n",(0,r.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,r.jsx)(n.p,{children:"As you will see in the next example, using middy is very\nsimple and requires just few steps:"}),"\n",(0,r.jsxs)(n.ol,{children:["\n",(0,r.jsx)(n.li,{children:"Write your Lambda handlers as usual, focusing mostly on implementing the bare\nbusiness logic for them."}),"\n",(0,r.jsxs)(n.li,{children:["Import ",(0,r.jsx)(n.code,{children:"middy"})," and all the middlewares you want to use."]}),"\n",(0,r.jsxs)(n.li,{children:["Wrap your handler in the ",(0,r.jsx)(n.code,{children:"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."]}),"\n",(0,r.jsxs)(n.li,{children:["Attach all the middlewares you need using the function ",(0,r.jsx)(n.code,{children:".use(somemiddleware())"})]}),"\n"]}),"\n",(0,r.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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()\n .use(middleware1())\n .use(middleware2())\n .use(middleware3())\n .handler(lambdaHandler)\n"})}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.code,{children:".use()"})," takes a single middleware or an array of middlewares, so you can attach multiple middlewares in a single call:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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()\n .use([middleware1(), middleware2(), middleware3()])\n .handler(lambdaHandler)\n"})}),"\n",(0,r.jsxs)(n.p,{children:["You can also attach ",(0,r.jsx)(n.a,{href:"#inline-middlewares",children:"inline middlewares"})," by using the functions ",(0,r.jsx)(n.code,{children:".before"}),", ",(0,r.jsx)(n.code,{children:".after"})," and ",(0,r.jsx)(n.code,{children:".onError"}),"."]}),"\n",(0,r.jsxs)(n.p,{children:["For a more detailed use case and examples check the ",(0,r.jsx)(n.a,{href:"#writing-a-middleware",children:"Writing a middleware section"}),"."]})]})}function h(e={}){const{wrapper:n}={...(0,t.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},5162:(e,n,a)=>{a.d(n,{Z:()=>s});a(7294);var r=a(6010);const t={tabItem:"tabItem_Ymn6"};var l=a(5893);function s(e){let{children:n,hidden:a,className:s}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,r.Z)(t.tabItem,s),hidden:a,children:n})}},4866:(e,n,a)=>{a.d(n,{Z:()=>j});var r=a(7294),t=a(6010),l=a(2466),s=a(6550),i=a(469),d=a(1980),o=a(7392),c=a(12);function u(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function m(e){const{values:n,children:a}=e;return(0,r.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:a,attributes:r,default:t}}=e;return{value:n,label:a,attributes:r,default:t}}))}(a);return function(e){const n=(0,o.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,a])}function h(e){let{value:n,tabValues:a}=e;return a.some((e=>e.value===n))}function p(e){let{queryString:n=!1,groupId:a}=e;const t=(0,s.k6)(),l=function(e){let{queryString:n=!1,groupId:a}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!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:n,groupId:a});return[(0,d._X)(l),(0,r.useCallback)((e=>{if(!l)return;const n=new URLSearchParams(t.location.search);n.set(l,e),t.replace({...t.location,search:n.toString()})}),[l,t])]}function b(e){const{defaultValue:n,queryString:a=!1,groupId:t}=e,l=m(e),[s,d]=(0,r.useState)((()=>function(e){let{defaultValue:n,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!h({value:n,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" 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 n}const r=a.find((e=>e.default))??a[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:n,tabValues:l}))),[o,u]=p({queryString:a,groupId:t}),[b,f]=function(e){let{groupId:n}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(n),[t,l]=(0,c.Nk)(a);return[t,(0,r.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:t}),g=(()=>{const e=o??b;return h({value:e,tabValues:l})?e:null})();(0,i.Z)((()=>{g&&d(g)}),[g]);return{selectedValue:s,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);d(e),u(e),f(e)}),[u,f,l]),tabValues:l}}var f=a(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=a(5893);function y(e){let{className:n,block:a,selectedValue:r,selectValue:s,tabValues:i}=e;const d=[],{blockElementScrollPositionUntilNextRender:o}=(0,l.o5)(),c=e=>{const n=e.currentTarget,a=d.indexOf(n),t=i[a].value;t!==r&&(o(n),s(t))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const a=d.indexOf(e.currentTarget)+1;n=d[a]??d[0];break}case"ArrowLeft":{const a=d.indexOf(e.currentTarget)-1;n=d[a]??d[d.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,t.Z)("tabs",{"tabs--block":a},n),children:i.map((e=>{let{value:n,label:a,attributes:l}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:r===n?0:-1,"aria-selected":r===n,ref:e=>d.push(e),onKeyDown:u,onClick:c,...l,className:(0,t.Z)("tabs__item",g.tabItem,l?.className,{"tabs__item--active":r===n}),children:a??n},n)}))})}function v(e){let{lazy:n,children:a,selectedValue:t}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(n){const e=l.find((e=>e.props.value===t));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:l.map(((e,n)=>(0,r.cloneElement)(e,{key:n,hidden:e.props.value!==t})))})}function w(e){const n=b(e);return(0,x.jsxs)("div",{className:(0,t.Z)("tabs-container",g.tabList),children:[(0,x.jsx)(y,{...e,...n}),(0,x.jsx)(v,{...e,...n})]})}function j(e){const n=(0,f.Z)();return(0,x.jsx)(w,{...e,children:u(e.children)},String(n))}},1151:(e,n,a)=>{a.d(n,{Z:()=>i,a:()=>s});var r=a(7294);const t={},l=r.createContext(t);function s(e){const n=r.useContext(l);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:s(e.components),r.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/5e80d65e.cbb9295d.js b/assets/js/5e80d65e.e26223e5.js similarity index 97% rename from assets/js/5e80d65e.cbb9295d.js rename to assets/js/5e80d65e.e26223e5.js index b4fae9843..45ae9e534 100644 --- a/assets/js/5e80d65e.cbb9295d.js +++ b/assets/js/5e80d65e.e26223e5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1436],{9114:(e,r,t)=>{t.r(r),t.d(r,{assets:()=>c,contentTitle:()=>s,default:()=>h,frontMatter:()=>i,metadata:()=>d,toc:()=>a});var o=t(5893),n=t(1151);const i={title:"Hooks",position:2},s=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/07-hooks.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},c={},a=[];function l(e){const r={a:"a",code:"code",li:"li",p:"p",ul:"ul",...(0,n.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(r.p,{children:"Middy provides hooks into it's core to allow for monitoring, setup, and cleaning that may not be possible within a middleware."}),"\n",(0,o.jsx)(r.p,{children:"In order of execution"}),"\n",(0,o.jsxs)(r.ul,{children:["\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"beforePrefetch"}),"(): Triggered once before middlewares are attached and prefetches are executed."]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"requestStart"}),"(): Triggered on every request before the first middleware."]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"beforeMiddleware"}),"/",(0,o.jsx)(r.code,{children:"afterMiddleware"}),"(fctName): Triggered before/after every ",(0,o.jsx)(r.code,{children:"before"}),", ",(0,o.jsx)(r.code,{children:"after"}),", and ",(0,o.jsx)(r.code,{children:"onError"})," middleware function. The function name is passed in, this is why all middlewares use a verbose naming pattern."]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"beforeHandler"}),"/",(0,o.jsx)(r.code,{children:"afterHandler"}),"(): Triggered before/after the handler."]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"requestEnd"}),"(request): Triggered right before the response is returned, including thrown errors."]}),"\n"]}),"\n",(0,o.jsxs)(r.p,{children:["See ",(0,o.jsx)(r.a,{href:"https://middy.js.org/docs/best-practices/profiling",children:"Profiling"})," for example usage."]})]})}function h(e={}){const{wrapper:r}={...(0,n.a)(),...e.components};return r?(0,o.jsx)(r,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,r,t)=>{t.d(r,{Z:()=>d,a:()=>s});var o=t(7294);const n={},i=o.createContext(n);function s(e){const r=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function d(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:s(e.components),o.createElement(i.Provider,{value:r},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1436],{9114:(e,r,t)=>{t.r(r),t.d(r,{assets:()=>c,contentTitle:()=>s,default:()=>h,frontMatter:()=>i,metadata:()=>d,toc:()=>a});var o=t(5893),n=t(1151);const i={title:"Hooks",position:2},s=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/07-hooks.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},c={},a=[];function l(e){const r={a:"a",code:"code",li:"li",p:"p",ul:"ul",...(0,n.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(r.p,{children:"Middy provides hooks into it's core to allow for monitoring, setup, and cleaning that may not be possible within a middleware."}),"\n",(0,o.jsx)(r.p,{children:"In order of execution"}),"\n",(0,o.jsxs)(r.ul,{children:["\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"beforePrefetch"}),"(): Triggered once before middlewares are attached and prefetches are executed."]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"requestStart"}),"(): Triggered on every request before the first middleware."]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"beforeMiddleware"}),"/",(0,o.jsx)(r.code,{children:"afterMiddleware"}),"(fctName): Triggered before/after every ",(0,o.jsx)(r.code,{children:"before"}),", ",(0,o.jsx)(r.code,{children:"after"}),", and ",(0,o.jsx)(r.code,{children:"onError"})," middleware function. The function name is passed in, this is why all middlewares use a verbose naming pattern."]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"beforeHandler"}),"/",(0,o.jsx)(r.code,{children:"afterHandler"}),"(): Triggered before/after the handler."]}),"\n",(0,o.jsxs)(r.li,{children:[(0,o.jsx)(r.code,{children:"requestEnd"}),"(request): Triggered right before the response is returned, including thrown errors."]}),"\n"]}),"\n",(0,o.jsxs)(r.p,{children:["See ",(0,o.jsx)(r.a,{href:"https://middy.js.org/docs/best-practices/profiling",children:"Profiling"})," for example usage."]})]})}function h(e={}){const{wrapper:r}={...(0,n.a)(),...e.components};return r?(0,o.jsx)(r,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,r,t)=>{t.d(r,{Z:()=>d,a:()=>s});var o=t(7294);const n={},i=o.createContext(n);function s(e){const r=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function d(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:s(e.components),o.createElement(i.Provider,{value:r},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/632f0854.1a482285.js b/assets/js/632f0854.d673a9dc.js similarity index 97% rename from assets/js/632f0854.1a482285.js rename to assets/js/632f0854.d673a9dc.js index 340a318d5..9dba369cb 100644 --- a/assets/js/632f0854.1a482285.js +++ b/assets/js/632f0854.d673a9dc.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9997],{5189:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>r,metadata:()=>s,toc:()=>l});var i=n(5893),o=n(1151);const r={title:"Handle Timeouts",position:5},a=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/05-timeouts.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[];function c(e){const t={code:"code",p:"p",pre:"pre",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When a lambda times out it throws an error that cannot be caught by middy. To work around this middy maintains an ",(0,i.jsx)(t.code,{children:"AbortController"})," that can be signalled early to allow time to clean up and log the error properly."]}),"\n",(0,i.jsxs)(t.p,{children:["You can set ",(0,i.jsx)(t.code,{children:"timeoutEarlyInMillis"})," to 0 to disable this functionality. If you want to override during testing, mock the lambda context to set ",(0,i.jsx)(t.code,{children:"getRemainingTimeInMillis"})," to a function that returns a very large value (e.g. ",(0,i.jsx)(t.code,{children:"() => 99999"}),")."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"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({\n timeoutEarlyInMillis: 50,\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n }\n}).handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>s,a:()=>a});var i=n(7294);const o={},r=i.createContext(o);function a(e){const t=i.useContext(r);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),i.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9997],{5189:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>r,metadata:()=>s,toc:()=>l});var i=n(5893),o=n(1151);const r={title:"Handle Timeouts",position:5},a=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/05-timeouts.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[];function c(e){const t={code:"code",p:"p",pre:"pre",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:["When a lambda times out it throws an error that cannot be caught by middy. To work around this middy maintains an ",(0,i.jsx)(t.code,{children:"AbortController"})," that can be signalled early to allow time to clean up and log the error properly."]}),"\n",(0,i.jsxs)(t.p,{children:["You can set ",(0,i.jsx)(t.code,{children:"timeoutEarlyInMillis"})," to 0 to disable this functionality. If you want to override during testing, mock the lambda context to set ",(0,i.jsx)(t.code,{children:"getRemainingTimeInMillis"})," to a function that returns a very large value (e.g. ",(0,i.jsx)(t.code,{children:"() => 99999"}),")."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"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({\n timeoutEarlyInMillis: 50,\n timeoutEarlyResponse: () => {\n return {\n statusCode: 408\n }\n }\n}).handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>s,a:()=>a});var i=n(7294);const o={},r=i.createContext(o);function a(e){const t=i.useContext(r);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),i.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/646b055a.e743fb12.js b/assets/js/646b055a.e30262ea.js similarity index 97% rename from assets/js/646b055a.e743fb12.js rename to assets/js/646b055a.e30262ea.js index a4b0774bd..81b694feb 100644 --- a/assets/js/646b055a.e743fb12.js +++ b/assets/js/646b055a.e30262ea.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5686],{4468:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>r,toc:()=>d});var s=n(5893),i=n(1151);const o={title:"S3 Batch"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/s3-batch.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"S3 Batch"},sidebar:"tutorialSidebar",previous:{title:"RDS",permalink:"/docs/events/rds"},next:{title:"S3 Object",permalink:"/docs/events/s3-object"}},c={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-s3-batch.html",children:"Using AWS Lambda with Amazon S3 batch operations"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var s=n(7294);const i={},o=s.createContext(i);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5686],{4468:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>r,toc:()=>d});var s=n(5893),i=n(1151);const o={title:"S3 Batch"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/s3-batch.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"S3 Batch"},sidebar:"tutorialSidebar",previous:{title:"RDS",permalink:"/docs/events/rds"},next:{title:"S3 Object",permalink:"/docs/events/s3-object"}},c={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-s3-batch.html",children:"Using AWS Lambda with Amazon S3 batch operations"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var s=n(7294);const i={},o=s.createContext(i);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/654635c7.dc35b4f1.js b/assets/js/654635c7.04dc4505.js similarity index 99% rename from assets/js/654635c7.dc35b4f1.js rename to assets/js/654635c7.04dc4505.js index 73440cc1a..02de7e1d6 100644 --- a/assets/js/654635c7.dc35b4f1.js +++ b/assets/js/654635c7.04dc4505.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1338],{7803:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>u,contentTitle:()=>d,default:()=>p,frontMatter:()=>o,metadata:()=>i,toc:()=>c});var n=r(5893),a=r(1151),l=r(4866),s=r(5162);const o={title:"http-router"},d=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/routers/http-router.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"http-router"},sidebar:"tutorialSidebar",previous:{title:"Routers",permalink:"/docs/category/routers"},next:{title:"ws-router",permalink:"/docs/routers/ws-router"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const t={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["This handler can route to requests to one of a nested handler based on ",(0,n.jsx)(t.code,{children:"method"})," and ",(0,n.jsx)(t.code,{children:"path"})," of an http event from API Gateway (REST or HTTP) or Elastic Load Balancer."]}),"\n",(0,n.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(s.Z,{value:"npm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-router\n"})})}),(0,n.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-router\n"})})}),(0,n.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-router\n"})})})]}),"\n",(0,n.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"routes"})," (array[{method, path, handler}]) (required): Array of route objects.","\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"method"})," (string) (required): One of ",(0,n.jsx)(t.code,{children:"GET"}),", ",(0,n.jsx)(t.code,{children:"POST"}),", ",(0,n.jsx)(t.code,{children:"PUT"}),", ",(0,n.jsx)(t.code,{children:"PATCH"}),", ",(0,n.jsx)(t.code,{children:"DELETE"}),", ",(0,n.jsx)(t.code,{children:"OPTIONS"})," and ",(0,n.jsx)(t.code,{children:"ANY"})," that will match to any method passed in"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"path"})," (string) (required): AWS formatted path starting with ",(0,n.jsx)(t.code,{children:"/"}),". Variable: ",(0,n.jsx)(t.code,{children:"/{id}/"}),", Wildcard: ",(0,n.jsx)(t.code,{children:"/{proxy+}"})]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"handler"})," (function) (required): Any ",(0,n.jsx)(t.code,{children:"handler(event, context)"})," function"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,n.jsx)(t.p,{children:"NOTES:"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:["When using API Gateway it may be required to prefix ",(0,n.jsx)(t.code,{children:"routes[].path"})," with ",(0,n.jsx)(t.code,{children:"/{stage}"})," depending on your use case."]}),"\n",(0,n.jsxs)(t.li,{children:["Errors should be handled as part of the router middleware stack ",(0,n.jsx)(t.strong,{children:"or"})," the lambdaHandler middleware stack. Handled errors in the later will trigger the ",(0,n.jsx)(t.code,{children:"after"})," middleware stack of the former."]}),"\n",(0,n.jsx)(t.li,{children:"Shared middlewares, connected to the router middleware stack, can only be run before the lambdaHandler middleware stack."}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"pathParameters"})," will automatically be set if not already set"]}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function p(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},5162:(e,t,r)=>{r.d(t,{Z:()=>s});r(7294);var n=r(6010);const a={tabItem:"tabItem_Ymn6"};var l=r(5893);function s(e){let{children:t,hidden:r,className:s}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,n.Z)(a.tabItem,s),hidden:r,children:t})}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var n=r(7294),a=r(6010),l=r(2466),s=r(6550),o=r(469),d=r(1980),i=r(7392),u=r(12);function c(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function h(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}(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 p(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:r}=e;const a=(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,d._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=h(e),[s,d]=(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 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,c]=m({queryString:r,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,u.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:a}),x=(()=>{const e=i??f;return p({value:e,tabValues:l})?e:null})();(0,o.Z)((()=>{x&&d(x)}),[x]);return{selectedValue:s,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);d(e),c(e),b(e)}),[c,b,l]),tabValues:l}}var b=r(2389);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=r(5893);function j(e){let{className:t,block:r,selectedValue:n,selectValue:s,tabValues:o}=e;const d=[],{blockElementScrollPositionUntilNextRender:i}=(0,l.o5)(),u=e=>{const t=e.currentTarget,r=d.indexOf(t),a=o[r].value;a!==n&&(i(t),s(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(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(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":r},t),children:o.map((e=>{let{value:t,label:r,attributes:l}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>d.push(e),onKeyDown:c,onClick:u,...l,className:(0,a.Z)("tabs__item",x.tabItem,l?.className,{"tabs__item--active":n===t}),children:r??t},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(0,v.jsx)("div",{className:"margin-top--md",children:l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=f(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",x.tabList),children:[(0,v.jsx)(j,{...e,...t}),(0,v.jsx)(g,{...e,...t})]})}function w(e){const t=(0,b.Z)();return(0,v.jsx)(y,{...e,children:c(e.children)},String(t))}},1151:(e,t,r)=>{r.d(t,{Z:()=>o,a:()=>s});var n=r(7294);const a={},l=n.createContext(a);function s(e){const t=n.useContext(l);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:s(e.components),n.createElement(l.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1338],{7803:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>u,contentTitle:()=>d,default:()=>p,frontMatter:()=>o,metadata:()=>i,toc:()=>c});var n=r(5893),a=r(1151),l=r(4866),s=r(5162);const o={title:"http-router"},d=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/routers/http-router.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"http-router"},sidebar:"tutorialSidebar",previous:{title:"Routers",permalink:"/docs/category/routers"},next:{title:"ws-router",permalink:"/docs/routers/ws-router"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const t={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["This handler can route to requests to one of a nested handler based on ",(0,n.jsx)(t.code,{children:"method"})," and ",(0,n.jsx)(t.code,{children:"path"})," of an http event from API Gateway (REST or HTTP) or Elastic Load Balancer."]}),"\n",(0,n.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(s.Z,{value:"npm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-router\n"})})}),(0,n.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-router\n"})})}),(0,n.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-router\n"})})})]}),"\n",(0,n.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"routes"})," (array[{method, path, handler}]) (required): Array of route objects.","\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"method"})," (string) (required): One of ",(0,n.jsx)(t.code,{children:"GET"}),", ",(0,n.jsx)(t.code,{children:"POST"}),", ",(0,n.jsx)(t.code,{children:"PUT"}),", ",(0,n.jsx)(t.code,{children:"PATCH"}),", ",(0,n.jsx)(t.code,{children:"DELETE"}),", ",(0,n.jsx)(t.code,{children:"OPTIONS"})," and ",(0,n.jsx)(t.code,{children:"ANY"})," that will match to any method passed in"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"path"})," (string) (required): AWS formatted path starting with ",(0,n.jsx)(t.code,{children:"/"}),". Variable: ",(0,n.jsx)(t.code,{children:"/{id}/"}),", Wildcard: ",(0,n.jsx)(t.code,{children:"/{proxy+}"})]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"handler"})," (function) (required): Any ",(0,n.jsx)(t.code,{children:"handler(event, context)"})," function"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,n.jsx)(t.p,{children:"NOTES:"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:["When using API Gateway it may be required to prefix ",(0,n.jsx)(t.code,{children:"routes[].path"})," with ",(0,n.jsx)(t.code,{children:"/{stage}"})," depending on your use case."]}),"\n",(0,n.jsxs)(t.li,{children:["Errors should be handled as part of the router middleware stack ",(0,n.jsx)(t.strong,{children:"or"})," the lambdaHandler middleware stack. Handled errors in the later will trigger the ",(0,n.jsx)(t.code,{children:"after"})," middleware stack of the former."]}),"\n",(0,n.jsx)(t.li,{children:"Shared middlewares, connected to the router middleware stack, can only be run before the lambdaHandler middleware stack."}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"pathParameters"})," will automatically be set if not already set"]}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function p(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},5162:(e,t,r)=>{r.d(t,{Z:()=>s});r(7294);var n=r(6010);const a={tabItem:"tabItem_Ymn6"};var l=r(5893);function s(e){let{children:t,hidden:r,className:s}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,n.Z)(a.tabItem,s),hidden:r,children:t})}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var n=r(7294),a=r(6010),l=r(2466),s=r(6550),o=r(469),d=r(1980),i=r(7392),u=r(12);function c(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function h(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}(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 p(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:r}=e;const a=(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,d._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=h(e),[s,d]=(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 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,c]=m({queryString:r,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,l]=(0,u.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&l.set(e)}),[r,l])]}({groupId:a}),x=(()=>{const e=i??f;return p({value:e,tabValues:l})?e:null})();(0,o.Z)((()=>{x&&d(x)}),[x]);return{selectedValue:s,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);d(e),c(e),b(e)}),[c,b,l]),tabValues:l}}var b=r(2389);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=r(5893);function j(e){let{className:t,block:r,selectedValue:n,selectValue:s,tabValues:o}=e;const d=[],{blockElementScrollPositionUntilNextRender:i}=(0,l.o5)(),u=e=>{const t=e.currentTarget,r=d.indexOf(t),a=o[r].value;a!==n&&(i(t),s(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(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(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":r},t),children:o.map((e=>{let{value:t,label:r,attributes:l}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>d.push(e),onKeyDown:c,onClick:u,...l,className:(0,a.Z)("tabs__item",x.tabItem,l?.className,{"tabs__item--active":n===t}),children:r??t},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(0,v.jsx)("div",{className:"margin-top--md",children:l.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=f(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",x.tabList),children:[(0,v.jsx)(j,{...e,...t}),(0,v.jsx)(g,{...e,...t})]})}function w(e){const t=(0,b.Z)();return(0,v.jsx)(y,{...e,children:c(e.children)},String(t))}},1151:(e,t,r)=>{r.d(t,{Z:()=>o,a:()=>s});var n=r(7294);const a={},l=n.createContext(a);function s(e){const t=n.useContext(l);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:s(e.components),n.createElement(l.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/65ce35be.70a66fc9.js b/assets/js/65ce35be.27bca138.js similarity index 97% rename from assets/js/65ce35be.70a66fc9.js rename to assets/js/65ce35be.27bca138.js index 1f39dc0b8..ee8f34ea2 100644 --- a/assets/js/65ce35be.70a66fc9.js +++ b/assets/js/65ce35be.27bca138.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8002],{350:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>o,default:()=>m,frontMatter:()=>s,metadata:()=>r,toc:()=>l});var a=t(5893),i=t(1151);const s={title:"Kafka, Self-Managed"},o=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kafka-self-managed.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.admonition,{type:"caution",children:(0,a.jsx)(n.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,a.jsx)(n.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsx)(n.li,{children:(0,a.jsx)(n.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-kafka.html",children:"Using Lambda with self-managed Apache Kafka"})}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(c,{...e})}):c(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>r,a:()=>o});var a=t(7294);const i={},s=a.createContext(i);function o(e){const n=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),a.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8002],{350:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>o,default:()=>m,frontMatter:()=>s,metadata:()=>r,toc:()=>l});var a=t(5893),i=t(1151);const s={title:"Kafka, Self-Managed"},o=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kafka-self-managed.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.admonition,{type:"caution",children:(0,a.jsx)(n.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,a.jsx)(n.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsx)(n.li,{children:(0,a.jsx)(n.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-kafka.html",children:"Using Lambda with self-managed Apache Kafka"})}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(c,{...e})}):c(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>r,a:()=>o});var a=t(7294);const i={},s=a.createContext(i);function o(e){const n=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),a.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/667584a0.c856e970.js b/assets/js/667584a0.326b11e5.js similarity index 97% rename from assets/js/667584a0.c856e970.js rename to assets/js/667584a0.326b11e5.js index e9b24fa0d..3664cc970 100644 --- a/assets/js/667584a0.c856e970.js +++ b/assets/js/667584a0.326b11e5.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2600],{7199:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>r,toc:()=>c});var s=n(5893),i=n(1151);const o={title:"SNS"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/sns.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"SNS"},sidebar:"tutorialSidebar",previous:{title:"SES",permalink:"/docs/events/ses"},next:{title:"SQS",permalink:"/docs/events/sqs"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html",children:"Using AWS Lambda with Amazon SNS"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var s=n(7294);const i={},o=s.createContext(i);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2600],{7199:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>r,toc:()=>c});var s=n(5893),i=n(1151);const o={title:"SNS"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/sns.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"SNS"},sidebar:"tutorialSidebar",previous:{title:"SES",permalink:"/docs/events/ses"},next:{title:"SQS",permalink:"/docs/events/sqs"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html",children:"Using AWS Lambda with Amazon SNS"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var s=n(7294);const i={},o=s.createContext(i);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/68318e94.f0552e72.js b/assets/js/68318e94.9ebd069a.js similarity index 97% rename from assets/js/68318e94.f0552e72.js rename to assets/js/68318e94.9ebd069a.js index 54a36a73d..659426035 100644 --- a/assets/js/68318e94.f0552e72.js +++ b/assets/js/68318e94.9ebd069a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[811],{4756:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var n=a(5893),i=a(1151);const o={title:"API Gateway Authorizer"},r=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-authorizer.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,n.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html",children:"Working with AWS Lambda authorizers for HTTP APIs"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-input.html",children:"Input to an Amazon API Gateway Lambda authorizer"})}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n"})})]})}function p(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(c,{...e})}):c(e)}},1151:(e,t,a)=>{a.d(t,{Z:()=>s,a:()=>r});var n=a(7294);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[811],{4756:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var n=a(5893),i=a(1151);const o={title:"API Gateway Authorizer"},r=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-authorizer.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,n.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html",children:"Working with AWS Lambda authorizers for HTTP APIs"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-input.html",children:"Input to an Amazon API Gateway Lambda authorizer"})}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n"})})]})}function p(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(c,{...e})}):c(e)}},1151:(e,t,a)=>{a.d(t,{Z:()=>s,a:()=>r});var n=a(7294);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/687b60fb.12305578.js b/assets/js/687b60fb.4df6009f.js similarity index 98% rename from assets/js/687b60fb.12305578.js rename to assets/js/687b60fb.4df6009f.js index 3af3b62a0..c8cdf3b50 100644 --- a/assets/js/687b60fb.12305578.js +++ b/assets/js/687b60fb.4df6009f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7783],{1476:(e,d,n)=>{n.r(d),n.d(d,{assets:()=>a,contentTitle:()=>o,default:()=>l,frontMatter:()=>t,metadata:()=>i,toc:()=>c});var r=n(5893),s=n(1151);const t={title:"Upgrade 0.x -> 1.x",sidebar_position:1e4},o=void 0,i={id:"upgrade/0-1",title:"Upgrade 0.x -> 1.x",description:'aka "The It\'s Stable Update"',source:"@site/docs/upgrade/0-1.md",sourceDirName:"upgrade",slug:"/upgrade/0-1",permalink:"/docs/upgrade/0-1",draft:!1,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/0-1.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},a={},c=[{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}];function h(e){const d={a:"a",code:"code",h2:"h2",li:"li",p:"p",ul:"ul",...(0,s.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(d.p,{children:'aka "The It\'s Stable Update"'}),"\n",(0,r.jsx)(d.h2,{id:"independent-packages-structure",children:"Independent packages structure"}),"\n",(0,r.jsxs)(d.p,{children:["Version 1.x of Middy features decoupled independent packages published on npm under the ",(0,r.jsx)(d.code,{children:"@middy"})," namespace. The core middleware engine has been moved to ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/core",children:(0,r.jsx)(d.code,{children:"@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:"]}),"\n",(0,r.jsxs)(d.ul,{children:["\n",(0,r.jsxs)(d.li,{children:["Core middleware functionality -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/core",children:(0,r.jsx)(d.code,{children:"@middy/core"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"cache"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/cache",children:(0,r.jsx)(d.code,{children:"@middy/cache"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"cors"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-cors",children:(0,r.jsx)(d.code,{children:"@middy/http-cors"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"doNotWaitForEmptyEventLoop"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/do-not-wait-for-empty-event-loop",children:(0,r.jsx)(d.code,{children:"@middy/do-not-wait-for-empty-event-loop"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"httpContentNegotiation"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-content-negotiation",children:(0,r.jsx)(d.code,{children:"@middy/http-content-negotiation"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"httpErrorHandler"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-error-handler",children:(0,r.jsx)(d.code,{children:"@middy/http-error-handler"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"httpEventNormalizer"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-event-normalizer",children:(0,r.jsx)(d.code,{children:"@middy/http-event-normalizer"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"httpHeaderNormalizer"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-header-normalizer",children:(0,r.jsx)(d.code,{children:"@middy/http-header-normalizer"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"httpMultipartBodyParser"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-json-body-parser",children:(0,r.jsx)(d.code,{children:"@middy/http-json-body-parser"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"httpPartialResponse"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-partial-response",children:(0,r.jsx)(d.code,{children:"@middy/http-partial-response"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"jsonBodyParser"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-json-body-parser",children:(0,r.jsx)(d.code,{children:"@middy/http-json-body-parser"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"s3KeyNormalizer"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/s3-key-normalizer",children:(0,r.jsx)(d.code,{children:"@middy/s3-key-normalizer"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"secretsManager"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/secrets-manager",children:(0,r.jsx)(d.code,{children:"@middy/secrets-manager"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"ssm"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/ssm",children:(0,r.jsx)(d.code,{children:"@middy/ssm"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"validator"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/validator",children:(0,r.jsx)(d.code,{children:"@middy/validator"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"urlEncodeBodyParser"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-urlencode-body-parser",children:(0,r.jsx)(d.code,{children:"@middy/http-urlencode-body-parser"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"warmup"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/warmup",children:(0,r.jsx)(d.code,{children:"@middy/warmup"})})]}),"\n"]}),"\n",(0,r.jsxs)(d.h2,{id:"header-normalization-in-http-header-normalizer",children:["Header normalization in ",(0,r.jsx)(d.code,{children:"http-header-normalizer"})]}),"\n",(0,r.jsxs)(d.p,{children:["In Middy 0.x the ",(0,r.jsx)(d.code,{children:"httpHeaderNormalizer"})," middleware normalizes HTTP header names into their own canonical format, for instance ",(0,r.jsx)(d.code,{children:"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.jsx)(d.code,{children:"sec-webSocket-key"}),"). This new behavior is more consistent with what Node.js core ",(0,r.jsx)(d.code,{children:"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."]}),"\n",(0,r.jsx)(d.h2,{id:"nodejs-10-and-12-now-supported--nodejs-6-and-8-now-dropped",children:"Node.js 10 and 12 now supported / Node.js 6 and 8 now dropped"}),"\n",(0,r.jsx)(d.p,{children:"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."})]})}function l(e={}){const{wrapper:d}={...(0,s.a)(),...e.components};return d?(0,r.jsx)(d,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},1151:(e,d,n)=>{n.d(d,{Z:()=>i,a:()=>o});var r=n(7294);const s={},t=r.createContext(s);function o(e){const d=r.useContext(t);return r.useMemo((function(){return"function"==typeof e?e(d):{...d,...e}}),[d,e])}function i(e){let d;return d=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),r.createElement(t.Provider,{value:d},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7783],{1476:(e,d,n)=>{n.r(d),n.d(d,{assets:()=>a,contentTitle:()=>o,default:()=>l,frontMatter:()=>t,metadata:()=>i,toc:()=>c});var r=n(5893),s=n(1151);const t={title:"Upgrade 0.x -> 1.x",sidebar_position:1e4},o=void 0,i={id:"upgrade/0-1",title:"Upgrade 0.x -> 1.x",description:'aka "The It\'s Stable Update"',source:"@site/docs/upgrade/0-1.md",sourceDirName:"upgrade",slug:"/upgrade/0-1",permalink:"/docs/upgrade/0-1",draft:!1,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/0-1.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},a={},c=[{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}];function h(e){const d={a:"a",code:"code",h2:"h2",li:"li",p:"p",ul:"ul",...(0,s.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(d.p,{children:'aka "The It\'s Stable Update"'}),"\n",(0,r.jsx)(d.h2,{id:"independent-packages-structure",children:"Independent packages structure"}),"\n",(0,r.jsxs)(d.p,{children:["Version 1.x of Middy features decoupled independent packages published on npm under the ",(0,r.jsx)(d.code,{children:"@middy"})," namespace. The core middleware engine has been moved to ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/core",children:(0,r.jsx)(d.code,{children:"@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:"]}),"\n",(0,r.jsxs)(d.ul,{children:["\n",(0,r.jsxs)(d.li,{children:["Core middleware functionality -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/core",children:(0,r.jsx)(d.code,{children:"@middy/core"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"cache"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/cache",children:(0,r.jsx)(d.code,{children:"@middy/cache"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"cors"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-cors",children:(0,r.jsx)(d.code,{children:"@middy/http-cors"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"doNotWaitForEmptyEventLoop"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/do-not-wait-for-empty-event-loop",children:(0,r.jsx)(d.code,{children:"@middy/do-not-wait-for-empty-event-loop"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"httpContentNegotiation"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-content-negotiation",children:(0,r.jsx)(d.code,{children:"@middy/http-content-negotiation"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"httpErrorHandler"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-error-handler",children:(0,r.jsx)(d.code,{children:"@middy/http-error-handler"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"httpEventNormalizer"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-event-normalizer",children:(0,r.jsx)(d.code,{children:"@middy/http-event-normalizer"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"httpHeaderNormalizer"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-header-normalizer",children:(0,r.jsx)(d.code,{children:"@middy/http-header-normalizer"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"httpMultipartBodyParser"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-json-body-parser",children:(0,r.jsx)(d.code,{children:"@middy/http-json-body-parser"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"httpPartialResponse"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-partial-response",children:(0,r.jsx)(d.code,{children:"@middy/http-partial-response"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"jsonBodyParser"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-json-body-parser",children:(0,r.jsx)(d.code,{children:"@middy/http-json-body-parser"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"s3KeyNormalizer"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/s3-key-normalizer",children:(0,r.jsx)(d.code,{children:"@middy/s3-key-normalizer"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"secretsManager"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/secrets-manager",children:(0,r.jsx)(d.code,{children:"@middy/secrets-manager"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"ssm"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/ssm",children:(0,r.jsx)(d.code,{children:"@middy/ssm"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"validator"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/validator",children:(0,r.jsx)(d.code,{children:"@middy/validator"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"urlEncodeBodyParser"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/http-urlencode-body-parser",children:(0,r.jsx)(d.code,{children:"@middy/http-urlencode-body-parser"})})]}),"\n",(0,r.jsxs)(d.li,{children:[(0,r.jsx)(d.code,{children:"warmup"})," -> ",(0,r.jsx)(d.a,{href:"https://www.npmjs.com/package/@middy/warmup",children:(0,r.jsx)(d.code,{children:"@middy/warmup"})})]}),"\n"]}),"\n",(0,r.jsxs)(d.h2,{id:"header-normalization-in-http-header-normalizer",children:["Header normalization in ",(0,r.jsx)(d.code,{children:"http-header-normalizer"})]}),"\n",(0,r.jsxs)(d.p,{children:["In Middy 0.x the ",(0,r.jsx)(d.code,{children:"httpHeaderNormalizer"})," middleware normalizes HTTP header names into their own canonical format, for instance ",(0,r.jsx)(d.code,{children:"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.jsx)(d.code,{children:"sec-webSocket-key"}),"). This new behavior is more consistent with what Node.js core ",(0,r.jsx)(d.code,{children:"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."]}),"\n",(0,r.jsx)(d.h2,{id:"nodejs-10-and-12-now-supported--nodejs-6-and-8-now-dropped",children:"Node.js 10 and 12 now supported / Node.js 6 and 8 now dropped"}),"\n",(0,r.jsx)(d.p,{children:"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."})]})}function l(e={}){const{wrapper:d}={...(0,s.a)(),...e.components};return d?(0,r.jsx)(d,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},1151:(e,d,n)=>{n.d(d,{Z:()=>i,a:()=>o});var r=n(7294);const s={},t=r.createContext(s);function o(e){const d=r.useContext(t);return r.useMemo((function(){return"function"==typeof e?e(d):{...d,...e}}),[d,e])}function i(e){let d;return d=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),r.createElement(t.Provider,{value:d},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6a1376e9.81fc68cb.js b/assets/js/6a1376e9.e5c32d03.js similarity index 99% rename from assets/js/6a1376e9.81fc68cb.js rename to assets/js/6a1376e9.e5c32d03.js index d03cf2980..058745154 100644 --- a/assets/js/6a1376e9.81fc68cb.js +++ b/assets/js/6a1376e9.e5c32d03.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8644],{8550:(e,a,t)=>{t.r(a),t.d(a,{assets:()=>c,contentTitle:()=>o,default:()=>m,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var r=t(5893),n=t(1151),s=t(4866),l=t(5162);const i={title:"sqs-partial-batch-failure"},o=void 0,u={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/sqs-partial-batch-failure.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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}];function p(e){const a={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,n.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(a.p,{children:"Middleware for handling partially failed SQS batches."}),"\n",(0,r.jsx)(a.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(a.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(l.Z,{value:"npm",children:(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-bash",children:"npm install --save @middy/sqs-partial-batch-failure\n# Required for types only\nnpm install --save-dev @aws-sdk/client-sqs\n"})})}),(0,r.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-bash",children:"yarn add @middy/sqs-partial-batch-failure\n# Required for types only\nyarn add --dev @aws-sdk/client-sqs\n"})})}),(0,r.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-bash",children:"pnpm add @middy/sqs-partial-batch-failure\n# Required for types only\npnpm add --save-dev @aws-sdk/client-sqs\n"})})})]}),"\n",(0,r.jsx)(a.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(a.ul,{children:["\n",(0,r.jsxs)(a.li,{children:[(0,r.jsx)(a.code,{children:"logger"})," (function) (optional): A function that will be called when a record fails to be processed. Default: ",(0,r.jsx)(a.code,{children:"console.error"})]}),"\n"]}),"\n",(0,r.jsx)(a.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-javascript",children:"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().use(sqsBatch()).handler(lambdaHandler)\n"})}),"\n",(0,r.jsx)(a.h2,{id:"important",children:"Important"}),"\n",(0,r.jsxs)(a.p,{children:["The value ",(0,r.jsx)(a.code,{children:"ReportBatchItemFailures"})," must be added to your Lambda's ",(0,r.jsx)(a.code,{children:"FunctionResponseTypes"})," in the ",(0,r.jsx)(a.code,{children:"EventSourceMapping"}),". See ",(0,r.jsx)(a.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting",children:"Reporting batch item failures"})," and ",(0,r.jsx)(a.a,{href:"https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html",children:"Lambda EventSourceMapping"})]})]})}function m(e={}){const{wrapper:a}={...(0,n.a)(),...e.components};return a?(0,r.jsx)(a,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,a,t)=>{t.d(a,{Z:()=>l});t(7294);var r=t(6010);const n={tabItem:"tabItem_Ymn6"};var s=t(5893);function l(e){let{children:a,hidden:t,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(n.tabItem,l),hidden:t,children:a})}},4866:(e,a,t)=>{t.d(a,{Z:()=>w});var r=t(7294),n=t(6010),s=t(2466),l=t(6550),i=t(469),o=t(1980),u=t(7392),c=t(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:a}=e;return!!a&&"object"==typeof a&&"value"in a}(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)??[]}function p(e){const{values:a,children:t}=e;return(0,r.useMemo)((()=>{const e=a??function(e){return d(e).map((e=>{let{props:{value:a,label:t,attributes:r,default:n}}=e;return{value:a,label:t,attributes:r,default:n}}))}(t);return function(e){const a=(0,u.l)(e,((e,a)=>e.value===a.value));if(a.length>0)throw new Error(`Docusaurus error: Duplicate values "${a.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[a,t])}function m(e){let{value:a,tabValues:t}=e;return t.some((e=>e.value===a))}function h(e){let{queryString:a=!1,groupId:t}=e;const n=(0,l.k6)(),s=function(e){let{queryString:a=!1,groupId:t}=e;if("string"==typeof a)return a;if(!1===a)return null;if(!0===a&&!t)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 t??null}({queryString:a,groupId:t});return[(0,o._X)(s),(0,r.useCallback)((e=>{if(!s)return;const a=new URLSearchParams(n.location.search);a.set(s,e),n.replace({...n.location,search:a.toString()})}),[s,n])]}function f(e){const{defaultValue:a,queryString:t=!1,groupId:n}=e,s=p(e),[l,o]=(0,r.useState)((()=>function(e){let{defaultValue:a,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(a){if(!m({value:a,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${a}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return a}const r=t.find((e=>e.default))??t[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:a,tabValues:s}))),[u,d]=h({queryString:t,groupId:n}),[f,b]=function(e){let{groupId:a}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(a),[n,s]=(0,c.Nk)(t);return[n,(0,r.useCallback)((e=>{t&&s.set(e)}),[t,s])]}({groupId:n}),v=(()=>{const e=u??f;return m({value:e,tabValues:s})?e:null})();(0,i.Z)((()=>{v&&o(v)}),[v]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),b(e)}),[d,b,s]),tabValues:s}}var b=t(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=t(5893);function y(e){let{className:a,block:t,selectedValue:r,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.o5)(),c=e=>{const a=e.currentTarget,t=o.indexOf(a),n=i[t].value;n!==r&&(u(a),l(n))},d=e=>{let a=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;a=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;a=o[t]??o[o.length-1];break}}a?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,n.Z)("tabs",{"tabs--block":t},a),children:i.map((e=>{let{value:a,label:t,attributes:s}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:r===a?0:-1,"aria-selected":r===a,ref:e=>o.push(e),onKeyDown:d,onClick:c,...s,className:(0,n.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":r===a}),children:t??a},a)}))})}function x(e){let{lazy:a,children:t,selectedValue:n}=e;const s=(Array.isArray(t)?t:[t]).filter(Boolean);if(a){const e=s.find((e=>e.props.value===n));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:s.map(((e,a)=>(0,r.cloneElement)(e,{key:a,hidden:e.props.value!==n})))})}function j(e){const a=f(e);return(0,g.jsxs)("div",{className:(0,n.Z)("tabs-container",v.tabList),children:[(0,g.jsx)(y,{...e,...a}),(0,g.jsx)(x,{...e,...a})]})}function w(e){const a=(0,b.Z)();return(0,g.jsx)(j,{...e,children:d(e.children)},String(a))}},1151:(e,a,t)=>{t.d(a,{Z:()=>i,a:()=>l});var r=t(7294);const n={},s=r.createContext(n);function l(e){const a=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(a):{...a,...e}}),[a,e])}function i(e){let a;return a=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:l(e.components),r.createElement(s.Provider,{value:a},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8644],{8550:(e,a,t)=>{t.r(a),t.d(a,{assets:()=>c,contentTitle:()=>o,default:()=>m,frontMatter:()=>i,metadata:()=>u,toc:()=>d});var r=t(5893),n=t(1151),s=t(4866),l=t(5162);const i={title:"sqs-partial-batch-failure"},o=void 0,u={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/sqs-partial-batch-failure.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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}];function p(e){const a={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,n.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(a.p,{children:"Middleware for handling partially failed SQS batches."}),"\n",(0,r.jsx)(a.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(a.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(l.Z,{value:"npm",children:(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-bash",children:"npm install --save @middy/sqs-partial-batch-failure\n# Required for types only\nnpm install --save-dev @aws-sdk/client-sqs\n"})})}),(0,r.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-bash",children:"yarn add @middy/sqs-partial-batch-failure\n# Required for types only\nyarn add --dev @aws-sdk/client-sqs\n"})})}),(0,r.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-bash",children:"pnpm add @middy/sqs-partial-batch-failure\n# Required for types only\npnpm add --save-dev @aws-sdk/client-sqs\n"})})})]}),"\n",(0,r.jsx)(a.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(a.ul,{children:["\n",(0,r.jsxs)(a.li,{children:[(0,r.jsx)(a.code,{children:"logger"})," (function) (optional): A function that will be called when a record fails to be processed. Default: ",(0,r.jsx)(a.code,{children:"console.error"})]}),"\n"]}),"\n",(0,r.jsx)(a.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-javascript",children:"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().use(sqsBatch()).handler(lambdaHandler)\n"})}),"\n",(0,r.jsx)(a.h2,{id:"important",children:"Important"}),"\n",(0,r.jsxs)(a.p,{children:["The value ",(0,r.jsx)(a.code,{children:"ReportBatchItemFailures"})," must be added to your Lambda's ",(0,r.jsx)(a.code,{children:"FunctionResponseTypes"})," in the ",(0,r.jsx)(a.code,{children:"EventSourceMapping"}),". See ",(0,r.jsx)(a.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting",children:"Reporting batch item failures"})," and ",(0,r.jsx)(a.a,{href:"https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html",children:"Lambda EventSourceMapping"})]})]})}function m(e={}){const{wrapper:a}={...(0,n.a)(),...e.components};return a?(0,r.jsx)(a,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,a,t)=>{t.d(a,{Z:()=>l});t(7294);var r=t(6010);const n={tabItem:"tabItem_Ymn6"};var s=t(5893);function l(e){let{children:a,hidden:t,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(n.tabItem,l),hidden:t,children:a})}},4866:(e,a,t)=>{t.d(a,{Z:()=>w});var r=t(7294),n=t(6010),s=t(2466),l=t(6550),i=t(469),o=t(1980),u=t(7392),c=t(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:a}=e;return!!a&&"object"==typeof a&&"value"in a}(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)??[]}function p(e){const{values:a,children:t}=e;return(0,r.useMemo)((()=>{const e=a??function(e){return d(e).map((e=>{let{props:{value:a,label:t,attributes:r,default:n}}=e;return{value:a,label:t,attributes:r,default:n}}))}(t);return function(e){const a=(0,u.l)(e,((e,a)=>e.value===a.value));if(a.length>0)throw new Error(`Docusaurus error: Duplicate values "${a.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[a,t])}function m(e){let{value:a,tabValues:t}=e;return t.some((e=>e.value===a))}function h(e){let{queryString:a=!1,groupId:t}=e;const n=(0,l.k6)(),s=function(e){let{queryString:a=!1,groupId:t}=e;if("string"==typeof a)return a;if(!1===a)return null;if(!0===a&&!t)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 t??null}({queryString:a,groupId:t});return[(0,o._X)(s),(0,r.useCallback)((e=>{if(!s)return;const a=new URLSearchParams(n.location.search);a.set(s,e),n.replace({...n.location,search:a.toString()})}),[s,n])]}function f(e){const{defaultValue:a,queryString:t=!1,groupId:n}=e,s=p(e),[l,o]=(0,r.useState)((()=>function(e){let{defaultValue:a,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(a){if(!m({value:a,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${a}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return a}const r=t.find((e=>e.default))??t[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:a,tabValues:s}))),[u,d]=h({queryString:t,groupId:n}),[f,b]=function(e){let{groupId:a}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(a),[n,s]=(0,c.Nk)(t);return[n,(0,r.useCallback)((e=>{t&&s.set(e)}),[t,s])]}({groupId:n}),v=(()=>{const e=u??f;return m({value:e,tabValues:s})?e:null})();(0,i.Z)((()=>{v&&o(v)}),[v]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),d(e),b(e)}),[d,b,s]),tabValues:s}}var b=t(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=t(5893);function y(e){let{className:a,block:t,selectedValue:r,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.o5)(),c=e=>{const a=e.currentTarget,t=o.indexOf(a),n=i[t].value;n!==r&&(u(a),l(n))},d=e=>{let a=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;a=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;a=o[t]??o[o.length-1];break}}a?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,n.Z)("tabs",{"tabs--block":t},a),children:i.map((e=>{let{value:a,label:t,attributes:s}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:r===a?0:-1,"aria-selected":r===a,ref:e=>o.push(e),onKeyDown:d,onClick:c,...s,className:(0,n.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":r===a}),children:t??a},a)}))})}function x(e){let{lazy:a,children:t,selectedValue:n}=e;const s=(Array.isArray(t)?t:[t]).filter(Boolean);if(a){const e=s.find((e=>e.props.value===n));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:s.map(((e,a)=>(0,r.cloneElement)(e,{key:a,hidden:e.props.value!==n})))})}function j(e){const a=f(e);return(0,g.jsxs)("div",{className:(0,n.Z)("tabs-container",v.tabList),children:[(0,g.jsx)(y,{...e,...a}),(0,g.jsx)(x,{...e,...a})]})}function w(e){const a=(0,b.Z)();return(0,g.jsx)(j,{...e,children:d(e.children)},String(a))}},1151:(e,a,t)=>{t.d(a,{Z:()=>i,a:()=>l});var r=t(7294);const n={},s=r.createContext(n);function l(e){const a=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(a):{...a,...e}}),[a,e])}function i(e){let a;return a=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:l(e.components),r.createElement(s.Provider,{value:a},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6c4d050a.c509b4ce.js b/assets/js/6c4d050a.81b70126.js similarity index 99% rename from assets/js/6c4d050a.c509b4ce.js rename to assets/js/6c4d050a.81b70126.js index 9d1240c27..611aedb5f 100644 --- a/assets/js/6c4d050a.c509b4ce.js +++ b/assets/js/6c4d050a.81b70126.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5512],{9794:(e,r,a)=>{a.r(r),a.d(r,{assets:()=>u,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>d,toc:()=>c});var t=a(5893),n=a(1151),l=a(4866),s=a(5162);const o={title:"http-header-normalizer"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-header-normalizer.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const r={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,n.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(r.p,{children:"This middleware normalizes HTTP header names. By default, it normalizes to lowercase. It\ncan also normalize to canonical form."}),"\n",(0,t.jsx)(r.p,{children:"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."}),"\n",(0,t.jsxs)(r.p,{children:["Other middlewares like ",(0,t.jsx)(r.a,{href:"#jsonbodyparser",children:(0,t.jsx)(r.code,{children:"jsonBodyParser"})})," or ",(0,t.jsx)(r.a,{href:"#urlencodebodyparser",children:(0,t.jsx)(r.code,{children:"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."]}),"\n",(0,t.jsxs)(r.p,{children:["This middleware will copy the original headers in ",(0,t.jsx)(r.code,{children:"event.rawHeaders"}),"."]}),"\n",(0,t.jsx)(r.h2,{id:"install",children:"Install"}),"\n",(0,t.jsx)(r.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,t.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,t.jsx)(s.Z,{value:"npm",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"npm install --save @middy/http-header-normalizer\n"})})}),(0,t.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"yarn add @middy/http-header-normalizer\n"})})}),(0,t.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"pnpm add @middy/http-header-normalizer\n"})})})]}),"\n",(0,t.jsx)(r.h2,{id:"options",children:"Options"}),"\n",(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.code,{children:"canonical"})," (bool) (optional): if true, modifies the headers to canonical format, otherwise the headers are normalized to lowercase (default ",(0,t.jsx)(r.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.code,{children:"defaultHeaders"})," (object) (optional): Default headers to used if any are missing. i.e. ",(0,t.jsx)(r.code,{children:"Content-Type"})," (default ",(0,t.jsx)(r.code,{children:"{}"}),")"]}),"\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.code,{children:"normalizeHeaderKey"})," (function) (optional): a function that accepts an header name as a parameter and returns its\ncanonical representation."]}),"\n"]}),"\n",(0,t.jsx)(r.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .use(httpHeaderNormalizer())\n .handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:r}={...(0,n.a)(),...e.components};return r?(0,t.jsx)(r,{...e,children:(0,t.jsx)(h,{...e})}):h(e)}},5162:(e,r,a)=>{a.d(r,{Z:()=>s});a(7294);var t=a(6010);const n={tabItem:"tabItem_Ymn6"};var l=a(5893);function s(e){let{children:r,hidden:a,className:s}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,t.Z)(n.tabItem,s),hidden:a,children:r})}},4866:(e,r,a)=>{a.d(r,{Z:()=>g});var t=a(7294),n=a(6010),l=a(2466),s=a(6550),o=a(469),i=a(1980),d=a(7392),u=a(12);function c(e){return t.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:r}=e;return!!r&&"object"==typeof r&&"value"in r}(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)??[]}function h(e){const{values:r,children:a}=e;return(0,t.useMemo)((()=>{const e=r??function(e){return c(e).map((e=>{let{props:{value:r,label:a,attributes:t,default:n}}=e;return{value:r,label:a,attributes:t,default:n}}))}(a);return function(e){const r=(0,d.l)(e,((e,r)=>e.value===r.value));if(r.length>0)throw new Error(`Docusaurus error: Duplicate values "${r.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[r,a])}function m(e){let{value:r,tabValues:a}=e;return a.some((e=>e.value===r))}function p(e){let{queryString:r=!1,groupId:a}=e;const n=(0,s.k6)(),l=function(e){let{queryString:r=!1,groupId:a}=e;if("string"==typeof r)return r;if(!1===r)return null;if(!0===r&&!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:r,groupId:a});return[(0,i._X)(l),(0,t.useCallback)((e=>{if(!l)return;const r=new URLSearchParams(n.location.search);r.set(l,e),n.replace({...n.location,search:r.toString()})}),[l,n])]}function f(e){const{defaultValue:r,queryString:a=!1,groupId:n}=e,l=h(e),[s,i]=(0,t.useState)((()=>function(e){let{defaultValue:r,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(r){if(!m({value:r,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${r}" 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 r}const t=a.find((e=>e.default))??a[0];if(!t)throw new Error("Unexpected error: 0 tabValues");return t.value}({defaultValue:r,tabValues:l}))),[d,c]=p({queryString:a,groupId:n}),[f,b]=function(e){let{groupId:r}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(r),[n,l]=(0,u.Nk)(a);return[n,(0,t.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:n}),v=(()=>{const e=d??f;return m({value:e,tabValues:l})?e:null})();(0,o.Z)((()=>{v&&i(v)}),[v]);return{selectedValue:s,selectValue:(0,t.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),b(e)}),[c,b,l]),tabValues:l}}var b=a(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=a(5893);function x(e){let{className:r,block:a,selectedValue:t,selectValue:s,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.o5)(),u=e=>{const r=e.currentTarget,a=i.indexOf(r),n=o[a].value;n!==t&&(d(r),s(n))},c=e=>{let r=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const a=i.indexOf(e.currentTarget)+1;r=i[a]??i[0];break}case"ArrowLeft":{const a=i.indexOf(e.currentTarget)-1;r=i[a]??i[i.length-1];break}}r?.focus()};return(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,n.Z)("tabs",{"tabs--block":a},r),children:o.map((e=>{let{value:r,label:a,attributes:l}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:t===r?0:-1,"aria-selected":t===r,ref:e=>i.push(e),onKeyDown:c,onClick:u,...l,className:(0,n.Z)("tabs__item",v.tabItem,l?.className,{"tabs__item--active":t===r}),children:a??r},r)}))})}function j(e){let{lazy:r,children:a,selectedValue:n}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(r){const e=l.find((e=>e.props.value===n));return e?(0,t.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:l.map(((e,r)=>(0,t.cloneElement)(e,{key:r,hidden:e.props.value!==n})))})}function w(e){const r=f(e);return(0,y.jsxs)("div",{className:(0,n.Z)("tabs-container",v.tabList),children:[(0,y.jsx)(x,{...e,...r}),(0,y.jsx)(j,{...e,...r})]})}function g(e){const r=(0,b.Z)();return(0,y.jsx)(w,{...e,children:c(e.children)},String(r))}},1151:(e,r,a)=>{a.d(r,{Z:()=>o,a:()=>s});var t=a(7294);const n={},l=t.createContext(n);function s(e){const r=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function o(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:s(e.components),t.createElement(l.Provider,{value:r},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5512],{9794:(e,r,a)=>{a.r(r),a.d(r,{assets:()=>u,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>d,toc:()=>c});var t=a(5893),n=a(1151),l=a(4866),s=a(5162);const o={title:"http-header-normalizer"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-header-normalizer.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const r={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,n.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(r.p,{children:"This middleware normalizes HTTP header names. By default, it normalizes to lowercase. It\ncan also normalize to canonical form."}),"\n",(0,t.jsx)(r.p,{children:"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."}),"\n",(0,t.jsxs)(r.p,{children:["Other middlewares like ",(0,t.jsx)(r.a,{href:"#jsonbodyparser",children:(0,t.jsx)(r.code,{children:"jsonBodyParser"})})," or ",(0,t.jsx)(r.a,{href:"#urlencodebodyparser",children:(0,t.jsx)(r.code,{children:"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."]}),"\n",(0,t.jsxs)(r.p,{children:["This middleware will copy the original headers in ",(0,t.jsx)(r.code,{children:"event.rawHeaders"}),"."]}),"\n",(0,t.jsx)(r.h2,{id:"install",children:"Install"}),"\n",(0,t.jsx)(r.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,t.jsxs)(l.Z,{groupId:"npm2yarn",children:[(0,t.jsx)(s.Z,{value:"npm",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"npm install --save @middy/http-header-normalizer\n"})})}),(0,t.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"yarn add @middy/http-header-normalizer\n"})})}),(0,t.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-bash",children:"pnpm add @middy/http-header-normalizer\n"})})})]}),"\n",(0,t.jsx)(r.h2,{id:"options",children:"Options"}),"\n",(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.code,{children:"canonical"})," (bool) (optional): if true, modifies the headers to canonical format, otherwise the headers are normalized to lowercase (default ",(0,t.jsx)(r.code,{children:"false"}),")"]}),"\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.code,{children:"defaultHeaders"})," (object) (optional): Default headers to used if any are missing. i.e. ",(0,t.jsx)(r.code,{children:"Content-Type"})," (default ",(0,t.jsx)(r.code,{children:"{}"}),")"]}),"\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.code,{children:"normalizeHeaderKey"})," (function) (optional): a function that accepts an header name as a parameter and returns its\ncanonical representation."]}),"\n"]}),"\n",(0,t.jsx)(r.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpHeaderNormalizer from '@middy/http-header-normalizer'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .use(httpHeaderNormalizer())\n .handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:r}={...(0,n.a)(),...e.components};return r?(0,t.jsx)(r,{...e,children:(0,t.jsx)(h,{...e})}):h(e)}},5162:(e,r,a)=>{a.d(r,{Z:()=>s});a(7294);var t=a(6010);const n={tabItem:"tabItem_Ymn6"};var l=a(5893);function s(e){let{children:r,hidden:a,className:s}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,t.Z)(n.tabItem,s),hidden:a,children:r})}},4866:(e,r,a)=>{a.d(r,{Z:()=>g});var t=a(7294),n=a(6010),l=a(2466),s=a(6550),o=a(469),i=a(1980),d=a(7392),u=a(12);function c(e){return t.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:r}=e;return!!r&&"object"==typeof r&&"value"in r}(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)??[]}function h(e){const{values:r,children:a}=e;return(0,t.useMemo)((()=>{const e=r??function(e){return c(e).map((e=>{let{props:{value:r,label:a,attributes:t,default:n}}=e;return{value:r,label:a,attributes:t,default:n}}))}(a);return function(e){const r=(0,d.l)(e,((e,r)=>e.value===r.value));if(r.length>0)throw new Error(`Docusaurus error: Duplicate values "${r.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[r,a])}function m(e){let{value:r,tabValues:a}=e;return a.some((e=>e.value===r))}function p(e){let{queryString:r=!1,groupId:a}=e;const n=(0,s.k6)(),l=function(e){let{queryString:r=!1,groupId:a}=e;if("string"==typeof r)return r;if(!1===r)return null;if(!0===r&&!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:r,groupId:a});return[(0,i._X)(l),(0,t.useCallback)((e=>{if(!l)return;const r=new URLSearchParams(n.location.search);r.set(l,e),n.replace({...n.location,search:r.toString()})}),[l,n])]}function f(e){const{defaultValue:r,queryString:a=!1,groupId:n}=e,l=h(e),[s,i]=(0,t.useState)((()=>function(e){let{defaultValue:r,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(r){if(!m({value:r,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${r}" 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 r}const t=a.find((e=>e.default))??a[0];if(!t)throw new Error("Unexpected error: 0 tabValues");return t.value}({defaultValue:r,tabValues:l}))),[d,c]=p({queryString:a,groupId:n}),[f,b]=function(e){let{groupId:r}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(r),[n,l]=(0,u.Nk)(a);return[n,(0,t.useCallback)((e=>{a&&l.set(e)}),[a,l])]}({groupId:n}),v=(()=>{const e=d??f;return m({value:e,tabValues:l})?e:null})();(0,o.Z)((()=>{v&&i(v)}),[v]);return{selectedValue:s,selectValue:(0,t.useCallback)((e=>{if(!m({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),b(e)}),[c,b,l]),tabValues:l}}var b=a(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=a(5893);function x(e){let{className:r,block:a,selectedValue:t,selectValue:s,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,l.o5)(),u=e=>{const r=e.currentTarget,a=i.indexOf(r),n=o[a].value;n!==t&&(d(r),s(n))},c=e=>{let r=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const a=i.indexOf(e.currentTarget)+1;r=i[a]??i[0];break}case"ArrowLeft":{const a=i.indexOf(e.currentTarget)-1;r=i[a]??i[i.length-1];break}}r?.focus()};return(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,n.Z)("tabs",{"tabs--block":a},r),children:o.map((e=>{let{value:r,label:a,attributes:l}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:t===r?0:-1,"aria-selected":t===r,ref:e=>i.push(e),onKeyDown:c,onClick:u,...l,className:(0,n.Z)("tabs__item",v.tabItem,l?.className,{"tabs__item--active":t===r}),children:a??r},r)}))})}function j(e){let{lazy:r,children:a,selectedValue:n}=e;const l=(Array.isArray(a)?a:[a]).filter(Boolean);if(r){const e=l.find((e=>e.props.value===n));return e?(0,t.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:l.map(((e,r)=>(0,t.cloneElement)(e,{key:r,hidden:e.props.value!==n})))})}function w(e){const r=f(e);return(0,y.jsxs)("div",{className:(0,n.Z)("tabs-container",v.tabList),children:[(0,y.jsx)(x,{...e,...r}),(0,y.jsx)(j,{...e,...r})]})}function g(e){const r=(0,b.Z)();return(0,y.jsx)(w,{...e,children:c(e.children)},String(r))}},1151:(e,r,a)=>{a.d(r,{Z:()=>o,a:()=>s});var t=a(7294);const n={},l=t.createContext(n);function s(e){const r=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function o(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:s(e.components),t.createElement(l.Provider,{value:r},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/70761510.54dab7d8.js b/assets/js/70761510.4552b410.js similarity index 98% rename from assets/js/70761510.54dab7d8.js rename to assets/js/70761510.4552b410.js index 0f79e57d4..c1a28b4ea 100644 --- a/assets/js/70761510.54dab7d8.js +++ b/assets/js/70761510.4552b410.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5024],{3455:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>a,toc:()=>d});var s=t(5893),r=t(1151);const o={title:"Small node_modules",sidebar_position:6},i=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/06-small-node-modules.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},c={},d=[];function l(e){const n={code:"code",p:"p",pre:"pre",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Using a bundler is the optimal solution, but can be complex depending on your setup."}),"\n",(0,s.jsxs)(n.p,{children:["In this case you should remove excess files from your ",(0,s.jsx)(n.code,{children:"node_modules"})," directory to ensure it doesn't have anything excess shipped to AWS."]}),"\n",(0,s.jsxs)(n.p,{children:["We put together a ",(0,s.jsx)(n.code,{children:".yarnclean"})," file you can check out and use as part of your CI/CD process:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-git",metastring:'title=".yarnclean"',children:"# -- 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"})})]})}function u(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>a,a:()=>i});var s=t(7294);const r={},o=s.createContext(r);function i(e){const n=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),s.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5024],{3455:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>a,toc:()=>d});var s=t(5893),r=t(1151);const o={title:"Small node_modules",sidebar_position:6},i=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/06-small-node-modules.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},c={},d=[];function l(e){const n={code:"code",p:"p",pre:"pre",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Using a bundler is the optimal solution, but can be complex depending on your setup."}),"\n",(0,s.jsxs)(n.p,{children:["In this case you should remove excess files from your ",(0,s.jsx)(n.code,{children:"node_modules"})," directory to ensure it doesn't have anything excess shipped to AWS."]}),"\n",(0,s.jsxs)(n.p,{children:["We put together a ",(0,s.jsx)(n.code,{children:".yarnclean"})," file you can check out and use as part of your CI/CD process:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-git",metastring:'title=".yarnclean"',children:"# -- 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"})})]})}function u(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>a,a:()=>i});var s=t(7294);const r={},o=s.createContext(r);function i(e){const n=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),s.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7076eee1.c00cdf79.js b/assets/js/7076eee1.69734316.js similarity index 98% rename from assets/js/7076eee1.c00cdf79.js rename to assets/js/7076eee1.69734316.js index f81aeb931..8155d669c 100644 --- a/assets/js/7076eee1.c00cdf79.js +++ b/assets/js/7076eee1.69734316.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[481],{2865:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>d,default:()=>m,frontMatter:()=>o,metadata:()=>i,toc:()=>l});var n=r(5893),a=r(1151);const o={title:"Application Load Balancer"},d=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/application-load-balancer.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},s={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function p(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:"Same as API Gateway (REST)"}),"\n",(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,n.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html",children:"Using AWS Lambda with an Application Load Balancer"})}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(p,{...e})}):p(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>i,a:()=>d});var n=r(7294);const a={},o=n.createContext(a);function d(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:d(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[481],{2865:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>d,default:()=>m,frontMatter:()=>o,metadata:()=>i,toc:()=>l});var n=r(5893),a=r(1151);const o={title:"Application Load Balancer"},d=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/application-load-balancer.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},s={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function p(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:"Same as API Gateway (REST)"}),"\n",(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,n.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html",children:"Using AWS Lambda with an Application Load Balancer"})}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(p,{...e})}):p(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>i,a:()=>d});var n=r(7294);const a={},o=n.createContext(a);function d(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:d(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/71d5009c.d9df73e2.js b/assets/js/71d5009c.b3ee3ff3.js similarity index 97% rename from assets/js/71d5009c.d9df73e2.js rename to assets/js/71d5009c.b3ee3ff3.js index 40fef7377..f257aa935 100644 --- a/assets/js/71d5009c.d9df73e2.js +++ b/assets/js/71d5009c.b3ee3ff3.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2193],{1853:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>r,default:()=>m,frontMatter:()=>s,metadata:()=>a,toc:()=>c});var o=t(5893),i=t(1151);const s={title:"Config"},r=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/config.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Config"},sidebar:"tutorialSidebar",previous:{title:"Cognito",permalink:"/docs/events/cognito"},next:{title:"Connect",permalink:"/docs/events/connect"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.admonition,{type:"caution",children:(0,o.jsx)(n.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(n.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsx)(n.li,{children:(0,o.jsx)(n.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-config.html",children:"Using AWS Lambda with AWS Config"})}),"\n"]}),"\n",(0,o.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>a,a:()=>r});var o=t(7294);const i={},s=o.createContext(i);function r(e){const n=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),o.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2193],{1853:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>r,default:()=>m,frontMatter:()=>s,metadata:()=>a,toc:()=>c});var o=t(5893),i=t(1151);const s={title:"Config"},r=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/config.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Config"},sidebar:"tutorialSidebar",previous:{title:"Cognito",permalink:"/docs/events/cognito"},next:{title:"Connect",permalink:"/docs/events/connect"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.admonition,{type:"caution",children:(0,o.jsx)(n.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(n.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsx)(n.li,{children:(0,o.jsx)(n.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-config.html",children:"Using AWS Lambda with AWS Config"})}),"\n"]}),"\n",(0,o.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>a,a:()=>r});var o=t(7294);const i={},s=o.createContext(i);function r(e){const n=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),o.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/73083085.4ed98a51.js b/assets/js/73083085.fc3228d6.js similarity index 98% rename from assets/js/73083085.4ed98a51.js rename to assets/js/73083085.fc3228d6.js index 795d6b653..40ad83a10 100644 --- a/assets/js/73083085.4ed98a51.js +++ b/assets/js/73083085.fc3228d6.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8365],{3131:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>m,frontMatter:()=>i,metadata:()=>d,toc:()=>p});var n=r(5893),a=r(1151);const i={title:"API Gateway (REST)"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-rest.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},s={},p=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,n.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html",children:"Using AWS Lambda with Amazon API Gateway"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html",children:"Working with REST APIs"})}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>d,a:()=>o});var n=r(7294);const a={},i=n.createContext(a);function o(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8365],{3131:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>m,frontMatter:()=>i,metadata:()=>d,toc:()=>p});var n=r(5893),a=r(1151);const i={title:"API Gateway (REST)"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-rest.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},s={},p=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,n.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html",children:"Using AWS Lambda with Amazon API Gateway"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html",children:"Working with REST APIs"})}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>d,a:()=>o});var n=r(7294);const a={},i=n.createContext(a);function o(e){const t=n.useContext(i);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),n.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7745d517.16dc1797.js b/assets/js/7745d517.a8080453.js similarity index 99% rename from assets/js/7745d517.16dc1797.js rename to assets/js/7745d517.a8080453.js index 03475cb93..a53b36623 100644 --- a/assets/js/7745d517.16dc1797.js +++ b/assets/js/7745d517.a8080453.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1702],{1391:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>h,frontMatter:()=>l,metadata:()=>d,toc:()=>u});var a=t(5893),r=t(1151),s=t(4866),i=t(5162);const l={title:"appconfig"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/appconfig.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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={},u=[{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},{value:"Usage with TypeScript",id:"usage-with-typescript",level:2}];function p(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.p,{children:"Fetches AppConfig stored configuration and parses out JSON."}),"\n",(0,a.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,a.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,a.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(i.Z,{value:"npm",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/appconfig\nnpm install --save-dev @aws-sdk/client-appconfigdata\n"})})}),(0,a.jsx)(i.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/appconfig\nyarn add --dev @aws-sdk/client-appconfigdata\n"})})}),(0,a.jsx)(i.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/appconfig\npnpm add --save-dev @aws-sdk/client-appconfigdata\n"})})})]}),"\n",(0,a.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,a.jsx)(n.code,{children:"AppConfigClient"}),"): AppConfigClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,a.jsx)(n.code,{children:"@aws-sdk/client-appconfig"}),"."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"awsClientOptions"})," (object) (default ",(0,a.jsx)(n.code,{children:"undefined"}),"): Options to pass to AppConfigClient class constructor."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"awsClientAssumeRole"})," (string) (default ",(0,a.jsx)(n.code,{children:"undefined"}),"): Internal key where secrets are stored. See ",(0,a.jsx)(n.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"awsClientCapture"})," (function) (default ",(0,a.jsx)(n.code,{children:"undefined"}),"): Enable XRay by passing ",(0,a.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,a.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameters."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,a.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,a.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"cacheKey"})," (string) (default ",(0,a.jsx)(n.code,{children:"appconfig"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"cacheExpiry"})," (number) (default ",(0,a.jsx)(n.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,a.jsx)(n.code,{children:"-1"}),": cache forever, ",(0,a.jsx)(n.code,{children:"0"}),": never cache, ",(0,a.jsx)(n.code,{children:"n"}),": cache for n ms."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"setToContext"})," (boolean) (default ",(0,a.jsx)(n.code,{children:"false"}),"): Store credentials to ",(0,a.jsx)(n.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,a.jsx)(n.p,{children:"NOTES:"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,a.jsx)(n.code,{children:"appconfig:StartConfigurationSession"})," and ",(0,a.jsx)(n.code,{children:"appconfig:GetLatestConfiguration"})]}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport appConfig from '@middy/appconfig'\n\nconst handler = middy()\n .use(\n appConfig({\n fetchData: {\n config: {\n Application: '...',\n ClientId: '...',\n Configuration: '...',\n Environment: '...'\n }\n }\n })\n )\n .handler((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n })\n"})}),"\n",(0,a.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,a.jsxs)(n.p,{children:["To exclude ",(0,a.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,a.jsx)(n.code,{children:"@aws-sdk/client-appconfig"})," to the exclude list."]}),"\n",(0,a.jsx)(n.h2,{id:"usage-with-typescript",children:"Usage with TypeScript"}),"\n",(0,a.jsxs)(n.p,{children:["Data in AppConfig can be stored as arbitrary structured data. It's not possible to know in advance what shape the fetched data will have, so by default the fetched parameters will have type ",(0,a.jsx)(n.code,{children:"unknown"}),"."]}),"\n",(0,a.jsxs)(n.p,{children:["You can provide some type hints by leveraging the ",(0,a.jsx)(n.code,{children:"appConfigReq"})," utility function. This function allows you to specify what's the expected type that will be fetched for every AppConfig request."]}),"\n",(0,a.jsxs)(n.p,{children:["The idea is that, for every request specified in the ",(0,a.jsx)(n.code,{children:"fetchData"})," option, rather than just providing the parameter path as a string, you can wrap it in a ",(0,a.jsx)(n.code,{children:"appConfigReq(config)"})," call. Internally, ",(0,a.jsx)(n.code,{children:"appConfigReq"})," is a function that will return ",(0,a.jsx)(n.code,{children:"config"})," as received, but it allows you to use generics to provide type hints for the expected type for that parameter."]}),"\n",(0,a.jsx)(n.p,{children:"This way TypeScript can understand how to treat the additional data attached to the context and stored in the internal storage."}),"\n",(0,a.jsxs)(n.p,{children:["The following example illustrates how to use ",(0,a.jsx)(n.code,{children:"appConfigReq"}),":"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-typescript",children:"import middy from '@middy/core'\nimport appConfig, { appConfigReq } from '@middy/appconfig'\n\nconst lambdaHandler = (event, context) => {\n return {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n})\n\nexport const handler = middy()\n .use(\n appConfig({\n fetchData: {\n config: {\n Application: '...',\n ClientId: '...',\n Configuration: '...',\n Environment: '...'\n }\n }\n })\n )\n .before(async (request) => {\n const data = await getInternal('config', request)\n // data.config.field1 (string)\n // data.config.field2 (string)\n // data.config.field3 (number)\n })\n.handler(lambdaHandler)\n"})})]})}function h(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(p,{...e})}):p(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>i});t(7294);var a=t(6010);const r={tabItem:"tabItem_Ymn6"};var s=t(5893);function i(e){let{children:n,hidden:t,className:i}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,a.Z)(r.tabItem,i),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var a=t(7294),r=t(6010),s=t(2466),i=t(6550),l=t(469),o=t(1980),d=t(7392),c=t(12);function u(e){return a.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function p(e){const{values:n,children:t}=e;return(0,a.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:a,default:r}}=e;return{value:n,label:t,attributes:a,default:r}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function h(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function f(e){let{queryString:n=!1,groupId:t}=e;const r=(0,i.k6)(),s=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(s),(0,a.useCallback)((e=>{if(!s)return;const n=new URLSearchParams(r.location.search);n.set(s,e),r.replace({...r.location,search:n.toString()})}),[s,r])]}function m(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,s=p(e),[i,o]=(0,a.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!h({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const a=t.find((e=>e.default))??t[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:n,tabValues:s}))),[d,u]=f({queryString:t,groupId:r}),[m,g]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,s]=(0,c.Nk)(t);return[r,(0,a.useCallback)((e=>{t&&s.set(e)}),[t,s])]}({groupId:r}),x=(()=>{const e=d??m;return h({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{x&&o(x)}),[x]);return{selectedValue:i,selectValue:(0,a.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),g(e)}),[u,g,s]),tabValues:s}}var g=t(2389);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=t(5893);function j(e){let{className:n,block:t,selectedValue:a,selectValue:i,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),c=e=>{const n=e.currentTarget,t=o.indexOf(n),r=l[t].value;r!==a&&(d(n),i(r))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":t},n),children:l.map((e=>{let{value:n,label:t,attributes:s}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:a===n?0:-1,"aria-selected":a===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...s,className:(0,r.Z)("tabs__item",x.tabItem,s?.className,{"tabs__item--active":a===n}),children:t??n},n)}))})}function y(e){let{lazy:n,children:t,selectedValue:r}=e;const s=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=s.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:s.map(((e,n)=>(0,a.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function v(e){const n=m(e);return(0,b.jsxs)("div",{className:(0,r.Z)("tabs-container",x.tabList),children:[(0,b.jsx)(j,{...e,...n}),(0,b.jsx)(y,{...e,...n})]})}function w(e){const n=(0,g.Z)();return(0,b.jsx)(v,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>l,a:()=>i});var a=t(7294);const r={},s=a.createContext(r);function i(e){const n=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),a.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1702],{1391:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>h,frontMatter:()=>l,metadata:()=>d,toc:()=>u});var a=t(5893),r=t(1151),s=t(4866),i=t(5162);const l={title:"appconfig"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/appconfig.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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={},u=[{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},{value:"Usage with TypeScript",id:"usage-with-typescript",level:2}];function p(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.p,{children:"Fetches AppConfig stored configuration and parses out JSON."}),"\n",(0,a.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,a.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,a.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(i.Z,{value:"npm",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/appconfig\nnpm install --save-dev @aws-sdk/client-appconfigdata\n"})})}),(0,a.jsx)(i.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/appconfig\nyarn add --dev @aws-sdk/client-appconfigdata\n"})})}),(0,a.jsx)(i.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/appconfig\npnpm add --save-dev @aws-sdk/client-appconfigdata\n"})})})]}),"\n",(0,a.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,a.jsx)(n.code,{children:"AppConfigClient"}),"): AppConfigClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,a.jsx)(n.code,{children:"@aws-sdk/client-appconfig"}),"."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"awsClientOptions"})," (object) (default ",(0,a.jsx)(n.code,{children:"undefined"}),"): Options to pass to AppConfigClient class constructor."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"awsClientAssumeRole"})," (string) (default ",(0,a.jsx)(n.code,{children:"undefined"}),"): Internal key where secrets are stored. See ",(0,a.jsx)(n.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"awsClientCapture"})," (function) (default ",(0,a.jsx)(n.code,{children:"undefined"}),"): Enable XRay by passing ",(0,a.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,a.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameters."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,a.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,a.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"cacheKey"})," (string) (default ",(0,a.jsx)(n.code,{children:"appconfig"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"cacheExpiry"})," (number) (default ",(0,a.jsx)(n.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,a.jsx)(n.code,{children:"-1"}),": cache forever, ",(0,a.jsx)(n.code,{children:"0"}),": never cache, ",(0,a.jsx)(n.code,{children:"n"}),": cache for n ms."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"setToContext"})," (boolean) (default ",(0,a.jsx)(n.code,{children:"false"}),"): Store credentials to ",(0,a.jsx)(n.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,a.jsx)(n.p,{children:"NOTES:"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,a.jsx)(n.code,{children:"appconfig:StartConfigurationSession"})," and ",(0,a.jsx)(n.code,{children:"appconfig:GetLatestConfiguration"})]}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport appConfig from '@middy/appconfig'\n\nconst handler = middy()\n .use(\n appConfig({\n fetchData: {\n config: {\n Application: '...',\n ClientId: '...',\n Configuration: '...',\n Environment: '...'\n }\n }\n })\n )\n .handler((event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n })\n"})}),"\n",(0,a.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,a.jsxs)(n.p,{children:["To exclude ",(0,a.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,a.jsx)(n.code,{children:"@aws-sdk/client-appconfig"})," to the exclude list."]}),"\n",(0,a.jsx)(n.h2,{id:"usage-with-typescript",children:"Usage with TypeScript"}),"\n",(0,a.jsxs)(n.p,{children:["Data in AppConfig can be stored as arbitrary structured data. It's not possible to know in advance what shape the fetched data will have, so by default the fetched parameters will have type ",(0,a.jsx)(n.code,{children:"unknown"}),"."]}),"\n",(0,a.jsxs)(n.p,{children:["You can provide some type hints by leveraging the ",(0,a.jsx)(n.code,{children:"appConfigReq"})," utility function. This function allows you to specify what's the expected type that will be fetched for every AppConfig request."]}),"\n",(0,a.jsxs)(n.p,{children:["The idea is that, for every request specified in the ",(0,a.jsx)(n.code,{children:"fetchData"})," option, rather than just providing the parameter path as a string, you can wrap it in a ",(0,a.jsx)(n.code,{children:"appConfigReq(config)"})," call. Internally, ",(0,a.jsx)(n.code,{children:"appConfigReq"})," is a function that will return ",(0,a.jsx)(n.code,{children:"config"})," as received, but it allows you to use generics to provide type hints for the expected type for that parameter."]}),"\n",(0,a.jsx)(n.p,{children:"This way TypeScript can understand how to treat the additional data attached to the context and stored in the internal storage."}),"\n",(0,a.jsxs)(n.p,{children:["The following example illustrates how to use ",(0,a.jsx)(n.code,{children:"appConfigReq"}),":"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-typescript",children:"import middy from '@middy/core'\nimport appConfig, { appConfigReq } from '@middy/appconfig'\n\nconst lambdaHandler = (event, context) => {\n return {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n})\n\nexport const handler = middy()\n .use(\n appConfig({\n fetchData: {\n config: {\n Application: '...',\n ClientId: '...',\n Configuration: '...',\n Environment: '...'\n }\n }\n })\n )\n .before(async (request) => {\n const data = await getInternal('config', request)\n // data.config.field1 (string)\n // data.config.field2 (string)\n // data.config.field3 (number)\n })\n.handler(lambdaHandler)\n"})})]})}function h(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(p,{...e})}):p(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>i});t(7294);var a=t(6010);const r={tabItem:"tabItem_Ymn6"};var s=t(5893);function i(e){let{children:n,hidden:t,className:i}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,a.Z)(r.tabItem,i),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var a=t(7294),r=t(6010),s=t(2466),i=t(6550),l=t(469),o=t(1980),d=t(7392),c=t(12);function u(e){return a.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function p(e){const{values:n,children:t}=e;return(0,a.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:a,default:r}}=e;return{value:n,label:t,attributes:a,default:r}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function h(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function f(e){let{queryString:n=!1,groupId:t}=e;const r=(0,i.k6)(),s=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(s),(0,a.useCallback)((e=>{if(!s)return;const n=new URLSearchParams(r.location.search);n.set(s,e),r.replace({...r.location,search:n.toString()})}),[s,r])]}function m(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,s=p(e),[i,o]=(0,a.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!h({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const a=t.find((e=>e.default))??t[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:n,tabValues:s}))),[d,u]=f({queryString:t,groupId:r}),[m,g]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,s]=(0,c.Nk)(t);return[r,(0,a.useCallback)((e=>{t&&s.set(e)}),[t,s])]}({groupId:r}),x=(()=>{const e=d??m;return h({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{x&&o(x)}),[x]);return{selectedValue:i,selectValue:(0,a.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),g(e)}),[u,g,s]),tabValues:s}}var g=t(2389);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=t(5893);function j(e){let{className:n,block:t,selectedValue:a,selectValue:i,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),c=e=>{const n=e.currentTarget,t=o.indexOf(n),r=l[t].value;r!==a&&(d(n),i(r))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":t},n),children:l.map((e=>{let{value:n,label:t,attributes:s}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:a===n?0:-1,"aria-selected":a===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...s,className:(0,r.Z)("tabs__item",x.tabItem,s?.className,{"tabs__item--active":a===n}),children:t??n},n)}))})}function y(e){let{lazy:n,children:t,selectedValue:r}=e;const s=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=s.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:s.map(((e,n)=>(0,a.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function v(e){const n=m(e);return(0,b.jsxs)("div",{className:(0,r.Z)("tabs-container",x.tabList),children:[(0,b.jsx)(j,{...e,...n}),(0,b.jsx)(y,{...e,...n})]})}function w(e){const n=(0,g.Z)();return(0,b.jsx)(v,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>l,a:()=>i});var a=t(7294);const r={},s=a.createContext(r);function i(e){const n=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),a.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/79674995.11a9a6a4.js b/assets/js/79674995.09cdec76.js similarity index 97% rename from assets/js/79674995.11a9a6a4.js rename to assets/js/79674995.09cdec76.js index a7eb8b41c..a55391083 100644 --- a/assets/js/79674995.11a9a6a4.js +++ b/assets/js/79674995.09cdec76.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8200],{1934:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>u,frontMatter:()=>a,metadata:()=>r,toc:()=>c});var o=n(5893),i=n(1151);const a={title:"CloudFormation"},s=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-formation.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"CloudFormation"},sidebar:"tutorialSidebar",previous:{title:"AppSync",permalink:"/docs/events/appsync"},next:{title:"CloudFront Lambda@Edge",permalink:"/docs/events/cloud-front"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cloudformation.html",children:"Using AWS Lambda with AWS CloudFormation"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>s});var o=n(7294);const i={},a=o.createContext(i);function s(e){const t=o.useContext(a);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),o.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8200],{1934:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>u,frontMatter:()=>a,metadata:()=>r,toc:()=>c});var o=n(5893),i=n(1151);const a={title:"CloudFormation"},s=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cloud-formation.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"CloudFormation"},sidebar:"tutorialSidebar",previous:{title:"AppSync",permalink:"/docs/events/appsync"},next:{title:"CloudFront Lambda@Edge",permalink:"/docs/events/cloud-front"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cloudformation.html",children:"Using AWS Lambda with AWS CloudFormation"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function u(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>s});var o=n(7294);const i={},a=o.createContext(i);function s(e){const t=o.useContext(a);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),o.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/796ad5a5.48948616.js b/assets/js/796ad5a5.a390c26f.js similarity index 94% rename from assets/js/796ad5a5.48948616.js rename to assets/js/796ad5a5.a390c26f.js index 3a615bf24..20cfa36fd 100644 --- a/assets/js/796ad5a5.48948616.js +++ b/assets/js/796ad5a5.a390c26f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6172],{5621:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>l,frontMatter:()=>a,metadata:()=>r,toc:()=>d});var o=n(5893),i=n(1151);const a={title:"AppSync"},s=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/appsync.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function p(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html",children:"Using AWS Lambda with AppSync"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n"})})]})}function l(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(p,{...e})}):p(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>s});var o=n(7294);const i={},a=o.createContext(i);function s(e){const t=o.useContext(a);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),o.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6172],{5621:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>l,frontMatter:()=>a,metadata:()=>r,toc:()=>d});var o=n(5893),i=n(1151);const a={title:"AppSync"},s=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/appsync.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function p(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html",children:"Using AWS Lambda with AppSync"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy().handler((event, context, { signal }) => {\n // ...\n})\n"})})]})}function l(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(p,{...e})}):p(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>s});var o=n(7294);const i={},a=o.createContext(i);function s(e){const t=o.useContext(a);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),o.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7cb784f6.f1547972.js b/assets/js/7cb784f6.b4905afc.js similarity index 99% rename from assets/js/7cb784f6.f1547972.js rename to assets/js/7cb784f6.b4905afc.js index edc9e9b23..f9d1cd207 100644 --- a/assets/js/7cb784f6.f1547972.js +++ b/assets/js/7cb784f6.b4905afc.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[711],{4122:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>l,contentTitle:()=>i,default:()=>h,frontMatter:()=>t,metadata:()=>a,toc:()=>o});var s=n(5893),d=n(1151);const t={title:"Upgrade 1.x -> 2.x",sidebar_position:1e3},i=void 0,a={id:"upgrade/1-2",title:"Upgrade 1.x -> 2.x",description:'aka "The async/await Update"',source:"@site/docs/upgrade/1-2.md",sourceDirName:"upgrade",slug:"/upgrade/1-2",permalink:"/docs/upgrade/1-2",draft:!1,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/1-2.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},l={},o=[{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}];function c(e){const r={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,d.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.p,{children:'aka "The async/await Update"'}),"\n",(0,s.jsxs)(r.p,{children:["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,s.jsx)(r.code,{children:"export"}),"), optional chaining (",(0,s.jsx)(r.code,{children:"?."}),") and nullish coalescing operator (",(0,s.jsx)(r.code,{children:"??"}),") natively."]}),"\n",(0,s.jsx)(r.h2,{id:"core",children:"Core"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["In handler ",(0,s.jsx)(r.code,{children:"callback(err, response)"})," have been removed for ",(0,s.jsx)(r.code,{children:"async/await"})," support","\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"return response"})," to trigger ",(0,s.jsx)(r.code,{children:"after"})," middleware stack"]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"throw new Error(...)"})," to trigger ",(0,s.jsx)(r.code,{children:"onError"})," middleware stack"]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(r.li,{children:["In middleware ",(0,s.jsx)(r.code,{children:"next(err)"})," has been removed for ",(0,s.jsx)(r.code,{children:"async/await"})," support","\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"throw new Error(...)"})," to trigger ",(0,s.jsx)(r.code,{children:"onError"})," middleware stack"]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"return response"})," to ",(0,s.jsx)(r.strong,{children:"short circuit"})," any middleware stack and respond. v1.x currently throws an error when something is returned"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"middleware",children:"Middleware"}),"\n",(0,s.jsx)(r.h3,{id:"cache",children:"cache"}),"\n",(0,s.jsx)(r.p,{children:"Deprecated. Too generic and had low usage."}),"\n",(0,s.jsx)(r.p,{children:"However, you can use the following if needed:"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-javascript",children:"const { createHash } = require('crypto')\n\nmodule.exports = (opts) => {\n const storage = {}\n const defaults = {\n calculateCacheId: async (event) =>\n 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"})}),"\n",(0,s.jsx)(r.h3,{id:"db-manager",children:"db-manager"}),"\n",(0,s.jsxs)(r.p,{children:["Deprecated. Too generic and had low usage. You can check out ",(0,s.jsx)(r.a,{href:"https://github.com/willfarrell/middy-rds",children:"middy-rds"})," as a\npossible alternative or example on building your own replacement."]}),"\n",(0,s.jsx)(r.h3,{id:"do-not-wait-for-empty-event-loop",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/do-not-wait-for-empty-event-loop",children:"do-not-wait-for-empty-event-loop"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"function-shield",children:"function-shield"}),"\n",(0,s.jsx)(r.p,{children:"Deprecated. Only supported up to Node v10."}),"\n",(0,s.jsx)(r.h3,{id:"http-content-negotiation",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-negotiation",children:"http-content-negotiation"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-cors",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-cors",children:"http-cors"})}),"\n",(0,s.jsx)(r.p,{children:"Added new options to support more headers"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"methods"}),"\n",(0,s.jsx)(r.li,{children:"exposeHeaders"}),"\n",(0,s.jsx)(r.li,{children:"requestHeaders"}),"\n",(0,s.jsx)(r.li,{children:"requestMethods"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-error-handler",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-error-handler",children:"http-error-handler"})}),"\n",(0,s.jsx)(r.p,{children:"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"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"fallbackMessage"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-event-normalizer",children:"http-event-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-header-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-header-normalizer",children:"http-header-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-json-body-parser",children:"http-json-body-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-multipart-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-multipart-body-parser",children:"http-multipart-body-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-partial-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-partial-response",children:"http-partial-response"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-response-serializer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-response-serializer",children:"http-response-serializer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-security-headers",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-security-headers",children:"http-security-headers"})}),"\n",(0,s.jsxs)(r.p,{children:["No longer adds ",(0,s.jsx)(r.code,{children:"statusCode:500"})," when there is no response."]}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-body-parser",children:"http-urlencode-body-parser"})}),"\n",(0,s.jsxs)(r.p,{children:["Remove ",(0,s.jsx)(r.code,{children:"extended"})," option. Only uses ",(0,s.jsx)(r.code,{children:"qs"})," as the parser, formally enabled by options ",(0,s.jsx)(r.code,{children:"{extended: true}"}),"."]}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-path-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-path-parser",children:"http-urlencode-path-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"input-output-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/input-output-logger",children:"input-output-logger"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Now additionally logs response from the ",(0,s.jsx)(r.code,{children:"onError"})," middleware stack"]}),"\n",(0,s.jsx)(r.li,{children:"Support for omiting within nested arrays"}),"\n",(0,s.jsxs)(r.li,{children:["Add in support for ",(0,s.jsx)(r.code,{children:"replacer"})," to be passed into ",(0,s.jsx)(r.code,{children:"JSON.stringify()"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"rds-signer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/rds-signer",children:"rds-signer"})}),"\n",(0,s.jsxs)(r.p,{children:["New middleware to fetch RDS credential used when connecting with IAM roles. This was built into ",(0,s.jsx)(r.code,{children:"db-manager"}),"."]}),"\n",(0,s.jsx)(r.h3,{id:"s3-key-normalizer",children:"s3-key-normalizer"}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"s3-object-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/s3-object-response",children:"s3-object-response"})}),"\n",(0,s.jsx)(r.p,{children:"New middleware to fetch and respond to S3 Object Get request event."}),"\n",(0,s.jsx)(r.h3,{id:"secrets-manager",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/secrets-manager",children:"secrets-manager"})}),"\n",(0,s.jsx)(r.p,{children:"Refactored, see documentation"}),"\n",(0,s.jsx)(r.h3,{id:"sqs-json-body-parser",children:"sqs-json-body-parser"}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"sqs-partial-batch-failure",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sqs-partial-batch-failure",children:"sqs-partial-batch-failure"})}),"\n",(0,s.jsxs)(r.p,{children:["Replaced option ",(0,s.jsx)(r.code,{children:"sqs"})," with ",(0,s.jsx)(r.code,{children:"AwsClient"})," and added in more options for control."]}),"\n",(0,s.jsx)(r.h3,{id:"ssm",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ssm",children:"ssm"})}),"\n",(0,s.jsx)(r.p,{children:"Refactored, see documentation"}),"\n",(0,s.jsx)(r.h3,{id:"sts",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sts",children:"sts"})}),"\n",(0,s.jsx)(r.p,{children:"New middleware to fetch assume role credentials."}),"\n",(0,s.jsx)(r.h3,{id:"validator",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/validator",children:"validator"})}),"\n",(0,s.jsxs)(r.p,{children:["Upgraded ",(0,s.jsx)(r.code,{children:"ajv"})," and it's plugins to support JSON Schema Draft 2020-12 specification. Defaults were change because of this."]}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Plugin ",(0,s.jsx)(r.code,{children:"ajv-keywords"})," removed from being included by default because it's quite a large package and usually only one keyword is used."]}),"\n",(0,s.jsxs)(r.li,{children:["Plugin ",(0,s.jsx)(r.code,{children:"ajv-errors"})," removed from included by default because it conflicts with ",(0,s.jsx)(r.code,{children:"ajv-i18n"})," when dealing with custom messages for multiple languages"]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"warmup",children:"warmup"}),"\n",(0,s.jsxs)(r.p,{children:["Deprecated. This was a work round for a missing feature in AWS Lambda. AWS added in the ability to use ",(0,s.jsx)(r.a,{href:"https://aws.amazon.com/blogs/aws/new-provisioned-concurrency-for-lambda-functions/",children:"provisioned concurrency"}),"\non 2019-12-03, removing the need for this work around."]}),"\n",(0,s.jsx)(r.p,{children:"However, you can use the following if needed:"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-javascript",children:"middy(lambdaHandler).before((request) => {\n if (request.event.source === 'serverless-plugin-warmup') {\n console.log('Exiting early via warmup Middleware')\n return 'warmup'\n }\n})\n"})})]})}function h(e={}){const{wrapper:r}={...(0,d.a)(),...e.components};return r?(0,s.jsx)(r,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,r,n)=>{n.d(r,{Z:()=>a,a:()=>i});var s=n(7294);const d={},t=s.createContext(d);function i(e){const r=s.useContext(t);return s.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function a(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(d):e.components||d:i(e.components),s.createElement(t.Provider,{value:r},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[711],{4122:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>l,contentTitle:()=>i,default:()=>h,frontMatter:()=>t,metadata:()=>a,toc:()=>o});var s=n(5893),d=n(1151);const t={title:"Upgrade 1.x -> 2.x",sidebar_position:1e3},i=void 0,a={id:"upgrade/1-2",title:"Upgrade 1.x -> 2.x",description:'aka "The async/await Update"',source:"@site/docs/upgrade/1-2.md",sourceDirName:"upgrade",slug:"/upgrade/1-2",permalink:"/docs/upgrade/1-2",draft:!1,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/1-2.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},l={},o=[{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}];function c(e){const r={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,d.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.p,{children:'aka "The async/await Update"'}),"\n",(0,s.jsxs)(r.p,{children:["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,s.jsx)(r.code,{children:"export"}),"), optional chaining (",(0,s.jsx)(r.code,{children:"?."}),") and nullish coalescing operator (",(0,s.jsx)(r.code,{children:"??"}),") natively."]}),"\n",(0,s.jsx)(r.h2,{id:"core",children:"Core"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["In handler ",(0,s.jsx)(r.code,{children:"callback(err, response)"})," have been removed for ",(0,s.jsx)(r.code,{children:"async/await"})," support","\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"return response"})," to trigger ",(0,s.jsx)(r.code,{children:"after"})," middleware stack"]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"throw new Error(...)"})," to trigger ",(0,s.jsx)(r.code,{children:"onError"})," middleware stack"]}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(r.li,{children:["In middleware ",(0,s.jsx)(r.code,{children:"next(err)"})," has been removed for ",(0,s.jsx)(r.code,{children:"async/await"})," support","\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"throw new Error(...)"})," to trigger ",(0,s.jsx)(r.code,{children:"onError"})," middleware stack"]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"return response"})," to ",(0,s.jsx)(r.strong,{children:"short circuit"})," any middleware stack and respond. v1.x currently throws an error when something is returned"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"middleware",children:"Middleware"}),"\n",(0,s.jsx)(r.h3,{id:"cache",children:"cache"}),"\n",(0,s.jsx)(r.p,{children:"Deprecated. Too generic and had low usage."}),"\n",(0,s.jsx)(r.p,{children:"However, you can use the following if needed:"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-javascript",children:"const { createHash } = require('crypto')\n\nmodule.exports = (opts) => {\n const storage = {}\n const defaults = {\n calculateCacheId: async (event) =>\n 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"})}),"\n",(0,s.jsx)(r.h3,{id:"db-manager",children:"db-manager"}),"\n",(0,s.jsxs)(r.p,{children:["Deprecated. Too generic and had low usage. You can check out ",(0,s.jsx)(r.a,{href:"https://github.com/willfarrell/middy-rds",children:"middy-rds"})," as a\npossible alternative or example on building your own replacement."]}),"\n",(0,s.jsx)(r.h3,{id:"do-not-wait-for-empty-event-loop",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/do-not-wait-for-empty-event-loop",children:"do-not-wait-for-empty-event-loop"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"function-shield",children:"function-shield"}),"\n",(0,s.jsx)(r.p,{children:"Deprecated. Only supported up to Node v10."}),"\n",(0,s.jsx)(r.h3,{id:"http-content-negotiation",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-negotiation",children:"http-content-negotiation"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-cors",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-cors",children:"http-cors"})}),"\n",(0,s.jsx)(r.p,{children:"Added new options to support more headers"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"methods"}),"\n",(0,s.jsx)(r.li,{children:"exposeHeaders"}),"\n",(0,s.jsx)(r.li,{children:"requestHeaders"}),"\n",(0,s.jsx)(r.li,{children:"requestMethods"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-error-handler",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-error-handler",children:"http-error-handler"})}),"\n",(0,s.jsx)(r.p,{children:"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"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"fallbackMessage"}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-event-normalizer",children:"http-event-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-header-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-header-normalizer",children:"http-header-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-json-body-parser",children:"http-json-body-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-multipart-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-multipart-body-parser",children:"http-multipart-body-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-partial-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-partial-response",children:"http-partial-response"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-response-serializer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-response-serializer",children:"http-response-serializer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-security-headers",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-security-headers",children:"http-security-headers"})}),"\n",(0,s.jsxs)(r.p,{children:["No longer adds ",(0,s.jsx)(r.code,{children:"statusCode:500"})," when there is no response."]}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-body-parser",children:"http-urlencode-body-parser"})}),"\n",(0,s.jsxs)(r.p,{children:["Remove ",(0,s.jsx)(r.code,{children:"extended"})," option. Only uses ",(0,s.jsx)(r.code,{children:"qs"})," as the parser, formally enabled by options ",(0,s.jsx)(r.code,{children:"{extended: true}"}),"."]}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-path-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-path-parser",children:"http-urlencode-path-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"input-output-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/input-output-logger",children:"input-output-logger"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Now additionally logs response from the ",(0,s.jsx)(r.code,{children:"onError"})," middleware stack"]}),"\n",(0,s.jsx)(r.li,{children:"Support for omiting within nested arrays"}),"\n",(0,s.jsxs)(r.li,{children:["Add in support for ",(0,s.jsx)(r.code,{children:"replacer"})," to be passed into ",(0,s.jsx)(r.code,{children:"JSON.stringify()"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"rds-signer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/rds-signer",children:"rds-signer"})}),"\n",(0,s.jsxs)(r.p,{children:["New middleware to fetch RDS credential used when connecting with IAM roles. This was built into ",(0,s.jsx)(r.code,{children:"db-manager"}),"."]}),"\n",(0,s.jsx)(r.h3,{id:"s3-key-normalizer",children:"s3-key-normalizer"}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"s3-object-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/s3-object-response",children:"s3-object-response"})}),"\n",(0,s.jsx)(r.p,{children:"New middleware to fetch and respond to S3 Object Get request event."}),"\n",(0,s.jsx)(r.h3,{id:"secrets-manager",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/secrets-manager",children:"secrets-manager"})}),"\n",(0,s.jsx)(r.p,{children:"Refactored, see documentation"}),"\n",(0,s.jsx)(r.h3,{id:"sqs-json-body-parser",children:"sqs-json-body-parser"}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"sqs-partial-batch-failure",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sqs-partial-batch-failure",children:"sqs-partial-batch-failure"})}),"\n",(0,s.jsxs)(r.p,{children:["Replaced option ",(0,s.jsx)(r.code,{children:"sqs"})," with ",(0,s.jsx)(r.code,{children:"AwsClient"})," and added in more options for control."]}),"\n",(0,s.jsx)(r.h3,{id:"ssm",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ssm",children:"ssm"})}),"\n",(0,s.jsx)(r.p,{children:"Refactored, see documentation"}),"\n",(0,s.jsx)(r.h3,{id:"sts",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sts",children:"sts"})}),"\n",(0,s.jsx)(r.p,{children:"New middleware to fetch assume role credentials."}),"\n",(0,s.jsx)(r.h3,{id:"validator",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/validator",children:"validator"})}),"\n",(0,s.jsxs)(r.p,{children:["Upgraded ",(0,s.jsx)(r.code,{children:"ajv"})," and it's plugins to support JSON Schema Draft 2020-12 specification. Defaults were change because of this."]}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Plugin ",(0,s.jsx)(r.code,{children:"ajv-keywords"})," removed from being included by default because it's quite a large package and usually only one keyword is used."]}),"\n",(0,s.jsxs)(r.li,{children:["Plugin ",(0,s.jsx)(r.code,{children:"ajv-errors"})," removed from included by default because it conflicts with ",(0,s.jsx)(r.code,{children:"ajv-i18n"})," when dealing with custom messages for multiple languages"]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"warmup",children:"warmup"}),"\n",(0,s.jsxs)(r.p,{children:["Deprecated. This was a work round for a missing feature in AWS Lambda. AWS added in the ability to use ",(0,s.jsx)(r.a,{href:"https://aws.amazon.com/blogs/aws/new-provisioned-concurrency-for-lambda-functions/",children:"provisioned concurrency"}),"\non 2019-12-03, removing the need for this work around."]}),"\n",(0,s.jsx)(r.p,{children:"However, you can use the following if needed:"}),"\n",(0,s.jsx)(r.pre,{children:(0,s.jsx)(r.code,{className:"language-javascript",children:"middy(lambdaHandler).before((request) => {\n if (request.event.source === 'serverless-plugin-warmup') {\n console.log('Exiting early via warmup Middleware')\n return 'warmup'\n }\n})\n"})})]})}function h(e={}){const{wrapper:r}={...(0,d.a)(),...e.components};return r?(0,s.jsx)(r,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,r,n)=>{n.d(r,{Z:()=>a,a:()=>i});var s=n(7294);const d={},t=s.createContext(d);function i(e){const r=s.useContext(t);return s.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function a(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(d):e.components||d:i(e.components),s.createElement(t.Provider,{value:r},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/89ce8835.2c537261.js b/assets/js/89ce8835.3200c61f.js similarity index 94% rename from assets/js/89ce8835.2c537261.js rename to assets/js/89ce8835.3200c61f.js index bc1a44801..072e4c8c6 100644 --- a/assets/js/89ce8835.2c537261.js +++ b/assets/js/89ce8835.3200c61f.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1955],{3596:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>s,metadata:()=>r,toc:()=>d});var o=n(5893),i=n(1151);const s={title:"Cognito"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cognito.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Cognito"},sidebar:"tutorialSidebar",previous:{title:"CodePipeline",permalink:"/docs/events/code-pipeline"},next:{title:"Config",permalink:"/docs/events/config"}},c={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cognito.html",children:"Using AWS Lambda with Amazon Cognito"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function p(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var o=n(7294);const i={},s=o.createContext(i);function a(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1955],{3596:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>s,metadata:()=>r,toc:()=>d});var o=n(5893),i=n(1151);const s={title:"Cognito"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/cognito.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Cognito"},sidebar:"tutorialSidebar",previous:{title:"CodePipeline",permalink:"/docs/events/code-pipeline"},next:{title:"Config",permalink:"/docs/events/config"}},c={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-cognito.html",children:"Using AWS Lambda with Amazon Cognito"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function p(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var o=n(7294);const i={},s=o.createContext(i);function a(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/949815f5.49d9a0c3.js b/assets/js/949815f5.53f891ac.js similarity index 97% rename from assets/js/949815f5.49d9a0c3.js rename to assets/js/949815f5.53f891ac.js index 6a24cb6c3..21e1193a0 100644 --- a/assets/js/949815f5.49d9a0c3.js +++ b/assets/js/949815f5.53f891ac.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8394],{5707:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>c,frontMatter:()=>o,metadata:()=>r,toc:()=>m});var a=n(5893),i=n(1151);const o={title:"Kafka, Managed Streaming (MSK)"},s=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kafka-managed-streaming.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},m=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(t.admonition,{type:"caution",children:(0,a.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,a.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsx)(t.li,{children:(0,a.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-msk.html",children:"Using Lambda with Amazon MSK"})}),"\n"]}),"\n",(0,a.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function c(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>s});var a=n(7294);const i={},o=a.createContext(i);function s(e){const t=a.useContext(o);return a.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),a.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8394],{5707:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>c,frontMatter:()=>o,metadata:()=>r,toc:()=>m});var a=n(5893),i=n(1151);const o={title:"Kafka, Managed Streaming (MSK)"},s=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kafka-managed-streaming.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},m=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(t.admonition,{type:"caution",children:(0,a.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,a.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsx)(t.li,{children:(0,a.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-msk.html",children:"Using Lambda with Amazon MSK"})}),"\n"]}),"\n",(0,a.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function c(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>s});var a=n(7294);const i={},o=a.createContext(i);function s(e){const t=a.useContext(o);return a.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),a.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/958c573d.2c60aa10.js b/assets/js/958c573d.72eef0c4.js similarity index 97% rename from assets/js/958c573d.2c60aa10.js rename to assets/js/958c573d.72eef0c4.js index f6d16a764..f417dff01 100644 --- a/assets/js/958c573d.2c60aa10.js +++ b/assets/js/958c573d.72eef0c4.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8786],{5585:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>a,metadata:()=>r,toc:()=>d});var s=n(5893),o=n(1151);const a={title:"S3 Object"},i=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/s3-object.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"S3 Object"},sidebar:"tutorialSidebar",previous:{title:"S3 Batch",permalink:"/docs/events/s3-batch"},next:{title:"S3",permalink:"/docs/events/s3"}},c={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html",children:"Transforming S3 Objects with S3 Object Lambda"})}),"\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/AmazonS3/latest/userguide/transforming-objects.html",children:"Transforming objects with S3 Object Lambda"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>i});var s=n(7294);const o={},a=s.createContext(o);function i(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8786],{5585:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>a,metadata:()=>r,toc:()=>d});var s=n(5893),o=n(1151);const a={title:"S3 Object"},i=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/s3-object.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"S3 Object"},sidebar:"tutorialSidebar",previous:{title:"S3 Batch",permalink:"/docs/events/s3-batch"},next:{title:"S3",permalink:"/docs/events/s3"}},c={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html",children:"Transforming S3 Objects with S3 Object Lambda"})}),"\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/AmazonS3/latest/userguide/transforming-objects.html",children:"Transforming objects with S3 Object Lambda"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>i});var s=n(7294);const o={},a=s.createContext(o);function i(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/9d43f09c.080e48a0.js b/assets/js/9d43f09c.04c1e859.js similarity index 97% rename from assets/js/9d43f09c.080e48a0.js rename to assets/js/9d43f09c.04c1e859.js index 1c6fd171a..029b577fc 100644 --- a/assets/js/9d43f09c.080e48a0.js +++ b/assets/js/9d43f09c.04c1e859.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8591],{7663:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>s,metadata:()=>r,toc:()=>c});var i=n(5893),o=n(1151);const s={title:"EC2"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/ec2.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"EC2"},sidebar:"tutorialSidebar",previous:{title:"DynamoDB",permalink:"/docs/events/dynamodb"},next:{title:"EventBridge",permalink:"/docs/events/event-bridge"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.admonition,{type:"caution",children:(0,i.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:(0,i.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-ec2.html",children:"Using AWS Lambda with Amazon EC2"})}),"\n"]}),"\n",(0,i.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var i=n(7294);const o={},s=i.createContext(o);function a(e){const t=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),i.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8591],{7663:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>s,metadata:()=>r,toc:()=>c});var i=n(5893),o=n(1151);const s={title:"EC2"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/ec2.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"EC2"},sidebar:"tutorialSidebar",previous:{title:"DynamoDB",permalink:"/docs/events/dynamodb"},next:{title:"EventBridge",permalink:"/docs/events/event-bridge"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.admonition,{type:"caution",children:(0,i.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:(0,i.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-ec2.html",children:"Using AWS Lambda with Amazon EC2"})}),"\n"]}),"\n",(0,i.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var i=n(7294);const o={},s=i.createContext(o);function a(e){const t=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),i.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/9d560f77.b2ec2bf6.js b/assets/js/9d560f77.8736369a.js similarity index 97% rename from assets/js/9d560f77.b2ec2bf6.js rename to assets/js/9d560f77.8736369a.js index 182f8a36f..d457175c0 100644 --- a/assets/js/9d560f77.b2ec2bf6.js +++ b/assets/js/9d560f77.8736369a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[310],{8618:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>r,contentTitle:()=>s,default:()=>m,frontMatter:()=>a,metadata:()=>d,toc:()=>c});var o=n(5893),i=n(1151);const a={title:"DynamoDB"},s=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/dynamodb.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"DynamoDB"},sidebar:"tutorialSidebar",previous:{title:"DocumentDB",permalink:"/docs/events/documentdb"},next:{title:"EC2",permalink:"/docs/events/ec2"}},r={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html",children:"Using AWS Lambda with Amazon DynamoDB"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>d,a:()=>s});var o=n(7294);const i={},a=o.createContext(i);function s(e){const t=o.useContext(a);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),o.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[310],{8618:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>r,contentTitle:()=>s,default:()=>m,frontMatter:()=>a,metadata:()=>d,toc:()=>c});var o=n(5893),i=n(1151);const a={title:"DynamoDB"},s=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/dynamodb.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"DynamoDB"},sidebar:"tutorialSidebar",previous:{title:"DocumentDB",permalink:"/docs/events/documentdb"},next:{title:"EC2",permalink:"/docs/events/ec2"}},r={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html",children:"Using AWS Lambda with Amazon DynamoDB"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>d,a:()=>s});var o=n(7294);const i={},a=o.createContext(i);function s(e){const t=o.useContext(a);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),o.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a0697f1b.8503c09e.js b/assets/js/a0697f1b.f222c6bb.js similarity index 98% rename from assets/js/a0697f1b.8503c09e.js rename to assets/js/a0697f1b.f222c6bb.js index d70d1d563..fab1e128e 100644 --- a/assets/js/a0697f1b.8503c09e.js +++ b/assets/js/a0697f1b.f222c6bb.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5258],{957:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>d,default:()=>m,frontMatter:()=>o,metadata:()=>a,toc:()=>p});var n=r(5893),i=r(1151);const o={title:"VPC Lattice"},d=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/vpc-lattice.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"VPC Lattice"},sidebar:"tutorialSidebar",previous:{title:"SQS",permalink:"/docs/events/sqs"},next:{title:"WorkMail",permalink:"/docs/events/workmail"}},s={},p=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,n.jsxs)(t.p,{children:["We recommend using ",(0,n.jsx)(t.code,{children:"@middy/http-event-normalizer"})," if you place to use any of the following: ",(0,n.jsx)(t.code,{children:"@middy/http-json-body-parser"}),", ",(0,n.jsx)(t.code,{children:"@middy/http-multipart-body-parser"}),", ",(0,n.jsx)(t.code,{children:"@middy/http-urlencode-body-parser"}),", ",(0,n.jsx)(t.code,{children:"@middy/http-partial-response"})]}),"\n",(0,n.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-vpc-lattice.html",children:"Using AWS Lambda with Amazon VPC Lattice"})}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>a,a:()=>d});var n=r(7294);const i={},o=n.createContext(i);function d(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:d(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5258],{957:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>d,default:()=>m,frontMatter:()=>o,metadata:()=>a,toc:()=>p});var n=r(5893),i=r(1151);const o={title:"VPC Lattice"},d=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/vpc-lattice.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"VPC Lattice"},sidebar:"tutorialSidebar",previous:{title:"SQS",permalink:"/docs/events/sqs"},next:{title:"WorkMail",permalink:"/docs/events/workmail"}},s={},p=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,n.jsxs)(t.p,{children:["We recommend using ",(0,n.jsx)(t.code,{children:"@middy/http-event-normalizer"})," if you place to use any of the following: ",(0,n.jsx)(t.code,{children:"@middy/http-json-body-parser"}),", ",(0,n.jsx)(t.code,{children:"@middy/http-multipart-body-parser"}),", ",(0,n.jsx)(t.code,{children:"@middy/http-urlencode-body-parser"}),", ",(0,n.jsx)(t.code,{children:"@middy/http-partial-response"})]}),"\n",(0,n.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-vpc-lattice.html",children:"Using AWS Lambda with Amazon VPC Lattice"})}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>a,a:()=>d});var n=r(7294);const i={},o=n.createContext(i);function d(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:d(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a07e9812.09648006.js b/assets/js/a07e9812.f3d0db35.js similarity index 97% rename from assets/js/a07e9812.09648006.js rename to assets/js/a07e9812.f3d0db35.js index 3268fd7a2..55e4863fe 100644 --- a/assets/js/a07e9812.09648006.js +++ b/assets/js/a07e9812.f3d0db35.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2511],{6916:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>m,frontMatter:()=>o,metadata:()=>a,toc:()=>c});var s=n(5893),i=n(1151);const o={title:"RDS"},r=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/rds.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"RDS"},sidebar:"tutorialSidebar",previous:{title:"MQ",permalink:"/docs/events/mq"},next:{title:"S3 Batch",permalink:"/docs/events/s3-batch"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-rds.html",children:"Using AWS Lambda with Amazon RDS"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>a,a:()=>r});var s=n(7294);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2511],{6916:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>m,frontMatter:()=>o,metadata:()=>a,toc:()=>c});var s=n(5893),i=n(1151);const o={title:"RDS"},r=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/rds.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"RDS"},sidebar:"tutorialSidebar",previous:{title:"MQ",permalink:"/docs/events/mq"},next:{title:"S3 Batch",permalink:"/docs/events/s3-batch"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-rds.html",children:"Using AWS Lambda with Amazon RDS"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>a,a:()=>r});var s=n(7294);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a17e0e42.13707390.js b/assets/js/a17e0e42.cd6d8763.js similarity index 99% rename from assets/js/a17e0e42.13707390.js rename to assets/js/a17e0e42.cd6d8763.js index 7c44c7a89..38313362e 100644 --- a/assets/js/a17e0e42.13707390.js +++ b/assets/js/a17e0e42.cd6d8763.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2201],{5276:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>p,frontMatter:()=>i,metadata:()=>d,toc:()=>u});var s=t(5893),r=t(1151),a=t(4866),l=t(5162);const i={title:"s3"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/s3.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{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},{value:"Usage with TypeScript",id:"usage-with-typescript",level:2}];function h(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Fetches S3 stored configuration and parses out JSON."}),"\n",(0,s.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(l.Z,{value:"npm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/s3\nnpm install --save-dev @aws-sdk/client-s3\n"})})}),(0,s.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/s3\nyarn add --dev @aws-sdk/client-s3\n"})})}),(0,s.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/s3\npnpm add --save-dev @aws-sdk/client-s3\n"})})})]}),"\n",(0,s.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(n.code,{children:"S3Client"}),"): S3Client class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-appconfig"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientOptions"})," (object) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Options to pass to S3Client class constructor."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," (string) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Internal key where secrets are stored. See ",(0,s.jsx)(n.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientCapture"})," (function) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Enable XRay by passing ",(0,s.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,s.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameters."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheKey"})," (string) (default ",(0,s.jsx)(n.code,{children:"s3"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheExpiry"})," (number) (default ",(0,s.jsx)(n.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,s.jsx)(n.code,{children:"-1"}),": cache forever, ",(0,s.jsx)(n.code,{children:"0"}),": never cache, ",(0,s.jsx)(n.code,{children:"n"}),": cache for n ms."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"setToContext"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): Store credentials to ",(0,s.jsx)(n.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(n.code,{children:"s3:GetObject"})]}),"\n",(0,s.jsxs)(n.li,{children:["If the file is stored without ",(0,s.jsx)(n.code,{children:"ContentType"}),", you can set it on the response using ",(0,s.jsx)(n.code,{children:"ResponseContentType"})," as part of the input"]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport s3 from '@middy/s3'\n\nconst lambdaHandler = (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\nexport const handler = middy()\n .use(\n s3({\n fetchData: {\n config: {\n Bucket: '...',\n Key: '...'\n }\n },\n setToContext: true\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(n.p,{children:["To exclude ",(0,s.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-s3"})," to the exclude list."]}),"\n",(0,s.jsx)(n.h2,{id:"usage-with-typescript",children:"Usage with TypeScript"}),"\n",(0,s.jsxs)(n.p,{children:["Data in an S3 object can be stored as arbitrary structured data. It's not possible to know in advance what shape the fetched data will have, so by default the fetched parameters will have type ",(0,s.jsx)(n.code,{children:"unknown"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["You can provide some type hints by leveraging the ",(0,s.jsx)(n.code,{children:"s3Req"})," utility function. This function allows you to specify what's the expected type that will be fetched for every S3 request."]}),"\n",(0,s.jsxs)(n.p,{children:["The idea is that, for every request specified in the ",(0,s.jsx)(n.code,{children:"fetchData"})," option, rather than just providing the parameter configuration as an object, you can wrap it in a ",(0,s.jsx)(n.code,{children:"s3Req(config)"})," call. Internally, ",(0,s.jsx)(n.code,{children:"s3Req"})," is a function that will return ",(0,s.jsx)(n.code,{children:"config"})," as received, but it allows you to use generics to provide type hints for the expected fetched value type for that request."]}),"\n",(0,s.jsx)(n.p,{children:"This way TypeScript can understand how to treat the additional data attached to the context and stored in the internal storage."}),"\n",(0,s.jsxs)(n.p,{children:["The following example illustrates how to use ",(0,s.jsx)(n.code,{children:"s3Req"}),":"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import middy from '@middy/core'\nimport s3, { s3Req } 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: s3Req<{field1: string, field2: string, field3: number}>({\n Bucket: '...',\n Key: '...'\n }\n }),\n setToContext: true\n })\n)\n.before(async (request) => {\n const data = await getInternal('config', request)\n // data.config.field1 (string)\n // data.config.field2 (string)\n // data.config.field3 (number)\n})\n"})})]})}function p(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>l});t(7294);var s=t(6010);const r={tabItem:"tabItem_Ymn6"};var a=t(5893);function l(e){let{children:n,hidden:t,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.Z)(r.tabItem,l),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var s=t(7294),r=t(6010),a=t(2466),l=t(6550),i=t(469),o=t(1980),d=t(7392),c=t(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:t}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:s,default:r}}=e;return{value:n,label:t,attributes:s,default:r}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function p(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function f(e){let{queryString:n=!1,groupId:t}=e;const r=(0,l.k6)(),a=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(a),(0,s.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(r.location.search);n.set(a,e),r.replace({...r.location,search:n.toString()})}),[a,r])]}function m(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,a=h(e),[l,o]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const s=t.find((e=>e.default))??t[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:a}))),[d,u]=f({queryString:t,groupId:r}),[m,x]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,a]=(0,c.Nk)(t);return[r,(0,s.useCallback)((e=>{t&&a.set(e)}),[t,a])]}({groupId:r}),b=(()=>{const e=d??m;return p({value:e,tabValues:a})?e:null})();(0,i.Z)((()=>{b&&o(b)}),[b]);return{selectedValue:l,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),x(e)}),[u,x,a]),tabValues:a}}var x=t(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=t(5893);function g(e){let{className:n,block:t,selectedValue:s,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,a.o5)(),c=e=>{const n=e.currentTarget,t=o.indexOf(n),r=i[t].value;r!==s&&(d(n),l(r))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":t},n),children:i.map((e=>{let{value:n,label:t,attributes:a}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...a,className:(0,r.Z)("tabs__item",b.tabItem,a?.className,{"tabs__item--active":s===n}),children:t??n},n)}))})}function y(e){let{lazy:n,children:t,selectedValue:r}=e;const a=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===r));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function v(e){const n=m(e);return(0,j.jsxs)("div",{className:(0,r.Z)("tabs-container",b.tabList),children:[(0,j.jsx)(g,{...e,...n}),(0,j.jsx)(y,{...e,...n})]})}function w(e){const n=(0,x.Z)();return(0,j.jsx)(v,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>l});var s=t(7294);const r={},a=s.createContext(r);function l(e){const n=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:l(e.components),s.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2201],{5276:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>p,frontMatter:()=>i,metadata:()=>d,toc:()=>u});var s=t(5893),r=t(1151),a=t(4866),l=t(5162);const i={title:"s3"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/s3.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{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},{value:"Usage with TypeScript",id:"usage-with-typescript",level:2}];function h(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Fetches S3 stored configuration and parses out JSON."}),"\n",(0,s.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(l.Z,{value:"npm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/s3\nnpm install --save-dev @aws-sdk/client-s3\n"})})}),(0,s.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/s3\nyarn add --dev @aws-sdk/client-s3\n"})})}),(0,s.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/s3\npnpm add --save-dev @aws-sdk/client-s3\n"})})})]}),"\n",(0,s.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(n.code,{children:"S3Client"}),"): S3Client class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-appconfig"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientOptions"})," (object) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Options to pass to S3Client class constructor."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," (string) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Internal key where secrets are stored. See ",(0,s.jsx)(n.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientCapture"})," (function) (default ",(0,s.jsx)(n.code,{children:"undefined"}),"): Enable XRay by passing ",(0,s.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,s.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameters."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheKey"})," (string) (default ",(0,s.jsx)(n.code,{children:"s3"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheExpiry"})," (number) (default ",(0,s.jsx)(n.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,s.jsx)(n.code,{children:"-1"}),": cache forever, ",(0,s.jsx)(n.code,{children:"0"}),": never cache, ",(0,s.jsx)(n.code,{children:"n"}),": cache for n ms."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"setToContext"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): Store credentials to ",(0,s.jsx)(n.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(n.code,{children:"s3:GetObject"})]}),"\n",(0,s.jsxs)(n.li,{children:["If the file is stored without ",(0,s.jsx)(n.code,{children:"ContentType"}),", you can set it on the response using ",(0,s.jsx)(n.code,{children:"ResponseContentType"})," as part of the input"]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport s3 from '@middy/s3'\n\nconst lambdaHandler = (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\nexport const handler = middy()\n .use(\n s3({\n fetchData: {\n config: {\n Bucket: '...',\n Key: '...'\n }\n },\n setToContext: true\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(n.p,{children:["To exclude ",(0,s.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-s3"})," to the exclude list."]}),"\n",(0,s.jsx)(n.h2,{id:"usage-with-typescript",children:"Usage with TypeScript"}),"\n",(0,s.jsxs)(n.p,{children:["Data in an S3 object can be stored as arbitrary structured data. It's not possible to know in advance what shape the fetched data will have, so by default the fetched parameters will have type ",(0,s.jsx)(n.code,{children:"unknown"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["You can provide some type hints by leveraging the ",(0,s.jsx)(n.code,{children:"s3Req"})," utility function. This function allows you to specify what's the expected type that will be fetched for every S3 request."]}),"\n",(0,s.jsxs)(n.p,{children:["The idea is that, for every request specified in the ",(0,s.jsx)(n.code,{children:"fetchData"})," option, rather than just providing the parameter configuration as an object, you can wrap it in a ",(0,s.jsx)(n.code,{children:"s3Req(config)"})," call. Internally, ",(0,s.jsx)(n.code,{children:"s3Req"})," is a function that will return ",(0,s.jsx)(n.code,{children:"config"})," as received, but it allows you to use generics to provide type hints for the expected fetched value type for that request."]}),"\n",(0,s.jsx)(n.p,{children:"This way TypeScript can understand how to treat the additional data attached to the context and stored in the internal storage."}),"\n",(0,s.jsxs)(n.p,{children:["The following example illustrates how to use ",(0,s.jsx)(n.code,{children:"s3Req"}),":"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import middy from '@middy/core'\nimport s3, { s3Req } 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: s3Req<{field1: string, field2: string, field3: number}>({\n Bucket: '...',\n Key: '...'\n }\n }),\n setToContext: true\n })\n)\n.before(async (request) => {\n const data = await getInternal('config', request)\n // data.config.field1 (string)\n // data.config.field2 (string)\n // data.config.field3 (number)\n})\n"})})]})}function p(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>l});t(7294);var s=t(6010);const r={tabItem:"tabItem_Ymn6"};var a=t(5893);function l(e){let{children:n,hidden:t,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.Z)(r.tabItem,l),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var s=t(7294),r=t(6010),a=t(2466),l=t(6550),i=t(469),o=t(1980),d=t(7392),c=t(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:t}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:s,default:r}}=e;return{value:n,label:t,attributes:s,default:r}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function p(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function f(e){let{queryString:n=!1,groupId:t}=e;const r=(0,l.k6)(),a=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(a),(0,s.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(r.location.search);n.set(a,e),r.replace({...r.location,search:n.toString()})}),[a,r])]}function m(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,a=h(e),[l,o]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const s=t.find((e=>e.default))??t[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:a}))),[d,u]=f({queryString:t,groupId:r}),[m,x]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,a]=(0,c.Nk)(t);return[r,(0,s.useCallback)((e=>{t&&a.set(e)}),[t,a])]}({groupId:r}),b=(()=>{const e=d??m;return p({value:e,tabValues:a})?e:null})();(0,i.Z)((()=>{b&&o(b)}),[b]);return{selectedValue:l,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),x(e)}),[u,x,a]),tabValues:a}}var x=t(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=t(5893);function g(e){let{className:n,block:t,selectedValue:s,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,a.o5)(),c=e=>{const n=e.currentTarget,t=o.indexOf(n),r=i[t].value;r!==s&&(d(n),l(r))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":t},n),children:i.map((e=>{let{value:n,label:t,attributes:a}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...a,className:(0,r.Z)("tabs__item",b.tabItem,a?.className,{"tabs__item--active":s===n}),children:t??n},n)}))})}function y(e){let{lazy:n,children:t,selectedValue:r}=e;const a=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===r));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function v(e){const n=m(e);return(0,j.jsxs)("div",{className:(0,r.Z)("tabs-container",b.tabList),children:[(0,j.jsx)(g,{...e,...n}),(0,j.jsx)(y,{...e,...n})]})}function w(e){const n=(0,x.Z)();return(0,j.jsx)(v,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>l});var s=t(7294);const r={},a=s.createContext(r);function l(e){const n=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:l(e.components),s.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a2b2d33a.938a0662.js b/assets/js/a2b2d33a.87ab86e7.js similarity index 96% rename from assets/js/a2b2d33a.938a0662.js rename to assets/js/a2b2d33a.87ab86e7.js index 79d27cf53..77db6e01a 100644 --- a/assets/js/a2b2d33a.938a0662.js +++ b/assets/js/a2b2d33a.87ab86e7.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8974],{9635:(e,t,i)=>{i.r(t),i.d(t,{assets:()=>a,contentTitle:()=>n,default:()=>c,frontMatter:()=>s,metadata:()=>d,toc:()=>m});var r=i(5893),o=i(1151);const s={title:"More Examples",position:6},n=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/06-more-examples.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},a={},m=[];function l(e){const t={a:"a",p:"p",...(0,o.a)(),...e.components};return(0,r.jsxs)(t.p,{children:["Check the ",(0,r.jsx)(t.a,{href:"https://github.com/middyjs/middy/tree/main/packages",children:"code for existing middlewares"})," to see more examples on how to write a middleware."]})}function c(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},1151:(e,t,i)=>{i.d(t,{Z:()=>d,a:()=>n});var r=i(7294);const o={},s=r.createContext(o);function n(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:n(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8974],{9635:(e,t,i)=>{i.r(t),i.d(t,{assets:()=>a,contentTitle:()=>n,default:()=>c,frontMatter:()=>s,metadata:()=>d,toc:()=>m});var r=i(5893),o=i(1151);const s={title:"More Examples",position:6},n=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/06-more-examples.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},a={},m=[];function l(e){const t={a:"a",p:"p",...(0,o.a)(),...e.components};return(0,r.jsxs)(t.p,{children:["Check the ",(0,r.jsx)(t.a,{href:"https://github.com/middyjs/middy/tree/main/packages",children:"code for existing middlewares"})," to see more examples on how to write a middleware."]})}function c(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},1151:(e,t,i)=>{i.d(t,{Z:()=>d,a:()=>n});var r=i(7294);const o={},s=r.createContext(o);function n(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:n(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a3787fd8.f9a8a6d5.js b/assets/js/a3787fd8.d2c7a42e.js similarity index 97% rename from assets/js/a3787fd8.f9a8a6d5.js rename to assets/js/a3787fd8.d2c7a42e.js index c6e79113d..0625368e9 100644 --- a/assets/js/a3787fd8.f9a8a6d5.js +++ b/assets/js/a3787fd8.d2c7a42e.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9576],{8133:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>u,frontMatter:()=>s,metadata:()=>c,toc:()=>a});var i=n(5893),o=n(1151);const s={title:"Influence"},r=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/08-influence.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:8,frontMatter:{title:"Influence"},sidebar:"tutorialSidebar",previous:{title:"History",permalink:"/docs/intro/history"},next:{title:"Utilities",permalink:"/docs/intro/utilities"}},d={},a=[];function l(e){const t={a:"a",li:"li",p:"p",ul:"ul",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.p,{children:"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."}),"\n",(0,i.jsx)(t.p,{children:"Since middy started to gain popularity in the Node.js ecosystem, we have seen some independent projects taking the same ideas to other ecosystems:"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:[".Net port ",(0,i.jsx)(t.a,{href:"https://github.com/VoxelGroup/Voxel.MiddyNet",children:"Voxel.MiddyNet"})," ",(0,i.jsx)(t.a,{href:"https://twitter.com/vgaltes/status/1366371605337825284",children:"@vgaltes"})]}),"\n",(0,i.jsxs)(t.li,{children:["GoLang port ",(0,i.jsx)(t.a,{href:"https://github.com/mefellows/vesper",children:"Vesper"})]}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:"Do you have a similar project? Let us know."})]})}function u(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>c,a:()=>r});var i=n(7294);const o={},s=i.createContext(o);function r(e){const t=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),i.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9576],{8133:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>u,frontMatter:()=>s,metadata:()=>c,toc:()=>a});var i=n(5893),o=n(1151);const s={title:"Influence"},r=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/08-influence.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:8,frontMatter:{title:"Influence"},sidebar:"tutorialSidebar",previous:{title:"History",permalink:"/docs/intro/history"},next:{title:"Utilities",permalink:"/docs/intro/utilities"}},d={},a=[];function l(e){const t={a:"a",li:"li",p:"p",ul:"ul",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.p,{children:"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."}),"\n",(0,i.jsx)(t.p,{children:"Since middy started to gain popularity in the Node.js ecosystem, we have seen some independent projects taking the same ideas to other ecosystems:"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:[".Net port ",(0,i.jsx)(t.a,{href:"https://github.com/VoxelGroup/Voxel.MiddyNet",children:"Voxel.MiddyNet"})," ",(0,i.jsx)(t.a,{href:"https://twitter.com/vgaltes/status/1366371605337825284",children:"@vgaltes"})]}),"\n",(0,i.jsxs)(t.li,{children:["GoLang port ",(0,i.jsx)(t.a,{href:"https://github.com/mefellows/vesper",children:"Vesper"})]}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:"Do you have a similar project? Let us know."})]})}function u(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>c,a:()=>r});var i=n(7294);const o={},s=i.createContext(o);function r(e){const t=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),i.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a7630442.30bdd835.js b/assets/js/a7630442.75d6c759.js similarity index 96% rename from assets/js/a7630442.30bdd835.js rename to assets/js/a7630442.75d6c759.js index ab458c3a7..c4058d618 100644 --- a/assets/js/a7630442.30bdd835.js +++ b/assets/js/a7630442.75d6c759.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9502],{9878:(t,o,n)=>{n.r(o),n.d(o,{assets:()=>d,contentTitle:()=>s,default:()=>u,frontMatter:()=>r,metadata:()=>a,toc:()=>c});var e=n(5893),i=n(1151);const r={title:"Sponsoring"},s=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/11-sponsoring.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:11,frontMatter:{title:"Sponsoring"},sidebar:"tutorialSidebar",previous:{title:"Contributing",permalink:"/docs/intro/contributing"},next:{title:"Middlewares",permalink:"/docs/category/middlewares"}},d={},c=[];function p(t){const o={a:"a",p:"p",...(0,i.a)(),...t.components};return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(o.p,{children:"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."}),"\n",(0,e.jsx)(o.p,{children:(0,e.jsx)(o.a,{href:"https://github.com/sponsors/willfarrell",children:"GitHub Sponsors"})})]})}function u(t={}){const{wrapper:o}={...(0,i.a)(),...t.components};return o?(0,e.jsx)(o,{...t,children:(0,e.jsx)(p,{...t})}):p(t)}},1151:(t,o,n)=>{n.d(o,{Z:()=>a,a:()=>s});var e=n(7294);const i={},r=e.createContext(i);function s(t){const o=e.useContext(r);return e.useMemo((function(){return"function"==typeof t?t(o):{...o,...t}}),[o,t])}function a(t){let o;return o=t.disableParentContext?"function"==typeof t.components?t.components(i):t.components||i:s(t.components),e.createElement(r.Provider,{value:o},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9502],{9878:(t,o,n)=>{n.r(o),n.d(o,{assets:()=>d,contentTitle:()=>s,default:()=>u,frontMatter:()=>r,metadata:()=>a,toc:()=>c});var e=n(5893),i=n(1151);const r={title:"Sponsoring"},s=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/11-sponsoring.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:11,frontMatter:{title:"Sponsoring"},sidebar:"tutorialSidebar",previous:{title:"Contributing",permalink:"/docs/intro/contributing"},next:{title:"Middlewares",permalink:"/docs/category/middlewares"}},d={},c=[];function p(t){const o={a:"a",p:"p",...(0,i.a)(),...t.components};return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(o.p,{children:"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."}),"\n",(0,e.jsx)(o.p,{children:(0,e.jsx)(o.a,{href:"https://github.com/sponsors/willfarrell",children:"GitHub Sponsors"})})]})}function u(t={}){const{wrapper:o}={...(0,i.a)(),...t.components};return o?(0,e.jsx)(o,{...t,children:(0,e.jsx)(p,{...t})}):p(t)}},1151:(t,o,n)=>{n.d(o,{Z:()=>a,a:()=>s});var e=n(7294);const i={},r=e.createContext(i);function s(t){const o=e.useContext(r);return e.useMemo((function(){return"function"==typeof t?t(o):{...o,...t}}),[o,t])}function a(t){let o;return o=t.disableParentContext?"function"==typeof t.components?t.components(i):t.components||i:s(t.components),e.createElement(r.Provider,{value:o},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/a7c9f8b5.6238d387.js b/assets/js/a7c9f8b5.2f0eccf1.js similarity index 97% rename from assets/js/a7c9f8b5.6238d387.js rename to assets/js/a7c9f8b5.2f0eccf1.js index 8654dfa58..ae4e19620 100644 --- a/assets/js/a7c9f8b5.6238d387.js +++ b/assets/js/a7c9f8b5.2f0eccf1.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5898],{207:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>r,toc:()=>c});var s=n(5893),i=n(1151);const o={title:"SES"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/ses.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"SES"},sidebar:"tutorialSidebar",previous:{title:"Secrets Manager",permalink:"/docs/events/secrets-manager"},next:{title:"SNS",permalink:"/docs/events/sns"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-ses.html",children:"Using AWS Lambda with Amazon SES"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var s=n(7294);const i={},o=s.createContext(i);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5898],{207:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>r,toc:()=>c});var s=n(5893),i=n(1151);const o={title:"SES"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/ses.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"SES"},sidebar:"tutorialSidebar",previous:{title:"Secrets Manager",permalink:"/docs/events/secrets-manager"},next:{title:"SNS",permalink:"/docs/events/sns"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-ses.html",children:"Using AWS Lambda with Amazon SES"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var s=n(7294);const i={},o=s.createContext(i);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a8e9225e.cbd3d422.js b/assets/js/a8e9225e.7e781477.js similarity index 99% rename from assets/js/a8e9225e.cbd3d422.js rename to assets/js/a8e9225e.7e781477.js index 99f8a2f35..8965b39a3 100644 --- a/assets/js/a8e9225e.cbd3d422.js +++ b/assets/js/a8e9225e.7e781477.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9319],{4579:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>p,frontMatter:()=>l,metadata:()=>d,toc:()=>u});var a=t(5893),r=t(1151),s=t(4866),i=t(5162);const l={title:"http-content-negotiation"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-content-negotiation.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(n.p,{children:["This middleware parses ",(0,a.jsx)(n.code,{children:"Accept-*"})," headers and provides utilities for ",(0,a.jsx)(n.a,{href:"https://tools.ietf.org/html/rfc7231#section-5.3",children:"HTTP content negotiation"})," (charset, encoding, language and media type)."]}),"\n",(0,a.jsxs)(n.p,{children:["By default the middleware parses charsets (",(0,a.jsx)(n.code,{children:"Accept-Charset"}),"), languages (",(0,a.jsx)(n.code,{children:"Accept-Language"}),"), encodings (",(0,a.jsx)(n.code,{children:"Accept-Encoding"}),") and media types (",(0,a.jsx)(n.code,{children:"Accept"}),") during the\n",(0,a.jsx)(n.code,{children:"before"})," phase and expands the ",(0,a.jsx)(n.code,{children:"context"})," object by adding the following properties:"]}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredCharsets"})," (",(0,a.jsx)(n.code,{children:"array"}),") - The list of charsets that can be safely used by the app (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredCharset"})," (",(0,a.jsx)(n.code,{children:"string"}),") - The preferred charset (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredEncodings"})," (",(0,a.jsx)(n.code,{children:"array"}),") - The list of encodings that can be safely used by the app (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredEncoding"})," (",(0,a.jsx)(n.code,{children:"string"}),") - The preferred encoding (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredLanguages"})," (",(0,a.jsx)(n.code,{children:"array"}),") - The list of languages that can be safely used by the app (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredLanguage"})," (",(0,a.jsx)(n.code,{children:"string"}),") - The preferred language (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredMediaTypes"})," (",(0,a.jsx)(n.code,{children:"array"}),") - The list of media types that can be safely used by the app (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredMediaType"})," (",(0,a.jsx)(n.code,{children:"string"}),") - The preferred media types (as the result of the negotiation)"]}),"\n"]}),"\n",(0,a.jsxs)(n.p,{children:["This middleware expects the headers in canonical format, so it should be attached after the ",(0,a.jsx)(n.a,{href:"#httpheadernormalizer",children:(0,a.jsx)(n.code,{children:"httpHeaderNormalizer"})})," middleware.\nIt also can throw an HTTP exception, so it can be convenient to use it in combination with the ",(0,a.jsx)(n.a,{href:"#httperrorhandler",children:(0,a.jsx)(n.code,{children:"httpErrorHandler"})}),"."]}),"\n",(0,a.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,a.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,a.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(i.Z,{value:"npm",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/http-content-negotiation\n"})})}),(0,a.jsx)(i.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/http-content-negotiation\n"})})}),(0,a.jsx)(i.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/http-content-negotiation\n"})})})]}),"\n",(0,a.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"parseCharsets"})," (defaults to ",(0,a.jsx)(n.code,{children:"true"}),") - Allows enabling/disabling the charsets parsing"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"availableCharsets"})," (defaults to ",(0,a.jsx)(n.code,{children:"undefined"}),") - Allows defining the list of charsets supported by the Lambda function"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"parseEncodings"})," (defaults to ",(0,a.jsx)(n.code,{children:"true"}),") - Allows enabling/disabling the encodings parsing"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"availableEncodings"})," (defaults to ",(0,a.jsx)(n.code,{children:"undefined"}),") - Allows defining the list of encodings supported by the Lambda function"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"parseLanguages"})," (defaults to ",(0,a.jsx)(n.code,{children:"true"}),") - Allows enabling/disabling the languages parsing"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"availableLanguages"})," (defaults to ",(0,a.jsx)(n.code,{children:"undefined"}),") - Allows defining the list of languages supported by the Lambda function"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"parseMediaTypes"})," (defaults to ",(0,a.jsx)(n.code,{children:"true"}),") - Allows enabling/disabling the media types parsing"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"availableMediaTypes"})," (defaults to ",(0,a.jsx)(n.code,{children:"undefined"}),") - Allows defining the list of media types supported by the Lambda function"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"failOnMismatch"})," (defaults to ",(0,a.jsx)(n.code,{children:"true"}),") - If set to true it will throw an HTTP ",(0,a.jsx)(n.code,{children:"NotAcceptable"})," (406) exception when the negotiation fails for one of the headers (e.g. none of the languages requested are supported by the app)"]}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"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\nconst lambdaHandler = (event, context) => {\n let message, body\n\n switch (context.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 (context.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\nexport const handler = middy()\n .use(httpHeaderNormalizer())\n .use(\n httpContentNegotiation({\n parseCharsets: false,\n parseEncodings: false,\n availableLanguages: ['it-it', 'fr-fr', 'en'],\n availableMediaTypes: [\n 'application/xml',\n 'application/yaml',\n 'application/json',\n 'text/plain'\n ]\n })\n )\n .use(httpErrorHandler())\n .handler(lambdaHandler)\n"})})]})}function p(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>i});t(7294);var a=t(6010);const r={tabItem:"tabItem_Ymn6"};var s=t(5893);function i(e){let{children:n,hidden:t,className:i}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,a.Z)(r.tabItem,i),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var a=t(7294),r=t(6010),s=t(2466),i=t(6550),l=t(469),o=t(1980),d=t(7392),c=t(12);function u(e){return a.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:t}=e;return(0,a.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:a,default:r}}=e;return{value:n,label:t,attributes:a,default:r}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function p(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function f(e){let{queryString:n=!1,groupId:t}=e;const r=(0,i.k6)(),s=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(s),(0,a.useCallback)((e=>{if(!s)return;const n=new URLSearchParams(r.location.search);n.set(s,e),r.replace({...r.location,search:n.toString()})}),[s,r])]}function g(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,s=h(e),[i,o]=(0,a.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const a=t.find((e=>e.default))??t[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:n,tabValues:s}))),[d,u]=f({queryString:t,groupId:r}),[g,m]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,s]=(0,c.Nk)(t);return[r,(0,a.useCallback)((e=>{t&&s.set(e)}),[t,s])]}({groupId:r}),b=(()=>{const e=d??g;return p({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{b&&o(b)}),[b]);return{selectedValue:i,selectValue:(0,a.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),m(e)}),[u,m,s]),tabValues:s}}var m=t(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=t(5893);function j(e){let{className:n,block:t,selectedValue:a,selectValue:i,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),c=e=>{const n=e.currentTarget,t=o.indexOf(n),r=l[t].value;r!==a&&(d(n),i(r))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":t},n),children:l.map((e=>{let{value:n,label:t,attributes:s}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:a===n?0:-1,"aria-selected":a===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...s,className:(0,r.Z)("tabs__item",b.tabItem,s?.className,{"tabs__item--active":a===n}),children:t??n},n)}))})}function y(e){let{lazy:n,children:t,selectedValue:r}=e;const s=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=s.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:s.map(((e,n)=>(0,a.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function v(e){const n=g(e);return(0,x.jsxs)("div",{className:(0,r.Z)("tabs-container",b.tabList),children:[(0,x.jsx)(j,{...e,...n}),(0,x.jsx)(y,{...e,...n})]})}function w(e){const n=(0,m.Z)();return(0,x.jsx)(v,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>l,a:()=>i});var a=t(7294);const r={},s=a.createContext(r);function i(e){const n=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),a.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9319],{4579:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>p,frontMatter:()=>l,metadata:()=>d,toc:()=>u});var a=t(5893),r=t(1151),s=t(4866),i=t(5162);const l={title:"http-content-negotiation"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-content-negotiation.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(n.p,{children:["This middleware parses ",(0,a.jsx)(n.code,{children:"Accept-*"})," headers and provides utilities for ",(0,a.jsx)(n.a,{href:"https://tools.ietf.org/html/rfc7231#section-5.3",children:"HTTP content negotiation"})," (charset, encoding, language and media type)."]}),"\n",(0,a.jsxs)(n.p,{children:["By default the middleware parses charsets (",(0,a.jsx)(n.code,{children:"Accept-Charset"}),"), languages (",(0,a.jsx)(n.code,{children:"Accept-Language"}),"), encodings (",(0,a.jsx)(n.code,{children:"Accept-Encoding"}),") and media types (",(0,a.jsx)(n.code,{children:"Accept"}),") during the\n",(0,a.jsx)(n.code,{children:"before"})," phase and expands the ",(0,a.jsx)(n.code,{children:"context"})," object by adding the following properties:"]}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredCharsets"})," (",(0,a.jsx)(n.code,{children:"array"}),") - The list of charsets that can be safely used by the app (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredCharset"})," (",(0,a.jsx)(n.code,{children:"string"}),") - The preferred charset (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredEncodings"})," (",(0,a.jsx)(n.code,{children:"array"}),") - The list of encodings that can be safely used by the app (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredEncoding"})," (",(0,a.jsx)(n.code,{children:"string"}),") - The preferred encoding (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredLanguages"})," (",(0,a.jsx)(n.code,{children:"array"}),") - The list of languages that can be safely used by the app (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredLanguage"})," (",(0,a.jsx)(n.code,{children:"string"}),") - The preferred language (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredMediaTypes"})," (",(0,a.jsx)(n.code,{children:"array"}),") - The list of media types that can be safely used by the app (as the result of the negotiation)"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"preferredMediaType"})," (",(0,a.jsx)(n.code,{children:"string"}),") - The preferred media types (as the result of the negotiation)"]}),"\n"]}),"\n",(0,a.jsxs)(n.p,{children:["This middleware expects the headers in canonical format, so it should be attached after the ",(0,a.jsx)(n.a,{href:"#httpheadernormalizer",children:(0,a.jsx)(n.code,{children:"httpHeaderNormalizer"})})," middleware.\nIt also can throw an HTTP exception, so it can be convenient to use it in combination with the ",(0,a.jsx)(n.a,{href:"#httperrorhandler",children:(0,a.jsx)(n.code,{children:"httpErrorHandler"})}),"."]}),"\n",(0,a.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,a.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,a.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(i.Z,{value:"npm",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/http-content-negotiation\n"})})}),(0,a.jsx)(i.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/http-content-negotiation\n"})})}),(0,a.jsx)(i.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/http-content-negotiation\n"})})})]}),"\n",(0,a.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"parseCharsets"})," (defaults to ",(0,a.jsx)(n.code,{children:"true"}),") - Allows enabling/disabling the charsets parsing"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"availableCharsets"})," (defaults to ",(0,a.jsx)(n.code,{children:"undefined"}),") - Allows defining the list of charsets supported by the Lambda function"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"parseEncodings"})," (defaults to ",(0,a.jsx)(n.code,{children:"true"}),") - Allows enabling/disabling the encodings parsing"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"availableEncodings"})," (defaults to ",(0,a.jsx)(n.code,{children:"undefined"}),") - Allows defining the list of encodings supported by the Lambda function"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"parseLanguages"})," (defaults to ",(0,a.jsx)(n.code,{children:"true"}),") - Allows enabling/disabling the languages parsing"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"availableLanguages"})," (defaults to ",(0,a.jsx)(n.code,{children:"undefined"}),") - Allows defining the list of languages supported by the Lambda function"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"parseMediaTypes"})," (defaults to ",(0,a.jsx)(n.code,{children:"true"}),") - Allows enabling/disabling the media types parsing"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"availableMediaTypes"})," (defaults to ",(0,a.jsx)(n.code,{children:"undefined"}),") - Allows defining the list of media types supported by the Lambda function"]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"failOnMismatch"})," (defaults to ",(0,a.jsx)(n.code,{children:"true"}),") - If set to true it will throw an HTTP ",(0,a.jsx)(n.code,{children:"NotAcceptable"})," (406) exception when the negotiation fails for one of the headers (e.g. none of the languages requested are supported by the app)"]}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"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\nconst lambdaHandler = (event, context) => {\n let message, body\n\n switch (context.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 (context.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\nexport const handler = middy()\n .use(httpHeaderNormalizer())\n .use(\n httpContentNegotiation({\n parseCharsets: false,\n parseEncodings: false,\n availableLanguages: ['it-it', 'fr-fr', 'en'],\n availableMediaTypes: [\n 'application/xml',\n 'application/yaml',\n 'application/json',\n 'text/plain'\n ]\n })\n )\n .use(httpErrorHandler())\n .handler(lambdaHandler)\n"})})]})}function p(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>i});t(7294);var a=t(6010);const r={tabItem:"tabItem_Ymn6"};var s=t(5893);function i(e){let{children:n,hidden:t,className:i}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,a.Z)(r.tabItem,i),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var a=t(7294),r=t(6010),s=t(2466),i=t(6550),l=t(469),o=t(1980),d=t(7392),c=t(12);function u(e){return a.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:t}=e;return(0,a.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:a,default:r}}=e;return{value:n,label:t,attributes:a,default:r}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function p(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function f(e){let{queryString:n=!1,groupId:t}=e;const r=(0,i.k6)(),s=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(s),(0,a.useCallback)((e=>{if(!s)return;const n=new URLSearchParams(r.location.search);n.set(s,e),r.replace({...r.location,search:n.toString()})}),[s,r])]}function g(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,s=h(e),[i,o]=(0,a.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const a=t.find((e=>e.default))??t[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:n,tabValues:s}))),[d,u]=f({queryString:t,groupId:r}),[g,m]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,s]=(0,c.Nk)(t);return[r,(0,a.useCallback)((e=>{t&&s.set(e)}),[t,s])]}({groupId:r}),b=(()=>{const e=d??g;return p({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{b&&o(b)}),[b]);return{selectedValue:i,selectValue:(0,a.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),m(e)}),[u,m,s]),tabValues:s}}var m=t(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=t(5893);function j(e){let{className:n,block:t,selectedValue:a,selectValue:i,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),c=e=>{const n=e.currentTarget,t=o.indexOf(n),r=l[t].value;r!==a&&(d(n),i(r))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":t},n),children:l.map((e=>{let{value:n,label:t,attributes:s}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:a===n?0:-1,"aria-selected":a===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...s,className:(0,r.Z)("tabs__item",b.tabItem,s?.className,{"tabs__item--active":a===n}),children:t??n},n)}))})}function y(e){let{lazy:n,children:t,selectedValue:r}=e;const s=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=s.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:s.map(((e,n)=>(0,a.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function v(e){const n=g(e);return(0,x.jsxs)("div",{className:(0,r.Z)("tabs-container",b.tabList),children:[(0,x.jsx)(j,{...e,...n}),(0,x.jsx)(y,{...e,...n})]})}function w(e){const n=(0,m.Z)();return(0,x.jsx)(v,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>l,a:()=>i});var a=t(7294);const r={},s=a.createContext(r);function i(e){const n=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),a.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/acb7d57c.a6d16426.js b/assets/js/acb7d57c.89f81365.js similarity index 96% rename from assets/js/acb7d57c.a6d16426.js rename to assets/js/acb7d57c.89f81365.js index b1c0d8b22..f6d36adaf 100644 --- a/assets/js/acb7d57c.a6d16426.js +++ b/assets/js/acb7d57c.89f81365.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1819],{7593:(t,e,n)=>{n.r(e),n.d(e,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=n(5893),o=n(1151);const i={title:"Intro",sidebar_position:1},r=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/01-intro.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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={},d=[];function u(t){const e={p:"p",...(0,o.a)(),...t.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(e.p,{children:"In this section you will find some common tips and tricks to ensure you don't hit any performance or security issues."}),"\n",(0,s.jsx)(e.p,{children:"Did we miss something? Let us know."})]})}function p(t={}){const{wrapper:e}={...(0,o.a)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(u,{...t})}):u(t)}},1151:(t,e,n)=>{n.d(e,{Z:()=>c,a:()=>r});var s=n(7294);const o={},i=s.createContext(o);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1819],{7593:(t,e,n)=>{n.r(e),n.d(e,{assets:()=>a,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>d});var s=n(5893),o=n(1151);const i={title:"Intro",sidebar_position:1},r=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/01-intro.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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={},d=[];function u(t){const e={p:"p",...(0,o.a)(),...t.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(e.p,{children:"In this section you will find some common tips and tricks to ensure you don't hit any performance or security issues."}),"\n",(0,s.jsx)(e.p,{children:"Did we miss something? Let us know."})]})}function p(t={}){const{wrapper:e}={...(0,o.a)(),...t.components};return e?(0,s.jsx)(e,{...t,children:(0,s.jsx)(u,{...t})}):u(t)}},1151:(t,e,n)=>{n.d(e,{Z:()=>c,a:()=>r});var s=n(7294);const o={},i=s.createContext(o);function r(t){const e=s.useContext(i);return s.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:r(t.components),s.createElement(i.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/ace0032f.98acff1b.js b/assets/js/ace0032f.eedb453d.js similarity index 96% rename from assets/js/ace0032f.98acff1b.js rename to assets/js/ace0032f.eedb453d.js index 3a5b2ccc6..e5fc5ecb2 100644 --- a/assets/js/ace0032f.98acff1b.js +++ b/assets/js/ace0032f.eedb453d.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2521],{2114:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>a,toc:()=>d});var n=s(5893),r=s(1151);const o={title:"Serverless Stack"},i=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/serverless-stack.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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={},d=[];function l(e){const t={admonition:"admonition",p:"p",...(0,r.a)(),...e.components};return(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})})}function u(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(e)}},1151:(e,t,s)=>{s.d(t,{Z:()=>a,a:()=>i});var n=s(7294);const r={},o=n.createContext(r);function i(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2521],{2114:(e,t,s)=>{s.r(t),s.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>u,frontMatter:()=>o,metadata:()=>a,toc:()=>d});var n=s(5893),r=s(1151);const o={title:"Serverless Stack"},i=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/serverless-stack.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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={},d=[];function l(e){const t={admonition:"admonition",p:"p",...(0,r.a)(),...e.components};return(0,n.jsx)(t.admonition,{type:"caution",children:(0,n.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})})}function u(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(e)}},1151:(e,t,s)=>{s.d(t,{Z:()=>a,a:()=>i});var n=s(7294);const r={},o=n.createContext(r);function i(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/ad1e712e.e1378430.js b/assets/js/ad1e712e.9b577a5c.js similarity index 99% rename from assets/js/ad1e712e.e1378430.js rename to assets/js/ad1e712e.9b577a5c.js index 970bc65e2..7791bcca0 100644 --- a/assets/js/ad1e712e.e1378430.js +++ b/assets/js/ad1e712e.9b577a5c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9235],{9869:(e,s,r)=>{r.r(s),r.d(s,{assets:()=>o,contentTitle:()=>d,default:()=>h,frontMatter:()=>t,metadata:()=>a,toc:()=>c});var n=r(5893),i=r(1151);const t={title:"Official middlewares",sidebar_position:0},d=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/00-intro.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},o={},c=[{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}];function l(e){const s={a:"a",code:"code",h2:"h2",li:"li",p:"p",ul:"ul",...(0,i.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.p,{children:"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."}),"\n",(0,n.jsx)(s.p,{children:"These middleware focus on common use cases when using Lambda with other AWS services."}),"\n",(0,n.jsx)(s.p,{children:"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."}),"\n",(0,n.jsx)(s.h2,{id:"misc",children:"Misc"}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/cloudwatch-metrics",children:(0,n.jsx)(s.code,{children:"cloudwatch-metrics"})}),": Hydrates lambda's ",(0,n.jsx)(s.code,{children:"context.metrics"})," property with an instance of AWS MetricLogger"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/do-not-wait-for-empty-event-loop",children:(0,n.jsx)(s.code,{children:"do-not-wait-for-empty-event-loop"})}),": Sets callbackWaitsForEmptyEventLoop property to false"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/error-logger",children:(0,n.jsx)(s.code,{children:"error-logger"})}),": Logs errors"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/input-output-logger",children:(0,n.jsx)(s.code,{children:"input-output-logger"})}),": Logs request and response"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/warmup",children:(0,n.jsx)(s.code,{children:"warmup"})}),": Used to pre-warm a lambda function"]}),"\n"]}),"\n",(0,n.jsx)(s.h2,{id:"request-transformation",children:"Request Transformation"}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/event-normalizer",children:(0,n.jsx)(s.code,{children:"event-normalizer"})}),": Middleware for iterating through an AWS event records, parsing and normalizing nested events."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-content-negotiation",children:(0,n.jsx)(s.code,{children:"http-content-negotiation"})}),": Parses ",(0,n.jsx)(s.code,{children:"Accept-*"})," headers and provides utilities for content negotiation (charset, encoding, language and media type) for HTTP requests"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-event-normalizer",children:(0,n.jsx)(s.code,{children:"http-event-normalizer"})}),": Normalizes HTTP events by adding an empty object for ",(0,n.jsx)(s.code,{children:"queryStringParameters"}),", ",(0,n.jsx)(s.code,{children:"multiValueQueryStringParameters"})," or ",(0,n.jsx)(s.code,{children:"pathParameters"})," if they are missing."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-header-normalizer",children:(0,n.jsx)(s.code,{children:"http-header-normalizer"})}),": Normalizes HTTP header names to their canonical format"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-json-body-parser",children:(0,n.jsx)(s.code,{children:"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.jsx)(s.code,{children:"httpErrorHandler"}),"."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-multipart-body-parser",children:(0,n.jsx)(s.code,{children:"http-multipart-body-parser"})}),": Automatically parses HTTP requests with content type ",(0,n.jsx)(s.code,{children:"multipart/form-data"})," and converts the body into an object."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-urlencode-body-parser",children:(0,n.jsx)(s.code,{children:"http-urlencode-body-parser"})}),": Automatically parses HTTP requests with URL encoded body (typically the result of a form submit)."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-urlencode-path-parser",children:(0,n.jsx)(s.code,{children:"http-urlencode-path-parser"})}),": Automatically parses HTTP requests with URL encoded path."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/validator",children:(0,n.jsx)(s.code,{children:"validator"})}),": Automatically validates incoming events and outgoing responses against custom schemas."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/ws-json-body-parser",children:(0,n.jsx)(s.code,{children:"ws-json-body-parser"})}),": Automatically parses WebSocket requests with JSON message and converts the message into an object."]}),"\n"]}),"\n",(0,n.jsx)(s.h2,{id:"response-transformation",children:"Response Transformation"}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-content-encoding",children:(0,n.jsx)(s.code,{children:"http-content-encoding"})}),": Sets HTTP Content-Encoding header on response and compresses response body"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-cors",children:(0,n.jsx)(s.code,{children:"http-cors"})}),": Sets HTTP CORS headers on response"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-error-handler",children:(0,n.jsx)(s.code,{children:"http-error-handler"})}),": Creates a proper HTTP response for errors that are created with the ",(0,n.jsx)(s.a,{href:"https://www.npmjs.com/package/http-errors",children:"http-errors"})," module and represents proper HTTP errors."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-security-headers",children:(0,n.jsx)(s.code,{children:"http-security-headers"})}),": Applies best practice security headers to responses. It's a simplified port of HelmetJS."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-partial-response",children:(0,n.jsx)(s.code,{children:"http-partial-response"})}),": Filter response objects attributes based on query string parameters."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-response-serializer",children:(0,n.jsx)(s.code,{children:"http-response-serializer"})}),": HTTP response serializer."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/sqs-partial-batch-failure",children:(0,n.jsx)(s.code,{children:"sqs-partial-batch-failure"})}),": Handles partially failed SQS batches."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/ws-response",children:(0,n.jsx)(s.code,{children:"ws-response"})}),": Forwards response to WebSocket endpoint."]}),"\n"]}),"\n",(0,n.jsx)(s.h2,{id:"fetch-data",children:"Fetch Data"}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/appconfig",children:(0,n.jsx)(s.code,{children:"appconfig"})}),": Fetch JSON configurations from AppConfig."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/dynamodb",children:(0,n.jsx)(s.code,{children:"dynamodb"})}),": Fetch configurations from DynamoDB."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/rds-signer",children:(0,n.jsx)(s.code,{children:"rds-signer"})}),": Fetches token for connecting to RDS with IAM users."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/s3",children:(0,n.jsx)(s.code,{children:"s3"})}),": Fetch JSON configurations from S3."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/s3-object-response",children:(0,n.jsx)(s.code,{children:"s3-object-response"})}),": Gets and write S3 object response."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/secrets-manager",children:(0,n.jsx)(s.code,{children:"secrets-manager"})}),": Fetches parameters from ",(0,n.jsx)(s.a,{href:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html",children:"AWS Secrets Manager"}),"."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/service-discovery",children:(0,n.jsx)(s.code,{children:"service-discovery"})}),": Fetches Service Discovery instances to be used when connecting to other AWS services."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/ssm",children:(0,n.jsx)(s.code,{children:"ssm"})}),": Fetches parameters from ",(0,n.jsx)(s.a,{href:"https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html",children:"AWS Systems Manager Parameter Store"}),"."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/sts",children:(0,n.jsx)(s.code,{children:"sts"})}),": Fetches credentials to assumes IAM roles for connection to other AWS services."]}),"\n"]})]})}function h(e={}){const{wrapper:s}={...(0,i.a)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.jsx)(l,{...e})}):l(e)}},1151:(e,s,r)=>{r.d(s,{Z:()=>a,a:()=>d});var n=r(7294);const i={},t=n.createContext(i);function d(e){const s=n.useContext(t);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function a(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:d(e.components),n.createElement(t.Provider,{value:s},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9235],{9869:(e,s,r)=>{r.r(s),r.d(s,{assets:()=>o,contentTitle:()=>d,default:()=>h,frontMatter:()=>t,metadata:()=>a,toc:()=>c});var n=r(5893),i=r(1151);const t={title:"Official middlewares",sidebar_position:0},d=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/00-intro.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},o={},c=[{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}];function l(e){const s={a:"a",code:"code",h2:"h2",li:"li",p:"p",ul:"ul",...(0,i.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.p,{children:"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."}),"\n",(0,n.jsx)(s.p,{children:"These middleware focus on common use cases when using Lambda with other AWS services."}),"\n",(0,n.jsx)(s.p,{children:"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."}),"\n",(0,n.jsx)(s.h2,{id:"misc",children:"Misc"}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/cloudwatch-metrics",children:(0,n.jsx)(s.code,{children:"cloudwatch-metrics"})}),": Hydrates lambda's ",(0,n.jsx)(s.code,{children:"context.metrics"})," property with an instance of AWS MetricLogger"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/do-not-wait-for-empty-event-loop",children:(0,n.jsx)(s.code,{children:"do-not-wait-for-empty-event-loop"})}),": Sets callbackWaitsForEmptyEventLoop property to false"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/error-logger",children:(0,n.jsx)(s.code,{children:"error-logger"})}),": Logs errors"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/input-output-logger",children:(0,n.jsx)(s.code,{children:"input-output-logger"})}),": Logs request and response"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/warmup",children:(0,n.jsx)(s.code,{children:"warmup"})}),": Used to pre-warm a lambda function"]}),"\n"]}),"\n",(0,n.jsx)(s.h2,{id:"request-transformation",children:"Request Transformation"}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/event-normalizer",children:(0,n.jsx)(s.code,{children:"event-normalizer"})}),": Middleware for iterating through an AWS event records, parsing and normalizing nested events."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-content-negotiation",children:(0,n.jsx)(s.code,{children:"http-content-negotiation"})}),": Parses ",(0,n.jsx)(s.code,{children:"Accept-*"})," headers and provides utilities for content negotiation (charset, encoding, language and media type) for HTTP requests"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-event-normalizer",children:(0,n.jsx)(s.code,{children:"http-event-normalizer"})}),": Normalizes HTTP events by adding an empty object for ",(0,n.jsx)(s.code,{children:"queryStringParameters"}),", ",(0,n.jsx)(s.code,{children:"multiValueQueryStringParameters"})," or ",(0,n.jsx)(s.code,{children:"pathParameters"})," if they are missing."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-header-normalizer",children:(0,n.jsx)(s.code,{children:"http-header-normalizer"})}),": Normalizes HTTP header names to their canonical format"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-json-body-parser",children:(0,n.jsx)(s.code,{children:"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.jsx)(s.code,{children:"httpErrorHandler"}),"."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-multipart-body-parser",children:(0,n.jsx)(s.code,{children:"http-multipart-body-parser"})}),": Automatically parses HTTP requests with content type ",(0,n.jsx)(s.code,{children:"multipart/form-data"})," and converts the body into an object."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-urlencode-body-parser",children:(0,n.jsx)(s.code,{children:"http-urlencode-body-parser"})}),": Automatically parses HTTP requests with URL encoded body (typically the result of a form submit)."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-urlencode-path-parser",children:(0,n.jsx)(s.code,{children:"http-urlencode-path-parser"})}),": Automatically parses HTTP requests with URL encoded path."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/validator",children:(0,n.jsx)(s.code,{children:"validator"})}),": Automatically validates incoming events and outgoing responses against custom schemas."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/ws-json-body-parser",children:(0,n.jsx)(s.code,{children:"ws-json-body-parser"})}),": Automatically parses WebSocket requests with JSON message and converts the message into an object."]}),"\n"]}),"\n",(0,n.jsx)(s.h2,{id:"response-transformation",children:"Response Transformation"}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-content-encoding",children:(0,n.jsx)(s.code,{children:"http-content-encoding"})}),": Sets HTTP Content-Encoding header on response and compresses response body"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-cors",children:(0,n.jsx)(s.code,{children:"http-cors"})}),": Sets HTTP CORS headers on response"]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-error-handler",children:(0,n.jsx)(s.code,{children:"http-error-handler"})}),": Creates a proper HTTP response for errors that are created with the ",(0,n.jsx)(s.a,{href:"https://www.npmjs.com/package/http-errors",children:"http-errors"})," module and represents proper HTTP errors."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-security-headers",children:(0,n.jsx)(s.code,{children:"http-security-headers"})}),": Applies best practice security headers to responses. It's a simplified port of HelmetJS."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-partial-response",children:(0,n.jsx)(s.code,{children:"http-partial-response"})}),": Filter response objects attributes based on query string parameters."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/http-response-serializer",children:(0,n.jsx)(s.code,{children:"http-response-serializer"})}),": HTTP response serializer."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/sqs-partial-batch-failure",children:(0,n.jsx)(s.code,{children:"sqs-partial-batch-failure"})}),": Handles partially failed SQS batches."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/ws-response",children:(0,n.jsx)(s.code,{children:"ws-response"})}),": Forwards response to WebSocket endpoint."]}),"\n"]}),"\n",(0,n.jsx)(s.h2,{id:"fetch-data",children:"Fetch Data"}),"\n",(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/appconfig",children:(0,n.jsx)(s.code,{children:"appconfig"})}),": Fetch JSON configurations from AppConfig."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/dynamodb",children:(0,n.jsx)(s.code,{children:"dynamodb"})}),": Fetch configurations from DynamoDB."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/rds-signer",children:(0,n.jsx)(s.code,{children:"rds-signer"})}),": Fetches token for connecting to RDS with IAM users."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/s3",children:(0,n.jsx)(s.code,{children:"s3"})}),": Fetch JSON configurations from S3."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/s3-object-response",children:(0,n.jsx)(s.code,{children:"s3-object-response"})}),": Gets and write S3 object response."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/secrets-manager",children:(0,n.jsx)(s.code,{children:"secrets-manager"})}),": Fetches parameters from ",(0,n.jsx)(s.a,{href:"https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html",children:"AWS Secrets Manager"}),"."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/service-discovery",children:(0,n.jsx)(s.code,{children:"service-discovery"})}),": Fetches Service Discovery instances to be used when connecting to other AWS services."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/ssm",children:(0,n.jsx)(s.code,{children:"ssm"})}),": Fetches parameters from ",(0,n.jsx)(s.a,{href:"https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html",children:"AWS Systems Manager Parameter Store"}),"."]}),"\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.a,{href:"/docs/middlewares/sts",children:(0,n.jsx)(s.code,{children:"sts"})}),": Fetches credentials to assumes IAM roles for connection to other AWS services."]}),"\n"]})]})}function h(e={}){const{wrapper:s}={...(0,i.a)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.jsx)(l,{...e})}):l(e)}},1151:(e,s,r)=>{r.d(s,{Z:()=>a,a:()=>d});var n=r(7294);const i={},t=n.createContext(i);function d(e){const s=n.useContext(t);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function a(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:d(e.components),n.createElement(t.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/aecdbf7e.bfba9e83.js b/assets/js/aecdbf7e.29d4d573.js similarity index 99% rename from assets/js/aecdbf7e.bfba9e83.js rename to assets/js/aecdbf7e.29d4d573.js index 6bc4b2a30..9113d34a2 100644 --- a/assets/js/aecdbf7e.bfba9e83.js +++ b/assets/js/aecdbf7e.29d4d573.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1073],{9232:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>h,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var r=n(5893),a=n(1151),s=n(4866),l=n(5162);const i={title:"cloudwatch-metrics"},o=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/cloudwatch-metrics.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function m(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["This middleware hydrates lambda's ",(0,r.jsx)(t.code,{children:"context.metrics"})," property with an instance of ",(0,r.jsx)(t.a,{href:"https://github.com/awslabs/aws-embedded-metrics-node#metriclogger",children:"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."]}),"\n",(0,r.jsxs)(t.p,{children:["Metrics collected with this logger are then available for querying within ",(0,r.jsx)(t.a,{href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html",children:"AWS CloudWatch Log Insights"})]}),"\n",(0,r.jsxs)(t.p,{children:["You can explore all the MetricLogger APIs following ",(0,r.jsx)(t.a,{href:"https://github.com/awslabs/aws-embedded-metrics-node",children:"aws-embedded-metrics"})," documentation."]}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(l.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/cloudwatch-metrics\n"})})}),(0,r.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/cloudwatch-metrics\n"})})}),(0,r.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/cloudwatch-metrics\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"namespace"})," (",(0,r.jsx)(t.code,{children:"string"}),") (optional): Defaults to ",(0,r.jsx)(t.code,{children:"aws-embedded-metrics"}),". Sets the CloudWatch ",(0,r.jsx)(t.a,{href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace",children:"namespace"})," that extracted metrics should be published to."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"dimensions"})," (",(0,r.jsx)(t.code,{children:"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,r.jsx)(t.a,{href:"https://github.com/awslabs/aws-embedded-metrics-node/tree/v4.1.0#configuration",children:"aws-embedded-metrics docs"}),"."]}),"\n"]}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"const middy = require('@middy/core')\nconst cloudwatchMetrics = require('@middy/cloudwatch-metrics')\n\nconst lambdaHandler = (event, context) => {\n context.metrics.putMetric('ProcessingLatency', 100, 'Milliseconds')\n context.metrics.setProperty(\n 'RequestId',\n '422b1569-16f6-4a03-b8f0-fe3fd9b100f8'\n )\n}\nexport const handler = middy()\n .use(\n cloudwatchMetrics({\n namespace: 'myAppliction',\n dimensions: [{ Action: 'Buy' }]\n })\n )\n .handler(lambdaHandler)\n"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>l});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function l(e){let{children:t,hidden:n,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,l),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>j});var r=n(7294),a=n(6010),s=n(2466),l=n(6550),i=n(469),o=n(1980),c=n(7392),d=n(12);function u(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(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 h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function p(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.k6)(),s=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)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=m(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(!h({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:s}))),[c,u]=p({queryString:n,groupId:a}),[b,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,d.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),g=(()=>{const e=c??b;return h({value:e,tabValues:s})?e:null})();(0,i.Z)((()=>{g&&o(g)}),[g]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),f(e)}),[u,f,s]),tabValues:s}}var f=n(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var w=n(5893);function v(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.o5)(),d=e=>{const t=e.currentTarget,n=o.indexOf(t),a=i[n].value;a!==r&&(c(t),l(a))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=o.indexOf(e.currentTarget)+1;t=o[n]??o[0];break}case"ArrowLeft":{const n=o.indexOf(e.currentTarget)-1;t=o[n]??o[o.length-1];break}}t?.focus()};return(0,w.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,w.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>o.push(e),onKeyDown:u,onClick:d,...s,className:(0,a.Z)("tabs__item",g.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,w.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=b(e);return(0,w.jsxs)("div",{className:(0,a.Z)("tabs-container",g.tabList),children:[(0,w.jsx)(v,{...e,...t}),(0,w.jsx)(x,{...e,...t})]})}function j(e){const t=(0,f.Z)();return(0,w.jsx)(y,{...e,children:u(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>i,a:()=>l});var r=n(7294);const a={},s=r.createContext(a);function l(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1073],{9232:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>h,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var r=n(5893),a=n(1151),s=n(4866),l=n(5162);const i={title:"cloudwatch-metrics"},o=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/cloudwatch-metrics.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function m(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["This middleware hydrates lambda's ",(0,r.jsx)(t.code,{children:"context.metrics"})," property with an instance of ",(0,r.jsx)(t.a,{href:"https://github.com/awslabs/aws-embedded-metrics-node#metriclogger",children:"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."]}),"\n",(0,r.jsxs)(t.p,{children:["Metrics collected with this logger are then available for querying within ",(0,r.jsx)(t.a,{href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html",children:"AWS CloudWatch Log Insights"})]}),"\n",(0,r.jsxs)(t.p,{children:["You can explore all the MetricLogger APIs following ",(0,r.jsx)(t.a,{href:"https://github.com/awslabs/aws-embedded-metrics-node",children:"aws-embedded-metrics"})," documentation."]}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(l.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/cloudwatch-metrics\n"})})}),(0,r.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/cloudwatch-metrics\n"})})}),(0,r.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/cloudwatch-metrics\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"namespace"})," (",(0,r.jsx)(t.code,{children:"string"}),") (optional): Defaults to ",(0,r.jsx)(t.code,{children:"aws-embedded-metrics"}),". Sets the CloudWatch ",(0,r.jsx)(t.a,{href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace",children:"namespace"})," that extracted metrics should be published to."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"dimensions"})," (",(0,r.jsx)(t.code,{children:"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,r.jsx)(t.a,{href:"https://github.com/awslabs/aws-embedded-metrics-node/tree/v4.1.0#configuration",children:"aws-embedded-metrics docs"}),"."]}),"\n"]}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"const middy = require('@middy/core')\nconst cloudwatchMetrics = require('@middy/cloudwatch-metrics')\n\nconst lambdaHandler = (event, context) => {\n context.metrics.putMetric('ProcessingLatency', 100, 'Milliseconds')\n context.metrics.setProperty(\n 'RequestId',\n '422b1569-16f6-4a03-b8f0-fe3fd9b100f8'\n )\n}\nexport const handler = middy()\n .use(\n cloudwatchMetrics({\n namespace: 'myAppliction',\n dimensions: [{ Action: 'Buy' }]\n })\n )\n .handler(lambdaHandler)\n"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>l});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function l(e){let{children:t,hidden:n,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,l),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>j});var r=n(7294),a=n(6010),s=n(2466),l=n(6550),i=n(469),o=n(1980),c=n(7392),d=n(12);function u(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(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 h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function p(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.k6)(),s=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)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=m(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(!h({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:s}))),[c,u]=p({queryString:n,groupId:a}),[b,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,d.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),g=(()=>{const e=c??b;return h({value:e,tabValues:s})?e:null})();(0,i.Z)((()=>{g&&o(g)}),[g]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),f(e)}),[u,f,s]),tabValues:s}}var f=n(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var w=n(5893);function v(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.o5)(),d=e=>{const t=e.currentTarget,n=o.indexOf(t),a=i[n].value;a!==r&&(c(t),l(a))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=o.indexOf(e.currentTarget)+1;t=o[n]??o[0];break}case"ArrowLeft":{const n=o.indexOf(e.currentTarget)-1;t=o[n]??o[o.length-1];break}}t?.focus()};return(0,w.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,w.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>o.push(e),onKeyDown:u,onClick:d,...s,className:(0,a.Z)("tabs__item",g.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,w.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=b(e);return(0,w.jsxs)("div",{className:(0,a.Z)("tabs-container",g.tabList),children:[(0,w.jsx)(v,{...e,...t}),(0,w.jsx)(x,{...e,...t})]})}function j(e){const t=(0,f.Z)();return(0,w.jsx)(y,{...e,children:u(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>i,a:()=>l});var r=n(7294);const a={},s=r.createContext(a);function l(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/b3edb814.faade522.js b/assets/js/b3edb814.a53bff2c.js similarity index 99% rename from assets/js/b3edb814.faade522.js rename to assets/js/b3edb814.a53bff2c.js index d481ff46c..cb71c11af 100644 --- a/assets/js/b3edb814.faade522.js +++ b/assets/js/b3edb814.a53bff2c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3786],{7963:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var s=t(5893),r=t(1151),a=t(4866),l=t(5162);const i={title:"sts"},o=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/sts.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"sts"},sidebar:"tutorialSidebar",previous:{title:"ssm",permalink:"/docs/middlewares/ssm"},next:{title:"validator",permalink:"/docs/middlewares/validator"}},d={},u=[{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}];function h(e){const n={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Fetches STS credentials to be used when connecting to other AWS services."}),"\n",(0,s.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(l.Z,{value:"npm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/sts\nnpm install --save-dev @aws-sdk/client-sts\n"})})}),(0,s.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/sts\nyarn add --dev @aws-sdk/client-sts\n"})})}),(0,s.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/sts\npnpm add --save-dev @aws-sdk/client-sts\n"})})})]}),"\n",(0,s.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(n.code,{children:"STSClient"}),"): STSClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-sts"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientOptions"})," (object) (optional): Options to pass to STSClient class constructor."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientCapture"})," (function) (optional): Enable XRay by passing ",(0,s.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,s.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameters."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheKey"})," (string) (default ",(0,s.jsx)(n.code,{children:"sts"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheExpiry"})," (number) (default ",(0,s.jsx)(n.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,s.jsx)(n.code,{children:"-1"}),": cache forever, ",(0,s.jsx)(n.code,{children:"0"}),": never cache, ",(0,s.jsx)(n.code,{children:"n"}),": cache for n ms."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"setToContext"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): Store credentials to ",(0,s.jsx)(n.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(n.code,{children:"sts:AssumeRole"})]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"setToContext"})," are included for legacy support and should be avoided for performance and security reasons. See main documentation for best practices."]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport sts from '@middy/sts'\n\nconst lambdaHandler = (event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n}\n\nexport const handler = middy()\n .use(\n sts({\n fetchData: {\n assumeRole: {\n RoleArn: '...',\n RoleSessionName: '' // optional\n }\n }\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(n.p,{children:["To exclude ",(0,s.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-sts"})," to the exclude list."]})]})}function p(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>l});t(7294);var s=t(6010);const r={tabItem:"tabItem_Ymn6"};var a=t(5893);function l(e){let{children:n,hidden:t,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.Z)(r.tabItem,l),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var s=t(7294),r=t(6010),a=t(2466),l=t(6550),i=t(469),o=t(1980),c=t(7392),d=t(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:t}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:s,default:r}}=e;return{value:n,label:t,attributes:s,default:r}}))}(t);return function(e){const n=(0,c.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function p(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function m(e){let{queryString:n=!1,groupId:t}=e;const r=(0,l.k6)(),a=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(a),(0,s.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(r.location.search);n.set(a,e),r.replace({...r.location,search:n.toString()})}),[a,r])]}function f(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,a=h(e),[l,o]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const s=t.find((e=>e.default))??t[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:a}))),[c,u]=m({queryString:t,groupId:r}),[f,b]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,a]=(0,d.Nk)(t);return[r,(0,s.useCallback)((e=>{t&&a.set(e)}),[t,a])]}({groupId:r}),x=(()=>{const e=c??f;return p({value:e,tabValues:a})?e:null})();(0,i.Z)((()=>{x&&o(x)}),[x]);return{selectedValue:l,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,a]),tabValues:a}}var b=t(2389);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=t(5893);function j(e){let{className:n,block:t,selectedValue:s,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.o5)(),d=e=>{const n=e.currentTarget,t=o.indexOf(n),r=i[t].value;r!==s&&(c(n),l(r))},u=e=>{let n=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":t},n),children:i.map((e=>{let{value:n,label:t,attributes:a}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>o.push(e),onKeyDown:u,onClick:d,...a,className:(0,r.Z)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":s===n}),children:t??n},n)}))})}function g(e){let{lazy:n,children:t,selectedValue:r}=e;const a=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===r));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function y(e){const n=f(e);return(0,v.jsxs)("div",{className:(0,r.Z)("tabs-container",x.tabList),children:[(0,v.jsx)(j,{...e,...n}),(0,v.jsx)(g,{...e,...n})]})}function w(e){const n=(0,b.Z)();return(0,v.jsx)(y,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>l});var s=t(7294);const r={},a=s.createContext(r);function l(e){const n=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:l(e.components),s.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3786],{7963:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var s=t(5893),r=t(1151),a=t(4866),l=t(5162);const i={title:"sts"},o=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/sts.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"sts"},sidebar:"tutorialSidebar",previous:{title:"ssm",permalink:"/docs/middlewares/ssm"},next:{title:"validator",permalink:"/docs/middlewares/validator"}},d={},u=[{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}];function h(e){const n={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Fetches STS credentials to be used when connecting to other AWS services."}),"\n",(0,s.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,s.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,s.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,s.jsx)(l.Z,{value:"npm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/sts\nnpm install --save-dev @aws-sdk/client-sts\n"})})}),(0,s.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/sts\nyarn add --dev @aws-sdk/client-sts\n"})})}),(0,s.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/sts\npnpm add --save-dev @aws-sdk/client-sts\n"})})})]}),"\n",(0,s.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"AwsClient"})," (object) (default ",(0,s.jsx)(n.code,{children:"STSClient"}),"): STSClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-sts"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientOptions"})," (object) (optional): Options to pass to STSClient class constructor."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"awsClientCapture"})," (function) (optional): Enable XRay by passing ",(0,s.jsx)(n.code,{children:"captureAWSv3Client"})," from ",(0,s.jsx)(n.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameters."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"disablePrefetch"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,s.jsx)(n.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheKey"})," (string) (default ",(0,s.jsx)(n.code,{children:"sts"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"cacheExpiry"})," (number) (default ",(0,s.jsx)(n.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,s.jsx)(n.code,{children:"-1"}),": cache forever, ",(0,s.jsx)(n.code,{children:"0"}),": never cache, ",(0,s.jsx)(n.code,{children:"n"}),": cache for n ms."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"setToContext"})," (boolean) (default ",(0,s.jsx)(n.code,{children:"false"}),"): Store credentials to ",(0,s.jsx)(n.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"NOTES:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["Lambda is required to have IAM permission for ",(0,s.jsx)(n.code,{children:"sts:AssumeRole"})]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:"setToContext"})," are included for legacy support and should be avoided for performance and security reasons. See main documentation for best practices."]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport sts from '@middy/sts'\n\nconst lambdaHandler = (event, context) => {\n const response = {\n statusCode: 200,\n headers: {},\n body: JSON.stringify({ message: 'hello world' })\n }\n\n return response\n}\n\nexport const handler = middy()\n .use(\n sts({\n fetchData: {\n assumeRole: {\n RoleArn: '...',\n RoleSessionName: '' // optional\n }\n }\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"bundling",children:"Bundling"}),"\n",(0,s.jsxs)(n.p,{children:["To exclude ",(0,s.jsx)(n.code,{children:"@aws-sdk"})," add ",(0,s.jsx)(n.code,{children:"@aws-sdk/client-sts"})," to the exclude list."]})]})}function p(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>l});t(7294);var s=t(6010);const r={tabItem:"tabItem_Ymn6"};var a=t(5893);function l(e){let{children:n,hidden:t,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,s.Z)(r.tabItem,l),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var s=t(7294),r=t(6010),a=t(2466),l=t(6550),i=t(469),o=t(1980),c=t(7392),d=t(12);function u(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:t}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:s,default:r}}=e;return{value:n,label:t,attributes:s,default:r}}))}(t);return function(e){const n=(0,c.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function p(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function m(e){let{queryString:n=!1,groupId:t}=e;const r=(0,l.k6)(),a=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(a),(0,s.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(r.location.search);n.set(a,e),r.replace({...r.location,search:n.toString()})}),[a,r])]}function f(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,a=h(e),[l,o]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const s=t.find((e=>e.default))??t[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:a}))),[c,u]=m({queryString:t,groupId:r}),[f,b]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,a]=(0,d.Nk)(t);return[r,(0,s.useCallback)((e=>{t&&a.set(e)}),[t,a])]}({groupId:r}),x=(()=>{const e=c??f;return p({value:e,tabValues:a})?e:null})();(0,i.Z)((()=>{x&&o(x)}),[x]);return{selectedValue:l,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,a]),tabValues:a}}var b=t(2389);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=t(5893);function j(e){let{className:n,block:t,selectedValue:s,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.o5)(),d=e=>{const n=e.currentTarget,t=o.indexOf(n),r=i[t].value;r!==s&&(c(n),l(r))},u=e=>{let n=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":t},n),children:i.map((e=>{let{value:n,label:t,attributes:a}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>o.push(e),onKeyDown:u,onClick:d,...a,className:(0,r.Z)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":s===n}),children:t??n},n)}))})}function g(e){let{lazy:n,children:t,selectedValue:r}=e;const a=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===r));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function y(e){const n=f(e);return(0,v.jsxs)("div",{className:(0,r.Z)("tabs-container",x.tabList),children:[(0,v.jsx)(j,{...e,...n}),(0,v.jsx)(g,{...e,...n})]})}function w(e){const n=(0,b.Z)();return(0,v.jsx)(y,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>l});var s=t(7294);const r={},a=s.createContext(r);function l(e){const n=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:l(e.components),s.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/b5163cd3.646f42cd.js b/assets/js/b5163cd3.f745c9fb.js similarity index 96% rename from assets/js/b5163cd3.646f42cd.js rename to assets/js/b5163cd3.f745c9fb.js index 7023f54d5..669902920 100644 --- a/assets/js/b5163cd3.646f42cd.js +++ b/assets/js/b5163cd3.f745c9fb.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4751],{9539:(t,e,n)=>{n.r(e),n.d(e,{assets:()=>c,contentTitle:()=>s,default:()=>u,frontMatter:()=>r,metadata:()=>a,toc:()=>d});var i=n(5893),o=n(1151);const r={title:"Integrations",position:1},s=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/01-intro.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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={},d=[];function p(t){const e={admonition:"admonition",p:"p",...(0,o.a)(),...t.components};return(0,i.jsx)(e.admonition,{type:"caution",children:(0,i.jsx)(e.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})})}function u(t={}){const{wrapper:e}={...(0,o.a)(),...t.components};return e?(0,i.jsx)(e,{...t,children:(0,i.jsx)(p,{...t})}):p(t)}},1151:(t,e,n)=>{n.d(e,{Z:()=>a,a:()=>s});var i=n(7294);const o={},r=i.createContext(o);function s(t){const e=i.useContext(r);return i.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function a(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:s(t.components),i.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4751],{9539:(t,e,n)=>{n.r(e),n.d(e,{assets:()=>c,contentTitle:()=>s,default:()=>u,frontMatter:()=>r,metadata:()=>a,toc:()=>d});var i=n(5893),o=n(1151);const r={title:"Integrations",position:1},s=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/01-intro.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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={},d=[];function p(t){const e={admonition:"admonition",p:"p",...(0,o.a)(),...t.components};return(0,i.jsx)(e.admonition,{type:"caution",children:(0,i.jsx)(e.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})})}function u(t={}){const{wrapper:e}={...(0,o.a)(),...t.components};return e?(0,i.jsx)(e,{...t,children:(0,i.jsx)(p,{...t})}):p(t)}},1151:(t,e,n)=>{n.d(e,{Z:()=>a,a:()=>s});var i=n(7294);const o={},r=i.createContext(o);function s(t){const e=i.useContext(r);return i.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function a(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:s(t.components),i.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/b5584809.8fa6684e.js b/assets/js/b5584809.484e13ec.js similarity index 96% rename from assets/js/b5584809.8fa6684e.js rename to assets/js/b5584809.484e13ec.js index fac80e30b..8c0a4ebd0 100644 --- a/assets/js/b5584809.8fa6684e.js +++ b/assets/js/b5584809.484e13ec.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2803],{8418:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>a,toc:()=>d});var s=r(5893),n=r(1151);const o={title:"Serverless Framework"},i=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/serverless-framework.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Serverless Framework"},sidebar:"tutorialSidebar",previous:{title:"Pino",permalink:"/docs/integrations/pino"},next:{title:"Serverless Stack",permalink:"/docs/integrations/serverless-stack"}},c={},d=[];function l(e){const t={admonition:"admonition",p:"p",...(0,n.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.p,{children:"TODO comment about serverless-warmup"})]})}function m(e={}){const{wrapper:t}={...(0,n.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>a,a:()=>i});var s=r(7294);const n={},o=s.createContext(n);function i(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:i(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2803],{8418:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>a,toc:()=>d});var s=r(5893),n=r(1151);const o={title:"Serverless Framework"},i=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/serverless-framework.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Serverless Framework"},sidebar:"tutorialSidebar",previous:{title:"Pino",permalink:"/docs/integrations/pino"},next:{title:"Serverless Stack",permalink:"/docs/integrations/serverless-stack"}},c={},d=[];function l(e){const t={admonition:"admonition",p:"p",...(0,n.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.p,{children:"TODO comment about serverless-warmup"})]})}function m(e={}){const{wrapper:t}={...(0,n.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>a,a:()=>i});var s=r(7294);const n={},o=s.createContext(n);function i(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:i(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/b5aee65c.86e1a1d5.js b/assets/js/b5aee65c.664aa256.js similarity index 98% rename from assets/js/b5aee65c.86e1a1d5.js rename to assets/js/b5aee65c.664aa256.js index f5f8d54a5..e5d2f58da 100644 --- a/assets/js/b5aee65c.86e1a1d5.js +++ b/assets/js/b5aee65c.664aa256.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4510],{8729:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>h,frontMatter:()=>s,metadata:()=>c,toc:()=>a});var r=n(5893),d=n(1151);const s={title:"Release Cycle"},i=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/09-release-cycle.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:9,frontMatter:{title:"Release Cycle"},sidebar:"tutorialSidebar",previous:{title:"Utilities",permalink:"/docs/intro/utilities"},next:{title:"Contributing",permalink:"/docs/intro/contributing"}},l={},a=[];function o(e){const t={code:"code",p:"p",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,d.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["Each major release has a two (2) month ",(0,r.jsx)(t.code,{children:"Alpha"})," period, one (1) month ",(0,r.jsx)(t.code,{children:"Beta"}),", before a full release and becomes ",(0,r.jsx)(t.code,{children:"Stable"}),".\nEach release goes into ",(0,r.jsx)(t.code,{children:"Maintenance"})," after nine (9) months, as the next release enters ",(0,r.jsx)(t.code,{children:"Alpha"}),".\nThis time period is chosen for alignment with AWS Lambda ",(0,r.jsx)(t.code,{children:"nodejs"})," runtime releases.\nAll Node.js Long-Term Support (LTS) releases that have AWS Lambda runtimes are supported."]}),"\n",(0,r.jsxs)(t.table,{children:[(0,r.jsx)(t.thead,{children:(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.th,{children:"Version"}),(0,r.jsx)(t.th,{children:"Status"}),(0,r.jsx)(t.th,{children:"Alpha Release"}),(0,r.jsx)(t.th,{children:"Stable Release"}),(0,r.jsx)(t.th,{children:"End-of-Life"})]})}),(0,r.jsxs)(t.tbody,{children:[(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v6"}),(0,r.jsx)(t.td,{children:"Scoping"}),(0,r.jsx)(t.td,{children:"2024-??-??"}),(0,r.jsx)(t.td,{children:"2024-10-29"}),(0,r.jsx)(t.td,{children:"2026-04-30"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v5"}),(0,r.jsx)(t.td,{children:"Stable"}),(0,r.jsx)(t.td,{children:"2023-06-01"}),(0,r.jsx)(t.td,{children:"2023-10-24"}),(0,r.jsx)(t.td,{children:"2025-04-30"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v4"}),(0,r.jsx)(t.td,{children:"Deprecated"}),(0,r.jsx)(t.td,{children:"2022-10-17"}),(0,r.jsx)(t.td,{children:"2022-11-24"}),(0,r.jsx)(t.td,{children:"2023-09-11"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v3"}),(0,r.jsx)(t.td,{children:"Deprecated"}),(0,r.jsx)(t.td,{children:"2022-01-04"}),(0,r.jsx)(t.td,{children:"2022-05-12"}),(0,r.jsx)(t.td,{children:"2022-12-31"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v2"}),(0,r.jsx)(t.td,{children:"Deprecated"}),(0,r.jsx)(t.td,{children:"2021-01-24"}),(0,r.jsx)(t.td,{children:"2021-04-01"}),(0,r.jsx)(t.td,{children:"2022-05-12"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v1"}),(0,r.jsx)(t.td,{children:"Deprecated"}),(0,r.jsx)(t.td,{children:"2018-05-20"}),(0,r.jsx)(t.td,{children:"2020-04-25"}),(0,r.jsx)(t.td,{children:"2021-04-01"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v0"}),(0,r.jsx)(t.td,{children:"Deprecated"}),(0,r.jsx)(t.td,{children:"2017-08-03"}),(0,r.jsx)(t.td,{children:"2017-09-04"}),(0,r.jsx)(t.td,{children:"2020-04-25"})]})]})]}),"\n",(0,r.jsx)(t.p,{children:"Dates are subject to change."}),"\n",(0,r.jsx)(t.p,{children:"If your organization requires a longer maintenance period of Middy, please reach out."})]})}function h(e={}){const{wrapper:t}={...(0,d.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(o,{...e})}):o(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>c,a:()=>i});var r=n(7294);const d={},s=r.createContext(d);function i(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(d):e.components||d:i(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4510],{8729:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>h,frontMatter:()=>s,metadata:()=>c,toc:()=>a});var r=n(5893),d=n(1151);const s={title:"Release Cycle"},i=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/09-release-cycle.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:9,frontMatter:{title:"Release Cycle"},sidebar:"tutorialSidebar",previous:{title:"Utilities",permalink:"/docs/intro/utilities"},next:{title:"Contributing",permalink:"/docs/intro/contributing"}},l={},a=[];function o(e){const t={code:"code",p:"p",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,d.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["Each major release has a two (2) month ",(0,r.jsx)(t.code,{children:"Alpha"})," period, one (1) month ",(0,r.jsx)(t.code,{children:"Beta"}),", before a full release and becomes ",(0,r.jsx)(t.code,{children:"Stable"}),".\nEach release goes into ",(0,r.jsx)(t.code,{children:"Maintenance"})," after nine (9) months, as the next release enters ",(0,r.jsx)(t.code,{children:"Alpha"}),".\nThis time period is chosen for alignment with AWS Lambda ",(0,r.jsx)(t.code,{children:"nodejs"})," runtime releases.\nAll Node.js Long-Term Support (LTS) releases that have AWS Lambda runtimes are supported."]}),"\n",(0,r.jsxs)(t.table,{children:[(0,r.jsx)(t.thead,{children:(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.th,{children:"Version"}),(0,r.jsx)(t.th,{children:"Status"}),(0,r.jsx)(t.th,{children:"Alpha Release"}),(0,r.jsx)(t.th,{children:"Stable Release"}),(0,r.jsx)(t.th,{children:"End-of-Life"})]})}),(0,r.jsxs)(t.tbody,{children:[(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v6"}),(0,r.jsx)(t.td,{children:"Scoping"}),(0,r.jsx)(t.td,{children:"2024-??-??"}),(0,r.jsx)(t.td,{children:"2024-10-29"}),(0,r.jsx)(t.td,{children:"2026-04-30"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v5"}),(0,r.jsx)(t.td,{children:"Stable"}),(0,r.jsx)(t.td,{children:"2023-06-01"}),(0,r.jsx)(t.td,{children:"2023-10-24"}),(0,r.jsx)(t.td,{children:"2025-04-30"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v4"}),(0,r.jsx)(t.td,{children:"Deprecated"}),(0,r.jsx)(t.td,{children:"2022-10-17"}),(0,r.jsx)(t.td,{children:"2022-11-24"}),(0,r.jsx)(t.td,{children:"2023-09-11"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v3"}),(0,r.jsx)(t.td,{children:"Deprecated"}),(0,r.jsx)(t.td,{children:"2022-01-04"}),(0,r.jsx)(t.td,{children:"2022-05-12"}),(0,r.jsx)(t.td,{children:"2022-12-31"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v2"}),(0,r.jsx)(t.td,{children:"Deprecated"}),(0,r.jsx)(t.td,{children:"2021-01-24"}),(0,r.jsx)(t.td,{children:"2021-04-01"}),(0,r.jsx)(t.td,{children:"2022-05-12"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v1"}),(0,r.jsx)(t.td,{children:"Deprecated"}),(0,r.jsx)(t.td,{children:"2018-05-20"}),(0,r.jsx)(t.td,{children:"2020-04-25"}),(0,r.jsx)(t.td,{children:"2021-04-01"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"v0"}),(0,r.jsx)(t.td,{children:"Deprecated"}),(0,r.jsx)(t.td,{children:"2017-08-03"}),(0,r.jsx)(t.td,{children:"2017-09-04"}),(0,r.jsx)(t.td,{children:"2020-04-25"})]})]})]}),"\n",(0,r.jsx)(t.p,{children:"Dates are subject to change."}),"\n",(0,r.jsx)(t.p,{children:"If your organization requires a longer maintenance period of Middy, please reach out."})]})}function h(e={}){const{wrapper:t}={...(0,d.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(o,{...e})}):o(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>c,a:()=>i});var r=n(7294);const d={},s=r.createContext(d);function i(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(d):e.components||d:i(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/b6105e9b.16794ff2.js b/assets/js/b6105e9b.40dd41d9.js similarity index 97% rename from assets/js/b6105e9b.16794ff2.js rename to assets/js/b6105e9b.40dd41d9.js index e0737c957..b1226132a 100644 --- a/assets/js/b6105e9b.16794ff2.js +++ b/assets/js/b6105e9b.40dd41d9.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8471],{530:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>d,default:()=>p,frontMatter:()=>s,metadata:()=>r,toc:()=>c});var i=n(5893),o=n(1151);const s={title:"CodePipeline"},d=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/code-pipeline.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"CodePipeline"},sidebar:"tutorialSidebar",previous:{title:"Code Commit",permalink:"/docs/events/code-commit"},next:{title:"Cognito",permalink:"/docs/events/cognito"}},a={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.admonition,{type:"caution",children:(0,i.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:(0,i.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-codepipeline.html",children:"Using AWS Lambda with AWS CodePipeline"})}),"\n"]}),"\n",(0,i.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function p(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>d});var i=n(7294);const o={},s=i.createContext(o);function d(e){const t=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:d(e.components),i.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8471],{530:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>d,default:()=>p,frontMatter:()=>s,metadata:()=>r,toc:()=>c});var i=n(5893),o=n(1151);const s={title:"CodePipeline"},d=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/code-pipeline.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"CodePipeline"},sidebar:"tutorialSidebar",previous:{title:"Code Commit",permalink:"/docs/events/code-commit"},next:{title:"Cognito",permalink:"/docs/events/cognito"}},a={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.admonition,{type:"caution",children:(0,i.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:(0,i.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-codepipeline.html",children:"Using AWS Lambda with AWS CodePipeline"})}),"\n"]}),"\n",(0,i.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function p(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>d});var i=n(7294);const o={},s=i.createContext(o);function d(e){const t=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:d(e.components),i.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/b6b85ed9.f56259e2.js b/assets/js/b6b85ed9.88f7e9a0.js similarity index 99% rename from assets/js/b6b85ed9.f56259e2.js rename to assets/js/b6b85ed9.88f7e9a0.js index 385dec887..4c4f820de 100644 --- a/assets/js/b6b85ed9.f56259e2.js +++ b/assets/js/b6b85ed9.88f7e9a0.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6476],{4670:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>d,toc:()=>u});var r=t(5893),o=t(1151),a=t(4866),s=t(5162);const i={title:"http-content-encoding"},l=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-content-encoding.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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={},u=[{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}];function h(e){const n={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.p,{children:["This middleware take the ",(0,r.jsx)(n.code,{children:"preferredEncoding"})," output from ",(0,r.jsx)(n.code,{children:"@middy/http-content-negotiation"})," and applies the encoding to ",(0,r.jsx)(n.code,{children:"response.body"})," when a string."]}),"\n",(0,r.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(s.Z,{value:"npm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/http-content-encoding\n"})})}),(0,r.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/http-content-encoding\n"})})}),(0,r.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/http-content-encoding\n"})})})]}),"\n",(0,r.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"br"})," (object) (default ",(0,r.jsx)(n.code,{children:"{}"}),"): ",(0,r.jsx)(n.code,{children:"zlib.createBrotliCompress"})," ",(0,r.jsx)(n.a,{href:"https://nodejs.org/api/zlib.html#zlib_class_brotlioptions",children:"brotliOptions"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"gzip"})," (object) (default ",(0,r.jsx)(n.code,{children:"{}"}),"): ",(0,r.jsx)(n.code,{children:"zlib.createGzip"})," ",(0,r.jsx)(n.a,{href:"https://nodejs.org/api/zlib.html#zlib_class_options",children:"gzipOptions"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"deflate"})," (object) (default ",(0,r.jsx)(n.code,{children:"{}"}),"): ",(0,r.jsx)(n.code,{children:"zlib.createDeflate"})," ",(0,r.jsx)(n.a,{href:"https://nodejs.org/api/zlib.html#zlib_class_options",children:"deflateOptions"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"overridePreferredEncoding"})," (array[string]) (optional): Override the preferred encoding order, most browsers prefer ",(0,r.jsx)(n.code,{children:"gzip"})," over ",(0,r.jsx)(n.code,{children:"br"}),", even though ",(0,r.jsx)(n.code,{children:"br"})," has higher compression. Default: ",(0,r.jsx)(n.code,{children:"[]"})]}),"\n"]}),"\n",(0,r.jsx)(n.p,{children:"NOTES:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Important"})," For ",(0,r.jsx)(n.code,{children:"br"})," encoding NodeJS defaults to ",(0,r.jsx)(n.code,{children:"11"}),". Levels ",(0,r.jsx)(n.code,{children:"10"})," & ",(0,r.jsx)(n.code,{children:"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."]}),"\n"]}),"\n",(0,r.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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"})}),"\n",(0,r.jsx)(n.h3,{id:"using-streams",children:"Using streams"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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\nconst lambdaHandler = (event, context) => {\n return {\n statusCode: 200,\n body: createReadableStream('{...}')\n }\n}\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(lambdaHandler)\n"})})]})}function p(e={}){const{wrapper:n}={...(0,o.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>s});t(7294);var r=t(6010);const o={tabItem:"tabItem_Ymn6"};var a=t(5893);function s(e){let{children:n,hidden:t,className:s}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,r.Z)(o.tabItem,s),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var r=t(7294),o=t(6010),a=t(2466),s=t(6550),i=t(469),l=t(1980),d=t(7392),c=t(12);function u(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:t}=e;return(0,r.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:r,default:o}}=e;return{value:n,label:t,attributes:r,default:o}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function p(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function m(e){let{queryString:n=!1,groupId:t}=e;const o=(0,s.k6)(),a=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,l._X)(a),(0,r.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(o.location.search);n.set(a,e),o.replace({...o.location,search:n.toString()})}),[a,o])]}function f(e){const{defaultValue:n,queryString:t=!1,groupId:o}=e,a=h(e),[s,l]=(0,r.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const r=t.find((e=>e.default))??t[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:n,tabValues:a}))),[d,u]=m({queryString:t,groupId:o}),[f,b]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[o,a]=(0,c.Nk)(t);return[o,(0,r.useCallback)((e=>{t&&a.set(e)}),[t,a])]}({groupId:o}),g=(()=>{const e=d??f;return p({value:e,tabValues:a})?e:null})();(0,i.Z)((()=>{g&&l(g)}),[g]);return{selectedValue:s,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),u(e),b(e)}),[u,b,a]),tabValues:a}}var b=t(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=t(5893);function j(e){let{className:n,block:t,selectedValue:r,selectValue:s,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:d}=(0,a.o5)(),c=e=>{const n=e.currentTarget,t=l.indexOf(n),o=i[t].value;o!==r&&(d(n),s(o))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;n=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;n=l[t]??l[l.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":t},n),children:i.map((e=>{let{value:n,label:t,attributes:a}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:r===n?0:-1,"aria-selected":r===n,ref:e=>l.push(e),onKeyDown:u,onClick:c,...a,className:(0,o.Z)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":r===n}),children:t??n},n)}))})}function v(e){let{lazy:n,children:t,selectedValue:o}=e;const a=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===o));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,r.cloneElement)(e,{key:n,hidden:e.props.value!==o})))})}function y(e){const n=f(e);return(0,x.jsxs)("div",{className:(0,o.Z)("tabs-container",g.tabList),children:[(0,x.jsx)(j,{...e,...n}),(0,x.jsx)(v,{...e,...n})]})}function w(e){const n=(0,b.Z)();return(0,x.jsx)(y,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>s});var r=t(7294);const o={},a=r.createContext(o);function s(e){const n=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:s(e.components),r.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6476],{4670:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>d,toc:()=>u});var r=t(5893),o=t(1151),a=t(4866),s=t(5162);const i={title:"http-content-encoding"},l=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-content-encoding.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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={},u=[{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}];function h(e){const n={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.p,{children:["This middleware take the ",(0,r.jsx)(n.code,{children:"preferredEncoding"})," output from ",(0,r.jsx)(n.code,{children:"@middy/http-content-negotiation"})," and applies the encoding to ",(0,r.jsx)(n.code,{children:"response.body"})," when a string."]}),"\n",(0,r.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(a.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(s.Z,{value:"npm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/http-content-encoding\n"})})}),(0,r.jsx)(s.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/http-content-encoding\n"})})}),(0,r.jsx)(s.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/http-content-encoding\n"})})})]}),"\n",(0,r.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"br"})," (object) (default ",(0,r.jsx)(n.code,{children:"{}"}),"): ",(0,r.jsx)(n.code,{children:"zlib.createBrotliCompress"})," ",(0,r.jsx)(n.a,{href:"https://nodejs.org/api/zlib.html#zlib_class_brotlioptions",children:"brotliOptions"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"gzip"})," (object) (default ",(0,r.jsx)(n.code,{children:"{}"}),"): ",(0,r.jsx)(n.code,{children:"zlib.createGzip"})," ",(0,r.jsx)(n.a,{href:"https://nodejs.org/api/zlib.html#zlib_class_options",children:"gzipOptions"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"deflate"})," (object) (default ",(0,r.jsx)(n.code,{children:"{}"}),"): ",(0,r.jsx)(n.code,{children:"zlib.createDeflate"})," ",(0,r.jsx)(n.a,{href:"https://nodejs.org/api/zlib.html#zlib_class_options",children:"deflateOptions"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"overridePreferredEncoding"})," (array[string]) (optional): Override the preferred encoding order, most browsers prefer ",(0,r.jsx)(n.code,{children:"gzip"})," over ",(0,r.jsx)(n.code,{children:"br"}),", even though ",(0,r.jsx)(n.code,{children:"br"})," has higher compression. Default: ",(0,r.jsx)(n.code,{children:"[]"})]}),"\n"]}),"\n",(0,r.jsx)(n.p,{children:"NOTES:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Important"})," For ",(0,r.jsx)(n.code,{children:"br"})," encoding NodeJS defaults to ",(0,r.jsx)(n.code,{children:"11"}),". Levels ",(0,r.jsx)(n.code,{children:"10"})," & ",(0,r.jsx)(n.code,{children:"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."]}),"\n"]}),"\n",(0,r.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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"})}),"\n",(0,r.jsx)(n.h3,{id:"using-streams",children:"Using streams"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"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\nconst lambdaHandler = (event, context) => {\n return {\n statusCode: 200,\n body: createReadableStream('{...}')\n }\n}\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(lambdaHandler)\n"})})]})}function p(e={}){const{wrapper:n}={...(0,o.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>s});t(7294);var r=t(6010);const o={tabItem:"tabItem_Ymn6"};var a=t(5893);function s(e){let{children:n,hidden:t,className:s}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,r.Z)(o.tabItem,s),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var r=t(7294),o=t(6010),a=t(2466),s=t(6550),i=t(469),l=t(1980),d=t(7392),c=t(12);function u(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:t}=e;return(0,r.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:r,default:o}}=e;return{value:n,label:t,attributes:r,default:o}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function p(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function m(e){let{queryString:n=!1,groupId:t}=e;const o=(0,s.k6)(),a=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,l._X)(a),(0,r.useCallback)((e=>{if(!a)return;const n=new URLSearchParams(o.location.search);n.set(a,e),o.replace({...o.location,search:n.toString()})}),[a,o])]}function f(e){const{defaultValue:n,queryString:t=!1,groupId:o}=e,a=h(e),[s,l]=(0,r.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const r=t.find((e=>e.default))??t[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:n,tabValues:a}))),[d,u]=m({queryString:t,groupId:o}),[f,b]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[o,a]=(0,c.Nk)(t);return[o,(0,r.useCallback)((e=>{t&&a.set(e)}),[t,a])]}({groupId:o}),g=(()=>{const e=d??f;return p({value:e,tabValues:a})?e:null})();(0,i.Z)((()=>{g&&l(g)}),[g]);return{selectedValue:s,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),u(e),b(e)}),[u,b,a]),tabValues:a}}var b=t(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=t(5893);function j(e){let{className:n,block:t,selectedValue:r,selectValue:s,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:d}=(0,a.o5)(),c=e=>{const n=e.currentTarget,t=l.indexOf(n),o=i[t].value;o!==r&&(d(n),s(o))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;n=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;n=l[t]??l[l.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":t},n),children:i.map((e=>{let{value:n,label:t,attributes:a}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:r===n?0:-1,"aria-selected":r===n,ref:e=>l.push(e),onKeyDown:u,onClick:c,...a,className:(0,o.Z)("tabs__item",g.tabItem,a?.className,{"tabs__item--active":r===n}),children:t??n},n)}))})}function v(e){let{lazy:n,children:t,selectedValue:o}=e;const a=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=a.find((e=>e.props.value===o));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,n)=>(0,r.cloneElement)(e,{key:n,hidden:e.props.value!==o})))})}function y(e){const n=f(e);return(0,x.jsxs)("div",{className:(0,o.Z)("tabs-container",g.tabList),children:[(0,x.jsx)(j,{...e,...n}),(0,x.jsx)(v,{...e,...n})]})}function w(e){const n=(0,b.Z)();return(0,x.jsx)(y,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>s});var r=t(7294);const o={},a=r.createContext(o);function s(e){const n=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:s(e.components),r.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/b83c886a.8851a69b.js b/assets/js/b83c886a.89f4028b.js similarity index 94% rename from assets/js/b83c886a.8851a69b.js rename to assets/js/b83c886a.89f4028b.js index 78d5cf892..b3a611954 100644 --- a/assets/js/b83c886a.8851a69b.js +++ b/assets/js/b83c886a.89f4028b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8931],{5357:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>d,contentTitle:()=>s,default:()=>l,frontMatter:()=>r,metadata:()=>c,toc:()=>u});var i=o(5893),n=o(1151);const r={title:"Contributing"},s=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/10-contributing.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:10,frontMatter:{title:"Contributing"},sidebar:"tutorialSidebar",previous:{title:"Release Cycle",permalink:"/docs/intro/release-cycle"},next:{title:"Sponsoring",permalink:"/docs/intro/sponsoring"}},d={},u=[];function a(t){const e={a:"a",p:"p",...(0,n.a)(),...t.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(e.p,{children:["In the spirit of Open Source Software, everyone is very welcome to contribute to this repository. Feel free to ",(0,i.jsx)(e.a,{href:"https://github.com/middyjs/middy/issues",children:"raise issues"})," or to ",(0,i.jsx)(e.a,{href:"https://github.com/middyjs/middy/pulls",children:"submit Pull Requests"}),"."]}),"\n",(0,i.jsxs)(e.p,{children:["Before contributing to the project, make sure to have a look at our ",(0,i.jsx)(e.a,{href:"https://github.com/middyjs/middy/blob/main/.github/CONTRIBUTING.md",children:"Code of Conduct"}),"."]})]})}function l(t={}){const{wrapper:e}={...(0,n.a)(),...t.components};return e?(0,i.jsx)(e,{...t,children:(0,i.jsx)(a,{...t})}):a(t)}},1151:(t,e,o)=>{o.d(e,{Z:()=>c,a:()=>s});var i=o(7294);const n={},r=i.createContext(n);function s(t){const e=i.useContext(r);return i.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:s(t.components),i.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8931],{5357:(t,e,o)=>{o.r(e),o.d(e,{assets:()=>d,contentTitle:()=>s,default:()=>l,frontMatter:()=>r,metadata:()=>c,toc:()=>u});var i=o(5893),n=o(1151);const r={title:"Contributing"},s=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/10-contributing.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:10,frontMatter:{title:"Contributing"},sidebar:"tutorialSidebar",previous:{title:"Release Cycle",permalink:"/docs/intro/release-cycle"},next:{title:"Sponsoring",permalink:"/docs/intro/sponsoring"}},d={},u=[];function a(t){const e={a:"a",p:"p",...(0,n.a)(),...t.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(e.p,{children:["In the spirit of Open Source Software, everyone is very welcome to contribute to this repository. Feel free to ",(0,i.jsx)(e.a,{href:"https://github.com/middyjs/middy/issues",children:"raise issues"})," or to ",(0,i.jsx)(e.a,{href:"https://github.com/middyjs/middy/pulls",children:"submit Pull Requests"}),"."]}),"\n",(0,i.jsxs)(e.p,{children:["Before contributing to the project, make sure to have a look at our ",(0,i.jsx)(e.a,{href:"https://github.com/middyjs/middy/blob/main/.github/CONTRIBUTING.md",children:"Code of Conduct"}),"."]})]})}function l(t={}){const{wrapper:e}={...(0,n.a)(),...t.components};return e?(0,i.jsx)(e,{...t,children:(0,i.jsx)(a,{...t})}):a(t)}},1151:(t,e,o)=>{o.d(e,{Z:()=>c,a:()=>s});var i=o(7294);const n={},r=i.createContext(n);function s(t){const e=i.useContext(r);return i.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function c(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(n):t.components||n:s(t.components),i.createElement(r.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/b9c75af0.f4f3ac3f.js b/assets/js/b9c75af0.5a79563a.js similarity index 97% rename from assets/js/b9c75af0.f4f3ac3f.js rename to assets/js/b9c75af0.5a79563a.js index 1e9cd073e..0e6dcc39f 100644 --- a/assets/js/b9c75af0.f4f3ac3f.js +++ b/assets/js/b9c75af0.5a79563a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4504],{582:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>m,frontMatter:()=>o,metadata:()=>a,toc:()=>l});var s=n(5893),i=n(1151);const o={title:"Kinesis Streams"},r=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kinesis-streams.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Kinesis Streams"},sidebar:"tutorialSidebar",previous:{title:"Kinesis Firehose",permalink:"/docs/events/kinesis-firehose"},next:{title:"Lex",permalink:"/docs/events/lex"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html",children:"Using AWS Lambda with Amazon Kinesis"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>a,a:()=>r});var s=n(7294);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4504],{582:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>m,frontMatter:()=>o,metadata:()=>a,toc:()=>l});var s=n(5893),i=n(1151);const o={title:"Kinesis Streams"},r=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/kinesis-streams.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Kinesis Streams"},sidebar:"tutorialSidebar",previous:{title:"Kinesis Firehose",permalink:"/docs/events/kinesis-firehose"},next:{title:"Lex",permalink:"/docs/events/lex"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html",children:"Using AWS Lambda with Amazon Kinesis"})}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>a,a:()=>r});var s=n(7294);const i={},o=s.createContext(i);function r(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/bb2b8b33.e13464cf.js b/assets/js/bb2b8b33.f7ca9290.js similarity index 99% rename from assets/js/bb2b8b33.e13464cf.js rename to assets/js/bb2b8b33.f7ca9290.js index 4a449612c..d60b80148 100644 --- a/assets/js/bb2b8b33.e13464cf.js +++ b/assets/js/bb2b8b33.f7ca9290.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9905],{1969:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>o,contentTitle:()=>i,default:()=>h,frontMatter:()=>t,metadata:()=>l,toc:()=>a});var s=n(5893),d=n(1151);const t={title:"Upgrade 4.x -> 5.x",sidebar_position:1},i=void 0,l={id:"upgrade/4-5",title:"Upgrade 4.x -> 5.x",description:'aka "The ESM Only Update"',source:"@site/docs/upgrade/4-5.md",sourceDirName:"upgrade",slug:"/upgrade/4-5",permalink:"/docs/upgrade/4-5",draft:!1,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/4-5.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:1,frontMatter:{title:"Upgrade 4.x -> 5.x",sidebar_position:1},sidebar:"tutorialSidebar",previous:{title:"Upgrade",permalink:"/docs/category/upgrade"},next:{title:"Upgrade 3.x -> 4.x",permalink:"/docs/upgrade/3-4"}},o={},a=[{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:"appconfig",id:"appconfig",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}];function c(e){const r={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",strong:"strong",ul:"ul",...(0,d.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.p,{children:'aka "The ESM Only Update"'}),"\n",(0,s.jsx)(r.p,{children:"Version 5.x of Middy no longer supports Node.js versions 16.x. You are highly encouraged to move to Node.js 20.x."}),"\n",(0,s.jsx)(r.h2,{id:"notable-changes",children:"Notable changes"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"Middy no longer support Common JS modules."}),"\n",(0,s.jsx)(r.li,{children:"Update to use TypeScript v5 along with a refactor to most packages"}),"\n",(0,s.jsxs)(r.li,{children:["Update all errors to be consistent ",(0,s.jsx)(r.code,{children:"new Error('message', { cause: { package:'@middy/***', data:*** } })"})]}),"\n",(0,s.jsxs)(r.li,{children:["If using multiple ",(0,s.jsx)(r.code,{children:"http-*-body-parsers"})," on the same endpoint you'll need to set ",(0,s.jsx)(r.code,{children:"disableContentTypeError:true"})]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"core",children:"Core"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated ",(0,s.jsx)(r.code,{children:"plugin.timeoutEarlyResponse(...)"})," to throw new error with name ",(0,s.jsx)(r.code,{children:"TimeoutError"})," to match new ",(0,s.jsx)(r.code,{children:"AbortSignal.timeout()"}),"."]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"util",children:"Util"}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h2,{id:"middleware",children:"Middleware"}),"\n",(0,s.jsx)(r.h2,{id:"appconfig",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/appconfig",children:"appconfig"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Update SDK to use newer ",(0,s.jsx)(r.code,{children:"appconfigdata"})," client ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"cloudwatch-metrics",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/cloudwatch-metrics",children:"cloudwatch-metrics"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"do-not-wait-for-empty-event-loop",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/do-not-wait-for-empty-event-loop",children:"do-not-wait-for-empty-event-loop"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"error-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/error-logger",children:"error-logger"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Change ",(0,s.jsx)(r.code,{children:"logger"})," to have ",(0,s.jsx)(r.code,{children:"request"})," passed in instead of ",(0,s.jsx)(r.code,{children:"request.error"})," by default to allow access ",(0,s.jsx)(r.code,{children:"request.context"})," and ",(0,s.jsx)(r.code,{children:"request.event"})," ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/event-normalizer",children:"event-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-content-encoding",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-encoding",children:"http-content-encoding"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Use ",(0,s.jsx)(r.code,{children:"preferredLanguage"})," from ",(0,s.jsx)(r.code,{children:"context"})," instead of ",(0,s.jsx)(r.code,{children:"event"})," (See http-content-negotiation). ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-content-negotiation",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-negotiation",children:"http-content-negotiation"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Moved ",(0,s.jsx)(r.code,{children:"preferred*"})," from ",(0,s.jsx)(r.code,{children:"event"})," to ",(0,s.jsx)(r.code,{children:"context"})," ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-cors",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-cors",children:"http-cors"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-error-handler",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-error-handler",children:"http-error-handler"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Will return ",(0,s.jsx)(r.code,{children:"500"})," for all unhandled errors thrown ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-event-normalizer",children:"http-event-normalizer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Will no longer throw an error when HTTP type can't be determined ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-header-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-header-normalizer",children:"http-header-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-json-body-parser",children:"http-json-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Change ",(0,s.jsx)(r.code,{children:"disableContentTypeError"})," to ",(0,s.jsx)(r.code,{children:"false"})," by default ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-multipart-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-multipart-body-parser",children:"http-multipart-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Change ",(0,s.jsx)(r.code,{children:"disableContentTypeError"})," to ",(0,s.jsx)(r.code,{children:"false"})," by default ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-partial-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-partial-response",children:"http-partial-response"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-response-serializer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-response-serializer",children:"http-response-serializer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-router",children:(0,s.jsx)(r.a,{href:"/docs/routers/http-router",children:"http-router"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-security-headers",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-security-headers",children:"http-security-headers"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-body-parser",children:"http-urlencode-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Change ",(0,s.jsx)(r.code,{children:"disableContentTypeError"})," to ",(0,s.jsx)(r.code,{children:"false"})," by default ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-path-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-path-parser",children:"http-urlencode-path-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"input-output-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/input-output-logger",children:"input-output-logger"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use ",(0,s.jsx)(r.code,{children:"structuredClone"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"rds-signer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/rds-signer",children:"rds-signer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"s3-object-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/s3-object-response",children:"s3-object-response"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Refactored to use ",(0,s.jsx)(r.code,{children:"fetch"})," over ",(0,s.jsx)(r.code,{children:"https"}),". ",(0,s.jsx)(r.code,{children:"context"})," now returns ",(0,s.jsx)(r.code,{children:"s3ObjectFetch"})," to allow more control over how it's used. ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"secrets-manager",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/secrets-manager",children:"secrets-manager"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"service-discovery",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/service-discovery",children:"service-discovery"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"sqs-partial-batch-failure",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sqs-partial-batch-failure",children:"sqs-partial-batch-failure"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Will now catch unhandled errors and set all messages to failed, preventing infinite loops ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"ssm",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ssm",children:"ssm"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"sts",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sts",children:"sts"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"validator",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/validator",children:"validator"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Use ",(0,s.jsx)(r.code,{children:"preferredLanguage"})," from ",(0,s.jsx)(r.code,{children:"context"})," instead of ",(0,s.jsx)(r.code,{children:"event"})," (See http-content-negotiation)."]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"ajv-cmd"})," is no longer a required dependency, if you're pre-transpiling you'll need to run ",(0,s.jsx)(r.code,{children:"npm i ajv-cmd"}),"."]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"warmup",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/warmup",children:"warmup"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"ws-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ws-json-body-parser",children:"ws-json-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Remove inclusion of ",(0,s.jsx)(r.code,{children:"rawBody"})," from event ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"ws-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ws-response",children:"ws-response"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"ws-router",children:(0,s.jsx)(r.a,{href:"/docs/routers/ws-router",children:"ws-router"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h2,{id:"notes",children:"Notes"}),"\n",(0,s.jsx)(r.p,{children:"None"})]})}function h(e={}){const{wrapper:r}={...(0,d.a)(),...e.components};return r?(0,s.jsx)(r,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,r,n)=>{n.d(r,{Z:()=>l,a:()=>i});var s=n(7294);const d={},t=s.createContext(d);function i(e){const r=s.useContext(t);return s.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function l(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(d):e.components||d:i(e.components),s.createElement(t.Provider,{value:r},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9905],{1969:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>o,contentTitle:()=>i,default:()=>h,frontMatter:()=>t,metadata:()=>l,toc:()=>a});var s=n(5893),d=n(1151);const t={title:"Upgrade 4.x -> 5.x",sidebar_position:1},i=void 0,l={id:"upgrade/4-5",title:"Upgrade 4.x -> 5.x",description:'aka "The ESM Only Update"',source:"@site/docs/upgrade/4-5.md",sourceDirName:"upgrade",slug:"/upgrade/4-5",permalink:"/docs/upgrade/4-5",draft:!1,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/upgrade/4-5.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:1,frontMatter:{title:"Upgrade 4.x -> 5.x",sidebar_position:1},sidebar:"tutorialSidebar",previous:{title:"Upgrade",permalink:"/docs/category/upgrade"},next:{title:"Upgrade 3.x -> 4.x",permalink:"/docs/upgrade/3-4"}},o={},a=[{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:"appconfig",id:"appconfig",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}];function c(e){const r={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",strong:"strong",ul:"ul",...(0,d.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r.p,{children:'aka "The ESM Only Update"'}),"\n",(0,s.jsx)(r.p,{children:"Version 5.x of Middy no longer supports Node.js versions 16.x. You are highly encouraged to move to Node.js 20.x."}),"\n",(0,s.jsx)(r.h2,{id:"notable-changes",children:"Notable changes"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsx)(r.li,{children:"Middy no longer support Common JS modules."}),"\n",(0,s.jsx)(r.li,{children:"Update to use TypeScript v5 along with a refactor to most packages"}),"\n",(0,s.jsxs)(r.li,{children:["Update all errors to be consistent ",(0,s.jsx)(r.code,{children:"new Error('message', { cause: { package:'@middy/***', data:*** } })"})]}),"\n",(0,s.jsxs)(r.li,{children:["If using multiple ",(0,s.jsx)(r.code,{children:"http-*-body-parsers"})," on the same endpoint you'll need to set ",(0,s.jsx)(r.code,{children:"disableContentTypeError:true"})]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"core",children:"Core"}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated ",(0,s.jsx)(r.code,{children:"plugin.timeoutEarlyResponse(...)"})," to throw new error with name ",(0,s.jsx)(r.code,{children:"TimeoutError"})," to match new ",(0,s.jsx)(r.code,{children:"AbortSignal.timeout()"}),"."]}),"\n"]}),"\n",(0,s.jsx)(r.h2,{id:"util",children:"Util"}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h2,{id:"middleware",children:"Middleware"}),"\n",(0,s.jsx)(r.h2,{id:"appconfig",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/appconfig",children:"appconfig"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Update SDK to use newer ",(0,s.jsx)(r.code,{children:"appconfigdata"})," client ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"cloudwatch-metrics",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/cloudwatch-metrics",children:"cloudwatch-metrics"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"do-not-wait-for-empty-event-loop",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/do-not-wait-for-empty-event-loop",children:"do-not-wait-for-empty-event-loop"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"error-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/error-logger",children:"error-logger"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Change ",(0,s.jsx)(r.code,{children:"logger"})," to have ",(0,s.jsx)(r.code,{children:"request"})," passed in instead of ",(0,s.jsx)(r.code,{children:"request.error"})," by default to allow access ",(0,s.jsx)(r.code,{children:"request.context"})," and ",(0,s.jsx)(r.code,{children:"request.event"})," ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/event-normalizer",children:"event-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-content-encoding",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-encoding",children:"http-content-encoding"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Use ",(0,s.jsx)(r.code,{children:"preferredLanguage"})," from ",(0,s.jsx)(r.code,{children:"context"})," instead of ",(0,s.jsx)(r.code,{children:"event"})," (See http-content-negotiation). ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-content-negotiation",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-content-negotiation",children:"http-content-negotiation"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Moved ",(0,s.jsx)(r.code,{children:"preferred*"})," from ",(0,s.jsx)(r.code,{children:"event"})," to ",(0,s.jsx)(r.code,{children:"context"})," ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-cors",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-cors",children:"http-cors"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-error-handler",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-error-handler",children:"http-error-handler"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Will return ",(0,s.jsx)(r.code,{children:"500"})," for all unhandled errors thrown ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-event-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-event-normalizer",children:"http-event-normalizer"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Will no longer throw an error when HTTP type can't be determined ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-header-normalizer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-header-normalizer",children:"http-header-normalizer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-json-body-parser",children:"http-json-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Change ",(0,s.jsx)(r.code,{children:"disableContentTypeError"})," to ",(0,s.jsx)(r.code,{children:"false"})," by default ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-multipart-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-multipart-body-parser",children:"http-multipart-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Change ",(0,s.jsx)(r.code,{children:"disableContentTypeError"})," to ",(0,s.jsx)(r.code,{children:"false"})," by default ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-partial-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-partial-response",children:"http-partial-response"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-response-serializer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-response-serializer",children:"http-response-serializer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-router",children:(0,s.jsx)(r.a,{href:"/docs/routers/http-router",children:"http-router"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-security-headers",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-security-headers",children:"http-security-headers"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-body-parser",children:"http-urlencode-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Change ",(0,s.jsx)(r.code,{children:"disableContentTypeError"})," to ",(0,s.jsx)(r.code,{children:"false"})," by default ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"http-urlencode-path-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/http-urlencode-path-parser",children:"http-urlencode-path-parser"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"input-output-logger",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/input-output-logger",children:"input-output-logger"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Updated to use ",(0,s.jsx)(r.code,{children:"structuredClone"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"rds-signer",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/rds-signer",children:"rds-signer"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"s3-object-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/s3-object-response",children:"s3-object-response"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Refactored to use ",(0,s.jsx)(r.code,{children:"fetch"})," over ",(0,s.jsx)(r.code,{children:"https"}),". ",(0,s.jsx)(r.code,{children:"context"})," now returns ",(0,s.jsx)(r.code,{children:"s3ObjectFetch"})," to allow more control over how it's used. ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"secrets-manager",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/secrets-manager",children:"secrets-manager"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"service-discovery",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/service-discovery",children:"service-discovery"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"sqs-partial-batch-failure",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sqs-partial-batch-failure",children:"sqs-partial-batch-failure"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Will now catch unhandled errors and set all messages to failed, preventing infinite loops ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"ssm",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ssm",children:"ssm"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"sts",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/sts",children:"sts"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"validator",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/validator",children:"validator"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Use ",(0,s.jsx)(r.code,{children:"preferredLanguage"})," from ",(0,s.jsx)(r.code,{children:"context"})," instead of ",(0,s.jsx)(r.code,{children:"event"})," (See http-content-negotiation)."]}),"\n",(0,s.jsxs)(r.li,{children:[(0,s.jsx)(r.code,{children:"ajv-cmd"})," is no longer a required dependency, if you're pre-transpiling you'll need to run ",(0,s.jsx)(r.code,{children:"npm i ajv-cmd"}),"."]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"warmup",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/warmup",children:"warmup"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"ws-json-body-parser",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ws-json-body-parser",children:"ws-json-body-parser"})}),"\n",(0,s.jsxs)(r.ul,{children:["\n",(0,s.jsxs)(r.li,{children:["Remove inclusion of ",(0,s.jsx)(r.code,{children:"rawBody"})," from event ",(0,s.jsx)(r.strong,{children:"Breaking Change"})]}),"\n"]}),"\n",(0,s.jsx)(r.h3,{id:"ws-response",children:(0,s.jsx)(r.a,{href:"/docs/middlewares/ws-response",children:"ws-response"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h3,{id:"ws-router",children:(0,s.jsx)(r.a,{href:"/docs/routers/ws-router",children:"ws-router"})}),"\n",(0,s.jsx)(r.p,{children:"No change"}),"\n",(0,s.jsx)(r.h2,{id:"notes",children:"Notes"}),"\n",(0,s.jsx)(r.p,{children:"None"})]})}function h(e={}){const{wrapper:r}={...(0,d.a)(),...e.components};return r?(0,s.jsx)(r,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,r,n)=>{n.d(r,{Z:()=>l,a:()=>i});var s=n(7294);const d={},t=s.createContext(d);function i(e){const r=s.useContext(t);return s.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function l(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(d):e.components||d:i(e.components),s.createElement(t.Provider,{value:r},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/bff6c11b.fdf7cd1a.js b/assets/js/bff6c11b.55a850eb.js similarity index 98% rename from assets/js/bff6c11b.fdf7cd1a.js rename to assets/js/bff6c11b.55a850eb.js index e7bdadc2b..ac9ec7fd8 100644 --- a/assets/js/bff6c11b.fdf7cd1a.js +++ b/assets/js/bff6c11b.55a850eb.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4785],{4300:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>i,toc:()=>c});var a=t(5893),s=t(1151);const o={title:"API Gateway (WebSocket)"},r=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-ws.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.admonition,{type:"caution",children:(0,a.jsx)(n.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,a.jsx)(n.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsx)(n.li,{children:(0,a.jsx)(n.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html",children:"Using AWS Lambda with Amazon API Gateway"})}),"\n",(0,a.jsx)(n.li,{children:(0,a.jsx)(n.a,{href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api.html",children:"Working with WebSocket APIs"})}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"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"})})]})}function p(e={}){const{wrapper:n}={...(0,s.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>r});var a=t(7294);const s={},o=a.createContext(s);function r(e){const n=a.useContext(o);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),a.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4785],{4300:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>r,default:()=>p,frontMatter:()=>o,metadata:()=>i,toc:()=>c});var a=t(5893),s=t(1151);const o={title:"API Gateway (WebSocket)"},r=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/api-gateway-ws.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.admonition,{type:"caution",children:(0,a.jsx)(n.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,a.jsx)(n.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsx)(n.li,{children:(0,a.jsx)(n.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html",children:"Using AWS Lambda with Amazon API Gateway"})}),"\n",(0,a.jsx)(n.li,{children:(0,a.jsx)(n.a,{href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api.html",children:"Working with WebSocket APIs"})}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"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"})})]})}function p(e={}){const{wrapper:n}={...(0,s.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>r});var a=t(7294);const s={},o=a.createContext(s);function r(e){const n=a.useContext(o);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),a.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/c0ad98a5.0edd04da.js b/assets/js/c0ad98a5.bf5a6484.js similarity index 99% rename from assets/js/c0ad98a5.0edd04da.js rename to assets/js/c0ad98a5.bf5a6484.js index 39fc5fa8e..f02a531c3 100644 --- a/assets/js/c0ad98a5.0edd04da.js +++ b/assets/js/c0ad98a5.bf5a6484.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2932],{3705:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>h,frontMatter:()=>i,metadata:()=>u,toc:()=>c});var r=n(5893),a=n(1151),s=n(4866),l=n(5162);const i={title:"http-partial-response"},o=void 0,u={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-partial-response.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["Filtering the data returned in an object or JSON stringified response has never been so easy. Add the ",(0,r.jsx)(t.code,{children:"httpPartialResponse"})," middleware to your middleware chain, specify a custom ",(0,r.jsx)(t.code,{children:"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,r.jsx)(t.code,{children:"fields=firstname,lastname"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:["This middleware is based on the awesome ",(0,r.jsx)(t.code,{children:"json-mask"})," package written by ",(0,r.jsx)(t.a,{href:"https://github.com/nemtsov",children:"Yuriy Nemtsov"})]}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(l.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-partial-response\n"})})}),(0,r.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-partial-response\n"})})}),(0,r.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-partial-response\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"filteringKeyName"})," (",(0,r.jsx)(t.code,{children:"string"}),") (optional): defaults to ",(0,r.jsx)(t.code,{children:"fields"})," the querystring key that will be used to filter the response."]}),"\n"]}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpPartialResponse from '@middy/http-partial-response'\n\nconst lambdaHandler = (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\nexport const handler = middy().use(httpPartialResponse()).handler(lambdaHandler)\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"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>l});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function l(e){let{children:t,hidden:n,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,l),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7294),a=n(6010),s=n(2466),l=n(6550),i=n(469),o=n(1980),u=n(7392),d=n(12);function c(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(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 h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.k6)(),s=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)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=p(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(!h({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:s}))),[u,c]=m({queryString:n,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,d.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),y=(()=>{const e=u??f;return h({value:e,tabValues:s})?e:null})();(0,i.Z)((()=>{y&&o(y)}),[y]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),c(e),b(e)}),[c,b,s]),tabValues:s}}var b=n(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(5893);function g(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.o5)(),d=e=>{const t=e.currentTarget,n=o.indexOf(t),a=i[n].value;a!==r&&(u(t),l(a))},c=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=o.indexOf(e.currentTarget)+1;t=o[n]??o[0];break}case"ArrowLeft":{const n=o.indexOf(e.currentTarget)-1;t=o[n]??o[o.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>o.push(e),onKeyDown:c,onClick:d,...s,className:(0,a.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function j(e){const t=f(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",y.tabList),children:[(0,v.jsx)(g,{...e,...t}),(0,v.jsx)(x,{...e,...t})]})}function w(e){const t=(0,b.Z)();return(0,v.jsx)(j,{...e,children:c(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>i,a:()=>l});var r=n(7294);const a={},s=r.createContext(a);function l(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[2932],{3705:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>h,frontMatter:()=>i,metadata:()=>u,toc:()=>c});var r=n(5893),a=n(1151),s=n(4866),l=n(5162);const i={title:"http-partial-response"},o=void 0,u={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-partial-response.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["Filtering the data returned in an object or JSON stringified response has never been so easy. Add the ",(0,r.jsx)(t.code,{children:"httpPartialResponse"})," middleware to your middleware chain, specify a custom ",(0,r.jsx)(t.code,{children:"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,r.jsx)(t.code,{children:"fields=firstname,lastname"}),"."]}),"\n",(0,r.jsxs)(t.p,{children:["This middleware is based on the awesome ",(0,r.jsx)(t.code,{children:"json-mask"})," package written by ",(0,r.jsx)(t.a,{href:"https://github.com/nemtsov",children:"Yuriy Nemtsov"})]}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(l.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-partial-response\n"})})}),(0,r.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-partial-response\n"})})}),(0,r.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-partial-response\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"filteringKeyName"})," (",(0,r.jsx)(t.code,{children:"string"}),") (optional): defaults to ",(0,r.jsx)(t.code,{children:"fields"})," the querystring key that will be used to filter the response."]}),"\n"]}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpPartialResponse from '@middy/http-partial-response'\n\nconst lambdaHandler = (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\nexport const handler = middy().use(httpPartialResponse()).handler(lambdaHandler)\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"})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>l});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function l(e){let{children:t,hidden:n,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,l),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7294),a=n(6010),s=n(2466),l=n(6550),i=n(469),o=n(1980),u=n(7392),d=n(12);function c(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(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 h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.k6)(),s=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)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=p(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(!h({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:s}))),[u,c]=m({queryString:n,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,d.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),y=(()=>{const e=u??f;return h({value:e,tabValues:s})?e:null})();(0,i.Z)((()=>{y&&o(y)}),[y]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),c(e),b(e)}),[c,b,s]),tabValues:s}}var b=n(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(5893);function g(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.o5)(),d=e=>{const t=e.currentTarget,n=o.indexOf(t),a=i[n].value;a!==r&&(u(t),l(a))},c=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=o.indexOf(e.currentTarget)+1;t=o[n]??o[0];break}case"ArrowLeft":{const n=o.indexOf(e.currentTarget)-1;t=o[n]??o[o.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>o.push(e),onKeyDown:c,onClick:d,...s,className:(0,a.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function x(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function j(e){const t=f(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",y.tabList),children:[(0,v.jsx)(g,{...e,...t}),(0,v.jsx)(x,{...e,...t})]})}function w(e){const t=(0,b.Z)();return(0,v.jsx)(j,{...e,children:c(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>i,a:()=>l});var r=n(7294);const a={},s=r.createContext(a);function l(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/c1378803.cea9a565.js b/assets/js/c1378803.f9621dea.js similarity index 99% rename from assets/js/c1378803.cea9a565.js rename to assets/js/c1378803.f9621dea.js index b7389ca61..4822625f3 100644 --- a/assets/js/c1378803.cea9a565.js +++ b/assets/js/c1378803.f9621dea.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7450],{1257:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>c,toc:()=>h});var a=n(5893),s=n(1151),r=n(4866),o=n(5162);const l={title:"Powertools for AWS Lambda"},i=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/lambda-powertools.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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={},h=[{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}];function u(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["Powertools for AWS is a developer toolkit to implement Serverless ",(0,a.jsx)(t.a,{href:"https://s12d.com/middy-intro",children:"best practices and increase developer velocity"}),"."]}),"\n",(0,a.jsx)(t.p,{children:"You can use Powertools for AWS in both TypeScript and JavaScript code bases."}),"\n",(0,a.jsx)(t.admonition,{type:"note",children:(0,a.jsxs)(t.p,{children:["Powertools officially supports ",(0,a.jsx)(t.code,{children:"@middy/core"})," v3.x only. In most cases when using Node.js 16 or higher you can use Powertools with ",(0,a.jsx)(t.code,{children:"@middy/core"})," v4.x, however support is provided on a best-effort basis and we recommend using ",(0,a.jsx)(t.code,{children:"@middy/core"})," v3.x."]})}),"\n",(0,a.jsx)(t.h2,{id:"intro",children:"Intro"}),"\n",(0,a.jsx)(t.p,{children:"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:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.a,{href:"https://s12d.com/middy-logger",children:(0,a.jsx)(t.strong,{children:"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."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.a,{href:"https://s12d.com/middy-tracer",children:(0,a.jsx)(t.strong,{children:"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."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.a,{href:"https://s12d.com/middy-metrics",children:(0,a.jsx)(t.strong,{children:"Metrics"})})," - Create Amazon CloudWatch custom metrics asynchronously with a middleware that takes care of capturing cold starts, and flushes metrics to CloudWatch in ",(0,a.jsx)(t.a,{href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html",children:"EMF-formatted"})," batches."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.a,{href:"https://s12d.com/middy-idempotency",children:(0,a.jsx)(t.strong,{children:"Idempotency"})})," - Middleware to make your Lambda functions idempotent and prevent duplicate execution based on payload content."]}),"\n"]}),"\n",(0,a.jsx)(t.h2,{id:"logger",children:"Logger"}),"\n",(0,a.jsx)(t.p,{children:"Key features:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsx)(t.li,{children:"Capturing key fields from the Lambda context, cold starts, and structure logging output as JSON."}),"\n",(0,a.jsx)(t.li,{children:"Logging Lambda invocation events when instructed (disabled by default)."}),"\n",(0,a.jsx)(t.li,{children:"Printing all the logs only for a percentage of invocations via log sampling (disabled by default)."}),"\n",(0,a.jsx)(t.li,{children:"Appending additional keys to structured logs at any point in time."}),"\n",(0,a.jsx)(t.li,{children:"Providing a custom log formatter (Bring Your Own Formatter) to output logs in a structure compatible with your organization\u2019s Logging RFC."}),"\n"]}),"\n",(0,a.jsx)(t.h3,{id:"install",children:"Install"}),"\n",(0,a.jsxs)(r.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(o.Z,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"npm install --save @aws-lambda-powertools/logger\n"})})}),(0,a.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"yarn add @aws-lambda-powertools/logger\n"})})}),(0,a.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"pnpm add @aws-lambda-powertools/logger\n"})})})]}),"\n",(0,a.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,a.jsx)(t.p,{children:"Class constructor accepts the following options, which are all optional:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"logLevel"})," (string|LogLevel): Log level to use. Defaults to ",(0,a.jsx)(t.code,{children:"INFO"}),", but you can use any of the following values: ",(0,a.jsx)(t.code,{children:"SILENT"}),", ",(0,a.jsx)(t.code,{children:"DEBUG"}),", ",(0,a.jsx)(t.code,{children:"INFO"}),", ",(0,a.jsx)(t.code,{children:"WARN"}),", ",(0,a.jsx)(t.code,{children:"ERROR"}),", ",(0,a.jsx)(t.code,{children:"CRITICAL"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"serviceName"})," (string): Service name to use that will be used in all log statements. Defaults to ",(0,a.jsx)(t.code,{children:"service_undefined"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"sampleRateValue"})," (number): number between ",(0,a.jsx)(t.code,{children:"0.0"})," and ",(0,a.jsx)(t.code,{children:"1"})," to determine the sample rate for debug logging. Defaults to ",(0,a.jsx)(t.code,{children:"0"})," (no debub logging)."]}),"\n"]}),"\n",(0,a.jsx)(t.p,{children:"Middleware accepts the following options:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"logger"})," (Logger) (required): An instance of the Logger class."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"option"})," (object) (optional): An object with the following keys:","\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"logEvent"})," (boolean) (optional): Whether to log the Lambda invocation event. Defaults to ",(0,a.jsx)(t.code,{children:"false"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"clearState"})," (boolean) (optional): Whether to clear the logger state after each invocation. Defaults to ",(0,a.jsx)(t.code,{children:"false"}),"."]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,a.jsx)(t.h3,{id:"sample-usage",children:"Sample usage"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"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"})}),"\n",(0,a.jsx)(t.p,{children:"The above code will output the following log:"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-json",children:'{\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'})}),"\n",(0,a.jsxs)(t.p,{children:["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,a.jsx)(t.code,{children:"cold_start"})," field indicates whether the Lambda function was cold started or not, and the ",(0,a.jsx)(t.code,{children:"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."]}),"\n",(0,a.jsxs)(t.p,{children:["The Logger utility also allows you to append arbitary keys to the log entry at both ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#appending-persistent-additional-log-keys-and-values",children:"the global level"}),", at the ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#clearing-all-state",children:"invocation level"}),", and at the ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#appending-additional-data-to-a-single-log-item",children:"single log level"}),". For example, there might be some keys that you want to include in all log entries, such as the ",(0,a.jsx)(t.code,{children:"environment"})," key to differentiate between the ",(0,a.jsx)(t.code,{children:"prod"})," and ",(0,a.jsx)(t.code,{children:"dev"})," environments, or in other cases you might want to include some keys only for a specific log entry, such as the ",(0,a.jsx)(t.code,{children:"customer_id"})," key to identify the customer that triggered the Lambda invocation."]}),"\n",(0,a.jsxs)(t.p,{children:["Additionally, you can also configure Logger to ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#log-incoming-event",children:"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,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#custom-log-formatter-bring-your-own-formatter",children:"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."]}),"\n",(0,a.jsx)(t.h2,{id:"tracer",children:"Tracer"}),"\n",(0,a.jsx)(t.p,{children:"Key features:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsx)(t.li,{children:"Auto-capturing cold start and service name as annotations, and responses or full exceptions as metadata."}),"\n",(0,a.jsx)(t.li,{children:"Automatically tracing HTTP(S) clients and generating segments for each request."}),"\n",(0,a.jsx)(t.li,{children:"Supporting tracing functions via decorators, middleware, and manual instrumentation."}),"\n",(0,a.jsx)(t.li,{children:"Supporting tracing AWS SDK v2 and v3 via AWS X-Ray SDK for Node.js."}),"\n",(0,a.jsx)(t.li,{children:"Auto-disable tracing when not running in the Lambda environment."}),"\n"]}),"\n",(0,a.jsx)(t.h3,{id:"install-1",children:"Install"}),"\n",(0,a.jsxs)(r.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(o.Z,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"npm install --save @aws-lambda-powertools/tracer\n"})})}),(0,a.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"yarn add @aws-lambda-powertools/tracer\n"})})}),(0,a.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"pnpm add @aws-lambda-powertools/tracer\n"})})})]}),"\n",(0,a.jsx)(t.h3,{id:"options-1",children:"Options"}),"\n",(0,a.jsx)(t.p,{children:"Class constructor accepts the following options, which are all optional:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"serviceName"})," (string): Service name to use that will be used in all log statements. Defaults to ",(0,a.jsx)(t.code,{children:"service_undefined"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"enabled"})," (boolean): Whether to enable tracing. Defaults to ",(0,a.jsx)(t.code,{children:"true"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"captureHTTPsRequests"})," (boolean): Whether to capture outgoing HTTP(S) requests as segment metadata. Defaults to ",(0,a.jsx)(t.code,{children:"true"}),"."]}),"\n"]}),"\n",(0,a.jsx)(t.p,{children:"Middleware accepts the following options:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"tracer"})," (Tracer) (required): An instance of the Tracer class."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"option"})," (object) (optional): An object with the following keys:","\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"captureResponse"})," (boolean) (optional): Whether to capture the Lambda invocation result as segment metadata. Defaults to ",(0,a.jsx)(t.code,{children:"true"}),"."]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,a.jsx)(t.h3,{id:"sample-usage-1",children:"Sample usage"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"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"})}),"\n",(0,a.jsxs)(t.p,{children:["The above code instructs the Tracer utility to create a custom segment named ",(0,a.jsx)(t.code,{children:"## index.handler"})," and to add an annotation to it with the key ",(0,a.jsx)(t.code,{children:"successfulBooking"})," and the value ",(0,a.jsx)(t.code,{children:"true"}),". The segment name is automatically generated based on the handler name, and the ",(0,a.jsx)(t.code,{children:"##"})," 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,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/#annotations-metadata",children:"as metadata"}),". The segment data will be automatically sent to AWS X-Ray when the Lambda function completes its execution."]}),"\n",(0,a.jsxs)(t.p,{children:["Tracer also automatically ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/#tracing-http-requests",children:"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,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/#patching-aws-sdk-clients",children:"capture any AWS SDK calls"})," made by the function, and do the same for them."]}),"\n",(0,a.jsx)(t.h2,{id:"metrics",children:"Metrics"}),"\n",(0,a.jsx)(t.p,{children:"Key features:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:["Aggregating up to 100 metrics using a single ",(0,a.jsx)(t.a,{href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html",children:"CloudWatch EMF"})," object."]}),"\n",(0,a.jsx)(t.li,{children:"Validating your metrics against common metric definitions mistakes (for example, metric unit, values, max dimensions, max metrics)."}),"\n",(0,a.jsx)(t.li,{children:"Metrics are created asynchronously by the CloudWatch service. You do not need any custom stacks, and there is no impact to Lambda function latency."}),"\n",(0,a.jsx)(t.li,{children:"Creating a one-off metric with different dimensions."}),"\n"]}),"\n",(0,a.jsxs)(t.p,{children:["If you're new to Amazon CloudWatch, there are a few terms like ",(0,a.jsx)(t.code,{children:"Namespace"}),", ",(0,a.jsx)(t.code,{children:"Dimensions"}),", ",(0,a.jsx)(t.code,{children:"Unit"}),", etc, that you must be aware of before you start using the Metrics utility. To learn more about these terms, see the ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#terminologies",children:"documentation on PowerTools Metrics"}),"."]}),"\n",(0,a.jsx)(t.h3,{id:"install-2",children:"Install"}),"\n",(0,a.jsxs)(r.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(o.Z,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"npm install --save @aws-lambda-powertools/metrics\n"})})}),(0,a.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"yarn add @aws-lambda-powertools/metrics\n"})})}),(0,a.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"pnpm add @aws-lambda-powertools/metrics\n"})})})]}),"\n",(0,a.jsx)(t.h3,{id:"options-2",children:"Options"}),"\n",(0,a.jsx)(t.p,{children:"Class constructor accepts the following options, which are all optional:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"serviceName"})," (string): Service name to use that will be used in all log statements. Defaults to ",(0,a.jsx)(t.code,{children:"service_undefined"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"defaultNamespace"})," (string): Default namespace to use for all metrics. Defaults to ",(0,a.jsx)(t.code,{children:"default_namespace"}),"."]}),"\n"]}),"\n",(0,a.jsx)(t.p,{children:"Middleware accepts the following options:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"metrics"})," (Metric) (required): An instance of the Metrics class."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"option"})," (object) (optional): An object with the following keys:","\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"throwOnEmptyMetrics"})," (boolean) (optional): Whether to throw an error if no metrics were added. Defaults to ",(0,a.jsx)(t.code,{children:"false"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"captureColdStartMetric"})," (boolean) (optional): Whether to capture the cold start metric. Defaults to ",(0,a.jsx)(t.code,{children:"true"}),"."]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,a.jsx)(t.h3,{id:"sample-usage-2",children:"Sample usage"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"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"})}),"\n",(0,a.jsx)(t.p,{children:"The above code will output a CloudWatch EMF object similar to the following:"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-json",children:'{\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'})}),"\n",(0,a.jsx)(t.p,{children:"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."}),"\n",(0,a.jsxs)(t.p,{children:["The Metrics utility supports ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#adding-high-resolution-metrics",children:"high-resolution metrics"})," as well as ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#adding-multi-value-metrics",children:"multi-value metrics"}),". It also allows you to add ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#adding-default-dimensions",children:"default dimensions"})," that are used in all the metrics emitted by your application or ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#single-metric-with-different-dimensions",children:"create a one-off metric"})," with different dimensions."]}),"\n",(0,a.jsx)(t.h2,{id:"idempotency",children:"Idempotency"}),"\n",(0,a.jsx)(t.p,{children:"Key features:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsx)(t.li,{children:"Prevent Lambda handler from executing more than once on the same event payload during a time window"}),"\n",(0,a.jsx)(t.li,{children:"Ensure Lambda handler returns the same result when called with the same payload"}),"\n",(0,a.jsx)(t.li,{children:"Select a subset of the event as the idempotency key using JMESPath expressions"}),"\n",(0,a.jsx)(t.li,{children:"Set a time window in which records with the same payload should be considered duplicates"}),"\n",(0,a.jsx)(t.li,{children:"Expires in-progress executions if the Lambda function times out halfway through"}),"\n"]}),"\n",(0,a.jsx)(t.p,{children:"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."}),"\n",(0,a.jsx)(t.h3,{id:"install-3",children:"Install"}),"\n",(0,a.jsxs)(r.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(o.Z,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"npm install --save @aws-lambda-powertools/idempotency @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb\n"})})}),(0,a.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"yarn add @aws-lambda-powertools/idempotency @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb\n"})})}),(0,a.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"pnpm add @aws-lambda-powertools/idempotency @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb\n"})})})]}),"\n",(0,a.jsx)(t.h3,{id:"options-3",children:"Options"}),"\n",(0,a.jsx)(t.p,{children:"Middleware accepts the following options:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"persistenceStore"})," (",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda/typescript/latest/api/classes/_aws_lambda_powertools_idempotency.persistence.BasePersistenceLayer.html",children:(0,a.jsx)(t.code,{children:"BasePersistenceLayer"})}),"): Class used to interact with a ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/idempotency/#persistence-layers",children:"persistence store"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"config"})," (",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda/typescript/latest/api/classes/_aws_lambda_powertools_idempotency.index.IdempotencyConfig.html",children:(0,a.jsx)(t.code,{children:"IdempotencyConfig"})}),") (optional): Configuration object to customize the ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/idempotency/#customizing-the-default-behavior",children:"default behavior"})," of the idempotency feature."]}),"\n"]}),"\n",(0,a.jsx)(t.h3,{id:"sample-usage-3",children:"Sample usage"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"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"})}),"\n",(0,a.jsx)(t.h2,{id:"best-practices",children:"Best practices"}),"\n",(0,a.jsx)(t.h3,{id:"using-multiple-utilities",children:"Using multiple utilities"}),"\n",(0,a.jsx)(t.p,{children:"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."}),"\n",(0,a.jsx)(t.p,{children:"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."}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"export const handler = middy(() => { /* ... */ })\n .use(captureLambdaHandler(tracer))\n .use(injectLambdaContext(logger, { logEvent: true }))\n .use(logMetrics(metrics, { captureColdStartMetric: true }));\n"})}),"\n",(0,a.jsx)(t.h3,{id:"cleaning-up-on-early-returns",children:"Cleaning up on early returns"}),"\n",(0,a.jsxs)(t.p,{children:["As discussed in the ",(0,a.jsx)(t.a,{href:"/docs/intro/early-interrupt",children:"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."]}),"\n",(0,a.jsxs)(t.p,{children:["For example, if you are using the Tracer utility, you must make sure to call the ",(0,a.jsx)(t.code,{children:"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,a.jsx)(t.code,{children:"clearMetrics"})," method so that the Metrics utility can emit the metrics that were stored in the buffer and avoid you losing any data."]}),"\n",(0,a.jsx)(t.p,{children:"Following the example described in the linked section, you can clean up all the utilities by doing the following:"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(u,{...e})}):u(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>o});n(7294);var a=n(6010);const s={tabItem:"tabItem_Ymn6"};var r=n(5893);function o(e){let{children:t,hidden:n,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,a.Z)(s.tabItem,o),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>v});var a=n(7294),s=n(6010),r=n(2466),o=n(6550),l=n(469),i=n(1980),c=n(7392),d=n(12);function h(e){return a.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function u(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??function(e){return h(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:s}}=e;return{value:t,label:n,attributes:a,default:s}}))}(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 p(e){let{queryString:t=!1,groupId:n}=e;const s=(0,o.k6)(),r=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)(r),(0,a.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(s.location.search);t.set(r,e),s.replace({...s.location,search:t.toString()})}),[r,s])]}function g(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,r=u(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 a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:r}))),[c,h]=p({queryString:n,groupId:s}),[g,x]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,r]=(0,d.Nk)(n);return[s,(0,a.useCallback)((e=>{n&&r.set(e)}),[n,r])]}({groupId:s}),f=(()=>{const e=c??g;return m({value:e,tabValues:r})?e:null})();(0,l.Z)((()=>{f&&i(f)}),[f]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);i(e),h(e),x(e)}),[h,x,r]),tabValues:r}}var x=n(2389);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(5893);function b(e){let{className:t,block:n,selectedValue:a,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.o5)(),d=e=>{const t=e.currentTarget,n=i.indexOf(t),s=l[n].value;s!==a&&(c(t),o(s))},h=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:r}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:a===t?0:-1,"aria-selected":a===t,ref:e=>i.push(e),onKeyDown:h,onClick:d,...r,className:(0,s.Z)("tabs__item",f.tabItem,r?.className,{"tabs__item--active":a===t}),children:n??t},t)}))})}function y(e){let{lazy:t,children:n,selectedValue:s}=e;const r=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=r.find((e=>e.props.value===s));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:r.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function w(e){const t=g(e);return(0,j.jsxs)("div",{className:(0,s.Z)("tabs-container",f.tabList),children:[(0,j.jsx)(b,{...e,...t}),(0,j.jsx)(y,{...e,...t})]})}function v(e){const t=(0,x.Z)();return(0,j.jsx)(w,{...e,children:h(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>l,a:()=>o});var a=n(7294);const s={},r=a.createContext(s);function o(e){const t=a.useContext(r);return a.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),a.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7450],{1257:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>m,frontMatter:()=>l,metadata:()=>c,toc:()=>h});var a=n(5893),s=n(1151),r=n(4866),o=n(5162);const l={title:"Powertools for AWS Lambda"},i=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/lambda-powertools.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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={},h=[{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}];function u(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["Powertools for AWS is a developer toolkit to implement Serverless ",(0,a.jsx)(t.a,{href:"https://s12d.com/middy-intro",children:"best practices and increase developer velocity"}),"."]}),"\n",(0,a.jsx)(t.p,{children:"You can use Powertools for AWS in both TypeScript and JavaScript code bases."}),"\n",(0,a.jsx)(t.admonition,{type:"note",children:(0,a.jsxs)(t.p,{children:["Powertools officially supports ",(0,a.jsx)(t.code,{children:"@middy/core"})," v3.x only. In most cases when using Node.js 16 or higher you can use Powertools with ",(0,a.jsx)(t.code,{children:"@middy/core"})," v4.x, however support is provided on a best-effort basis and we recommend using ",(0,a.jsx)(t.code,{children:"@middy/core"})," v3.x."]})}),"\n",(0,a.jsx)(t.h2,{id:"intro",children:"Intro"}),"\n",(0,a.jsx)(t.p,{children:"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:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.a,{href:"https://s12d.com/middy-logger",children:(0,a.jsx)(t.strong,{children:"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."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.a,{href:"https://s12d.com/middy-tracer",children:(0,a.jsx)(t.strong,{children:"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."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.a,{href:"https://s12d.com/middy-metrics",children:(0,a.jsx)(t.strong,{children:"Metrics"})})," - Create Amazon CloudWatch custom metrics asynchronously with a middleware that takes care of capturing cold starts, and flushes metrics to CloudWatch in ",(0,a.jsx)(t.a,{href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html",children:"EMF-formatted"})," batches."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.a,{href:"https://s12d.com/middy-idempotency",children:(0,a.jsx)(t.strong,{children:"Idempotency"})})," - Middleware to make your Lambda functions idempotent and prevent duplicate execution based on payload content."]}),"\n"]}),"\n",(0,a.jsx)(t.h2,{id:"logger",children:"Logger"}),"\n",(0,a.jsx)(t.p,{children:"Key features:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsx)(t.li,{children:"Capturing key fields from the Lambda context, cold starts, and structure logging output as JSON."}),"\n",(0,a.jsx)(t.li,{children:"Logging Lambda invocation events when instructed (disabled by default)."}),"\n",(0,a.jsx)(t.li,{children:"Printing all the logs only for a percentage of invocations via log sampling (disabled by default)."}),"\n",(0,a.jsx)(t.li,{children:"Appending additional keys to structured logs at any point in time."}),"\n",(0,a.jsx)(t.li,{children:"Providing a custom log formatter (Bring Your Own Formatter) to output logs in a structure compatible with your organization\u2019s Logging RFC."}),"\n"]}),"\n",(0,a.jsx)(t.h3,{id:"install",children:"Install"}),"\n",(0,a.jsxs)(r.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(o.Z,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"npm install --save @aws-lambda-powertools/logger\n"})})}),(0,a.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"yarn add @aws-lambda-powertools/logger\n"})})}),(0,a.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"pnpm add @aws-lambda-powertools/logger\n"})})})]}),"\n",(0,a.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,a.jsx)(t.p,{children:"Class constructor accepts the following options, which are all optional:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"logLevel"})," (string|LogLevel): Log level to use. Defaults to ",(0,a.jsx)(t.code,{children:"INFO"}),", but you can use any of the following values: ",(0,a.jsx)(t.code,{children:"SILENT"}),", ",(0,a.jsx)(t.code,{children:"DEBUG"}),", ",(0,a.jsx)(t.code,{children:"INFO"}),", ",(0,a.jsx)(t.code,{children:"WARN"}),", ",(0,a.jsx)(t.code,{children:"ERROR"}),", ",(0,a.jsx)(t.code,{children:"CRITICAL"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"serviceName"})," (string): Service name to use that will be used in all log statements. Defaults to ",(0,a.jsx)(t.code,{children:"service_undefined"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"sampleRateValue"})," (number): number between ",(0,a.jsx)(t.code,{children:"0.0"})," and ",(0,a.jsx)(t.code,{children:"1"})," to determine the sample rate for debug logging. Defaults to ",(0,a.jsx)(t.code,{children:"0"})," (no debub logging)."]}),"\n"]}),"\n",(0,a.jsx)(t.p,{children:"Middleware accepts the following options:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"logger"})," (Logger) (required): An instance of the Logger class."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"option"})," (object) (optional): An object with the following keys:","\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"logEvent"})," (boolean) (optional): Whether to log the Lambda invocation event. Defaults to ",(0,a.jsx)(t.code,{children:"false"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"clearState"})," (boolean) (optional): Whether to clear the logger state after each invocation. Defaults to ",(0,a.jsx)(t.code,{children:"false"}),"."]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,a.jsx)(t.h3,{id:"sample-usage",children:"Sample usage"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"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"})}),"\n",(0,a.jsx)(t.p,{children:"The above code will output the following log:"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-json",children:'{\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'})}),"\n",(0,a.jsxs)(t.p,{children:["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,a.jsx)(t.code,{children:"cold_start"})," field indicates whether the Lambda function was cold started or not, and the ",(0,a.jsx)(t.code,{children:"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."]}),"\n",(0,a.jsxs)(t.p,{children:["The Logger utility also allows you to append arbitary keys to the log entry at both ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#appending-persistent-additional-log-keys-and-values",children:"the global level"}),", at the ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#clearing-all-state",children:"invocation level"}),", and at the ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#appending-additional-data-to-a-single-log-item",children:"single log level"}),". For example, there might be some keys that you want to include in all log entries, such as the ",(0,a.jsx)(t.code,{children:"environment"})," key to differentiate between the ",(0,a.jsx)(t.code,{children:"prod"})," and ",(0,a.jsx)(t.code,{children:"dev"})," environments, or in other cases you might want to include some keys only for a specific log entry, such as the ",(0,a.jsx)(t.code,{children:"customer_id"})," key to identify the customer that triggered the Lambda invocation."]}),"\n",(0,a.jsxs)(t.p,{children:["Additionally, you can also configure Logger to ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#log-incoming-event",children:"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,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/logger/#custom-log-formatter-bring-your-own-formatter",children:"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."]}),"\n",(0,a.jsx)(t.h2,{id:"tracer",children:"Tracer"}),"\n",(0,a.jsx)(t.p,{children:"Key features:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsx)(t.li,{children:"Auto-capturing cold start and service name as annotations, and responses or full exceptions as metadata."}),"\n",(0,a.jsx)(t.li,{children:"Automatically tracing HTTP(S) clients and generating segments for each request."}),"\n",(0,a.jsx)(t.li,{children:"Supporting tracing functions via decorators, middleware, and manual instrumentation."}),"\n",(0,a.jsx)(t.li,{children:"Supporting tracing AWS SDK v2 and v3 via AWS X-Ray SDK for Node.js."}),"\n",(0,a.jsx)(t.li,{children:"Auto-disable tracing when not running in the Lambda environment."}),"\n"]}),"\n",(0,a.jsx)(t.h3,{id:"install-1",children:"Install"}),"\n",(0,a.jsxs)(r.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(o.Z,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"npm install --save @aws-lambda-powertools/tracer\n"})})}),(0,a.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"yarn add @aws-lambda-powertools/tracer\n"})})}),(0,a.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"pnpm add @aws-lambda-powertools/tracer\n"})})})]}),"\n",(0,a.jsx)(t.h3,{id:"options-1",children:"Options"}),"\n",(0,a.jsx)(t.p,{children:"Class constructor accepts the following options, which are all optional:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"serviceName"})," (string): Service name to use that will be used in all log statements. Defaults to ",(0,a.jsx)(t.code,{children:"service_undefined"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"enabled"})," (boolean): Whether to enable tracing. Defaults to ",(0,a.jsx)(t.code,{children:"true"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"captureHTTPsRequests"})," (boolean): Whether to capture outgoing HTTP(S) requests as segment metadata. Defaults to ",(0,a.jsx)(t.code,{children:"true"}),"."]}),"\n"]}),"\n",(0,a.jsx)(t.p,{children:"Middleware accepts the following options:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"tracer"})," (Tracer) (required): An instance of the Tracer class."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"option"})," (object) (optional): An object with the following keys:","\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"captureResponse"})," (boolean) (optional): Whether to capture the Lambda invocation result as segment metadata. Defaults to ",(0,a.jsx)(t.code,{children:"true"}),"."]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,a.jsx)(t.h3,{id:"sample-usage-1",children:"Sample usage"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"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"})}),"\n",(0,a.jsxs)(t.p,{children:["The above code instructs the Tracer utility to create a custom segment named ",(0,a.jsx)(t.code,{children:"## index.handler"})," and to add an annotation to it with the key ",(0,a.jsx)(t.code,{children:"successfulBooking"})," and the value ",(0,a.jsx)(t.code,{children:"true"}),". The segment name is automatically generated based on the handler name, and the ",(0,a.jsx)(t.code,{children:"##"})," 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,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/#annotations-metadata",children:"as metadata"}),". The segment data will be automatically sent to AWS X-Ray when the Lambda function completes its execution."]}),"\n",(0,a.jsxs)(t.p,{children:["Tracer also automatically ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/#tracing-http-requests",children:"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,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/tracer/#patching-aws-sdk-clients",children:"capture any AWS SDK calls"})," made by the function, and do the same for them."]}),"\n",(0,a.jsx)(t.h2,{id:"metrics",children:"Metrics"}),"\n",(0,a.jsx)(t.p,{children:"Key features:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:["Aggregating up to 100 metrics using a single ",(0,a.jsx)(t.a,{href:"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html",children:"CloudWatch EMF"})," object."]}),"\n",(0,a.jsx)(t.li,{children:"Validating your metrics against common metric definitions mistakes (for example, metric unit, values, max dimensions, max metrics)."}),"\n",(0,a.jsx)(t.li,{children:"Metrics are created asynchronously by the CloudWatch service. You do not need any custom stacks, and there is no impact to Lambda function latency."}),"\n",(0,a.jsx)(t.li,{children:"Creating a one-off metric with different dimensions."}),"\n"]}),"\n",(0,a.jsxs)(t.p,{children:["If you're new to Amazon CloudWatch, there are a few terms like ",(0,a.jsx)(t.code,{children:"Namespace"}),", ",(0,a.jsx)(t.code,{children:"Dimensions"}),", ",(0,a.jsx)(t.code,{children:"Unit"}),", etc, that you must be aware of before you start using the Metrics utility. To learn more about these terms, see the ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#terminologies",children:"documentation on PowerTools Metrics"}),"."]}),"\n",(0,a.jsx)(t.h3,{id:"install-2",children:"Install"}),"\n",(0,a.jsxs)(r.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(o.Z,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"npm install --save @aws-lambda-powertools/metrics\n"})})}),(0,a.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"yarn add @aws-lambda-powertools/metrics\n"})})}),(0,a.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"pnpm add @aws-lambda-powertools/metrics\n"})})})]}),"\n",(0,a.jsx)(t.h3,{id:"options-2",children:"Options"}),"\n",(0,a.jsx)(t.p,{children:"Class constructor accepts the following options, which are all optional:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"serviceName"})," (string): Service name to use that will be used in all log statements. Defaults to ",(0,a.jsx)(t.code,{children:"service_undefined"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"defaultNamespace"})," (string): Default namespace to use for all metrics. Defaults to ",(0,a.jsx)(t.code,{children:"default_namespace"}),"."]}),"\n"]}),"\n",(0,a.jsx)(t.p,{children:"Middleware accepts the following options:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"metrics"})," (Metric) (required): An instance of the Metrics class."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"option"})," (object) (optional): An object with the following keys:","\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"throwOnEmptyMetrics"})," (boolean) (optional): Whether to throw an error if no metrics were added. Defaults to ",(0,a.jsx)(t.code,{children:"false"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"captureColdStartMetric"})," (boolean) (optional): Whether to capture the cold start metric. Defaults to ",(0,a.jsx)(t.code,{children:"true"}),"."]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,a.jsx)(t.h3,{id:"sample-usage-2",children:"Sample usage"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"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"})}),"\n",(0,a.jsx)(t.p,{children:"The above code will output a CloudWatch EMF object similar to the following:"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-json",children:'{\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'})}),"\n",(0,a.jsx)(t.p,{children:"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."}),"\n",(0,a.jsxs)(t.p,{children:["The Metrics utility supports ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#adding-high-resolution-metrics",children:"high-resolution metrics"})," as well as ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#adding-multi-value-metrics",children:"multi-value metrics"}),". It also allows you to add ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#adding-default-dimensions",children:"default dimensions"})," that are used in all the metrics emitted by your application or ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda-typescript/latest/core/metrics/#single-metric-with-different-dimensions",children:"create a one-off metric"})," with different dimensions."]}),"\n",(0,a.jsx)(t.h2,{id:"idempotency",children:"Idempotency"}),"\n",(0,a.jsx)(t.p,{children:"Key features:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsx)(t.li,{children:"Prevent Lambda handler from executing more than once on the same event payload during a time window"}),"\n",(0,a.jsx)(t.li,{children:"Ensure Lambda handler returns the same result when called with the same payload"}),"\n",(0,a.jsx)(t.li,{children:"Select a subset of the event as the idempotency key using JMESPath expressions"}),"\n",(0,a.jsx)(t.li,{children:"Set a time window in which records with the same payload should be considered duplicates"}),"\n",(0,a.jsx)(t.li,{children:"Expires in-progress executions if the Lambda function times out halfway through"}),"\n"]}),"\n",(0,a.jsx)(t.p,{children:"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."}),"\n",(0,a.jsx)(t.h3,{id:"install-3",children:"Install"}),"\n",(0,a.jsxs)(r.Z,{groupId:"npm2yarn",children:[(0,a.jsx)(o.Z,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"npm install --save @aws-lambda-powertools/idempotency @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb\n"})})}),(0,a.jsx)(o.Z,{value:"yarn",label:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"yarn add @aws-lambda-powertools/idempotency @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb\n"})})}),(0,a.jsx)(o.Z,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"pnpm add @aws-lambda-powertools/idempotency @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb\n"})})})]}),"\n",(0,a.jsx)(t.h3,{id:"options-3",children:"Options"}),"\n",(0,a.jsx)(t.p,{children:"Middleware accepts the following options:"}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"persistenceStore"})," (",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda/typescript/latest/api/classes/_aws_lambda_powertools_idempotency.persistence.BasePersistenceLayer.html",children:(0,a.jsx)(t.code,{children:"BasePersistenceLayer"})}),"): Class used to interact with a ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/idempotency/#persistence-layers",children:"persistence store"}),"."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"config"})," (",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda/typescript/latest/api/classes/_aws_lambda_powertools_idempotency.index.IdempotencyConfig.html",children:(0,a.jsx)(t.code,{children:"IdempotencyConfig"})}),") (optional): Configuration object to customize the ",(0,a.jsx)(t.a,{href:"https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/idempotency/#customizing-the-default-behavior",children:"default behavior"})," of the idempotency feature."]}),"\n"]}),"\n",(0,a.jsx)(t.h3,{id:"sample-usage-3",children:"Sample usage"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"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"})}),"\n",(0,a.jsx)(t.h2,{id:"best-practices",children:"Best practices"}),"\n",(0,a.jsx)(t.h3,{id:"using-multiple-utilities",children:"Using multiple utilities"}),"\n",(0,a.jsx)(t.p,{children:"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."}),"\n",(0,a.jsx)(t.p,{children:"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."}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"export const handler = middy(() => { /* ... */ })\n .use(captureLambdaHandler(tracer))\n .use(injectLambdaContext(logger, { logEvent: true }))\n .use(logMetrics(metrics, { captureColdStartMetric: true }));\n"})}),"\n",(0,a.jsx)(t.h3,{id:"cleaning-up-on-early-returns",children:"Cleaning up on early returns"}),"\n",(0,a.jsxs)(t.p,{children:["As discussed in the ",(0,a.jsx)(t.a,{href:"/docs/intro/early-interrupt",children:"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."]}),"\n",(0,a.jsxs)(t.p,{children:["For example, if you are using the Tracer utility, you must make sure to call the ",(0,a.jsx)(t.code,{children:"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,a.jsx)(t.code,{children:"clearMetrics"})," method so that the Metrics utility can emit the metrics that were stored in the buffer and avoid you losing any data."]}),"\n",(0,a.jsx)(t.p,{children:"Following the example described in the linked section, you can clean up all the utilities by doing the following:"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(u,{...e})}):u(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>o});n(7294);var a=n(6010);const s={tabItem:"tabItem_Ymn6"};var r=n(5893);function o(e){let{children:t,hidden:n,className:o}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,a.Z)(s.tabItem,o),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>v});var a=n(7294),s=n(6010),r=n(2466),o=n(6550),l=n(469),i=n(1980),c=n(7392),d=n(12);function h(e){return a.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function u(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??function(e){return h(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:s}}=e;return{value:t,label:n,attributes:a,default:s}}))}(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 p(e){let{queryString:t=!1,groupId:n}=e;const s=(0,o.k6)(),r=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)(r),(0,a.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(s.location.search);t.set(r,e),s.replace({...s.location,search:t.toString()})}),[r,s])]}function g(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,r=u(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 a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:r}))),[c,h]=p({queryString:n,groupId:s}),[g,x]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,r]=(0,d.Nk)(n);return[s,(0,a.useCallback)((e=>{n&&r.set(e)}),[n,r])]}({groupId:s}),f=(()=>{const e=c??g;return m({value:e,tabValues:r})?e:null})();(0,l.Z)((()=>{f&&i(f)}),[f]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);i(e),h(e),x(e)}),[h,x,r]),tabValues:r}}var x=n(2389);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=n(5893);function b(e){let{className:t,block:n,selectedValue:a,selectValue:o,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.o5)(),d=e=>{const t=e.currentTarget,n=i.indexOf(t),s=l[n].value;s!==a&&(c(t),o(s))},h=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:r}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:a===t?0:-1,"aria-selected":a===t,ref:e=>i.push(e),onKeyDown:h,onClick:d,...r,className:(0,s.Z)("tabs__item",f.tabItem,r?.className,{"tabs__item--active":a===t}),children:n??t},t)}))})}function y(e){let{lazy:t,children:n,selectedValue:s}=e;const r=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=r.find((e=>e.props.value===s));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:r.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function w(e){const t=g(e);return(0,j.jsxs)("div",{className:(0,s.Z)("tabs-container",f.tabList),children:[(0,j.jsx)(b,{...e,...t}),(0,j.jsx)(y,{...e,...t})]})}function v(e){const t=(0,x.Z)();return(0,j.jsx)(w,{...e,children:h(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>l,a:()=>o});var a=n(7294);const s={},r=a.createContext(s);function o(e){const t=a.useContext(r);return a.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),a.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/c21432a2.2489ca26.js b/assets/js/c21432a2.2177ce78.js similarity index 98% rename from assets/js/c21432a2.2489ca26.js rename to assets/js/c21432a2.2177ce78.js index 72bff993b..988baac61 100644 --- a/assets/js/c21432a2.2489ca26.js +++ b/assets/js/c21432a2.2177ce78.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1570],{1964:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>r,default:()=>m,frontMatter:()=>s,metadata:()=>i,toc:()=>l});var a=t(5893),o=t(1151);const s={title:"Streamify Response",position:5},r=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/06-streamify-response.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[{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}];function c(e){const n={a:"a",blockquote:"blockquote",code:"code",h2:"h2",h3:"h3",li:"li",ol:"ol",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.p,{children:"Middy also supports streamed responses."}),"\n",(0,a.jsxs)(n.blockquote,{children:["\n",(0,a.jsxs)(n.p,{children:["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.jsx)(n.a,{href:"https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/",children:"https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/"}),")"]}),"\n"]}),"\n",(0,a.jsxs)(n.ol,{children:["\n",(0,a.jsxs)(n.li,{children:["Set ",(0,a.jsx)(n.code,{children:"streamifyResponse: true"})," into middy options"]}),"\n",(0,a.jsx)(n.li,{children:"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."}),"\n"]}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:["API Gateway: If you're getting a ",(0,a.jsx)(n.code,{children:"500"})," status code. Be sure to set your integration to ",(0,a.jsx)(n.code,{children:"HTTP_PROXY"})," over ",(0,a.jsx)(n.code,{children:"LAMBDA_PROXY"})," and enable Function URL on the lambda."]}),"\n",(0,a.jsxs)(n.li,{children:["Function URLs: If receiving no content and non-200 status code are being converted to ",(0,a.jsx)(n.code,{children:"200"}),". Be sure to set ",(0,a.jsx)(n.code,{children:"Invoke Mode"})," to ",(0,a.jsx)(n.code,{children:"RESPONSE_STREAM"})," over ",(0,a.jsx)(n.code,{children:"BUFFERED"}),"."]}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"lambda-function-url-example",children:"Lambda Function URL Example"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport { createReadableStream } from '@datastream/core'\n\nconst lambdaHandler = (event, context) => {\n return {\n statusCode: 200,\n headers: {\n 'Content-Type': 'text/csv'\n },\n body: createReadableStream('...') // or string\n }\n}\n\nexport const handler = middy({ streamifyResponse: true }).handler(lambdaHandler)\n"})}),"\n",(0,a.jsx)(n.h2,{id:"lambda-invokewithresponsestream-example",children:"Lambda InvokeWithResponseStream Example"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport { createReadableStream } from '@datastream/core'\n\nconst lambdaHandler = (event, context) => {\n return createReadableStream('...') // or string\n}\nexport const handler = middy({ streamifyResponse: true }).handler(lambdaHandler)\n"})}),"\n",(0,a.jsx)(n.h3,{id:"requesting-lambda",children:"Requesting Lambda"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:n}={...(0,o.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(c,{...e})}):c(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>r});var a=t(7294);const o={},s=a.createContext(o);function r(e){const n=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),a.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1570],{1964:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>r,default:()=>m,frontMatter:()=>s,metadata:()=>i,toc:()=>l});var a=t(5893),o=t(1151);const s={title:"Streamify Response",position:5},r=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/06-streamify-response.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[{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}];function c(e){const n={a:"a",blockquote:"blockquote",code:"code",h2:"h2",h3:"h3",li:"li",ol:"ol",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.p,{children:"Middy also supports streamed responses."}),"\n",(0,a.jsxs)(n.blockquote,{children:["\n",(0,a.jsxs)(n.p,{children:["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.jsx)(n.a,{href:"https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/",children:"https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/"}),")"]}),"\n"]}),"\n",(0,a.jsxs)(n.ol,{children:["\n",(0,a.jsxs)(n.li,{children:["Set ",(0,a.jsx)(n.code,{children:"streamifyResponse: true"})," into middy options"]}),"\n",(0,a.jsx)(n.li,{children:"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."}),"\n"]}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:["API Gateway: If you're getting a ",(0,a.jsx)(n.code,{children:"500"})," status code. Be sure to set your integration to ",(0,a.jsx)(n.code,{children:"HTTP_PROXY"})," over ",(0,a.jsx)(n.code,{children:"LAMBDA_PROXY"})," and enable Function URL on the lambda."]}),"\n",(0,a.jsxs)(n.li,{children:["Function URLs: If receiving no content and non-200 status code are being converted to ",(0,a.jsx)(n.code,{children:"200"}),". Be sure to set ",(0,a.jsx)(n.code,{children:"Invoke Mode"})," to ",(0,a.jsx)(n.code,{children:"RESPONSE_STREAM"})," over ",(0,a.jsx)(n.code,{children:"BUFFERED"}),"."]}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"lambda-function-url-example",children:"Lambda Function URL Example"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport { createReadableStream } from '@datastream/core'\n\nconst lambdaHandler = (event, context) => {\n return {\n statusCode: 200,\n headers: {\n 'Content-Type': 'text/csv'\n },\n body: createReadableStream('...') // or string\n }\n}\n\nexport const handler = middy({ streamifyResponse: true }).handler(lambdaHandler)\n"})}),"\n",(0,a.jsx)(n.h2,{id:"lambda-invokewithresponsestream-example",children:"Lambda InvokeWithResponseStream Example"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport { createReadableStream } from '@datastream/core'\n\nconst lambdaHandler = (event, context) => {\n return createReadableStream('...') // or string\n}\nexport const handler = middy({ streamifyResponse: true }).handler(lambdaHandler)\n"})}),"\n",(0,a.jsx)(n.h3,{id:"requesting-lambda",children:"Requesting Lambda"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:n}={...(0,o.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(c,{...e})}):c(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>r});var a=t(7294);const o={},s=a.createContext(o);function r(e){const n=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),a.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/c2371ba7.0fb54ba7.js b/assets/js/c2371ba7.89556c94.js similarity index 99% rename from assets/js/c2371ba7.0fb54ba7.js rename to assets/js/c2371ba7.89556c94.js index c5aeb28eb..35e185365 100644 --- a/assets/js/c2371ba7.0fb54ba7.js +++ b/assets/js/c2371ba7.89556c94.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7724],{3675:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>h,frontMatter:()=>l,metadata:()=>d,toc:()=>u});var r=t(5893),a=t(1151),s=t(4866),i=t(5162);const l={title:"http-response-serializer"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-response-serializer.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",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}];function p(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.p,{children:"The Http Serializer middleware lets you define serialization mechanisms based on the current content negotiation."}),"\n",(0,r.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(i.Z,{value:"npm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/http-response-serializer\n"})})}),(0,r.jsx)(i.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/http-response-serializer\n"})})}),(0,r.jsx)(i.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/http-response-serializer\n"})})})]}),"\n",(0,r.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"defaultContentType"})," (optional): used if the request and handler don't specify what type is wanted."]}),"\n"]}),"\n",(0,r.jsx)(n.h2,{id:"configuration",children:"Configuration"}),"\n",(0,r.jsxs)(n.p,{children:["The middleware is configured by defining some ",(0,r.jsx)(n.code,{children:"serializers"}),"."]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"{\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"})}),"\n",(0,r.jsx)(n.h2,{id:"serializer-functions",children:"Serializer Functions"}),"\n",(0,r.jsxs)(n.p,{children:["When a matching serializer is found, the ",(0,r.jsx)(n.code,{children:"Content-Type"})," header is set and the serializer function is run."]}),"\n",(0,r.jsxs)(n.p,{children:["The function is passed the entire ",(0,r.jsx)(n.code,{children:"response"})," object, and should return either a string or an object."]}),"\n",(0,r.jsxs)(n.p,{children:["If a string is returned, the ",(0,r.jsx)(n.code,{children:"body"})," attribute of the response is updated."]}),"\n",(0,r.jsxs)(n.p,{children:["If an object with a ",(0,r.jsx)(n.code,{children:"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."]}),"\n",(0,r.jsx)(n.h2,{id:"content-type-negotiation",children:"Content Type Negotiation"}),"\n",(0,r.jsx)(n.p,{children:"The header is not the only way the middleware decides which serializer to execute."}),"\n",(0,r.jsx)(n.p,{children:"The content type is determined in the following order:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"context.requiredContentType"})," -- allows the handler to override everything else"]}),"\n",(0,r.jsxs)(n.li,{children:["The ",(0,r.jsx)(n.code,{children:"Accept"})," header via ",(0,r.jsx)(n.a,{href:"https://www.npmjs.com/package/accept",children:"accept"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"context.preferredContentType"})," -- allows the handler to override the default, but lets the request ask first"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"defaultContentType"})," middleware configuration"]}),"\n"]}),"\n",(0,r.jsxs)(n.p,{children:["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,r.jsx)(n.code,{children:"Accept"}),", an external input, it is recommended to validate that it is an expected value."]}),"\n",(0,r.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpResponseSerializer from '@middy/http-response-serializer'\n\nconst lambdaHandler = (event, context) => {\n const body = 'Hello World'\n\n return {\n statusCode: 200,\n body\n }\n}\n\nexport const handler = middy()\n .use(\n 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 )\n .handler(lambdaHandler)\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"})})]})}function h(e={}){const{wrapper:n}={...(0,a.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>i});t(7294);var r=t(6010);const a={tabItem:"tabItem_Ymn6"};var s=t(5893);function i(e){let{children:n,hidden:t,className:i}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,i),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var r=t(7294),a=t(6010),s=t(2466),i=t(6550),l=t(469),o=t(1980),d=t(7392),c=t(12);function u(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function p(e){const{values:n,children:t}=e;return(0,r.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:r,default:a}}=e;return{value:n,label:t,attributes:r,default:a}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function h(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function m(e){let{queryString:n=!1,groupId:t}=e;const a=(0,i.k6)(),s=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(s),(0,r.useCallback)((e=>{if(!s)return;const n=new URLSearchParams(a.location.search);n.set(s,e),a.replace({...a.location,search:n.toString()})}),[s,a])]}function f(e){const{defaultValue:n,queryString:t=!1,groupId:a}=e,s=p(e),[i,o]=(0,r.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!h({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const r=t.find((e=>e.default))??t[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:n,tabValues:s}))),[d,u]=m({queryString:t,groupId:a}),[f,b]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[a,s]=(0,c.Nk)(t);return[a,(0,r.useCallback)((e=>{t&&s.set(e)}),[t,s])]}({groupId:a}),x=(()=>{const e=d??f;return h({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{x&&o(x)}),[x]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,s]),tabValues:s}}var b=t(2389);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=t(5893);function g(e){let{className:n,block:t,selectedValue:r,selectValue:i,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),c=e=>{const n=e.currentTarget,t=o.indexOf(n),a=l[t].value;a!==r&&(d(n),i(a))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":t},n),children:l.map((e=>{let{value:n,label:t,attributes:s}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:r===n?0:-1,"aria-selected":r===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...s,className:(0,a.Z)("tabs__item",x.tabItem,s?.className,{"tabs__item--active":r===n}),children:t??n},n)}))})}function v(e){let{lazy:n,children:t,selectedValue:a}=e;const s=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:s.map(((e,n)=>(0,r.cloneElement)(e,{key:n,hidden:e.props.value!==a})))})}function j(e){const n=f(e);return(0,y.jsxs)("div",{className:(0,a.Z)("tabs-container",x.tabList),children:[(0,y.jsx)(g,{...e,...n}),(0,y.jsx)(v,{...e,...n})]})}function w(e){const n=(0,b.Z)();return(0,y.jsx)(j,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>l,a:()=>i});var r=t(7294);const a={},s=r.createContext(a);function i(e){const n=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:i(e.components),r.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7724],{3675:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>h,frontMatter:()=>l,metadata:()=>d,toc:()=>u});var r=t(5893),a=t(1151),s=t(4866),i=t(5162);const l={title:"http-response-serializer"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-response-serializer.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",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}];function p(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.p,{children:"The Http Serializer middleware lets you define serialization mechanisms based on the current content negotiation."}),"\n",(0,r.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(i.Z,{value:"npm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/http-response-serializer\n"})})}),(0,r.jsx)(i.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/http-response-serializer\n"})})}),(0,r.jsx)(i.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/http-response-serializer\n"})})})]}),"\n",(0,r.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"defaultContentType"})," (optional): used if the request and handler don't specify what type is wanted."]}),"\n"]}),"\n",(0,r.jsx)(n.h2,{id:"configuration",children:"Configuration"}),"\n",(0,r.jsxs)(n.p,{children:["The middleware is configured by defining some ",(0,r.jsx)(n.code,{children:"serializers"}),"."]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"{\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"})}),"\n",(0,r.jsx)(n.h2,{id:"serializer-functions",children:"Serializer Functions"}),"\n",(0,r.jsxs)(n.p,{children:["When a matching serializer is found, the ",(0,r.jsx)(n.code,{children:"Content-Type"})," header is set and the serializer function is run."]}),"\n",(0,r.jsxs)(n.p,{children:["The function is passed the entire ",(0,r.jsx)(n.code,{children:"response"})," object, and should return either a string or an object."]}),"\n",(0,r.jsxs)(n.p,{children:["If a string is returned, the ",(0,r.jsx)(n.code,{children:"body"})," attribute of the response is updated."]}),"\n",(0,r.jsxs)(n.p,{children:["If an object with a ",(0,r.jsx)(n.code,{children:"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."]}),"\n",(0,r.jsx)(n.h2,{id:"content-type-negotiation",children:"Content Type Negotiation"}),"\n",(0,r.jsx)(n.p,{children:"The header is not the only way the middleware decides which serializer to execute."}),"\n",(0,r.jsx)(n.p,{children:"The content type is determined in the following order:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"context.requiredContentType"})," -- allows the handler to override everything else"]}),"\n",(0,r.jsxs)(n.li,{children:["The ",(0,r.jsx)(n.code,{children:"Accept"})," header via ",(0,r.jsx)(n.a,{href:"https://www.npmjs.com/package/accept",children:"accept"})]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"context.preferredContentType"})," -- allows the handler to override the default, but lets the request ask first"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"defaultContentType"})," middleware configuration"]}),"\n"]}),"\n",(0,r.jsxs)(n.p,{children:["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,r.jsx)(n.code,{children:"Accept"}),", an external input, it is recommended to validate that it is an expected value."]}),"\n",(0,r.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpResponseSerializer from '@middy/http-response-serializer'\n\nconst lambdaHandler = (event, context) => {\n const body = 'Hello World'\n\n return {\n statusCode: 200,\n body\n }\n}\n\nexport const handler = middy()\n .use(\n 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 )\n .handler(lambdaHandler)\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"})})]})}function h(e={}){const{wrapper:n}={...(0,a.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>i});t(7294);var r=t(6010);const a={tabItem:"tabItem_Ymn6"};var s=t(5893);function i(e){let{children:n,hidden:t,className:i}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,i),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>w});var r=t(7294),a=t(6010),s=t(2466),i=t(6550),l=t(469),o=t(1980),d=t(7392),c=t(12);function u(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function p(e){const{values:n,children:t}=e;return(0,r.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:t,attributes:r,default:a}}=e;return{value:n,label:t,attributes:r,default:a}}))}(t);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function h(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function m(e){let{queryString:n=!1,groupId:t}=e;const a=(0,i.k6)(),s=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)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 t??null}({queryString:n,groupId:t});return[(0,o._X)(s),(0,r.useCallback)((e=>{if(!s)return;const n=new URLSearchParams(a.location.search);n.set(s,e),a.replace({...a.location,search:n.toString()})}),[s,a])]}function f(e){const{defaultValue:n,queryString:t=!1,groupId:a}=e,s=p(e),[i,o]=(0,r.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!h({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const r=t.find((e=>e.default))??t[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:n,tabValues:s}))),[d,u]=m({queryString:t,groupId:a}),[f,b]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[a,s]=(0,c.Nk)(t);return[a,(0,r.useCallback)((e=>{t&&s.set(e)}),[t,s])]}({groupId:a}),x=(()=>{const e=d??f;return h({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{x&&o(x)}),[x]);return{selectedValue:i,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,s]),tabValues:s}}var b=t(2389);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=t(5893);function g(e){let{className:n,block:t,selectedValue:r,selectValue:i,tabValues:l}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),c=e=>{const n=e.currentTarget,t=o.indexOf(n),a=l[t].value;a!==r&&(d(n),i(a))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=o.indexOf(e.currentTarget)+1;n=o[t]??o[0];break}case"ArrowLeft":{const t=o.indexOf(e.currentTarget)-1;n=o[t]??o[o.length-1];break}}n?.focus()};return(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":t},n),children:l.map((e=>{let{value:n,label:t,attributes:s}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:r===n?0:-1,"aria-selected":r===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...s,className:(0,a.Z)("tabs__item",x.tabItem,s?.className,{"tabs__item--active":r===n}),children:t??n},n)}))})}function v(e){let{lazy:n,children:t,selectedValue:a}=e;const s=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:s.map(((e,n)=>(0,r.cloneElement)(e,{key:n,hidden:e.props.value!==a})))})}function j(e){const n=f(e);return(0,y.jsxs)("div",{className:(0,a.Z)("tabs-container",x.tabList),children:[(0,y.jsx)(g,{...e,...n}),(0,y.jsx)(v,{...e,...n})]})}function w(e){const n=(0,b.Z)();return(0,y.jsx)(j,{...e,children:u(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>l,a:()=>i});var r=t(7294);const a={},s=r.createContext(a);function i(e){const n=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:i(e.components),r.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/c4fefc0c.9e140cb7.js b/assets/js/c4fefc0c.45104288.js similarity index 98% rename from assets/js/c4fefc0c.9e140cb7.js rename to assets/js/c4fefc0c.45104288.js index 7e4135ce0..31cb14f62 100644 --- a/assets/js/c4fefc0c.9e140cb7.js +++ b/assets/js/c4fefc0c.45104288.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7812],{3784:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>o,default:()=>u,frontMatter:()=>a,metadata:()=>i,toc:()=>d});var r=n(5893),s=n(1151);const a={title:"Internal Context",sidebar_position:3},o=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/03-internal-context.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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={},d=[];function l(e){const t={code:"code",p:"p",pre:"pre",...(0,s.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["Middy is built to be async even at it's core. Middlewares can set promises to ",(0,r.jsx)(t.code,{children:"internal"}),".\nThis approach allows them to be resolved together just when you need them."]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport {getInternal} from '@middy/util'\n\nconst lambdaHandler = async (event, context, { signal }) => {\n\n}\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(config)\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(lambdaHandler)\n"})})]})}function u(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>i,a:()=>o});var r=n(7294);const s={},a=r.createContext(s);function o(e){const t=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),r.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7812],{3784:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>o,default:()=>u,frontMatter:()=>a,metadata:()=>i,toc:()=>d});var r=n(5893),s=n(1151);const a={title:"Internal Context",sidebar_position:3},o=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/best-practices/03-internal-context.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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={},d=[];function l(e){const t={code:"code",p:"p",pre:"pre",...(0,s.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["Middy is built to be async even at it's core. Middlewares can set promises to ",(0,r.jsx)(t.code,{children:"internal"}),".\nThis approach allows them to be resolved together just when you need them."]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport {getInternal} from '@middy/util'\n\nconst lambdaHandler = async (event, context, { signal }) => {\n\n}\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(config)\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(lambdaHandler)\n"})})]})}function u(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>i,a:()=>o});var r=n(7294);const s={},a=r.createContext(s);function o(e){const t=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),r.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/cc16eb0f.4d3bf260.js b/assets/js/cc16eb0f.59b1d3f9.js similarity index 97% rename from assets/js/cc16eb0f.4d3bf260.js rename to assets/js/cc16eb0f.59b1d3f9.js index 7356216c8..c76b0a723 100644 --- a/assets/js/cc16eb0f.4d3bf260.js +++ b/assets/js/cc16eb0f.59b1d3f9.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5893],{9823:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>r,toc:()=>l});var s=n(5893),i=n(1151);const o={title:"Lex"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/lex.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Lex"},sidebar:"tutorialSidebar",previous:{title:"Kinesis Streams",permalink:"/docs/events/kinesis-streams"},next:{title:"MQ",permalink:"/docs/events/mq"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-lex.html",children:"Using AWS Lambda with Amazon Lex"})}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html",children:"Using an AWS Lambda function"})," with Amazon Lex V2"]}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var s=n(7294);const i={},o=s.createContext(i);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[5893],{9823:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>r,toc:()=>l});var s=n(5893),i=n(1151);const o={title:"Lex"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/lex.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Lex"},sidebar:"tutorialSidebar",previous:{title:"Kinesis Streams",permalink:"/docs/events/kinesis-streams"},next:{title:"MQ",permalink:"/docs/events/mq"}},d={},l=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function c(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.admonition,{type:"caution",children:(0,s.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,s.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-lex.html",children:"Using AWS Lambda with Amazon Lex"})}),"\n",(0,s.jsxs)(t.li,{children:[(0,s.jsx)(t.a,{href:"https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html",children:"Using an AWS Lambda function"})," with Amazon Lex V2"]}),"\n"]}),"\n",(0,s.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var s=n(7294);const i={},o=s.createContext(i);function a(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/cd47eedf.79840171.js b/assets/js/cd47eedf.9c13bbc4.js similarity index 97% rename from assets/js/cd47eedf.79840171.js rename to assets/js/cd47eedf.9c13bbc4.js index 344e4b59a..b260586ff 100644 --- a/assets/js/cd47eedf.79840171.js +++ b/assets/js/cd47eedf.9c13bbc4.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4388],{8852:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>d,contentTitle:()=>a,default:()=>p,frontMatter:()=>s,metadata:()=>i,toc:()=>l});var t=n(5893),o=n(1151);const s={title:"Handling Errors",position:5},a=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/05-handling-errors.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[];function c(e){const r={code:"code",p:"p",pre:"pre",...(0,o.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(r.p,{children:"But, what happens when there is an error?"}),"\n",(0,t.jsxs)(r.p,{children:["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,t.jsx)(r.code,{children:"onError"}),", following\nthe same order as ",(0,t.jsx)(r.code,{children:"after"}),"."]}),"\n",(0,t.jsxs)(r.p,{children:["Every ",(0,t.jsx)(r.code,{children:"onError"})," middleware can decide to handle the error and create a proper response or\nto delegate the error to the next middleware."]}),"\n",(0,t.jsx)(r.p,{children:"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."}),"\n",(0,t.jsx)(r.p,{children:"If no middleware manages the error, the Lambda execution fails reporting the unmanaged error."}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-javascript",children:"// 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"})})]})}function p(e={}){const{wrapper:r}={...(0,o.a)(),...e.components};return r?(0,t.jsx)(r,{...e,children:(0,t.jsx)(c,{...e})}):c(e)}},1151:(e,r,n)=>{n.d(r,{Z:()=>i,a:()=>a});var t=n(7294);const o={},s=t.createContext(o);function a(e){const r=t.useContext(s);return t.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function i(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),t.createElement(s.Provider,{value:r},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4388],{8852:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>d,contentTitle:()=>a,default:()=>p,frontMatter:()=>s,metadata:()=>i,toc:()=>l});var t=n(5893),o=n(1151);const s={title:"Handling Errors",position:5},a=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/05-handling-errors.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[];function c(e){const r={code:"code",p:"p",pre:"pre",...(0,o.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(r.p,{children:"But, what happens when there is an error?"}),"\n",(0,t.jsxs)(r.p,{children:["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,t.jsx)(r.code,{children:"onError"}),", following\nthe same order as ",(0,t.jsx)(r.code,{children:"after"}),"."]}),"\n",(0,t.jsxs)(r.p,{children:["Every ",(0,t.jsx)(r.code,{children:"onError"})," middleware can decide to handle the error and create a proper response or\nto delegate the error to the next middleware."]}),"\n",(0,t.jsx)(r.p,{children:"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."}),"\n",(0,t.jsx)(r.p,{children:"If no middleware manages the error, the Lambda execution fails reporting the unmanaged error."}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-javascript",children:"// 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"})})]})}function p(e={}){const{wrapper:r}={...(0,o.a)(),...e.components};return r?(0,t.jsx)(r,{...e,children:(0,t.jsx)(c,{...e})}):c(e)}},1151:(e,r,n)=>{n.d(r,{Z:()=>i,a:()=>a});var t=n(7294);const o={},s=t.createContext(o);function a(e){const r=t.useContext(s);return t.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function i(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),t.createElement(s.Provider,{value:r},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/ce7003dc.662df6b1.js b/assets/js/ce7003dc.ec6ac700.js similarity index 98% rename from assets/js/ce7003dc.662df6b1.js rename to assets/js/ce7003dc.ec6ac700.js index 43e2a0595..6acb5d0f9 100644 --- a/assets/js/ce7003dc.662df6b1.js +++ b/assets/js/ce7003dc.ec6ac700.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9071],{1884:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>o,default:()=>m,frontMatter:()=>s,metadata:()=>d,toc:()=>l});var r=t(5893),i=t(1151);const s={title:"Inline Middlewares",position:3},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/03-inline-middlewares.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},a={},l=[];function c(e){const n={code:"code",p:"p",pre:"pre",strong:"strong",...(0,i.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.p,{children:["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,r.jsx)(n.code,{children:"before"}),", ",(0,r.jsx)(n.code,{children:"after"})," or ",(0,r.jsx)(n.code,{children:"onError"}),")."]}),"\n",(0,r.jsxs)(n.p,{children:["In these cases you can use ",(0,r.jsx)(n.strong,{children:"inline middlewares"})," which are shortcut functions to hook\nlogic into Middy's control flow."]}),"\n",(0,r.jsx)(n.p,{children:"Let's see how inline middlewares work with a simple example:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nconst lambdaHandler = (event, context) => {\n // do stuff\n}\n\nexport const handler = middy()\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 .handler(lambdaHandler)\n"})}),"\n",(0,r.jsxs)(n.p,{children:["As you can see above, a middy instance also exposes the ",(0,r.jsx)(n.code,{children:"before"}),", ",(0,r.jsx)(n.code,{children:"after"})," and ",(0,r.jsx)(n.code,{children:"onError"}),"\nmethods to allow you to quickly hook in simple inline middlewares."]})]})}function m(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>d,a:()=>o});var r=t(7294);const i={},s=r.createContext(i);function o(e){const n=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),r.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9071],{1884:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>o,default:()=>m,frontMatter:()=>s,metadata:()=>d,toc:()=>l});var r=t(5893),i=t(1151);const s={title:"Inline Middlewares",position:3},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/03-inline-middlewares.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},a={},l=[];function c(e){const n={code:"code",p:"p",pre:"pre",strong:"strong",...(0,i.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.p,{children:["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,r.jsx)(n.code,{children:"before"}),", ",(0,r.jsx)(n.code,{children:"after"})," or ",(0,r.jsx)(n.code,{children:"onError"}),")."]}),"\n",(0,r.jsxs)(n.p,{children:["In these cases you can use ",(0,r.jsx)(n.strong,{children:"inline middlewares"})," which are shortcut functions to hook\nlogic into Middy's control flow."]}),"\n",(0,r.jsx)(n.p,{children:"Let's see how inline middlewares work with a simple example:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nconst lambdaHandler = (event, context) => {\n // do stuff\n}\n\nexport const handler = middy()\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 .handler(lambdaHandler)\n"})}),"\n",(0,r.jsxs)(n.p,{children:["As you can see above, a middy instance also exposes the ",(0,r.jsx)(n.code,{children:"before"}),", ",(0,r.jsx)(n.code,{children:"after"})," and ",(0,r.jsx)(n.code,{children:"onError"}),"\nmethods to allow you to quickly hook in simple inline middlewares."]})]})}function m(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>d,a:()=>o});var r=t(7294);const i={},s=r.createContext(i);function o(e){const n=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),r.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d0953a14.7e6317fb.js b/assets/js/d0953a14.cf7a4dd6.js similarity index 99% rename from assets/js/d0953a14.7e6317fb.js rename to assets/js/d0953a14.cf7a4dd6.js index 7cba583ef..eb40685b3 100644 --- a/assets/js/d0953a14.7e6317fb.js +++ b/assets/js/d0953a14.cf7a4dd6.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4740],{217:(e,n,a)=>{a.r(n),a.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>m,frontMatter:()=>i,metadata:()=>d,toc:()=>u});var t=a(5893),r=a(1151),s=a(4866),l=a(5162);const i={title:"validator"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/validator.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"validator"},sidebar:"tutorialSidebar",previous:{title:"sts",permalink:"/docs/middlewares/sts"},next:{title:"warmup",permalink:"/docs/middlewares/warmup"}},c={},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}];function h(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:["This middleware automatically validates incoming events and outgoing responses against custom\nschemas defined with the ",(0,t.jsx)(n.a,{href:"http://json-schema.org/",children:"JSON schema syntax"}),"."]}),"\n",(0,t.jsx)(n.p,{children:"Want to use another validator? Try one of the community validators:"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.a,{href:"https://www.npmjs.com/package/middy-ajv",children:"ajv"})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.a,{href:"https://www.npmjs.com/package/middy-sparks-joi",children:"middy-sparks-joi"})}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:["If an incoming event fails validation a ",(0,t.jsx)(n.code,{children:"BadRequest"})," error is raised.\nIf an outgoing response fails validation a ",(0,t.jsx)(n.code,{children:"InternalServerError"})," error is\nraised."]}),"\n",(0,t.jsxs)(n.p,{children:["This middleware can be used in combination with\n",(0,t.jsx)(n.a,{href:"#httperrorhandler",children:(0,t.jsx)(n.code,{children:"httpErrorHandler"})})," to automatically return the right\nresponse to the user."]}),"\n",(0,t.jsxs)(n.p,{children:["It can also be used in combination with ",(0,t.jsx)(n.a,{href:"#httpContentNegotiation",children:(0,t.jsx)(n.code,{children:"http-content-negotiation"})})," to load localized translations for the error messages (based on the currently requested language). This feature uses internally ",(0,t.jsx)(n.a,{href:"http://npm.im/ajv-ftl-i18n",children:(0,t.jsx)(n.code,{children:"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,t.jsx)(n.code,{children:"en"}),"), but you can redefine the default language by passing it in the ",(0,t.jsx)(n.code,{children:"ajvOptions"})," options with the key ",(0,t.jsx)(n.code,{children:"defaultLanguage"})," and specifying as value one of the ",(0,t.jsx)(n.a,{href:"https://www.npmjs.com/package/ajv-i18n#supported-locales",children:"supported locales"}),"."]}),"\n",(0,t.jsxs)(n.p,{children:["Also, this middleware accepts an object with plugins to be applied to customize the internal ",(0,t.jsx)(n.code,{children:"ajv"})," instance."]}),"\n",(0,t.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,t.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,t.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,t.jsx)(l.Z,{value:"npm",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/validator\nnpm install --save-dev ajv-cmd # Optional: for pre-transpiling\n"})})}),(0,t.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/validator\nyarn add --dev ajv-cmd # Optional: for pre-transpiling\n"})})}),(0,t.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/validator\npnpm add --save-dev ajv-cmd # Optional: for pre-transpiling\n"})})})]}),"\n",(0,t.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"eventSchema"})," (function) (default ",(0,t.jsx)(n.code,{children:"undefined"}),"): The compiled ajv validator that will be used\nto validate the input (",(0,t.jsx)(n.code,{children:"request.event"}),") of the Lambda handler."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"contextSchema"})," (function) (default ",(0,t.jsx)(n.code,{children:"undefined"}),"): The compiled ajv validator that will be used\nto validate the input (",(0,t.jsx)(n.code,{children:"request.context"}),") of the Lambda handler. Has additional support for ",(0,t.jsx)(n.code,{children:"typeof"})," keyword to allow validation of ",(0,t.jsx)(n.code,{children:'"typeof":"function"'}),"."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"responseSchema"})," (function) (default ",(0,t.jsx)(n.code,{children:"undefined"}),"): The compiled ajv validator that will be used\nto validate the output (",(0,t.jsx)(n.code,{children:"request.response"}),") of the Lambda handler."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"i18nEnabled"})," (boolean) (default ",(0,t.jsx)(n.code,{children:"true"}),"): Option to disable i18n default package."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"defaultLanguage"})," (string) (default ",(0,t.jsx)(n.code,{children:"en"}),"): When language not found, what language to fallback to."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"languages"})," (object) (default: ",(0,t.jsx)(n.code,{children:"{}"}),"): Localization overrides"]}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"NOTES:"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["At least one of ",(0,t.jsx)(n.code,{children:"eventSchema"})," or ",(0,t.jsx)(n.code,{children:"responseSchema"})," is required."]}),"\n",(0,t.jsxs)(n.li,{children:["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,t.jsx)(n.code,{children:"request.error.cause.data"}),", the original response can be found at ",(0,t.jsx)(n.code,{children:"request.error.response"}),"."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.strong,{children:"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."]}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"transpileschema",children:"transpileSchema"}),"\n",(0,t.jsxs)(n.p,{children:["Transpile JSON-Schema in to JavaScript. Default ajv plugins used: ",(0,t.jsx)(n.code,{children:"ajv-i18n"}),", ",(0,t.jsx)(n.code,{children:"ajv-formats"}),", ",(0,t.jsx)(n.code,{children:"ajv-formats-draft2019"}),", ",(0,t.jsx)(n.code,{children:"ajv-keywords"}),", ",(0,t.jsx)(n.code,{children:"ajv-errors"}),"."]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"schema"})," (object) (required): JSON-Schema object"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"ajvOptions"})," (object) (default ",(0,t.jsx)(n.code,{children:"undefined"}),"): Options to pass to ",(0,t.jsx)(n.a,{href:"https://ajv.js.org/docs/api.html#options",children:"ajv"}),"\nclass constructor. Defaults are ",(0,t.jsx)(n.code,{children:"{ strict: true, coerceTypes: 'array', allErrors: true, useDefaults: 'empty', messages: true }"}),"."]}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"transpilelocale",children:"transpileLocale"}),"\n",(0,t.jsxs)(n.p,{children:["Transpile Fluent (.ftl) localization file into ajv compatible format. Allows the overriding of the default messages and adds support for multi-language ",(0,t.jsx)(n.code,{children:"errrorMessages"}),"."]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"ftl"})," (string) (required): Contents of an ftl file to be transpiled."]}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,t.jsx)(n.p,{children:"Example for event validation:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport validator from '@middy/validator'\nimport { transpileSchema } from '@middy/validator/transpile'\n\nconst lambdaHandler = (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\nexport const handler = middy()\n .use(\n validator({\n eventSchema: transpileSchema(schema)\n })\n )\n .handler(lambdaHandler)\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"})}),"\n",(0,t.jsx)(n.p,{children:"Example for response validation:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport validator from '@middy/validator'\nimport { transpileSchema } from '@middy/validator/transpile'\n\nconst lambdaHandler = (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\nexport const handler = middy()\n .use(validator({ responseSchema }))\n .handler(lambdaHandler)\n\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"})}),"\n",(0,t.jsx)(n.p,{children:"Example for body validation:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"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 lambdaHandler = (event, context) => {\n return {}\n}\n\nconst eventSchema = {\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\nexport const handler = middy()\n // to validate the body we need to parse it first\n .use(httpJsonBodyParser())\n .use(\n validator({\n eventSchema: transpileSchema(eventSchema)\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,t.jsx)(n.h2,{id:"pre-transpiling-example-recommended",children:"Pre-transpiling example (recommended)"}),"\n",(0,t.jsx)(n.p,{children:"Run a build script to before running tests & deployment."}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"#!/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"})}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"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\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .use(\n validator({\n eventSchema,\n languages: { en, fr }\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,t.jsx)(n.h2,{id:"transpile-during-cold-start",children:"Transpile during cold-start"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"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 lambdaHandler = (event, context) => {\n return {}\n}\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(lambdaHandler)\n"})}),"\n",(0,t.jsx)(n.h2,{id:"transpile-during-cold-start-with-default-messages",children:"Transpile during cold-start with default messages"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"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\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .use(\n validator({\n eventSchema: transpileSchema(eventSchema),\n languages: { en, fr }\n })\n )\n .handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(h,{...e})}):h(e)}},5162:(e,n,a)=>{a.d(n,{Z:()=>l});a(7294);var t=a(6010);const r={tabItem:"tabItem_Ymn6"};var s=a(5893);function l(e){let{children:n,hidden:a,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,t.Z)(r.tabItem,l),hidden:a,children:n})}},4866:(e,n,a)=>{a.d(n,{Z:()=>w});var t=a(7294),r=a(6010),s=a(2466),l=a(6550),i=a(469),o=a(1980),d=a(7392),c=a(12);function u(e){return t.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:a}=e;return(0,t.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:a,attributes:t,default:r}}=e;return{value:n,label:a,attributes:t,default:r}}))}(a);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,a])}function m(e){let{value:n,tabValues:a}=e;return a.some((e=>e.value===n))}function p(e){let{queryString:n=!1,groupId:a}=e;const r=(0,l.k6)(),s=function(e){let{queryString:n=!1,groupId:a}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!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:n,groupId:a});return[(0,o._X)(s),(0,t.useCallback)((e=>{if(!s)return;const n=new URLSearchParams(r.location.search);n.set(s,e),r.replace({...r.location,search:n.toString()})}),[s,r])]}function f(e){const{defaultValue:n,queryString:a=!1,groupId:r}=e,s=h(e),[l,o]=(0,t.useState)((()=>function(e){let{defaultValue:n,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" 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 n}const t=a.find((e=>e.default))??a[0];if(!t)throw new Error("Unexpected error: 0 tabValues");return t.value}({defaultValue:n,tabValues:s}))),[d,u]=p({queryString:a,groupId:r}),[f,v]=function(e){let{groupId:n}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,s]=(0,c.Nk)(a);return[r,(0,t.useCallback)((e=>{a&&s.set(e)}),[a,s])]}({groupId:r}),j=(()=>{const e=d??f;return m({value:e,tabValues:s})?e:null})();(0,i.Z)((()=>{j&&o(j)}),[j]);return{selectedValue:l,selectValue:(0,t.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),v(e)}),[u,v,s]),tabValues:s}}var v=a(2389);const j={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=a(5893);function g(e){let{className:n,block:a,selectedValue:t,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),c=e=>{const n=e.currentTarget,a=o.indexOf(n),r=i[a].value;r!==t&&(d(n),l(r))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const a=o.indexOf(e.currentTarget)+1;n=o[a]??o[0];break}case"ArrowLeft":{const a=o.indexOf(e.currentTarget)-1;n=o[a]??o[o.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":a},n),children:i.map((e=>{let{value:n,label:a,attributes:s}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:t===n?0:-1,"aria-selected":t===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...s,className:(0,r.Z)("tabs__item",j.tabItem,s?.className,{"tabs__item--active":t===n}),children:a??n},n)}))})}function b(e){let{lazy:n,children:a,selectedValue:r}=e;const s=(Array.isArray(a)?a:[a]).filter(Boolean);if(n){const e=s.find((e=>e.props.value===r));return e?(0,t.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:s.map(((e,n)=>(0,t.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function y(e){const n=f(e);return(0,x.jsxs)("div",{className:(0,r.Z)("tabs-container",j.tabList),children:[(0,x.jsx)(g,{...e,...n}),(0,x.jsx)(b,{...e,...n})]})}function w(e){const n=(0,v.Z)();return(0,x.jsx)(y,{...e,children:u(e.children)},String(n))}},1151:(e,n,a)=>{a.d(n,{Z:()=>i,a:()=>l});var t=a(7294);const r={},s=t.createContext(r);function l(e){const n=t.useContext(s);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:l(e.components),t.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4740],{217:(e,n,a)=>{a.r(n),a.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>m,frontMatter:()=>i,metadata:()=>d,toc:()=>u});var t=a(5893),r=a(1151),s=a(4866),l=a(5162);const i={title:"validator"},o=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/validator.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"validator"},sidebar:"tutorialSidebar",previous:{title:"sts",permalink:"/docs/middlewares/sts"},next:{title:"warmup",permalink:"/docs/middlewares/warmup"}},c={},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}];function h(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:["This middleware automatically validates incoming events and outgoing responses against custom\nschemas defined with the ",(0,t.jsx)(n.a,{href:"http://json-schema.org/",children:"JSON schema syntax"}),"."]}),"\n",(0,t.jsx)(n.p,{children:"Want to use another validator? Try one of the community validators:"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.a,{href:"https://www.npmjs.com/package/middy-ajv",children:"ajv"})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.a,{href:"https://www.npmjs.com/package/middy-sparks-joi",children:"middy-sparks-joi"})}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:["If an incoming event fails validation a ",(0,t.jsx)(n.code,{children:"BadRequest"})," error is raised.\nIf an outgoing response fails validation a ",(0,t.jsx)(n.code,{children:"InternalServerError"})," error is\nraised."]}),"\n",(0,t.jsxs)(n.p,{children:["This middleware can be used in combination with\n",(0,t.jsx)(n.a,{href:"#httperrorhandler",children:(0,t.jsx)(n.code,{children:"httpErrorHandler"})})," to automatically return the right\nresponse to the user."]}),"\n",(0,t.jsxs)(n.p,{children:["It can also be used in combination with ",(0,t.jsx)(n.a,{href:"#httpContentNegotiation",children:(0,t.jsx)(n.code,{children:"http-content-negotiation"})})," to load localized translations for the error messages (based on the currently requested language). This feature uses internally ",(0,t.jsx)(n.a,{href:"http://npm.im/ajv-ftl-i18n",children:(0,t.jsx)(n.code,{children:"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,t.jsx)(n.code,{children:"en"}),"), but you can redefine the default language by passing it in the ",(0,t.jsx)(n.code,{children:"ajvOptions"})," options with the key ",(0,t.jsx)(n.code,{children:"defaultLanguage"})," and specifying as value one of the ",(0,t.jsx)(n.a,{href:"https://www.npmjs.com/package/ajv-i18n#supported-locales",children:"supported locales"}),"."]}),"\n",(0,t.jsxs)(n.p,{children:["Also, this middleware accepts an object with plugins to be applied to customize the internal ",(0,t.jsx)(n.code,{children:"ajv"})," instance."]}),"\n",(0,t.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,t.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,t.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,t.jsx)(l.Z,{value:"npm",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/validator\nnpm install --save-dev ajv-cmd # Optional: for pre-transpiling\n"})})}),(0,t.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"yarn add @middy/validator\nyarn add --dev ajv-cmd # Optional: for pre-transpiling\n"})})}),(0,t.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"pnpm add @middy/validator\npnpm add --save-dev ajv-cmd # Optional: for pre-transpiling\n"})})})]}),"\n",(0,t.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"eventSchema"})," (function) (default ",(0,t.jsx)(n.code,{children:"undefined"}),"): The compiled ajv validator that will be used\nto validate the input (",(0,t.jsx)(n.code,{children:"request.event"}),") of the Lambda handler."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"contextSchema"})," (function) (default ",(0,t.jsx)(n.code,{children:"undefined"}),"): The compiled ajv validator that will be used\nto validate the input (",(0,t.jsx)(n.code,{children:"request.context"}),") of the Lambda handler. Has additional support for ",(0,t.jsx)(n.code,{children:"typeof"})," keyword to allow validation of ",(0,t.jsx)(n.code,{children:'"typeof":"function"'}),"."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"responseSchema"})," (function) (default ",(0,t.jsx)(n.code,{children:"undefined"}),"): The compiled ajv validator that will be used\nto validate the output (",(0,t.jsx)(n.code,{children:"request.response"}),") of the Lambda handler."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"i18nEnabled"})," (boolean) (default ",(0,t.jsx)(n.code,{children:"true"}),"): Option to disable i18n default package."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"defaultLanguage"})," (string) (default ",(0,t.jsx)(n.code,{children:"en"}),"): When language not found, what language to fallback to."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"languages"})," (object) (default: ",(0,t.jsx)(n.code,{children:"{}"}),"): Localization overrides"]}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"NOTES:"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["At least one of ",(0,t.jsx)(n.code,{children:"eventSchema"})," or ",(0,t.jsx)(n.code,{children:"responseSchema"})," is required."]}),"\n",(0,t.jsxs)(n.li,{children:["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,t.jsx)(n.code,{children:"request.error.cause.data"}),", the original response can be found at ",(0,t.jsx)(n.code,{children:"request.error.response"}),"."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.strong,{children:"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."]}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"transpileschema",children:"transpileSchema"}),"\n",(0,t.jsxs)(n.p,{children:["Transpile JSON-Schema in to JavaScript. Default ajv plugins used: ",(0,t.jsx)(n.code,{children:"ajv-i18n"}),", ",(0,t.jsx)(n.code,{children:"ajv-formats"}),", ",(0,t.jsx)(n.code,{children:"ajv-formats-draft2019"}),", ",(0,t.jsx)(n.code,{children:"ajv-keywords"}),", ",(0,t.jsx)(n.code,{children:"ajv-errors"}),"."]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"schema"})," (object) (required): JSON-Schema object"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"ajvOptions"})," (object) (default ",(0,t.jsx)(n.code,{children:"undefined"}),"): Options to pass to ",(0,t.jsx)(n.a,{href:"https://ajv.js.org/docs/api.html#options",children:"ajv"}),"\nclass constructor. Defaults are ",(0,t.jsx)(n.code,{children:"{ strict: true, coerceTypes: 'array', allErrors: true, useDefaults: 'empty', messages: true }"}),"."]}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"transpilelocale",children:"transpileLocale"}),"\n",(0,t.jsxs)(n.p,{children:["Transpile Fluent (.ftl) localization file into ajv compatible format. Allows the overriding of the default messages and adds support for multi-language ",(0,t.jsx)(n.code,{children:"errrorMessages"}),"."]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"ftl"})," (string) (required): Contents of an ftl file to be transpiled."]}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,t.jsx)(n.p,{children:"Example for event validation:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport validator from '@middy/validator'\nimport { transpileSchema } from '@middy/validator/transpile'\n\nconst lambdaHandler = (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\nexport const handler = middy()\n .use(\n validator({\n eventSchema: transpileSchema(schema)\n })\n )\n .handler(lambdaHandler)\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"})}),"\n",(0,t.jsx)(n.p,{children:"Example for response validation:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport validator from '@middy/validator'\nimport { transpileSchema } from '@middy/validator/transpile'\n\nconst lambdaHandler = (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\nexport const handler = middy()\n .use(validator({ responseSchema }))\n .handler(lambdaHandler)\n\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"})}),"\n",(0,t.jsx)(n.p,{children:"Example for body validation:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"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 lambdaHandler = (event, context) => {\n return {}\n}\n\nconst eventSchema = {\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\nexport const handler = middy()\n // to validate the body we need to parse it first\n .use(httpJsonBodyParser())\n .use(\n validator({\n eventSchema: transpileSchema(eventSchema)\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,t.jsx)(n.h2,{id:"pre-transpiling-example-recommended",children:"Pre-transpiling example (recommended)"}),"\n",(0,t.jsx)(n.p,{children:"Run a build script to before running tests & deployment."}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"#!/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"})}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"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\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .use(\n validator({\n eventSchema,\n languages: { en, fr }\n })\n )\n .handler(lambdaHandler)\n"})}),"\n",(0,t.jsx)(n.h2,{id:"transpile-during-cold-start",children:"Transpile during cold-start"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"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 lambdaHandler = (event, context) => {\n return {}\n}\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(lambdaHandler)\n"})}),"\n",(0,t.jsx)(n.h2,{id:"transpile-during-cold-start-with-default-messages",children:"Transpile during cold-start with default messages"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"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\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .use(\n validator({\n eventSchema: transpileSchema(eventSchema),\n languages: { en, fr }\n })\n )\n .handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(h,{...e})}):h(e)}},5162:(e,n,a)=>{a.d(n,{Z:()=>l});a(7294);var t=a(6010);const r={tabItem:"tabItem_Ymn6"};var s=a(5893);function l(e){let{children:n,hidden:a,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,t.Z)(r.tabItem,l),hidden:a,children:n})}},4866:(e,n,a)=>{a.d(n,{Z:()=>w});var t=a(7294),r=a(6010),s=a(2466),l=a(6550),i=a(469),o=a(1980),d=a(7392),c=a(12);function u(e){return t.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(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)??[]}function h(e){const{values:n,children:a}=e;return(0,t.useMemo)((()=>{const e=n??function(e){return u(e).map((e=>{let{props:{value:n,label:a,attributes:t,default:r}}=e;return{value:n,label:a,attributes:t,default:r}}))}(a);return function(e){const n=(0,d.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,a])}function m(e){let{value:n,tabValues:a}=e;return a.some((e=>e.value===n))}function p(e){let{queryString:n=!1,groupId:a}=e;const r=(0,l.k6)(),s=function(e){let{queryString:n=!1,groupId:a}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!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:n,groupId:a});return[(0,o._X)(s),(0,t.useCallback)((e=>{if(!s)return;const n=new URLSearchParams(r.location.search);n.set(s,e),r.replace({...r.location,search:n.toString()})}),[s,r])]}function f(e){const{defaultValue:n,queryString:a=!1,groupId:r}=e,s=h(e),[l,o]=(0,t.useState)((()=>function(e){let{defaultValue:n,tabValues:a}=e;if(0===a.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:a}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" 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 n}const t=a.find((e=>e.default))??a[0];if(!t)throw new Error("Unexpected error: 0 tabValues");return t.value}({defaultValue:n,tabValues:s}))),[d,u]=p({queryString:a,groupId:r}),[f,v]=function(e){let{groupId:n}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,s]=(0,c.Nk)(a);return[r,(0,t.useCallback)((e=>{a&&s.set(e)}),[a,s])]}({groupId:r}),j=(()=>{const e=d??f;return m({value:e,tabValues:s})?e:null})();(0,i.Z)((()=>{j&&o(j)}),[j]);return{selectedValue:l,selectValue:(0,t.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),v(e)}),[u,v,s]),tabValues:s}}var v=a(2389);const j={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=a(5893);function g(e){let{className:n,block:a,selectedValue:t,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:d}=(0,s.o5)(),c=e=>{const n=e.currentTarget,a=o.indexOf(n),r=i[a].value;r!==t&&(d(n),l(r))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const a=o.indexOf(e.currentTarget)+1;n=o[a]??o[0];break}case"ArrowLeft":{const a=o.indexOf(e.currentTarget)-1;n=o[a]??o[o.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":a},n),children:i.map((e=>{let{value:n,label:a,attributes:s}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:t===n?0:-1,"aria-selected":t===n,ref:e=>o.push(e),onKeyDown:u,onClick:c,...s,className:(0,r.Z)("tabs__item",j.tabItem,s?.className,{"tabs__item--active":t===n}),children:a??n},n)}))})}function b(e){let{lazy:n,children:a,selectedValue:r}=e;const s=(Array.isArray(a)?a:[a]).filter(Boolean);if(n){const e=s.find((e=>e.props.value===r));return e?(0,t.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:s.map(((e,n)=>(0,t.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function y(e){const n=f(e);return(0,x.jsxs)("div",{className:(0,r.Z)("tabs-container",j.tabList),children:[(0,x.jsx)(g,{...e,...n}),(0,x.jsx)(b,{...e,...n})]})}function w(e){const n=(0,v.Z)();return(0,x.jsx)(y,{...e,children:u(e.children)},String(n))}},1151:(e,n,a)=>{a.d(n,{Z:()=>i,a:()=>l});var t=a(7294);const r={},s=t.createContext(r);function l(e){const n=t.useContext(s);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:l(e.components),t.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d80baa5c.ab51e3fa.js b/assets/js/d80baa5c.bb37b4b8.js similarity index 98% rename from assets/js/d80baa5c.ab51e3fa.js rename to assets/js/d80baa5c.bb37b4b8.js index 58017806f..f10f09660 100644 --- a/assets/js/d80baa5c.ab51e3fa.js +++ b/assets/js/d80baa5c.bb37b4b8.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9647],{6592:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>o,default:()=>u,frontMatter:()=>a,metadata:()=>i,toc:()=>d});var s=n(5893),r=n(1151);const a={title:"Internal Storage",position:4},o=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/04-internal-storage.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},c={},d=[];function l(e){const t={code:"code",p:"p",pre:"pre",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The handler also contains an ",(0,s.jsx)(t.code,{children:"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,s.jsx)(t.code,{children:"before"})," these promises can be stored into ",(0,s.jsx)(t.code,{children:"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."]}),"\n",(0,s.jsx)(t.p,{children:"Here is a middleware boilerplate using this pattern:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function u(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>i,a:()=>o});var s=n(7294);const r={},a=s.createContext(r);function o(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9647],{6592:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>o,default:()=>u,frontMatter:()=>a,metadata:()=>i,toc:()=>d});var s=n(5893),r=n(1151);const a={title:"Internal Storage",position:4},o=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/writing-middlewares/04-internal-storage.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},c={},d=[];function l(e){const t={code:"code",p:"p",pre:"pre",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["The handler also contains an ",(0,s.jsx)(t.code,{children:"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,s.jsx)(t.code,{children:"before"})," these promises can be stored into ",(0,s.jsx)(t.code,{children:"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."]}),"\n",(0,s.jsx)(t.p,{children:"Here is a middleware boilerplate using this pattern:"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function u(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>i,a:()=>o});var s=n(7294);const r={},a=s.createContext(r);function o(e){const t=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),s.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/da0b5c8a.0de36f7f.js b/assets/js/da0b5c8a.78f38714.js similarity index 99% rename from assets/js/da0b5c8a.0de36f7f.js rename to assets/js/da0b5c8a.78f38714.js index a2126b32e..fcb1bf9ef 100644 --- a/assets/js/da0b5c8a.0de36f7f.js +++ b/assets/js/da0b5c8a.78f38714.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7796],{8029:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>m,frontMatter:()=>s,metadata:()=>d,toc:()=>c});var r=n(5893),a=n(1151),o=n(4866),l=n(5162);const s={title:"do-not-wait-for-empty-event-loop"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/do-not-wait-for-empty-event-loop.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["This middleware sets ",(0,r.jsx)(t.code,{children:"context.callbackWaitsForEmptyEventLoop"})," property to ",(0,r.jsx)(t.code,{children:"false"}),".\nThis will prevent Lambda from timing out because of open database connections, etc."]}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(o.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(l.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/do-not-wait-for-empty-event-loop\n"})})}),(0,r.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/do-not-wait-for-empty-event-loop\n"})})}),(0,r.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/do-not-wait-for-empty-event-loop\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(t.p,{children:["By default the middleware sets the ",(0,r.jsx)(t.code,{children:"callbackWaitsForEmptyEventLoop"})," property to ",(0,r.jsx)(t.code,{children:"false"})," only in the ",(0,r.jsx)(t.code,{children:"before"})," phase,\nmeaning you can override it in handler to ",(0,r.jsx)(t.code,{children:"true"})," if needed. You can set it in all steps with the options:"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"runOnBefore"})," (defaults to ",(0,r.jsx)(t.code,{children:"true"}),") - sets property before running your handler"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"runOnAfter"})," (defaults to ",(0,r.jsx)(t.code,{children:"false"}),")"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"runOnError"})," (defaults to ",(0,r.jsx)(t.code,{children:"false"}),")"]}),"\n"]}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport doNotWaitForEmptyEventLoop from '@middy/do-not-wait-for-empty-event-loop'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .use(doNotWaitForEmptyEventLoop({ runOnError: true }))\n .handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>l});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var o=n(5893);function l(e){let{children:t,hidden:n,className:l}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,l),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>g});var r=n(7294),a=n(6010),o=n(2466),l=n(6550),s=n(469),i=n(1980),d=n(7392),u=n(12);function c(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(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 h(e){let{queryString:t=!1,groupId:n}=e;const a=(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,i._X)(o),(0,r.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:n=!1,groupId:a}=e,o=p(e),[l,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 r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[d,c]=h({queryString:n,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,o]=(0,u.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:a}),v=(()=>{const e=d??f;return m({value:e,tabValues:o})?e:null})();(0,s.Z)((()=>{v&&i(v)}),[v]);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),b(e)}),[c,b,o]),tabValues:o}}var b=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=n(5893);function x(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:s}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,o.o5)(),u=e=>{const t=e.currentTarget,n=i.indexOf(t),a=s[n].value;a!==r&&(d(t),l(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:s.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:c,onClick:u,...o,className:(0,a.Z)("tabs__item",v.tabItem,o?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function w(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function j(e){const t=f(e);return(0,y.jsxs)("div",{className:(0,a.Z)("tabs-container",v.tabList),children:[(0,y.jsx)(x,{...e,...t}),(0,y.jsx)(w,{...e,...t})]})}function g(e){const t=(0,b.Z)();return(0,y.jsx)(j,{...e,children:c(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>s,a:()=>l});var r=n(7294);const a={},o=r.createContext(a);function l(e){const t=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),r.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7796],{8029:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>i,default:()=>m,frontMatter:()=>s,metadata:()=>d,toc:()=>c});var r=n(5893),a=n(1151),o=n(4866),l=n(5162);const s={title:"do-not-wait-for-empty-event-loop"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/do-not-wait-for-empty-event-loop.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},u={},c=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function p(e){const t={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["This middleware sets ",(0,r.jsx)(t.code,{children:"context.callbackWaitsForEmptyEventLoop"})," property to ",(0,r.jsx)(t.code,{children:"false"}),".\nThis will prevent Lambda from timing out because of open database connections, etc."]}),"\n",(0,r.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,r.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,r.jsxs)(o.Z,{groupId:"npm2yarn",children:[(0,r.jsx)(l.Z,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/do-not-wait-for-empty-event-loop\n"})})}),(0,r.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/do-not-wait-for-empty-event-loop\n"})})}),(0,r.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/do-not-wait-for-empty-event-loop\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,r.jsxs)(t.p,{children:["By default the middleware sets the ",(0,r.jsx)(t.code,{children:"callbackWaitsForEmptyEventLoop"})," property to ",(0,r.jsx)(t.code,{children:"false"})," only in the ",(0,r.jsx)(t.code,{children:"before"})," phase,\nmeaning you can override it in handler to ",(0,r.jsx)(t.code,{children:"true"})," if needed. You can set it in all steps with the options:"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"runOnBefore"})," (defaults to ",(0,r.jsx)(t.code,{children:"true"}),") - sets property before running your handler"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"runOnAfter"})," (defaults to ",(0,r.jsx)(t.code,{children:"false"}),")"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.code,{children:"runOnError"})," (defaults to ",(0,r.jsx)(t.code,{children:"false"}),")"]}),"\n"]}),"\n",(0,r.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport doNotWaitForEmptyEventLoop from '@middy/do-not-wait-for-empty-event-loop'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy()\n .use(doNotWaitForEmptyEventLoop({ runOnError: true }))\n .handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>l});n(7294);var r=n(6010);const a={tabItem:"tabItem_Ymn6"};var o=n(5893);function l(e){let{children:t,hidden:n,className:l}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,l),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>g});var r=n(7294),a=n(6010),o=n(2466),l=n(6550),s=n(469),i=n(1980),d=n(7392),u=n(12);function c(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(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 h(e){let{queryString:t=!1,groupId:n}=e;const a=(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,i._X)(o),(0,r.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:n=!1,groupId:a}=e,o=p(e),[l,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 r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[d,c]=h({queryString:n,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,o]=(0,u.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:a}),v=(()=>{const e=d??f;return m({value:e,tabValues:o})?e:null})();(0,s.Z)((()=>{v&&i(v)}),[v]);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),b(e)}),[c,b,o]),tabValues:o}}var b=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=n(5893);function x(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:s}=e;const i=[],{blockElementScrollPositionUntilNextRender:d}=(0,o.o5)(),u=e=>{const t=e.currentTarget,n=i.indexOf(t),a=s[n].value;a!==r&&(d(t),l(a))},c=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:s.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:c,onClick:u,...o,className:(0,a.Z)("tabs__item",v.tabItem,o?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function w(e){let{lazy:t,children:n,selectedValue:a}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function j(e){const t=f(e);return(0,y.jsxs)("div",{className:(0,a.Z)("tabs-container",v.tabList),children:[(0,y.jsx)(x,{...e,...t}),(0,y.jsx)(w,{...e,...t})]})}function g(e){const t=(0,b.Z)();return(0,y.jsx)(j,{...e,children:c(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>s,a:()=>l});var r=n(7294);const a={},o=r.createContext(a);function l(e){const t=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),r.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/dbc9373d.2213d515.js b/assets/js/dbc9373d.627c9070.js similarity index 99% rename from assets/js/dbc9373d.2213d515.js rename to assets/js/dbc9373d.627c9070.js index c7e450373..0a6995782 100644 --- a/assets/js/dbc9373d.2213d515.js +++ b/assets/js/dbc9373d.627c9070.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9116],{1660:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var n=r(5893),a=r(1151),s=r(4866),l=r(5162);const i={title:"http-security-headers"},o=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-security-headers.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["Applies best practice security headers to responses. It's a simplified port of HelmetJS. See ",(0,n.jsx)(t.a,{href:"https://helmetjs.github.io/",children:"HelmetJS"})," documentation for more details."]}),"\n",(0,n.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(l.Z,{value:"npm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-security-headers\n"})})}),(0,n.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-security-headers\n"})})}),(0,n.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-security-headers\n"})})})]}),"\n",(0,n.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"dnsPrefetchControl"})," controls browser DNS prefetching"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"expectCt"})," for handling Certificate Transparency (Future Feature)"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"frameguard"})," to prevent clickjacking"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"hidePoweredBy"})," to remove the Server/X-Powered-By header"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"hsts"})," for HTTP Strict Transport Security"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"ieNoOpen"})," sets X-Download-Options for IE8+"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"noSniff"})," to keep clients from sniffing the MIME type"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"referrerPolicy"})," to hide the Referer header"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"xssFilter"})," adds some small XSS protections"]}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpSecurityHeaders from '@middy/http-security-headers'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy().use(httpSecurityHeaders()).handler(lambdaHandler)\n"})})]})}function p(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},5162:(e,t,r)=>{r.d(t,{Z:()=>l});r(7294);var n=r(6010);const a={tabItem:"tabItem_Ymn6"};var s=r(5893);function l(e){let{children:t,hidden:r,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,n.Z)(a.tabItem,l),hidden:r,children:t})}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var n=r(7294),a=r(6010),s=r(2466),l=r(6550),i=r(469),o=r(1980),c=r(7392),d=r(12);function u(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function h(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}(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 m(e){let{queryString:t=!1,groupId:r}=e;const a=(0,l.k6)(),s=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,o._X)(s),(0,n.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,s=h(e),[l,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(!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 n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:s}))),[c,u]=m({queryString:r,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,d.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&s.set(e)}),[r,s])]}({groupId:a}),y=(()=>{const e=c??f;return p({value:e,tabValues:s})?e:null})();(0,i.Z)((()=>{y&&o(y)}),[y]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,s]),tabValues:s}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=r(5893);function x(e){let{className:t,block:r,selectedValue:n,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.o5)(),d=e=>{const t=e.currentTarget,r=o.indexOf(t),a=i[r].value;a!==n&&(c(t),l(a))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const r=o.indexOf(e.currentTarget)+1;t=o[r]??o[0];break}case"ArrowLeft":{const r=o.indexOf(e.currentTarget)-1;t=o[r]??o[o.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":r},t),children:i.map((e=>{let{value:t,label:r,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>o.push(e),onKeyDown:u,onClick:d,...s,className:(0,a.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":n===t}),children:r??t},t)}))})}function j(e){let{lazy:t,children:r,selectedValue:a}=e;const s=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function g(e){const t=f(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",y.tabList),children:[(0,v.jsx)(x,{...e,...t}),(0,v.jsx)(j,{...e,...t})]})}function w(e){const t=(0,b.Z)();return(0,v.jsx)(g,{...e,children:u(e.children)},String(t))}},1151:(e,t,r)=>{r.d(t,{Z:()=>i,a:()=>l});var n=r(7294);const a={},s=n.createContext(a);function l(e){const t=n.useContext(s);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),n.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9116],{1660:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>p,frontMatter:()=>i,metadata:()=>c,toc:()=>u});var n=r(5893),a=r(1151),s=r(4866),l=r(5162);const i={title:"http-security-headers"},o=void 0,c={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-security-headers.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},u=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["Applies best practice security headers to responses. It's a simplified port of HelmetJS. See ",(0,n.jsx)(t.a,{href:"https://helmetjs.github.io/",children:"HelmetJS"})," documentation for more details."]}),"\n",(0,n.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(l.Z,{value:"npm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-security-headers\n"})})}),(0,n.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-security-headers\n"})})}),(0,n.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-security-headers\n"})})})]}),"\n",(0,n.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"dnsPrefetchControl"})," controls browser DNS prefetching"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"expectCt"})," for handling Certificate Transparency (Future Feature)"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"frameguard"})," to prevent clickjacking"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"hidePoweredBy"})," to remove the Server/X-Powered-By header"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"hsts"})," for HTTP Strict Transport Security"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"ieNoOpen"})," sets X-Download-Options for IE8+"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"noSniff"})," to keep clients from sniffing the MIME type"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"referrerPolicy"})," to hide the Referer header"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"xssFilter"})," adds some small XSS protections"]}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpSecurityHeaders from '@middy/http-security-headers'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nexport const handler = middy().use(httpSecurityHeaders()).handler(lambdaHandler)\n"})})]})}function p(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},5162:(e,t,r)=>{r.d(t,{Z:()=>l});r(7294);var n=r(6010);const a={tabItem:"tabItem_Ymn6"};var s=r(5893);function l(e){let{children:t,hidden:r,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,n.Z)(a.tabItem,l),hidden:r,children:t})}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var n=r(7294),a=r(6010),s=r(2466),l=r(6550),i=r(469),o=r(1980),c=r(7392),d=r(12);function u(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function h(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}(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 m(e){let{queryString:t=!1,groupId:r}=e;const a=(0,l.k6)(),s=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,o._X)(s),(0,n.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,s=h(e),[l,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(!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 n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:s}))),[c,u]=m({queryString:r,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,d.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&s.set(e)}),[r,s])]}({groupId:a}),y=(()=>{const e=c??f;return p({value:e,tabValues:s})?e:null})();(0,i.Z)((()=>{y&&o(y)}),[y]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),b(e)}),[u,b,s]),tabValues:s}}var b=r(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=r(5893);function x(e){let{className:t,block:r,selectedValue:n,selectValue:l,tabValues:i}=e;const o=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.o5)(),d=e=>{const t=e.currentTarget,r=o.indexOf(t),a=i[r].value;a!==n&&(c(t),l(a))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const r=o.indexOf(e.currentTarget)+1;t=o[r]??o[0];break}case"ArrowLeft":{const r=o.indexOf(e.currentTarget)-1;t=o[r]??o[o.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":r},t),children:i.map((e=>{let{value:t,label:r,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>o.push(e),onKeyDown:u,onClick:d,...s,className:(0,a.Z)("tabs__item",y.tabItem,s?.className,{"tabs__item--active":n===t}),children:r??t},t)}))})}function j(e){let{lazy:t,children:r,selectedValue:a}=e;const s=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function g(e){const t=f(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",y.tabList),children:[(0,v.jsx)(x,{...e,...t}),(0,v.jsx)(j,{...e,...t})]})}function w(e){const t=(0,b.Z)();return(0,v.jsx)(g,{...e,children:u(e.children)},String(t))}},1151:(e,t,r)=>{r.d(t,{Z:()=>i,a:()=>l});var n=r(7294);const a={},s=n.createContext(a);function l(e){const t=n.useContext(s);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),n.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/e0fb88b0.5d442774.js b/assets/js/e0fb88b0.7c8be2e6.js similarity index 99% rename from assets/js/e0fb88b0.5d442774.js rename to assets/js/e0fb88b0.7c8be2e6.js index 555cb1ae2..59ae59788 100644 --- a/assets/js/e0fb88b0.5d442774.js +++ b/assets/js/e0fb88b0.7c8be2e6.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4288],{4903:(e,i,s)=>{s.r(i),s.d(i,{assets:()=>o,contentTitle:()=>a,default:()=>h,frontMatter:()=>n,metadata:()=>d,toc:()=>l});var r=s(5893),t=s(1151);const n={title:"Third-party middlewares",sidebar_position:100},a=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/third-party.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},o={},l=[{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}];function c(e){const i={a:"a",code:"code",h2:"h2",li:"li",p:"p",ul:"ul",...(0,t.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(i.p,{children:["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,r.jsx)(i.a,{href:"https://github.com/middyjs/middy/pulls",children:"open a Pull Request"}),"."]}),"\n",(0,r.jsx)(i.h2,{id:"version-2x---4x",children:"Version 2.x - 4.x"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://github.com/getndazn/dazn-lambda-powertools",children:"dazn-lambda-powertools"}),": A collection of middlewares, AWS clients and helper libraries that make working with lambda easier."]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-ajv",children:"middy-ajv"}),": AJV validator optimized for performance"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://github.com/serkan-ozal/middy-console-logger",children:"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."]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://github.com/serkan-ozal/middy-event-loop-tracer",children:"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."]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-idempotent",children:"middy-idempotent"}),": idempotency middleware for middy"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://github.com/serkan-ozal/middy-invocation",children:"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,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-lesslog",children:"middy-lesslog"}),": Middleware for ",(0,r.jsx)(i.code,{children:"lesslog"}),", a teeny-tiny and severless-ready logging utility"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-jsonapi",children:"middy-jsonapi"}),": JSONAPI middleware for middy"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-lesslog",children:"middy-lesslog"}),": Middleware for ",(0,r.jsx)(i.code,{children:"lesslog"}),", a teeny-tiny and severless-ready logging utility"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://github.com/serkan-ozal/middy-profiler",children:"middy-profiler"}),": Middleware for profiling CPU on AWS Lambda during invocation and shows what methods/modules consume what percent of CPU time"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-rds",children:"middy-rds"}),": Creates RDS connection using ",(0,r.jsx)(i.code,{children:"knex"})," or ",(0,r.jsx)(i.code,{children:"pg"})]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-recaptcha",children:"middy-recaptcha"}),": reCAPTCHA validation middleware"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-sparks-joi",children:"middy-sparks-joi"}),": Joi validator"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@iress/middy-http-path-router",children:"@iress/middy-http-path-router"}),": Routes AWS API Gateway events to handlers based on static and dynamic paths"]}),"\n"]}),"\n",(0,r.jsx)(i.h2,{id:"version-2x---3x",children:"Version 2.x - 3.x"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsxs)(i.li,{children:["\n",(0,r.jsxs)(i.p,{children:[(0,r.jsx)(i.a,{href:"https://github.com/awslabs/aws-lambda-powertools-typescript",children:"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"]}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger/#capturing-lambda-context-info",children:"logger"}),": Structured logging made easier, and a middleware to enrich log items with key details of the Lambda context"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics/#middy-middleware",children:"metrics"}),": Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/",children:"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."]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer/#lambda-handler",children:"tracer"}),": Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(i.h2,{id:"version-1x",children:"Version 1.x"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-redis",children:"middy-redis"}),": Redis connection middleware"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-extractor",children:"middy-extractor"}),": Extracts data from events using expressions"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@keboola/middy-error-logger",children:"@keboola/middy-error-logger"}),": middleware that catches thrown exceptions and rejected promises and logs them comprehensibly to the console"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@keboola/middy-event-validator",children:"@keboola/middy-event-validator"}),": Joi powered event validation middleware"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-reroute",children:"middy-reroute"}),": provides complex redirect, rewrite and proxying capabilities by simply placing a rules file into your S3 bucket"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middytohof",children:"middytohof"}),": Convert Middy middleware plugins to higher-order functions returning lambda handlers"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/wrap-ware",children:"wrap-ware"}),": A middleware wrapper which works with promises / async"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-middleware-warmup",children:"middy-middleware-warmup"}),": A middy plugin to help keep your Lambdas warm during Winter"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@sharecover-co/middy-aws-xray-tracing",children:"@sharecover-co/middy-aws-xray-tracing"}),": AWS X-Ray Tracing Middleware"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@sharecover-co/middy-http-response-serializer",children:"@sharecover-co/middy-http-response-serializer"}),": This middleware serializes the response to JSON and wraps it in a 200 HTTP response"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@seedrs/middyjs-middleware",children:"@seedrs/middyjs-middleware"}),": Collection of useful middlewares"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-autoproxyresponse",children:"middy-autoproxyresponse"}),": A middleware that lets you return simple JavaScript objects from Lambda function handlers and converts them into LAMBDA_PROXY responses"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-middleware-jwt-auth",children:"jwt-auth"}),": JSON web token authorization middleware based on ",(0,r.jsx)(i.code,{children:"express-jwt"})]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-mongoose-connector",children:"middy-mongoose-connector"}),": MongoDB connection middleware for ",(0,r.jsx)(i.a,{href:"https://mongoosejs.com/",children:"mongoose.js"})]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@ematipico/middy-request-response",children:"@ematipico/middy-request-response"}),": a middleware that creates a pair of request/response objects"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@marcosantonocito/middy-cognito-permission",children:"@marcosantonocito/middy-cognito-permission"}),": Authorization and roles permission management for the Middy framework that works with Amazon Cognito"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-env",children:"middy-env"}),": Fetch, validate and type cast environment variables"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://github.com/Eomm/sqs-json-body-parser",children:"sqs-json-body-parser"}),": Parse the SQS body to JSON"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-lesslog/v/legacy",children:"middy-lesslog"}),": Middleware for ",(0,r.jsx)(i.code,{children:"lesslog"}),", a teeny-tiny and severless-ready logging utility"]}),"\n"]})]})}function h(e={}){const{wrapper:i}={...(0,t.a)(),...e.components};return i?(0,r.jsx)(i,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},1151:(e,i,s)=>{s.d(i,{Z:()=>d,a:()=>a});var r=s(7294);const t={},n=r.createContext(t);function a(e){const i=r.useContext(n);return r.useMemo((function(){return"function"==typeof e?e(i):{...i,...e}}),[i,e])}function d(e){let i;return i=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:a(e.components),r.createElement(n.Provider,{value:i},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4288],{4903:(e,i,s)=>{s.r(i),s.d(i,{assets:()=>o,contentTitle:()=>a,default:()=>h,frontMatter:()=>n,metadata:()=>d,toc:()=>l});var r=s(5893),t=s(1151);const n={title:"Third-party middlewares",sidebar_position:100},a=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/third-party.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},o={},l=[{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}];function c(e){const i={a:"a",code:"code",h2:"h2",li:"li",p:"p",ul:"ul",...(0,t.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(i.p,{children:["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,r.jsx)(i.a,{href:"https://github.com/middyjs/middy/pulls",children:"open a Pull Request"}),"."]}),"\n",(0,r.jsx)(i.h2,{id:"version-2x---4x",children:"Version 2.x - 4.x"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://github.com/getndazn/dazn-lambda-powertools",children:"dazn-lambda-powertools"}),": A collection of middlewares, AWS clients and helper libraries that make working with lambda easier."]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-ajv",children:"middy-ajv"}),": AJV validator optimized for performance"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://github.com/serkan-ozal/middy-console-logger",children:"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."]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://github.com/serkan-ozal/middy-event-loop-tracer",children:"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."]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-idempotent",children:"middy-idempotent"}),": idempotency middleware for middy"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://github.com/serkan-ozal/middy-invocation",children:"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,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-lesslog",children:"middy-lesslog"}),": Middleware for ",(0,r.jsx)(i.code,{children:"lesslog"}),", a teeny-tiny and severless-ready logging utility"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-jsonapi",children:"middy-jsonapi"}),": JSONAPI middleware for middy"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-lesslog",children:"middy-lesslog"}),": Middleware for ",(0,r.jsx)(i.code,{children:"lesslog"}),", a teeny-tiny and severless-ready logging utility"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://github.com/serkan-ozal/middy-profiler",children:"middy-profiler"}),": Middleware for profiling CPU on AWS Lambda during invocation and shows what methods/modules consume what percent of CPU time"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-rds",children:"middy-rds"}),": Creates RDS connection using ",(0,r.jsx)(i.code,{children:"knex"})," or ",(0,r.jsx)(i.code,{children:"pg"})]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-recaptcha",children:"middy-recaptcha"}),": reCAPTCHA validation middleware"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-sparks-joi",children:"middy-sparks-joi"}),": Joi validator"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@iress/middy-http-path-router",children:"@iress/middy-http-path-router"}),": Routes AWS API Gateway events to handlers based on static and dynamic paths"]}),"\n"]}),"\n",(0,r.jsx)(i.h2,{id:"version-2x---3x",children:"Version 2.x - 3.x"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsxs)(i.li,{children:["\n",(0,r.jsxs)(i.p,{children:[(0,r.jsx)(i.a,{href:"https://github.com/awslabs/aws-lambda-powertools-typescript",children:"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"]}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger/#capturing-lambda-context-info",children:"logger"}),": Structured logging made easier, and a middleware to enrich log items with key details of the Lambda context"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics/#middy-middleware",children:"metrics"}),": Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/",children:"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."]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer/#lambda-handler",children:"tracer"}),": Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(i.h2,{id:"version-1x",children:"Version 1.x"}),"\n",(0,r.jsxs)(i.ul,{children:["\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-redis",children:"middy-redis"}),": Redis connection middleware"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-extractor",children:"middy-extractor"}),": Extracts data from events using expressions"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@keboola/middy-error-logger",children:"@keboola/middy-error-logger"}),": middleware that catches thrown exceptions and rejected promises and logs them comprehensibly to the console"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@keboola/middy-event-validator",children:"@keboola/middy-event-validator"}),": Joi powered event validation middleware"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-reroute",children:"middy-reroute"}),": provides complex redirect, rewrite and proxying capabilities by simply placing a rules file into your S3 bucket"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middytohof",children:"middytohof"}),": Convert Middy middleware plugins to higher-order functions returning lambda handlers"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/wrap-ware",children:"wrap-ware"}),": A middleware wrapper which works with promises / async"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-middleware-warmup",children:"middy-middleware-warmup"}),": A middy plugin to help keep your Lambdas warm during Winter"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@sharecover-co/middy-aws-xray-tracing",children:"@sharecover-co/middy-aws-xray-tracing"}),": AWS X-Ray Tracing Middleware"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@sharecover-co/middy-http-response-serializer",children:"@sharecover-co/middy-http-response-serializer"}),": This middleware serializes the response to JSON and wraps it in a 200 HTTP response"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@seedrs/middyjs-middleware",children:"@seedrs/middyjs-middleware"}),": Collection of useful middlewares"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-autoproxyresponse",children:"middy-autoproxyresponse"}),": A middleware that lets you return simple JavaScript objects from Lambda function handlers and converts them into LAMBDA_PROXY responses"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-middleware-jwt-auth",children:"jwt-auth"}),": JSON web token authorization middleware based on ",(0,r.jsx)(i.code,{children:"express-jwt"})]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-mongoose-connector",children:"middy-mongoose-connector"}),": MongoDB connection middleware for ",(0,r.jsx)(i.a,{href:"https://mongoosejs.com/",children:"mongoose.js"})]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@ematipico/middy-request-response",children:"@ematipico/middy-request-response"}),": a middleware that creates a pair of request/response objects"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/@marcosantonocito/middy-cognito-permission",children:"@marcosantonocito/middy-cognito-permission"}),": Authorization and roles permission management for the Middy framework that works with Amazon Cognito"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-env",children:"middy-env"}),": Fetch, validate and type cast environment variables"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://github.com/Eomm/sqs-json-body-parser",children:"sqs-json-body-parser"}),": Parse the SQS body to JSON"]}),"\n",(0,r.jsxs)(i.li,{children:[(0,r.jsx)(i.a,{href:"https://www.npmjs.com/package/middy-lesslog/v/legacy",children:"middy-lesslog"}),": Middleware for ",(0,r.jsx)(i.code,{children:"lesslog"}),", a teeny-tiny and severless-ready logging utility"]}),"\n"]})]})}function h(e={}){const{wrapper:i}={...(0,t.a)(),...e.components};return i?(0,r.jsx)(i,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},1151:(e,i,s)=>{s.d(i,{Z:()=>d,a:()=>a});var r=s(7294);const t={},n=r.createContext(t);function a(e){const i=r.useContext(n);return r.useMemo((function(){return"function"==typeof e?e(i):{...i,...e}}),[i,e])}function d(e){let i;return i=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:a(e.components),r.createElement(n.Provider,{value:i},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/e1c77d88.474a5a04.js b/assets/js/e1c77d88.901a8a24.js similarity index 97% rename from assets/js/e1c77d88.474a5a04.js rename to assets/js/e1c77d88.901a8a24.js index a3df729e2..8e4e8f356 100644 --- a/assets/js/e1c77d88.474a5a04.js +++ b/assets/js/e1c77d88.901a8a24.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6388],{3571:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>c,frontMatter:()=>a,metadata:()=>s,toc:()=>d});var r=o(5893),n=o(1151);const a={title:"Apollo Server"},i=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/apollo-server.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},l={},d=[];function p(e){const t={admonition:"admonition",code:"code",p:"p",pre:"pre",...(0,n.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.admonition,{type:"caution",children:(0,r.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"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().handler(graphQL.createHandler())\n"})})]})}function c(e={}){const{wrapper:t}={...(0,n.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},1151:(e,t,o)=>{o.d(t,{Z:()=>s,a:()=>i});var r=o(7294);const n={},a=r.createContext(n);function i(e){const t=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:i(e.components),r.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6388],{3571:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>c,frontMatter:()=>a,metadata:()=>s,toc:()=>d});var r=o(5893),n=o(1151);const a={title:"Apollo Server"},i=void 0,s={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/integrations/apollo-server.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},l={},d=[];function p(e){const t={admonition:"admonition",code:"code",p:"p",pre:"pre",...(0,n.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.admonition,{type:"caution",children:(0,r.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-javascript",children:"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().handler(graphQL.createHandler())\n"})})]})}function c(e={}){const{wrapper:t}={...(0,n.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},1151:(e,t,o)=>{o.d(t,{Z:()=>s,a:()=>i});var r=o(7294);const n={},a=r.createContext(n);function i(e){const t=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:i(e.components),r.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/ea2a30f2.99e73e03.js b/assets/js/ea2a30f2.d5afcb0b.js similarity index 98% rename from assets/js/ea2a30f2.99e73e03.js rename to assets/js/ea2a30f2.d5afcb0b.js index 46b2b0884..0052184ff 100644 --- a/assets/js/ea2a30f2.99e73e03.js +++ b/assets/js/ea2a30f2.d5afcb0b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[527],{6831:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>h,frontMatter:()=>o,metadata:()=>a,toc:()=>l});var i=n(5893),s=n(1151);const o={title:"Testing",position:5},r=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/06-testing.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[];function c(e){const t={admonition:"admonition",code:"code",li:"li",ol:"ol",p:"p",pre:"pre",...(0,s.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.admonition,{type:"caution",children:(0,i.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(t.p,{children:"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:"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Set ",(0,i.jsx)(t.code,{children:"middy(handler, { timeoutEarlyInMillis: 0 })"})," to alternatively disable the creation of the AbortController."]}),"\n",(0,i.jsxs)(t.li,{children:["Set ",(0,i.jsx)(t.code,{children:"middy(handler, { timeoutEarlyResponse: () => {} })"})," to disable the timeout error from being thrown using a no-op."]}),"\n",(0,i.jsxs)(t.li,{children:["Set ",(0,i.jsx)(t.code,{children:"context.getRemainingTimeInMillis = falsy"})," to disable the creation of the AbortController."]}),"\n"]}),"\n",(0,i.jsxs)(t.p,{children:["When using Middy ",(0,i.jsx)(t.code,{children:"cache"})," and ",(0,i.jsx)(t.code,{children:"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.jsx)(t.code,{children:"options"})," fields as follows:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"{\n cache: false,\n cacheExpiry: 0,\n ...\n}\n"})}),"\n",(0,i.jsx)(t.p,{children:"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."}),"\n",(0,i.jsx)(t.p,{children:"An example of a message generated by Jest unit tests and which signals the need for this is as follows:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"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"})})]})}function h(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>a,a:()=>r});var i=n(7294);const s={},o=i.createContext(s);function r(e){const t=i.useContext(o);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),i.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[527],{6831:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>r,default:()=>h,frontMatter:()=>o,metadata:()=>a,toc:()=>l});var i=n(5893),s=n(1151);const o={title:"Testing",position:5},r=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/06-testing.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},l=[];function c(e){const t={admonition:"admonition",code:"code",li:"li",ol:"ol",p:"p",pre:"pre",...(0,s.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.admonition,{type:"caution",children:(0,i.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,i.jsx)(t.p,{children:"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:"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Set ",(0,i.jsx)(t.code,{children:"middy(handler, { timeoutEarlyInMillis: 0 })"})," to alternatively disable the creation of the AbortController."]}),"\n",(0,i.jsxs)(t.li,{children:["Set ",(0,i.jsx)(t.code,{children:"middy(handler, { timeoutEarlyResponse: () => {} })"})," to disable the timeout error from being thrown using a no-op."]}),"\n",(0,i.jsxs)(t.li,{children:["Set ",(0,i.jsx)(t.code,{children:"context.getRemainingTimeInMillis = falsy"})," to disable the creation of the AbortController."]}),"\n"]}),"\n",(0,i.jsxs)(t.p,{children:["When using Middy ",(0,i.jsx)(t.code,{children:"cache"})," and ",(0,i.jsx)(t.code,{children:"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.jsx)(t.code,{children:"options"})," fields as follows:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"{\n cache: false,\n cacheExpiry: 0,\n ...\n}\n"})}),"\n",(0,i.jsx)(t.p,{children:"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."}),"\n",(0,i.jsx)(t.p,{children:"An example of a message generated by Jest unit tests and which signals the need for this is as follows:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"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"})})]})}function h(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>a,a:()=>r});var i=n(7294);const s={},o=i.createContext(s);function r(e){const t=i.useContext(o);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),i.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/ec96ff11.563bae6b.js b/assets/js/ec96ff11.0acc771b.js similarity index 96% rename from assets/js/ec96ff11.563bae6b.js rename to assets/js/ec96ff11.0acc771b.js index cf249a6c1..a012578eb 100644 --- a/assets/js/ec96ff11.563bae6b.js +++ b/assets/js/ec96ff11.0acc771b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7276],{1415:(t,e,i)=>{i.r(e),i.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>l,frontMatter:()=>s,metadata:()=>a,toc:()=>d});var n=i(5893),o=i(1151);const s={title:"Utilities"},r=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/08-utilities.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:8,frontMatter:{title:"Utilities"},sidebar:"tutorialSidebar",previous:{title:"Influence",permalink:"/docs/intro/influence"},next:{title:"Release Cycle",permalink:"/docs/intro/release-cycle"}},c={},d=[];function u(t){const e={admonition:"admonition",p:"p",...(0,o.a)(),...t.components};return(0,n.jsx)(e.admonition,{type:"caution",children:(0,n.jsx)(e.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})})}function l(t={}){const{wrapper:e}={...(0,o.a)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.jsx)(u,{...t})}):u(t)}},1151:(t,e,i)=>{i.d(e,{Z:()=>a,a:()=>r});var n=i(7294);const o={},s=n.createContext(o);function r(t){const e=n.useContext(s);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function a(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:r(t.components),n.createElement(s.Provider,{value:e},t.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[7276],{1415:(t,e,i)=>{i.r(e),i.d(e,{assets:()=>c,contentTitle:()=>r,default:()=>l,frontMatter:()=>s,metadata:()=>a,toc:()=>d});var n=i(5893),o=i(1151);const s={title:"Utilities"},r=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/08-utilities.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",sidebarPosition:8,frontMatter:{title:"Utilities"},sidebar:"tutorialSidebar",previous:{title:"Influence",permalink:"/docs/intro/influence"},next:{title:"Release Cycle",permalink:"/docs/intro/release-cycle"}},c={},d=[];function u(t){const e={admonition:"admonition",p:"p",...(0,o.a)(),...t.components};return(0,n.jsx)(e.admonition,{type:"caution",children:(0,n.jsx)(e.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})})}function l(t={}){const{wrapper:e}={...(0,o.a)(),...t.components};return e?(0,n.jsx)(e,{...t,children:(0,n.jsx)(u,{...t})}):u(t)}},1151:(t,e,i)=>{i.d(e,{Z:()=>a,a:()=>r});var n=i(7294);const o={},s=n.createContext(o);function r(t){const e=n.useContext(s);return n.useMemo((function(){return"function"==typeof t?t(e):{...e,...t}}),[e,t])}function a(t){let e;return e=t.disableParentContext?"function"==typeof t.components?t.components(o):t.components||o:r(t.components),n.createElement(s.Provider,{value:e},t.children)}}}]); \ No newline at end of file diff --git a/assets/js/ecbeea21.66be3876.js b/assets/js/ecbeea21.2e9a8125.js similarity index 99% rename from assets/js/ecbeea21.66be3876.js rename to assets/js/ecbeea21.2e9a8125.js index a1516f6fb..96901477a 100644 --- a/assets/js/ecbeea21.66be3876.js +++ b/assets/js/ecbeea21.2e9a8125.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9310],{6432:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var i=t(5893),r=t(1151);const o={sidebar_position:1,title:"Introduction",slug:"/"},a=void 0,s={id:"intro/intro",title:"Introduction",description:"What is middy",source:"@site/docs/intro/01-intro.md",sourceDirName:"intro",slug:"/",permalink:"/docs/",draft:!1,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/01-intro.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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}];function c(e){const n={a:"a",code:"code",em:"em",h2:"h2",p:"p",pre:"pre",strong:"strong",...(0,r.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h2,{id:"what-is-middy",children:"What is middy"}),"\n",(0,i.jsxs)(n.p,{children:["Middy is a very simple ",(0,i.jsx)(n.strong,{children:"middleware engine"})," that allows you to simplify your ",(0,i.jsx)(n.strong,{children:"AWS Lambda"})," code when using ",(0,i.jsx)(n.strong,{children:"Node.js"}),"."]}),"\n",(0,i.jsx)(n.p,{children:"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."}),"\n",(0,i.jsx)(n.p,{children:"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."}),"\n",(0,i.jsx)(n.h2,{id:"a-quick-example",children:"A quick example"}),"\n",(0,i.jsx)(n.p,{children:"Code is better than 10,000 words, so let's jump into an example."}),"\n",(0,i.jsx)(n.p,{children:"Let's assume you are building a JSON API to process a payment:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-javascript",metastring:'title="handler.js"',children:"// 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\nexport const 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"})}),"\n",(0,i.jsx)(n.h2,{id:"why",children:"Why?"}),"\n",(0,i.jsx)(n.p,{children:"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."}),"\n",(0,i.jsx)(n.p,{children:"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."}),"\n",(0,i.jsx)(n.p,{children:"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."}),"\n",(0,i.jsxs)(n.p,{children:["In other contexts, like generic web frameworks (",(0,i.jsx)(n.a,{href:"http://fastify.io",children:"fastify"}),", ",(0,i.jsx)(n.a,{href:"https://hapijs.com/",children:"hapi"}),", ",(0,i.jsx)(n.a,{href:"http://expressjs.com/",children:"express"}),", etc.), this\nproblem has been solved using the ",(0,i.jsx)(n.a,{href:"https://www.packtpub.com/mapt/book/web_development/9781783287314/4/ch04lvl1sec33/middleware",children:"middleware pattern"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:["This pattern allows developers to isolate these common technical concerns into\n",(0,i.jsx)(n.em,{children:'"steps"'})," that ",(0,i.jsx)(n.em,{children:"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."]}),"\n",(0,i.jsx)(n.p,{children:"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."})]})}function m(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>s,a:()=>a});var i=t(7294);const r={},o=i.createContext(r);function a(e){const n=i.useContext(o);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function s(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),i.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[9310],{6432:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>a,default:()=>m,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var i=t(5893),r=t(1151);const o={sidebar_position:1,title:"Introduction",slug:"/"},a=void 0,s={id:"intro/intro",title:"Introduction",description:"What is middy",source:"@site/docs/intro/01-intro.md",sourceDirName:"intro",slug:"/",permalink:"/docs/",draft:!1,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/01-intro.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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}];function c(e){const n={a:"a",code:"code",em:"em",h2:"h2",p:"p",pre:"pre",strong:"strong",...(0,r.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h2,{id:"what-is-middy",children:"What is middy"}),"\n",(0,i.jsxs)(n.p,{children:["Middy is a very simple ",(0,i.jsx)(n.strong,{children:"middleware engine"})," that allows you to simplify your ",(0,i.jsx)(n.strong,{children:"AWS Lambda"})," code when using ",(0,i.jsx)(n.strong,{children:"Node.js"}),"."]}),"\n",(0,i.jsx)(n.p,{children:"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."}),"\n",(0,i.jsx)(n.p,{children:"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."}),"\n",(0,i.jsx)(n.h2,{id:"a-quick-example",children:"A quick example"}),"\n",(0,i.jsx)(n.p,{children:"Code is better than 10,000 words, so let's jump into an example."}),"\n",(0,i.jsx)(n.p,{children:"Let's assume you are building a JSON API to process a payment:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-javascript",metastring:'title="handler.js"',children:"// 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\nexport const 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"})}),"\n",(0,i.jsx)(n.h2,{id:"why",children:"Why?"}),"\n",(0,i.jsx)(n.p,{children:"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."}),"\n",(0,i.jsx)(n.p,{children:"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."}),"\n",(0,i.jsx)(n.p,{children:"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."}),"\n",(0,i.jsxs)(n.p,{children:["In other contexts, like generic web frameworks (",(0,i.jsx)(n.a,{href:"http://fastify.io",children:"fastify"}),", ",(0,i.jsx)(n.a,{href:"https://hapijs.com/",children:"hapi"}),", ",(0,i.jsx)(n.a,{href:"http://expressjs.com/",children:"express"}),", etc.), this\nproblem has been solved using the ",(0,i.jsx)(n.a,{href:"https://www.packtpub.com/mapt/book/web_development/9781783287314/4/ch04lvl1sec33/middleware",children:"middleware pattern"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:["This pattern allows developers to isolate these common technical concerns into\n",(0,i.jsx)(n.em,{children:'"steps"'})," that ",(0,i.jsx)(n.em,{children:"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."]}),"\n",(0,i.jsx)(n.p,{children:"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."})]})}function m(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>s,a:()=>a});var i=t(7294);const r={},o=i.createContext(r);function a(e){const n=i.useContext(o);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function s(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),i.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f0136a98.e82a8d57.js b/assets/js/f0136a98.4dd220ef.js similarity index 99% rename from assets/js/f0136a98.e82a8d57.js rename to assets/js/f0136a98.4dd220ef.js index efae41e5c..8d8a0a089 100644 --- a/assets/js/f0136a98.e82a8d57.js +++ b/assets/js/f0136a98.4dd220ef.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1575],{3584:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>u,toc:()=>c});var n=r(5893),a=r(1151),s=r(4866),l=r(5162);const o={title:"http-event-normalizer"},i=void 0,u={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-event-normalizer.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const t={blockquote:"blockquote",code:"code",h2:"h2",p:"p",pre:"pre",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["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.jsx)(t.code,{children:"event.queryStringParameters"}),", ",(0,n.jsx)(t.code,{children:"event.multiValueQueryStringParameters"})," and\n",(0,n.jsx)(t.code,{children:"event.pathParameters"}),", for example: ",(0,n.jsx)(t.code,{children:"event.pathParameters.userId"}),". Unfortunately\nif there are no parameters for these parameter holders, the relevant key ",(0,n.jsx)(t.code,{children:"queryStringParameters"}),", ",(0,n.jsx)(t.code,{children:"multiValueQueryStringParameters"})," or ",(0,n.jsx)(t.code,{children:"pathParameters"})," won't be available in the object, causing an expression like ",(0,n.jsx)(t.code,{children:"event.pathParameters.userId"}),"\nto fail with the error: ",(0,n.jsx)(t.code,{children:"TypeError: Cannot read property 'userId' of undefined"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["A simple solution would be to add an ",(0,n.jsx)(t.code,{children:"if"})," statement to verify if the ",(0,n.jsx)(t.code,{children:"pathParameters"})," (or ",(0,n.jsx)(t.code,{children:"queryStringParameters"}),"/",(0,n.jsx)(t.code,{children:"multiValueQueryStringParameters"}),")\nexists before accessing one of its parameters, but this approach is very verbose and error prone."]}),"\n",(0,n.jsxs)(t.p,{children:["This middleware normalizes the API Gateway, ALB, Function URLs, and VPC Lattice events, making sure that an object for ",(0,n.jsx)(t.code,{children:"queryStringParameters"}),", ",(0,n.jsx)(t.code,{children:"multiValueQueryStringParameters"}),", ",(0,n.jsx)(t.code,{children:"pathParameters"}),", and ",(0,n.jsx)(t.code,{children:"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.jsx)(t.code,{children:"if"})," statements before trying to read a property and calling ",(0,n.jsx)(t.code,{children:"event.pathParameters.userId"})," will result in ",(0,n.jsx)(t.code,{children:"undefined"})," when no path parameter is available, but not in an error."]}),"\n",(0,n.jsxs)(t.blockquote,{children:["\n",(0,n.jsxs)(t.p,{children:["Important note : API Gateway HTTP API format 2.0 doesn't have ",(0,n.jsx)(t.code,{children:"multiValueQueryStringParameters"})," fields. Duplicate query strings are combined with commas and included in the ",(0,n.jsx)(t.code,{children:"queryStringParameters"})," field."]}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(l.Z,{value:"npm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-event-normalizer\n"})})}),(0,n.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-event-normalizer\n"})})}),(0,n.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-event-normalizer\n"})})})]}),"\n",(0,n.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpEventNormalizer from '@middy/http-event-normalizer'\n\nconst lambdaHander = (event, context) => {\n console.log(`Hello user ${event.pathParameters.userId}`)\n // might produce `Hello user undefined`, but not an error\n\n return {}\n}\nexport const handler = middy().use(httpEventNormalizer()).handler(lambdaHander)\n"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},5162:(e,t,r)=>{r.d(t,{Z:()=>l});r(7294);var n=r(6010);const a={tabItem:"tabItem_Ymn6"};var s=r(5893);function l(e){let{children:t,hidden:r,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,n.Z)(a.tabItem,l),hidden:r,children:t})}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var n=r(7294),a=r(6010),s=r(2466),l=r(6550),o=r(469),i=r(1980),u=r(7392),d=r(12);function c(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function h(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}(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 p(e){let{queryString:t=!1,groupId:r}=e;const a=(0,l.k6)(),s=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)(s),(0,n.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,s=h(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 n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:s}))),[u,c]=p({queryString:r,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,d.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&s.set(e)}),[r,s])]}({groupId:a}),v=(()=>{const e=u??f;return m({value:e,tabValues:s})?e:null})();(0,o.Z)((()=>{v&&i(v)}),[v]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),b(e)}),[c,b,s]),tabValues:s}}var b=r(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=r(5893);function x(e){let{className:t,block:r,selectedValue:n,selectValue:l,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.o5)(),d=e=>{const t=e.currentTarget,r=i.indexOf(t),a=o[r].value;a!==n&&(u(t),l(a))},c=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const r=i.indexOf(e.currentTarget)+1;t=i[r]??i[0];break}case"ArrowLeft":{const r=i.indexOf(e.currentTarget)-1;t=i[r]??i[i.length-1];break}}t?.focus()};return(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":r},t),children:o.map((e=>{let{value:t,label:r,attributes:s}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:c,onClick:d,...s,className:(0,a.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":n===t}),children:r??t},t)}))})}function g(e){let{lazy:t,children:r,selectedValue:a}=e;const s=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function j(e){const t=f(e);return(0,y.jsxs)("div",{className:(0,a.Z)("tabs-container",v.tabList),children:[(0,y.jsx)(x,{...e,...t}),(0,y.jsx)(g,{...e,...t})]})}function w(e){const t=(0,b.Z)();return(0,y.jsx)(j,{...e,children:c(e.children)},String(t))}},1151:(e,t,r)=>{r.d(t,{Z:()=>o,a:()=>l});var n=r(7294);const a={},s=n.createContext(a);function l(e){const t=n.useContext(s);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),n.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1575],{3584:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>u,toc:()=>c});var n=r(5893),a=r(1151),s=r(4866),l=r(5162);const o={title:"http-event-normalizer"},i=void 0,u={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/http-event-normalizer.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[{value:"Install",id:"install",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function h(e){const t={blockquote:"blockquote",code:"code",h2:"h2",p:"p",pre:"pre",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["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.jsx)(t.code,{children:"event.queryStringParameters"}),", ",(0,n.jsx)(t.code,{children:"event.multiValueQueryStringParameters"})," and\n",(0,n.jsx)(t.code,{children:"event.pathParameters"}),", for example: ",(0,n.jsx)(t.code,{children:"event.pathParameters.userId"}),". Unfortunately\nif there are no parameters for these parameter holders, the relevant key ",(0,n.jsx)(t.code,{children:"queryStringParameters"}),", ",(0,n.jsx)(t.code,{children:"multiValueQueryStringParameters"})," or ",(0,n.jsx)(t.code,{children:"pathParameters"})," won't be available in the object, causing an expression like ",(0,n.jsx)(t.code,{children:"event.pathParameters.userId"}),"\nto fail with the error: ",(0,n.jsx)(t.code,{children:"TypeError: Cannot read property 'userId' of undefined"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["A simple solution would be to add an ",(0,n.jsx)(t.code,{children:"if"})," statement to verify if the ",(0,n.jsx)(t.code,{children:"pathParameters"})," (or ",(0,n.jsx)(t.code,{children:"queryStringParameters"}),"/",(0,n.jsx)(t.code,{children:"multiValueQueryStringParameters"}),")\nexists before accessing one of its parameters, but this approach is very verbose and error prone."]}),"\n",(0,n.jsxs)(t.p,{children:["This middleware normalizes the API Gateway, ALB, Function URLs, and VPC Lattice events, making sure that an object for ",(0,n.jsx)(t.code,{children:"queryStringParameters"}),", ",(0,n.jsx)(t.code,{children:"multiValueQueryStringParameters"}),", ",(0,n.jsx)(t.code,{children:"pathParameters"}),", and ",(0,n.jsx)(t.code,{children:"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.jsx)(t.code,{children:"if"})," statements before trying to read a property and calling ",(0,n.jsx)(t.code,{children:"event.pathParameters.userId"})," will result in ",(0,n.jsx)(t.code,{children:"undefined"})," when no path parameter is available, but not in an error."]}),"\n",(0,n.jsxs)(t.blockquote,{children:["\n",(0,n.jsxs)(t.p,{children:["Important note : API Gateway HTTP API format 2.0 doesn't have ",(0,n.jsx)(t.code,{children:"multiValueQueryStringParameters"})," fields. Duplicate query strings are combined with commas and included in the ",(0,n.jsx)(t.code,{children:"queryStringParameters"})," field."]}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(l.Z,{value:"npm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/http-event-normalizer\n"})})}),(0,n.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/http-event-normalizer\n"})})}),(0,n.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/http-event-normalizer\n"})})})]}),"\n",(0,n.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport httpEventNormalizer from '@middy/http-event-normalizer'\n\nconst lambdaHander = (event, context) => {\n console.log(`Hello user ${event.pathParameters.userId}`)\n // might produce `Hello user undefined`, but not an error\n\n return {}\n}\nexport const handler = middy().use(httpEventNormalizer()).handler(lambdaHander)\n"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},5162:(e,t,r)=>{r.d(t,{Z:()=>l});r(7294);var n=r(6010);const a={tabItem:"tabItem_Ymn6"};var s=r(5893);function l(e){let{children:t,hidden:r,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,n.Z)(a.tabItem,l),hidden:r,children:t})}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var n=r(7294),a=r(6010),s=r(2466),l=r(6550),o=r(469),i=r(1980),u=r(7392),d=r(12);function c(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function h(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return c(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:a}}=e;return{value:t,label:r,attributes:n,default:a}}))}(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 p(e){let{queryString:t=!1,groupId:r}=e;const a=(0,l.k6)(),s=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)(s),(0,n.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function f(e){const{defaultValue:t,queryString:r=!1,groupId:a}=e,s=h(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 n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:s}))),[u,c]=p({queryString:r,groupId:a}),[f,b]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,d.Nk)(r);return[a,(0,n.useCallback)((e=>{r&&s.set(e)}),[r,s])]}({groupId:a}),v=(()=>{const e=u??f;return m({value:e,tabValues:s})?e:null})();(0,o.Z)((()=>{v&&i(v)}),[v]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);i(e),c(e),b(e)}),[c,b,s]),tabValues:s}}var b=r(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=r(5893);function x(e){let{className:t,block:r,selectedValue:n,selectValue:l,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.o5)(),d=e=>{const t=e.currentTarget,r=i.indexOf(t),a=o[r].value;a!==n&&(u(t),l(a))},c=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const r=i.indexOf(e.currentTarget)+1;t=i[r]??i[0];break}case"ArrowLeft":{const r=i.indexOf(e.currentTarget)-1;t=i[r]??i[i.length-1];break}}t?.focus()};return(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":r},t),children:o.map((e=>{let{value:t,label:r,attributes:s}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>i.push(e),onKeyDown:c,onClick:d,...s,className:(0,a.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":n===t}),children:r??t},t)}))})}function g(e){let{lazy:t,children:r,selectedValue:a}=e;const s=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function j(e){const t=f(e);return(0,y.jsxs)("div",{className:(0,a.Z)("tabs-container",v.tabList),children:[(0,y.jsx)(x,{...e,...t}),(0,y.jsx)(g,{...e,...t})]})}function w(e){const t=(0,b.Z)();return(0,y.jsx)(j,{...e,children:c(e.children)},String(t))}},1151:(e,t,r)=>{r.d(t,{Z:()=>o,a:()=>l});var n=r(7294);const a={},s=n.createContext(a);function l(e){const t=n.useContext(s);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),n.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f0886e87.a7b07d9a.js b/assets/js/f0886e87.4048dc8c.js similarity index 98% rename from assets/js/f0886e87.a7b07d9a.js rename to assets/js/f0886e87.4048dc8c.js index 130885d88..2c715f29a 100644 --- a/assets/js/f0886e87.a7b07d9a.js +++ b/assets/js/f0886e87.4048dc8c.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3955],{4462:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>d,toc:()=>p});var n=r(5893),a=r(1151);const o={title:"Function URL"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/function-url.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Function URL"},sidebar:"tutorialSidebar",previous:{title:"EventBridge",permalink:"/docs/events/event-bridge"},next:{title:"IoT Events",permalink:"/docs/events/iot-events"}},s={},p=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:"Same as API Gateway (HTTP), but with support for response streams."}),"\n",(0,n.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html",children:"Using AWS Lambda with Amazon API Gateway"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html",children:"Working with HTTP APIs"})}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>d,a:()=>i});var n=r(7294);const a={},o=n.createContext(a);function i(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:i(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[3955],{4462:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>m,frontMatter:()=>o,metadata:()=>d,toc:()=>p});var n=r(5893),a=r(1151);const o={title:"Function URL"},i=void 0,d={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/function-url.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Function URL"},sidebar:"tutorialSidebar",previous:{title:"EventBridge",permalink:"/docs/events/event-bridge"},next:{title:"IoT Events",permalink:"/docs/events/iot-events"}},s={},p=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.p,{children:"Same as API Gateway (HTTP), but with support for response streams."}),"\n",(0,n.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html",children:"Using AWS Lambda with Amazon API Gateway"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html",children:"Working with HTTP APIs"})}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"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"})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(l,{...e})}):l(e)}},1151:(e,t,r)=>{r.d(t,{Z:()=>d,a:()=>i});var n=r(7294);const a={},o=n.createContext(a);function i(e){const t=n.useContext(o);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:i(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f20815ad.322794e6.js b/assets/js/f20815ad.c0bbe8db.js similarity index 94% rename from assets/js/f20815ad.322794e6.js rename to assets/js/f20815ad.c0bbe8db.js index b63911537..1e90e34de 100644 --- a/assets/js/f20815ad.322794e6.js +++ b/assets/js/f20815ad.c0bbe8db.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4760],{6433:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>c,default:()=>m,frontMatter:()=>s,metadata:()=>a,toc:()=>d});var o=t(5893),i=t(1151);const s={title:"Connect"},c=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/connect.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Connect"},sidebar:"tutorialSidebar",previous:{title:"Config",permalink:"/docs/events/config"},next:{title:"DocumentDB",permalink:"/docs/events/documentdb"}},r={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.admonition,{type:"caution",children:(0,o.jsx)(n.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(n.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsx)(n.li,{children:(0,o.jsx)(n.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-connect.html",children:"Using Lambda with Amazon Connect"})}),"\n"]}),"\n",(0,o.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>a,a:()=>c});var o=t(7294);const i={},s=o.createContext(i);function c(e){const n=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:c(e.components),o.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4760],{6433:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>r,contentTitle:()=>c,default:()=>m,frontMatter:()=>s,metadata:()=>a,toc:()=>d});var o=t(5893),i=t(1151);const s={title:"Connect"},c=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/connect.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"Connect"},sidebar:"tutorialSidebar",previous:{title:"Config",permalink:"/docs/events/config"},next:{title:"DocumentDB",permalink:"/docs/events/documentdb"}},r={},d=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.admonition,{type:"caution",children:(0,o.jsx)(n.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(n.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsx)(n.li,{children:(0,o.jsx)(n.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-connect.html",children:"Using Lambda with Amazon Connect"})}),"\n"]}),"\n",(0,o.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function m(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>a,a:()=>c});var o=t(7294);const i={},s=o.createContext(i);function c(e){const n=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:c(e.components),o.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f33bafb6.1c03333a.js b/assets/js/f33bafb6.2f021912.js similarity index 98% rename from assets/js/f33bafb6.1c03333a.js rename to assets/js/f33bafb6.2f021912.js index af37c1946..f2a78e5ca 100644 --- a/assets/js/f33bafb6.1c03333a.js +++ b/assets/js/f33bafb6.2f021912.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8185],{2737:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>l,contentTitle:()=>s,default:()=>u,frontMatter:()=>d,metadata:()=>a,toc:()=>i});var t=r(5893),o=r(1151);const d={title:"ws-router"},s=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/routers/ws-router.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"ws-router"},sidebar:"tutorialSidebar",previous:{title:"http-router",permalink:"/docs/routers/http-router"},next:{title:"Upgrade",permalink:"/docs/category/upgrade"}},l={},i=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function c(e){const n={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:["This handler can route to requests to one of a nested handler based on ",(0,t.jsx)(n.code,{children:"routeKey"})," of an WebSocket event from API Gateway (WebSocket)."]}),"\n",(0,t.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,t.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/ws-router\n"})}),"\n",(0,t.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"routes"})," (array[{routeKey, handler}]) (required): Array of route objects.","\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"routeKey"})," (string) (required): AWS formatted route key. ie ",(0,t.jsx)(n.code,{children:"$connect"}),", ",(0,t.jsx)(n.code,{children:"$disconnect"}),", ",(0,t.jsx)(n.code,{children:"$default"})]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"handler"})," (function) (required): Any ",(0,t.jsx)(n.code,{children:"handler(event, context, {signal})"})," function"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"NOTES:"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["Errors should be handled as part of the router middleware stack ",(0,t.jsx)(n.strong,{children:"or"})," the lambdaHandler middleware stack. Handled errors in the later will trigger the ",(0,t.jsx)(n.code,{children:"after"})," middleware stack of the former."]}),"\n",(0,t.jsx)(n.li,{children:"Shared middlewares, connected to the router middleware stack, can only be run before the lambdaHandler middleware stack."}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"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\nconst routes = [\n {\n routeKey: '$connect',\n handler: connectHandler\n },\n {\n routeKey: '$disconnect',\n handler: disconnectHandler\n }\n]\n\nexport const handler = middy()\n .use(wsResponseMiddleware())\n .handler(wsRouterHandler(routes))\n"})})]})}function u(e={}){const{wrapper:n}={...(0,o.a)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(c,{...e})}):c(e)}},1151:(e,n,r)=>{r.d(n,{Z:()=>a,a:()=>s});var t=r(7294);const o={},d=t.createContext(o);function s(e){const n=t.useContext(d);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:s(e.components),t.createElement(d.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8185],{2737:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>l,contentTitle:()=>s,default:()=>u,frontMatter:()=>d,metadata:()=>a,toc:()=>i});var t=r(5893),o=r(1151);const d={title:"ws-router"},s=void 0,a={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/routers/ws-router.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 2023",frontMatter:{title:"ws-router"},sidebar:"tutorialSidebar",previous:{title:"http-router",permalink:"/docs/routers/http-router"},next:{title:"Upgrade",permalink:"/docs/category/upgrade"}},l={},i=[{value:"Install",id:"install",level:2},{value:"Options",id:"options",level:2},{value:"Sample usage",id:"sample-usage",level:2}];function c(e){const n={code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:["This handler can route to requests to one of a nested handler based on ",(0,t.jsx)(n.code,{children:"routeKey"})," of an WebSocket event from API Gateway (WebSocket)."]}),"\n",(0,t.jsx)(n.h2,{id:"install",children:"Install"}),"\n",(0,t.jsx)(n.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"npm install --save @middy/ws-router\n"})}),"\n",(0,t.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"routes"})," (array[{routeKey, handler}]) (required): Array of route objects.","\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"routeKey"})," (string) (required): AWS formatted route key. ie ",(0,t.jsx)(n.code,{children:"$connect"}),", ",(0,t.jsx)(n.code,{children:"$disconnect"}),", ",(0,t.jsx)(n.code,{children:"$default"})]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.code,{children:"handler"})," (function) (required): Any ",(0,t.jsx)(n.code,{children:"handler(event, context, {signal})"})," function"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"NOTES:"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["Errors should be handled as part of the router middleware stack ",(0,t.jsx)(n.strong,{children:"or"})," the lambdaHandler middleware stack. Handled errors in the later will trigger the ",(0,t.jsx)(n.code,{children:"after"})," middleware stack of the former."]}),"\n",(0,t.jsx)(n.li,{children:"Shared middlewares, connected to the router middleware stack, can only be run before the lambdaHandler middleware stack."}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-javascript",children:"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\nconst routes = [\n {\n routeKey: '$connect',\n handler: connectHandler\n },\n {\n routeKey: '$disconnect',\n handler: disconnectHandler\n }\n]\n\nexport const handler = middy()\n .use(wsResponseMiddleware())\n .handler(wsRouterHandler(routes))\n"})})]})}function u(e={}){const{wrapper:n}={...(0,o.a)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(c,{...e})}):c(e)}},1151:(e,n,r)=>{r.d(n,{Z:()=>a,a:()=>s});var t=r(7294);const o={},d=t.createContext(o);function s(e){const n=t.useContext(d);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:s(e.components),t.createElement(d.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f795adf5.dcb256e5.js b/assets/js/f795adf5.f73bc52b.js similarity index 98% rename from assets/js/f795adf5.dcb256e5.js rename to assets/js/f795adf5.f73bc52b.js index db642f94b..82b464476 100644 --- a/assets/js/f795adf5.dcb256e5.js +++ b/assets/js/f795adf5.f73bc52b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8841],{5196:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>s,default:()=>u,frontMatter:()=>a,metadata:()=>i,toc:()=>d});var r=t(5893),o=t(1151);const a={title:"Early return",position:4},s=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/04-early-interrupt.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},c={},d=[];function l(e){const n={code:"code",p:"p",pre:"pre",strong:"strong",...(0,o.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.p,{children:"Some middlewares might need to stop the whole execution flow and return a response immediately."}),"\n",(0,r.jsxs)(n.p,{children:["If you want to do this you can invoke ",(0,r.jsx)(n.code,{children:"return response"})," in your middleware."]}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"Note"}),": this will totally stop the execution of successive middlewares in any phase (",(0,r.jsx)(n.code,{children:"before"}),", ",(0,r.jsx)(n.code,{children:"after"}),", ",(0,r.jsx)(n.code,{children:"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."]}),"\n",(0,r.jsx)(n.p,{children:"In this example, we can use this capability for building a sample caching middleware:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"// 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 lambdaHandler = (event, context) => {\n /* ... */\n}\nexport const handler = middy()\n .use(\n cacheMiddleware({\n calculateCacheId,\n storage\n })\n )\n .handler(lambdaHandler)\n"})})]})}function u(e={}){const{wrapper:n}={...(0,o.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>s});var r=t(7294);const o={},a=r.createContext(o);function s(e){const n=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:s(e.components),r.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[8841],{5196:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>s,default:()=>u,frontMatter:()=>a,metadata:()=>i,toc:()=>d});var r=t(5893),o=t(1151);const a={title:"Early return",position:4},s=void 0,i={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/04-early-interrupt.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},c={},d=[];function l(e){const n={code:"code",p:"p",pre:"pre",strong:"strong",...(0,o.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.p,{children:"Some middlewares might need to stop the whole execution flow and return a response immediately."}),"\n",(0,r.jsxs)(n.p,{children:["If you want to do this you can invoke ",(0,r.jsx)(n.code,{children:"return response"})," in your middleware."]}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"Note"}),": this will totally stop the execution of successive middlewares in any phase (",(0,r.jsx)(n.code,{children:"before"}),", ",(0,r.jsx)(n.code,{children:"after"}),", ",(0,r.jsx)(n.code,{children:"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."]}),"\n",(0,r.jsx)(n.p,{children:"In this example, we can use this capability for building a sample caching middleware:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"// 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 lambdaHandler = (event, context) => {\n /* ... */\n}\nexport const handler = middy()\n .use(\n cacheMiddleware({\n calculateCacheId,\n storage\n })\n )\n .handler(lambdaHandler)\n"})})]})}function u(e={}){const{wrapper:n}={...(0,o.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},1151:(e,n,t)=>{t.d(n,{Z:()=>i,a:()=>s});var r=t(7294);const o={},a=r.createContext(o);function s(e){const n=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:s(e.components),r.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f9850e34.e053ea41.js b/assets/js/f9850e34.d3f7123b.js similarity index 98% rename from assets/js/f9850e34.e053ea41.js rename to assets/js/f9850e34.d3f7123b.js index 87d375a0f..ba448dfc0 100644 --- a/assets/js/f9850e34.e053ea41.js +++ b/assets/js/f9850e34.d3f7123b.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6177],{9983:(e,t,i)=>{i.r(t),i.d(t,{assets:()=>a,contentTitle:()=>d,default:()=>c,frontMatter:()=>s,metadata:()=>o,toc:()=>l});var n=i(5893),r=i(1151);const s={title:"How it works",position:3},d=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/03-how-it-works.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},a={},l=[{value:"Execution order",id:"execution-order",level:2}];function h(e){const t={code:"code",em:"em",h2:"h2",img:"img",li:"li",p:"p",ul:"ul",...(0,r.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["Middy implements the classic ",(0,n.jsx)(t.em,{children:"onion-like"})," middleware pattern, with some peculiar details."]}),"\n",(0,n.jsx)(t.p,{children:(0,n.jsx)(t.img,{alt:"Middy middleware engine diagram",src:i(2321).Z+"",width:"664",height:"547"})}),"\n",(0,n.jsx)(t.p,{children:"When you attach a new middleware this will wrap the business logic contained in the handler\nin two separate steps."}),"\n",(0,n.jsxs)(t.p,{children:["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,n.jsx)(t.em,{children:"request"})," (event) and the ",(0,n.jsx)(t.em,{children:"response"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["This way the ",(0,n.jsx)(t.em,{children:"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."]}),"\n",(0,n.jsx)(t.h2,{id:"execution-order",children:"Execution order"}),"\n",(0,n.jsxs)(t.p,{children:["Middlewares have two phases: ",(0,n.jsx)(t.code,{children:"before"})," and ",(0,n.jsx)(t.code,{children:"after"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"before"})," phase, happens ",(0,n.jsx)(t.em,{children:"before"})," the handler is executed. In this code the\nresponse is not created yet, so you will have access only to the request."]}),"\n",(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"after"})," phase, happens ",(0,n.jsx)(t.em,{children:"after"})," the handler is executed. In this code you will\nhave access to both the request and the response."]}),"\n",(0,n.jsx)(t.p,{children:"If you have three middlewares attached (as in the image above), this is the expected\norder of execution:"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"middleware1"})," (before)"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"middleware2"})," (before)"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"middleware3"})," (before)"]}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.code,{children:"handler"})}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"middleware3"})," (after)"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"middleware2"})," (after)"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"middleware1"})," (after)"]}),"\n"]}),"\n",(0,n.jsxs)(t.p,{children:["Notice that in the ",(0,n.jsx)(t.code,{children:"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."]})]})}function c(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},2321:(e,t,i)=>{i.d(t,{Z:()=>n});const n=i.p+"assets/images/middy-middleware-engine-eb7bdaefff782d4d36cce8f149f7fa85.png"},1151:(e,t,i)=>{i.d(t,{Z:()=>o,a:()=>d});var n=i(7294);const r={},s=n.createContext(r);function d(e){const t=n.useContext(s);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:d(e.components),n.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[6177],{9983:(e,t,i)=>{i.r(t),i.d(t,{assets:()=>a,contentTitle:()=>d,default:()=>c,frontMatter:()=>s,metadata:()=>o,toc:()=>l});var n=i(5893),r=i(1151);const s={title:"How it works",position:3},d=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/intro/03-how-it-works.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},a={},l=[{value:"Execution order",id:"execution-order",level:2}];function h(e){const t={code:"code",em:"em",h2:"h2",img:"img",li:"li",p:"p",ul:"ul",...(0,r.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["Middy implements the classic ",(0,n.jsx)(t.em,{children:"onion-like"})," middleware pattern, with some peculiar details."]}),"\n",(0,n.jsx)(t.p,{children:(0,n.jsx)(t.img,{alt:"Middy middleware engine diagram",src:i(2321).Z+"",width:"664",height:"547"})}),"\n",(0,n.jsx)(t.p,{children:"When you attach a new middleware this will wrap the business logic contained in the handler\nin two separate steps."}),"\n",(0,n.jsxs)(t.p,{children:["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,n.jsx)(t.em,{children:"request"})," (event) and the ",(0,n.jsx)(t.em,{children:"response"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["This way the ",(0,n.jsx)(t.em,{children:"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."]}),"\n",(0,n.jsx)(t.h2,{id:"execution-order",children:"Execution order"}),"\n",(0,n.jsxs)(t.p,{children:["Middlewares have two phases: ",(0,n.jsx)(t.code,{children:"before"})," and ",(0,n.jsx)(t.code,{children:"after"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"before"})," phase, happens ",(0,n.jsx)(t.em,{children:"before"})," the handler is executed. In this code the\nresponse is not created yet, so you will have access only to the request."]}),"\n",(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.code,{children:"after"})," phase, happens ",(0,n.jsx)(t.em,{children:"after"})," the handler is executed. In this code you will\nhave access to both the request and the response."]}),"\n",(0,n.jsx)(t.p,{children:"If you have three middlewares attached (as in the image above), this is the expected\norder of execution:"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"middleware1"})," (before)"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"middleware2"})," (before)"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"middleware3"})," (before)"]}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.code,{children:"handler"})}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"middleware3"})," (after)"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"middleware2"})," (after)"]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"middleware1"})," (after)"]}),"\n"]}),"\n",(0,n.jsxs)(t.p,{children:["Notice that in the ",(0,n.jsx)(t.code,{children:"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."]})]})}function c(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},2321:(e,t,i)=>{i.d(t,{Z:()=>n});const n=i.p+"assets/images/middy-middleware-engine-eb7bdaefff782d4d36cce8f149f7fa85.png"},1151:(e,t,i)=>{i.d(t,{Z:()=>o,a:()=>d});var n=i(7294);const r={},s=n.createContext(r);function d(e){const t=n.useContext(s);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:d(e.components),n.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/faf674c6.f8055c7b.js b/assets/js/faf674c6.399c34bf.js similarity index 97% rename from assets/js/faf674c6.f8055c7b.js rename to assets/js/faf674c6.399c34bf.js index 697e9d62d..d44aadf5a 100644 --- a/assets/js/faf674c6.f8055c7b.js +++ b/assets/js/faf674c6.399c34bf.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4962],{2342:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>u,frontMatter:()=>i,metadata:()=>r,toc:()=>c});var o=n(5893),s=n(1151);const i={title:"IoT Events"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/iot-events.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-iotevents.html",children:"Using AWS Lambda with AWS IoT Events"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function u(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var o=n(7294);const s={},i=o.createContext(s);function a(e){const t=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),o.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[4962],{2342:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>a,default:()=>u,frontMatter:()=>i,metadata:()=>r,toc:()=>c});var o=n(5893),s=n(1151);const i={title:"IoT Events"},a=void 0,r={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/events/iot-events.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},d={},c=[{value:"AWS Documentation",id:"aws-documentation",level:2},{value:"Example",id:"example",level:2}];function l(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsx)(t.p,{children:"This page is a work in progress. If you want to help us to make this page better, please consider contributing on GitHub."})}),"\n",(0,o.jsx)(t.h2,{id:"aws-documentation",children:"AWS Documentation"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://docs.aws.amazon.com/lambda/latest/dg/services-iotevents.html",children:"Using AWS Lambda with AWS IoT Events"})}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\n\nexport const handler = middy()\n .handler((event, context, {signal}) => {\n // ...\n })\n"})})]})}function u(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>r,a:()=>a});var o=n(7294);const s={},i=o.createContext(s);function a(e){const t=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),o.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/ff488875.61c29dc9.js b/assets/js/ff488875.433a9ee1.js similarity index 99% rename from assets/js/ff488875.61c29dc9.js rename to assets/js/ff488875.433a9ee1.js index b64ba2304..f4d394c68 100644 --- a/assets/js/ff488875.61c29dc9.js +++ b/assets/js/ff488875.433a9ee1.js @@ -1 +1 @@ -"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1531],{4974:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>c,contentTitle:()=>d,default:()=>m,frontMatter:()=>i,metadata:()=>o,toc:()=>u});var n=a(5893),s=a(1151),r=a(4866),l=a(5162);const i={title:"ssm"},d=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/ssm.md",tags:[],version:"current",lastUpdatedAt:1700079044,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{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},{value:"Usage with TypeScript",id:"usage-with-typescript",level:2}];function h(e){const t={a:"a",code:"code",em:"em",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["This middleware fetches parameters from ",(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html",children:"AWS Systems Manager Parameter Store"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["Parameters to fetch can be defined by path and by name (not mutually exclusive). See AWS docs ",(0,n.jsx)(t.a,{href:"https://aws.amazon.com/blogs/mt/organize-parameters-by-hierarchy-tags-or-amazon-cloudwatch-events-with-amazon-ec2-systems-manager-parameter-store/",children:"here"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["Parameters can be assigned to the function handler's ",(0,n.jsx)(t.code,{children:"context"})," object by setting the ",(0,n.jsx)(t.code,{children:"setToContext"})," flag to ",(0,n.jsx)(t.code,{children:"true"}),". By default all parameters are added with uppercase names."]}),"\n",(0,n.jsx)(t.p,{children:"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."}),"\n",(0,n.jsxs)(t.p,{children:["For each parameter defined by name, you also provide the name under which its value should be added to ",(0,n.jsx)(t.code,{children:"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,n.jsx)(t.code,{children:"context"})," with a name equal to what's left of the parameter's full name ",(0,n.jsx)(t.em,{children:"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,n.jsx)(t.code,{children:"getParamNameFromPath"})," config option."]}),"\n",(0,n.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(r.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(l.Z,{value:"npm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/ssm\nnpm install --save-dev @aws-sdk/client-ssm\n"})})}),(0,n.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/ssm\nyarn add --dev @aws-sdk/client-ssm\n"})})}),(0,n.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/ssm\npnpm add --save-dev @aws-sdk/client-ssm\n"})})})]}),"\n",(0,n.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"AwsClient"})," (object) (default ",(0,n.jsx)(t.code,{children:"SSMClient"}),"): SSMClient class constructor (i.e. that has been instrumented with AWS X-Ray). Must be from ",(0,n.jsx)(t.code,{children:"@aws-sdk/client-ssm"}),"."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"awsClientOptions"})," (object) (optional): Options to pass to SSMClient class constructor."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"awsClientAssumeRole"})," (string) (optional): Internal key where role tokens are stored. See ",(0,n.jsx)(t.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"awsClientCapture"})," (function) (optional): Enable AWS X-Ray by passing ",(0,n.jsx)(t.code,{children:"captureAWSv3Client"})," from ",(0,n.jsx)(t.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameter ",(0,n.jsx)(t.code,{children:"Names"}),"/",(0,n.jsx)(t.code,{children:"Path"}),". ",(0,n.jsx)(t.code,{children:"SecureString"})," are automatically decrypted."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"disablePrefetch"})," (boolean) (default ",(0,n.jsx)(t.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,n.jsx)(t.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"cacheKey"})," (string) (default ",(0,n.jsx)(t.code,{children:"ssm"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"cacheExpiry"})," (number) (default ",(0,n.jsx)(t.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,n.jsx)(t.code,{children:"-1"}),": cache forever, ",(0,n.jsx)(t.code,{children:"0"}),": never cache, ",(0,n.jsx)(t.code,{children:"n"}),": cache for n ms."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"setToContext"})," (boolean) (default ",(0,n.jsx)(t.code,{children:"false"}),"): Store role tokens to ",(0,n.jsx)(t.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,n.jsx)(t.p,{children:"NOTES:"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:["Lambda is required to have IAM permission for ",(0,n.jsx)(t.code,{children:"ssm:GetParameters"})," and/or ",(0,n.jsx)(t.code,{children:"ssm:GetParametersByPath"})," depending on what you're requesting, along with ",(0,n.jsx)(t.code,{children:"kms:Decrypt"}),"."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"SSM"})," has ",(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/general/latest/gr/ssm.html",children:"throughput limitations"}),". Switching to Advanced Parameter type or increasing ",(0,n.jsx)(t.code,{children:"maxRetries"})," and ",(0,n.jsx)(t.code,{children:"retryDelayOptions.base"})," in ",(0,n.jsx)(t.code,{children:"awsClientOptions"})," may be required."]}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport ssm from '@middy/ssm'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nlet globalDefaults = {}\nexport const handler = middy()\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 .handler(lambdaHandler)\n"})}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport { getInternal } from '@middy/util'\nimport ssm from '@middy/ssm'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nlet globalDefaults = {}\nexport const handler = middy()\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 .handler(lambdaHandler)\n"})}),"\n",(0,n.jsx)(t.h2,{id:"bundling",children:"Bundling"}),"\n",(0,n.jsxs)(t.p,{children:["To exclude ",(0,n.jsx)(t.code,{children:"@aws-sdk"})," add ",(0,n.jsx)(t.code,{children:"@aws-sdk/client-ssm"})," to the exclude list."]}),"\n",(0,n.jsx)(t.h2,{id:"usage-with-typescript",children:"Usage with TypeScript"}),"\n",(0,n.jsxs)(t.p,{children:["Data in SSM can be stored as arbitrary JSON values. It's not possible to know in advance what shape the fetched SSM parameters will have, so by default the fetched parameters will have type ",(0,n.jsx)(t.code,{children:"unknown"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["You can provide some type hints by leveraging the ",(0,n.jsx)(t.code,{children:"ssmParam"})," utility function. This function allows you to specify what's the expected type that will be fetched for every parameter."]}),"\n",(0,n.jsxs)(t.p,{children:["The idea is that, for every parameter specified in the ",(0,n.jsx)(t.code,{children:"fetchData"})," option, rather than just providing the parameter path as a string, you can wrap it in a ",(0,n.jsx)(t.code,{children:"ssmParam(parameterPath)"})," call. Internally, ",(0,n.jsx)(t.code,{children:"ssmParam"})," is a function that will return ",(0,n.jsx)(t.code,{children:"parameterPath"})," as received, but it allows you to use generics to provide type hints for the expected type for that parameter."]}),"\n",(0,n.jsx)(t.p,{children:"This way TypeScript can understand how to treat the additional data attached to the context and stored in the internal storage."}),"\n",(0,n.jsxs)(t.p,{children:["The following example illustrates how to use ",(0,n.jsx)(t.code,{children:"ssmParam"}),":"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-typescript",children:"import middy from '@middy/core'\nimport { getInternal } from '@middy/util'\nimport ssm, { ssmParam } from '@middy/ssm'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nlet globalDefaults = {}\nexport const handler = middy()\n .use(\n ssm({\n fetchData: {\n accessToken: ssmParam('/dev/service_name/access_token'), // single value (will be typed as string)\n dbParams: ssmParam<{ user: string; pass: string }>(\n '/dev/service_name/database/'\n ) // object of values (typed as {user: string, pass: string})\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(['accessToken', 'dbParams'], request)\n // data.accessToken (string)\n // data.dbParams ({user: string, pass: string})\n })\n .handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},5162:(e,t,a)=>{a.d(t,{Z:()=>l});a(7294);var n=a(6010);const s={tabItem:"tabItem_Ymn6"};var r=a(5893);function l(e){let{children:t,hidden:a,className:l}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.Z)(s.tabItem,l),hidden:a,children:t})}},4866:(e,t,a)=>{a.d(t,{Z:()=>w});var n=a(7294),s=a(6010),r=a(2466),l=a(6550),i=a(469),d=a(1980),o=a(7392),c=a(12);function u(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function h(e){const{values:t,children:a}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:a,attributes:n,default:s}}=e;return{value:t,label:a,attributes:n,default:s}}))}(a);return function(e){const t=(0,o.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 p(e){let{queryString:t=!1,groupId:a}=e;const s=(0,l.k6)(),r=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)(r),(0,n.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(s.location.search);t.set(r,e),s.replace({...s.location,search:t.toString()})}),[r,s])]}function f(e){const{defaultValue:t,queryString:a=!1,groupId:s}=e,r=h(e),[l,d]=(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 n=a.find((e=>e.default))??a[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:r}))),[o,u]=p({queryString:a,groupId:s}),[f,x]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,r]=(0,c.Nk)(a);return[s,(0,n.useCallback)((e=>{a&&r.set(e)}),[a,r])]}({groupId:s}),b=(()=>{const e=o??f;return m({value:e,tabValues:r})?e:null})();(0,i.Z)((()=>{b&&d(b)}),[b]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);d(e),u(e),x(e)}),[u,x,r]),tabValues:r}}var x=a(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=a(5893);function j(e){let{className:t,block:a,selectedValue:n,selectValue:l,tabValues:i}=e;const d=[],{blockElementScrollPositionUntilNextRender:o}=(0,r.o5)(),c=e=>{const t=e.currentTarget,a=d.indexOf(t),s=i[a].value;s!==n&&(o(t),l(s))},u=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(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":a},t),children:i.map((e=>{let{value:t,label:a,attributes:r}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>d.push(e),onKeyDown:u,onClick:c,...r,className:(0,s.Z)("tabs__item",b.tabItem,r?.className,{"tabs__item--active":n===t}),children:a??t},t)}))})}function g(e){let{lazy:t,children:a,selectedValue:s}=e;const r=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=r.find((e=>e.props.value===s));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:r.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function v(e){const t=f(e);return(0,y.jsxs)("div",{className:(0,s.Z)("tabs-container",b.tabList),children:[(0,y.jsx)(j,{...e,...t}),(0,y.jsx)(g,{...e,...t})]})}function w(e){const t=(0,x.Z)();return(0,y.jsx)(v,{...e,children:u(e.children)},String(t))}},1151:(e,t,a)=>{a.d(t,{Z:()=>i,a:()=>l});var n=a(7294);const s={},r=n.createContext(s);function l(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[1531],{4974:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>c,contentTitle:()=>d,default:()=>m,frontMatter:()=>i,metadata:()=>o,toc:()=>u});var n=a(5893),s=a(1151),r=a(4866),l=a(5162);const i={title:"ssm"},d=void 0,o={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,unlisted:!1,editUrl:"https://github.com/middyjs/middy/tree/main/website/docs/middlewares/ssm.md",tags:[],version:"current",lastUpdatedAt:1700079159,formattedLastUpdatedAt:"Nov 15, 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"}},c={},u=[{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},{value:"Usage with TypeScript",id:"usage-with-typescript",level:2}];function h(e){const t={a:"a",code:"code",em:"em",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(t.p,{children:["This middleware fetches parameters from ",(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html",children:"AWS Systems Manager Parameter Store"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["Parameters to fetch can be defined by path and by name (not mutually exclusive). See AWS docs ",(0,n.jsx)(t.a,{href:"https://aws.amazon.com/blogs/mt/organize-parameters-by-hierarchy-tags-or-amazon-cloudwatch-events-with-amazon-ec2-systems-manager-parameter-store/",children:"here"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["Parameters can be assigned to the function handler's ",(0,n.jsx)(t.code,{children:"context"})," object by setting the ",(0,n.jsx)(t.code,{children:"setToContext"})," flag to ",(0,n.jsx)(t.code,{children:"true"}),". By default all parameters are added with uppercase names."]}),"\n",(0,n.jsx)(t.p,{children:"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."}),"\n",(0,n.jsxs)(t.p,{children:["For each parameter defined by name, you also provide the name under which its value should be added to ",(0,n.jsx)(t.code,{children:"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,n.jsx)(t.code,{children:"context"})," with a name equal to what's left of the parameter's full name ",(0,n.jsx)(t.em,{children:"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,n.jsx)(t.code,{children:"getParamNameFromPath"})," config option."]}),"\n",(0,n.jsx)(t.h2,{id:"install",children:"Install"}),"\n",(0,n.jsx)(t.p,{children:"To install this middleware you can use NPM:"}),"\n",(0,n.jsxs)(r.Z,{groupId:"npm2yarn",children:[(0,n.jsx)(l.Z,{value:"npm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"npm install --save @middy/ssm\nnpm install --save-dev @aws-sdk/client-ssm\n"})})}),(0,n.jsx)(l.Z,{value:"yarn",label:"Yarn",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"yarn add @middy/ssm\nyarn add --dev @aws-sdk/client-ssm\n"})})}),(0,n.jsx)(l.Z,{value:"pnpm",label:"pnpm",children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-bash",children:"pnpm add @middy/ssm\npnpm add --save-dev @aws-sdk/client-ssm\n"})})})]}),"\n",(0,n.jsx)(t.h2,{id:"options",children:"Options"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"AwsClient"})," (object) (default ",(0,n.jsx)(t.code,{children:"SSMClient"}),"): SSMClient class constructor (i.e. that has been instrumented with AWS X-Ray). Must be from ",(0,n.jsx)(t.code,{children:"@aws-sdk/client-ssm"}),"."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"awsClientOptions"})," (object) (optional): Options to pass to SSMClient class constructor."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"awsClientAssumeRole"})," (string) (optional): Internal key where role tokens are stored. See ",(0,n.jsx)(t.a,{href:"/docs/middlewares/sts",children:"@middy/sts"})," on to set this."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"awsClientCapture"})," (function) (optional): Enable AWS X-Ray by passing ",(0,n.jsx)(t.code,{children:"captureAWSv3Client"})," from ",(0,n.jsx)(t.code,{children:"aws-xray-sdk"})," in."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"fetchData"})," (object) (required): Mapping of internal key name to API request parameter ",(0,n.jsx)(t.code,{children:"Names"}),"/",(0,n.jsx)(t.code,{children:"Path"}),". ",(0,n.jsx)(t.code,{children:"SecureString"})," are automatically decrypted."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"disablePrefetch"})," (boolean) (default ",(0,n.jsx)(t.code,{children:"false"}),"): On cold start requests will trigger early if they can. Setting ",(0,n.jsx)(t.code,{children:"awsClientAssumeRole"})," disables prefetch."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"cacheKey"})," (string) (default ",(0,n.jsx)(t.code,{children:"ssm"}),"): Cache key for the fetched data responses. Must be unique across all middleware."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"cacheExpiry"})," (number) (default ",(0,n.jsx)(t.code,{children:"-1"}),"): How long fetch data responses should be cached for. ",(0,n.jsx)(t.code,{children:"-1"}),": cache forever, ",(0,n.jsx)(t.code,{children:"0"}),": never cache, ",(0,n.jsx)(t.code,{children:"n"}),": cache for n ms."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"setToContext"})," (boolean) (default ",(0,n.jsx)(t.code,{children:"false"}),"): Store role tokens to ",(0,n.jsx)(t.code,{children:"request.context"}),"."]}),"\n"]}),"\n",(0,n.jsx)(t.p,{children:"NOTES:"}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:["Lambda is required to have IAM permission for ",(0,n.jsx)(t.code,{children:"ssm:GetParameters"})," and/or ",(0,n.jsx)(t.code,{children:"ssm:GetParametersByPath"})," depending on what you're requesting, along with ",(0,n.jsx)(t.code,{children:"kms:Decrypt"}),"."]}),"\n",(0,n.jsxs)(t.li,{children:[(0,n.jsx)(t.code,{children:"SSM"})," has ",(0,n.jsx)(t.a,{href:"https://docs.aws.amazon.com/general/latest/gr/ssm.html",children:"throughput limitations"}),". Switching to Advanced Parameter type or increasing ",(0,n.jsx)(t.code,{children:"maxRetries"})," and ",(0,n.jsx)(t.code,{children:"retryDelayOptions.base"})," in ",(0,n.jsx)(t.code,{children:"awsClientOptions"})," may be required."]}),"\n"]}),"\n",(0,n.jsx)(t.h2,{id:"sample-usage",children:"Sample usage"}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport ssm from '@middy/ssm'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nlet globalDefaults = {}\nexport const handler = middy()\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 .handler(lambdaHandler)\n"})}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-javascript",children:"import middy from '@middy/core'\nimport { getInternal } from '@middy/util'\nimport ssm from '@middy/ssm'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nlet globalDefaults = {}\nexport const handler = middy()\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 .handler(lambdaHandler)\n"})}),"\n",(0,n.jsx)(t.h2,{id:"bundling",children:"Bundling"}),"\n",(0,n.jsxs)(t.p,{children:["To exclude ",(0,n.jsx)(t.code,{children:"@aws-sdk"})," add ",(0,n.jsx)(t.code,{children:"@aws-sdk/client-ssm"})," to the exclude list."]}),"\n",(0,n.jsx)(t.h2,{id:"usage-with-typescript",children:"Usage with TypeScript"}),"\n",(0,n.jsxs)(t.p,{children:["Data in SSM can be stored as arbitrary JSON values. It's not possible to know in advance what shape the fetched SSM parameters will have, so by default the fetched parameters will have type ",(0,n.jsx)(t.code,{children:"unknown"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["You can provide some type hints by leveraging the ",(0,n.jsx)(t.code,{children:"ssmParam"})," utility function. This function allows you to specify what's the expected type that will be fetched for every parameter."]}),"\n",(0,n.jsxs)(t.p,{children:["The idea is that, for every parameter specified in the ",(0,n.jsx)(t.code,{children:"fetchData"})," option, rather than just providing the parameter path as a string, you can wrap it in a ",(0,n.jsx)(t.code,{children:"ssmParam(parameterPath)"})," call. Internally, ",(0,n.jsx)(t.code,{children:"ssmParam"})," is a function that will return ",(0,n.jsx)(t.code,{children:"parameterPath"})," as received, but it allows you to use generics to provide type hints for the expected type for that parameter."]}),"\n",(0,n.jsx)(t.p,{children:"This way TypeScript can understand how to treat the additional data attached to the context and stored in the internal storage."}),"\n",(0,n.jsxs)(t.p,{children:["The following example illustrates how to use ",(0,n.jsx)(t.code,{children:"ssmParam"}),":"]}),"\n",(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-typescript",children:"import middy from '@middy/core'\nimport { getInternal } from '@middy/util'\nimport ssm, { ssmParam } from '@middy/ssm'\n\nconst lambdaHandler = (event, context) => {\n return {}\n}\n\nlet globalDefaults = {}\nexport const handler = middy()\n .use(\n ssm({\n fetchData: {\n accessToken: ssmParam('/dev/service_name/access_token'), // single value (will be typed as string)\n dbParams: ssmParam<{ user: string; pass: string }>(\n '/dev/service_name/database/'\n ) // object of values (typed as {user: string, pass: string})\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(['accessToken', 'dbParams'], request)\n // data.accessToken (string)\n // data.dbParams ({user: string, pass: string})\n })\n .handler(lambdaHandler)\n"})})]})}function m(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},5162:(e,t,a)=>{a.d(t,{Z:()=>l});a(7294);var n=a(6010);const s={tabItem:"tabItem_Ymn6"};var r=a(5893);function l(e){let{children:t,hidden:a,className:l}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.Z)(s.tabItem,l),hidden:a,children:t})}},4866:(e,t,a)=>{a.d(t,{Z:()=>w});var n=a(7294),s=a(6010),r=a(2466),l=a(6550),i=a(469),d=a(1980),o=a(7392),c=a(12);function u(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((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)??[]}function h(e){const{values:t,children:a}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:a,attributes:n,default:s}}=e;return{value:t,label:a,attributes:n,default:s}}))}(a);return function(e){const t=(0,o.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 p(e){let{queryString:t=!1,groupId:a}=e;const s=(0,l.k6)(),r=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)(r),(0,n.useCallback)((e=>{if(!r)return;const t=new URLSearchParams(s.location.search);t.set(r,e),s.replace({...s.location,search:t.toString()})}),[r,s])]}function f(e){const{defaultValue:t,queryString:a=!1,groupId:s}=e,r=h(e),[l,d]=(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 n=a.find((e=>e.default))??a[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:r}))),[o,u]=p({queryString:a,groupId:s}),[f,x]=function(e){let{groupId:t}=e;const a=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,r]=(0,c.Nk)(a);return[s,(0,n.useCallback)((e=>{a&&r.set(e)}),[a,r])]}({groupId:s}),b=(()=>{const e=o??f;return m({value:e,tabValues:r})?e:null})();(0,i.Z)((()=>{b&&d(b)}),[b]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);d(e),u(e),x(e)}),[u,x,r]),tabValues:r}}var x=a(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=a(5893);function j(e){let{className:t,block:a,selectedValue:n,selectValue:l,tabValues:i}=e;const d=[],{blockElementScrollPositionUntilNextRender:o}=(0,r.o5)(),c=e=>{const t=e.currentTarget,a=d.indexOf(t),s=i[a].value;s!==n&&(o(t),l(s))},u=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(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":a},t),children:i.map((e=>{let{value:t,label:a,attributes:r}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>d.push(e),onKeyDown:u,onClick:c,...r,className:(0,s.Z)("tabs__item",b.tabItem,r?.className,{"tabs__item--active":n===t}),children:a??t},t)}))})}function g(e){let{lazy:t,children:a,selectedValue:s}=e;const r=(Array.isArray(a)?a:[a]).filter(Boolean);if(t){const e=r.find((e=>e.props.value===s));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:r.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function v(e){const t=f(e);return(0,y.jsxs)("div",{className:(0,s.Z)("tabs-container",b.tabList),children:[(0,y.jsx)(j,{...e,...t}),(0,y.jsx)(g,{...e,...t})]})}function w(e){const t=(0,x.Z)();return(0,y.jsx)(v,{...e,children:u(e.children)},String(t))}},1151:(e,t,a)=>{a.d(t,{Z:()=>i,a:()=>l});var n=a(7294);const s={},r=n.createContext(s);function l(e){const t=n.useContext(r);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/main.be3ccd6b.js b/assets/js/main.c92a1803.js similarity index 99% rename from assets/js/main.be3ccd6b.js rename to assets/js/main.c92a1803.js index 76e67ba7f..ec2a8217c 100644 --- a/assets/js/main.be3ccd6b.js +++ b/assets/js/main.c92a1803.js @@ -1,2 +1,2 @@ -/*! For license information please see main.be3ccd6b.js.LICENSE.txt */ -(self.webpackChunkmiddy=self.webpackChunkmiddy||[]).push([[179],{723:(e,t,n)=>{"use strict";n.d(t,{Z:()=>p});n(7294);var r=n(8356),a=n.n(r),o=n(6887);const i={"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,2339)),"@site/docs/middlewares/http-json-body-parser.md",2339],"028754be":[()=>n.e(6238).then(n.bind(n,3568)),"@site/docs/events/sqs.md",3568],"0480b142":[()=>n.e(836).then(n.bind(n,8976)),"@site/docs/faq.md",8976],"08eadb91":[()=>n.e(1428).then(n.bind(n,7702)),"@site/docs/writing-middlewares/01-intro.md",7702],"08f83687":[()=>n.e(5409).then(n.bind(n,2423)),"@site/docs/events/code-commit.md",2423],"0976e874":[()=>Promise.all([n.e(532),n.e(4267)]).then(n.bind(n,8369)),"@site/docs/middlewares/error-logger.md",8369],"0ce61a91":[()=>n.e(6540).then(n.bind(n,8593)),"@site/docs/best-practices/05-bundling.md",8593],"0d245e6a":[()=>n.e(8481).then(n.bind(n,9081)),"@site/docs/events/kinesis-firehose.md",9081],"0e90e864":[()=>Promise.all([n.e(532),n.e(1469)]).then(n.bind(n,3048)),"@site/docs/middlewares/secrets-manager.md",3048],"1124057e":[()=>Promise.all([n.e(532),n.e(2308)]).then(n.bind(n,8625)),"@site/docs/middlewares/dynamodb.md",8625],"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,3158)),"@site/docs/integrations/RDS.md",3158],17896441:[()=>Promise.all([n.e(532),n.e(9286),n.e(7908),n.e(7918)]).then(n.bind(n,230)),"@theme/DocItem",230],"18dc5a76":[()=>n.e(7566).then(n.bind(n,9307)),"@site/docs/events/api-gateway-http.md",9307],"19606b2d":[()=>Promise.all([n.e(532),n.e(1544)]).then(n.bind(n,6145)),"@site/docs/middlewares/event-normalizer.md",6145],"1c88510b":[()=>Promise.all([n.e(532),n.e(7858)]).then(n.bind(n,4328)),"@site/docs/middlewares/s3-object-response.md",4328],"1e42f3f3":[()=>n.e(8102).then(n.bind(n,1586)),"@site/docs/middlewares/ws-json-body-parser.md",1586],"1ea8ecd6":[()=>n.e(5341).then(n.bind(n,8683)),"@site/docs/events/iot.md",8683],"1f391b9e":[()=>Promise.all([n.e(532),n.e(9286),n.e(7908),n.e(3085)]).then(n.bind(n,4247)),"@theme/MDXPage",4247],"211396ae":[()=>n.e(3616).then(n.bind(n,394)),"@site/docs/events/cloud-watch-logs.md",394],"24a252b9":[()=>Promise.all([n.e(532),n.e(1098)]).then(n.bind(n,8500)),"@site/docs/middlewares/input-output-logger.md",8500],"28b74e92":[()=>n.e(3839).then(n.bind(n,7978)),"@site/docs/events/cloud-trail.md",7978],"2b234cfe":[()=>n.e(9158).then(n.bind(n,1910)),"@site/docs/events/secrets-manager.md",1910],"2e6cdb22":[()=>Promise.all([n.e(532),n.e(5774)]).then(n.bind(n,4919)),"@site/docs/middlewares/ws-response.md",4919],"2f4f2e7a":[()=>n.e(5222).then(n.bind(n,1950)),"@site/docs/events/alexa.md",1950],"340d0816":[()=>n.e(8729).then(n.bind(n,9571)),"@site/docs/events/mq.md",9571],"34ad80cb":[()=>n.e(4662).then(n.bind(n,9061)),"@site/docs/events/cloud-front.md",9061],"34ebece8":[()=>n.e(5853).then(n.bind(n,2900)),"@site/docs/events/workmail.md",2900],"3673b941":[()=>Promise.all([n.e(532),n.e(2344)]).then(n.bind(n,7017)),"@site/docs/middlewares/rds-signer.md",7017],"393be207":[()=>n.e(7414).then(n.bind(n,1181)),"@site/src/pages/markdown-page.md",1181],"3a74057e":[()=>n.e(517).then(n.bind(n,8740)),"@site/docs/integrations/pino.md",8740],"3db93d31":[()=>Promise.all([n.e(532),n.e(3631)]).then(n.bind(n,3252)),"@site/docs/middlewares/http-multipart-body-parser.md",3252],"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,4775)),"@site/docs/middlewares/warmup.md",4775],"4149078a":[()=>n.e(4183).then(n.bind(n,3171)),"@site/docs/upgrade/2-3.md",3171],"41b3f383":[()=>Promise.all([n.e(532),n.e(479)]).then(n.bind(n,4379)),"@site/docs/middlewares/service-discovery.md",4379],"436b299f":[()=>Promise.all([n.e(532),n.e(5077)]).then(n.bind(n,8230)),"@site/docs/middlewares/http-error-handler.md",8230],"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,2912)),"@site/docs/writing-middlewares/02-configurable-middlewares.md",2912],"4924cac4":[()=>Promise.all([n.e(532),n.e(5270)]).then(n.bind(n,6535)),"@site/docs/middlewares/http-cors.md",6535],"49fe1afb":[()=>n.e(9076).then(n.bind(n,4451)),"@site/docs/writing-middlewares/07-with-typescript.md",4451],"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,3238)),"@site/docs/events/documentdb.md",3238],"5018e04c":[()=>n.e(9862).then(n.bind(n,2258)),"@site/docs/intro/06-typescript.md",2258],"52912c74":[()=>n.e(7452).then(n.bind(n,949)),"@site/docs/events/event-bridge.md",949],"53f1e98a":[()=>n.e(2469).then(n.bind(n,3099)),"@site/docs/events/s3.md",3099],"54ed1cf2":[()=>n.e(6827).then(n.bind(n,5837)),"@site/docs/best-practices/07-profiling.md",5837],"54fc444e":[()=>n.e(1790).then(n.bind(n,737)),"@site/docs/best-practices/02-connection-reuse.md",737],"56ed1c64":[()=>n.e(4097).then(n.bind(n,8928)),"@site/docs/events/01-intro.md",8928],"58ba397f":[()=>Promise.all([n.e(532),n.e(1497)]).then(n.bind(n,7095)),"@site/docs/middlewares/http-urlencode-path-parser.md",7095],"590578cb":[()=>n.e(3181).then(n.bind(n,1115)),"@site/docs/intro/08-history.md",1115],"59ac4306":[()=>Promise.all([n.e(532),n.e(3151)]).then(n.bind(n,487)),"@site/docs/middlewares/http-urlencode-body-parser.md",487],"5a01598e":[()=>n.e(4297).then(n.bind(n,1627)),"@site/docs/upgrade/3-4.md",1627],"5afe45f2":[()=>Promise.all([n.e(532),n.e(5938)]).then(n.bind(n,770)),"@site/docs/intro/02-getting-started.md",770],"5e80d65e":[()=>n.e(1436).then(n.bind(n,9114)),"@site/docs/intro/07-hooks.md",9114],"5e95c892":[()=>n.e(9661).then(n.bind(n,1892)),"@theme/DocsRoot",1892],"5e9f5e1a":[()=>Promise.resolve().then(n.bind(n,6809)),"@generated/docusaurus.config",6809],"632f0854":[()=>n.e(9997).then(n.bind(n,5189)),"@site/docs/writing-middlewares/05-timeouts.md",5189],"646b055a":[()=>n.e(5686).then(n.bind(n,4468)),"@site/docs/events/s3-batch.md",4468],"654635c7":[()=>Promise.all([n.e(532),n.e(1338)]).then(n.bind(n,7803)),"@site/docs/routers/http-router.md",7803],"65ce35be":[()=>n.e(8002).then(n.bind(n,350)),"@site/docs/events/kafka-self-managed.md",350],"667584a0":[()=>n.e(2600).then(n.bind(n,7199)),"@site/docs/events/sns.md",7199],"68318e94":[()=>n.e(811).then(n.bind(n,4756)),"@site/docs/events/api-gateway-authorizer.md",4756],"687b60fb":[()=>n.e(7783).then(n.bind(n,1476)),"@site/docs/upgrade/0-1.md",1476],"6a1376e9":[()=>Promise.all([n.e(532),n.e(8644)]).then(n.bind(n,8550)),"@site/docs/middlewares/sqs-partial-batch-failure.md",8550],"6c4d050a":[()=>Promise.all([n.e(532),n.e(5512)]).then(n.bind(n,9794)),"@site/docs/middlewares/http-header-normalizer.md",9794],70761510:[()=>n.e(5024).then(n.bind(n,3455)),"@site/docs/best-practices/06-small-node-modules.md",3455],"7076eee1":[()=>n.e(481).then(n.bind(n,2865)),"@site/docs/events/application-load-balancer.md",2865],"71d5009c":[()=>n.e(2193).then(n.bind(n,1853)),"@site/docs/events/config.md",1853],73083085:[()=>n.e(8365).then(n.bind(n,3131)),"@site/docs/events/api-gateway-rest.md",3131],"7745d517":[()=>Promise.all([n.e(532),n.e(1702)]).then(n.bind(n,1391)),"@site/docs/middlewares/appconfig.md",1391],79674995:[()=>n.e(8200).then(n.bind(n,1934)),"@site/docs/events/cloud-formation.md",1934],"796ad5a5":[()=>n.e(6172).then(n.bind(n,5621)),"@site/docs/events/appsync.md",5621],"7cb784f6":[()=>n.e(711).then(n.bind(n,4122)),"@site/docs/upgrade/1-2.md",4122],"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,3596)),"@site/docs/events/cognito.md",3596],"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,5707)),"@site/docs/events/kafka-managed-streaming.md",5707],"958c573d":[()=>n.e(8786).then(n.bind(n,5585)),"@site/docs/events/s3-object.md",5585],"9d43f09c":[()=>n.e(8591).then(n.bind(n,7663)),"@site/docs/events/ec2.md",7663],"9d560f77":[()=>n.e(310).then(n.bind(n,8618)),"@site/docs/events/dynamodb.md",8618],a0697f1b:[()=>n.e(5258).then(n.bind(n,957)),"@site/docs/events/vpc-lattice.md",957],a07e9812:[()=>n.e(2511).then(n.bind(n,6916)),"@site/docs/events/rds.md",6916],a17e0e42:[()=>Promise.all([n.e(532),n.e(2201)]).then(n.bind(n,5276)),"@site/docs/middlewares/s3.md",5276],a2b2d33a:[()=>n.e(8974).then(n.bind(n,9635)),"@site/docs/writing-middlewares/06-more-examples.md",9635],a3787fd8:[()=>n.e(9576).then(n.bind(n,8133)),"@site/docs/intro/08-influence.md",8133],a7630442:[()=>n.e(9502).then(n.bind(n,9878)),"@site/docs/intro/11-sponsoring.md",9878],a7bd4aaa:[()=>n.e(8518).then(n.bind(n,8564)),"@theme/DocVersionRoot",8564],a7c9f8b5:[()=>n.e(5898).then(n.bind(n,207)),"@site/docs/events/ses.md",207],a8e9225e:[()=>Promise.all([n.e(532),n.e(9319)]).then(n.bind(n,4579)),"@site/docs/middlewares/http-content-negotiation.md",4579],a94703ab:[()=>Promise.all([n.e(532),n.e(4368)]).then(n.bind(n,4867)),"@theme/DocRoot",4867],acb7d57c:[()=>n.e(1819).then(n.bind(n,7593)),"@site/docs/best-practices/01-intro.md",7593],ace0032f:[()=>n.e(2521).then(n.bind(n,2114)),"@site/docs/integrations/serverless-stack.md",2114],ad1e712e:[()=>n.e(9235).then(n.bind(n,9869)),"@site/docs/middlewares/00-intro.md",9869],aecdbf7e:[()=>Promise.all([n.e(532),n.e(1073)]).then(n.bind(n,9232)),"@site/docs/middlewares/cloudwatch-metrics.md",9232],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,7963)),"@site/docs/middlewares/sts.md",7963],b5163cd3:[()=>n.e(4751).then(n.bind(n,9539)),"@site/docs/integrations/01-intro.md",9539],b5584809:[()=>n.e(2803).then(n.bind(n,8418)),"@site/docs/integrations/serverless-framework.md",8418],b5aee65c:[()=>n.e(4510).then(n.bind(n,8729)),"@site/docs/intro/09-release-cycle.md",8729],b6105e9b:[()=>n.e(8471).then(n.bind(n,530)),"@site/docs/events/code-pipeline.md",530],b6b85ed9:[()=>Promise.all([n.e(532),n.e(6476)]).then(n.bind(n,4670)),"@site/docs/middlewares/http-content-encoding.md",4670],b83c886a:[()=>n.e(8931).then(n.bind(n,5357)),"@site/docs/intro/10-contributing.md",5357],b9c75af0:[()=>n.e(4504).then(n.bind(n,582)),"@site/docs/events/kinesis-streams.md",582],bb2b8b33:[()=>n.e(9905).then(n.bind(n,1969)),"@site/docs/upgrade/4-5.md",1969],bff6c11b:[()=>n.e(4785).then(n.bind(n,4300)),"@site/docs/events/api-gateway-ws.md",4300],c0ad98a5:[()=>Promise.all([n.e(532),n.e(2932)]).then(n.bind(n,3705)),"@site/docs/middlewares/http-partial-response.md",3705],c1378803:[()=>Promise.all([n.e(532),n.e(7450)]).then(n.bind(n,1257)),"@site/docs/integrations/lambda-powertools.md",1257],c21432a2:[()=>n.e(1570).then(n.bind(n,1964)),"@site/docs/intro/06-streamify-response.md",1964],c2371ba7:[()=>Promise.all([n.e(532),n.e(7724)]).then(n.bind(n,3675)),"@site/docs/middlewares/http-response-serializer.md",3675],c4f5d8e4:[()=>Promise.all([n.e(532),n.e(9286),n.e(4195)]).then(n.bind(n,1658)),"@site/src/pages/index.js",1658],c4fefc0c:[()=>n.e(7812).then(n.bind(n,3784)),"@site/docs/best-practices/03-internal-context.md",3784],cb00b214:[()=>n.e(1721).then(n.t.bind(n,6105,19)),"~docs/default/category-docs-tutorialsidebar-category-aws-event-examples-51d.json",6105],cc16eb0f:[()=>n.e(5893).then(n.bind(n,9823)),"@site/docs/events/lex.md",9823],cd47eedf:[()=>n.e(4388).then(n.bind(n,8852)),"@site/docs/intro/05-handling-errors.md",8852],ce7003dc:[()=>n.e(9071).then(n.bind(n,1884)),"@site/docs/writing-middlewares/03-inline-middlewares.md",1884],d0953a14:[()=>Promise.all([n.e(532),n.e(4740)]).then(n.bind(n,217)),"@site/docs/middlewares/validator.md",217],d80baa5c:[()=>n.e(9647).then(n.bind(n,6592)),"@site/docs/writing-middlewares/04-internal-storage.md",6592],da0b5c8a:[()=>Promise.all([n.e(532),n.e(7796)]).then(n.bind(n,8029)),"@site/docs/middlewares/do-not-wait-for-empty-event-loop.md",8029],dbc9373d:[()=>Promise.all([n.e(532),n.e(9116)]).then(n.bind(n,1660)),"@site/docs/middlewares/http-security-headers.md",1660],e0fb88b0:[()=>n.e(4288).then(n.bind(n,4903)),"@site/docs/middlewares/third-party.md",4903],e1c77d88:[()=>n.e(6388).then(n.bind(n,3571)),"@site/docs/integrations/apollo-server.md",3571],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,6831)),"@site/docs/intro/06-testing.md",6831],ec96ff11:[()=>n.e(7276).then(n.bind(n,1415)),"@site/docs/intro/08-utilities.md",1415],ecbeea21:[()=>n.e(9310).then(n.bind(n,6432)),"@site/docs/intro/01-intro.md",6432],f0136a98:[()=>Promise.all([n.e(532),n.e(1575)]).then(n.bind(n,3584)),"@site/docs/middlewares/http-event-normalizer.md",3584],f0886e87:[()=>n.e(3955).then(n.bind(n,4462)),"@site/docs/events/function-url.md",4462],f20815ad:[()=>n.e(4760).then(n.bind(n,6433)),"@site/docs/events/connect.md",6433],f33bafb6:[()=>n.e(8185).then(n.bind(n,2737)),"@site/docs/routers/ws-router.md",2737],f795adf5:[()=>n.e(8841).then(n.bind(n,5196)),"@site/docs/intro/04-early-interrupt.md",5196],f9850e34:[()=>n.e(6177).then(n.bind(n,9983)),"@site/docs/intro/03-how-it-works.md",9983],faf674c6:[()=>n.e(4962).then(n.bind(n,2342)),"@site/docs/events/iot-events.md",2342],ff488875:[()=>Promise.all([n.e(532),n.e(1531)]).then(n.bind(n,4974)),"@site/docs/middlewares/ssm.md",4974]};var s=n(5893);function l(e){let{error:t,retry:n,pastDelay:r}=e;return t?(0,s.jsxs)("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%"},children:[(0,s.jsx)("p",{children:String(t)}),(0,s.jsx)("div",{children:(0,s.jsx)("button",{type:"button",onClick:n,children:"Retry"})})]}):r?(0,s.jsx)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"},children:(0,s.jsx)("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",children:(0,s.jsxs)("g",{fill:"none",fillRule:"evenodd",transform:"translate(1 1)",strokeWidth:"2",children:[(0,s.jsxs)("circle",{cx:"22",cy:"22",r:"6",strokeOpacity:"0",children:[(0,s.jsx)("animate",{attributeName:"r",begin:"1.5s",dur:"3s",values:"6;22",calcMode:"linear",repeatCount:"indefinite"}),(0,s.jsx)("animate",{attributeName:"stroke-opacity",begin:"1.5s",dur:"3s",values:"1;0",calcMode:"linear",repeatCount:"indefinite"}),(0,s.jsx)("animate",{attributeName:"stroke-width",begin:"1.5s",dur:"3s",values:"2;0",calcMode:"linear",repeatCount:"indefinite"})]}),(0,s.jsxs)("circle",{cx:"22",cy:"22",r:"6",strokeOpacity:"0",children:[(0,s.jsx)("animate",{attributeName:"r",begin:"3s",dur:"3s",values:"6;22",calcMode:"linear",repeatCount:"indefinite"}),(0,s.jsx)("animate",{attributeName:"stroke-opacity",begin:"3s",dur:"3s",values:"1;0",calcMode:"linear",repeatCount:"indefinite"}),(0,s.jsx)("animate",{attributeName:"stroke-width",begin:"3s",dur:"3s",values:"2;0",calcMode:"linear",repeatCount:"indefinite"})]}),(0,s.jsx)("circle",{cx:"22",cy:"22",r:"8",children:(0,s.jsx)("animate",{attributeName:"r",begin:"0s",dur:"1.5s",values:"6;1;2;3;4;5;6",calcMode:"linear",repeatCount:"indefinite"})})]})})}):null}var c=n(9670),u=n(226);function d(e,t){if("*"===e)return a()({loading:l,loader:()=>n.e(4204).then(n.bind(n,4204)),modules:["@theme/NotFound"],webpack:()=>[4204],render(e,t){const n=e.default;return(0,s.jsx)(u.z,{value:{plugin:{name:"native",id:"default"}},children:(0,s.jsx)(n,{...t})})}});const r=o[`${e}-${t}`],d={},p=[],f=[],m=(0,c.Z)(r);return Object.entries(m).forEach((e=>{let[t,n]=e;const r=i[n];r&&(d[t]=r[0],p.push(r[1]),f.push(r[2]))})),a().Map({loading:l,loader:d,modules:p,webpack:()=>f,render(t,n){const a=JSON.parse(JSON.stringify(r));Object.entries(t).forEach((t=>{let[n,r]=t;const o=r.default;if(!o)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 o&&"function"!=typeof o||Object.keys(r).filter((e=>"default"!==e)).forEach((e=>{o[e]=r[e]}));let i=a;const s=n.split(".");s.slice(0,-1).forEach((e=>{i=i[e]})),i[s[s.length-1]]=o}));const o=a.__comp;delete a.__comp;const i=a.__context;return delete a.__context,(0,s.jsx)(u.z,{value:i,children:(0,s.jsx)(o,{...a,...n})})}})}const p=[{path:"/markdown-page",component:d("/markdown-page","08c"),exact:!0},{path:"/docs",component:d("/docs","7d9"),routes:[{path:"/docs",component:d("/docs","2ba"),routes:[{path:"/docs",component:d("/docs","bfd"),routes:[{path:"/docs/",component:d("/docs/","a61"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/best-practices/bundling",component:d("/docs/best-practices/bundling","ec3"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/best-practices/connection-reuse",component:d("/docs/best-practices/connection-reuse","e9a"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/best-practices/internal-context",component:d("/docs/best-practices/internal-context","fb7"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/best-practices/intro",component:d("/docs/best-practices/intro","816"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/best-practices/profiling",component:d("/docs/best-practices/profiling","6cf"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/best-practices/small-node-modules",component:d("/docs/best-practices/small-node-modules","385"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/aws-event-examples",component:d("/docs/category/aws-event-examples","116"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/best-practices",component:d("/docs/category/best-practices","320"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/integrations",component:d("/docs/category/integrations","3d4"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/intro-to-middy",component:d("/docs/category/intro-to-middy","a3d"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/middlewares",component:d("/docs/category/middlewares","65f"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/routers",component:d("/docs/category/routers","8cd"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/upgrade",component:d("/docs/category/upgrade","558"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/category/writing-middlewares",component:d("/docs/category/writing-middlewares","c76"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/alexa",component:d("/docs/events/alexa","561"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/api-gateway-authorizer",component:d("/docs/events/api-gateway-authorizer","b1d"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/api-gateway-http",component:d("/docs/events/api-gateway-http","dc8"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/api-gateway-rest",component:d("/docs/events/api-gateway-rest","1d4"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/api-gateway-ws",component:d("/docs/events/api-gateway-ws","ddb"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/application-load-balancer",component:d("/docs/events/application-load-balancer","344"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/appsync",component:d("/docs/events/appsync","c0f"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/cloud-formation",component:d("/docs/events/cloud-formation","134"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/cloud-front",component:d("/docs/events/cloud-front","2e5"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/cloud-trail",component:d("/docs/events/cloud-trail","ec9"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/cloud-watch-logs",component:d("/docs/events/cloud-watch-logs","21e"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/code-commit",component:d("/docs/events/code-commit","676"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/code-pipeline",component:d("/docs/events/code-pipeline","785"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/cognito",component:d("/docs/events/cognito","207"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/config",component:d("/docs/events/config","bfe"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/connect",component:d("/docs/events/connect","f4d"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/documentdb",component:d("/docs/events/documentdb","7a2"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/dynamodb",component:d("/docs/events/dynamodb","53a"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/ec2",component:d("/docs/events/ec2","94f"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/event-bridge",component:d("/docs/events/event-bridge","3bf"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/function-url",component:d("/docs/events/function-url","b85"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/intro",component:d("/docs/events/intro","e69"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/iot",component:d("/docs/events/iot","cea"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/iot-events",component:d("/docs/events/iot-events","6c2"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/kafka-managed-streaming",component:d("/docs/events/kafka-managed-streaming","bbd"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/kafka-self-managed",component:d("/docs/events/kafka-self-managed","d9e"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/kinesis-firehose",component:d("/docs/events/kinesis-firehose","253"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/kinesis-streams",component:d("/docs/events/kinesis-streams","9aa"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/lex",component:d("/docs/events/lex","af4"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/mq",component:d("/docs/events/mq","5eb"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/rds",component:d("/docs/events/rds","3c4"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/s3",component:d("/docs/events/s3","05f"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/s3-batch",component:d("/docs/events/s3-batch","e3b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/s3-object",component:d("/docs/events/s3-object","d5a"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/secrets-manager",component:d("/docs/events/secrets-manager","ea6"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/ses",component:d("/docs/events/ses","22b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/sns",component:d("/docs/events/sns","af6"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/sqs",component:d("/docs/events/sqs","2ce"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/vpc-lattice",component:d("/docs/events/vpc-lattice","ec4"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/events/workmail",component:d("/docs/events/workmail","541"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/faq",component:d("/docs/faq","e79"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/apollo-server",component:d("/docs/integrations/apollo-server","d7d"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/intro",component:d("/docs/integrations/intro","0d2"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/lambda-powertools",component:d("/docs/integrations/lambda-powertools","57c"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/pino",component:d("/docs/integrations/pino","2b6"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/RDS",component:d("/docs/integrations/RDS","c6b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/serverless-framework",component:d("/docs/integrations/serverless-framework","95a"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/integrations/serverless-stack",component:d("/docs/integrations/serverless-stack","206"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/contributing",component:d("/docs/intro/contributing","e03"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/early-interrupt",component:d("/docs/intro/early-interrupt","5ac"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/getting-started",component:d("/docs/intro/getting-started","224"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/handling-errors",component:d("/docs/intro/handling-errors","9da"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/history",component:d("/docs/intro/history","b44"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/hooks",component:d("/docs/intro/hooks","bb3"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/how-it-works",component:d("/docs/intro/how-it-works","965"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/influence",component:d("/docs/intro/influence","6be"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/release-cycle",component:d("/docs/intro/release-cycle","f31"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/sponsoring",component:d("/docs/intro/sponsoring","578"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/streamify-response",component:d("/docs/intro/streamify-response","9ee"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/testing",component:d("/docs/intro/testing","064"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/typescript",component:d("/docs/intro/typescript","3e8"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/intro/utilities",component:d("/docs/intro/utilities","b1f"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/appconfig",component:d("/docs/middlewares/appconfig","ca4"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/cloudwatch-metrics",component:d("/docs/middlewares/cloudwatch-metrics","8bc"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/do-not-wait-for-empty-event-loop",component:d("/docs/middlewares/do-not-wait-for-empty-event-loop","579"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/dynamodb",component:d("/docs/middlewares/dynamodb","8d2"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/error-logger",component:d("/docs/middlewares/error-logger","388"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/event-normalizer",component:d("/docs/middlewares/event-normalizer","6b6"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-content-encoding",component:d("/docs/middlewares/http-content-encoding","404"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-content-negotiation",component:d("/docs/middlewares/http-content-negotiation","b8b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-cors",component:d("/docs/middlewares/http-cors","d5f"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-error-handler",component:d("/docs/middlewares/http-error-handler","044"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-event-normalizer",component:d("/docs/middlewares/http-event-normalizer","442"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-header-normalizer",component:d("/docs/middlewares/http-header-normalizer","614"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-json-body-parser",component:d("/docs/middlewares/http-json-body-parser","6df"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-multipart-body-parser",component:d("/docs/middlewares/http-multipart-body-parser","022"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-partial-response",component:d("/docs/middlewares/http-partial-response","35c"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-response-serializer",component:d("/docs/middlewares/http-response-serializer","041"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-security-headers",component:d("/docs/middlewares/http-security-headers","410"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-urlencode-body-parser",component:d("/docs/middlewares/http-urlencode-body-parser","041"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/http-urlencode-path-parser",component:d("/docs/middlewares/http-urlencode-path-parser","678"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/input-output-logger",component:d("/docs/middlewares/input-output-logger","40b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/intro",component:d("/docs/middlewares/intro","e79"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/rds-signer",component:d("/docs/middlewares/rds-signer","a53"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/s3",component:d("/docs/middlewares/s3","b3a"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/s3-object-response",component:d("/docs/middlewares/s3-object-response","5ed"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/secrets-manager",component:d("/docs/middlewares/secrets-manager","381"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/service-discovery",component:d("/docs/middlewares/service-discovery","d35"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/sqs-partial-batch-failure",component:d("/docs/middlewares/sqs-partial-batch-failure","4f2"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/ssm",component:d("/docs/middlewares/ssm","42b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/sts",component:d("/docs/middlewares/sts","522"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/third-party",component:d("/docs/middlewares/third-party","588"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/validator",component:d("/docs/middlewares/validator","37c"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/warmup",component:d("/docs/middlewares/warmup","d75"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/ws-json-body-parser",component:d("/docs/middlewares/ws-json-body-parser","8b5"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/middlewares/ws-response",component:d("/docs/middlewares/ws-response","702"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/routers/http-router",component:d("/docs/routers/http-router","9b1"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/routers/ws-router",component:d("/docs/routers/ws-router","354"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/upgrade/0-1",component:d("/docs/upgrade/0-1","95b"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/upgrade/1-2",component:d("/docs/upgrade/1-2","667"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/upgrade/2-3",component:d("/docs/upgrade/2-3","b3c"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/upgrade/3-4",component:d("/docs/upgrade/3-4","809"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/upgrade/4-5",component:d("/docs/upgrade/4-5","9a2"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/configurable-middlewares",component:d("/docs/writing-middlewares/configurable-middlewares","4e7"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/inline-middlewares",component:d("/docs/writing-middlewares/inline-middlewares","d97"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/internal-storage",component:d("/docs/writing-middlewares/internal-storage","cc1"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/intro",component:d("/docs/writing-middlewares/intro","b44"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/more-examples",component:d("/docs/writing-middlewares/more-examples","fa2"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/timeouts",component:d("/docs/writing-middlewares/timeouts","1a6"),exact:!0,sidebar:"tutorialSidebar"},{path:"/docs/writing-middlewares/with-typescript",component:d("/docs/writing-middlewares/with-typescript","863"),exact:!0,sidebar:"tutorialSidebar"}]}]}]},{path:"/",component:d("/","645"),exact:!0},{path:"*",component:d("*")}]},8934:(e,t,n)=>{"use strict";n.d(t,{_:()=>o,t:()=>i});var r=n(7294),a=n(5893);const o=r.createContext(!1);function i(e){let{children:t}=e;const[n,i]=(0,r.useState)(!1);return(0,r.useEffect)((()=>{i(!0)}),[]),(0,a.jsx)(o.Provider,{value:n,children:t})}},7221:(e,t,n)=>{"use strict";var r=n(7294),a=n(745),o=n(3727),i=n(405),s=n(412);const l=[n(2497),n(3310),n(8320),n(2295)];var c=n(723),u=n(6550),d=n(8790),p=n(5893);function f(e){let{children:t}=e;return(0,p.jsx)(p.Fragment,{children:t})}var m=n(5742),h=n(2263),g=n(4996),b=n(6668),y=n(1944),v=n(4711),w=n(9727),k=n(3320),x=n(8780),S=n(197);function E(){const{i18n:{currentLocale:e,defaultLocale:t,localeConfigs:n}}=(0,h.Z)(),r=(0,v.l)(),a=n[e].htmlLang,o=e=>e.replace("-","_");return(0,p.jsxs)(m.Z,{children:[Object.entries(n).map((e=>{let[t,{htmlLang:n}]=e;return(0,p.jsx)("link",{rel:"alternate",href:r.createUrl({locale:t,fullyQualified:!0}),hrefLang:n},t)})),(0,p.jsx)("link",{rel:"alternate",href:r.createUrl({locale:t,fullyQualified:!0}),hrefLang:"x-default"}),(0,p.jsx)("meta",{property:"og:locale",content:o(a)}),Object.values(n).filter((e=>a!==e.htmlLang)).map((e=>(0,p.jsx)("meta",{property:"og:locale:alternate",content:o(e.htmlLang)},`meta-og-${e.htmlLang}`)))]})}function _(e){let{permalink:t}=e;const{siteConfig:{url:n}}=(0,h.Z)(),r=function(){const{siteConfig:{url:e,baseUrl:t,trailingSlash:n}}=(0,h.Z)(),{pathname:r}=(0,u.TH)();return e+(0,x.applyTrailingSlash)((0,g.Z)(r),{trailingSlash:n,baseUrl:t})}(),a=t?`${n}${t}`:r;return(0,p.jsxs)(m.Z,{children:[(0,p.jsx)("meta",{property:"og:url",content:a}),(0,p.jsx)("link",{rel:"canonical",href:a})]})}function C(){const{i18n:{currentLocale:e}}=(0,h.Z)(),{metadata:t,image:n}=(0,b.L)();return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(m.Z,{children:[(0,p.jsx)("meta",{name:"twitter:card",content:"summary_large_image"}),(0,p.jsx)("body",{className:w.h})]}),n&&(0,p.jsx)(y.d,{image:n}),(0,p.jsx)(_,{}),(0,p.jsx)(E,{}),(0,p.jsx)(S.Z,{tag:k.HX,locale:e}),(0,p.jsx)(m.Z,{children:t.map(((e,t)=>(0,p.jsx)("meta",{...e},t)))})]})}const T=new Map;function j(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 N=n(8934),R=n(8940),A=n(469);function L(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 P=function(e){let{children:t,location:n,previousLocation:r}=e;return(0,A.Z)((()=>{r!==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:r}),L("onRouteDidUpdate",{previousLocation:r,location:n}))}),[r,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=s.Z.canUseDOM?L("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=L("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(0,p.jsx)(P,{previousLocation:this.previousLocation,location:t,children:(0,p.jsx)(u.AW,{location:t,render:()=>e})})}}const D=I,M="__docusaurus-base-url-issue-banner-container",F="__docusaurus-base-url-issue-banner",z="__docusaurus-base-url-issue-banner-suggestion-container";function B(e){return`\ndocument.addEventListener('DOMContentLoaded', function maybeInsertBanner() {\n var shouldInsert = typeof window['docusaurus'] === 'undefined';\n shouldInsert && insertBanner();\n});\n\nfunction insertBanner() {\n var bannerContainer = document.createElement('div');\n bannerContainer.id = '${M}';\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(/{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 Y=n(9670);const K=new Set,X=new Set,J=()=>navigator.connection?.effectiveType.includes("2g")||navigator.connection?.saveData,ee={prefetch(e){if(!(e=>!J()&&!X.has(e)&&!K.has(e))(e))return!1;K.add(e);const t=(0,d.f)(c.Z,e).flatMap((e=>{return t=e.route.path,Object.entries(V).filter((e=>{let[n]=e;return n.replace(/-[^-]+$/,"")===t})).flatMap((e=>{let[,t]=e;return Object.values((0,Y.Z)(t))}));var t}));return Promise.all(t.map((e=>{const t=n.gca(e);return t&&!t.includes("undefined")?Q(t).catch((()=>{})):Promise.resolve()})))},preload:e=>!!(e=>!J()&&!X.has(e))(e)&&(X.add(e),O(e))},te=Object.freeze(ee),ne=Boolean(!0);if(s.Z.canUseDOM){window.docusaurus=te;const e=document.getElementById("__docusaurus"),t=(0,p.jsx)(i.B6,{children:(0,p.jsx)(o.VK,{children:(0,p.jsx)(W,{})})}),n=(e,t)=>{console.error("Docusaurus React Root onRecoverableError:",e,t)},s=()=>{if(ne)r.startTransition((()=>{a.hydrateRoot(e,t,{onRecoverableError:n})}));else{const o=a.createRoot(e,{onRecoverableError:n});r.startTransition((()=>{o.render(t)}))}};O(window.location.pathname).then(s)}},8940:(e,t,n)=>{"use strict";n.d(t,{_:()=>d,M:()=>p});var r=n(7294),a=n(6809);const o=JSON.parse('{"docusaurus-lunr-search":{"default":{"fileNames":{"searchDoc":"search-doc-1700079117944.json","lunrIndex":"lunr-index-1700079117944.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":"upgrade/4-5","path":"/docs/upgrade/4-5","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 s=n(7529);const l=JSON.parse('{"docusaurusVersion":"3.0.0","siteVersion":"0.0.0","pluginVersions":{"docusaurus-plugin-content-docs":{"type":"package","name":"@docusaurus/plugin-content-docs","version":"3.0.0"},"docusaurus-plugin-content-blog":{"type":"package","name":"@docusaurus/plugin-content-blog","version":"3.0.0"},"docusaurus-plugin-content-pages":{"type":"package","name":"@docusaurus/plugin-content-pages","version":"3.0.0"},"docusaurus-plugin-sitemap":{"type":"package","name":"@docusaurus/plugin-sitemap","version":"3.0.0"},"docusaurus-theme-classic":{"type":"package","name":"@docusaurus/theme-classic","version":"3.0.0"},"docusaurus-lunr-search":{"type":"package","name":"docusaurus-lunr-search","version":"3.3.0"}}}');var c=n(5893);const u={siteConfig:a.default,siteMetadata:l,globalData:o,i18n:i,codeTranslations:s},d=r.createContext(u);function p(e){let{children:t}=e;return(0,c.jsx)(d.Provider,{value:u,children:t})}},4763:(e,t,n)=>{"use strict";n.d(t,{Z:()=>f});var r=n(7294),a=n(412),o=n(5742),i=n(8780),s=n(63),l=n(5893);function c(e){let{error:t,tryAgain:n}=e;return(0,l.jsxs)("div",{style:{display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"flex-start",minHeight:"100vh",width:"100%",maxWidth:"80ch",fontSize:"20px",margin:"0 auto",padding:"1rem"},children:[(0,l.jsx)("h1",{style:{fontSize:"3rem"},children:"This page crashed"}),(0,l.jsx)("button",{type:"button",onClick:n,style:{margin:"1rem 0",fontSize:"2rem",cursor:"pointer",borderRadius:20,padding:"1rem"},children:"Try again"}),(0,l.jsx)(u,{error:t})]})}function u(e){let{error:t}=e;const n=(0,i.getErrorCausalChain)(t).map((e=>e.message)).join("\n\nCause:\n");return(0,l.jsx)("p",{style:{whiteSpace:"pre-wrap"},children:n})}function d(e){let{error:t,tryAgain:n}=e;return(0,l.jsxs)(f,{fallback:()=>(0,l.jsx)(c,{error:t,tryAgain:n}),children:[(0,l.jsx)(o.Z,{children:(0,l.jsx)("title",{children:"Page Error"})}),(0,l.jsx)(s.Z,{children:(0,l.jsx)(c,{error:t,tryAgain:n})})]})}const p=e=>(0,l.jsx)(d,{...e});class f 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??p)(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});n(7294);var r=n(405),a=n(5893);function o(e){return(0,a.jsx)(r.ql,{...e})}},9960:(e,t,n)=>{"use strict";n.d(t,{Z:()=>f});var r=n(7294),a=n(3727),o=n(8780),i=n(2263),s=n(3919),l=n(412),c=n(5893);const u=r.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,...y}=e;const{siteConfig:{trailingSlash:v,baseUrl:w}}=(0,i.Z)(),{withBaseUrl:k}=(0,d.C)(),x=(0,r.useContext)(u),S=(0,r.useRef)(null);(0,r.useImperativeHandle)(t,(()=>S.current));const E=p||f;const _=(0,s.Z)(E),C=E?.replace("pathname://","");let T=void 0!==C?(j=C,b&&(e=>e.startsWith("/"))(j)?k(j):j):void 0;var j;T&&_&&(T=(0,o.applyTrailingSlash)(T,{trailingSlash:v,baseUrl:w}));const N=(0,r.useRef)(!1),R=n?a.OL:a.rU,A=l.Z.canUseIntersectionObserver,L=(0,r.useRef)(),P=()=>{N.current||null==T||(window.docusaurus.preload(T),N.current=!0)};(0,r.useEffect)((()=>(!A&&_&&null!=T&&window.docusaurus.prefetch(T),()=>{A&&L.current&&L.current.disconnect()})),[L,T,A,_]);const O=T?.startsWith("#")??!1,I=!T||!_||O;return I||g||x.collectLink(T),I?(0,c.jsx)("a",{ref:S,href:T,...E&&!_&&{target:"_blank",rel:"noopener noreferrer"},...y}):(0,c.jsx)(R,{...y,onMouseEnter:P,onTouchStart:P,innerRef:e=>{S.current=e,A&&e&&_&&(L.current=new window.IntersectionObserver((t=>{t.forEach((t=>{e===t.target&&(t.isIntersecting||t.intersectionRatio>0)&&(L.current.unobserve(e),L.current.disconnect(),null!=T&&window.docusaurus.prefetch(T))}))})),L.current.observe(e))},to:T,...n&&{isActive:h,activeClassName:m}})}const f=r.forwardRef(p)},5999:(e,t,n)=>{"use strict";n.d(t,{Z:()=>c,I:()=>l});var r=n(7294),a=n(5893);function o(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 i=n(7529);function s(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 i[t??n]??n??t}function l(e,t){let{message:n,id:r}=e;return o(s({message:n,id:r}),t)}function c(e){let{children:t,id:n,values:r}=e;if(t&&"string"!=typeof t)throw console.warn("Illegal children",t),new Error("The Docusaurus component only accept simple string values");const i=s({message:t,id:n});return(0,a.jsx)(a.Fragment,{children:o(i,r)})}},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:()=>s});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 s=n.startsWith(t)?n:t+n.replace(/^\//,"");return i?e+s:s}(t,e,n,r)),[t,e]);return{withBaseUrl:n}}function s(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._)}},469:(e,t,n)=>{"use strict";n.d(t,{Z:()=>a});var r=n(7294);const a=n(412).Z.canUseDOM?r.useLayoutEffect:r.useEffect},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 s=a?`${a}.${o}`:o;r(i)?e(i,s):t[s]=i}))}(e),t}},226:(e,t,n)=>{"use strict";n.d(t,{_:()=>o,z:()=>i});var r=n(7294),a=n(5893);const o=r.createContext(null);function i(e){let{children:t,value:n}=e;const i=r.useContext(o),s=(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:i,value:n})),[i,n]);return(0,a.jsx)(o.Provider,{value:s,children:t})}},4104:(e,t,n)=>{"use strict";n.d(t,{Iw:()=>f,gA:()=>u,_r:()=>l,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 s={},l=()=>(0,a.OD)("docusaurus-plugin-content-docs")??s,c=e=>(0,a.eZ)("docusaurus-plugin-content-docs",e,{failfast:!0});function u(e){void 0===e&&(e={});const t=l(),{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(2573),a=n(6809);!function(e){const{themeConfig:{prism:t}}=a.default,{additionalLanguages:r}=t;globalThis.Prism=e,r.forEach((e=>{"php"===e&&n(6854),n(6726)(`./prism-${e}`)})),delete globalThis.Prism}(r.p1)},2503:(e,t,n)=>{"use strict";n.d(t,{Z:()=>c});n(7294);var r=n(6010),a=n(5999),o=n(6668),i=n(9960);const s={anchorWithStickyNavbar:"anchorWithStickyNavbar_LWe7",anchorWithHideOnScrollNavbar:"anchorWithHideOnScrollNavbar_WYt5"};var l=n(5893);function c(e){let{as:t,id:n,...c}=e;const{navbar:{hideOnScroll:u}}=(0,o.L)();if("h1"===t||!n)return(0,l.jsx)(t,{...c,id:void 0});const d=(0,a.I)({id:"theme.common.headingLinkTitle",message:"Direct link to {heading}",description:"Title for link to heading"},{heading:"string"==typeof c.children?c.children:n});return(0,l.jsxs)(t,{...c,className:(0,r.Z)("anchor",u?s.anchorWithHideOnScrollNavbar:s.anchorWithStickyNavbar,c.className),id:n,children:[c.children,(0,l.jsx)(i.Z,{className:"hash-link",to:`#${n}`,"aria-label":d,title:d,children:"\u200b"})]})}},9471:(e,t,n)=>{"use strict";n.d(t,{Z:()=>o});n(7294);const r={iconExternalLink:"iconExternalLink_nPIU"};var a=n(5893);function o(e){let{width:t=13.5,height:n=13.5}=e;return(0,a.jsx)("svg",{width:t,height:n,"aria-hidden":"true",viewBox:"0 0 24 24",className:r.iconExternalLink,children:(0,a.jsx)("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"})})}},63:(e,t,n)=>{"use strict";n.d(t,{Z:()=>gt});var r=n(7294),a=n(6010),o=n(4763),i=n(1944),s=n(6550),l=n(5999),c=n(5936),u=n(5893);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,c.S)((n=>{let{location:r}=n;e.current&&!r.hash&&"PUSH"===t&&p(e.current)})),{containerRef:e,onClick:n}}const m=(0,l.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:r}=f();return(0,u.jsx)("div",{ref:n,role:"region","aria-label":m,children:(0,u.jsx)("a",{...e,href:`#${d}`,onClick:r,children:t})})}var g=n(5281),b=n(9727);const y={skipToContent:"skipToContent_fXgn"};function v(){return(0,u.jsx)(h,{className:y.skipToContent})}var w=n(6668),k=n(9689);function x(e){let{width:t=21,height:n=21,color:r="currentColor",strokeWidth:a=1.2,className:o,...i}=e;return(0,u.jsx)("svg",{viewBox:"0 0 15 15",width:t,height:n,...i,children:(0,u.jsx)("g",{stroke:r,strokeWidth:a,children:(0,u.jsx)("path",{d:"M.75.75l13.5 13.5M14.25.75L.75 14.25"})})})}const S={closeButton:"closeButton_CVFx"};function E(e){return(0,u.jsx)("button",{type:"button","aria-label":(0,l.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",S.closeButton,e.className),children:(0,u.jsx)(x,{width:14,height:14,strokeWidth:3.1})})}const _={content:"content_knG7"};function C(e){const{announcementBar:t}=(0,w.L)(),{content:n}=t;return(0,u.jsx)("div",{...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 j(){const{announcementBar:e}=(0,w.L)(),{isActive:t,close:n}=(0,k.nT)();if(!t)return null;const{backgroundColor:r,textColor:a,isCloseable:o}=e;return(0,u.jsxs)("div",{className:T.announcementBar,style:{backgroundColor:r,color:a},role:"banner",children:[o&&(0,u.jsx)("div",{className:T.announcementBarPlaceholder}),(0,u.jsx)(C,{className:T.announcementBarContent}),o&&(0,u.jsx)(E,{onClick:n,className:T.announcementBarClose})]})}var N=n(3163),R=n(2466);var A=n(902),L=n(3102);const P=r.createContext(null);function O(e){let{children:t}=e;const n=function(){const e=(0,N.e)(),t=(0,L.HY)(),[n,a]=(0,r.useState)(!1),o=null!==t.component,i=(0,A.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(0,u.jsx)(P.Provider,{value:n,children:t})}function I(e){if(e.component){const t=e.component;return(0,u.jsx)(t,{...e.props})}}function D(){const e=(0,r.useContext)(P);if(!e)throw new A.i6("NavbarSecondaryMenuDisplayProvider");const[t,n]=e,a=(0,r.useCallback)((()=>n(!1)),[n]),o=(0,L.HY)();return(0,r.useMemo)((()=>({shown:t,hide:a,content:I(o)})),[a,o,t])}function M(e){let{header:t,primaryMenu:n,secondaryMenu:r}=e;const{shown:o}=D();return(0,u.jsxs)("div",{className:"navbar-sidebar",children:[t,(0,u.jsxs)("div",{className:(0,a.Z)("navbar-sidebar__items",{"navbar-sidebar__items--show-secondary":o}),children:[(0,u.jsx)("div",{className:"navbar-sidebar__item menu",children:n}),(0,u.jsx)("div",{className:"navbar-sidebar__item menu",children:r})]})]})}var F=n(2949),z=n(2389);function B(e){return(0,u.jsx)("svg",{viewBox:"0 0 24 24",width:24,height:24,...e,children:(0,u.jsx)("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 $(e){return(0,u.jsx)("svg",{viewBox:"0 0 24 24",width:24,height:24,...e,children:(0,u.jsx)("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 U={toggle:"toggle_vylO",toggleButton:"toggleButton_gllP",darkToggleIcon:"darkToggleIcon_wfgR",lightToggleIcon:"lightToggleIcon_pyhR",toggleButtonDisabled:"toggleButtonDisabled_aARS"};function q(e){let{className:t,buttonClassName:n,value:r,onChange:o}=e;const i=(0,z.Z)(),s=(0,l.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"===r?(0,l.I)({message:"dark mode",id:"theme.colorToggle.ariaLabel.mode.dark",description:"The name for the dark color mode"}):(0,l.I)({message:"light mode",id:"theme.colorToggle.ariaLabel.mode.light",description:"The name for the light color mode"})});return(0,u.jsx)("div",{className:(0,a.Z)(U.toggle,t),children:(0,u.jsxs)("button",{className:(0,a.Z)("clean-btn",U.toggleButton,!i&&U.toggleButtonDisabled,n),type:"button",onClick:()=>o("dark"===r?"light":"dark"),disabled:!i,title:s,"aria-label":s,"aria-live":"polite",children:[(0,u.jsx)(B,{className:(0,a.Z)(U.toggleIcon,U.lightToggleIcon)}),(0,u.jsx)($,{className:(0,a.Z)(U.toggleIcon,U.darkToggleIcon)})]})})}const H=r.memo(q),Z={darkNavbarColorModeToggle:"darkNavbarColorModeToggle_X3D1"};function G(e){let{className:t}=e;const n=(0,w.L)().navbar.style,r=(0,w.L)().colorMode.disableSwitch,{colorMode:a,setColorMode:o}=(0,F.I)();return r?null:(0,u.jsx)(H,{className:t,buttonClassName:"dark"===n?Z.darkNavbarColorModeToggle:void 0,value:a,onChange:o})}var W=n(1327);function V(){return(0,u.jsx)(W.Z,{className:"navbar__brand",imageClassName:"navbar__logo",titleClassName:"navbar__title text--truncate"})}function Q(){const e=(0,N.e)();return(0,u.jsx)("button",{type:"button","aria-label":(0,l.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(),children:(0,u.jsx)(x,{color:"var(--ifm-color-emphasis-600)"})})}function Y(){return(0,u.jsxs)("div",{className:"navbar-sidebar__brand",children:[(0,u.jsx)(V,{}),(0,u.jsx)(G,{className:"margin-right--md"}),(0,u.jsx)(Q,{})]})}var K=n(9960),X=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:r,href:a,label:o,html:i,isDropdownLink:s,prependBaseUrlToHref:l,...c}=e;const d=(0,X.Z)(r),p=(0,X.Z)(t),f=(0,X.Z)(a,{forcePrependBaseUrl:!0}),m=o&&a&&!(0,J.Z)(a),h=i?{dangerouslySetInnerHTML:{__html:i}}:{children:(0,u.jsxs)(u.Fragment,{children:[o,m&&(0,u.jsx)(te.Z,{...s&&{width:12,height:12}})]})};return a?(0,u.jsx)(K.Z,{href:l?f:a,...c,...h}):(0,u.jsx)(K.Z,{to:d,isNavLink:!0,...(t||n)&&{isActive:(e,t)=>n?ee(n,t.pathname):t.pathname.startsWith(p)},...c,...h})}function re(e){let{className:t,isDropdownItem:n=!1,...r}=e;const o=(0,u.jsx)(ne,{className:(0,a.Z)(n?"dropdown__link":"navbar__item navbar__link",t),isDropdownLink:n,...r});return n?(0,u.jsx)("li",{children:o}):o}function ae(e){let{className:t,isDropdownItem:n,...r}=e;return(0,u.jsx)("li",{className:"menu__list-item",children:(0,u.jsx)(ne,{className:(0,a.Z)("menu__link",t),...r})})}function oe(e){let{mobile:t=!1,position:n,...r}=e;const a=t?ae:re;return(0,u.jsx)(a,{...r,activeClassName:r.activeClassName??(t?"menu__link--active":"navbar__link--active")})}var ie=n(6043),se=n(8596),le=n(2263);function ce(e,t){return e.some((e=>function(e,t){return!!(0,se.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 l=(0,r.useRef)(null),[c,d]=(0,r.useState)(!1);return(0,r.useEffect)((()=>{const e=e=>{l.current&&!l.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)}}),[l]),(0,u.jsxs)("div",{ref:l,className:(0,a.Z)("navbar__item","dropdown","dropdown--hoverable",{"dropdown--right":"right"===n,"dropdown--show":c}),children:[(0,u.jsx)(ne,{"aria-haspopup":"true","aria-expanded":c,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(!c))},children:s.children??s.label}),(0,u.jsx)("ul",{className:"dropdown__menu",children:t.map(((e,t)=>(0,r.createElement)(je,{isDropdownItem:!0,activeClassName:"dropdown__link--active",...e,key:t})))})]})}function de(e){let{items:t,className:n,position:o,onClick:i,...l}=e;const c=function(){const{siteConfig:{baseUrl:e}}=(0,le.Z)(),{pathname:t}=(0,s.TH)();return t.replace(e,"/")}(),d=ce(t,c),{collapsed:p,toggleCollapsed:f,setCollapsed:m}=(0,ie.u)({initialState:()=>!d});return(0,r.useEffect)((()=>{d&&m(!d)}),[c,d,m]),(0,u.jsxs)("li",{className:(0,a.Z)("menu__list-item",{"menu__list-item--collapsed":p}),children:[(0,u.jsx)(ne,{role:"button",className:(0,a.Z)("menu__link menu__link--sublist menu__link--sublist-caret",n),...l,onClick:e=>{e.preventDefault(),f()},children:l.children??l.label}),(0,u.jsx)(ie.z,{lazy:!0,as:"ul",className:"menu__list",collapsed:p,children:t.map(((e,t)=>(0,r.createElement)(je,{mobile:!0,isDropdownItem:!0,onClick:i,activeClassName:"menu__link--active",...e,key:t})))})]})}function pe(e){let{mobile:t=!1,...n}=e;const r=t?de:ue;return(0,u.jsx)(r,{...n})}var fe=n(4711);function me(e){let{width:t=20,height:n=20,...r}=e;return(0,u.jsx)("svg",{viewBox:"0 0 24 24",width:t,height:n,"aria-hidden":!0,...r,children:(0,u.jsx)("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),be=n(813),ye=n.n(be);function ve(){const e=(0,s.TH)(),t=(0,s.k6)(),{siteConfig:{baseUrl:n}}=(0,le.Z)(),[a,o]=(0,r.useState)({wordToHighlight:"",isTitleSuggestion:!1,titleText:""});return(0,r.useEffect)((()=>{if(!e.state?.highlightState||0===e.state.highlightState.wordToHighlight.length)return;o(e.state.highlightState);const{highlightState:n,...r}=e.state;t.replace({...e,state:r})}),[e.state?.highlightState,t,e]),(0,r.useEffect)((()=>{if(0===a.wordToHighlight.length)return;const e=document.getElementsByTagName("article")[0]??document.getElementsByTagName("main")[0];if(!e)return;const t=new(ye())(e),n={ignoreJoiners:!0};return t.mark(a.wordToHighlight,n),()=>t.unmark(n)}),[a,n]),null}const we=e=>{const t=(0,r.useRef)(!1),o=(0,r.useRef)(null),[i,l]=(0,r.useState)(!1),c=(0,s.k6)(),{siteConfig:d={}}=(0,le.Z)(),p=(d.plugins||[]).find((e=>Array.isArray(e)&&"string"==typeof e[0]&&e[0].includes("docusaurus-lunr-search"))),f=(0,z.Z)(),{baseUrl:m}=d,h=p&&p[1]?.assetUrl||m,g=(0,ge.eZ)("docusaurus-lunr-search"),b=()=>{t.current||(Promise.all([fetch(`${h}${g.fileNames.searchDoc}`).then((e=>e.json())),fetch(`${h}${g.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;const{searchDocs:a,options:o}=t;a&&0!==a.length&&(((e,t,n,r)=>{new n({searchDocs:e,searchIndex:t,baseUrl:m,inputSelector:"#search_input_react",handleSelected:(e,t,n)=>{const a=n.url||"/";document.createElement("a").href=a,e.setVal(""),t.target.blur();let o="";if(r.highlightResult)try{const e=(n.text||n.subcategory||n.title).match(new RegExp("\\w*","g"));if(e&&e.length>0){const t=document.createElement("div");t.innerHTML=e[0],o=t.textContent}}catch(i){console.log(i)}c.push(a,{highlightState:{wordToHighlight:o}})}})})(a,n,r,o),l(!0))})),t.current=!0)},y=(0,r.useCallback)((t=>{o.current.contains(t.target)||o.current.focus(),e.handleSearchBarToggle&&e.handleSearchBarToggle(!e.isSearchBarExpanded)}),[e.isSearchBarExpanded]);return f&&b(),(0,u.jsxs)("div",{className:"navbar__search",children:[(0,u.jsx)("span",{"aria-label":"expand searchbar",role:"button",className:(0,a.Z)("search-icon",{"search-icon-hidden":e.isSearchBarExpanded}),onClick:y,onKeyDown:y,tabIndex:0}),(0,u.jsx)("input",{id:"search_input_react",type:"search",placeholder:i?"Search Ctrl+K":"Loading...","aria-label":"Search",className:(0,a.Z)("navbar__search-input",{"search-bar-expanded":e.isSearchBarExpanded},{"search-bar":!e.isSearchBarExpanded}),onClick:b,onMouseOver:b,onFocus:y,onBlur:y,ref:o,disabled:!i}),(0,u.jsx)(ve,{})]},"search-box")},ke={navbarSearchContainer:"navbarSearchContainer_Bca1"};function xe(e){let{children:t,className:n}=e;return(0,u.jsx)("div",{className:(0,a.Z)(n,ke.navbarSearchContainer),children:t})}var Se=n(4104),Ee=n(3438);var _e=n(373);const Ce=e=>e.docs.find((t=>t.id===e.mainDocId));const Te={default:oe,localeDropdown:function(e){let{mobile:t,dropdownItemsBefore:n,dropdownItemsAfter:r,queryString:a="",...o}=e;const{i18n:{currentLocale:i,locales:c,localeConfigs:d}}=(0,le.Z)(),p=(0,fe.l)(),{search:f,hash:m}=(0,s.TH)(),h=[...n,...c.map((e=>{const n=`${`pathname://${p.createUrl({locale:e,fullyQualified:!1})}`}${f}${m}${a}`;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":""}})),...r],g=t?(0,l.I)({message:"Languages",id:"theme.navbar.mobileLanguageDropdown.label",description:"The label for the mobile language switcher dropdown"}):d[i].label;return(0,u.jsx)(pe,{...o,mobile:t,label:(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(me,{className:he}),g]}),items:h})},search:function(e){let{mobile:t,className:n}=e;return t?null:(0,u.jsx)(xe,{className:n,children:(0,u.jsx)(we,{})})},dropdown:pe,html:function(e){let{value:t,className:n,mobile:r=!1,isDropdownItem:o=!1}=e;const i=o?"li":"div";return(0,u.jsx)(i,{className:(0,a.Z)({navbar__item:!r&&!o,"menu__list-item":r},n),dangerouslySetInnerHTML:{__html:t}})},doc:function(e){let{docId:t,label:n,docsPluginId:r,...a}=e;const{activeDoc:o}=(0,Se.Iw)(r),i=(0,Ee.vY)(t,r),s=o?.path===i?.path;return null===i||i.unlisted&&!s?null:(0,u.jsx)(oe,{exact:!0,...a,isActive:()=>s||!!o?.sidebar&&o.sidebar===i.sidebar,label:n??i.id,to:i.path})},docSidebar:function(e){let{sidebarId:t,label:n,docsPluginId:r,...a}=e;const{activeDoc:o}=(0,Se.Iw)(r),i=(0,Ee.oz)(t,r).link;if(!i)throw new Error(`DocSidebarNavbarItem: Sidebar with ID "${t}" doesn't have anything to be linked to.`);return(0,u.jsx)(oe,{exact:!0,...a,isActive:()=>o?.sidebar===t,label:n??i.label,to:i.path})},docsVersion:function(e){let{label:t,to:n,docsPluginId:r,...a}=e;const o=(0,Ee.lO)(r)[0],i=t??o.label,s=n??(e=>e.docs.find((t=>t.id===e.mainDocId)))(o).path;return(0,u.jsx)(oe,{...a,label:i,to:s})},docsVersionDropdown:function(e){let{mobile:t,docsPluginId:n,dropdownActiveClassDisabled:r,dropdownItemsBefore:a,dropdownItemsAfter:o,...i}=e;const{search:c,hash:d}=(0,s.TH)(),p=(0,Se.Iw)(n),f=(0,Se.gB)(n),{savePreferredVersionName:m}=(0,_e.J)(n),h=[...a,...f.map((e=>{const t=p.alternateDocVersions[e.name]??Ce(e);return{label:e.label,to:`${t.path}${c}${d}`,isActive:()=>e===p.activeVersion,onClick:()=>m(e.name)}})),...o],g=(0,Ee.lO)(n)[0],b=t&&h.length>1?(0,l.I)({id:"theme.navbar.mobileVersionsDropdown.label",message:"Versions",description:"The label for the navbar versions dropdown on mobile view"}):g.label,y=t&&h.length>1?void 0:Ce(g).path;return h.length<=1?(0,u.jsx)(oe,{...i,mobile:t,label:b,to:y,isActive:r?()=>!1:void 0}):(0,u.jsx)(pe,{...i,mobile:t,label:b,to:y,items:h,isActive:r?()=>!1:void 0})}};function je(e){let{type:t,...n}=e;const r=function(e,t){return e&&"default"!==e?e:"items"in t?"dropdown":"default"}(t,n),a=Te[r];if(!a)throw new Error(`No NavbarItem component found for type "${t}".`);return(0,u.jsx)(a,{...n})}function Ne(){const e=(0,N.e)(),t=(0,w.L)().navbar.items;return(0,u.jsx)("ul",{className:"menu__list",children:t.map(((t,n)=>(0,r.createElement)(je,{mobile:!0,...t,onClick:()=>e.toggle(),key:n})))})}function Re(e){return(0,u.jsx)("button",{...e,type:"button",className:"clean-btn navbar-sidebar__back",children:(0,u.jsx)(l.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)",children:"\u2190 Back to main menu"})})}function Ae(){const e=0===(0,w.L)().navbar.items.length,t=D();return(0,u.jsxs)(u.Fragment,{children:[!e&&(0,u.jsx)(Re,{onClick:()=>t.hide()}),t.content]})}function Le(){const e=(0,N.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?(0,u.jsx)(M,{header:(0,u.jsx)(Y,{}),primaryMenu:(0,u.jsx)(Ne,{}),secondaryMenu:(0,u.jsx)(Ae,{})}):null}const Pe={navbarHideable:"navbarHideable_m1mJ",navbarHidden:"navbarHidden_jGov"};function Oe(e){return(0,u.jsx)("div",{role:"presentation",...e,className:(0,a.Z)("navbar-sidebar__backdrop",e.className)})}function Ie(e){let{children:t}=e;const{navbar:{hideOnScroll:n,style:o}}=(0,w.L)(),i=(0,N.e)(),{navbarRef:s,isNavbarVisible:d}=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,R.RF)(((t,r)=>{let{scrollY:i}=t;if(!e)return;if(i=s?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(0,u.jsxs)("nav",{ref:s,"aria-label":(0,l.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,!d&&Pe.navbarHidden],{"navbar--dark":"dark"===o,"navbar--primary":"primary"===o,"navbar-sidebar--show":i.shown}),children:[t,(0,u.jsx)(Oe,{onClick:i.toggle}),(0,u.jsx)(Le,{})]})}var De=n(8780);const Me={errorBoundaryError:"errorBoundaryError_a6uf",errorBoundaryFallback:"errorBoundaryFallback_VBag"};function Fe(e){return(0,u.jsx)("button",{type:"button",...e,children:(0,u.jsx)(l.Z,{id:"theme.ErrorPageContent.tryAgain",description:"The label of the button to try again rendering when the React error boundary captures an error",children:"Try again"})})}function ze(e){let{error:t}=e;const n=(0,De.getErrorCausalChain)(t).map((e=>e.message)).join("\n\nCause:\n");return(0,u.jsx)("p",{className:Me.errorBoundaryError,children:n})}class Be extends r.Component{componentDidCatch(e,t){throw this.props.onError(e,t)}render(){return this.props.children}}const $e="right";function Ue(e){let{width:t=30,height:n=30,className:r,...a}=e;return(0,u.jsx)("svg",{className:r,width:t,height:n,viewBox:"0 0 30 30","aria-hidden":"true",...a,children:(0,u.jsx)("path",{stroke:"currentColor",strokeLinecap:"round",strokeMiterlimit:"10",strokeWidth:"2",d:"M4 7h22M4 15h22M4 23h22"})})}function qe(){const{toggle:e,shown:t}=(0,N.e)();return(0,u.jsx)("button",{onClick:e,"aria-label":(0,l.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",children:(0,u.jsx)(Ue,{})})}const He={colorModeToggle:"colorModeToggle_DEke"};function Ze(e){let{items:t}=e;return(0,u.jsx)(u.Fragment,{children:t.map(((e,t)=>(0,u.jsx)(Be,{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}),children:(0,u.jsx)(je,{...e})},t)))})}function Ge(e){let{left:t,right:n}=e;return(0,u.jsxs)("div",{className:"navbar__inner",children:[(0,u.jsx)("div",{className:"navbar__items",children:t}),(0,u.jsx)("div",{className:"navbar__items navbar__items--right",children:n})]})}function We(){const e=(0,N.e)(),t=(0,w.L)().navbar.items,[n,r]=function(e){function t(e){return"left"===(e.position??$e)}return[e.filter(t),e.filter((e=>!t(e)))]}(t),a=t.find((e=>"search"===e.type));return(0,u.jsx)(Ge,{left:(0,u.jsxs)(u.Fragment,{children:[!e.disabled&&(0,u.jsx)(qe,{}),(0,u.jsx)(V,{}),(0,u.jsx)(Ze,{items:n})]}),right:(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(Ze,{items:r}),(0,u.jsx)(G,{className:He.colorModeToggle}),!a&&(0,u.jsx)(xe,{children:(0,u.jsx)(we,{})})]})})}function Ve(){return(0,u.jsx)(Ie,{children:(0,u.jsx)(We,{})})}function Qe(e){let{item:t}=e;const{to:n,href:r,label:a,prependBaseUrlToHref:o,...i}=t,s=(0,X.Z)(n),l=(0,X.Z)(r,{forcePrependBaseUrl:!0});return(0,u.jsxs)(K.Z,{className:"footer__link-item",...r?{href:o?l:r}:{to:s},...i,children:[a,r&&!(0,J.Z)(r)&&(0,u.jsx)(te.Z,{})]})}function Ye(e){let{item:t}=e;return t.html?(0,u.jsx)("li",{className:"footer__item",dangerouslySetInnerHTML:{__html:t.html}}):(0,u.jsx)("li",{className:"footer__item",children:(0,u.jsx)(Qe,{item:t})},t.href??t.to)}function Ke(e){let{column:t}=e;return(0,u.jsxs)("div",{className:"col footer__col",children:[(0,u.jsx)("div",{className:"footer__title",children:t.title}),(0,u.jsx)("ul",{className:"footer__items clean-list",children:t.items.map(((e,t)=>(0,u.jsx)(Ye,{item:e},t)))})]})}function Xe(e){let{columns:t}=e;return(0,u.jsx)("div",{className:"row footer__links",children:t.map(((e,t)=>(0,u.jsx)(Ke,{column:e},t)))})}function Je(){return(0,u.jsx)("span",{className:"footer__link-separator",children:"\xb7"})}function et(e){let{item:t}=e;return t.html?(0,u.jsx)("span",{className:"footer__link-item",dangerouslySetInnerHTML:{__html:t.html}}):(0,u.jsx)(Qe,{item:t})}function tt(e){let{links:t}=e;return(0,u.jsx)("div",{className:"footer__links text--center",children:(0,u.jsx)("div",{className:"footer__links",children:t.map(((e,n)=>(0,u.jsxs)(r.Fragment,{children:[(0,u.jsx)(et,{item:e}),t.length!==n+1&&(0,u.jsx)(Je,{})]},n)))})})}function nt(e){let{links:t}=e;return function(e){return"title"in e[0]}(t)?(0,u.jsx)(Xe,{columns:t}):(0,u.jsx)(tt,{links:t})}var rt=n(9965);const at={footerLogoLink:"footerLogoLink_BH7S"};function ot(e){let{logo:t}=e;const{withBaseUrl:n}=(0,X.C)(),r={light:n(t.src),dark:n(t.srcDark??t.src)};return(0,u.jsx)(rt.Z,{className:(0,a.Z)("footer__logo",t.className),alt:t.alt,sources:r,width:t.width,height:t.height,style:t.style})}function it(e){let{logo:t}=e;return t.href?(0,u.jsx)(K.Z,{href:t.href,className:at.footerLogoLink,target:t.target,children:(0,u.jsx)(ot,{logo:t})}):(0,u.jsx)(ot,{logo:t})}function st(e){let{copyright:t}=e;return(0,u.jsx)("div",{className:"footer__copyright",dangerouslySetInnerHTML:{__html:t}})}function lt(e){let{style:t,links:n,logo:r,copyright:o}=e;return(0,u.jsx)("footer",{className:(0,a.Z)("footer",{"footer--dark":"dark"===t}),children:(0,u.jsxs)("div",{className:"container container-fluid",children:[n,(r||o)&&(0,u.jsxs)("div",{className:"footer__bottom text--center",children:[r&&(0,u.jsx)("div",{className:"margin-bottom--sm",children:r}),o]})]})})}function ct(){const{footer:e}=(0,w.L)();if(!e)return null;const{copyright:t,links:n,logo:r,style:a}=e;return(0,u.jsx)(lt,{style:a,links:n&&n.length>0&&(0,u.jsx)(nt,{links:n}),logo:r&&(0,u.jsx)(it,{logo:r}),copyright:t&&(0,u.jsx)(st,{copyright:t})})}const ut=r.memo(ct),dt=(0,A.Qc)([F.S,k.pl,R.OC,_e.L5,i.VC,function(e){let{children:t}=e;return(0,u.jsx)(L.n2,{children:(0,u.jsx)(N.M,{children:(0,u.jsx)(O,{children:t})})})}]);function pt(e){let{children:t}=e;return(0,u.jsx)(dt,{children:t})}var ft=n(2503);function mt(e){let{error:t,tryAgain:n}=e;return(0,u.jsx)("main",{className:"container margin-vert--xl",children:(0,u.jsx)("div",{className:"row",children:(0,u.jsxs)("div",{className:"col col--6 col--offset-3",children:[(0,u.jsx)(ft.Z,{as:"h1",className:"hero__title",children:(0,u.jsx)(l.Z,{id:"theme.ErrorPageContent.title",description:"The title of the fallback page when the page crashed",children:"This page crashed."})}),(0,u.jsx)("div",{className:"margin-vert--lg",children:(0,u.jsx)(Fe,{onClick:n,className:"button button--primary shadow--lw"})}),(0,u.jsx)("hr",{}),(0,u.jsx)("div",{className:"margin-vert--md",children:(0,u.jsx)(ze,{error:t})})]})})})}const ht={mainWrapper:"mainWrapper_z2l0"};function gt(e){const{children:t,noFooter:n,wrapperClassName:r,title:s,description:l}=e;return(0,b.t)(),(0,u.jsxs)(pt,{children:[(0,u.jsx)(i.d,{title:s,description:l}),(0,u.jsx)(v,{}),(0,u.jsx)(j,{}),(0,u.jsx)(Ve,{}),(0,u.jsx)("div",{id:d,className:(0,a.Z)(g.k.wrapper.main,ht.mainWrapper,r),children:(0,u.jsx)(o.Z,{fallback:e=>(0,u.jsx)(mt,{...e}),children:t})}),!n&&(0,u.jsx)(ut,{})]})}},1327:(e,t,n)=>{"use strict";n.d(t,{Z:()=>u});n(7294);var r=n(9960),a=n(4996),o=n(2263),i=n(6668),s=n(9965),l=n(5893);function c(e){let{logo:t,alt:n,imageClassName:r}=e;const o={light:(0,a.Z)(t.src),dark:(0,a.Z)(t.srcDark||t.src)},i=(0,l.jsx)(s.Z,{className:t.className,sources:o,height:t.height,width:t.width,alt:n,style:t.style});return r?(0,l.jsx)("div",{className:r,children:i}):i}function u(e){const{siteConfig:{title:t}}=(0,o.Z)(),{navbar:{title:n,logo:s}}=(0,i.L)(),{imageClassName:u,titleClassName:d,...p}=e,f=(0,a.Z)(s?.href||"/"),m=n?"":t,h=s?.alt??m;return(0,l.jsxs)(r.Z,{to:f,...p,...s?.target&&{target:s.target},children:[s&&(0,l.jsx)(c,{logo:s,alt:h,imageClassName:u}),null!=n&&(0,l.jsx)("b",{className:d,children:n})]})}},197:(e,t,n)=>{"use strict";n.d(t,{Z:()=>o});n(7294);var r=n(5742),a=n(5893);function o(e){let{locale:t,version:n,tag:o}=e;const i=t;return(0,a.jsxs)(r.Z,{children:[t&&(0,a.jsx)("meta",{name:"docusaurus_locale",content:t}),n&&(0,a.jsx)("meta",{name:"docusaurus_version",content:n}),o&&(0,a.jsx)("meta",{name:"docusaurus_tag",content:o}),i&&(0,a.jsx)("meta",{name:"docsearch:language",content:i}),n&&(0,a.jsx)("meta",{name:"docsearch:version",content:n}),o&&(0,a.jsx)("meta",{name:"docsearch:docusaurus_tag",content:o})]})}},9965:(e,t,n)=>{"use strict";n.d(t,{Z:()=>u});var r=n(7294),a=n(6010),o=n(2389),i=n(2949);const s={themedComponent:"themedComponent_mlkZ","themedComponent--light":"themedComponent--light_NVdE","themedComponent--dark":"themedComponent--dark_xIcU"};var l=n(5893);function c(e){let{className:t,children:n}=e;const c=(0,o.Z)(),{colorMode:u}=(0,i.I)();return(0,l.jsx)(l.Fragment,{children:(c?"dark"===u?["dark"]:["light"]:["light","dark"]).map((e=>{const o=n({theme:e,className:(0,a.Z)(t,s.themedComponent,s[`themedComponent--${e}`])});return(0,l.jsx)(r.Fragment,{children:o},e)}))})}function u(e){const{sources:t,className:n,alt:r,...a}=e;return(0,l.jsx)(c,{className:n,children:e=>{let{theme:n,className:o}=e;return(0,l.jsx)("img",{src:t[n],alt:r,className:o,...a})}})}},6043:(e,t,n)=>{"use strict";n.d(t,{u:()=>c,z:()=>b});var r=n(7294),a=n(412),o=n(469),i=n(1442),s=n(5893);const l="ease-in-out";function c(e){let{initialState:t}=e;const[n,a]=(0,r.useState)(t??!1),o=(0,r.useCallback)((()=>{a((e=>!e))}),[]);return{collapsed:n,setCollapsed:a,toggleCollapsed:o}}const u={display:"none",overflow:"hidden",height:"0px"},d={display:"block",overflow:"visible",height:"auto"};function p(e,t){const n=t?u:d;e.style.display=n.display,e.style.overflow=n.overflow,e.style.height=n.height}function f(e){let{collapsibleRef:t,collapsed:n,animation:a}=e;const o=(0,r.useRef)(!1);(0,r.useEffect)((()=>{const e=t.current;function r(){const t=e.scrollHeight,n=a?.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 ${a?.easing??l}`,height:`${t}px`}}function s(){const t=r();e.style.transition=t.transition,e.style.height=t.height}if(!o.current)return p(e,n),void(o.current=!0);return e.style.willChange="height",function(){const t=requestAnimationFrame((()=>{n?(s(),requestAnimationFrame((()=>{e.style.height=u.height,e.style.overflow=u.overflow}))):(e.style.display="block",requestAnimationFrame((()=>{s()})))}));return()=>cancelAnimationFrame(t)}()}),[t,n,a])}function m(e){if(!a.Z.canUseDOM)return e?u:d}function h(e){let{as:t="div",collapsed:n,children:a,animation:o,onCollapseTransitionEnd:i,className:l,disableSSRStyle:c}=e;const u=(0,r.useRef)(null);return f({collapsibleRef:u,collapsed:n,animation:o}),(0,s.jsx)(t,{ref:u,style:c?void 0:m(n),onTransitionEnd:e=>{"height"===e.propertyName&&(p(u.current,n),i?.(n))},className:l,children:a})}function g(e){let{collapsed:t,...n}=e;const[a,i]=(0,r.useState)(!t),[l,c]=(0,r.useState)(t);return(0,o.Z)((()=>{t||i(!0)}),[t]),(0,o.Z)((()=>{a&&c(t)}),[a,t]),a?(0,s.jsx)(h,{...n,collapsed:l}):null}function b(e){let{lazy:t,...n}=e;const r=t?g:h;return(0,s.jsx)(r,{...n})}},9689:(e,t,n)=>{"use strict";n.d(t,{nT:()=>h,pl:()=>m});var r=n(7294),a=n(2389),o=n(12),i=n(902),s=n(6668),l=n(5893);const c=(0,o.WA)("docusaurus.announcement.dismiss"),u=(0,o.WA)("docusaurus.announcement.id"),d=()=>"true"===c.get(),p=e=>c.set(String(e)),f=r.createContext(null);function m(e){let{children:t}=e;const n=function(){const{announcementBar:e}=(0,s.L)(),t=(0,a.Z)(),[n,o]=(0,r.useState)((()=>!!t&&d()));(0,r.useEffect)((()=>{o(d())}),[]);const i=(0,r.useCallback)((()=>{p(!0),o(!0)}),[]);return(0,r.useEffect)((()=>{if(!e)return;const{id:t}=e;let n=u.get();"annoucement-bar"===n&&(n="announcement-bar");const r=t!==n;u.set(t),r&&p(!1),!r&&d()||o(!1)}),[e]),(0,r.useMemo)((()=>({isActive:!!e&&!n,close:i})),[e,n,i])}();return(0,l.jsx)(f.Provider,{value:n,children:t})}function h(){const e=(0,r.useContext)(f);if(!e)throw new i.i6("AnnouncementBarProvider");return e}},2949:(e,t,n)=>{"use strict";n.d(t,{I:()=>b,S:()=>g});var r=n(7294),a=n(412),o=n(902),i=n(12),s=n(6668),l=n(5893);const c=r.createContext(void 0),u="theme",d=(0,i.WA)(u),p={light:"light",dark:"dark"},f=e=>e===p.dark?p.dark:p.light,m=e=>a.Z.canUseDOM?f(document.documentElement.getAttribute("data-theme")):f(e),h=e=>{d.set(f(e))};function g(e){let{children:t}=e;const n=function(){const{colorMode:{defaultMode:e,disableSwitch:t,respectPrefersColorScheme:n}}=(0,s.L)(),[a,o]=(0,r.useState)(m(e));(0,r.useEffect)((()=>{t&&d.del()}),[t]);const i=(0,r.useCallback)((function(t,r){void 0===r&&(r={});const{persist:a=!0}=r;t?(o(t),a&&h(t)):(o(n?window.matchMedia("(prefers-color-scheme: dark)").matches?p.dark:p.light:e),d.del())}),[n,e]);(0,r.useEffect)((()=>{document.documentElement.setAttribute("data-theme",f(a))}),[a]),(0,r.useEffect)((()=>{if(t)return;const e=e=>{if(e.key!==u)return;const t=d.get();null!==t&&i(f(t))};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)}),[t,i]);const l=(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||l.current?l.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===p.dark},setLightTheme(){i(p.light)},setDarkTheme(){i(p.dark)}})),[a,i])}();return(0,l.jsx)(c.Provider,{value:n,children:t})}function b(){const e=(0,r.useContext)(c);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:()=>b});var r=n(7294),a=n(4104),o=n(9935),i=n(6668),s=n(3438),l=n(902),c=n(12),u=n(5893);const d=e=>`docs-preferred-version-${e}`,p={save:(e,t,n)=>{(0,c.WA)(d(e),{persistence:t}).set(n)},read:(e,t)=>(0,c.WA)(d(e),{persistence:t}).get(),clear:(e,t)=>{(0,c.WA)(d(e),{persistence:t}).del()}},f=e=>Object.fromEntries(e.map((e=>[e,{preferredVersionName:null}])));const m=r.createContext(null);function h(){const e=(0,a._r)(),t=(0,i.L)().docs.versionPersistence,n=(0,r.useMemo)((()=>Object.keys(e)),[e]),[o,s]=(0,r.useState)((()=>f(n)));(0,r.useEffect)((()=>{s(function(e){let{pluginIds:t,versionPersistence:n,allDocsData:r}=e;function a(e){const t=p.read(e,n);return r[e].versions.some((e=>e.name===t))?{preferredVersionName:t}:(p.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){p.save(e,t,n),s((t=>({...t,[e]:{preferredVersionName:n}})))}})),[t])]}function g(e){let{children:t}=e;const n=h();return(0,u.jsx)(m.Provider,{value:n,children:t})}function b(e){let{children:t}=e;return s.cE?(0,u.jsx)(g,{children:t}):(0,u.jsx)(u.Fragment,{children:t})}function y(){const e=(0,r.useContext)(m);if(!e)throw new l.i6("DocsPreferredVersionContextProvider");return e}function v(e){void 0===e&&(e=o.m);const t=(0,a.zh)(e),[n,i]=y(),{preferredVersionName:s}=n[e];return{preferredVersion:t.versions.find((e=>e.name===s))??null,savePreferredVersionName:(0,r.useCallback)((t=>{i.savePreferredVersion(e,t)}),[i,e])}}},1116:(e,t,n)=>{"use strict";n.d(t,{V:()=>c,b:()=>l});var r=n(7294),a=n(902),o=n(5893);const i=Symbol("EmptyContext"),s=r.createContext(i);function l(e){let{children:t,name:n,items:a}=e;const i=(0,r.useMemo)((()=>n&&a?{name:n,items:a}:null),[n,a]);return(0,o.jsx)(s.Provider,{value:i,children:t})}function c(){const e=(0,r.useContext)(s);if(e===i)throw new a.i6("DocsSidebarProvider");return e}},4477:(e,t,n)=>{"use strict";n.d(t,{E:()=>l,q:()=>s});var r=n(7294),a=n(902),o=n(5893);const i=r.createContext(null);function s(e){let{children:t,version:n}=e;return(0,o.jsx)(i.Provider,{value:n,children:t})}function l(){const e=(0,r.useContext)(i);if(null===e)throw new a.i6("DocsVersionProvider");return e}},3163:(e,t,n)=>{"use strict";n.d(t,{M:()=>p,e:()=>f});var r=n(7294),a=n(3102),o=n(7524),i=n(1980),s=n(6668),l=n(902),c=n(5893);const u=r.createContext(void 0);function d(){const e=function(){const e=(0,a.HY)(),{items:t}=(0,s.L)().navbar;return 0===t.length&&!e.component}(),t=(0,o.i)(),n=!e&&"mobile"===t,[l,c]=(0,r.useState)(!1);(0,i.Rb)((()=>{if(l)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:l})),[e,n,u,l])}function p(e){let{children:t}=e;const n=d();return(0,c.jsx)(u.Provider,{value:n,children:t})}function f(){const e=r.useContext(u);if(void 0===e)throw new l.i6("NavbarMobileSidebarProvider");return e}},3102:(e,t,n)=>{"use strict";n.d(t,{HY:()=>l,Zo:()=>c,n2:()=>s});var r=n(7294),a=n(902),o=n(5893);const i=r.createContext(null);function s(e){let{children:t}=e;const n=(0,r.useState)({component:null,props:null});return(0,o.jsx)(i.Provider,{value:n,children:t})}function l(){const e=(0,r.useContext)(i);if(!e)throw new a.i6("NavbarSecondaryMenuContentProvider");return e[0]}function c(e){let{component:t,props:n}=e;const o=(0,r.useContext)(i);if(!o)throw new a.i6("NavbarSecondaryMenuContentProvider");const[,s]=o,l=(0,a.Ql)(n);return(0,r.useEffect)((()=>{s({component:t,props:l})}),[s,t,l]),(0,r.useEffect)((()=>()=>s({component:null,props:null})),[s]),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:()=>s});var r=n(7294),a=n(412);const o={desktop:"desktop",mobile:"mobile",ssr:"ssr"},i=996;function s(){const[e,t]=(0,r.useState)((()=>"ssr"));return(0,r.useEffect)((()=>{function e(){t(function(){if(!a.Z.canUseDOM)throw new Error("getWindowSize() should only be called after React hydration");return window.innerWidth>i?o.desktop:o.mobile}())}return e(),window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e)}}),[]),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",unlistedBanner:"theme-unlisted-banner",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,{LM:()=>m,MN:()=>T,SN:()=>C,_F:()=>y,cE:()=>p,f:()=>w,jA:()=>h,lO:()=>S,oz:()=>E,s1:()=>x,vY:()=>_,xz:()=>f});var r=n(7294),a=n(6550),o=n(8790),i=n(4104),s=n(373),l=n(4477),c=n(1116),u=n(7392),d=n(8596);const p=!!i._r;function f(e){const t=(0,l.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){return"link"!==e.type||e.unlisted?"category"===e.type?function(e){if(e.href&&!e.linkUnlisted)return e.href;for(const t of e.items){const e=m(t);if(e)return e}}(e):void 0:e.href}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=k({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=>y(e,t)));function y(e,t){return"link"===e.type?g(e.href,t):"category"===e.type&&(g(e.href,t)||b(e.items,t))}function v(e,t){switch(e.type){case"category":return y(e,t)||e.items.some((e=>v(e,t)));case"link":return!e.unlisted||y(e,t);default:return!1}}function w(e,t){return(0,r.useMemo)((()=>e.filter((e=>v(e,t)))),[e,t])}function k(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 x(){const e=(0,c.V)(),{pathname:t}=(0,a.TH)(),n=(0,i.gA)()?.pluginData.breadcrumbs;return!1!==n&&e?k({sidebarItems:e.items,pathname:t}):null}function S(e){const{activeVersion:t}=(0,i.Iw)(e),{preferredVersion:n}=(0,s.J)(e),a=(0,i.yW)(e);return(0,r.useMemo)((()=>(0,u.j)([t,n,a].filter(Boolean))),[t,n,a])}function E(e,t){const n=S(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,t){const n=S(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 C(e){let{route:t}=e;const n=(0,a.TH)(),r=(0,l.E)(),i=t.routes,s=i.find((e=>(0,a.LX)(n.pathname,e)));if(!s)return null;const c=s.sidebar,u=c?r.docsSidebars[c]:void 0;return{docElement:(0,o.H)(i),sidebarName:c,sidebarItems:u}}function T(e){return e.filter((e=>!("category"===e.type||"link"===e.type)||!!m(e)))}},1980:(e,t,n)=>{"use strict";n.d(t,{Rb:()=>i,_X:()=>s});var r=n(7294),a=n(6550),o=n(902);function i(e){!function(e){const t=(0,a.k6)(),n=(0,o.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,r.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:()=>f,d:()=>d,VC:()=>m});var r=n(7294),a=n(6010),o=n(5742),i=n(226);function s(){const e=r.useContext(i._);if(!e)throw new Error("Unexpected: no Docusaurus route context found");return e}var l=n(4996),c=n(2263);var u=n(5893);function d(e){let{title:t,description:n,keywords:r,image:a,children:i}=e;const s=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,l.C)(),p=a?d(a,{absolute:!0}):void 0;return(0,u.jsxs)(o.Z,{children:[t&&(0,u.jsx)("title",{children:s}),t&&(0,u.jsx)("meta",{property:"og:title",content:s}),n&&(0,u.jsx)("meta",{name:"description",content:n}),n&&(0,u.jsx)("meta",{property:"og:description",content:n}),r&&(0,u.jsx)("meta",{name:"keywords",content:Array.isArray(r)?r.join(","):r}),p&&(0,u.jsx)("meta",{property:"og:image",content:p}),p&&(0,u.jsx)("meta",{name:"twitter:image",content:p}),i]})}const p=r.createContext(void 0);function f(e){let{className:t,children:n}=e;const i=r.useContext(p),s=(0,a.Z)(i,t);return(0,u.jsxs)(p.Provider,{value:s,children:[(0,u.jsx)(o.Z,{children:(0,u.jsx)("html",{className:s})}),n]})}function m(e){let{children:t}=e;const n=s(),r=`plugin-${n.plugin.name.replace(/docusaurus-(?:plugin|theme)-(?:content-)?/gi,"")}`;const o=`plugin-id-${n.plugin.id}`;return(0,u.jsx)(f,{className:(0,a.Z)(r,o),children:t})}},902:(e,t,n)=>{"use strict";n.d(t,{D9:()=>s,Qc:()=>u,Ql:()=>c,i6:()=>l,zX:()=>i});var r=n(7294),a=n(469),o=n(5893);function i(e){const t=(0,r.useRef)(e);return(0,a.Z)((()=>{t.current=e}),[e]),(0,r.useCallback)((function(){return t.current(...arguments)}),[])}function s(e){const t=(0,r.useRef)();return(0,a.Z)((()=>{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 c(e){const t=Object.entries(e);return t.sort(((e,t)=>e[0].localeCompare(t[0]))),(0,r.useMemo)((()=>e),t.flat())}function u(e){return t=>{let{children:n}=t;return(0,o.jsx)(o.Fragment,{children:e.reduceRight(((e,t)=>(0,o.jsx)(t,{children:e})),n)})}}},8596:(e,t,n)=>{"use strict";n.d(t,{Mg:()=>i,Ns:()=>s});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 s(){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:()=>h,OC:()=>u,RF:()=>f,o5:()=>m});var r=n(7294),a=n(412),o=n(2389),i=n(469),s=n(902),l=n(5893);const c=r.createContext(void 0);function u(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(0,l.jsx)(c.Provider,{value:n,children:t})}function d(){const e=(0,r.useContext)(c);if(null==e)throw new s.i6("ScrollControllerProvider");return e}const p=()=>a.Z.canUseDOM?{scrollX:window.pageXOffset,scrollY:window.pageYOffset}:null;function f(e,t){void 0===t&&(t=[]);const{scrollEventsEnabledRef:n}=d(),a=(0,r.useRef)(p()),o=(0,s.zX)(e);(0,r.useEffect)((()=>{const e=()=>{if(!n.current)return;const e=p();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 m(){const e=d(),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,i.Z)((()=>{queueMicrotask((()=>n.current?.()))})),{blockElementScrollPositionUntilNextRender:a}}function h(){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:()=>u,WA:()=>c});var r=n(7294);const a="localStorage";function o(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 i(e){if(void 0===e&&(e=a),"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 l={get:()=>null,set:()=>{},del:()=>{},listen:()=>()=>{}};function c(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=i(t?.persistence);return null===n?l:{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),o({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),o({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 u(e,t){const n=(0,r.useRef)((()=>null===e?l:c(e,t))).current(),a=(0,r.useCallback)((e=>"undefined"==typeof window?()=>{}:n.listen(e)),[n]);return[(0,r.useSyncExternalStore)(a,(()=>"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:s}}=(0,r.Z)(),{pathname:l}=(0,a.TH)(),c=(0,o.applyTrailingSlash)(l,{trailingSlash:n,baseUrl:e}),u=s===i?e:e.replace(`/${s}/`,"/"),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:()=>j,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 s=n(8776);function l(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(s){throw s instanceof URIError?new URIError('Pathname "'+o.pathname+'" could not be decoded. This is likely caused by an invalid percent-encoding.'):s}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:v,goBack:function(){v(-1)},goForward:function(){v(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},s={};function l(e){return r.isMemo(e)?i:s[e.$$typeof]||a}s[r.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},s[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 s=l(t),h=l(n),g=0;g{"use strict";e.exports=function(e,t,n,r,a,o,i,s){if(!e){var l;if(void 0===t)l=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,s],u=0;(l=new Error(t.replace(/%s/g,(function(){return c[u++]})))).name="Invariant Violation"}throw l.framesToPop=1,l}}},5826:e=>{e.exports=Array.isArray||function(e){return"[object Array]"==Object.prototype.toString.call(e)}},813:function(e){e.exports=function(){"use strict";var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function e(e,t){for(var n=0;n1&&void 0!==arguments[1])||arguments[1],a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:5e3;t(this,e),this.ctx=n,this.iframes=r,this.exclude=a,this.iframesTimeout=o}return n(e,[{key:"getContexts",value:function(){var e=[];return(void 0!==this.ctx&&this.ctx?NodeList.prototype.isPrototypeOf(this.ctx)?Array.prototype.slice.call(this.ctx):Array.isArray(this.ctx)?this.ctx:"string"==typeof this.ctx?Array.prototype.slice.call(document.querySelectorAll(this.ctx)):[this.ctx]:[]).forEach((function(t){var n=e.filter((function(e){return e.contains(t)})).length>0;-1!==e.indexOf(t)||n||e.push(t)})),e}},{key:"getIframeContents",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},r=void 0;try{var a=e.contentWindow;if(r=a.document,!a||!r)throw new Error("iframe inaccessible")}catch(o){n()}r&&t(r)}},{key:"isIframeBlank",value:function(e){var t="about:blank",n=e.getAttribute("src").trim();return e.contentWindow.location.href===t&&n!==t&&n}},{key:"observeIframeLoad",value:function(e,t,n){var r=this,a=!1,o=null,i=function i(){if(!a){a=!0,clearTimeout(o);try{r.isIframeBlank(e)||(e.removeEventListener("load",i),r.getIframeContents(e,t,n))}catch(s){n()}}};e.addEventListener("load",i),o=setTimeout(i,this.iframesTimeout)}},{key:"onIframeReady",value:function(e,t,n){try{"complete"===e.contentWindow.document.readyState?this.isIframeBlank(e)?this.observeIframeLoad(e,t,n):this.getIframeContents(e,t,n):this.observeIframeLoad(e,t,n)}catch(r){n()}}},{key:"waitForIframes",value:function(e,t){var n=this,r=0;this.forEachIframe(e,(function(){return!0}),(function(e){r++,n.waitForIframes(e.querySelector("html"),(function(){--r||t()}))}),(function(e){e||t()}))}},{key:"forEachIframe",value:function(t,n,r){var a=this,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){},i=t.querySelectorAll("iframe"),s=i.length,l=0;i=Array.prototype.slice.call(i);var c=function(){--s<=0&&o(l)};s||c(),i.forEach((function(t){e.matches(t,a.exclude)?c():a.onIframeReady(t,(function(e){n(t)&&(l++,r(e)),c()}),c)}))}},{key:"createIterator",value:function(e,t,n){return document.createNodeIterator(e,t,n,!1)}},{key:"createInstanceOnIframe",value:function(t){return new e(t.querySelector("html"),this.iframes)}},{key:"compareNodeIframe",value:function(e,t,n){if(e.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_PRECEDING){if(null===t)return!0;if(t.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_FOLLOWING)return!0}return!1}},{key:"getIteratorNode",value:function(e){var t=e.previousNode();return{prevNode:t,node:(null===t||e.nextNode())&&e.nextNode()}}},{key:"checkIframeFilter",value:function(e,t,n,r){var a=!1,o=!1;return r.forEach((function(e,t){e.val===n&&(a=t,o=e.handled)})),this.compareNodeIframe(e,t,n)?(!1!==a||o?!1===a||o||(r[a].handled=!0):r.push({val:n,handled:!0}),!0):(!1===a&&r.push({val:n,handled:!1}),!1)}},{key:"handleOpenIframes",value:function(e,t,n,r){var a=this;e.forEach((function(e){e.handled||a.getIframeContents(e.val,(function(e){a.createInstanceOnIframe(e).forEachNode(t,n,r)}))}))}},{key:"iterateThroughNodes",value:function(e,t,n,r,a){for(var o=this,i=this.createIterator(t,e,r),s=[],l=[],c=void 0,u=void 0,d=function(){var e=o.getIteratorNode(i);return u=e.prevNode,c=e.node};d();)this.iframes&&this.forEachIframe(t,(function(e){return o.checkIframeFilter(c,u,e,s)}),(function(t){o.createInstanceOnIframe(t).forEachNode(e,(function(e){return l.push(e)}),r)})),l.push(c);l.forEach((function(e){n(e)})),this.iframes&&this.handleOpenIframes(s,e,n,r),a()}},{key:"forEachNode",value:function(e,t,n){var r=this,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){},o=this.getContexts(),i=o.length;i||a(),o.forEach((function(o){var s=function(){r.iterateThroughNodes(e,o,t,n,(function(){--i<=0&&a()}))};r.iframes?r.waitForIframes(o,s):s()}))}}],[{key:"matches",value:function(e,t){var n="string"==typeof t?[t]:t,r=e.matches||e.matchesSelector||e.msMatchesSelector||e.mozMatchesSelector||e.oMatchesSelector||e.webkitMatchesSelector;if(r){var a=!1;return n.every((function(t){return!r.call(e,t)||(a=!0,!1)})),a}return!1}}]),e}(),o=function(){function o(e){t(this,o),this.ctx=e,this.ie=!1;var n=window.navigator.userAgent;(n.indexOf("MSIE")>-1||n.indexOf("Trident")>-1)&&(this.ie=!0)}return n(o,[{key:"log",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"debug",r=this.opt.log;this.opt.debug&&"object"===(void 0===r?"undefined":e(r))&&"function"==typeof r[n]&&r[n]("mark.js: "+t)}},{key:"escapeStr",value:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}},{key:"createRegExp",value:function(e){return"disabled"!==this.opt.wildcards&&(e=this.setupWildcardsRegExp(e)),e=this.escapeStr(e),Object.keys(this.opt.synonyms).length&&(e=this.createSynonymsRegExp(e)),(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.setupIgnoreJoinersRegExp(e)),this.opt.diacritics&&(e=this.createDiacriticsRegExp(e)),e=this.createMergedBlanksRegExp(e),(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.createJoinersRegExp(e)),"disabled"!==this.opt.wildcards&&(e=this.createWildcardsRegExp(e)),e=this.createAccuracyRegExp(e)}},{key:"createSynonymsRegExp",value:function(e){var t=this.opt.synonyms,n=this.opt.caseSensitive?"":"i",r=this.opt.ignoreJoiners||this.opt.ignorePunctuation.length?"\0":"";for(var a in t)if(t.hasOwnProperty(a)){var o=t[a],i="disabled"!==this.opt.wildcards?this.setupWildcardsRegExp(a):this.escapeStr(a),s="disabled"!==this.opt.wildcards?this.setupWildcardsRegExp(o):this.escapeStr(o);""!==i&&""!==s&&(e=e.replace(new RegExp("("+this.escapeStr(i)+"|"+this.escapeStr(s)+")","gm"+n),r+"("+this.processSynomyms(i)+"|"+this.processSynomyms(s)+")"+r))}return e}},{key:"processSynomyms",value:function(e){return(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.setupIgnoreJoinersRegExp(e)),e}},{key:"setupWildcardsRegExp",value:function(e){return(e=e.replace(/(?:\\)*\?/g,(function(e){return"\\"===e.charAt(0)?"?":"\x01"}))).replace(/(?:\\)*\*/g,(function(e){return"\\"===e.charAt(0)?"*":"\x02"}))}},{key:"createWildcardsRegExp",value:function(e){var t="withSpaces"===this.opt.wildcards;return e.replace(/\u0001/g,t?"[\\S\\s]?":"\\S?").replace(/\u0002/g,t?"[\\S\\s]*?":"\\S*")}},{key:"setupIgnoreJoinersRegExp",value:function(e){return e.replace(/[^(|)\\]/g,(function(e,t,n){var r=n.charAt(t+1);return/[(|)\\]/.test(r)||""===r?e:e+"\0"}))}},{key:"createJoinersRegExp",value:function(e){var t=[],n=this.opt.ignorePunctuation;return Array.isArray(n)&&n.length&&t.push(this.escapeStr(n.join(""))),this.opt.ignoreJoiners&&t.push("\\u00ad\\u200b\\u200c\\u200d"),t.length?e.split(/\u0000+/).join("["+t.join("")+"]*"):e}},{key:"createDiacriticsRegExp",value:function(e){var t=this.opt.caseSensitive?"":"i",n=this.opt.caseSensitive?["a\xe0\xe1\u1ea3\xe3\u1ea1\u0103\u1eb1\u1eaf\u1eb3\u1eb5\u1eb7\xe2\u1ea7\u1ea5\u1ea9\u1eab\u1ead\xe4\xe5\u0101\u0105","A\xc0\xc1\u1ea2\xc3\u1ea0\u0102\u1eb0\u1eae\u1eb2\u1eb4\u1eb6\xc2\u1ea6\u1ea4\u1ea8\u1eaa\u1eac\xc4\xc5\u0100\u0104","c\xe7\u0107\u010d","C\xc7\u0106\u010c","d\u0111\u010f","D\u0110\u010e","e\xe8\xe9\u1ebb\u1ebd\u1eb9\xea\u1ec1\u1ebf\u1ec3\u1ec5\u1ec7\xeb\u011b\u0113\u0119","E\xc8\xc9\u1eba\u1ebc\u1eb8\xca\u1ec0\u1ebe\u1ec2\u1ec4\u1ec6\xcb\u011a\u0112\u0118","i\xec\xed\u1ec9\u0129\u1ecb\xee\xef\u012b","I\xcc\xcd\u1ec8\u0128\u1eca\xce\xcf\u012a","l\u0142","L\u0141","n\xf1\u0148\u0144","N\xd1\u0147\u0143","o\xf2\xf3\u1ecf\xf5\u1ecd\xf4\u1ed3\u1ed1\u1ed5\u1ed7\u1ed9\u01a1\u1edf\u1ee1\u1edb\u1edd\u1ee3\xf6\xf8\u014d","O\xd2\xd3\u1ece\xd5\u1ecc\xd4\u1ed2\u1ed0\u1ed4\u1ed6\u1ed8\u01a0\u1ede\u1ee0\u1eda\u1edc\u1ee2\xd6\xd8\u014c","r\u0159","R\u0158","s\u0161\u015b\u0219\u015f","S\u0160\u015a\u0218\u015e","t\u0165\u021b\u0163","T\u0164\u021a\u0162","u\xf9\xfa\u1ee7\u0169\u1ee5\u01b0\u1eeb\u1ee9\u1eed\u1eef\u1ef1\xfb\xfc\u016f\u016b","U\xd9\xda\u1ee6\u0168\u1ee4\u01af\u1eea\u1ee8\u1eec\u1eee\u1ef0\xdb\xdc\u016e\u016a","y\xfd\u1ef3\u1ef7\u1ef9\u1ef5\xff","Y\xdd\u1ef2\u1ef6\u1ef8\u1ef4\u0178","z\u017e\u017c\u017a","Z\u017d\u017b\u0179"]:["a\xe0\xe1\u1ea3\xe3\u1ea1\u0103\u1eb1\u1eaf\u1eb3\u1eb5\u1eb7\xe2\u1ea7\u1ea5\u1ea9\u1eab\u1ead\xe4\xe5\u0101\u0105A\xc0\xc1\u1ea2\xc3\u1ea0\u0102\u1eb0\u1eae\u1eb2\u1eb4\u1eb6\xc2\u1ea6\u1ea4\u1ea8\u1eaa\u1eac\xc4\xc5\u0100\u0104","c\xe7\u0107\u010dC\xc7\u0106\u010c","d\u0111\u010fD\u0110\u010e","e\xe8\xe9\u1ebb\u1ebd\u1eb9\xea\u1ec1\u1ebf\u1ec3\u1ec5\u1ec7\xeb\u011b\u0113\u0119E\xc8\xc9\u1eba\u1ebc\u1eb8\xca\u1ec0\u1ebe\u1ec2\u1ec4\u1ec6\xcb\u011a\u0112\u0118","i\xec\xed\u1ec9\u0129\u1ecb\xee\xef\u012bI\xcc\xcd\u1ec8\u0128\u1eca\xce\xcf\u012a","l\u0142L\u0141","n\xf1\u0148\u0144N\xd1\u0147\u0143","o\xf2\xf3\u1ecf\xf5\u1ecd\xf4\u1ed3\u1ed1\u1ed5\u1ed7\u1ed9\u01a1\u1edf\u1ee1\u1edb\u1edd\u1ee3\xf6\xf8\u014dO\xd2\xd3\u1ece\xd5\u1ecc\xd4\u1ed2\u1ed0\u1ed4\u1ed6\u1ed8\u01a0\u1ede\u1ee0\u1eda\u1edc\u1ee2\xd6\xd8\u014c","r\u0159R\u0158","s\u0161\u015b\u0219\u015fS\u0160\u015a\u0218\u015e","t\u0165\u021b\u0163T\u0164\u021a\u0162","u\xf9\xfa\u1ee7\u0169\u1ee5\u01b0\u1eeb\u1ee9\u1eed\u1eef\u1ef1\xfb\xfc\u016f\u016bU\xd9\xda\u1ee6\u0168\u1ee4\u01af\u1eea\u1ee8\u1eec\u1eee\u1ef0\xdb\xdc\u016e\u016a","y\xfd\u1ef3\u1ef7\u1ef9\u1ef5\xffY\xdd\u1ef2\u1ef6\u1ef8\u1ef4\u0178","z\u017e\u017c\u017aZ\u017d\u017b\u0179"],r=[];return e.split("").forEach((function(a){n.every((function(n){if(-1!==n.indexOf(a)){if(r.indexOf(n)>-1)return!1;e=e.replace(new RegExp("["+n+"]","gm"+t),"["+n+"]"),r.push(n)}return!0}))})),e}},{key:"createMergedBlanksRegExp",value:function(e){return e.replace(/[\s]+/gim,"[\\s]+")}},{key:"createAccuracyRegExp",value:function(e){var t=this,n="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~\xa1\xbf",r=this.opt.accuracy,a="string"==typeof r?r:r.value,o="string"==typeof r?[]:r.limiters,i="";switch(o.forEach((function(e){i+="|"+t.escapeStr(e)})),a){case"partially":default:return"()("+e+")";case"complementary":return"()([^"+(i="\\s"+(i||this.escapeStr(n)))+"]*"+e+"[^"+i+"]*)";case"exactly":return"(^|\\s"+i+")("+e+")(?=$|\\s"+i+")"}}},{key:"getSeparatedKeywords",value:function(e){var t=this,n=[];return e.forEach((function(e){t.opt.separateWordSearch?e.split(" ").forEach((function(e){e.trim()&&-1===n.indexOf(e)&&n.push(e)})):e.trim()&&-1===n.indexOf(e)&&n.push(e)})),{keywords:n.sort((function(e,t){return t.length-e.length})),length:n.length}}},{key:"isNumeric",value:function(e){return Number(parseFloat(e))==e}},{key:"checkRanges",value:function(e){var t=this;if(!Array.isArray(e)||"[object Object]"!==Object.prototype.toString.call(e[0]))return this.log("markRanges() will only accept an array of objects"),this.opt.noMatch(e),[];var n=[],r=0;return e.sort((function(e,t){return e.start-t.start})).forEach((function(e){var a=t.callNoMatchOnInvalidRanges(e,r),o=a.start,i=a.end;a.valid&&(e.start=o,e.length=i-o,n.push(e),r=i)})),n}},{key:"callNoMatchOnInvalidRanges",value:function(e,t){var n=void 0,r=void 0,a=!1;return e&&void 0!==e.start?(r=(n=parseInt(e.start,10))+parseInt(e.length,10),this.isNumeric(e.start)&&this.isNumeric(e.length)&&r-t>0&&r-n>0?a=!0:(this.log("Ignoring invalid or overlapping range: "+JSON.stringify(e)),this.opt.noMatch(e))):(this.log("Ignoring invalid range: "+JSON.stringify(e)),this.opt.noMatch(e)),{start:n,end:r,valid:a}}},{key:"checkWhitespaceRanges",value:function(e,t,n){var r=void 0,a=!0,o=n.length,i=t-o,s=parseInt(e.start,10)-i;return(r=(s=s>o?o:s)+parseInt(e.length,10))>o&&(r=o,this.log("End range automatically set to the max value of "+o)),s<0||r-s<0||s>o||r>o?(a=!1,this.log("Invalid range: "+JSON.stringify(e)),this.opt.noMatch(e)):""===n.substring(s,r).replace(/\s+/g,"")&&(a=!1,this.log("Skipping whitespace only range: "+JSON.stringify(e)),this.opt.noMatch(e)),{start:s,end:r,valid:a}}},{key:"getTextNodes",value:function(e){var t=this,n="",r=[];this.iterator.forEachNode(NodeFilter.SHOW_TEXT,(function(e){r.push({start:n.length,end:(n+=e.textContent).length,node:e})}),(function(e){return t.matchesExclude(e.parentNode)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}),(function(){e({value:n,nodes:r})}))}},{key:"matchesExclude",value:function(e){return a.matches(e,this.opt.exclude.concat(["script","style","title","head","html"]))}},{key:"wrapRangeInTextNode",value:function(e,t,n){var r=this.opt.element?this.opt.element:"mark",a=e.splitText(t),o=a.splitText(n-t),i=document.createElement(r);return i.setAttribute("data-markjs","true"),this.opt.className&&i.setAttribute("class",this.opt.className),i.textContent=a.textContent,a.parentNode.replaceChild(i,a),o}},{key:"wrapRangeInMappedTextNode",value:function(e,t,n,r,a){var o=this;e.nodes.every((function(i,s){var l=e.nodes[s+1];if(void 0===l||l.start>t){if(!r(i.node))return!1;var c=t-i.start,u=(n>i.end?i.end:n)-i.start,d=e.value.substr(0,i.start),p=e.value.substr(u+i.start);if(i.node=o.wrapRangeInTextNode(i.node,c,u),e.value=d+p,e.nodes.forEach((function(t,n){n>=s&&(e.nodes[n].start>0&&n!==s&&(e.nodes[n].start-=u),e.nodes[n].end-=u)})),n-=u,a(i.node.previousSibling,i.start),!(n>i.end))return!1;t=i.end}return!0}))}},{key:"wrapMatches",value:function(e,t,n,r,a){var o=this,i=0===t?0:t+1;this.getTextNodes((function(t){t.nodes.forEach((function(t){t=t.node;for(var a=void 0;null!==(a=e.exec(t.textContent))&&""!==a[i];)if(n(a[i],t)){var s=a.index;if(0!==i)for(var l=1;l{"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,s((function(t){""===r.positionUsing&&(r.positionUsing=n.getPositioningCSS()),l(c,i(e,u,d)),1===e?(l(o,{transition:"none",opacity:1}),o.offsetWidth,setTimeout((function(){l(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),s=e?"-100":o(n.status||0),c=document.querySelector(r.parent);return l(i,{transition:"all 0 linear",transform:"translate3d("+s+"%,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 s=function(){var e=[];function t(){var n=e.shift();n&&n(t)}return function(n){e.push(n),1==e.length&&t()}}(),l=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)},4779:(e,t,n)=>{var r=n(5826);e.exports=f,e.exports.parse=o,e.exports.compile=function(e,t){return s(o(e,t),t)},e.exports.tokensToFunction=s,e.exports.tokensToRegExp=p;var a=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function o(e,t){for(var n,r=[],o=0,i=0,s="",u=t&&t.delimiter||"/";null!=(n=a.exec(e));){var d=n[0],p=n[1],f=n.index;if(s+=e.slice(i,f),i=f+d.length,p)s+=p[1];else{var m=e[i],h=n[2],g=n[3],b=n[4],y=n[5],v=n[6],w=n[7];s&&(r.push(s),s="");var k=null!=h&&null!=m&&m!==h,x="+"===v||"*"===v,S="?"===v||"*"===v,E=n[2]||u,_=b||y;r.push({name:g||o++,prefix:h||"",delimiter:E,optional:S,repeat:x,partial:k,asterisk:!!w,pattern:_?c(_):w?".*":"[^"+l(E)+"]+?"})}}return i{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},6854:()=>{!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,s=i.length;-1!==n.code.indexOf(a=t(r,s));)++s;return i[s]=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(s){for(var l=0;l=o.length);l++){var c=s[l];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),y=[];h&&y.push.apply(y,i([h])),y.push(g),b&&y.push.apply(y,i([b])),"string"==typeof c?s.splice.apply(s,[l,1].concat(y)):c.content=y}}else c.content&&i(c.content)}return s}(n.tokens)}}}})}(Prism)},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 s={},l=e[r];if(l){function c(t){if(!(t in e))throw new Error(r+" depends on an unknown component "+t);if(!(t in s))for(var i in a(t,o),s[t]=!0,n[t])s[i]=!0}t(l.require,c),t(l.optional,c),t(l.modify,c)}n[r]=s,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,s){var l=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}}(l);i=i.map(c),s=(s||[]).map(c);var u=n(i),d=n(s);i.forEach((function e(n){var r=l[n];t(r&&r.require,(function(t){t in d||(u[t]=!0,e(t))}))}));for(var p,f=r(l),m=u;a(m);){for(var h in p={},m){var g=l[h];t(g&&g.modify,(function(e){e in d&&(p[e]=!0)}))}for(var b in d)if(!(b in u))for(var y in f(b))if(y in u){p[b]=!0;break}for(var v in m=p)u[v]=!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,s={},l={};function c(e){if(e in s)return s[e];l[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 l[e],t})));o?a=o(p,(function(){return r(e)})):r(e)}return s[e]=a}for(var u in n)c(u);var d=[];for(var p in l)d.push(s[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 s=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 s.name="Invariant Violation",s}}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(3840);function o(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n