{"_id":"@allenzhong/sqs-consumer","_rev":"1-8524738ee38930d84fa58c0e20958892","name":"@allenzhong/sqs-consumer","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@allenzhong/sqs-consumer","version":"0.0.1","description":"Build SQS-based Node applications without the boilerplate","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","watch":"tsc --watch","clean":"rm -fr dist/*","prepublish":"npm run build","pretest":"npm run build","test":"mocha --recursive --full-trace --exit","lint":"eslint . --ext .ts","lint:fix":"eslint . --fix","coverage":"nyc mocha && nyc report --reporter=html && nyc report --reporter=json-summary","lcov":"nyc mocha && nyc report --reporter=lcov","posttest":"npm run lint"},"repository":{"type":"git","url":"git+https://github.com/allenzhong/sqs-consumer.git"},"bugs":{"url":"https://github.com/allenzhong/sqs-consumer/issues"},"homepage":"https://github.com/allenzhong/sqs-consumer","keywords":["sqs","queue","consumer"],"license":"Apache-2.0","devDependencies":{"@types/chai":"^4.2.11","@types/debug":"^4.1.5","@types/mocha":"^7.0.2","@types/node":"^14.0.13","@types/sinon":"^9.0.4","chai":"^4.2.0","eslint":"^8.14.0","eslint-config-iplayer-ts":"^4.0.0","mocha":"^8.0.1","p-event":"^4.2.0","sinon":"^9.0.2","ts-node":"^8.10.2","typescript":"^4.6.4","@aws-sdk/client-sqs":"^3.82.0"},"dependencies":{"debug":"^4.3.1"},"peerDependencies":{"@aws-sdk/client-sqs":"^3.82.0"},"eslintConfig":{"extends":"iplayer-ts","parserOptions":{"ecmaVersion":2017,"sourceType":"module"}},"mocha":{"spec":"test/**/**/*.ts","require":"ts-node/register"},"gitHead":"b283bcba606b5f7f4b1dfe521186900d009932ff","_id":"@allenzhong/sqs-consumer@0.0.1","_nodeVersion":"14.18.1","_npmVersion":"8.6.0","dist":{"integrity":"sha512-yOEP+Th2Uhc9bvpbXkTawcC3yV11NahGVbXEJKH+R5zWksfMuyZJZYph1PdqwNCn8a0g8+WyDs1W8aoUkBFu8g==","shasum":"964224fe702bf87460681173aafacdbf4d3f7d76","tarball":"https://registry.npmjs.org/@allenzhong/sqs-consumer/-/sqs-consumer-0.0.1.tgz","fileCount":24,"unpackedSize":69913,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD65Okd03TqM0SseIKF9NFo0WGlQXHct5hH3V7kOfTKeQIgLFiggbDEUFAJdTdBcrPG8gEktvuZ187e+10a+EmIlRE="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJica9bACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq7Xg//cHyArTdmKxb2YwAAc9GZ8fvxTgJ/iRbsUfRPwUKw5h7GBtOi\r\nG8sfgs8MJDIN8lDZx/BvnT7GAIjf3qij/xJjaX/om3AVppFePVRWAxvjIA3H\r\nnR1YWkZttCHx1njoAJi5S/Q/Akrt42JavBLfVJZK0ObxWGoDAFiTt3uEcmqg\r\nLVnkCXkFJiF984Wi7Q1ZPr5Yg9BkZyATCSCuCy8AuJhgJfCr+88ebpBteI+V\r\nT2smPPHQRAeO0x83s8lpcKLytUEAuLdthqpA+/l0RhMewFdKDM1+nNmVup7y\r\neqaKf4kmCFCZjZzhoaSqOSrPyTpLISMJwoGgO2sFrNH9GVr3mwQe13bYTXwJ\r\nN2lZQy/Z1KyOXOfXtMkjFbHDbPFsRzcJmn4zjH439tBm7nh9eRKuMv4zNX1h\r\n81QavdtdBEKR00fs/ExqOHw+o2pfxLlkkYqEl7rp6Q4R/2E1YJb966gmSm0b\r\nySBDh8AvyXhmEqJ6JiSAivUYa2/ozBicbad3lyrkkCJNfaRxEQu56qlPjJjA\r\nr2M0hoIU+ENQBkBzn2wmisMn/FROvO0F6+0vc4gXWDuB2Rkk4Up+T0yyhxvm\r\nLdipgqfrkAlqSmzffYwHoExXTX0L74CPLutnCT5ZDxP1QnP416oBI+NNJiDU\r\n4r4vHea79GFp2oStFZvJQvnkm/sRCPDVEi8=\r\n=RFSG\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"allenzhong","email":"zhong.allen@gmail.com"},"directories":{},"maintainers":[{"name":"allenzhong","email":"zhong.allen@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sqs-consumer_0.0.1_1651617626837_0.6940459029126387"},"_hasShrinkwrap":false},"0.0.2":{"name":"@allenzhong/sqs-consumer","version":"0.0.2","description":"Build SQS-based Node applications without the boilerplate","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","watch":"tsc --watch","clean":"rm -fr dist/*","prepublish":"npm run build","pretest":"npm run build","test":"mocha --recursive --full-trace --exit","lint":"eslint . --ext .ts","lint:fix":"eslint . --fix","coverage":"nyc mocha && nyc report --reporter=html && nyc report --reporter=json-summary","lcov":"nyc mocha && nyc report --reporter=lcov","posttest":"npm run lint"},"repository":{"type":"git","url":"git+https://github.com/allenzhong/sqs-consumer.git"},"bugs":{"url":"https://github.com/allenzhong/sqs-consumer/issues"},"homepage":"https://github.com/allenzhong/sqs-consumer","keywords":["sqs","queue","consumer"],"license":"Apache-2.0","devDependencies":{"@types/chai":"^4.2.11","@types/debug":"^4.1.5","@types/mocha":"^7.0.2","@types/node":"^14.0.13","@types/sinon":"^9.0.4","chai":"^4.2.0","eslint":"^8.14.0","eslint-config-iplayer-ts":"^4.0.0","mocha":"^8.0.1","p-event":"^4.2.0","sinon":"^9.0.2","ts-node":"^8.10.2","typescript":"^4.6.4","@aws-sdk/client-sqs":"^3.82.0"},"dependencies":{"debug":"^4.3.1"},"peerDependencies":{"@aws-sdk/client-sqs":"^3.82.0"},"eslintConfig":{"extends":"iplayer-ts","parserOptions":{"ecmaVersion":2017,"sourceType":"module"}},"mocha":{"spec":"test/**/**/*.ts","require":"ts-node/register"},"gitHead":"992b789fed9d52d188e18b2a2eb318aaed8c0ade","_id":"@allenzhong/sqs-consumer@0.0.2","_nodeVersion":"14.18.1","_npmVersion":"8.6.0","dist":{"integrity":"sha512-fKZiEo92j7uK2i2P0c/c4nBOdOkC418oOrBb6Aou5pu3qe8q811B6jXkjljaj7q2x+xP+gPskxeS6j/IKBj/7Q==","shasum":"c5e08df6be0b4fa2f02eb0dc52e70c81de7a1c47","tarball":"https://registry.npmjs.org/@allenzhong/sqs-consumer/-/sqs-consumer-0.0.2.tgz","fileCount":24,"unpackedSize":70055,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCXtWNl0VEMNKBvgxKD9OEK0V/z8ZBtibm80h4EKUcRSgIhAL58keHQaR+Xkcy/w3d4daNn76dsXMJoBX5XncDGabDC"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJicbOSACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmob8Q/9Gio5W7qQNDQhx0L9FLQlunZVJOL9FjBbn5aB96BZwxXNjJzt\r\nv+lciCp2vftuc3KbFodWgfdM3sCF6ZQKWgpgb3udJ0x9t9xWNfR3qM72uii8\r\np4AIyMiVU3gi35p2IUfl6bwTb0HiJisu9bVHd6uTlZQHAml947V9XAR7oDua\r\nEMao95YLXJhi6/wT4lhcjMXe1bq1ZhQyIrkvY6tXTXQYl6yO/l8HIh9H6Nit\r\njHuBcBckuKAJwthemQREvg6VtskT/4eYHpa1DbvGgIo2xcA7RLaMKgsA4hmK\r\nezvrZv64sbZX7Q99heEPJRxBd1tPAQABEjUcspEsQPaJ/sufxynB3En5XM8V\r\nWS16A4npzBkvO75TQ1Gjy+cbjN9BUwHelcgvR13Rlii8H9u/G80012BKoTYp\r\n1RWhi4eNOY6ro95i5AXfOjJn7b6tAumP3Z9P0jUqnkBJfUaamYhavH11pKdU\r\ni9gwhAhKiXivSEcgo07fGAhWvCmjV71TqZDKLQOmjivBYSA5HBaX/9l/T0s4\r\nRU9iwMymupTPU7sW0+2Dn0sLGxJKijgkpzW+Vw07engKYM6swdVE+6r2TYSx\r\nS/XM5Q6uO6KWEvYJbnyLR1JPZXEVxExgS6xPzhwoqyf2f59S8GSsq04nKSKo\r\n7vs8ZjH284RPqUp/vJGjYHLWVn8k/0hn0k0=\r\n=7dg7\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"allenzhong","email":"zhong.allen@gmail.com"},"directories":{},"maintainers":[{"name":"allenzhong","email":"zhong.allen@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sqs-consumer_0.0.2_1651618706196_0.47065347201331664"},"_hasShrinkwrap":false}},"time":{"created":"2022-05-03T22:40:26.775Z","0.0.1":"2022-05-03T22:40:27.002Z","modified":"2022-05-03T22:58:26.502Z","0.0.2":"2022-05-03T22:58:26.426Z"},"maintainers":[{"name":"allenzhong","email":"zhong.allen@gmail.com"}],"description":"Build SQS-based Node applications without the boilerplate","homepage":"https://github.com/allenzhong/sqs-consumer","keywords":["sqs","queue","consumer"],"repository":{"type":"git","url":"git+https://github.com/allenzhong/sqs-consumer.git"},"bugs":{"url":"https://github.com/allenzhong/sqs-consumer/issues"},"license":"Apache-2.0","readme":"# sqs-consumer\n\n[![NPM downloads](https://img.shields.io/npm/dm/sqs-consumer.svg?style=flat)](https://npmjs.org/package/sqs-consumer)\n\nForked from bbs/sqs-consumer. Build SQS-based applications without the boilerplate. Just define an async function that handles the SQS message processing.\n\nAs the original repo is too slow to update, this repo copied the AWS sdk update from this [PR](https://github.com/bbc/sqs-consumer/pull/252).\n\n## Installation\n\n```bash\nnpm add sqs-consumer\n```\n\nNote: This library assumes you are using [AWS SDK v3](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-sqs/index.html). If you are using v2, please install v5.5.0:\n\n```bash\nnpm add sqs-consumer@5.5.0\n```\n\n## Usage\n\n```js\nimport { Consumer } from 'sqs-consumer';\n\nconst app = Consumer.create({\n  queueUrl: 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name',\n  handleMessage: async (message) => {\n    // do some work with `message`\n  }\n});\n\napp.on('error', (err) => {\n  console.error(err.message);\n});\n\napp.on('processing_error', (err) => {\n  console.error(err.message);\n});\n\napp.start();\n```\n\n* The queue is polled continuously for messages using [long polling](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html).\n* Messages are deleted from the queue once the handler function has completed successfully.\n* Throwing an error (or returning a rejected promise) from the handler function will cause the message to be left on the queue. An [SQS redrive policy](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/SQSDeadLetterQueue.html) can be used to move messages that cannot be processed to a dead letter queue.\n* By default messages are processed one at a time – a new message won't be received until the first one has been processed. To process messages in parallel, use the `batchSize` option [detailed below](#options).\n* If you need to add specific configuration options to the SQS client, you may pass an instantiated client to the Consumer constructor:\n```js\nimport { Consumer } from 'sqs-consumer';\nimport { SQSClient } from '@aws-sdk/client-sqs';\n\nconst app = Consumer.create({\n  queueUrl: 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name',\n  handleMessage: async (message) => {\n    // do some work with `message`\n  },\n  sqs: new SQSClient({\n    region: 'my-region',\n    requestHandler: MyCustomHttpHandler\n  })\n});\n\napp.on('error', (err) => {\n  console.error(err.message);\n});\n\napp.on('processing_error', (err) => {\n  console.error(err.message);\n});\n\napp.start();\n```\n\n### Credentials\n\nBy default the consumer will look for AWS credentials in the places [specified by the AWS SDK](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Setting_AWS_Credentials). The simplest option is to export your credentials as environment variables:\n\n```bash\nexport AWS_SECRET_ACCESS_KEY=...\nexport AWS_ACCESS_KEY_ID=...\n```\n\nIf you need to specify your credentials manually, you can use a pre-configured instance of the [SQS Client](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-sqs/classes/sqsclient.html) client and chose from [a valid credentials provider](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/)\n\n\n```js\nimport { Consumer } from 'sqs-consumer';\nimport { SQSClient } from '@aws-sdk/client-sqs';\nimport { fromIni } from '@aws-sdk/credential-provider-ini';\n\nconst credentials = fromIni({\n  profile: 'my-profile'\n});\n\nconst region = 'my-region';\n\nconst app = Consumer.create({\n  queueUrl: 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name',\n  handleMessage: async (message) => {\n    // ...\n  },\n  sqs: new SQSClient({ region, credentials })\n});\n\napp.on('error', (err) => {\n  console.error(err.message);\n});\n\napp.on('processing_error', (err) => {\n  console.error(err.message);\n});\n\napp.on('timeout_error', (err) => {\n console.error(err.message);\n});\n\napp.start();\n```\n\n## API\n\n### `Consumer.create(options)`\n\nCreates a new SQS consumer.\n\n#### Options\n\n* `queueUrl` - _String_ - The SQS queue URL\n* `region` - _String_ - The AWS region (default `eu-west-1`)\n* `handleMessage` - _Function_ - An `async` function (or function that returns a `Promise`) to be called whenever a message is received. Receives an SQS message object as it's first argument.\n* `handleMessageBatch` - _Function_ - An `async` function (or function that returns a `Promise`) to be called whenever a batch of messages is received. Similar to `handleMessage` but will receive the list of messages, not each message individually. **If both are set, `handleMessageBatch` overrides `handleMessage`**.\n* `handleMessageTimeout` - _Number_ - Time in ms to wait for `handleMessage` to process a message before timing out. Emits `timeout_error` on timeout. By default, if `handleMessage` times out, the unprocessed message returns to the end of the queue.\n* `attributeNames` - _Array_ - List of queue attributes to retrieve (i.e. `['All', 'ApproximateFirstReceiveTimestamp', 'ApproximateReceiveCount']`).\n* `messageAttributeNames` - _Array_ - List of message attributes to retrieve (i.e. `['name', 'address']`).\n* `batchSize` - _Number_ - The number of messages to request from SQS when polling (default `1`). This cannot be higher than the AWS limit of 10.\n* `visibilityTimeout` - _Number_ - The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request.\n* `heartbeatInterval` - _Number_ - The interval (in seconds) between requests to extend the message visibility timeout. On each heartbeat the visibility is extended by adding `visibilityTimeout` to the number of seconds since the start of the handler function. This value must less than `visibilityTimeout`.\n* `terminateVisibilityTimeout` - _Boolean_ - If true, sets the message visibility timeout to 0 after a `processing_error` (defaults to `false`).\n* `waitTimeSeconds` - _Number_ - The duration (in seconds) for which the call will wait for a message to arrive in the queue before returning.\n* `authenticationErrorTimeout` - _Number_ - The duration (in milliseconds) to wait before retrying after an authentication error (defaults to `10000`).\n* `pollingWaitTimeMs` - _Number_ - The duration (in milliseconds) to wait before repolling the queue (defaults to `0`).\n* `sqs` - _Object_ - An optional [SQS Client](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-sqs/classes/sqsclient.html) object to use if you need to configure the client manually\n\n### `consumer.start()`\n\nStart polling the queue for messages.\n\n### `consumer.stop()`\n\nStop polling the queue for messages.\n\n### `consumer.isRunning`  \n\nReturns the current polling state of the consumer: `true` if it is actively polling, `false` if it is not.\n\n### Events\n\nEach consumer is an [`EventEmitter`](http://nodejs.org/api/events.html) and emits the following events:\n\n|Event|Params|Description|\n|-----|------|-----------|\n|`error`|`err`, `[message]`|Fired when an error occurs interacting with the queue. If the error correlates to a message, that error is included in Params|\n|`processing_error`|`err`, `message`|Fired when an error occurs processing the message.|\n|`timeout_error`|`err`, `message`|Fired when `handleMessageTimeout` is supplied as an option and if `handleMessage` times out.|\n|`message_received`|`message`|Fired when a message is received.|\n|`message_processed`|`message`|Fired when a message is successfully processed and removed from the queue.|\n|`response_processed`|None|Fired after one batch of items (up to `batchSize`) has been successfully processed.|\n|`stopped`|None|Fired when the consumer finally stops its work.|\n|`empty`|None|Fired when the queue is empty (All messages have been consumed).|\n\n### AWS IAM Permissions\n\nConsumer will receive and delete messages from the SQS queue. Ensure `sqs:ReceiveMessage` and `sqs:DeleteMessage` access is granted on the queue being consumed.\n\n\n### Contributing \nSee contributing [guidelines](https://github.com/bbc/sqs-consumer/blob/master/.github/CONTRIBUTING.md).","readmeFilename":"README.md"}