@mbc-cqrs-serverless/core
Version:
CQRS and event base core
36 lines • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BUILTIN_NOTIFICATION_TRANSPORT_ENV = void 0;
exports.parseNotificationTransports = parseNotificationTransports;
exports.validateBuiltinNotificationTransportEnv = validateBuiltinNotificationTransportEnv;
const enums_1 = require("./notifications/enums");
/** Built-in transports and their required endpoint environment variables. */
exports.BUILTIN_NOTIFICATION_TRANSPORT_ENV = {
[enums_1.NotificationTransports.APPSYNC_GRAPHQL]: 'APPSYNC_ENDPOINT',
[enums_1.NotificationTransports.APPSYNC_EVENT]: 'APPSYNC_EVENTS_ENDPOINT',
};
/**
* Parses NOTIFICATION_TRANSPORTS the same way as NotificationEventHandler.
* Defaults to appsync-graphql when unset or empty.
*/
function parseNotificationTransports(raw) {
const names = (raw ?? '')
.split(',')
.map((s) => s.trim())
.filter(Boolean);
return names.length > 0 ? names : [enums_1.NotificationTransports.APPSYNC_GRAPHQL];
}
function validateBuiltinNotificationTransportEnv(config) {
const active = parseNotificationTransports(config.NOTIFICATION_TRANSPORTS);
for (const name of active) {
const envKey = exports.BUILTIN_NOTIFICATION_TRANSPORT_ENV[name];
if (!envKey) {
continue;
}
const value = config[envKey];
if (typeof value !== 'string' || !value.trim()) {
throw new Error(`Notification transport "${name}" is enabled (NOTIFICATION_TRANSPORTS) but ${envKey} is not set.`);
}
}
}
//# sourceMappingURL=notification-env.validation.js.map