UNPKG

@message-queue-toolkit/sns

Version:
47 lines (46 loc) 3.18 kB
import type { SNSClient } from '@aws-sdk/client-sns'; import type { STSClient } from '@aws-sdk/client-sts'; import type { SQSConsumerDependencies, SQSConsumerOptions, SQSCreationConfig, SQSMessage, SQSQueueLocatorType } from '@message-queue-toolkit/sqs'; import { AbstractSqsConsumer } from '@message-queue-toolkit/sqs'; import type { SNSSubscriptionOptions } from '../utils/snsSubscriber.ts'; import type { SNSCreationConfig, SNSOptions, SNSTopicLocatorType } from './AbstractSnsService.ts'; export type SNSSQSConsumerDependencies = SQSConsumerDependencies & { snsClient: SNSClient; stsClient: STSClient; }; export type SNSSQSCreationConfig = Omit<SQSCreationConfig, 'policyConfig'> & SNSCreationConfig; export type SNSSQSQueueLocatorType = Partial<SQSQueueLocatorType> & SNSTopicLocatorType & { subscriptionArn?: string; }; export type SNSSQSConsumerOptions<MessagePayloadType extends object, ExecutionContext, PrehandlerOutput> = SQSConsumerOptions<MessagePayloadType, ExecutionContext, PrehandlerOutput, SNSSQSCreationConfig, SNSSQSQueueLocatorType> & SNSOptions & { subscriptionConfig?: SNSSubscriptionOptions; }; export declare abstract class AbstractSnsSqsConsumer<MessagePayloadSchemas extends object, ExecutionContext, PrehandlerOutput = undefined> extends AbstractSqsConsumer<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput, SNSSQSCreationConfig, SNSSQSQueueLocatorType, SNSSQSConsumerOptions<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>> { private readonly subscriptionConfig?; private readonly snsClient; private readonly stsClient; /** * Tracks whether resources (SNS topic, SQS queue, subscription) are ready. * In non-blocking polling mode, this may be false initially and become true * when the onResourcesReady callback fires. */ private resourcesReady; /** * Tracks whether start() has been called but consumers couldn't be started * because resources weren't ready yet. When resources become ready and this * is true, consumers will be started automatically. */ private startRequested; protected topicArn: string; protected subscriptionArn: string; protected constructor(dependencies: SNSSQSConsumerDependencies, options: SNSSQSConsumerOptions<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>, executionContext: ExecutionContext); init(): Promise<void>; /** * Starts the consumer. In non-blocking polling mode, if resources aren't ready yet, * this method will return immediately and consumers will start automatically once * resources become available. */ start(): Promise<void>; protected resolveMessage(message: SQSMessage): import("@lokalise/node-core").Either<import("@message-queue-toolkit/core").MessageInvalidFormatError | import("@message-queue-toolkit/core").MessageValidationError, import("@message-queue-toolkit/core").ResolvedMessage>; protected resolveSchema(messagePayload: MessagePayloadSchemas): import("@lokalise/node-core").Either<Error, import("zod/v4").ZodType<MessagePayloadSchemas, unknown, import("zod/v4/core").$ZodTypeInternals<MessagePayloadSchemas, unknown>>>; }