Skip to content

Commit

Permalink
Export snsUtils (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad committed Jul 18, 2023
1 parent 9135bd4 commit 0b96b71
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
2 changes: 2 additions & 0 deletions packages/sns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export type { SNSMessageOptions } from './lib/sns/AbstractSnsPublisher'
export type { CommonMessage } from './lib/types/MessageTypes'

export { deserializeSNSMessage } from './lib/sns/snsMessageDeserializer'

export { assertTopic, deleteTopic, getTopicAttributes } from './lib/utils/snsUtils'
22 changes: 21 additions & 1 deletion packages/sns/lib/utils/snsUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { CreateTopicCommandInput, SNSClient } from '@aws-sdk/client-sns'
import { CreateTopicCommand, GetTopicAttributesCommand } from '@aws-sdk/client-sns'
import {
CreateTopicCommand,
DeleteTopicCommand,
GetTopicAttributesCommand,
} from '@aws-sdk/client-sns'
import type { Either } from '@lokalise/node-core'

type QueueAttributesResult = {
Expand Down Expand Up @@ -42,3 +46,19 @@ export async function assertTopic(snsClient: SNSClient, topicOptions: CreateTopi
}
return response.TopicArn
}

export async function deleteTopic(client: SNSClient, topicName: string) {
try {
const topicArn = await assertTopic(client, {
Name: topicName,
})

const command = new DeleteTopicCommand({
TopicArn: topicArn,
})

await client.send(command)
} catch (err) {
// we don't care it operation has failed
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import type { AwilixContainer } from 'awilix'
import { asClass } from 'awilix'
import { describe, beforeEach, afterEach, expect, it, afterAll, beforeAll } from 'vitest'

import { assertTopic } from '../../lib/utils/snsUtils'
import { assertTopic, deleteTopic } from '../../lib/utils/snsUtils'
import { FakeConsumerErrorResolver } from '../fakes/FakeConsumerErrorResolver'
import type { SnsPermissionPublisher } from '../publishers/SnsPermissionPublisher'
import { userPermissionMap } from '../repositories/PermissionRepository'
import { deleteTopic } from '../utils/snsUtils'
import { registerDependencies, SINGLETON_CONFIG } from '../utils/testContext'
import type { Dependencies } from '../utils/testContext'

Expand Down
3 changes: 1 addition & 2 deletions packages/sns/test/publishers/SnsPermissionPublisher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import { describe, beforeEach, afterEach, expect, it, afterAll, beforeAll } from

import { subscribeToTopic } from '../../lib/sns/SnsSubscriber'
import { deserializeSNSMessage } from '../../lib/sns/snsMessageDeserializer'
import { assertTopic } from '../../lib/utils/snsUtils'
import { assertTopic, deleteTopic } from '../../lib/utils/snsUtils'
import { SnsSqsPermissionConsumer } from '../consumers/SnsSqsPermissionConsumer'
import type { PERMISSIONS_MESSAGE_TYPE } from '../consumers/userConsumerSchemas'
import { PERMISSIONS_MESSAGE_SCHEMA } from '../consumers/userConsumerSchemas'
import { FakeConsumerErrorResolver } from '../fakes/FakeConsumerErrorResolver'
import { userPermissionMap } from '../repositories/PermissionRepository'
import { deleteTopic } from '../utils/snsUtils'
import { registerDependencies, SINGLETON_CONFIG } from '../utils/testContext'
import type { Dependencies } from '../utils/testContext'

Expand Down
21 changes: 0 additions & 21 deletions packages/sns/test/utils/snsUtils.ts

This file was deleted.

0 comments on commit 0b96b71

Please sign in to comment.