{"_id":"@ashkiani/mongo-logger","_rev":"2-45c97df39912f9b9ca06f2dbabb6a0e6","name":"@ashkiani/mongo-logger","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@ashkiani/mongo-logger","version":"1.0.0","keywords":["mongodb","logger","api","authorization","request-logging","utility"],"author":{"name":"Siavash Ashkiani"},"license":"MIT","_id":"@ashkiani/mongo-logger@1.0.0","maintainers":[{"name":"ashkiani","email":"ashkiani@yahoo.com"}],"homepage":"https://github.com/ashkiani/mongo-logger#readme","bugs":{"url":"https://github.com/ashkiani/mongo-logger/issues"},"dist":{"shasum":"f01c48e33711f4ef3cfaab9ae9b03e8c83cc5a34","tarball":"https://registry.npmjs.org/@ashkiani/mongo-logger/-/mongo-logger-1.0.0.tgz","fileCount":5,"integrity":"sha512-RXk/zVlM8ODdkqIrE4Mawrj6R2DB7ck1mE6RwKCTEAjHhCYa4mkMMNJEflqQUKmxJiIZaKCK/RJtd1t+WBStZA==","signatures":[{"sig":"MEYCIQDZnKBtQ4MKQrHpRboomZZt0s5RdCyHjMPTiwu2OzF+vwIhAIqB8rIB7utBhMUKpU9bOWvcDNXMH0YFDXL1liZB8MyY","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":8202},"main":"index.js","gitHead":"02176efff640c149b85713473ea0e2bbcd2dac76","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"ashkiani","email":"ashkiani@yahoo.com"},"repository":{"url":"git+https://github.com/ashkiani/mongo-logger.git","type":"git"},"_npmVersion":"9.2.0","description":"Reusable request logger and API key authorizer using MongoDB for Node projects.","directories":{},"_nodeVersion":"20.19.0","dependencies":{"bcrypt":"^5.1.1","@ashkiani/mongo-client":"^1.0.1"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/mongo-logger_1.0.0_1746560040767_0.2346870842954485","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@ashkiani/mongo-logger","version":"1.0.1","description":"Reusable request logger and API key authorizer using MongoDB for Node projects.","main":"index.js","scripts":{"test":"node --test","prepublishOnly":"npm test"},"repository":{"type":"git","url":"git+https://github.com/ashkiani/mongo-logger.git"},"keywords":["mongodb","logger","api","authorization","request-logging","utility"],"author":{"name":"Siavash Ashkiani"},"license":"MIT","bugs":{"url":"https://github.com/ashkiani/mongo-logger/issues"},"homepage":"https://github.com/ashkiani/mongo-logger#readme","dependencies":{"@ashkiani/mongo-client":"^1.0.1","bcrypt":"^6.0.0"},"gitHead":"656d908dd312a595a689ed2b31756738e95733d7","_id":"@ashkiani/mongo-logger@1.0.1","_nodeVersion":"18.19.1","_npmVersion":"9.2.0","dist":{"integrity":"sha512-R55IEsuLh42B9BRBMRss0rvnuymyCW+jD508S4KCpnfvpIs2ujb3uTc0rAoa2DcYBI+Rj/wehF9lpzM5qAW9tg==","shasum":"28d824452fcd314a67acbc23c515a5aef9683bba","tarball":"https://registry.npmjs.org/@ashkiani/mongo-logger/-/mongo-logger-1.0.1.tgz","fileCount":6,"unpackedSize":14241,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHL7ddNY/cVCr2QxgeptpZ05dIo3Vq6vVjnAHfcHQUsnAiEAun+IZor3XVaQMKQFDHFTAmdqPd9uVdua91rnjgZGaaI="}]},"_npmUser":{"name":"ashkiani","email":"ashkiani@yahoo.com"},"directories":{},"maintainers":[{"name":"ashkiani","email":"ashkiani@yahoo.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mongo-logger_1.0.1_1782425642606_0.6162118547892808"},"_hasShrinkwrap":false}},"time":{"created":"2025-05-06T19:34:00.671Z","modified":"2026-06-25T22:14:02.849Z","1.0.0":"2025-05-06T19:34:00.960Z","1.0.1":"2026-06-25T22:14:02.756Z"},"bugs":{"url":"https://github.com/ashkiani/mongo-logger/issues"},"author":{"name":"Siavash Ashkiani"},"license":"MIT","homepage":"https://github.com/ashkiani/mongo-logger#readme","keywords":["mongodb","logger","api","authorization","request-logging","utility"],"repository":{"type":"git","url":"git+https://github.com/ashkiani/mongo-logger.git"},"description":"Reusable request logger and API key authorizer using MongoDB for Node projects.","maintainers":[{"name":"ashkiani","email":"ashkiani@yahoo.com"}],"readme":"# mongo-logger\n\nReusable request logger and API key authorizer using MongoDB for Node projects.\n\n````markdown\n# @ashkiani/mongo-logger\n\nReusable request logger and API key authorizer using MongoDB.  \nThis utility provides a structured logging mechanism and optional key-based API access control for Express apps and other Node.js services backed by MongoDB.\n\n---\n\n## 📦 Installation\n\nnpm install @ashkiani/mongo-logger\n````\n\n---\n\n## 🛠 Usage\n\n### 1. Set your environment variable:\n\nMake sure your project defines the MongoDB URI as:\n\n```\nMongo_URI=mongodb://username:password@host:port/dbname\n```\n\n---\n\n### 2. Import and use in your Node.js code:\n\n```js\nconst dbClient = require('@ashkiani/mongo-client');  \nconst mongoLogger = require('@ashkiani/mongo-logger');\n\n(async () => {\n    await dbClient.connect();\n\n    app.post(\"/some/api\", async (req, res) => {\n        const logEntry = await mongoLogger.createLogEntryObj(req, dbClient.get(), \"/some/api\");\n\n        await mongoLogger.writeLogObj(logEntry, dbClient.get(), \"your-db-name\", \"your-collection-name\");\n\n        if (!logEntry.user.authorized) {\n            return res.status(403).json({ error: logEntry.user.issue });\n        }\n\n        res.json({ message: \"Authorized request processed!\" });\n    });\n})();\n```\n\n---\n\n## 📘 API\n\n### `createLogEntryObj(req, dbClient, route)`\nCreates a structured log object based on the request, origin, API key, and metadata.\n\n### `writeLogObj(logEntry, dbClient, dbName, colName)`\nWrites the log object to the given MongoDB database and collection. Automatically scrubs the API key from storage if the user is authorized.\n\n🔐 Keyless Access Behavior\nIf no key is provided, the logger checks if the environment (api_env) allows keyless access (dev, test, prod) and verifies if the origin is in the ALLOWED_ORIGINS list.\n\n---\n\n## 💡 Notes\n\n* This module is designed to be used as a singleton across your app.\n* Uses bcrypt to hash and match keys securely.\n* Keys must be stored in MongoDB with pre-generated bcrypt-hashed values.\n* Intended for API backends using Express or similar frameworks.\n* API keys are scrubbed from logs for security.\n* Connection URI should be stored securely in environment variables (`.env` or your deployment config).\n\n\n---\n\n## 📄 License\n\nMIT © [Siavash Ashkiani](https://github.com/ashkiani)\n","readmeFilename":"README.md"}