🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@sebspark/logging

Package Overview
Dependencies
Maintainers
4
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sebspark/logging - npm Package Compare versions

Comparing version
0.0.3
to
0.0.4
+8
dist/index.d.mts
import { Request, Response, NextFunction } from 'express';
declare const CorrIdHeaderName = "X-Correlation-Id";
declare const runWithCorrelationId: (callback: () => Promise<void>, existingCorrId?: string) => Promise<void>;
declare const getCorrId: () => string | undefined;
declare const correlationIdMiddleware: (req: Request, _res: Response, next: NextFunction) => void;
export { CorrIdHeaderName, correlationIdMiddleware, getCorrId, runWithCorrelationId };
import { Request, Response, NextFunction } from 'express';
declare const CorrIdHeaderName = "X-Correlation-Id";
declare const runWithCorrelationId: (callback: () => Promise<void>, existingCorrId?: string) => Promise<void>;
declare const getCorrId: () => string | undefined;
declare const correlationIdMiddleware: (req: Request, _res: Response, next: NextFunction) => void;
export { CorrIdHeaderName, correlationIdMiddleware, getCorrId, runWithCorrelationId };
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
CorrIdHeaderName: () => CorrIdHeaderName,
correlationIdMiddleware: () => correlationIdMiddleware,
getCorrId: () => getCorrId,
runWithCorrelationId: () => runWithCorrelationId
});
module.exports = __toCommonJS(src_exports);
// src/lib/correlationid.ts
var import_async_hooks = require("async_hooks");
var import_crypto = require("crypto");
var asyncLocalStorage = new import_async_hooks.AsyncLocalStorage();
var CorrIdHeaderName = "X-Correlation-Id";
var runWithCorrelationId = async (callback, existingCorrId) => {
return new Promise((res) => {
const corrId = existingCorrId ?? (0, import_crypto.randomUUID)().substring(0, 8);
asyncLocalStorage.run({ corrId }, async () => {
await callback();
res();
});
});
};
var getCorrId = () => {
var _a;
return (_a = asyncLocalStorage.getStore()) == null ? void 0 : _a.corrId;
};
var correlationIdMiddleware = (req, _res, next) => {
runWithCorrelationId(async () => {
next();
}, req.get(CorrIdHeaderName));
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CorrIdHeaderName,
correlationIdMiddleware,
getCorrId,
runWithCorrelationId
});
// src/lib/correlationid.ts
import { AsyncLocalStorage } from "async_hooks";
import { randomUUID } from "crypto";
var asyncLocalStorage = new AsyncLocalStorage();
var CorrIdHeaderName = "X-Correlation-Id";
var runWithCorrelationId = async (callback, existingCorrId) => {
return new Promise((res) => {
const corrId = existingCorrId ?? randomUUID().substring(0, 8);
asyncLocalStorage.run({ corrId }, async () => {
await callback();
res();
});
});
};
var getCorrId = () => {
var _a;
return (_a = asyncLocalStorage.getStore()) == null ? void 0 : _a.corrId;
};
var correlationIdMiddleware = (req, _res, next) => {
runWithCorrelationId(async () => {
next();
}, req.get(CorrIdHeaderName));
};
export {
CorrIdHeaderName,
correlationIdMiddleware,
getCorrId,
runWithCorrelationId
};
+14
-11
{
"name": "@sebspark/logging",
"version": "0.0.3",
"publishConfig": {
"directory": "../../dist/packages/logging"
"version": "0.0.4",
"license": "UNLICENSED",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsup-node src/index.ts --format esm,cjs --dts",
"lint": "eslint \"src/**/*.ts*\"",
"test": "vitest run"
},
"peerDependencies": {
"@swc/helpers": "0.5.0"
},
"main": "./src/index.js",
"exports": {
".": {
"require": "./src/index.js"
}
"devDependencies": {
"tsconfig": "*"
}
}
# @sebspark/logging
## 0.0.3
### Patch Changes
- 9900279: Make a first release
## 0.0.2
### Patch Changes
- a36b647: Adding logging package
export * from './lib/correlationid';
"use strict";
const _export_star = require("@swc/helpers/_/_export_star");
_export_star._(require("./lib/correlationid"), exports);
//# sourceMappingURL=index.js.map
{"version":3,"sources":["../../../../packages/logging/src/index.ts"],"sourcesContent":["export * from './lib/correlationid'\n"],"names":[],"mappings":";;uBAAc"}
import type { Request, Response, NextFunction } from 'express';
export declare const CorrIdHeaderName = "X-Correlation-Id";
export declare const runWithCorrelationId: (callback: () => Promise<void>, existingCorrId?: string) => Promise<void>;
export declare const getCorrId: () => string;
export declare const correlationIdMiddleware: (req: Request, _res: Response, next: NextFunction) => void;
"use strict";
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
CorrIdHeaderName: function() {
return CorrIdHeaderName;
},
runWithCorrelationId: function() {
return runWithCorrelationId;
},
getCorrId: function() {
return getCorrId;
},
correlationIdMiddleware: function() {
return correlationIdMiddleware;
}
});
const _async_hooks = require("async_hooks");
const _crypto = require("crypto");
const asyncLocalStorage = new _async_hooks.AsyncLocalStorage();
const CorrIdHeaderName = 'X-Correlation-Id';
const runWithCorrelationId = async (callback, existingCorrId)=>{
return new Promise((res)=>{
const corrId = existingCorrId != null ? existingCorrId : (0, _crypto.randomUUID)().substring(0, 8);
asyncLocalStorage.run({
corrId
}, async ()=>{
await callback();
res();
});
});
};
const getCorrId = ()=>{
var _asyncLocalStorage_getStore;
return (_asyncLocalStorage_getStore = asyncLocalStorage.getStore()) == null ? void 0 : _asyncLocalStorage_getStore.corrId;
};
const correlationIdMiddleware = (req, _res, next)=>{
runWithCorrelationId(async ()=>{
next();
}, req.get(CorrIdHeaderName));
};
//# sourceMappingURL=correlationid.js.map
{"version":3,"sources":["../../../../../packages/logging/src/lib/correlationid.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'async_hooks'\nimport { randomUUID } from 'crypto'\nimport type { Request, Response, NextFunction } from 'express'\n\nconst asyncLocalStorage = new AsyncLocalStorage<{ corrId: string }>()\n\nexport const CorrIdHeaderName = 'X-Correlation-Id'\n\nexport const runWithCorrelationId = async (\n callback: () => Promise<void>,\n existingCorrId?: string\n) => {\n return new Promise<void>((res) => {\n const corrId = existingCorrId ?? randomUUID().substring(0, 8)\n asyncLocalStorage.run({ corrId }, async () => {\n await callback()\n res()\n })\n })\n}\n\nexport const getCorrId = () => {\n return asyncLocalStorage.getStore()?.corrId\n}\n\nexport const correlationIdMiddleware = (\n req: Request,\n _res: Response,\n next: NextFunction\n) => {\n runWithCorrelationId(async () => {\n next()\n }, req.get(CorrIdHeaderName))\n}\n"],"names":["CorrIdHeaderName","runWithCorrelationId","getCorrId","correlationIdMiddleware","asyncLocalStorage","AsyncLocalStorage","callback","existingCorrId","Promise","res","corrId","randomUUID","substring","run","getStore","req","_res","next","get"],"mappings":";;;;;;;;IAMaA,gBAAgB;eAAhBA;;IAEAC,oBAAoB;eAApBA;;IAaAC,SAAS;eAATA;;IAIAC,uBAAuB;eAAvBA;;;6BAzBqB;wBACP;AAG3B,MAAMC,oBAAoB,IAAIC,8BAAiB;AAExC,MAAML,mBAAmB;AAEzB,MAAMC,uBAAuB,OAClCK,UACAC,iBACG;IACH,OAAO,IAAIC,QAAc,CAACC,MAAQ;QAChC,MAAMC,SAASH,yBAAAA,iBAAkBI,IAAAA,kBAAU,IAAGC,SAAS,CAAC,GAAG,EAAE;QAC7DR,kBAAkBS,GAAG,CAAC;YAAEH;QAAO,GAAG,UAAY;YAC5C,MAAMJ;YACNG;QACF;IACF;AACF;AAEO,MAAMP,YAAY,IAAM;QACtBE;IAAP,OAAOA,CAAAA,8BAAAA,kBAAkBU,QAAQ,cAA1BV,KAAAA,IAAAA,4BAA8BM,MAAM;AAC7C;AAEO,MAAMP,0BAA0B,CACrCY,KACAC,MACAC,OACG;IACHhB,qBAAqB,UAAY;QAC/BgB;IACF,GAAGF,IAAIG,GAAG,CAAClB;AACb"}