@nestjs-mod/webhook
Version:
Webhook module with an error filter, guard, controller, database migrations and rest-sdk for work with module from other nodejs appliaction
101 lines • 5.06 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebhookModule = void 0;
const common_1 = require("@nestjs-mod/common");
const prisma_1 = require("@nestjs-mod/prisma");
const prisma_tools_1 = require("@nestjs-mod/prisma-tools");
const axios_1 = require("@nestjs/axios");
const common_2 = require("@nestjs/common");
const webhook_controller_1 = require("./controllers/webhook.controller");
const webhook_bootstrap_service_1 = require("./services/webhook-bootstrap.service");
const webhook_users_service_1 = require("./services/webhook-users.service");
const webhook_service_1 = require("./services/webhook.service");
const webhook_configuration_1 = require("./webhook.configuration");
const webhook_constants_1 = require("./webhook.constants");
const webhook_environments_1 = require("./webhook.environments");
const webhook_filter_1 = require("./webhook.filter");
const webhook_guard_1 = require("./webhook.guard");
const keyv_1 = require("@nestjs-mod/keyv");
const core_1 = require("@nestjs/core");
const adapter_pg_1 = require("@prisma/adapter-pg");
const nestjs_translates_1 = require("nestjs-translates");
const webhook_logs_controller_1 = require("./controllers/webhook-logs.controller");
const webhook_cache_service_1 = require("./services/webhook-cache.service");
const webhook_prisma_sdk_1 = require("./webhook.prisma-sdk");
// fake update
exports.WebhookModule = (0, common_1.createNestModule)({
moduleName: webhook_constants_1.WEBHOOK_MODULE,
moduleDescription: 'Webhook module with an error filter, guard, controller, database migrations and rest-sdk for work with module from other nodejs appliaction',
moduleCategory: common_1.NestModuleCategory.feature,
staticEnvironmentsModel: webhook_environments_1.WebhookStaticEnvironments,
featureConfigurationModel: webhook_configuration_1.WebhookFeatureConfiguration,
configurationModel: webhook_configuration_1.WebhookConfiguration,
staticConfigurationModel: webhook_configuration_1.WebhookStaticConfiguration,
imports: [
axios_1.HttpModule,
prisma_1.PrismaModule.forFeature({
contextName: webhook_constants_1.WEBHOOK_FEATURE,
featureModuleName: webhook_constants_1.WEBHOOK_FEATURE,
}),
prisma_tools_1.PrismaToolsModule.forFeature({
featureModuleName: webhook_constants_1.WEBHOOK_FEATURE,
}),
keyv_1.KeyvModule.forFeature({
featureModuleName: webhook_constants_1.WEBHOOK_FEATURE,
}),
nestjs_translates_1.TranslatesModule,
prisma_1.PrismaModule.forRoot({
contextName: webhook_constants_1.WEBHOOK_FEATURE,
staticConfiguration: {
featureName: webhook_constants_1.WEBHOOK_FEATURE,
provider: 'prisma-client',
prismaClientFactory: async (options) => {
const { url, ...otherOoptions } = options;
const adapter = new adapter_pg_1.PrismaPg({ connectionString: url });
return new webhook_prisma_sdk_1.WebhookPrismaSdk.PrismaClient({
adapter,
...otherOoptions,
});
},
},
}),
],
sharedImports: [
axios_1.HttpModule,
prisma_1.PrismaModule.forFeature({
contextName: webhook_constants_1.WEBHOOK_FEATURE,
featureModuleName: webhook_constants_1.WEBHOOK_FEATURE,
}),
],
providers: (asyncModuleOptions) => [
webhook_bootstrap_service_1.WebhookServiceBootstrap,
webhook_cache_service_1.WebhookCacheService,
...(asyncModuleOptions.staticEnvironments.useFilters
? [{ provide: core_1.APP_FILTER, useClass: webhook_filter_1.WebhookExceptionsFilter }]
: []),
],
controllers: (asyncModuleOptions) => [webhook_logs_controller_1.WebhookLogsController, webhook_controller_1.WebhookController].map((ctrl) => {
if (asyncModuleOptions.staticEnvironments?.useGuards) {
(0, common_2.UseGuards)(...(asyncModuleOptions.staticConfiguration?.guards || []), webhook_guard_1.WebhookGuard)(ctrl);
}
if (asyncModuleOptions.staticConfiguration.mutateController) {
asyncModuleOptions.staticConfiguration.mutateController(ctrl);
}
return ctrl;
}),
sharedProviders: [webhook_service_1.WebhookService, webhook_users_service_1.WebhookUsersService],
wrapForRootAsync: (asyncModuleOptions) => {
if (!asyncModuleOptions) {
asyncModuleOptions = {};
}
const FomatterClass = (0, common_1.getFeatureDotEnvPropertyNameFormatter)(webhook_constants_1.WEBHOOK_FEATURE);
Object.assign(asyncModuleOptions, {
environmentsOptions: {
propertyNameFormatters: [new FomatterClass()],
name: webhook_constants_1.WEBHOOK_FEATURE,
},
});
return { asyncModuleOptions };
},
}).WebhookModule;
//# sourceMappingURL=webhook.module.js.map