@message-queue-toolkit/sns 1.0.0 → 1.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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { SNSTopicAWSConfig, SNSTopicConfig, SNSConsumerDependencies, } from './lib/sns/AbstractSnsService';
1
+ export type { SNSTopicAWSConfig, SNSTopicConfig, SNSConsumerDependencies, SNSQueueLocatorType, } from './lib/sns/AbstractSnsService';
2
2
  export { SnsConsumerErrorResolver } from './lib/errors/SnsConsumerErrorResolver';
3
3
  export { AbstractSnsPublisher } from './lib/sns/AbstractSnsPublisher';
4
4
  export type { SNSMessageOptions } from './lib/sns/AbstractSnsPublisher';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAMA,kFAAgF;AAAvE,oIAAA,wBAAwB,OAAA;AAEjC,uEAAqE;AAA5D,4HAAA,oBAAoB,OAAA;AAK7B,2EAAwE;AAA/D,+HAAA,qBAAqB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAOA,kFAAgF;AAAvE,oIAAA,wBAAwB,OAAA;AAEjC,uEAAqE;AAA5D,4HAAA,oBAAoB,OAAA;AAK7B,2EAAwE;AAA/D,+HAAA,qBAAqB,OAAA"}
@@ -4,6 +4,9 @@ import { AbstractQueueService } from '@message-queue-toolkit/core';
4
4
  export type SNSDependencies = QueueDependencies & {
5
5
  snsClient: SNSClient;
6
6
  };
7
+ export type SNSQueueLocatorType = {
8
+ topicArn: string;
9
+ };
7
10
  export type SNSConsumerDependencies = SNSDependencies & QueueConsumerDependencies;
8
11
  export type SNSTopicAWSConfig = Omit<CreateTopicCommandInput, 'Name'>;
9
12
  export type SNSTopicConfig = {
@@ -19,7 +22,8 @@ export type SNSTopicConfig = {
19
22
  ContentBasedDeduplication?: boolean;
20
23
  };
21
24
  };
22
- export declare class AbstractSnsService<MessagePayloadType extends object, SNSOptionsType extends QueueOptions<MessagePayloadType, SNSTopicAWSConfig> = QueueOptions<MessagePayloadType, SNSTopicAWSConfig>, DependenciesType extends SNSDependencies = SNSDependencies> extends AbstractQueueService<MessagePayloadType, DependenciesType, SNSTopicAWSConfig, SNSOptionsType> {
25
+ export type SNSOptions<MessagePayloadType extends object> = QueueOptions<MessagePayloadType, SNSTopicAWSConfig, SNSQueueLocatorType>;
26
+ export declare class AbstractSnsService<MessagePayloadType extends object, SNSOptionsType extends QueueOptions<MessagePayloadType, SNSTopicAWSConfig, SNSQueueLocatorType> = SNSOptions<MessagePayloadType>, DependenciesType extends SNSDependencies = SNSDependencies> extends AbstractQueueService<MessagePayloadType, DependenciesType, SNSTopicAWSConfig, SNSQueueLocatorType, SNSOptionsType> {
23
27
  protected readonly snsClient: SNSClient;
24
28
  topicArn: string;
25
29
  constructor(dependencies: DependenciesType, options: SNSOptionsType);
@@ -12,6 +12,15 @@ class AbstractSnsService extends core_1.AbstractQueueService {
12
12
  this.snsClient = dependencies.snsClient;
13
13
  }
14
14
  async init() {
15
+ if (this.queueLocator) {
16
+ const checkResult = await (0, snsUtils_1.getTopicAttributes)(this.snsClient, this.queueLocator.topicArn);
17
+ if (checkResult.error === 'not_found') {
18
+ throw new Error(`Topic with topicArn ${this.queueLocator.topicArn} does not exist.`);
19
+ }
20
+ this.topicArn = this.queueLocator.topicArn;
21
+ return;
22
+ }
23
+ // create new topic if it does not exist
15
24
  this.topicArn = await (0, snsUtils_1.assertTopic)(this.snsClient, {
16
25
  Name: this.queueName,
17
26
  ...this.queueConfiguration,
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractSnsService.js","sourceRoot":"","sources":["../../../lib/sns/AbstractSnsService.ts"],"names":[],"mappings":";;;AAMA,sDAAkE;AAElE,gDAA+C;AAwB/C,MAAa,kBAOX,SAAQ,2BAKT;IACoB,SAAS,CAAW;IACvC,aAAa;IACN,Q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QAAQ,GAAG,MAAM,IAAA,sBAAW,EAAC,IAAI,CAAC,SAAS,EAAE;YAChD,IAAI,EAAE,IAAI,CAAC,SAAS;YACpB,GAAG,IAAI,CAAC,kBAAkB;SAC3B,CAAC,CAAA;IACJ,CAAC;IAED,4DAA4D;IAC5C,KAAK,CAAC,KAAK,KAAmB,CAAC;CAChD;AA7CD,gDA6CC"}
@@ -1,16 +1,21 @@
1
1
  import type { CreateTopicCommandInput, SNSClient } from '@aws-sdk/client-sns';
2
- import type { SQSConsumerDependencies, SQSConsumerOptions } from '@message-queue-toolkit/sqs';
2
+ import type { SQSConsumerDependencies, SQSConsumerOptions, SQSQueueLocatorType } from '@message-queue-toolkit/sqs';
3
3
  import { AbstractSqsConsumer } from '@message-queue-toolkit/sqs';
4
- export type SnsSqsConsumerOptions<MessagePayloadType extends object> = SQSConsumerOptions<MessagePayloadType> & {
5
- subscribedToTopic: CreateTopicCommandInput;
4
+ import type { SNSQueueLocatorType } from './AbstractSnsService';
5
+ export type SnsSqsConsumerOptions<MessagePayloadType extends object> = SQSConsumerOptions<MessagePayloadType, SNSSQSQueueLocatorType> & {
6
+ subscribedToTopic?: CreateTopicCommandInput;
6
7
  };
7
8
  export type SNSSQSConsumerDependencies = SQSConsumerDependencies & {
8
9
  snsClient: SNSClient;
9
10
  };
10
- export declare abstract class AbstractSnsSqsConsumer<MessagePayloadType extends object> extends AbstractSqsConsumer<MessagePayloadType, SnsSqsConsumerOptions<MessagePayloadType>> {
11
- private readonly subscribedToTopic;
11
+ export type SNSSQSQueueLocatorType = SQSQueueLocatorType & SNSQueueLocatorType & {
12
+ subscriptionArn?: string;
13
+ };
14
+ export declare abstract class AbstractSnsSqsConsumer<MessagePayloadType extends object> extends AbstractSqsConsumer<MessagePayloadType, SNSSQSQueueLocatorType, SnsSqsConsumerOptions<MessagePayloadType>> {
15
+ private readonly subscribedToTopic?;
12
16
  private readonly snsClient;
13
17
  topicArn: string;
18
+ subscriptionArn: string;
14
19
  protected constructor(dependencies: SNSSQSConsumerDependencies, options: SnsSqsConsumerOptions<MessagePayloadType>);
15
20
  init(): Promise<void>;
16
21
  }
@@ -10,6 +10,8 @@ class AbstractSnsSqsConsumer extends sqs_1.AbstractSqsConsumer {
10
10
  snsClient;
11
11
  // @ts-ignore
12
12
  topicArn;
13
+ // @ts-ignore
14
+ subscriptionArn;
13
15
  constructor(dependencies, options) {
14
16
  super(dependencies, {
15
17
  ...options,
@@ -20,11 +22,37 @@ class AbstractSnsSqsConsumer extends sqs_1.AbstractSqsConsumer {
20
22
  }
21
23
  async init() {
22
24
  await super.init();
23
- this.topicArn = await (0, snsUtils_1.assertTopic)(this.snsClient, this.subscribedToTopic);
24
- await (0, SnsSubscriber_1.subscribeToTopic)(this.sqsClient, this.snsClient, {
25
- QueueName: this.queueName,
26
- ...this.queueConfiguration,
27
- }, this.subscribedToTopic);
25
+ // reuse existing queue only
26
+ if (this.queueLocator) {
27
+ const checkResult = await (0, snsUtils_1.getTopicAttributes)(this.snsClient, this.queueLocator.topicArn);
28
+ if (checkResult.error === 'not_found') {
29
+ throw new Error(`Topic with topicArn ${this.queueLocator.topicArn} does not exist.`);
30
+ }
31
+ this.topicArn = this.queueLocator.topicArn;
32
+ }
33
+ // create new topic if it does not exist
34
+ else {
35
+ if (!this.subscribedToTopic) {
36
+ throw new Error('If queueLocator.subscriptionArn is not specified, subscribedToTopic parameter is mandatory, as there will be an attempt to create the missing topic');
37
+ }
38
+ this.topicArn = await (0, snsUtils_1.assertTopic)(this.snsClient, this.subscribedToTopic);
39
+ }
40
+ if (!this.queueLocator?.subscriptionArn) {
41
+ if (!this.subscribedToTopic) {
42
+ throw new Error('If queueLocator.subscriptionArn is not specified, subscribedToTopic parameter is mandatory, as there will be an attempt to create the missing topic');
43
+ }
44
+ const { subscriptionArn } = await (0, SnsSubscriber_1.subscribeToTopic)(this.sqsClient, this.snsClient, {
45
+ QueueName: this.queueName,
46
+ ...this.queueConfiguration,
47
+ }, this.subscribedToTopic);
48
+ if (!subscriptionArn) {
49
+ throw new Error('Failed to subscribe');
50
+ }
51
+ this.subscriptionArn = subscriptionArn;
52
+ }
53
+ else {
54
+ this.subscriptionArn = this.queueLocator.subscriptionArn;
55
+ }
28
56
  }
29
57
  }
30
58
  exports.AbstractSnsSqsConsumer = AbstractSnsSqsConsumer;
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractSnsSqsConsumer.js","sourceRoot":"","sources":["../../../lib/sns/AbstractSnsSqsConsumer.ts"],"names":[],"mappings":";;;AAEA,oDAAgE;AAEhE,gDAA+C;AAE/C,mDAAkD;AAClD,qEAAgE;AAWhE,MAAsB,sBAEpB,SAAQ,yBAAkF;IACzE,iBAAiB,CAAyB;IAC1C,SAAS,CAAW;IACrC,aAAa;IACN,QAAQ,CAAQ;IAEvB,YACE,YAAwC,EACxC,OAAkD;QAElD,KAAK,CAAC,YAAY,EAAE;YAClB,GAAG,OAAO;YACV,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,8CAAqB;SAC5D,CAAC,CAAA;QAEF,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAA;QAClD,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC,SAAS,CAAA;IACzC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;QAElB,IAAI,CAAC,QAAQ,GAAG,MAAM,IAAA,sBAAW,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAA;QAEzE,MAAM,IAAA,gCAAgB,EACpB,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,SAAS,EACd;YACE,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,GAAG,IAAI,CAAC,kBAAkB;SAC3B,EACD,IAAI,CAAC,iBAAiB,CACvB,CAAA;IACH,CAAC;CACF;AApCD,wDAoCC"}
1
+ {"version":3,"file":"AbstractSnsSqsConsumer.js","sourceRoot":"","sources":["../../../lib/sns/AbstractSnsS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,EAAE,eAAe,EAAE;YACvC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE;gBAC3B,MAAM,IAAI,KAAK,CACb,qJAAqJ,CACtJ,CAAA;aACF;YAED,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,IAAA,gCAAgB,EAChD,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,SAAS,EACd;gBACE,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,GAAG,IAAI,CAAC,kBAAkB;aAC3B,EACD,IAAI,CAAC,iBAAiB,CACvB,CAAA;YACD,IAAI,CAAC,eAAe,EAAE;gBACpB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;aACvC;YACD,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;SACvC;aAAM;YACL,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,YAAY,CAAC,eAAe,CAAA;SACzD;IACH,CAAC;CACF;AA1ED,wDA0EC"}
@@ -1,3 +1,5 @@
1
1
  import type { CreateTopicCommandInput, SNSClient } from '@aws-sdk/client-sns';
2
2
  import type { CreateQueueCommandInput, SQSClient } from '@aws-sdk/client-sqs';
3
- export declare function subscribeToTopic(sqsClient: SQSClient, snsClient: SNSClient, queueConfiguration: CreateQueueCommandInput, topicConfiguration: CreateTopicCommandInput): Promise<void>;
3
+ export declare function subscribeToTopic(sqsClient: SQSClient, snsClient: SNSClient, queueConfiguration: CreateQueueCommandInput, topicConfiguration: CreateTopicCommandInput): Promise<{
4
+ subscriptionArn: string | undefined;
5
+ }>;
@@ -22,7 +22,10 @@ async function subscribeToTopic(sqsClient, snsClient, queueConfiguration, topicC
22
22
  Endpoint: sqsArn,
23
23
  Protocol: 'sqs',
24
24
  });
25
- await snsClient.send(subscribeCommand);
25
+ const subscriptionResult = await snsClient.send(subscribeCommand);
26
+ return {
27
+ subscriptionArn: subscriptionResult.SubscriptionArn,
28
+ };
26
29
  }
27
30
  exports.subscribeToTopic = subscribeToTopic;
28
31
  //# sourceMappingURL=SnsSubscriber.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SnsSubscriber.js","sourceRoot":"","sources":["../../../lib/sns/SnsSubscriber.ts"],"names":[],"mappings":";;;AACA,oDAAsD;AAEtD,oDAA+D;AAC/D,oDAAwD;AAExD,gDAA+C;AAExC,KAAK,UAAU,gBAAgB,CACpC,SAAoB,EACpB,SAAoB,EACpB,kBAA2C,EAC3C,kBAA2C;IAE3C,MAAM,QAAQ,GAAG,MAAM,IAAA,sBAAW,EAAC,SAAS,EAAE,kBAAkB,CAAC,CAAA;IACjE,MAAM,QAAQ,GAAG,MAAM,IAAA,iBAAW,EAAC,SAAS,EAAE,kBAAkB,CAAC,CAAA;IAEjE,MAAM,yBAAyB,GAAG,IAAI,sCAAyB,CAAC;QAC9D,QAAQ,EAAE,QAAQ;QAClB,cAAc,EAAE,CAAC,UAAU,CAAC;KAC7B,CAAC,CAAA;IACF,MAAM,uBAAuB,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAA;IAC/E,MAAM,MAAM,GAAG,uBAAuB,CAAC,UAAU,EAAE,QAAQ,CAAA;IAE3D,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,SAAS,QAAQ,qBAAqB,CAAC,CAAA;KACxD;IAED,MAAM,gBAAgB,GAAG,IAAI,6BAAgB,CAAC;QAC5C,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,MAAM;QAChB,QAAQ,EAAE,KAAK;KAChB,CAAC,CAAA;IAEF,MAAM,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;AACxC,CAAC;AA3BD,4CA2BC"}
1
+ {"version":3,"file":"SnsSubscriber.js","sourceRoot":"","sources":["../../../lib/sns/SnsSubscriber.ts"],"names":[],"mappings":";;;AACA,oDAAsD;AAEtD,oDAA+D;AAC/D,oDAAwD;AAExD,gDAA+C;AAExC,KAAK,UAAU,gBAAgB,CACpC,SAAoB,EACpB,SAAoB,EACpB,kBAA2C,EAC3C,kBAA2C;IAE3C,MAAM,QAAQ,GAAG,MAAM,IAAA,sBAAW,EAAC,SAAS,EAAE,kBAAkB,CAAC,CAAA;IACjE,MAAM,QAAQ,GAAG,MAAM,IAAA,iBAAW,EAAC,SAAS,EAAE,kBAAkB,CAAC,CAAA;IAEjE,MAAM,yBAAyB,GAAG,IAAI,sCAAyB,CAAC;QAC9D,QAAQ,EAAE,QAAQ;QAClB,cAAc,EAAE,CAAC,UAAU,CAAC;KAC7B,CAAC,CAAA;IACF,MAAM,uBAAuB,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAA;IAC/E,MAAM,MAAM,GAAG,uBAAuB,CAAC,UAAU,EAAE,QAAQ,CAAA;IAE3D,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,SAAS,QAAQ,qBAAqB,CAAC,CAAA;KACxD;IAED,MAAM,gBAAgB,GAAG,IAAI,6BAAgB,CAAC;QAC5C,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,MAAM;QAChB,QAAQ,EAAE,KAAK;KAChB,CAAC,CAAA;IAEF,MAAM,kBAAkB,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;IACjE,OAAO;QACL,eAAe,EAAE,kBAAkB,CAAC,eAAe;KACpD,CAAA;AACH,CAAC;AA9BD,4CA8BC"}
@@ -1,2 +1,8 @@
1
1
  import type { CreateTopicCommandInput, SNSClient } from '@aws-sdk/client-sns';
2
+ import type { Either } from '@lokalise/node-core';
3
+ type QueueAttributesResult = {
4
+ attributes?: Record<string, string>;
5
+ };
6
+ export declare function getTopicAttributes(snsClient: SNSClient, topicArn: string): Promise<Either<'not_found', QueueAttributesResult>>;
2
7
  export declare function assertTopic(snsClient: SNSClient, topicOptions: CreateTopicCommandInput): Promise<string>;
8
+ export {};
@@ -1,7 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertTopic = void 0;
3
+ exports.assertTopic = exports.getTopicAttributes = void 0;
4
4
  const client_sns_1 = require("@aws-sdk/client-sns");
5
+ async function getTopicAttributes(snsClient, topicArn) {
6
+ const command = new client_sns_1.GetTopicAttributesCommand({
7
+ TopicArn: topicArn,
8
+ });
9
+ try {
10
+ const response = await snsClient.send(command);
11
+ return {
12
+ result: {
13
+ attributes: response.Attributes,
14
+ },
15
+ };
16
+ }
17
+ catch (err) {
18
+ // @ts-ignore
19
+ if (err.Code === 'AWS.SimpleQueueService.NonExistentQueue') {
20
+ return {
21
+ // @ts-ignore
22
+ error: 'not_found',
23
+ };
24
+ }
25
+ throw err;
26
+ }
27
+ }
28
+ exports.getTopicAttributes = getTopicAttributes;
5
29
  async function assertTopic(snsClient, topicOptions) {
6
30
  const command = new client_sns_1.CreateTopicCommand(topicOptions);
7
31
  const response = await snsClient.send(command);
@@ -1 +1 @@
1
- {"version":3,"file":"snsUtils.js","sourceRoot":"","sources":["../../../lib/utils/snsUtils.ts"],"names":[],"mappings":";;;AACA,oDAAwD;AAEjD,KAAK,UAAU,WAAW,CAAC,SAAoB,EAAE,YAAqC;IAC3F,MAAM,OAAO,GAAG,IAAI,+BAAkB,CAAC,YAAY,CAAC,CAAA;IACpD,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAE9C,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;KAC5C;IACD,OAAO,QAAQ,CAAC,QAAQ,CAAA;AAC1B,CAAC;AARD,kCAQC"}
1
+ {"version":3,"file":"snsUtils.js","sourceRoot":"","sources":["../../../lib/utils/snsUtils.ts"],"names":[],"mappings":";;;AACA,oDAAmF;AAO5E,KAAK,UAAU,kBAAkB,CACtC,SAAoB,EACpB,QAAgB;IAEhB,MAAM,OAAO,GAAG,IAAI,sCAAyB,CAAC;QAC5C,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAA;IAEF,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC9C,OAAO;YACL,MAAM,EAAE;gBACN,UAAU,EAAE,QAAQ,CAAC,UAAU;aAChC;SACF,CAAA;KACF;IAAC,OAAO,GAAG,EAAE;QACZ,aAAa;QACb,IAAI,GAAG,CAAC,IAAI,KAAK,yCAAyC,EAAE;YAC1D,OAAO;gBACL,aAAa;gBACb,KAAK,EAAE,WAAW;aACnB,CAAA;SACF;QACD,MAAM,GAAG,CAAA;KACV;AACH,CAAC;AAzBD,gDAyBC;AAEM,KAAK,UAAU,WAAW,CAAC,SAAoB,EAAE,YAAqC;IAC3F,MAAM,OAAO,GAAG,IAAI,+BAAkB,CAAC,YAAY,CAAC,CAAA;IACpD,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAE9C,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;KAC5C;IACD,OAAO,QAAQ,CAAC,QAAQ,CAAA;AAC1B,CAAC;AARD,kCAQC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@message-queue-toolkit/sns",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "SNS adapter for message-queue-toolkit",
@@ -26,34 +26,36 @@
26
26
  "prepublishOnly": "npm run build:release"
27
27
  },
28
28
  "dependencies": {
29
- "@aws-sdk/client-sns": "^3.360.0",
30
- "@aws-sdk/client-sqs": "^3.360.0",
31
- "@lokalise/node-core": "^5.8.1",
32
- "sqs-consumer": "^7.2.0",
29
+ "@lokalise/node-core": "^5.10.0",
30
+ "sqs-consumer": "^7.2.2",
33
31
  "zod": "^3.21.4"
34
32
  },
35
33
  "peerDependencies": {
34
+ "@aws-sdk/client-sns": "^3.369.0",
35
+ "@aws-sdk/client-sqs": "^3.369.0",
36
36
  "@message-queue-toolkit/core": "^1.1.0",
37
37
  "@message-queue-toolkit/sqs": "^1.1.0"
38
38
  },
39
39
  "devDependencies": {
40
+ "@aws-sdk/client-sns": "^3.369.0",
41
+ "@aws-sdk/client-sqs": "^3.369.0",
40
42
  "@message-queue-toolkit/core": "*",
41
43
  "@message-queue-toolkit/sqs": "*",
42
- "@types/node": "^20.3.1",
43
- "@typescript-eslint/eslint-plugin": "^5.60.0",
44
- "@typescript-eslint/parser": "^5.60.0",
45
- "@vitest/coverage-v8": "^0.32.2",
44
+ "@types/node": "^20.4.1",
45
+ "@typescript-eslint/eslint-plugin": "^5.61.0",
46
+ "@typescript-eslint/parser": "^5.62.0",
47
+ "@vitest/coverage-v8": "^0.33.0",
46
48
  "awilix": "^8.0.1",
47
49
  "awilix-manager": "^2.0.0",
48
50
  "del-cli": "^5.0.0",
49
- "eslint": "^8.43.0",
51
+ "eslint": "^8.44.0",
50
52
  "eslint-config-prettier": "^8.8.0",
51
53
  "eslint-plugin-import": "^2.27.5",
52
54
  "eslint-plugin-prettier": "^4.2.1",
53
55
  "eslint-plugin-vitest": "^0.2.6",
54
56
  "prettier": "^2.8.8",
55
- "typescript": "^5.1.3",
56
- "vitest": "^0.32.2"
57
+ "typescript": "^5.1.6",
58
+ "vitest": "^0.33.0"
57
59
  },
58
60
  "homepage": "https://github.com/kibertoad/message-queue-toolkit",
59
61
  "repository": {