@mbc-cqrs-serverless/core
Version:
CQRS and event base core
185 lines • 8.35 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnvironmentVariables = exports.Environment = exports.validateBuiltinNotificationTransportEnv = exports.parseNotificationTransports = exports.BUILTIN_NOTIFICATION_TRANSPORT_ENV = void 0;
exports.getValidateConfig = getValidateConfig;
const common_1 = require("@nestjs/common");
const class_transformer_1 = require("class-transformer");
const class_validator_1 = require("class-validator");
const notification_env_validation_1 = require("./notification-env.validation");
var notification_env_validation_2 = require("./notification-env.validation");
Object.defineProperty(exports, "BUILTIN_NOTIFICATION_TRANSPORT_ENV", { enumerable: true, get: function () { return notification_env_validation_2.BUILTIN_NOTIFICATION_TRANSPORT_ENV; } });
Object.defineProperty(exports, "parseNotificationTransports", { enumerable: true, get: function () { return notification_env_validation_2.parseNotificationTransports; } });
Object.defineProperty(exports, "validateBuiltinNotificationTransportEnv", { enumerable: true, get: function () { return notification_env_validation_2.validateBuiltinNotificationTransportEnv; } });
var Environment;
(function (Environment) {
Environment["Local"] = "local";
Environment["Development"] = "dev";
Environment["Production"] = "prod";
Environment["Staging"] = "stg";
})(Environment || (exports.Environment = Environment = {}));
class EnvironmentVariables {
}
exports.EnvironmentVariables = EnvironmentVariables;
__decorate([
(0, class_validator_1.IsEnum)(Environment),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "NODE_ENV", void 0);
__decorate([
(0, class_validator_1.IsString)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "APP_NAME", void 0);
__decorate([
(0, class_validator_1.IsNumber)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], EnvironmentVariables.prototype, "APP_PORT", void 0);
__decorate([
(0, class_validator_1.IsBoolean)(),
__metadata("design:type", Boolean)
], EnvironmentVariables.prototype, "EVENT_SOURCE_DISABLED", void 0);
__decorate([
(0, class_validator_1.IsString)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "LOG_LEVEL", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "DYNAMODB_ENDPOINT", void 0);
__decorate([
(0, class_validator_1.IsOptional)(),
(0, class_validator_1.IsString)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "DYNAMODB_REGION", void 0);
__decorate([
(0, class_validator_1.IsPositive)(),
__metadata("design:type", Number)
], EnvironmentVariables.prototype, "ATTRIBUTE_LIMIT_SIZE", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "S3_ENDPOINT", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "S3_REGION", void 0);
__decorate([
(0, class_validator_1.IsString)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "S3_BUCKET_NAME", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "SFN_ENDPOINT", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "SFN_REGION", void 0);
__decorate([
(0, class_validator_1.IsString)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "SFN_COMMAND_ARN", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "SNS_ENDPOINT", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "SNS_REGION", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "NOTIFICATION_TRANSPORTS", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "APPSYNC_ENDPOINT", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "APPSYNC_EVENTS_ENDPOINT", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "APPSYNC_EVENTS_NAMESPACE", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "SES_ENDPOINT", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "SES_REGION", void 0);
__decorate([
(0, class_validator_1.IsString)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "SES_FROM_EMAIL", void 0);
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", String)
], EnvironmentVariables.prototype, "REQUEST_BODY_SIZE_LIMIT", void 0);
__decorate([
(0, class_validator_1.IsNumber)(),
(0, class_validator_1.IsOptional)(),
__metadata("design:type", Number)
], EnvironmentVariables.prototype, "RYW_SESSION_TTL_MINUTES", void 0);
// Deprecated environment variable mappings: [oldName, newName]
const DEPRECATED_ENV_VARS = [
['COGNITO_USER_POLL_CLIENT_ID', 'COGNITO_USER_POOL_CLIENT_ID'],
];
/**
* Migrate deprecated environment variable names to their new names.
* If the old name is set and the new name is not, the value is copied
* to the new name and a deprecation warning is logged.
*/
function migrateDeprecatedEnvVars(config) {
const logger = new common_1.Logger('EnvValidation');
for (const [oldName, newName] of DEPRECATED_ENV_VARS) {
if (config[oldName] !== undefined && config[newName] === undefined) {
config[newName] = config[oldName];
logger.warn(`Environment variable "${oldName}" is deprecated. ` +
`Please use "${newName}" instead.`);
}
}
return config;
}
function getValidateConfig(cls) {
return function validate(config) {
const migratedConfig = migrateDeprecatedEnvVars(config);
const validatedConfig = (0, class_transformer_1.plainToInstance)(cls || EnvironmentVariables, migratedConfig, {
enableImplicitConversion: true,
});
const errors = (0, class_validator_1.validateSync)(validatedConfig, {
skipMissingProperties: false,
});
if (errors.length > 0) {
throw new Error(errors.toString());
}
(0, notification_env_validation_1.validateBuiltinNotificationTransportEnv)(validatedConfig);
return validatedConfig;
};
}
//# sourceMappingURL=env.validation.js.map