@fgiova/fastify-sqs-consumer 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -1
- package/dist/cjs/index.d.ts +10 -2
- package/dist/cjs/index.js +13 -1
- package/dist/esm/index.d.mts +10 -2
- package/dist/esm/index.mjs +13 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,10 +74,39 @@ Options are an array of objects with the following properties (one for each queu
|
|
|
74
74
|
| parallelExecution | boolean | Enable parallel execution of message handlers. |
|
|
75
75
|
| credentials | {accessKeyId, secretAccessKey} | Explicit AWS credentials (alternative to environment configuration). |
|
|
76
76
|
| events | object | Events functions for the consumer (detail in next table). |
|
|
77
|
-
| sqs | MiniSQSClient
|
|
77
|
+
| sqs | MiniSQSClient \| SQSOptions | Either an initialized [@fgiova/mini-sqs-client](https://www.npmjs.com/package/@fgiova/mini-sqs-client) instance (useful for testing sessions) or an options object used to build the client (see below). |
|
|
78
78
|
|
|
79
79
|
\* required
|
|
80
80
|
|
|
81
|
+
### sqs options object
|
|
82
|
+
|
|
83
|
+
Instead of passing a pre-built `MiniSQSClient`, you can pass an options object so the plugin builds the client for you:
|
|
84
|
+
|
|
85
|
+
| Option | Type | Description |
|
|
86
|
+
|---------------|---------------------------------|----------------------------------------------------------------------------------------------|
|
|
87
|
+
| endpoint | string | Custom SQS endpoint (e.g. a local LocalStack/ElasticMQ instance). |
|
|
88
|
+
| undiciOptions | Pool.Options | [undici](https://undici.nodejs.org/#/docs/api/Pool) `Pool` options for the underlying HTTP client. |
|
|
89
|
+
| credentials | {accessKeyId, secretAccessKey} | Explicit AWS credentials. The top-level `credentials` option takes precedence over this one. |
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
app.register(sqsConsumer, [
|
|
93
|
+
{
|
|
94
|
+
arn: "arn:aws:sqs:eu-central-1:000000000000:MyQueue",
|
|
95
|
+
sqs: {
|
|
96
|
+
endpoint: "http://localhost:4566",
|
|
97
|
+
undiciOptions: { connections: 1 },
|
|
98
|
+
credentials: {
|
|
99
|
+
accessKeyId: "AWS_ACCESS_KEY_ID",
|
|
100
|
+
secretAccessKey: "AWS_SECRET_ACCESS_KEY"
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
handlerFunction: async (message, fastify) => {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
]);
|
|
108
|
+
```
|
|
109
|
+
|
|
81
110
|
## Decorator
|
|
82
111
|
|
|
83
112
|
The plugin decorates the Fastify instance with `sqsConsumers`, a `Record<string, { consumer: SQSConsumer, meta: { pendingMessages: number } }>` that provides access to the registered consumers and their metadata.
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Message, MiniSQSClient } from "@fgiova/mini-sqs-client";
|
|
2
2
|
import { type HooksOptions, SQSConsumer } from "@fgiova/sqs-consumer";
|
|
3
3
|
import type { FastifyInstance } from "fastify";
|
|
4
|
+
import type { Pool } from "undici";
|
|
4
5
|
declare module "fastify" {
|
|
5
6
|
interface FastifyInstance {
|
|
6
7
|
sqsConsumers: Record<string, {
|
|
@@ -26,7 +27,14 @@ declare function sqsConsumerPlugin(fastify: FastifyInstance, options: {
|
|
|
26
27
|
attributeNames?: string[];
|
|
27
28
|
events?: HooksOptions;
|
|
28
29
|
parallelExecution?: boolean;
|
|
29
|
-
sqs?: MiniSQSClient
|
|
30
|
+
sqs?: MiniSQSClient | {
|
|
31
|
+
endpoint?: string;
|
|
32
|
+
undiciOptions?: Pool.Options;
|
|
33
|
+
credentials?: {
|
|
34
|
+
accessKeyId: string;
|
|
35
|
+
secretAccessKey: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
30
38
|
}[], done: (err?: Error) => void): void;
|
|
31
39
|
export declare const fastifyPlugin: typeof sqsConsumerPlugin;
|
|
32
40
|
export default fastifyPlugin;
|
package/dist/cjs/index.js
CHANGED
|
@@ -5,12 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.fastifyPlugin = void 0;
|
|
7
7
|
const node_crypto_1 = require("node:crypto");
|
|
8
|
+
const mini_sqs_client_1 = require("@fgiova/mini-sqs-client");
|
|
8
9
|
const sqs_consumer_1 = require("@fgiova/sqs-consumer");
|
|
9
10
|
// @ts-expect-error
|
|
10
11
|
const unpromise_1 = require("@watchable/unpromise");
|
|
11
12
|
const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
|
|
12
13
|
function createConsumer(fastify, queueArn, handlerFunction, timeout = 90000, waitTimeSeconds = 20, batchSize = 1, attributeNames = [], messageAttributeNames = [], parallelExecution, hooks, sqs, credentials) {
|
|
13
14
|
const meta = { pendingMessages: 0 };
|
|
15
|
+
credentials =
|
|
16
|
+
credentials ??
|
|
17
|
+
(typeof sqs === "object" && !(sqs instanceof mini_sqs_client_1.MiniSQSClient)
|
|
18
|
+
? sqs.credentials
|
|
19
|
+
: undefined);
|
|
14
20
|
return {
|
|
15
21
|
consumer: new sqs_consumer_1.SQSConsumer({
|
|
16
22
|
queueARN: queueArn,
|
|
@@ -28,7 +34,13 @@ function createConsumer(fastify, queueArn, handlerFunction, timeout = 90000, wai
|
|
|
28
34
|
},
|
|
29
35
|
hooks,
|
|
30
36
|
clientOptions: {
|
|
31
|
-
sqsClient: sqs,
|
|
37
|
+
sqsClient: sqs instanceof mini_sqs_client_1.MiniSQSClient ? sqs : undefined,
|
|
38
|
+
endpoint: typeof sqs === "object" && !(sqs instanceof mini_sqs_client_1.MiniSQSClient)
|
|
39
|
+
? sqs.endpoint
|
|
40
|
+
: undefined,
|
|
41
|
+
undiciOptions: typeof sqs === "object" && !(sqs instanceof mini_sqs_client_1.MiniSQSClient)
|
|
42
|
+
? sqs.undiciOptions
|
|
43
|
+
: undefined,
|
|
32
44
|
/* c8 ignore next 1 */
|
|
33
45
|
signer: credentials ? { credentials } : undefined,
|
|
34
46
|
},
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Message, MiniSQSClient } from "@fgiova/mini-sqs-client";
|
|
2
2
|
import { type HooksOptions, SQSConsumer } from "@fgiova/sqs-consumer";
|
|
3
3
|
import type { FastifyInstance } from "fastify";
|
|
4
|
+
import type { Pool } from "undici";
|
|
4
5
|
declare module "fastify" {
|
|
5
6
|
interface FastifyInstance {
|
|
6
7
|
sqsConsumers: Record<string, {
|
|
@@ -26,7 +27,14 @@ declare function sqsConsumerPlugin(fastify: FastifyInstance, options: {
|
|
|
26
27
|
attributeNames?: string[];
|
|
27
28
|
events?: HooksOptions;
|
|
28
29
|
parallelExecution?: boolean;
|
|
29
|
-
sqs?: MiniSQSClient
|
|
30
|
+
sqs?: MiniSQSClient | {
|
|
31
|
+
endpoint?: string;
|
|
32
|
+
undiciOptions?: Pool.Options;
|
|
33
|
+
credentials?: {
|
|
34
|
+
accessKeyId: string;
|
|
35
|
+
secretAccessKey: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
30
38
|
}[], done: (err?: Error) => void): void;
|
|
31
39
|
export declare const fastifyPlugin: typeof sqsConsumerPlugin;
|
|
32
40
|
export default fastifyPlugin;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { MiniSQSClient } from "@fgiova/mini-sqs-client";
|
|
2
3
|
import { SQSConsumer } from "@fgiova/sqs-consumer";
|
|
3
4
|
// @ts-expect-error
|
|
4
5
|
import { Unpromise } from "@watchable/unpromise";
|
|
5
6
|
import fp from "fastify-plugin";
|
|
6
7
|
function createConsumer(fastify, queueArn, handlerFunction, timeout = 90000, waitTimeSeconds = 20, batchSize = 1, attributeNames = [], messageAttributeNames = [], parallelExecution, hooks, sqs, credentials) {
|
|
7
8
|
const meta = { pendingMessages: 0 };
|
|
9
|
+
credentials =
|
|
10
|
+
credentials ??
|
|
11
|
+
(typeof sqs === "object" && !(sqs instanceof MiniSQSClient)
|
|
12
|
+
? sqs.credentials
|
|
13
|
+
: undefined);
|
|
8
14
|
return {
|
|
9
15
|
consumer: new SQSConsumer({
|
|
10
16
|
queueARN: queueArn,
|
|
@@ -22,7 +28,13 @@ function createConsumer(fastify, queueArn, handlerFunction, timeout = 90000, wai
|
|
|
22
28
|
},
|
|
23
29
|
hooks,
|
|
24
30
|
clientOptions: {
|
|
25
|
-
sqsClient: sqs,
|
|
31
|
+
sqsClient: sqs instanceof MiniSQSClient ? sqs : undefined,
|
|
32
|
+
endpoint: typeof sqs === "object" && !(sqs instanceof MiniSQSClient)
|
|
33
|
+
? sqs.endpoint
|
|
34
|
+
: undefined,
|
|
35
|
+
undiciOptions: typeof sqs === "object" && !(sqs instanceof MiniSQSClient)
|
|
36
|
+
? sqs.undiciOptions
|
|
37
|
+
: undefined,
|
|
26
38
|
/* c8 ignore next 1 */
|
|
27
39
|
signer: credentials ? { credentials } : undefined,
|
|
28
40
|
},
|