@message-queue-toolkit/sns 17.2.0 → 18.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.
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/sns/AbstractSnsPublisher.d.ts +2 -2
- package/dist/lib/sns/AbstractSnsService.d.ts +10 -5
- package/dist/lib/sns/AbstractSnsService.js +4 -2
- package/dist/lib/sns/AbstractSnsService.js.map +1 -1
- package/dist/lib/sns/AbstractSnsSqsConsumer.d.ts +5 -2
- package/dist/lib/sns/AbstractSnsSqsConsumer.js +4 -2
- package/dist/lib/sns/AbstractSnsSqsConsumer.js.map +1 -1
- package/dist/lib/sns/SnsPublisherManager.d.ts +2 -2
- package/dist/lib/sns/SnsPublisherManager.js +1 -0
- package/dist/lib/sns/SnsPublisherManager.js.map +1 -1
- package/dist/lib/types/TopicTypes.d.ts +5 -0
- package/dist/lib/types/TopicTypes.js +12 -0
- package/dist/lib/types/TopicTypes.js.map +1 -0
- package/dist/lib/utils/snsInitter.d.ts +7 -6
- package/dist/lib/utils/snsInitter.js +53 -22
- package/dist/lib/utils/snsInitter.js.map +1 -1
- package/dist/lib/utils/snsSubscriber.d.ts +4 -2
- package/dist/lib/utils/snsSubscriber.js +23 -6
- package/dist/lib/utils/snsSubscriber.js.map +1 -1
- package/dist/lib/utils/snsUtils.d.ts +6 -4
- package/dist/lib/utils/snsUtils.js +62 -16
- package/dist/lib/utils/snsUtils.js.map +1 -1
- package/dist/lib/utils/stsUtils.d.ts +8 -0
- package/dist/lib/utils/stsUtils.js +35 -0
- package/dist/lib/utils/stsUtils.js.map +1 -0
- package/package.json +17 -16
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { SNSTopicAWSConfig, SNSTopicConfig,
|
|
1
|
+
export type { SNSTopicAWSConfig, SNSTopicConfig, SNSTopicLocatorType, SNSCreationConfig, SNSDependencies, } from './lib/sns/AbstractSnsService';
|
|
2
2
|
export { SNS_MESSAGE_MAX_SIZE } from './lib/sns/AbstractSnsService';
|
|
3
3
|
export { AbstractSnsService } from './lib/sns/AbstractSnsService';
|
|
4
4
|
export { SnsConsumerErrorResolver } from './lib/errors/SnsConsumerErrorResolver';
|
|
@@ -9,6 +9,7 @@ export { AbstractSnsSqsConsumer } from './lib/sns/AbstractSnsSqsConsumer';
|
|
|
9
9
|
export type { CommonMessage } from './lib/types/MessageTypes';
|
|
10
10
|
export { deserializeSNSMessage } from './lib/utils/snsMessageDeserializer';
|
|
11
11
|
export { assertTopic, deleteTopic, getTopicAttributes, deleteSubscription, findSubscriptionByTopicAndQueue, getSubscriptionAttributes, } from './lib/utils/snsUtils';
|
|
12
|
+
export { clearCachedCallerIdentity } from './lib/utils/stsUtils';
|
|
12
13
|
export { subscribeToTopic } from './lib/utils/snsSubscriber';
|
|
13
14
|
export { initSns, initSnsSqs } from './lib/utils/snsInitter';
|
|
14
15
|
export { readSnsMessage } from './lib/utils/snsMessageReader';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FakeConsumer = exports.generateTopicSubscriptionPolicy = exports.generateFilterAttributes = exports.readSnsMessage = exports.initSnsSqs = exports.initSns = exports.subscribeToTopic = exports.getSubscriptionAttributes = exports.findSubscriptionByTopicAndQueue = exports.deleteSubscription = exports.getTopicAttributes = exports.deleteTopic = exports.assertTopic = exports.deserializeSNSMessage = exports.AbstractSnsSqsConsumer = exports.AbstractSnsPublisher = exports.SnsConsumerErrorResolver = exports.AbstractSnsService = exports.SNS_MESSAGE_MAX_SIZE = void 0;
|
|
3
|
+
exports.FakeConsumer = exports.generateTopicSubscriptionPolicy = exports.generateFilterAttributes = exports.readSnsMessage = exports.initSnsSqs = exports.initSns = exports.subscribeToTopic = exports.clearCachedCallerIdentity = exports.getSubscriptionAttributes = exports.findSubscriptionByTopicAndQueue = exports.deleteSubscription = exports.getTopicAttributes = exports.deleteTopic = exports.assertTopic = exports.deserializeSNSMessage = exports.AbstractSnsSqsConsumer = exports.AbstractSnsPublisher = exports.SnsConsumerErrorResolver = exports.AbstractSnsService = exports.SNS_MESSAGE_MAX_SIZE = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
var AbstractSnsService_1 = require("./lib/sns/AbstractSnsService");
|
|
6
6
|
Object.defineProperty(exports, "SNS_MESSAGE_MAX_SIZE", { enumerable: true, get: function () { return AbstractSnsService_1.SNS_MESSAGE_MAX_SIZE; } });
|
|
@@ -21,6 +21,8 @@ Object.defineProperty(exports, "getTopicAttributes", { enumerable: true, get: fu
|
|
|
21
21
|
Object.defineProperty(exports, "deleteSubscription", { enumerable: true, get: function () { return snsUtils_1.deleteSubscription; } });
|
|
22
22
|
Object.defineProperty(exports, "findSubscriptionByTopicAndQueue", { enumerable: true, get: function () { return snsUtils_1.findSubscriptionByTopicAndQueue; } });
|
|
23
23
|
Object.defineProperty(exports, "getSubscriptionAttributes", { enumerable: true, get: function () { return snsUtils_1.getSubscriptionAttributes; } });
|
|
24
|
+
var stsUtils_1 = require("./lib/utils/stsUtils");
|
|
25
|
+
Object.defineProperty(exports, "clearCachedCallerIdentity", { enumerable: true, get: function () { return stsUtils_1.clearCachedCallerIdentity; } });
|
|
24
26
|
var snsSubscriber_1 = require("./lib/utils/snsSubscriber");
|
|
25
27
|
Object.defineProperty(exports, "subscribeToTopic", { enumerable: true, get: function () { return snsSubscriber_1.subscribeToTopic; } });
|
|
26
28
|
var snsInitter_1 = require("./lib/utils/snsInitter");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;AAQA,mEAAmE;AAA1D,0HAAA,oBAAoB,OAAA;AAE7B,mEAAiE;AAAxD,wHAAA,kBAAkB,OAAA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@
|
|
|
1
1
|
import type { Either } from '@lokalise/node-core';
|
|
2
2
|
import type { AsyncPublisher, BarrierResult, MessageInvalidFormatError, MessageValidationError, OffloadedPayloadPointerPayload, QueuePublisherOptions, ResolvedMessage } from '@message-queue-toolkit/core';
|
|
3
|
-
import type { SNSCreationConfig, SNSDependencies,
|
|
3
|
+
import type { SNSCreationConfig, SNSDependencies, SNSTopicLocatorType } from './AbstractSnsService';
|
|
4
4
|
import { AbstractSnsService } from './AbstractSnsService';
|
|
5
5
|
export type SNSMessageOptions = {
|
|
6
6
|
MessageGroupId?: string;
|
|
7
7
|
MessageDeduplicationId?: string;
|
|
8
8
|
};
|
|
9
|
-
export type SNSPublisherOptions<MessagePayloadType extends object> = QueuePublisherOptions<SNSCreationConfig,
|
|
9
|
+
export type SNSPublisherOptions<MessagePayloadType extends object> = QueuePublisherOptions<SNSCreationConfig, SNSTopicLocatorType, MessagePayloadType>;
|
|
10
10
|
export declare abstract class AbstractSnsPublisher<MessagePayloadType extends object> extends AbstractSnsService<MessagePayloadType, MessagePayloadType> implements AsyncPublisher<MessagePayloadType, SNSMessageOptions> {
|
|
11
11
|
private readonly messageSchemaContainer;
|
|
12
12
|
private initPromise?;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { CreateTopicCommandInput, SNSClient, Tag } from '@aws-sdk/client-sns';
|
|
2
2
|
import type { QueueDependencies, QueueOptions } from '@message-queue-toolkit/core';
|
|
3
3
|
import { AbstractQueueService } from '@message-queue-toolkit/core';
|
|
4
|
+
import type { STSClient } from '@aws-sdk/client-sts';
|
|
4
5
|
import type { SNS_MESSAGE_BODY_TYPE } from '../types/MessageTypes';
|
|
5
6
|
export declare const SNS_MESSAGE_MAX_SIZE: number;
|
|
6
7
|
export type SNSDependencies = QueueDependencies & {
|
|
7
8
|
snsClient: SNSClient;
|
|
9
|
+
stsClient: STSClient;
|
|
8
10
|
};
|
|
9
11
|
export type SNSTopicAWSConfig = CreateTopicCommandInput;
|
|
10
12
|
export type SNSTopicConfig = {
|
|
@@ -23,17 +25,20 @@ export type SNSTopicConfig = {
|
|
|
23
25
|
export type ExtraSNSCreationParams = {
|
|
24
26
|
queueUrlsWithSubscribePermissionsPrefix?: string | readonly string[];
|
|
25
27
|
allowedSourceOwner?: string;
|
|
28
|
+
forceTagUpdate?: boolean;
|
|
26
29
|
};
|
|
27
30
|
export type SNSCreationConfig = {
|
|
28
|
-
topic
|
|
31
|
+
topic?: SNSTopicAWSConfig;
|
|
29
32
|
updateAttributesIfExists?: boolean;
|
|
30
33
|
} & ExtraSNSCreationParams;
|
|
31
|
-
export type
|
|
32
|
-
topicArn
|
|
34
|
+
export type SNSTopicLocatorType = {
|
|
35
|
+
topicArn?: string;
|
|
36
|
+
topicName?: string;
|
|
33
37
|
};
|
|
34
|
-
export type SNSOptions = QueueOptions<SNSCreationConfig,
|
|
35
|
-
export declare abstract class AbstractSnsService<MessagePayloadType extends object, MessageEnvelopeType extends object = SNS_MESSAGE_BODY_TYPE, SNSOptionsType extends SNSOptions = SNSOptions, DependenciesType extends SNSDependencies = SNSDependencies> extends AbstractQueueService<MessagePayloadType, MessageEnvelopeType, DependenciesType, SNSCreationConfig,
|
|
38
|
+
export type SNSOptions = QueueOptions<SNSCreationConfig, SNSTopicLocatorType>;
|
|
39
|
+
export declare abstract class AbstractSnsService<MessagePayloadType extends object, MessageEnvelopeType extends object = SNS_MESSAGE_BODY_TYPE, SNSOptionsType extends SNSOptions = SNSOptions, DependenciesType extends SNSDependencies = SNSDependencies> extends AbstractQueueService<MessagePayloadType, MessageEnvelopeType, DependenciesType, SNSCreationConfig, SNSTopicLocatorType, SNSOptionsType> {
|
|
36
40
|
protected readonly snsClient: SNSClient;
|
|
41
|
+
protected readonly stsClient: STSClient;
|
|
37
42
|
protected topicArn: string;
|
|
38
43
|
constructor(dependencies: DependenciesType, options: SNSOptionsType);
|
|
39
44
|
init(): Promise<void>;
|
|
@@ -7,17 +7,19 @@ const snsInitter_1 = require("../utils/snsInitter");
|
|
|
7
7
|
exports.SNS_MESSAGE_MAX_SIZE = 256 * 1024; // 256KB
|
|
8
8
|
class AbstractSnsService extends core_1.AbstractQueueService {
|
|
9
9
|
snsClient;
|
|
10
|
+
stsClient;
|
|
10
11
|
// @ts-ignore
|
|
11
12
|
topicArn;
|
|
12
13
|
constructor(dependencies, options) {
|
|
13
14
|
super(dependencies, options);
|
|
14
15
|
this.snsClient = dependencies.snsClient;
|
|
16
|
+
this.stsClient = dependencies.stsClient;
|
|
15
17
|
}
|
|
16
18
|
async init() {
|
|
17
19
|
if (this.deletionConfig && this.creationConfig) {
|
|
18
|
-
await (0, snsInitter_1.deleteSns)(this.snsClient, this.deletionConfig, this.creationConfig);
|
|
20
|
+
await (0, snsInitter_1.deleteSns)(this.snsClient, this.stsClient, this.deletionConfig, this.creationConfig);
|
|
19
21
|
}
|
|
20
|
-
const initResult = await (0, snsInitter_1.initSns)(this.snsClient, this.locatorConfig, this.creationConfig);
|
|
22
|
+
const initResult = await (0, snsInitter_1.initSns)(this.snsClient, this.stsClient, this.locatorConfig, this.creationConfig);
|
|
21
23
|
this.topicArn = initResult.topicArn;
|
|
22
24
|
this.isInitted = true;
|
|
23
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractSnsService.js","sourceRoot":"","sources":["../../../lib/sns/AbstractSnsService.ts"],"names":[],"mappings":";;;AAEA,sDAAkE;
|
|
1
|
+
{"version":3,"file":"AbstractSnsService.js","sourceRoot":"","sources":["../../../lib/sns/AbstractSnsService.ts"],"names":[],"mappings":";;;AAEA,sDAAkE;AAIlE,oDAAwD;AAExD,yDAAyD;AAC5C,QAAA,oBAAoB,GAAG,GAAG,GAAG,IAAI,CAAA,CAAC,QAAQ;AAyCvD,MAAsB,kBAKpB,SAAQ,2BAOT;IACoB,SAAS,CAAW;IACpB,SAAS,CAAW;IACvC,aAAa;IACH,QAAQ,CAAQ;IAE1B,YAAY,YAA8B,EAAE,OAAuB;QACjE,KAAK,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;QAE5B,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC,SAAS,CAAA;QACvC,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC,SAAS,CAAA;IACzC,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YAC/C,MAAM,IAAA,sBAAS,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;QAC3F,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,IAAA,oBAAO,EAC9B,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,cAAc,CACpB,CAAA;QACD,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAA;QACnC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;IACvB,CAAC;IAEe,KAAK;QACnB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAA;QACtB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;IAC1B,CAAC;CACF;AA5CD,gDA4CC"}
|
|
@@ -2,12 +2,14 @@ import type { SNSClient } from '@aws-sdk/client-sns';
|
|
|
2
2
|
import type { SQSConsumerDependencies, SQSConsumerOptions, SQSCreationConfig, SQSMessage, SQSQueueLocatorType } from '@message-queue-toolkit/sqs';
|
|
3
3
|
import { AbstractSqsConsumer } from '@message-queue-toolkit/sqs';
|
|
4
4
|
import type { SNSSubscriptionOptions } from '../utils/snsSubscriber';
|
|
5
|
-
import type {
|
|
5
|
+
import type { STSClient } from '@aws-sdk/client-sts';
|
|
6
|
+
import type { SNSCreationConfig, SNSOptions, SNSTopicLocatorType } from './AbstractSnsService';
|
|
6
7
|
export type SNSSQSConsumerDependencies = SQSConsumerDependencies & {
|
|
7
8
|
snsClient: SNSClient;
|
|
9
|
+
stsClient: STSClient;
|
|
8
10
|
};
|
|
9
11
|
export type SNSSQSCreationConfig = SQSCreationConfig & SNSCreationConfig;
|
|
10
|
-
export type SNSSQSQueueLocatorType = SQSQueueLocatorType &
|
|
12
|
+
export type SNSSQSQueueLocatorType = Partial<SQSQueueLocatorType> & SNSTopicLocatorType & {
|
|
11
13
|
subscriptionArn?: string;
|
|
12
14
|
};
|
|
13
15
|
export type SNSSQSConsumerOptions<MessagePayloadType extends object, ExecutionContext, PrehandlerOutput> = SQSConsumerOptions<MessagePayloadType, ExecutionContext, PrehandlerOutput, SNSSQSCreationConfig, SNSSQSQueueLocatorType> & SNSOptions & {
|
|
@@ -16,6 +18,7 @@ export type SNSSQSConsumerOptions<MessagePayloadType extends object, ExecutionCo
|
|
|
16
18
|
export declare abstract class AbstractSnsSqsConsumer<MessagePayloadSchemas extends object, ExecutionContext, PrehandlerOutput = undefined> extends AbstractSqsConsumer<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput, SNSSQSCreationConfig, SNSSQSQueueLocatorType, SNSSQSConsumerOptions<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>> {
|
|
17
19
|
private readonly subscriptionConfig?;
|
|
18
20
|
private readonly snsClient;
|
|
21
|
+
private readonly stsClient;
|
|
19
22
|
protected topicArn: string;
|
|
20
23
|
protected subscriptionArn: string;
|
|
21
24
|
protected constructor(dependencies: SNSSQSConsumerDependencies, options: SNSSQSConsumerOptions<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>, executionContext: ExecutionContext);
|
|
@@ -7,6 +7,7 @@ const snsMessageReader_1 = require("../utils/snsMessageReader");
|
|
|
7
7
|
class AbstractSnsSqsConsumer extends sqs_1.AbstractSqsConsumer {
|
|
8
8
|
subscriptionConfig;
|
|
9
9
|
snsClient;
|
|
10
|
+
stsClient;
|
|
10
11
|
// @ts-ignore
|
|
11
12
|
topicArn;
|
|
12
13
|
// @ts-ignore
|
|
@@ -17,15 +18,16 @@ class AbstractSnsSqsConsumer extends sqs_1.AbstractSqsConsumer {
|
|
|
17
18
|
}, executionContext);
|
|
18
19
|
this.subscriptionConfig = options.subscriptionConfig;
|
|
19
20
|
this.snsClient = dependencies.snsClient;
|
|
21
|
+
this.stsClient = dependencies.stsClient;
|
|
20
22
|
}
|
|
21
23
|
async init() {
|
|
22
24
|
if (this.deletionConfig && this.creationConfig && this.subscriptionConfig) {
|
|
23
|
-
await (0, snsInitter_1.deleteSnsSqs)(this.sqsClient, this.snsClient, this.deletionConfig, this.creationConfig.queue, this.creationConfig.topic, this.subscriptionConfig);
|
|
25
|
+
await (0, snsInitter_1.deleteSnsSqs)(this.sqsClient, this.snsClient, this.stsClient, this.deletionConfig, this.creationConfig.queue, this.creationConfig.topic, this.subscriptionConfig, undefined, this.locatorConfig);
|
|
24
26
|
}
|
|
25
27
|
else if (this.deletionConfig && this.creationConfig) {
|
|
26
28
|
await (0, sqs_1.deleteSqs)(this.sqsClient, this.deletionConfig, this.creationConfig);
|
|
27
29
|
}
|
|
28
|
-
const initSnsSqsResult = await (0, snsInitter_1.initSnsSqs)(this.sqsClient, this.snsClient, this.locatorConfig, this.creationConfig, this.subscriptionConfig, { logger: this.logger });
|
|
30
|
+
const initSnsSqsResult = await (0, snsInitter_1.initSnsSqs)(this.sqsClient, this.snsClient, this.stsClient, this.locatorConfig, this.creationConfig, this.subscriptionConfig, { logger: this.logger });
|
|
29
31
|
this.queueName = initSnsSqsResult.queueName;
|
|
30
32
|
this.queueUrl = initSnsSqsResult.queueUrl;
|
|
31
33
|
this.topicArn = initSnsSqsResult.topicArn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractSnsSqsConsumer.js","sourceRoot":"","sources":["../../../lib/sns/AbstractSnsSqsConsumer.ts"],"names":[],"mappings":";;;AAQA,oDAA2E;AAE3E,oDAA8D;AAC9D,gEAA0D;
|
|
1
|
+
{"version":3,"file":"AbstractSnsSqsConsumer.js","sourceRoot":"","sources":["../../../lib/sns/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C,SAAS,EACd,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,kBAAkB,EACvB,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CACxB,CAAA;QACD,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC,SAAS,CAAA;QAC3C,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAA;QACzC,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAA;QACzC,IAAI,CAAC,eAAe,GAAG,gBAAgB,CAAC,eAAe,CAAA;QAEvD,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAA;IAClC,CAAC;IAEkB,cAAc,CAAC,OAAmB;QACnD,MAAM,MAAM,GAAG,IAAA,iCAAc,EAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;QAC1D,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,OAAO,MAAM,CAAA;QACf,CAAC;QAED,qDAAqD;QACrD,OAAO,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;IACtC,CAAC;IAEkB,aAAa,CAAC,cAAqC;QACpE,OAAO,IAAI,CAAC,uBAAuB,CAAC,aAAa,CAAC,cAAc,CAAC,CAAA;IACnE,CAAC;CACF;AAtFD,wDAsFC"}
|
|
@@ -4,7 +4,7 @@ import type { PublisherMessageMetadataType } from '@message-queue-toolkit/core/l
|
|
|
4
4
|
import type { SnsAwareEventDefinition } from '@message-queue-toolkit/schemas';
|
|
5
5
|
import type z from 'zod';
|
|
6
6
|
import type { AbstractSnsPublisher, SNSMessageOptions, SNSPublisherOptions } from './AbstractSnsPublisher';
|
|
7
|
-
import type { SNSCreationConfig, SNSDependencies,
|
|
7
|
+
import type { SNSCreationConfig, SNSDependencies, SNSTopicLocatorType } from './AbstractSnsService';
|
|
8
8
|
import type { SnsPublisherFactory } from './CommonSnsPublisherFactory';
|
|
9
9
|
export type { SnsAwareEventDefinition };
|
|
10
10
|
export type SnsPublisherManagerDependencies<SupportedEvents extends SnsAwareEventDefinition[]> = {
|
|
@@ -19,7 +19,7 @@ export type SnsPublisherManagerOptions<T extends AbstractSnsPublisher<EventType>
|
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
21
|
export type SnsMessageSchemaType<T extends SnsAwareEventDefinition> = z.infer<T['publisherSchema']>;
|
|
22
|
-
export declare class SnsPublisherManager<T extends AbstractSnsPublisher<z.infer<SupportedEventDefinitions[number]['publisherSchema']>>, SupportedEventDefinitions extends SnsAwareEventDefinition[], MetadataType = PublisherMessageMetadataType> extends AbstractPublisherManager<SnsAwareEventDefinition, NonNullable<SupportedEventDefinitions[number]['snsTopic']>, AbstractSnsPublisher<z.infer<SupportedEventDefinitions[number]['publisherSchema']>>, SNSDependencies, SNSCreationConfig,
|
|
22
|
+
export declare class SnsPublisherManager<T extends AbstractSnsPublisher<z.infer<SupportedEventDefinitions[number]['publisherSchema']>>, SupportedEventDefinitions extends SnsAwareEventDefinition[], MetadataType = PublisherMessageMetadataType> extends AbstractPublisherManager<SnsAwareEventDefinition, NonNullable<SupportedEventDefinitions[number]['snsTopic']>, AbstractSnsPublisher<z.infer<SupportedEventDefinitions[number]['publisherSchema']>>, SNSDependencies, SNSCreationConfig, SNSTopicLocatorType, SnsMessageSchemaType<SnsAwareEventDefinition>, Omit<SNSPublisherOptions<z.infer<SupportedEventDefinitions[number]['publisherSchema']>>, 'messageSchemas' | 'creationConfig' | 'locatorConfig'>, SupportedEventDefinitions, MetadataType, SNSMessageOptions> {
|
|
23
23
|
constructor(dependencies: SnsPublisherManagerDependencies<SupportedEventDefinitions>, options: SnsPublisherManagerOptions<T, z.infer<SupportedEventDefinitions[number]['publisherSchema']>, MetadataType>);
|
|
24
24
|
publish(topic: NonNullable<SupportedEventDefinitions[number]['snsTopic']>, message: MessagePublishType<SupportedEventDefinitions[number]>, precedingEventMetadata?: Partial<MetadataType>, messageOptions?: SNSMessageOptions): Promise<MessageSchemaType<SupportedEventDefinitions[number]>>;
|
|
25
25
|
protected resolveCreationConfig(eventTarget: NonNullable<SupportedEventDefinitions[number]['snsTopic']>): SNSCreationConfig;
|
|
@@ -13,6 +13,7 @@ class SnsPublisherManager extends core_1.AbstractPublisherManager {
|
|
|
13
13
|
newPublisherOptions: options.newPublisherOptions,
|
|
14
14
|
publisherDependencies: {
|
|
15
15
|
snsClient: dependencies.snsClient,
|
|
16
|
+
stsClient: dependencies.stsClient,
|
|
16
17
|
logger: dependencies.logger,
|
|
17
18
|
errorReporter: dependencies.errorReporter,
|
|
18
19
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnsPublisherManager.js","sourceRoot":"","sources":["../../../lib/sns/SnsPublisherManager.ts"],"names":[],"mappings":";;;AAOA,sDAAsE;AAYtE,2EAAuE;AA0BvE,MAAa,mBAIX,SAAQ,+BAeT;IACC,YACE,YAAwE,EACxE,OAIC;QAED,KAAK,CAAC;YACJ,OAAO,EAAE,IAAI;YACb,aAAa,EAAE,YAAY,CAAC,aAAa;YACzC,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,UAAU;YAClD,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;YAChD,qBAAqB,EAAE;gBACrB,SAAS,EAAE,YAAY,CAAC,SAAS;gBACjC,MAAM,EAAE,YAAY,CAAC,MAAM;gBAC3B,aAAa,EAAE,YAAY,CAAC,aAAa;aAC1C;YACD,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI,IAAI,qDAAyB,EAAE;SAC9E,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,CACL,KAAiE,EACjE,OAA8D,EAC9D,sBAA8C,EAC9C,cAAkC;QAElC,4EAA4E;QAC5E,kCAAkC;QAClC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,sBAAsB,EAAE,cAAc,CAAC,CAAA;IAC9E,CAAC;IAEkB,qBAAqB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AEkB,kBAAkB,CACnC,KAA8B;QAE9B,OAAO,KAAK,CAAC,QAAQ,CAAA;IACvB,CAAC;CACF;AAvED,kDAuEC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CreateTopicCommandInput } from '@aws-sdk/client-sns';
|
|
2
|
+
import type { SNSTopicLocatorType } from '../sns/AbstractSnsService';
|
|
3
|
+
export type TopicResolutionOptions = CreateTopicCommandInput | SNSTopicLocatorType;
|
|
4
|
+
export declare function isCreateTopicCommand(value: unknown): value is CreateTopicCommandInput;
|
|
5
|
+
export declare function isSNSTopicLocatorType(value: unknown): value is SNSTopicLocatorType;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCreateTopicCommand = isCreateTopicCommand;
|
|
4
|
+
exports.isSNSTopicLocatorType = isSNSTopicLocatorType;
|
|
5
|
+
function isCreateTopicCommand(value) {
|
|
6
|
+
return !!value && !!value.Name;
|
|
7
|
+
}
|
|
8
|
+
function isSNSTopicLocatorType(value) {
|
|
9
|
+
return (!!value &&
|
|
10
|
+
(!!value.topicArn || !!value.topicName));
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=TopicTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TopicTypes.js","sourceRoot":"","sources":["../../../lib/types/TopicTypes.ts"],"names":[],"mappings":";;AAKA,oDAEC;AAED,sDAKC;AATD,SAAgB,oBAAoB,CAAC,KAAc;IACjD,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,CAAE,KAAiC,CAAC,IAAI,CAAA;AAC7D,CAAC;AAED,SAAgB,qBAAqB,CAAC,KAAc;IAClD,OAAO,CACL,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,CAAE,KAA6B,CAAC,QAAQ,IAAI,CAAC,CAAE,KAA6B,CAAC,SAAS,CAAC,CAC1F,CAAA;AACH,CAAC"}
|
|
@@ -2,17 +2,18 @@ import type { CreateTopicCommandInput, SNSClient } from '@aws-sdk/client-sns';
|
|
|
2
2
|
import type { CreateQueueCommandInput, SQSClient } from '@aws-sdk/client-sqs';
|
|
3
3
|
import type { DeletionConfig, ExtraParams } from '@message-queue-toolkit/core';
|
|
4
4
|
import type { SQSCreationConfig } from '@message-queue-toolkit/sqs';
|
|
5
|
-
import type { SNSCreationConfig,
|
|
5
|
+
import type { SNSCreationConfig, SNSTopicLocatorType } from '../sns/AbstractSnsService';
|
|
6
6
|
import type { SNSSQSQueueLocatorType } from '../sns/AbstractSnsSqsConsumer';
|
|
7
|
+
import type { STSClient } from '@aws-sdk/client-sts';
|
|
7
8
|
import type { SNSSubscriptionOptions } from './snsSubscriber';
|
|
8
|
-
export declare function initSnsSqs(sqsClient: SQSClient, snsClient: SNSClient, locatorConfig?: SNSSQSQueueLocatorType, creationConfig?: SNSCreationConfig & SQSCreationConfig, subscriptionConfig?: SNSSubscriptionOptions, extraParams?: ExtraParams): Promise<{
|
|
9
|
+
export declare function initSnsSqs(sqsClient: SQSClient, snsClient: SNSClient, stsClient: STSClient, locatorConfig?: SNSSQSQueueLocatorType, creationConfig?: SNSCreationConfig & SQSCreationConfig, subscriptionConfig?: SNSSubscriptionOptions, extraParams?: ExtraParams): Promise<{
|
|
9
10
|
subscriptionArn: string;
|
|
10
11
|
topicArn: string;
|
|
11
|
-
queueName: string;
|
|
12
12
|
queueUrl: string;
|
|
13
|
+
queueName: string;
|
|
13
14
|
}>;
|
|
14
|
-
export declare function deleteSnsSqs(sqsClient: SQSClient, snsClient: SNSClient, deletionConfig: DeletionConfig, queueConfiguration: CreateQueueCommandInput, topicConfiguration: CreateTopicCommandInput, subscriptionConfiguration: SNSSubscriptionOptions, extraParams?: ExtraParams): Promise<void>;
|
|
15
|
-
export declare function deleteSns(snsClient: SNSClient, deletionConfig: DeletionConfig, creationConfig: SNSCreationConfig): Promise<void>;
|
|
16
|
-
export declare function initSns(snsClient: SNSClient, locatorConfig?:
|
|
15
|
+
export declare function deleteSnsSqs(sqsClient: SQSClient, snsClient: SNSClient, stsClient: STSClient, deletionConfig: DeletionConfig, queueConfiguration: CreateQueueCommandInput, topicConfiguration: CreateTopicCommandInput | undefined, subscriptionConfiguration: SNSSubscriptionOptions, extraParams?: ExtraParams, topicLocator?: SNSTopicLocatorType): Promise<void>;
|
|
16
|
+
export declare function deleteSns(snsClient: SNSClient, stsClient: STSClient, deletionConfig: DeletionConfig, creationConfig: SNSCreationConfig): Promise<void>;
|
|
17
|
+
export declare function initSns(snsClient: SNSClient, stsClient: STSClient, locatorConfig?: SNSTopicLocatorType, creationConfig?: SNSCreationConfig): Promise<{
|
|
17
18
|
topicArn: string;
|
|
18
19
|
}>;
|
|
@@ -6,12 +6,14 @@ exports.deleteSns = deleteSns;
|
|
|
6
6
|
exports.initSns = initSns;
|
|
7
7
|
const core_1 = require("@message-queue-toolkit/core");
|
|
8
8
|
const sqs_1 = require("@message-queue-toolkit/sqs");
|
|
9
|
+
const TopicTypes_1 = require("../types/TopicTypes");
|
|
9
10
|
const snsSubscriber_1 = require("./snsSubscriber");
|
|
10
11
|
const snsUtils_1 = require("./snsUtils");
|
|
11
|
-
|
|
12
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
|
|
13
|
+
async function initSnsSqs(sqsClient, snsClient, stsClient, locatorConfig, creationConfig, subscriptionConfig, extraParams) {
|
|
12
14
|
if (!locatorConfig?.subscriptionArn) {
|
|
13
|
-
if (!creationConfig?.topic) {
|
|
14
|
-
throw new Error('If locatorConfig.subscriptionArn is not specified, creationConfig.topic
|
|
15
|
+
if (!creationConfig?.topic && !locatorConfig?.topicArn && !locatorConfig?.topicName) {
|
|
16
|
+
throw new Error('If locatorConfig.subscriptionArn is not specified, creationConfig.topic is mandatory in order to attempt to create missing topic and subscribe to it OR locatorConfig.name or locatorConfig.topicArn parameter is mandatory, to create subscription for existing topic.');
|
|
15
17
|
}
|
|
16
18
|
if (!creationConfig?.queue) {
|
|
17
19
|
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');
|
|
@@ -22,12 +24,17 @@ async function initSnsSqs(sqsClient, snsClient, locatorConfig, creationConfig, s
|
|
|
22
24
|
if (!subscriptionConfig) {
|
|
23
25
|
throw new Error('If locatorConfig.subscriptionArn is not specified, subscriptionConfig parameter is mandatory, as there will be an attempt to create the missing subscription');
|
|
24
26
|
}
|
|
25
|
-
const
|
|
27
|
+
const topicResolutionOptions = {
|
|
28
|
+
...locatorConfig,
|
|
29
|
+
...creationConfig.topic,
|
|
30
|
+
};
|
|
31
|
+
const { subscriptionArn, topicArn, queueUrl } = await (0, snsSubscriber_1.subscribeToTopic)(sqsClient, snsClient, stsClient, creationConfig.queue, topicResolutionOptions, subscriptionConfig, {
|
|
26
32
|
updateAttributesIfExists: creationConfig.updateAttributesIfExists,
|
|
27
33
|
queueUrlsWithSubscribePermissionsPrefix: creationConfig.queueUrlsWithSubscribePermissionsPrefix,
|
|
28
34
|
allowedSourceOwner: creationConfig.allowedSourceOwner,
|
|
29
35
|
topicArnsWithPublishPermissionsPrefix: creationConfig.topicArnsWithPublishPermissionsPrefix,
|
|
30
36
|
logger: extraParams?.logger,
|
|
37
|
+
forceTagUpdate: creationConfig.forceTagUpdate,
|
|
31
38
|
});
|
|
32
39
|
if (!subscriptionArn) {
|
|
33
40
|
throw new Error('Failed to subscribe');
|
|
@@ -39,72 +46,96 @@ async function initSnsSqs(sqsClient, snsClient, locatorConfig, creationConfig, s
|
|
|
39
46
|
queueUrl,
|
|
40
47
|
};
|
|
41
48
|
}
|
|
49
|
+
if (!locatorConfig.queueUrl) {
|
|
50
|
+
throw new Error('If locatorConfig.subscriptionArn is provided, you have to also provide locatorConfig.queueUrl');
|
|
51
|
+
}
|
|
52
|
+
const checkPromises = [];
|
|
42
53
|
// Check for existing resources, using the locators
|
|
43
|
-
const
|
|
44
|
-
const topicPromise = (0, snsUtils_1.getTopicAttributes)(snsClient,
|
|
45
|
-
|
|
46
|
-
if (
|
|
54
|
+
const subscriptionTopicArn = locatorConfig.topicArn ?? (await (0, snsUtils_1.getTopicArnByName)(snsClient, locatorConfig.topicName));
|
|
55
|
+
const topicPromise = (0, snsUtils_1.getTopicAttributes)(snsClient, subscriptionTopicArn);
|
|
56
|
+
checkPromises.push(topicPromise);
|
|
57
|
+
if (locatorConfig.queueUrl) {
|
|
58
|
+
const queuePromise = (0, sqs_1.getQueueAttributes)(sqsClient, locatorConfig.queueUrl);
|
|
59
|
+
checkPromises.push(queuePromise);
|
|
60
|
+
}
|
|
61
|
+
const [topicCheckResult, queueCheckResult] = await Promise.all(checkPromises);
|
|
62
|
+
if (queueCheckResult?.error === 'not_found') {
|
|
47
63
|
throw new Error(`Queue with queueUrl ${locatorConfig.queueUrl} does not exist.`);
|
|
48
64
|
}
|
|
49
65
|
if (topicCheckResult.error === 'not_found') {
|
|
50
66
|
throw new Error(`Topic with topicArn ${locatorConfig.topicArn} does not exist.`);
|
|
51
67
|
}
|
|
52
|
-
|
|
53
|
-
|
|
68
|
+
let queueName;
|
|
69
|
+
if (locatorConfig.queueUrl) {
|
|
70
|
+
const splitUrl = locatorConfig.queueUrl.split('/');
|
|
71
|
+
queueName = splitUrl[splitUrl.length - 1];
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
queueName = creationConfig.queue.QueueName;
|
|
75
|
+
}
|
|
54
76
|
return {
|
|
55
77
|
subscriptionArn: locatorConfig.subscriptionArn,
|
|
56
|
-
topicArn:
|
|
78
|
+
topicArn: subscriptionTopicArn,
|
|
57
79
|
queueUrl: locatorConfig.queueUrl,
|
|
58
80
|
queueName,
|
|
59
81
|
};
|
|
60
82
|
}
|
|
61
|
-
async function deleteSnsSqs(sqsClient, snsClient, deletionConfig, queueConfiguration, topicConfiguration, subscriptionConfiguration, extraParams) {
|
|
83
|
+
async function deleteSnsSqs(sqsClient, snsClient, stsClient, deletionConfig, queueConfiguration, topicConfiguration, subscriptionConfiguration, extraParams, topicLocator) {
|
|
62
84
|
if (!deletionConfig.deleteIfExists) {
|
|
63
85
|
return;
|
|
64
86
|
}
|
|
65
87
|
if ((0, core_1.isProduction)() && !deletionConfig.forceDeleteInProduction) {
|
|
66
88
|
throw new Error('You are running autodeletion in production. This can and probably will cause a loss of data. If you are absolutely sure you want to do this, please set deletionConfig.forceDeleteInProduction to true');
|
|
67
89
|
}
|
|
68
|
-
const { subscriptionArn } = await (0, snsSubscriber_1.subscribeToTopic)(sqsClient, snsClient, queueConfiguration, topicConfiguration, subscriptionConfiguration, extraParams);
|
|
90
|
+
const { subscriptionArn } = await (0, snsSubscriber_1.subscribeToTopic)(sqsClient, snsClient, stsClient, queueConfiguration, topicConfiguration ?? topicLocator, subscriptionConfiguration, extraParams);
|
|
69
91
|
if (!subscriptionArn) {
|
|
70
92
|
throw new Error('subscriptionArn must be set for automatic deletion');
|
|
71
93
|
}
|
|
72
94
|
await (0, sqs_1.deleteQueue)(sqsClient,
|
|
73
95
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
74
96
|
queueConfiguration.QueueName, deletionConfig.waitForConfirmation !== false);
|
|
75
|
-
|
|
76
|
-
|
|
97
|
+
if (topicConfiguration) {
|
|
98
|
+
const topicName = (0, TopicTypes_1.isCreateTopicCommand)(topicConfiguration)
|
|
99
|
+
? topicConfiguration.Name
|
|
100
|
+
: 'undefined';
|
|
101
|
+
if (!topicName) {
|
|
102
|
+
throw new Error('Failed to resolve topic name');
|
|
103
|
+
}
|
|
104
|
+
await (0, snsUtils_1.deleteTopic)(snsClient, stsClient, topicName);
|
|
105
|
+
}
|
|
77
106
|
await (0, snsUtils_1.deleteSubscription)(snsClient, subscriptionArn);
|
|
78
107
|
}
|
|
79
|
-
async function deleteSns(snsClient, deletionConfig, creationConfig) {
|
|
108
|
+
async function deleteSns(snsClient, stsClient, deletionConfig, creationConfig) {
|
|
80
109
|
if (!deletionConfig.deleteIfExists) {
|
|
81
110
|
return;
|
|
82
111
|
}
|
|
83
112
|
if ((0, core_1.isProduction)() && !deletionConfig.forceDeleteInProduction) {
|
|
84
113
|
throw new Error('You are running autodeletion in production. This can and probably will cause a loss of data. If you are absolutely sure you want to do this, please set deletionConfig.forceDeleteInProduction to true');
|
|
85
114
|
}
|
|
86
|
-
if (!creationConfig.topic
|
|
115
|
+
if (!creationConfig.topic?.Name) {
|
|
87
116
|
throw new Error('topic.Name must be set for automatic deletion');
|
|
88
117
|
}
|
|
89
|
-
await (0, snsUtils_1.deleteTopic)(snsClient, creationConfig.topic.Name);
|
|
118
|
+
await (0, snsUtils_1.deleteTopic)(snsClient, stsClient, creationConfig.topic.Name);
|
|
90
119
|
}
|
|
91
|
-
async function initSns(snsClient, locatorConfig, creationConfig) {
|
|
120
|
+
async function initSns(snsClient, stsClient, locatorConfig, creationConfig) {
|
|
92
121
|
if (locatorConfig) {
|
|
93
|
-
const
|
|
122
|
+
const topicArn = locatorConfig.topicArn ?? (await (0, snsUtils_1.getTopicArnByName)(snsClient, locatorConfig.topicName));
|
|
123
|
+
const checkResult = await (0, snsUtils_1.getTopicAttributes)(snsClient, topicArn);
|
|
94
124
|
if (checkResult.error === 'not_found') {
|
|
95
125
|
throw new Error(`Topic with topicArn ${locatorConfig.topicArn} does not exist.`);
|
|
96
126
|
}
|
|
97
127
|
return {
|
|
98
|
-
topicArn
|
|
128
|
+
topicArn,
|
|
99
129
|
};
|
|
100
130
|
}
|
|
101
131
|
// create new topic if it does not exist
|
|
102
132
|
if (!creationConfig) {
|
|
103
133
|
throw new Error('When locatorConfig for the topic is not specified, creationConfig of the topic is mandatory');
|
|
104
134
|
}
|
|
105
|
-
const topicArn = await (0, snsUtils_1.assertTopic)(snsClient, creationConfig.topic, {
|
|
135
|
+
const topicArn = await (0, snsUtils_1.assertTopic)(snsClient, stsClient, creationConfig.topic, {
|
|
106
136
|
queueUrlsWithSubscribePermissionsPrefix: creationConfig.queueUrlsWithSubscribePermissionsPrefix,
|
|
107
137
|
allowedSourceOwner: creationConfig.allowedSourceOwner,
|
|
138
|
+
forceTagUpdate: creationConfig.forceTagUpdate,
|
|
108
139
|
});
|
|
109
140
|
return {
|
|
110
141
|
topicArn,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snsInitter.js","sourceRoot":"","sources":["../../../lib/utils/snsInitter.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"snsInitter.js","sourceRoot":"","sources":["../../../lib/utils/snsInitter.ts"],"names":[],"mappings":";;AAwBA,gCA4GC;AAED,oCAoDC;AAED,8BAqBC;AAED,0BAiCC;AAjPD,sDAA0D;AAE1D,oDAA4E;AAO5E,oDAAuF;AAEvF,mDAAkD;AAClD,yCAMmB;AAEnB,6EAA6E;AACtE,KAAK,UAAU,UAAU,CAC9B,SAAoB,EACpB,SAAoB,EACpB,SAAoB,EACpB,aAAsC,EACtC,cAAsD,EACtD,kBAA2C,EAC3C,WAAyB;IAEzB,IAAI,CAAC,aAAa,EAAE,eAAe,EAAE,CAAC;QACpC,IAAI,CAAC,cAAc,EAAE,KAAK,IAAI,CAAC,aAAa,EAAE,QAAQ,IAAI,CAAC,aAAa,EAAE,SAAS,EAAE,CAAC;YACpF,MAAM,IAAI,KAAK,CACb,yQAAyQ,CAC1Q,CAAA;QACH,CAAC;QACD,IAAI,CAAC,cAAc,EAAE,KAAK,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CACb,yJAAyJ,CAC1J,CAAA;QACH,CAAC;QACD,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CACb,mKAAmK,CACpK,CAAA;QACH,CAAC;QACD,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CACb,8JAA8J,CAC/J,CAAA;QACH,CAAC;QAED,MAAM,sBAAsB,GAA2B;YACrD,GAAG,aAAa;YAChB,GAAG,cAAc,CAAC,KAAK;SACxB,CAAA;QAED,MAAM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,EAAC,SAAS,EAAE,SAAS,EAAE,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AACpE,CAAC;AAEM,KAAK,UAAU,OAAO,CAC3B,SAAoB,EACpB,SAAoB,EACpB,aAAmC,EACnC,cAAkC;IAElC,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,QAAQ,GACZ,aAAa,CAAC,QAAQ,IAAI,CAAC,MAAM,IAAA,4BAAiB,EAAC,SAAS,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC,CAAA;QACzF,MAAM,WAAW,GAAG,MAAM,IAAA,6BAAkB,EAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;QACjE,IAAI,WAAW,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,uBAAuB,aAAa,CAAC,QAAQ,kBAAkB,CAAC,CAAA;QAClF,CAAC;QAED,OAAO;YACL,QAAQ;SACT,CAAA;IACH,CAAC;IAED,wCAAwC;IACxC,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,6FAA6F,CAC9F,CAAA;IACH,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,IAAA,sBAAW,EAAC,SAAS,EAAE,SAAS,EAAE,cAAc,CAAC,KAAM,EAAE;QAC9E,uCAAuC,EAAE,cAAc,CAAC,uCAAuC;QAC/F,kBAAkB,EAAE,cAAc,CAAC,kBAAkB;QACrD,cAAc,EAAE,cAAc,CAAC,cAAc;KAC9C,CAAC,CAAA;IACF,OAAO;QACL,QAAQ;KACT,CAAA;AACH,CAAC"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SNSClient } from '@aws-sdk/client-sns';
|
|
2
2
|
import type { SubscribeCommandInput } from '@aws-sdk/client-sns/dist-types/commands/SubscribeCommand';
|
|
3
3
|
import type { CreateQueueCommandInput, SQSClient } from '@aws-sdk/client-sqs';
|
|
4
4
|
import type { ExtraParams } from '@message-queue-toolkit/core';
|
|
5
5
|
import type { ExtraSQSCreationParams } from '@message-queue-toolkit/sqs';
|
|
6
6
|
import type { ExtraSNSCreationParams } from '../sns/AbstractSnsService';
|
|
7
|
+
import type { STSClient } from '@aws-sdk/client-sts';
|
|
8
|
+
import { type TopicResolutionOptions } from '../types/TopicTypes';
|
|
7
9
|
export type SNSSubscriptionOptions = Omit<SubscribeCommandInput, 'TopicArn' | 'Endpoint' | 'Protocol' | 'ReturnSubscriptionArn'> & {
|
|
8
10
|
updateAttributesIfExists: boolean;
|
|
9
11
|
};
|
|
10
|
-
export declare function subscribeToTopic(sqsClient: SQSClient, snsClient: SNSClient, queueConfiguration: CreateQueueCommandInput, topicConfiguration:
|
|
12
|
+
export declare function subscribeToTopic(sqsClient: SQSClient, snsClient: SNSClient, stsClient: STSClient, queueConfiguration: CreateQueueCommandInput, topicConfiguration: TopicResolutionOptions, subscriptionConfiguration: SNSSubscriptionOptions, extraParams?: ExtraSNSCreationParams & ExtraSQSCreationParams & ExtraParams): Promise<{
|
|
11
13
|
subscriptionArn: string | undefined;
|
|
12
14
|
topicArn: string;
|
|
13
15
|
queueUrl: string;
|
|
@@ -3,15 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.subscribeToTopic = subscribeToTopic;
|
|
4
4
|
const client_sns_1 = require("@aws-sdk/client-sns");
|
|
5
5
|
const sqs_1 = require("@message-queue-toolkit/sqs");
|
|
6
|
+
const TopicTypes_1 = require("../types/TopicTypes");
|
|
6
7
|
const snsUtils_1 = require("./snsUtils");
|
|
7
|
-
async function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
8
|
+
async function resolveTopicArnToSubscribeTo(snsClient, stsClient, topicConfiguration, extraParams) {
|
|
9
|
+
//If topicArn is present, let's use it and return early.
|
|
10
|
+
if ((0, TopicTypes_1.isSNSTopicLocatorType)(topicConfiguration) && topicConfiguration.topicArn) {
|
|
11
|
+
return topicConfiguration.topicArn;
|
|
12
|
+
}
|
|
13
|
+
//If input configuration is capable of creating a topic, let's create it and return its ARN.
|
|
14
|
+
if ((0, TopicTypes_1.isCreateTopicCommand)(topicConfiguration)) {
|
|
15
|
+
return await (0, snsUtils_1.assertTopic)(snsClient, stsClient, topicConfiguration, {
|
|
16
|
+
queueUrlsWithSubscribePermissionsPrefix: extraParams?.queueUrlsWithSubscribePermissionsPrefix,
|
|
17
|
+
allowedSourceOwner: extraParams?.allowedSourceOwner,
|
|
18
|
+
forceTagUpdate: extraParams?.forceTagUpdate,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//Last option: let's not create a topic but resolve a ARN based on the desired topic name.
|
|
22
|
+
return await (0, snsUtils_1.getTopicArnByName)(snsClient, topicConfiguration.topicName);
|
|
23
|
+
}
|
|
24
|
+
async function subscribeToTopic(sqsClient, snsClient, stsClient, queueConfiguration, topicConfiguration, subscriptionConfiguration, extraParams) {
|
|
25
|
+
const topicArn = await resolveTopicArnToSubscribeTo(snsClient, stsClient, topicConfiguration, extraParams);
|
|
12
26
|
const { queueUrl, queueArn } = await (0, sqs_1.assertQueue)(sqsClient, queueConfiguration, {
|
|
13
27
|
topicArnsWithPublishPermissionsPrefix: extraParams?.topicArnsWithPublishPermissionsPrefix,
|
|
14
28
|
updateAttributesIfExists: extraParams?.updateAttributesIfExists,
|
|
29
|
+
forceTagUpdate: extraParams?.forceTagUpdate,
|
|
15
30
|
});
|
|
16
31
|
const subscribeCommand = new client_sns_1.SubscribeCommand({
|
|
17
32
|
TopicArn: topicArn,
|
|
@@ -32,7 +47,9 @@ async function subscribeToTopic(sqsClient, snsClient, queueConfiguration, topicC
|
|
|
32
47
|
catch (err) {
|
|
33
48
|
const logger = extraParams?.logger ?? console;
|
|
34
49
|
// @ts-ignore
|
|
35
|
-
logger.error(`Error while creating subscription for queue "${queueConfiguration.QueueName}", topic "${
|
|
50
|
+
logger.error(`Error while creating subscription for queue "${queueConfiguration.QueueName}", topic "${(0, TopicTypes_1.isCreateTopicCommand)(topicConfiguration)
|
|
51
|
+
? topicConfiguration.Name
|
|
52
|
+
: topicConfiguration.topicName}": ${err.message}`);
|
|
36
53
|
if (subscriptionConfiguration.updateAttributesIfExists &&
|
|
37
54
|
err.message.indexOf('Subscription already exists with different attributes') !== -1) {
|
|
38
55
|
const result = await tryToUpdateSubscription(snsClient, topicArn, queueArn, subscriptionConfiguration);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snsSubscriber.js","sourceRoot":"","sources":["../../../lib/utils/snsSubscriber.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"snsSubscriber.js","sourceRoot":"","sources":["../../../lib/utils/snsSubscriber.ts"],"names":[],"mappings":";;AA+CA,4CAyEC;AAvHD,oDAAwF;AAKxF,oDAAwD;AAKxD,oDAI4B;AAC5B,yCAA4F;AAO5F,KAAK,UAAU,4BAA4B,CACzC,SAAoB,EACpB,SAAoB,EACpB,kBAA0C,EAC1C,WAAwF;IAExF,wDAAwD;IACxD,IAAI,IAAA,kCAAqB,EAAC,kBAAkB,CAAC,IAAI,kBAAkB,CAAC,QAAQ,EAAE,CAAC;QAC7E,OAAO,kBAAkB,CAAC,QAAQ,CAAA;IACpC,CAAC;IAED,4FAA4F;IAC5F,IAAI,IAAA,iCAAoB,EAAC,kBAAkB,CAAC,EAAE,CAAC;QAC7C,OAAO,MAAM,IAAA,sBAAW,EAAC,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE;YACjE,uCAAuC,EAAE,WAAW,EAAE,uCAAuC;YAC7F,kBAAkB,EAAE,WAAW,EAAE,kBAAkB;YACnD,cAAc,EAAE,WAAW,EAAE,cAAc;SAC5C,CAAC,CAAA;IACJ,CAAC;IAED,0FAA0F;IAC1F,OAAO,MAAM,IAAA,4BAAiB,EAAC,SAAS,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAA;AACzE,CAAC;AAEM,KAAK,UAAU,gBAAgB,CACpC,SAAoB,EACpB,SAAoB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ient } from '@aws-sdk/client-sns';
|
|
2
|
+
import { type Either } from '@lokalise/node-core';
|
|
3
3
|
import type { ExtraSNSCreationParams } from '../sns/AbstractSnsService';
|
|
4
|
+
import type { STSClient } from '@aws-sdk/client-sts';
|
|
4
5
|
type AttributesResult = {
|
|
5
6
|
attributes?: Record<string, string>;
|
|
6
7
|
};
|
|
7
8
|
export declare function getTopicAttributes(snsClient: SNSClient, topicArn: string): Promise<Either<'not_found', AttributesResult>>;
|
|
8
9
|
export declare function getSubscriptionAttributes(snsClient: SNSClient, subscriptionArn: string): Promise<Either<'not_found', AttributesResult>>;
|
|
9
|
-
export declare function assertTopic(snsClient: SNSClient, topicOptions: CreateTopicCommandInput, extraParams?: ExtraSNSCreationParams): Promise<string>;
|
|
10
|
-
export declare function deleteTopic(
|
|
10
|
+
export declare function assertTopic(snsClient: SNSClient, stsClient: STSClient, topicOptions: CreateTopicCommandInput, extraParams?: ExtraSNSCreationParams): Promise<string>;
|
|
11
|
+
export declare function deleteTopic(snsClient: SNSClient, stsClient: STSClient, topicName: string): Promise<void>;
|
|
11
12
|
export declare function deleteSubscription(client: SNSClient, subscriptionArn: string): Promise<void>;
|
|
12
13
|
export declare function findSubscriptionByTopicAndQueue(snsClient: SNSClient, topicArn: string, queueArn: string): Promise<import("@aws-sdk/client-sns").Subscription | undefined>;
|
|
14
|
+
export declare function getTopicArnByName(snsClient: SNSClient, topicName?: string): Promise<string>;
|
|
13
15
|
/**
|
|
14
16
|
* Calculates the size of an outgoing SNS message.
|
|
15
17
|
*
|
|
@@ -7,11 +7,15 @@ exports.assertTopic = assertTopic;
|
|
|
7
7
|
exports.deleteTopic = deleteTopic;
|
|
8
8
|
exports.deleteSubscription = deleteSubscription;
|
|
9
9
|
exports.findSubscriptionByTopicAndQueue = findSubscriptionByTopicAndQueue;
|
|
10
|
+
exports.getTopicArnByName = getTopicArnByName;
|
|
10
11
|
const client_sns_1 = require("@aws-sdk/client-sns");
|
|
12
|
+
const client_sns_2 = require("@aws-sdk/client-sns");
|
|
13
|
+
const node_core_1 = require("@lokalise/node-core");
|
|
11
14
|
const sqs_1 = require("@message-queue-toolkit/sqs");
|
|
12
15
|
const snsAttributeUtils_1 = require("./snsAttributeUtils");
|
|
16
|
+
const stsUtils_1 = require("./stsUtils");
|
|
13
17
|
async function getTopicAttributes(snsClient, topicArn) {
|
|
14
|
-
const command = new
|
|
18
|
+
const command = new client_sns_2.GetTopicAttributesCommand({
|
|
15
19
|
TopicArn: topicArn,
|
|
16
20
|
});
|
|
17
21
|
try {
|
|
@@ -34,7 +38,7 @@ async function getTopicAttributes(snsClient, topicArn) {
|
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
40
|
async function getSubscriptionAttributes(snsClient, subscriptionArn) {
|
|
37
|
-
const command = new
|
|
41
|
+
const command = new client_sns_2.GetSubscriptionAttributesCommand({
|
|
38
42
|
SubscriptionArn: subscriptionArn,
|
|
39
43
|
});
|
|
40
44
|
try {
|
|
@@ -56,15 +60,26 @@ async function getSubscriptionAttributes(snsClient, subscriptionArn) {
|
|
|
56
60
|
throw err;
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
|
-
async function assertTopic(snsClient, topicOptions, extraParams) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
async function assertTopic(snsClient, stsClient, topicOptions, extraParams) {
|
|
64
|
+
let topicArn;
|
|
65
|
+
try {
|
|
66
|
+
const command = new client_sns_2.CreateTopicCommand(topicOptions);
|
|
67
|
+
const response = await snsClient.send(command);
|
|
68
|
+
if (!response.TopicArn)
|
|
69
|
+
throw new Error('No topic arn in response');
|
|
70
|
+
topicArn = response.TopicArn;
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
// We only manually build ARN in case of tag update
|
|
74
|
+
if (!extraParams?.forceTagUpdate)
|
|
75
|
+
throw err;
|
|
76
|
+
// To build ARN we need topic name and error should be "topic already exist with different tags"
|
|
77
|
+
if (!topicOptions.Name || !isTopicAlreadyExistWithDifferentTagsError(err))
|
|
78
|
+
throw err;
|
|
79
|
+
topicArn = await (0, stsUtils_1.buildTopicArn)(stsClient, topicOptions.Name);
|
|
64
80
|
}
|
|
65
|
-
const topicArn = response.TopicArn;
|
|
66
81
|
if (extraParams?.queueUrlsWithSubscribePermissionsPrefix || extraParams?.allowedSourceOwner) {
|
|
67
|
-
const setTopicAttributesCommand = new
|
|
82
|
+
const setTopicAttributesCommand = new client_sns_2.SetTopicAttributesCommand({
|
|
68
83
|
TopicArn: topicArn,
|
|
69
84
|
AttributeName: 'Policy',
|
|
70
85
|
AttributeValue: (0, snsAttributeUtils_1.generateTopicSubscriptionPolicy)({
|
|
@@ -75,24 +90,30 @@ async function assertTopic(snsClient, topicOptions, extraParams) {
|
|
|
75
90
|
});
|
|
76
91
|
await snsClient.send(setTopicAttributesCommand);
|
|
77
92
|
}
|
|
93
|
+
if (extraParams?.forceTagUpdate && topicOptions.Tags) {
|
|
94
|
+
const tagTopicCommand = new client_sns_1.TagResourceCommand({
|
|
95
|
+
ResourceArn: topicArn,
|
|
96
|
+
Tags: topicOptions.Tags,
|
|
97
|
+
});
|
|
98
|
+
await snsClient.send(tagTopicCommand);
|
|
99
|
+
}
|
|
78
100
|
return topicArn;
|
|
79
101
|
}
|
|
80
|
-
async function deleteTopic(
|
|
102
|
+
async function deleteTopic(snsClient, stsClient, topicName) {
|
|
81
103
|
try {
|
|
82
|
-
const topicArn = await assertTopic(
|
|
104
|
+
const topicArn = await assertTopic(snsClient, stsClient, {
|
|
83
105
|
Name: topicName,
|
|
84
106
|
});
|
|
85
|
-
|
|
107
|
+
await snsClient.send(new client_sns_2.DeleteTopicCommand({
|
|
86
108
|
TopicArn: topicArn,
|
|
87
|
-
});
|
|
88
|
-
await client.send(command);
|
|
109
|
+
}));
|
|
89
110
|
}
|
|
90
111
|
catch (_) {
|
|
91
112
|
// we don't care it operation has failed
|
|
92
113
|
}
|
|
93
114
|
}
|
|
94
115
|
async function deleteSubscription(client, subscriptionArn) {
|
|
95
|
-
const command = new
|
|
116
|
+
const command = new client_sns_2.UnsubscribeCommand({
|
|
96
117
|
SubscriptionArn: subscriptionArn,
|
|
97
118
|
});
|
|
98
119
|
try {
|
|
@@ -103,7 +124,7 @@ async function deleteSubscription(client, subscriptionArn) {
|
|
|
103
124
|
}
|
|
104
125
|
}
|
|
105
126
|
async function findSubscriptionByTopicAndQueue(snsClient, topicArn, queueArn) {
|
|
106
|
-
const listSubscriptionsCommand = new
|
|
127
|
+
const listSubscriptionsCommand = new client_sns_2.ListSubscriptionsByTopicCommand({
|
|
107
128
|
TopicArn: topicArn,
|
|
108
129
|
});
|
|
109
130
|
const listSubscriptionResult = await snsClient.send(listSubscriptionsCommand);
|
|
@@ -111,6 +132,21 @@ async function findSubscriptionByTopicAndQueue(snsClient, topicArn, queueArn) {
|
|
|
111
132
|
return entry.Endpoint === queueArn;
|
|
112
133
|
});
|
|
113
134
|
}
|
|
135
|
+
async function getTopicArnByName(snsClient, topicName) {
|
|
136
|
+
if (!topicName) {
|
|
137
|
+
throw new Error('topicName is not provided');
|
|
138
|
+
}
|
|
139
|
+
// Use paginator to automatically handle NextToken
|
|
140
|
+
const paginator = (0, client_sns_1.paginateListTopics)({ client: snsClient }, {});
|
|
141
|
+
for await (const page of paginator) {
|
|
142
|
+
for (const topic of page.Topics || []) {
|
|
143
|
+
if (topic.TopicArn?.includes(topicName)) {
|
|
144
|
+
return topic.TopicArn;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
throw new Error(`Failed to resolve topic by name ${topicName}`);
|
|
149
|
+
}
|
|
114
150
|
/**
|
|
115
151
|
* Calculates the size of an outgoing SNS message.
|
|
116
152
|
*
|
|
@@ -124,4 +160,14 @@ async function findSubscriptionByTopicAndQueue(snsClient, topicArn, queueArn) {
|
|
|
124
160
|
*/
|
|
125
161
|
const calculateOutgoingMessageSize = (message) => (0, sqs_1.calculateOutgoingMessageSize)(message);
|
|
126
162
|
exports.calculateOutgoingMessageSize = calculateOutgoingMessageSize;
|
|
163
|
+
const isTopicAlreadyExistWithDifferentTagsError = (error) => !!error &&
|
|
164
|
+
(0, node_core_1.isError)(error) &&
|
|
165
|
+
'Error' in error &&
|
|
166
|
+
!!error.Error &&
|
|
167
|
+
typeof error.Error === 'object' &&
|
|
168
|
+
'Code' in error.Error &&
|
|
169
|
+
'Message' in error.Error &&
|
|
170
|
+
typeof error.Error.Message === 'string' &&
|
|
171
|
+
error.Error.Code === 'InvalidParameter' &&
|
|
172
|
+
error.Error.Message.includes('already exists with different tags');
|
|
127
173
|
//# sourceMappingURL=snsUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snsUtils.js","sourceRoot":"","sources":["../../../lib/utils/snsUtils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"snsUtils.js","sourceRoot":"","sources":["../../../lib/utils/snsUtils.ts"],"names":[],"mappings":";;;AA4BA,gDAyBC;AAED,8DAyBC;AAED,kCAyCC;AAED,kCAcC;AAED,gDASC;AAED,0EAaC;AAED,8CAeC;AAtLD,oDAK4B;AAC5B,oDAQ4B;AAC5B,mDAA0D;AAC1D,oDAA4G;AAK5G,2DAAqE;AACrE,yCAA0C;AAMnC,KAAK,UAAU,kBAAkB,CACtC,SAAoB,EACpB,QAAgB;IAEhB,MAAM,OAAO,GAAG,IAAI,sCAAyB,CAAC;QAC5C,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAA;IAEF,IAAI,CAAC;QACH,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;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,aAAa;QACb,IAAI,GAAG,CAAC,IAAI,KAAK,yCAAyC,EAAE,CAAC;YAC3D,OAAO;gBACL,aAAa;gBACb,KA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,EAAE,CAAC,CAAA;AACjE,CAAC;AAED;;;;;;;;;;GAUG;AACI,MAAM,4BAA4B,GAAG,CAAC,OAAgB,EAAE,EAAE,CAC/D,IAAA,kCAA+B,EAAC,OAAO,CAAC,CAAA;AAD7B,QAAA,4BAA4B,gCACC;AAE1C,MAAM,yCAAyC,GAAG,CAAC,KAAc,EAAE,EAAE,CACnE,CAAC,CAAC,KAAK;IACP,IAAA,mBAAO,EAAC,KAAK,CAAC;IACd,OAAO,IAAI,KAAK;IAChB,CAAC,CAAC,KAAK,CAAC,KAAK;IACb,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;IAC/B,MAAM,IAAI,KAAK,CAAC,KAAK;IACrB,SAAS,IAAI,KAAK,CAAC,KAAK;IACxB,OAAO,KAAK,CAAC,KAAK,CAAC,OAAO,KAAK,QAAQ;IACvC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,kBAAkB;IACvC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,oCAAoC,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type STSClient } from '@aws-sdk/client-sts';
|
|
2
|
+
/**
|
|
3
|
+
* Manually builds the ARN of a topic based on the current AWS account and the topic name.
|
|
4
|
+
* It follows the following pattern: arn:aws:sns:<region>:<account-id>:<topic-name>
|
|
5
|
+
* Doc -> https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
|
|
6
|
+
*/
|
|
7
|
+
export declare const buildTopicArn: (client: STSClient, topicName: string) => Promise<string>;
|
|
8
|
+
export declare const clearCachedCallerIdentity: () => void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clearCachedCallerIdentity = exports.buildTopicArn = void 0;
|
|
4
|
+
const client_sts_1 = require("@aws-sdk/client-sts");
|
|
5
|
+
let callerIdentityPromise;
|
|
6
|
+
let callerIdentityCached;
|
|
7
|
+
/**
|
|
8
|
+
* Manually builds the ARN of a topic based on the current AWS account and the topic name.
|
|
9
|
+
* It follows the following pattern: arn:aws:sns:<region>:<account-id>:<topic-name>
|
|
10
|
+
* Doc -> https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
|
|
11
|
+
*/
|
|
12
|
+
const buildTopicArn = async (client, topicName) => {
|
|
13
|
+
const identityResponse = await getAndCacheCallerIdentity(client);
|
|
14
|
+
const region = typeof client.config.region === 'string' ? client.config.region : await client.config.region();
|
|
15
|
+
return `arn:aws:sns:${region}:${identityResponse.Account}:${topicName}`;
|
|
16
|
+
};
|
|
17
|
+
exports.buildTopicArn = buildTopicArn;
|
|
18
|
+
const clearCachedCallerIdentity = () => {
|
|
19
|
+
callerIdentityPromise = undefined;
|
|
20
|
+
callerIdentityCached = undefined;
|
|
21
|
+
};
|
|
22
|
+
exports.clearCachedCallerIdentity = clearCachedCallerIdentity;
|
|
23
|
+
const getAndCacheCallerIdentity = async (client) => {
|
|
24
|
+
if (!callerIdentityCached) {
|
|
25
|
+
if (!callerIdentityPromise) {
|
|
26
|
+
callerIdentityPromise = client.send(new client_sts_1.GetCallerIdentityCommand({})).then((response) => {
|
|
27
|
+
callerIdentityCached = response;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
await callerIdentityPromise;
|
|
31
|
+
callerIdentityPromise = undefined;
|
|
32
|
+
}
|
|
33
|
+
return callerIdentityCached;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=stsUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stsUtils.js","sourceRoot":"","sources":["../../../lib/utils/stsUtils.ts"],"names":[],"mappings":";;;AAAA,oDAI4B;AAE5B,IAAI,qBAAgD,CAAA;AACpD,IAAI,oBAAgE,CAAA;AAEpE;;;;GAIG;AACI,MAAM,aAAa,GAAG,KAAK,EAAE,MAAiB,EAAE,SAAiB,EAAE,EAAE;IAC1E,MAAM,gBAAgB,GAAG,MAAM,yBAAyB,CAAC,MAAM,CAAC,CAAA;IAChE,MAAM,MAAM,GACV,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAA;IAEhG,OAAO,eAAe,MAAM,IAAI,gBAAgB,CAAC,OAAO,IAAI,SAAS,EAAE,CAAA;AACzE,CAAC,CAAA;AANY,QAAA,aAAa,iBAMzB;AAEM,MAAM,yBAAyB,GAAG,GAAG,EAAE;IAC5C,qBAAqB,GAAG,SAAS,CAAA;IACjC,oBAAoB,GAAG,SAAS,CAAA;AAClC,CAAC,CAAA;AAHY,QAAA,yBAAyB,6BAGrC;AAED,MAAM,yBAAyB,GAAG,KAAK,EACrC,MAAiB,EACwB,EAAE;IAC3C,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC3B,qBAAqB,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,qCAAwB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACtF,oBAAoB,GAAG,QAAQ,CAAA;YACjC,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,MAAM,qBAAqB,CAAA;QAC3B,qBAAqB,GAAG,SAAS,CAAA;IACnC,CAAC;IAED,OAAO,oBAAqB,CAAA;AAC9B,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@message-queue-toolkit/sns",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "18.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "SNS adapter for message-queue-toolkit",
|
|
@@ -25,33 +25,34 @@
|
|
|
25
25
|
"prepublishOnly": "npm run build:release"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@lokalise/node-core": "^
|
|
29
|
-
"sqs-consumer": "^11.0
|
|
28
|
+
"@lokalise/node-core": "^13.0.1",
|
|
29
|
+
"sqs-consumer": "^11.1.0",
|
|
30
30
|
"zod": "^3.23.8"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@aws-sdk/client-sns": "^3.
|
|
34
|
-
"@aws-sdk/client-sqs": "^3.
|
|
33
|
+
"@aws-sdk/client-sns": "^3.632.0",
|
|
34
|
+
"@aws-sdk/client-sqs": "^3.632.0",
|
|
35
|
+
"@aws-sdk/client-sts": "^3.632.0",
|
|
35
36
|
"@message-queue-toolkit/core": ">=15.0.0",
|
|
36
37
|
"@message-queue-toolkit/schemas": ">=2.0.0",
|
|
37
38
|
"@message-queue-toolkit/sqs": "^17.0.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@aws-sdk/client-s3": "^3.
|
|
41
|
-
"@aws-sdk/client-sns": "^3.
|
|
42
|
-
"@aws-sdk/client-sqs": "^3.
|
|
41
|
+
"@aws-sdk/client-s3": "^3.670.0",
|
|
42
|
+
"@aws-sdk/client-sns": "^3.670.0",
|
|
43
|
+
"@aws-sdk/client-sqs": "^3.670.0",
|
|
44
|
+
"@biomejs/biome": "1.9.3",
|
|
45
|
+
"@kibertoad/biome-config": "^1.2.1",
|
|
43
46
|
"@message-queue-toolkit/core": "*",
|
|
44
47
|
"@message-queue-toolkit/s3-payload-store": "*",
|
|
45
48
|
"@message-queue-toolkit/sqs": "*",
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"
|
|
49
|
-
"@vitest/coverage-v8": "^2.0.4",
|
|
50
|
-
"awilix": "^11.0.0",
|
|
49
|
+
"@types/node": "^22.7.5",
|
|
50
|
+
"@vitest/coverage-v8": "^2.1.2",
|
|
51
|
+
"awilix": "^12.0.1",
|
|
51
52
|
"awilix-manager": "^5.1.0",
|
|
52
|
-
"del-cli": "^
|
|
53
|
-
"typescript": "^5.
|
|
54
|
-
"vitest": "^2.
|
|
53
|
+
"del-cli": "^6.0.0",
|
|
54
|
+
"typescript": "^5.6.3",
|
|
55
|
+
"vitest": "^2.1.2"
|
|
55
56
|
},
|
|
56
57
|
"homepage": "https://github.com/kibertoad/message-queue-toolkit",
|
|
57
58
|
"repository": {
|