@@ -2,6 +2,7 @@ import type { SNSClient, SubscribeCommandInput } from '@aws-sdk/client-sns'
2
2
import { SetSubscriptionAttributesCommand , SubscribeCommand } from '@aws-sdk/client-sns'
3
3
import type { CreateQueueCommandInput , SQSClient } from '@aws-sdk/client-sqs'
4
4
import type { STSClient } from '@aws-sdk/client-sts'
5
+ import { InternalError , stringValueSerializer } from '@lokalise/node-core'
5
6
import type { ExtraParams } from '@message-queue-toolkit/core'
6
7
import type { ExtraSQSCreationParams } from '@message-queue-toolkit/sqs'
7
8
import { assertQueue } from '@message-queue-toolkit/sqs'
@@ -11,7 +12,8 @@ import {
11
12
isSNSTopicLocatorType ,
12
13
type TopicResolutionOptions ,
13
14
} from '../types/TopicTypes.ts'
14
- import { assertTopic , findSubscriptionByTopicAndQueue , getTopicArnByName } from './snsUtils.ts'
15
+ import { assertTopic , findSubscriptionByTopicAndQueue } from './snsUtils.ts'
16
+ import { buildTopicArn } from './stsUtils.js'
15
17
16
18
export type SNSSubscriptionOptions = Omit <
17
19
SubscribeCommandInput ,
@@ -24,12 +26,11 @@ async function resolveTopicArnToSubscribeTo(
24
26
topicConfiguration : TopicResolutionOptions ,
25
27
extraParams : ( ExtraSNSCreationParams & ExtraSQSCreationParams & ExtraParams ) | undefined ,
26
28
) {
27
- //If topicArn is present, let's use it and return early.
28
- if ( isSNSTopicLocatorType ( topicConfiguration ) && topicConfiguration . topicArn ) {
29
- return topicConfiguration . topicArn
29
+ if ( isSNSTopicLocatorType ( topicConfiguration ) ) {
30
+ if ( topicConfiguration . topicArn ) return topicConfiguration . topicArn
31
+ if ( topicConfiguration . topicName ) return buildTopicArn ( stsClient , topicConfiguration . topicName )
30
32
}
31
33
32
- //If input configuration is capable of creating a topic, let's create it and return its ARN.
33
34
if ( isCreateTopicCommand ( topicConfiguration ) ) {
34
35
return await assertTopic ( snsClient , stsClient , topicConfiguration , {
35
36
queueUrlsWithSubscribePermissionsPrefix : extraParams ?. queueUrlsWithSubscribePermissionsPrefix ,
@@ -38,8 +39,11 @@ async function resolveTopicArnToSubscribeTo(
38
39
} )
39
40
}
40
41
41
- //Last option: let's not create a topic but resolve a ARN based on the desired topic name.
42
- return await getTopicArnByName ( snsClient , topicConfiguration . topicName )
42
+ throw new InternalError ( {
43
+ errorCode : 'invalid_topic_configuration' ,
44
+ message : 'Invalid topic configuration provided, cannot resolve topic ARN' ,
45
+ details : { topicConfiguration : stringValueSerializer ( topicConfiguration ) } ,
46
+ } )
43
47
}
44
48
45
49
export async function subscribeToTopic (
0 commit comments