Repository URL to install this package:
|
Version:
2.0.21 ▾
|
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const uuid_1 = __importDefault(require("uuid"));
const exotic_1 = require("exotic");
// this we can output to a file
// and then get all the logs for a specific deploy
exports.idList = [];
exports.correlationIdNamespace = process.env.SKCID || '@@graphql';
exports.cookieNamespace = process.env.COOKIE_NAMESPACE || '@@cookie';
const fromReqToCookie = (request) => {
return exotic_1.isFunction(request.headers.get)
? request.headers.get('Cookie')
: exotic_1.isFunction(request.get)
? request.get('Cookie')
: request.headers.Cookie || request.Headers.cookie || undefined;
};
/**
* @todo add this req param if we want to use it explicitly,
* since we should set it on the req
*/
exports.toCorrelationId = (req) => {
// index?: number
// return at an index, or the last one
// if (index !== undefined) {
// return idList[index] || idList[idList.length - 1]
// }
/**
* @note BREAKING CHANGE
* BACKWARDS API,
* NOW NOTHING GIVES THE LAST ONE,
* REQUIRES A REQUEST TO GENERATE A NEW ONE
*/
if (req === undefined) {
return exports.idList[exports.idList.length - 1];
}
const idForRequest = exports.correlationIdNamespace +
uuid_1.default() +
exports.cookieNamespace +
'=' +
fromReqToCookie(req);
req.log.info('[gql] toCorrelationId: ', idForRequest);
exports.idList.push(idForRequest);
return idForRequest;
};
//# sourceMappingURL=correlationId.js.map