@message-queue-toolkit/sns 1.2.0 → 2.0.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.
@@ -1,5 +1,5 @@
1
1
  import type { SNSClient, CreateTopicCommandInput, Tag } from '@aws-sdk/client-sns';
2
- import type { QueueConsumerDependencies, QueueDependencies, QueueOptions } from '@message-queue-toolkit/core';
2
+ import type { QueueConsumerDependencies, QueueDependencies, NewQueueOptions, ExistingQueueOptions } from '@message-queue-toolkit/core';
3
3
  import { AbstractQueueService } from '@message-queue-toolkit/core';
4
4
  export type SNSDependencies = QueueDependencies & {
5
5
  snsClient: SNSClient;
@@ -8,7 +8,7 @@ export type SNSQueueLocatorType = {
8
8
  topicArn: string;
9
9
  };
10
10
  export type SNSConsumerDependencies = SNSDependencies & QueueConsumerDependencies;
11
- export type SNSTopicAWSConfig = Omit<CreateTopicCommandInput, 'Name'>;
11
+ export type SNSTopicAWSConfig = CreateTopicCommandInput;
12
12
  export type SNSTopicConfig = {
13
13
  tags?: Tag[];
14
14
  DataProtectionPolicy?: string;
@@ -22,8 +22,12 @@ export type SNSTopicConfig = {
22
22
  ContentBasedDeduplication?: boolean;
23
23
  };
24
24
  };
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> {
25
+ export type NewSNSOptions<MessagePayloadType extends object> = NewQueueOptions<MessagePayloadType, SNSCreationConfig>;
26
+ export type ExistingSNSOptions<MessagePayloadType extends object> = ExistingQueueOptions<MessagePayloadType, SNSQueueLocatorType>;
27
+ export type SNSCreationConfig = {
28
+ topic: SNSTopicAWSConfig;
29
+ };
30
+ export declare class AbstractSnsService<MessagePayloadType extends object, SNSOptionsType extends ExistingQueueOptions<MessagePayloadType, SNSQueueLocatorType> | NewQueueOptions<MessagePayloadType, SNSCreationConfig> = ExistingSNSOptions<MessagePayloadType> | NewQueueOptions<MessagePayloadType, SNSCreationConfig>, DependenciesType extends SNSDependencies = SNSDependencies> extends AbstractQueueService<MessagePayloadType, DependenciesType, SNSCreationConfig, SNSQueueLocatorType, SNSOptionsType> {
27
31
  protected readonly snsClient: SNSClient;
28
32
  topicArn: string;
29
33
  constructor(dependencies: DependenciesType, options: SNSOptionsType);
@@ -12,19 +12,19 @@ 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);
15
+ if (this.locatorConfig) {
16
+ const checkResult = await (0, snsUtils_1.getTopicAttributes)(this.snsClient, this.locatorConfig.topicArn);
17
17
  if (checkResult.error === 'not_found') {
18
- throw new Error(`Topic with topicArn ${this.queueLocator.topicArn} does not exist.`);
18
+ throw new Error(`Topic with topicArn ${this.locatorConfig.topicArn} does not exist.`);
19
19
  }
20
- this.topicArn = this.queueLocator.topicArn;
20
+ this.topicArn = this.locatorConfig.topicArn;
21
21
  return;
22
22
  }
23
23
  // create new topic if it does not exist
24
- this.topicArn = await (0, snsUtils_1.assertTopic)(this.snsClient, {
25
- Name: this.queueName,
26
- ...this.queueConfiguration,
27
- });
24
+ if (!this.creationConfig) {
25
+ throw new Error('When locatorConfig for the topic is not specified, creationConfig of the topic is mandatory');
26
+ }
27
+ this.topicArn = await (0, snsUtils_1.assertTopic)(this.snsClient, this.creationConfig.topic);
28
28
  }
29
29
  // eslint-disable-next-line @typescript-eslint/require-await
30
30
  async close() { }
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractSnsService.js","sourceRoot":"","sources":["../../../lib/sns/AbstractSnsService.ts"],"names":[],"mappings":";;;AAMA,sDAAkE;AAElE,gDAAmE;AAkCnE,MAAa,kBAQX,SAAQ,2BAMT;IACoB,SAAS,CAAW;IACvC,aAAa;IACN,QAAQ,CAAQ;IAEvB,YAAY,YAA8B,EAAE,OAAuB;QACjE,KAAK,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;QAE5B,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC,SAAS,CAAA;IACzC,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,IAAI,IAAI,CAAC,YAAY,EAAE;YACrB,MAAM,WAAW,GAAG,MAAM,IAAA,6BAAkB,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;YACxF,IAAI,WAAW,CAAC,KAAK,KAAK,WAAW,EAAE;gBACrC,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,YAAY,CAAC,QAAQ,kBAAkB,CAAC,CAAA;aACrF;YAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAA;YAC1C,OAAM;SACP;QAED,wCAAwC;QACxC,IAAI,CAAC,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
+ {"version":3,"file":"AbstractSnsService.js","sourceRoot":"","sources":["../../../lib/sns/AbstractSnsService.ts"],"names":[],"mappings":";;;AAOA,sDAAkE;AAElE,gDAAmE;AA0CnE,MAAa,kBAQX,SAAQ,2BAMT;IACoB,SAAS,CAAW;IACvC,aAAa;IACN,QAAQ,CAAQ;IAEvB,YAAY,YAA8B,EAAE,OAAuB;QACjE,KAAK,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;QAE5B,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC,SAAS,CAAA;IACzC,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,IAAI,IAAI,CAAC,aAAa,EAAE;YACtB,MAAM,WAAW,GAAG,MAAM,IAAA,6BAAkB,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;YACzF,IAAI,WAAW,CAAC,KAAK,KAAK,WAAW,EAAE;gBACrC,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,aAAa,CAAC,QAAQ,kBAAkB,CAAC,CAAA;aACtF;YAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAA;YAC3C,OAAM;SACP;QAED,wCAAwC;QACxC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACxB,MAAM,IAAI,KAAK,CACb,6FAA6F,CAC9F,CAAA;SACF;QACD,IAAI,CAAC,QAAQ,GAAG,MAAM,IAAA,sBAAW,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IAC9E,CAAC;IAED,4DAA4D;IAC5C,KAAK,CAAC,KAAK,KAAmB,CAAC;CAChD;AA/CD,gDA+CC"}
@@ -1,9 +1,13 @@
1
- import type { CreateTopicCommandInput, SNSClient } from '@aws-sdk/client-sns';
2
- import type { SQSConsumerDependencies, SQSConsumerOptions, SQSQueueLocatorType } from '@message-queue-toolkit/sqs';
1
+ import type { SNSClient } from '@aws-sdk/client-sns';
2
+ import type { SQSConsumerDependencies, NewSQSConsumerOptions, ExistingSQSConsumerOptions, SQSQueueLocatorType, SQSCreationConfig } from '@message-queue-toolkit/sqs';
3
3
  import { AbstractSqsConsumer } from '@message-queue-toolkit/sqs';
4
- import type { SNSQueueLocatorType } from './AbstractSnsService';
5
- export type SnsSqsConsumerOptions<MessagePayloadType extends object> = SQSConsumerOptions<MessagePayloadType, SNSSQSQueueLocatorType> & {
6
- subscribedToTopic?: CreateTopicCommandInput;
4
+ import type { ExistingSNSOptions, NewSNSOptions, SNSCreationConfig, SNSQueueLocatorType } from './AbstractSnsService';
5
+ import type { SNSSubscriptionOptions } from './SnsSubscriber';
6
+ export type NewSnsSqsConsumerOptions<MessagePayloadType extends object> = NewSQSConsumerOptions<MessagePayloadType, SQSCreationConfig & SNSCreationConfig> & NewSNSOptions<MessagePayloadType> & {
7
+ subscriptionConfig?: SNSSubscriptionOptions;
8
+ };
9
+ export type ExistingSnsSqsConsumerOptions<MessagePayloadType extends object> = ExistingSQSConsumerOptions<MessagePayloadType, SNSSQSQueueLocatorType> & ExistingSNSOptions<MessagePayloadType> & {
10
+ subscriptionConfig?: SNSSubscriptionOptions;
7
11
  };
8
12
  export type SNSSQSConsumerDependencies = SQSConsumerDependencies & {
9
13
  snsClient: SNSClient;
@@ -11,11 +15,11 @@ export type SNSSQSConsumerDependencies = SQSConsumerDependencies & {
11
15
  export type SNSSQSQueueLocatorType = SQSQueueLocatorType & SNSQueueLocatorType & {
12
16
  subscriptionArn?: string;
13
17
  };
14
- export declare abstract class AbstractSnsSqsConsumer<MessagePayloadType extends object> extends AbstractSqsConsumer<MessagePayloadType, SNSSQSQueueLocatorType, SnsSqsConsumerOptions<MessagePayloadType>> {
15
- private readonly subscribedToTopic?;
18
+ export declare abstract class AbstractSnsSqsConsumer<MessagePayloadType extends object> extends AbstractSqsConsumer<MessagePayloadType, SNSSQSQueueLocatorType, SNSCreationConfig & SQSCreationConfig, NewSnsSqsConsumerOptions<MessagePayloadType> | ExistingSnsSqsConsumerOptions<MessagePayloadType>> {
19
+ private readonly subscriptionConfig?;
16
20
  private readonly snsClient;
17
21
  topicArn: string;
18
22
  subscriptionArn: string;
19
- protected constructor(dependencies: SNSSQSConsumerDependencies, options: SnsSqsConsumerOptions<MessagePayloadType>);
23
+ protected constructor(dependencies: SNSSQSConsumerDependencies, options: NewSnsSqsConsumerOptions<MessagePayloadType> | ExistingSnsSqsConsumerOptions<MessagePayloadType>);
20
24
  init(): Promise<void>;
21
25
  }
@@ -6,7 +6,7 @@ const snsUtils_1 = require("../utils/snsUtils");
6
6
  const SnsSubscriber_1 = require("./SnsSubscriber");
7
7
  const snsMessageDeserializer_1 = require("./snsMessageDeserializer");
8
8
  class AbstractSnsSqsConsumer extends sqs_1.AbstractSqsConsumer {
9
- subscribedToTopic;
9
+ subscriptionConfig;
10
10
  snsClient;
11
11
  // @ts-ignore
12
12
  topicArn;
@@ -17,41 +17,44 @@ class AbstractSnsSqsConsumer extends sqs_1.AbstractSqsConsumer {
17
17
  ...options,
18
18
  deserializer: options.deserializer ?? snsMessageDeserializer_1.deserializeSNSMessage,
19
19
  });
20
- this.subscribedToTopic = options.subscribedToTopic;
20
+ this.subscriptionConfig = options.subscriptionConfig;
21
21
  this.snsClient = dependencies.snsClient;
22
22
  }
23
23
  async init() {
24
24
  await super.init();
25
25
  // reuse existing queue only
26
- if (this.queueLocator) {
27
- const checkResult = await (0, snsUtils_1.getTopicAttributes)(this.snsClient, this.queueLocator.topicArn);
26
+ if (this.locatorConfig) {
27
+ const checkResult = await (0, snsUtils_1.getTopicAttributes)(this.snsClient, this.locatorConfig.topicArn);
28
28
  if (checkResult.error === 'not_found') {
29
- throw new Error(`Topic with topicArn ${this.queueLocator.topicArn} does not exist.`);
29
+ throw new Error(`Topic with topicArn ${this.locatorConfig.topicArn} does not exist.`);
30
30
  }
31
- this.topicArn = this.queueLocator.topicArn;
31
+ this.topicArn = this.locatorConfig.topicArn;
32
32
  }
33
33
  // create new topic if it does not exist
34
34
  else {
35
- if (!this.subscribedToTopic) {
35
+ if (!this.creationConfig) {
36
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
37
  }
38
- this.topicArn = await (0, snsUtils_1.assertTopic)(this.snsClient, this.subscribedToTopic);
38
+ this.topicArn = await (0, snsUtils_1.assertTopic)(this.snsClient, this.creationConfig?.topic);
39
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');
40
+ if (!this.locatorConfig?.subscriptionArn) {
41
+ if (!this.creationConfig?.topic) {
42
+ throw new Error('If locatorConfig.subscriptionArn is not specified, creationConfig.topic parameter is mandatory, as there will be an attempt to create the missing topic');
43
+ }
44
+ if (!this.creationConfig?.queue) {
45
+ throw new Error('If locatorConfig.subscriptionArn is not specified, creationConfig.queue parameter is mandatory, as there will be an attempt to create the missing queue');
46
+ }
47
+ if (!this.subscriptionConfig) {
48
+ throw new Error('If locatorConfig.subscriptionArn is not specified, subscriptionConfig parameter is mandatory, as there will be an attempt to create the missing subscription');
43
49
  }
44
- const { subscriptionArn } = await (0, SnsSubscriber_1.subscribeToTopic)(this.sqsClient, this.snsClient, {
45
- QueueName: this.queueName,
46
- ...this.queueConfiguration,
47
- }, this.subscribedToTopic);
50
+ const { subscriptionArn } = await (0, SnsSubscriber_1.subscribeToTopic)(this.sqsClient, this.snsClient, this.creationConfig.queue, this.creationConfig.topic, this.subscriptionConfig);
48
51
  if (!subscriptionArn) {
49
52
  throw new Error('Failed to subscribe');
50
53
  }
51
54
  this.subscriptionArn = subscriptionArn;
52
55
  }
53
56
  else {
54
- this.subscriptionArn = this.queueLocator.subscriptionArn;
57
+ this.subscriptionArn = this.locatorConfig.subscriptionArn;
55
58
  }
56
59
  }
57
60
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractSnsSqsConsumer.js","sourceRoot":"","sources":["../../../lib/sns/AbstractSnsSqsConsumer.ts"],"names":[],"mappings":";;;AAMA,oDAAgE;AAEhE,gDAAmE;AAGnE,mDAAkD;AAClD,qEAAgE;AAkBhE,MAAsB,sBAEpB,SAAQ,yBAIT;IACkB,iBAAiB,CAA0B;IAC3C,SAAS,CAAW;IACrC,aAAa;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AC,eAAe,CAAA;SAC1D;IACH,CAAC;CACF;AArFD,wDAqFC"}
@@ -1,5 +1,7 @@
1
1
  import type { CreateTopicCommandInput, SNSClient } from '@aws-sdk/client-sns';
2
+ import type { SubscribeCommandInput } from '@aws-sdk/client-sns/dist-types/commands/SubscribeCommand';
2
3
  import type { CreateQueueCommandInput, SQSClient } from '@aws-sdk/client-sqs';
3
- export declare function subscribeToTopic(sqsClient: SQSClient, snsClient: SNSClient, queueConfiguration: CreateQueueCommandInput, topicConfiguration: CreateTopicCommandInput): Promise<{
4
+ export type SNSSubscriptionOptions = Omit<SubscribeCommandInput, 'TopicArn' | 'Endpoint' | 'Protocol' | 'ReturnSubscriptionArn'>;
5
+ export declare function subscribeToTopic(sqsClient: SQSClient, snsClient: SNSClient, queueConfiguration: CreateQueueCommandInput, topicConfiguration: CreateTopicCommandInput, subscriptionConfiguration: SNSSubscriptionOptions): Promise<{
4
6
  subscriptionArn: string | undefined;
5
7
  }>;
@@ -5,7 +5,7 @@ const client_sns_1 = require("@aws-sdk/client-sns");
5
5
  const client_sqs_1 = require("@aws-sdk/client-sqs");
6
6
  const sqs_1 = require("@message-queue-toolkit/sqs");
7
7
  const snsUtils_1 = require("../utils/snsUtils");
8
- async function subscribeToTopic(sqsClient, snsClient, queueConfiguration, topicConfiguration) {
8
+ async function subscribeToTopic(sqsClient, snsClient, queueConfiguration, topicConfiguration, subscriptionConfiguration) {
9
9
  const topicArn = await (0, snsUtils_1.assertTopic)(snsClient, topicConfiguration);
10
10
  const queueUrl = await (0, sqs_1.assertQueue)(sqsClient, queueConfiguration);
11
11
  const getQueueAttributesCommand = new client_sqs_1.GetQueueAttributesCommand({
@@ -21,6 +21,8 @@ async function subscribeToTopic(sqsClient, snsClient, queueConfiguration, topicC
21
21
  TopicArn: topicArn,
22
22
  Endpoint: sqsArn,
23
23
  Protocol: 'sqs',
24
+ ReturnSubscriptionArn: true,
25
+ ...subscriptionConfiguration,
24
26
  });
25
27
  const subscriptionResult = await snsClient.send(subscribeCommand);
26
28
  return {
@@ -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,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
+ {"version":3,"file":"SnsSubscriber.js","sourceRoot":"","sources":["../../../lib/sns/SnsSubscriber.ts"],"names":[],"mappings":";;;AACA,oDAAsD;AAGtD,oDAA+D;AAC/D,oDAAwD;AAExD,gDAA+C;AAOxC,KAAK,UAAU,gBAAgB,CACpC,SAAoB,EACpB,SAAoB,EACpB,kBAA2C,EAC3C,kBAA2C,EAC3C,yBAAiD;IAEjD,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;QACf,qBAAqB,EAAE,IAAI;QAC3B,GAAG,yBAAyB;KAC7B,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;AAjCD,4CAiCC"}
@@ -14,9 +14,9 @@ export declare const SNS_MESSAGE_BODY_SCHEMA: z.ZodObject<{
14
14
  UnsubscribeURL: z.ZodString;
15
15
  }, "strip", z.ZodTypeAny, {
16
16
  Message: string;
17
+ TopicArn: string;
17
18
  Type: string;
18
19
  MessageId: string;
19
- TopicArn: string;
20
20
  Timestamp: string;
21
21
  SignatureVersion: string;
22
22
  Signature: string;
@@ -24,9 +24,9 @@ export declare const SNS_MESSAGE_BODY_SCHEMA: z.ZodObject<{
24
24
  UnsubscribeURL: string;
25
25
  }, {
26
26
  Message: string;
27
+ TopicArn: string;
27
28
  Type: string;
28
29
  MessageId: string;
29
- TopicArn: string;
30
30
  Timestamp: string;
31
31
  SignatureVersion: string;
32
32
  Signature: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@message-queue-toolkit/sns",
3
- "version": "1.2.0",
3
+ "version": "2.0.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "SNS adapter for message-queue-toolkit",
@@ -33,8 +33,8 @@
33
33
  "peerDependencies": {
34
34
  "@aws-sdk/client-sns": "^3.369.0",
35
35
  "@aws-sdk/client-sqs": "^3.369.0",
36
- "@message-queue-toolkit/core": "^1.1.0",
37
- "@message-queue-toolkit/sqs": "^1.1.0"
36
+ "@message-queue-toolkit/core": "^1.2.0",
37
+ "@message-queue-toolkit/sqs": "^1.2.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@aws-sdk/client-sns": "^3.369.0",
@@ -51,9 +51,9 @@
51
51
  "eslint": "^8.44.0",
52
52
  "eslint-config-prettier": "^8.8.0",
53
53
  "eslint-plugin-import": "^2.27.5",
54
- "eslint-plugin-prettier": "^4.2.1",
54
+ "eslint-plugin-prettier": "^5.0.0",
55
55
  "eslint-plugin-vitest": "^0.2.6",
56
- "prettier": "^2.8.8",
56
+ "prettier": "^3.0.0",
57
57
  "typescript": "^5.1.6",
58
58
  "vitest": "^0.33.0"
59
59
  },