{"name":"@smithy/middleware-stack","version":"3.0.11","description":"Provides a means for composing multiple middleware functions into a single handler","scripts":{"build":"concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'","build:cjs":"node ../../scripts/inline middleware-stack","build:es":"yarn g:tsc -p tsconfig.es.json","build:types":"yarn g:tsc -p tsconfig.types.json","build:types:downlevel":"rimraf dist-types/ts3.4 && downlevel-dts dist-types dist-types/ts3.4","stage-release":"rimraf ./.release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz","clean":"rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0","lint":"eslint -c ../../.eslintrc.js \"src/**/*.ts\"","format":"prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"","extract:docs":"api-extractor run --local","test":"yarn g:vitest run","test:watch":"yarn g:vitest watch"},"author":{"name":"AWS SDK for JavaScript Team","url":"https://aws.amazon.com/javascript/"},"license":"Apache-2.0","main":"./dist-cjs/index.js","module":"./dist-es/index.js","types":"./dist-types/index.d.ts","dependencies":{"@smithy/types":"^3.7.2","tslib":"^2.6.2"},"devDependencies":{"concurrently":"7.0.0","downlevel-dts":"0.10.1","rimraf":"3.0.2","typedoc":"0.23.23"},"engines":{"node":">=16.0.0"},"typesVersions":{"<4.0":{"dist-types/*":["dist-types/ts3.4/*"]}},"homepage":"https://github.com/awslabs/smithy-typescript/tree/main/packages/middleware-stack","repository":{"type":"git","url":"git+https://github.com/awslabs/smithy-typescript.git","directory":"packages/middleware-stack"},"typedoc":{"entryPoint":"src/index.ts"},"publishConfig":{"directory":".release/package"},"_id":"@smithy/middleware-stack@3.0.11","gitHead":"50d8c5457e7feea41169a37fb2fdb1e448f82e9e","bugs":{"url":"https://github.com/awslabs/smithy-typescript/issues"},"_nodeVersion":"18.20.5","_npmVersion":"10.8.2","dist":{"integrity":"sha512-1HGo9a6/ikgOMrTrWL/WiN9N8GSVYpuRQO5kjstAq4CvV59bjqnh7TbdXGQ4vxLD3xlSjfBjq5t1SOELePsLnA==","shasum":"453af2096924e4064d9da4e053cfdf65d9a36acc","tarball":"http://registry-npm.ywwl.com/@smithy/middleware-stack/download/@smithy/middleware-stack-3.0.11.tgz","fileCount":15,"unpackedSize":43069,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHDT5WhqxMK+lDQPqxSAB7hDmLr3klWjrQpZPvcOm+WkAiEAiCIoRBxyOzzDnsp7FQePFhakN47LU8+XgKSzZz2VDqw="}],"size":10192,"noattachment":false,"key":"/@smithy/middleware-stack/-/@smithy/middleware-stack-3.0.11.tgz"},"_npmUser":{"name":"smithy-team","email":"aws-smithy-team+npm@amazon.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/middleware-stack_3.0.11_1733759915976_0.33644298993793886"},"_hasShrinkwrap":false,"readme":"# @smithy/middleware-stack\n\n[![NPM version](https://img.shields.io/npm/v/@smithy/middleware-stack/latest.svg)](https://www.npmjs.com/package/@smithy/middleware-stack)\n[![NPM downloads](https://img.shields.io/npm/dm/@smithy/middleware-stack.svg)](https://www.npmjs.com/package/@smithy/middleware-stack)\n\nThe package contains an implementation of middleware stack interface. Middleware\nstack is a structure storing middleware in specified order and resolve these\nmiddleware into a single handler.\n\nA middleware stack has five `Step`s, each of them represents a specific request life cycle:\n\n- **initialize**: The input is being prepared. Examples of typical initialization tasks include injecting default options computing derived parameters.\n\n- **serialize**: The input is complete and ready to be serialized. Examples of typical serialization tasks include input validation and building an HTTP request from user input.\n\n- **build**: The input has been serialized into an HTTP request, but that request may require further modification. Any request alterations will be applied to all retries. Examples of typical build tasks include injecting HTTP headers that describe a stable aspect of the request, such as `Content-Length` or a body checksum.\n\n- **finalizeRequest**: The request is being prepared to be sent over the wire. The request in this stage should already be semantically complete and should therefore only be altered to match the recipient's expectations. Examples of typical finalization tasks include request signing and injecting hop-by-hop headers.\n\n- **deserialize**: The response has arrived, the middleware here will deserialize the raw response object to structured response\n\n## Adding Middleware\n\nThere are two ways to add middleware to a middleware stack. They both add middleware to specified `Step` but they provide fine-grained location control differently.\n\n### Absolute Location\n\nYou can add middleware to specified step with:\n\n```javascript\nstack.add(middleware, {\n  step: \"finalizeRequest\",\n});\n```\n\nThis approach works for most cases. Sometimes you want your middleware to be executed in the front of the `Step`, you can set the `Priority` to `high`. Set the `Priority` to `low` then this middleware will be executed at the end of `Step`:\n\n```javascript\nstack.add(middleware, {\n  step: \"finalizeRequest\",\n  priority: \"high\",\n});\n```\n\nIf multiple middleware is added to same `step` with same `priority`, the order of them is determined by the order of adding them.\n\n### Relative Location\n\nIn some cases, you might want to execute your middleware before some other known middleware, then you can use `addRelativeTo()`:\n\n```javascript\nstack.add(middleware, {\n  step: \"finalizeRequest\",\n  name: \"myMiddleware\",\n});\nstack.addRelativeTo(anotherMiddleware, {\n  relation: \"before\", //or 'after'\n  toMiddleware: \"myMiddleware\",\n});\n```\n\n## Removing Middleware\n\nYou can remove middleware by name one at a time:\n\n```javascript\nstack.remove(\"Middleware1\");\n```\n\nIf you specify tags for middleware, you can remove multiple middleware at a time according to tag:\n\n```javascript\nstack.add(middleware, {\n  step: \"finalizeRequest\",\n  tags: [\"final\"],\n});\nstack.removeByTag(\"final\");\n```\n","publish_time":1733759916140,"maintainers":[{"name":"trivikr-aws","email":"trivikr@amazon.com"},{"name":"smithy-team","email":"aws-smithy-team+npm@amazon.com"}],"_cnpm_publish_time":1733759916140,"dist-tags":{"latest":"4.5.2"}}