UNPKG

moleculer-api

Version:

A dynamic API Gateway for MoleculerJS which updates REST endpoints and aggregated GraphQL schema, access control policy for each action calls from metadata of remote services schema without restart or deployment.

31 lines 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IDContextFactory = void 0; const tslib_1 = require("tslib"); const _ = tslib_1.__importStar(require("lodash")); const uuid = tslib_1.__importStar(require("uuid")); const factory_1 = require("./factory"); /* ID Context Factory */ class IDContextFactory extends factory_1.APIRequestContextFactory { constructor(props, opts) { super(props); this.props = props; this.opts = _.defaultsDeep(opts || {}, IDContextFactory.autoLoadOptions); this.opts.requestIdHeaderName = this.opts.requestIdHeaderName.toLowerCase(); } create({ headers }) { const { requestIdHeaderName, factory } = this.opts; if (typeof headers[requestIdHeaderName] === "string") return headers[requestIdHeaderName]; return factory(); } } exports.IDContextFactory = IDContextFactory; IDContextFactory.key = "id"; IDContextFactory.autoLoadOptions = { requestIdHeaderName: "X-Request-Id", factory: () => uuid.v4().split("-").join(""), }; //# sourceMappingURL=id.js.map