{"id":24087122,"url":"https://github.com/hapipal/toys","last_synced_at":"2025-05-05T17:56:18.318Z","repository":{"id":31868688,"uuid":"81050042","full_name":"hapipal/toys","owner":"hapipal","description":"The hapi utility toy chest","archived":false,"fork":false,"pushed_at":"2023-02-27T04:57:05.000Z","size":135,"stargazers_count":32,"open_issues_count":0,"forks_count":9,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-11T23:18:07.890Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hapipal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-06T05:10:47.000Z","updated_at":"2023-11-03T17:12:44.000Z","dependencies_parsed_at":"2024-06-18T16:57:00.833Z","dependency_job_id":null,"html_url":"https://github.com/hapipal/toys","commit_stats":{"total_commits":85,"total_committers":8,"mean_commits":10.625,"dds":"0.23529411764705888","last_synced_commit":"3c3f371f25d93d3201354844a4dac2b7bc76450f"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapipal%2Ftoys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapipal%2Ftoys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapipal%2Ftoys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapipal%2Ftoys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hapipal","download_url":"https://codeload.github.com/hapipal/toys/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252547021,"owners_count":21765893,"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":"2025-01-10T03:02:14.635Z","updated_at":"2025-05-05T17:56:18.297Z","avatar_url":"https://github.com/hapipal.png","language":"JavaScript","readme":"# toys\n\nThe hapi utility toy chest\n\n[![Build Status](https://app.travis-ci.com/hapipal/toys.svg?branch=main)](https://app.travis-ci.com/hapipal/toys) [![Coverage Status](https://coveralls.io/repos/hapipal/toys/badge.svg?branch=main\u0026service=github)](https://coveralls.io/github/hapipal/toys?branch=main)\n\nLead Maintainer - [Devin Ivy](https://github.com/devinivy)\n\n## Installation\n```sh\nnpm install @hapipal/toys\n```\n\n## Usage\n\u003e See also the [API Reference](API.md)\n\u003e\n\u003e Toys is intended for use with hapi v20+ and nodejs v16+ (_see v3 for lower support_).\n\nToys is a collection of utilities made to reduce common boilerplate in **hapi v20+** projects.\n\nBelow is an example featuring [`Toys.auth.strategy()`](API.md#toysauthstrategyserver-name-authenticate) and [`Toys.withRouteDefaults()`](API.md#toyswithroutedefaultsdefaults).  The [API Reference](API.md) is also filled with examples.\n\n```js\nconst Hapi = require('@hapi/hapi');\nconst Boom = require('@hapi/boom');\nconst Toys = require('@hapipal/toys');\n\n(async () =\u003e {\n\n    const server = Hapi.server();\n\n    // Make a one-off auth strategy for testing\n    Toys.auth.strategy(server, 'name-from-param', (request, h) =\u003e {\n\n        // Yes, perhaps not the most secure\n        const { username } = request.params;\n\n        if (!username) {\n            throw Boom.unauthorized(null, 'Custom');\n        }\n\n        return h.authenticated({ credentials: { user: { name: username } } });\n    });\n\n    // Default all route methods to \"get\", unless otherwise specified\n    const defaultToGet = Toys.withRouteDefaults({ method: 'get' });\n\n    server.route(\n        defaultToGet([\n            {\n                method: 'post',\n                path: '/',\n                handler: (request) =\u003e {\n\n                    return { posted: true };\n                }\n            },\n            {   // Look ma, my method is defaulting to \"get\"!\n                path: '/as/{username}',\n                options: {\n                    auth: 'name-from-param', // Here's our simple auth strategy\n                    handler: (request) =\u003e {\n\n                        const username = request.auth.credentials?.user?.name;\n\n                        return { username };\n                    }\n                }\n            }\n        ])\n    );\n\n    await server.start();\n\n    console.log(`Now, go forth and ${server.info.uri}/as/your-name`);\n})();\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhapipal%2Ftoys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhapipal%2Ftoys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhapipal%2Ftoys/lists"}