{"_id":"@aexol/syncano-middleware-common","_rev":"11-10d25b00e39fd94bf57bfeb00c34c177","name":"@aexol/syncano-middleware-common","dist-tags":{"latest":"0.3.0"},"versions":{"0.1.0":{"name":"@aexol/syncano-middleware-common","version":"0.1.0","keywords":["syncano","middleware","common"],"author":{"name":"Aexol"},"license":"MIT","_id":"@aexol/syncano-middleware-common@0.1.0","maintainers":[{"name":"aexol","email":"aexol@aexol.com"}],"homepage":"https://github.com/aexol/syncano-middleware-common#readme","bugs":{"url":"https://github.com/aexol/syncano-middleware-common/issues"},"dist":{"shasum":"8a3312276111e0c1c4efe30fc235f1d44e5e308e","tarball":"https://registry.npmjs.org/@aexol/syncano-middleware-common/-/syncano-middleware-common-0.1.0.tgz","fileCount":13,"integrity":"sha512-B1CSjM3vtlTrvOjQaZLq/AbzH9Rx3QE/hzyNN25gwXb05BXdnQm0kYTe+rmlT99/i7V1CBq5wyYnTOL1muwXQg==","signatures":[{"sig":"MEYCIQDFsD+P4GKbn2VmuzfpauPVX2z5HZ1Px9riX0bMx9slwgIhAPD9N/L7MsDfQBUE7VCaWTz5uOXQvK9K8s0+RGcs3ol6","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":18043},"jest":{"testRegex":"(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$","transform":{"^.+\\.tsx?$":"ts-jest"},"moduleFileExtensions":["ts","tsx","js","jsx","json","node"]},"main":"lib/index.js","gitHead":"505356fde3f0500de88c3a82b6132a1ff7005f51","scripts":{"docs":"jsdoc2md -t jsdoc2md/README.hbs lib/*.js > README.md; echo","test":"jest","build":"rm -rf lib && tsc","prepack":"npm run test && npm run docs","prepare":"npm run build"},"_npmUser":{"name":"aexol","email":"aexol@aexol.com"},"repository":{"url":"git+https://github.com/aexol/syncano-middleware-common.git","type":"git"},"_npmVersion":"5.6.0","description":"Collection of common middlewares for syncano sockets.","directories":{},"_nodeVersion":"9.5.0","dependencies":{"@syncano/core":"^0.9.3","@aexol/syncano-middleware":"^0.1.6"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^22.4.2","tslint":"^5.9.1","ts-jest":"^22.0.4","ts-node":"^5.0.0","typescript":"^2.7.2","@types/jest":"^22.1.3","@types/lodash.get":"^4.4.3","@types/node-fetch":"^1.6.7","jsdoc-to-markdown":"^4.0.1"},"_npmOperationalInternal":{"tmp":"tmp/syncano-middleware-common_0.1.0_1519394047409_0.009082804094813657","host":"s3://npm-registry-packages"}},"0.1.1":{"name":"@aexol/syncano-middleware-common","version":"0.1.1","keywords":["syncano","middleware","common"],"author":{"name":"Aexol"},"license":"MIT","_id":"@aexol/syncano-middleware-common@0.1.1","maintainers":[{"name":"aexol","email":"aexol@aexol.com"}],"homepage":"https://github.com/aexol/syncano-middleware-common#readme","bugs":{"url":"https://github.com/aexol/syncano-middleware-common/issues"},"dist":{"shasum":"7ac11f71ea5f75c5510dc50e0f0c50080f26bfff","tarball":"https://registry.npmjs.org/@aexol/syncano-middleware-common/-/syncano-middleware-common-0.1.1.tgz","fileCount":13,"integrity":"sha512-MPj73HAe10BWb+T4C0ckmhSPCs8qpb0n9nJtkH1K6E3gQMy+RGoWqvKaXSb8ZFgvdYeEsgAcx32p1wpFke3Odw==","signatures":[{"sig":"MEUCIHr09YWnkIeYcqGRuvPvKs0nW8+FtwHHwb3PPR6YXIJxAiEA4D8eiNYMxZ0YOT/F39ZZxt/XOy/Dud9KEdn7Tgz9GK0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":18072},"jest":{"testRegex":"(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$","transform":{"^.+\\.tsx?$":"ts-jest"},"moduleFileExtensions":["ts","tsx","js","jsx","json","node"]},"main":"lib/index.js","types":"lib/index.d.ts","gitHead":"02a7416a9a33f9ce9b3c30f740cdadc6fd312706","scripts":{"docs":"jsdoc2md -t jsdoc2md/README.hbs lib/*.js > README.md; echo","test":"jest","build":"rm -rf lib && tsc","prepack":"npm run test && npm run docs","prepare":"npm run build"},"_npmUser":{"name":"aexol","email":"aexol@aexol.com"},"repository":{"url":"git+https://github.com/aexol/syncano-middleware-common.git","type":"git"},"_npmVersion":"5.6.0","description":"Collection of common middlewares for syncano sockets.","directories":{},"_nodeVersion":"9.5.0","dependencies":{"@syncano/core":"^0.9.3","@aexol/syncano-middleware":"^0.1.6"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^22.4.2","tslint":"^5.9.1","ts-jest":"^22.0.4","ts-node":"^5.0.0","typescript":"^2.7.2","@types/jest":"^22.1.3","@types/lodash.get":"^4.4.3","@types/node-fetch":"^1.6.7","jsdoc-to-markdown":"^4.0.1"},"_npmOperationalInternal":{"tmp":"tmp/syncano-middleware-common_0.1.1_1519394430913_0.48652662302801253","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"@aexol/syncano-middleware-common","version":"0.2.0","keywords":["syncano","middleware","common"],"author":{"name":"Aexol"},"license":"MIT","_id":"@aexol/syncano-middleware-common@0.2.0","maintainers":[{"name":"aexol","email":"aexol@aexol.com"}],"homepage":"https://github.com/aexol/syncano-middleware-common#readme","bugs":{"url":"https://github.com/aexol/syncano-middleware-common/issues"},"dist":{"shasum":"5d88d84357724e41b4f0bb5b3e46ab76aeaf7c30","tarball":"https://registry.npmjs.org/@aexol/syncano-middleware-common/-/syncano-middleware-common-0.2.0.tgz","fileCount":17,"integrity":"sha512-VcGcqIsbHby9rcA6kpn8HuZdmzl8dYoyz9CBXNUfA4hd2P988ZqLD2xJ08Im6+qB1r16cj5KQG1uCXjbbTCSnw==","signatures":[{"sig":"MEQCIFrng4+jsgAew14TV0el9wj0F7iKMeb3ZnJAUvVe33JXAiAm0FJEEoXfwJ38V4diBMEP8jIw6jk7C7s5/Tq3Fm4QBw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":23765},"jest":{"testRegex":"(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$","transform":{"^.+\\.tsx?$":"ts-jest"},"moduleFileExtensions":["ts","tsx","js","jsx","json","node"]},"main":"lib/index.js","types":"lib/index.d.ts","gitHead":"dd1b6993d8b381e222a420a28b685ea3b61567ac","scripts":{"docs":"jsdoc2md -t jsdoc2md/README.hbs lib/*.js > README.md; echo","test":"jest","build":"rm -rf lib && tsc","prepack":"npm run test && npm run docs","prepare":"npm run build"},"_npmUser":{"name":"aexol","email":"aexol@aexol.com"},"repository":{"url":"git+https://github.com/aexol/syncano-middleware-common.git","type":"git"},"_npmVersion":"5.6.0","description":"Collection of common middlewares for syncano sockets.","directories":{},"_nodeVersion":"9.6.1","dependencies":{"@syncano/core":"^0.9.3","@aexol/syncano-middleware":"^0.1.6"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^22.4.2","tslint":"^5.9.1","ts-jest":"^22.0.4","ts-node":"^5.0.0","typescript":"^2.7.2","@types/jest":"^22.1.3","@types/lodash.get":"^4.4.3","@types/node-fetch":"^1.6.7","jsdoc-to-markdown":"^4.0.1"},"_npmOperationalInternal":{"tmp":"tmp/syncano-middleware-common_0.2.0_1519837009549_0.7270154285716366","host":"s3://npm-registry-packages"}},"0.2.1":{"name":"@aexol/syncano-middleware-common","version":"0.2.1","keywords":["syncano","middleware","common"],"author":{"name":"Aexol"},"license":"MIT","_id":"@aexol/syncano-middleware-common@0.2.1","maintainers":[{"name":"aexol","email":"aexol@aexol.com"}],"homepage":"https://github.com/aexol/syncano-middleware-common#readme","bugs":{"url":"https://github.com/aexol/syncano-middleware-common/issues"},"dist":{"shasum":"da3889c5cf76e52c8eb33eff2c4367ff3c998280","tarball":"https://registry.npmjs.org/@aexol/syncano-middleware-common/-/syncano-middleware-common-0.2.1.tgz","fileCount":17,"integrity":"sha512-qnC2E9NkC4IucxFHknbbL4JzMfVgVbqxRSn32/1RxORid7yzSy0z2D4OBGNzmqj7/RE88pXOYOLDEdfApBAKVA==","signatures":[{"sig":"MEUCIC4HZ9Okb9YE4ktS8C3ARt3RJRgpCI8BlqosG9sgczLmAiEAmo/RcvV4jbQBDDfDXXxHUIRkI5xDpbz4ZCSGyfXGxew=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":23879},"jest":{"testRegex":"(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$","transform":{"^.+\\.tsx?$":"ts-jest"},"moduleFileExtensions":["ts","tsx","js","jsx","json","node"]},"main":"lib/index.js","types":"lib/index.d.ts","gitHead":"ffc6cc171d2039cb67b5fd78c46edd7d59544022","scripts":{"docs":"jsdoc2md -t jsdoc2md/README.hbs lib/*.js > README.md; echo","test":"jest","build":"rm -rf lib && tsc","prepack":"npm run test && npm run docs","prepare":"npm run build"},"_npmUser":{"name":"aexol","email":"aexol@aexol.com"},"repository":{"url":"git+https://github.com/aexol/syncano-middleware-common.git","type":"git"},"_npmVersion":"5.6.0","description":"Collection of common middlewares for syncano sockets.","directories":{},"_nodeVersion":"9.6.1","dependencies":{"@syncano/core":"^0.9.3","@aexol/syncano-middleware":"^0.1.6"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^22.4.2","tslint":"^5.9.1","ts-jest":"^22.0.4","ts-node":"^5.0.0","typescript":"^2.7.2","@types/jest":"^22.1.3","@types/lodash.get":"^4.4.3","@types/node-fetch":"^1.6.7","jsdoc-to-markdown":"^4.0.1"},"_npmOperationalInternal":{"tmp":"tmp/syncano-middleware-common_0.2.1_1519837271653_0.29219489940627796","host":"s3://npm-registry-packages"}},"0.3.0":{"name":"@aexol/syncano-middleware-common","version":"0.3.0","keywords":["syncano","middleware","common"],"author":{"name":"Aexol"},"license":"MIT","_id":"@aexol/syncano-middleware-common@0.3.0","maintainers":[{"name":"aexol","email":"aexol@aexol.com"}],"homepage":"https://github.com/aexol/syncano-middleware-common#readme","bugs":{"url":"https://github.com/aexol/syncano-middleware-common/issues"},"dist":{"shasum":"227d7013945236f249f36c9469c232479a0d9dd3","tarball":"https://registry.npmjs.org/@aexol/syncano-middleware-common/-/syncano-middleware-common-0.3.0.tgz","fileCount":21,"integrity":"sha512-GabXxuj4hmheymGYEvE0Wdx/GD8cwziutxQM+IIRe63DWVSSvrUMkYQxVUZMgbtXlsj/qxNbkU0y6Y0zINAlsg==","signatures":[{"sig":"MEUCIQDm2275ovRRsB4VHtB9E7RNT0QYwrcR5UGeesuig2I7HQIgRr7MqvFfgnc6ut94b2o9BcAz6d6rY40ohAANCx12zvI=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":33286},"jest":{"testRegex":"(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$","transform":{"^.+\\.tsx?$":"ts-jest"},"moduleFileExtensions":["ts","tsx","js","jsx","json","node"]},"main":"lib/index.js","types":"lib/index.d.ts","gitHead":"ef79c84686eeb8d83c2a6f4d13ccb0b2d9d945d2","scripts":{"docs":"jsdoc2md -t jsdoc2md/README.hbs lib/*.js > README.md; echo","test":"jest","build":"rm -rf lib && tsc","prepack":"npm run test && npm run docs","prepare":"npm run build"},"_npmUser":{"name":"aexol","email":"aexol@aexol.com"},"repository":{"url":"git+https://github.com/aexol/syncano-middleware-common.git","type":"git"},"_npmVersion":"5.7.1","description":"Collection of common middlewares for syncano sockets.","directories":{},"_nodeVersion":"9.6.1","dependencies":{"@syncano/core":"^0.9.3","@aexol/syncano-middleware":"^0.1.6"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^22.4.2","tslint":"^5.9.1","ts-jest":"^22.0.4","ts-node":"^5.0.0","typescript":"^2.7.2","@types/jest":"^22.1.3","@types/lodash.get":"^4.4.3","@types/node-fetch":"^1.6.7","jsdoc-to-markdown":"^4.0.1"},"_npmOperationalInternal":{"tmp":"tmp/syncano-middleware-common_0.3.0_1522939608147_0.29528729770938766","host":"s3://npm-registry-packages"}}},"time":{"created":"2018-02-23T13:54:07.357Z","modified":"2026-04-03T08:10:36.771Z","0.1.0":"2018-02-23T13:54:07.548Z","0.1.1":"2018-02-23T14:00:31.025Z","0.2.0":"2018-02-28T16:56:49.598Z","0.2.1":"2018-02-28T17:01:11.717Z","0.3.0":"2018-04-05T14:46:48.241Z"},"bugs":{"url":"https://github.com/aexol/syncano-middleware-common/issues"},"author":{"name":"Aexol"},"license":"MIT","homepage":"https://github.com/aexol/syncano-middleware-common#readme","keywords":["syncano","middleware","common"],"repository":{"url":"git+https://github.com/aexol/syncano-middleware-common.git","type":"git"},"description":"Collection of common middlewares for syncano sockets.","maintainers":[{"email":"aexol@aexol.com","name":"arturczemiel"},{"email":"ania@aexol.com","name":"ania-aexol"},{"email":"office@aexol.com","name":"aexol-office"},{"email":"kamil@aexol.com","name":"kamil-aexol"}],"readme":"# Syncano Middleware Common\n\n## About\nCollection of common utilities for sockets in syncano that can be used in conjunction with @aexol/syncano-middleware lib.\n\n## Installation\nnpm install @aexol/syncano-middleware-common\n\n## Usage\n\n## API Reference\n## Modules\n\n<dl>\n<dt><a href=\"#module_@aexol/syncano-middleware-common\">@aexol/syncano-middleware-common</a></dt>\n<dd><p>Common middlewares for syncano.</p>\n</dd>\n</dl>\n\n## Functions\n\n<dl>\n<dt><a href=\"#allowedMethods\">allowedMethods(fn, allowed)</a> ⇒ <code>function</code></dt>\n<dd><p>Checks if request is allowed based on request method.</p>\n</dd>\n<dt><a href=\"#loggedIn\">loggedIn(fn, opts)</a> ⇒ <code>Object</code></dt>\n<dd><p>Checks if user is logged in, returning response with 403 and message if not.</p>\n</dd>\n<dt><a href=\"#parseGETFields\">parseGETFields(fn)</a> ⇒ <code>function</code></dt>\n<dd><p>Parses args in GET request as json if possible. If not, leaves them unchanged.</p>\n</dd>\n<dt><a href=\"#replaceBuffers\">replaceBuffers(fn, opts)</a> ⇒ <code>Object</code></dt>\n<dd><p>Replace all buffers in socket args.</p>\n</dd>\n<dt><a href=\"#rootAccount\">rootAccount(fn, opts)</a> ⇒ <code>Object</code></dt>\n<dd><p>Root account check middleware.</p>\n</dd>\n<dt><a href=\"#toBool\">toBool(fn, fields)</a></dt>\n<dd><p>Attempts to cast certain fields in request to bool.\nCan be useful to handling both GET and POST input on endpoint\nas GET endpoints will always have a string.</p>\n<p>Fields that are either <code>true</code> or <code>&#39;true&#39;</code> will evaluate to true.\nEverything else will be considered false.</p>\n</dd>\n<dt><a href=\"#toNumber\">toNumber(fn, fields)</a></dt>\n<dd><p>Attempts to cast certain fields in request to number.\nCan be useful to handling both GET and POST input on endpoint\nas GET endpoints will always have a string.</p>\n</dd>\n</dl>\n\n<a name=\"module_@aexol/syncano-middleware-common\"></a>\n\n## @aexol/syncano-middleware-common\nCommon middlewares for syncano.\n\n<a name=\"allowedMethods\"></a>\n\n## allowedMethods(fn, allowed) ⇒ <code>function</code>\nChecks if request is allowed based on request method.\n\n**Kind**: global function  \n**Access**: public  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| fn | <code>function</code> \\| <code>Object</code> | Either next function in chain or object with  `key: value` pairs of method and handler function for method type. |\n| allowed | <code>Array</code> | List of allowed methods in case of fn being function. Optional. |\n\n**Example**  \n```javascript\nimport serve, {response} from '@aexol/syncano-middleware'\nimport {allowedMethods} from '@aexol/syncano-middleware-common'\n\nasync function hello(ctx, syncano) {\n    return response.success({message: `Hello, ${ctx.meta.user.username}`)\n}\n\nexport default ctx => serve(ctx, allowedMethods(hello, ['GET']))\n```\n**Example**  \n```javascript\nimport serve, {response} from '@aexol/syncano-middleware'\nimport {allowedMethods} from '@aexol/syncano-middleware-common'\n\nasync function hello(ctx, syncano) {\n    return response.success({message: `Hello, ${ctx.meta.user.username}`)\n}\n\nexport default ctx => serve(ctx, allowedMethods({\n GET: hello,\n POST: hello\n}))\n```\n<a name=\"loggedIn\"></a>\n\n## loggedIn(fn, opts) ⇒ <code>Object</code>\nChecks if user is logged in, returning response with 403 and message if not.\n\n**Kind**: global function  \n**Access**: public  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| fn | <code>function</code> | Next function in request chain |\n| opts | <code>Object</code> | Additional options. Optional |\n| opts.message | <code>String</code> | Alternative message if user is not logged in. |\n\n**Example**  \n```javascript\nimport serve, {response} from '@aexol/syncano-middleware'\nimport {loggedIn} from '@aexol/syncano-middleware-common'\n\nasync function hello(ctx, syncano) {\n    return response.success({message: `Hello, ${ctx.meta.user.username}`)\n}\n\nexport default ctx => serve(ctx, loggedIn(hello))\n```\n<a name=\"parseGETFields\"></a>\n\n## parseGETFields(fn) ⇒ <code>function</code>\nParses args in GET request as json if possible. If not, leaves them unchanged.\n\n**Kind**: global function  \n**Access**: public  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| fn | <code>function</code> | Next function in request chain |\n\n**Example**  \n```javascript\nimport serve, {response} from '@aexol/syncano-middleware'\nimport {parseGETFields} from '@aexol/syncano-middleware-common'\n\nasync function hello(ctx, syncano) {\n    return response.success({message: `Hello, ${ctx.meta.user.username}`)\n}\n\nexport default ctx => serve(ctx, parseGETFields(hello))\n```\n<a name=\"replaceBuffers\"></a>\n\n## replaceBuffers(fn, opts) ⇒ <code>Object</code>\nReplace all buffers in socket args.\n\n**Kind**: global function  \n**Access**: public  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| fn | <code>function</code> | Handler function |\n| opts | <code>Object</code> | Aditional opts. Optional |\n| opts.replaceFn | <code>function</code> | If set, will be used to replace buffer contents instead of default behaviour. |\n| opts.exclude | <code>Array</code> | List of args to skip from replacing. |\n| opts.encoding | <code>String</code> | Input encoding of buffer in args. |\n| opts.inputEncoding | <code>String</code> | Output encoding of buffer in args. Unless, replaceFn was set, this middleware replaces all buffers with it's string content in place. Modifies ctx.args. |\n\n**Example**  \n```javascript\nimport serve, {response} from '@aexol/syncano-middleware'\nimport {replaceBuffers} from '@aexol/syncano-middleware-common'\n\nasync function hello(ctx, syncano) {\n    return response.success({message: 'ok'})\n}\n\nexport default ctx => serve(ctx, replaceBuffers(hello))\n```\n<a name=\"rootAccount\"></a>\n\n## rootAccount(fn, opts) ⇒ <code>Object</code>\nRoot account check middleware.\n\n**Kind**: global function  \n**Access**: public  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| fn | <code>function</code> | Next function in chain. |\n| opts | <code>Object</code> | Additional options. Optional. |\n| opts.message | <code>String</code> | Custom error message if not root account. |\n| opts.condFn | <code>function</code> | Check for root only if function evaluates to true. |\n\n**Example**  \n```javascript\nimport serve, {response} from '@aexol/syncano-middleware'\nimport {rootAccount} from '@aexol/syncano-middleware-common'\n\nasync function hello(ctx, syncano) {\n    return response.success({message: `Hello, ${ctx.meta.admin.email}`)\n}\n\nexport default ctx => serve(ctx, rootAccount(hello))\n```\n<a name=\"toBool\"></a>\n\n## toBool(fn, fields)\nAttempts to cast certain fields in request to bool.\nCan be useful to handling both GET and POST input on endpoint\nas GET endpoints will always have a string.\n\nFields that are either `true` or `'true'` will evaluate to true.\nEverything else will be considered false.\n\n**Kind**: global function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| fn | <code>function</code> | Next function in chain |\n| fields | <code>Array</code> | fields to cast to bool |\n\n<a name=\"toNumber\"></a>\n\n## toNumber(fn, fields)\nAttempts to cast certain fields in request to number.\nCan be useful to handling both GET and POST input on endpoint\nas GET endpoints will always have a string.\n\n**Kind**: global function  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| fn | <code>function</code> | Next function in chain |\n| fields | <code>Array</code> | fields to cast to number |\n\n","readmeFilename":"README.md"}