@@ -2,6 +2,7 @@ import type { SNSClient, SubscribeCommandInput } from '@aws-sdk/client-sns'
22import { SetSubscriptionAttributesCommand , SubscribeCommand } from '@aws-sdk/client-sns'
33import type { CreateQueueCommandInput , SQSClient } from '@aws-sdk/client-sqs'
44import type { STSClient } from '@aws-sdk/client-sts'
5+ import { InternalError , stringValueSerializer } from '@lokalise/node-core'
56import type { ExtraParams } from '@message-queue-toolkit/core'
67import type { ExtraSQSCreationParams } from '@message-queue-toolkit/sqs'
78import { assertQueue } from '@message-queue-toolkit/sqs'
@@ -11,7 +12,8 @@ import {
1112 isSNSTopicLocatorType ,
1213 type TopicResolutionOptions ,
1314} 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'
1517
1618export type SNSSubscriptionOptions = Omit <
1719 SubscribeCommandInput ,
@@ -24,12 +26,11 @@ async function resolveTopicArnToSubscribeTo(
2426 topicConfiguration : TopicResolutionOptions ,
2527 extraParams : ( ExtraSNSCreationParams & ExtraSQSCreationParams & ExtraParams ) | undefined ,
2628) {
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 )
3032 }
3133
32- //If input configuration is capable of creating a topic, let's create it and return its ARN.
3334 if ( isCreateTopicCommand ( topicConfiguration ) ) {
3435 return await assertTopic ( snsClient , stsClient , topicConfiguration , {
3536 queueUrlsWithSubscribePermissionsPrefix : extraParams ?. queueUrlsWithSubscribePermissionsPrefix ,
@@ -38,8 +39,11 @@ async function resolveTopicArnToSubscribeTo(
3839 } )
3940 }
4041
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+ } )
4347}
4448
4549export async function subscribeToTopic (
0 commit comments