UNPKG

@mbc-cqrs-serverless/core

Version:
45 lines (44 loc) 1.87 kB
import { ConfigService } from '@nestjs/config'; import { INotification } from '../interfaces'; import { INotificationTransport } from './interfaces'; export declare class AppSyncEventsService implements INotificationTransport { private readonly config; private readonly logger; private readonly url; private readonly namespace; private readonly signer; constructor(config: ConfigService); /** * Publish INotification to an AppSync Events channel via IAM SigV4. * * Channel structure (max 5 segments, seg 1 = namespace): * /{namespace}/{tenantCode}/{action}/{sanitizedId} * * Client subscription options (wildcard /* catches all sub-channels): * /{namespace}/{tenantCode}/* — all events for tenant * /{namespace}/{tenantCode}/{action}/* — filtered by action * /{namespace}/{tenantCode}/{action}/{id} — specific command * * Requires: Lambda execution role must have appsync:EventPublish permission. */ sendMessage(notification: INotification): Promise<void>; /** * Resolves the most specific channel path for a notification. * Non-alphanumeric characters (e.g. #, @) are sanitized to dashes * since AppSync Events channel segments only allow [a-zA-Z0-9-]. */ resolveChannel(notification: INotification): string; /** * Formats a string to comply with AppSync Events API channel segment rules: * 1. Only alphanumeric characters and dashes. * 2. Cannot start or end with a dash. * 3. Maximum length of 50 characters. */ private sanitizeSegment; private postToChannel; /** * Builds and signs an HttpRequest for the given channel and notification. * Separating signing from the fetch call makes each step independently testable. */ private signRequest; }