UNPKG

@evanion/nestjs-correlation-id

Version:

Transparently forward or add correlation id to all requests

24 lines (23 loc) 1.53 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.withCorrelation = void 0; const constants_1 = require("./constants"); const correlation_module_1 = require("./correlation.module"); const correlation_service_1 = require("./correlation.service"); const withCorrelation = (config) => ({ imports: [correlation_module_1.CorrelationModule], useFactory: (correlationService) => __awaiter(void 0, void 0, void 0, function* () { return (Object.assign(Object.assign({}, config), { headers: Object.assign(Object.assign({}, ((config === null || config === void 0 ? void 0 : config.headers) && config.headers)), { [constants_1.CORRELATION_ID_HEADER]: correlationService.getCorrelationId() }) })); }), inject: [correlation_service_1.CorrelationService], }); exports.withCorrelation = withCorrelation;