{"id":19195286,"url":"https://github.com/fixate/fixate-feathers-hooks","last_synced_at":"2025-02-23T04:39:01.589Z","repository":{"id":57237659,"uuid":"83549095","full_name":"fixate/fixate-feathers-hooks","owner":"fixate","description":"Some useful and miscellaneous feathers hooks","archived":false,"fork":false,"pushed_at":"2018-09-10T13:43:47.000Z","size":32,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-20T09:40:05.265Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fixate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-01T11:53:07.000Z","updated_at":"2019-05-15T15:47:41.000Z","dependencies_parsed_at":"2022-08-26T14:04:17.684Z","dependency_job_id":null,"html_url":"https://github.com/fixate/fixate-feathers-hooks","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fixate%2Ffixate-feathers-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fixate%2Ffixate-feathers-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fixate%2Ffixate-feathers-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fixate%2Ffixate-feathers-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fixate","download_url":"https://codeload.github.com/fixate/fixate-feathers-hooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240271526,"owners_count":19774859,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T12:09:30.976Z","updated_at":"2025-02-23T04:39:01.558Z","avatar_url":"https://github.com/fixate.png","language":"JavaScript","readme":"# fixate-feathers-hooks\n\n### These are largely deprecated by the latest feathers-hooks-common \n\nA mixed bag of feathers hooks that are useful in almost all projects.\n\nThey all curry the hook function, so the 'outer' call is used for configuration and returns a\nfunction.\n\nDependencies:\n\n- lodash/fp (Many hooks use this)\n- bcryptjs (can remove see `optionalHashPassword` below)\n- deep-assign (defaults)\n- string (slugify)\n- feathers-errors (setUserField)\n- feathers-hooks (removeSensitiveFields)\n\nInstall: `npm install --save fixate-feathers-hooks`\n\nInclude:\n`const defaults = require('fixate-feathers-hooks/defaults')` or\n`const { defaults } = require('fixate-feathers-hooks');`\n\n## Hooks\n\n### defaults\n\nSpecify default query params or results. You can also use a function which\nreturns a calculated default.\n\n```javascript\ndefaults({ q: 'foo', complex(hook) { return hook.params.anotherField } }, { deep: true })(hook);\n// (before hook) params = { q: 'bar', anotherField: 'test123' } then params.query will have { q:'bar', complex: 'test123' }\n```\n\n### optionalHashPassword\n\nWorkaround for issue. Copy of feathers-authentication's `hashPassword` hook, but we can use this in\nupdates and patches because it doesn't try and hash a falsey password.\nTODO: remove; fixed in [PR#287](https://github.com/feathersjs/feathers-authentication/pull/287)\n\n### permitFields\n\nSelect fields in `data` (before hook) or `result` (after hook) to allow through using dot notation\n(lodash get). Handles deeply nested objects too.\n\n```javascript\npermitFields('public.object', 'private.item.name')(hook);\n```\n\n### removeSensitiveFields\n\nConfigure fields which should be removed from api responses.\nConfigure `sensitiveFields` in your `default.json` (uses `app.get` and `feathers-hooks.remove` hook).\n\n`\u003e= 1.0.4` - Will throw an error if you use this hook without a configuration for the \"model\". This is to prevent typos causing data to leak.\n\n```javascript\nremoveSensitiveFields('user')(hook);\n\n// default.json\n...\n\"sensitiveFields\": {\n  \"user\": [\"password\", \"forgottenPasswordToken\", ...],\n  \"creditCard\": [\"cvv\"],\n}\n```\n\n### requiredParams\n\nSpecify and validate required params - if params are missing throw an error (`BadRequest by default`)\n\n```javascript\nrequiredParams('firstName', 'lastName', 'email', { Error: new Error('My custom error') })(hook);\n```\n\n### scopeQueryTo\n\nWill ensure that `hook.params.query` has the specified values.\n\n```javascript\nscopeQueryTo({ status: 'active' })(hook);\n\n// with function\nconst scopeToOwner = scopeQueryTo(hook =\u003e ({ user: hook.user._id }));\nexports.before = {\n  find: scopeToOwner,\n  get: scopeToOwner,\n  update: scopeToOwner,\n  patch: scopeToOwner,\n  remove: scopeToOwner,\n};\n```\n\n### setUserField\n\nSets the `data` object to a field contained in `hooks.user` object.\nIf `overwrite` is `false`, then only set if data value is empty\n(probably want to be careful of doing that).\n\n```javascript\n// with default options (except field which is required)\nsetUserField({ field: 'user', userField: '_id', overwrite: true })(hook);\n```\n\n### Slugify\n\nSlugifies fields in object and sets the result to another field.\n\n```javascript\nslugify('mySlug', 'firstName'/*, overwrite = false*/);\n// Or\nslugify('mySlug', ['firstName', 'lastName']/*, overwrite = false*/);\n```\n\n\n### timestamps\n\nSets the current timestamp\n\n```javascript\n// true = Overwrites\nconst updatedAt = timestamp('updatedAt', true);\n// Does not overwrite - note: if your database defaults to now you won't need this :)\nconst createdAt = timestamp('createdAt');\nexport.before = {\n  create: createdAt,\n  update: updatedAt,\n  patch: updatedAt,\n}\n```\n\n### validateUnique\n\nCalls your `options.userService` service to check if `options.field` already exists. If not, it\nwill `BadRequest`, otherwise it'll let the request continue. Asynchronous, returns promise.\nUseful for protecting against mongoose duplicate key errors and returning a useful error.\n\n```javascript\n// with defaults\nvalidateUnique({ field: 'username', userService: '/users' })(hook);\n```\n\n## TODO\n\n* Tests\n* Remove optionalHashPassword\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffixate%2Ffixate-feathers-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffixate%2Ffixate-feathers-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffixate%2Ffixate-feathers-hooks/lists"}