{"id":15999641,"url":"https://github.com/jaredwray/tensile","last_synced_at":"2025-04-19T12:14:01.276Z","repository":{"id":227525304,"uuid":"771668322","full_name":"jaredwray/tensile","owner":"jaredwray","description":"A Modern Enterprise Auth Framework","archived":false,"fork":false,"pushed_at":"2025-02-10T17:14:24.000Z","size":61,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-15T09:08:14.979Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://tensile.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaredwray.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2024-03-13T18:15:10.000Z","updated_at":"2025-02-10T17:14:28.000Z","dependencies_parsed_at":"2024-03-13T19:40:35.453Z","dependency_job_id":"34d010ca-75bf-468b-8923-7557aeec08f3","html_url":"https://github.com/jaredwray/tensile","commit_stats":null,"previous_names":["jaredwray/httpmock","jaredwray/tensile"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredwray%2Ftensile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredwray%2Ftensile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredwray%2Ftensile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredwray%2Ftensile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredwray","download_url":"https://codeload.github.com/jaredwray/tensile/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240386295,"owners_count":19793155,"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-10-08T09:00:42.624Z","updated_at":"2025-02-23T22:20:47.204Z","avatar_url":"https://github.com/jaredwray.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![site/logo.svg](site/logo.svg)\n\n[![codecov](https://codecov.io/gh/jaredwray/tensile/graph/badge.svg?token=iAkdAEwD6S)](https://codecov.io/gh/jaredwray/tensile)\n[![tests](https://github.com/jaredwray/tensile/actions/workflows/tests.yaml/badge.svg)](https://github.com/jaredwray/tensile/actions/workflows/tests.yaml)\n[![GitHub license](https://img.shields.io/github/license/jaredwray/tensile)](https://github.com/jaredwray/tensile/blob/master/LICENSE)\n[![npm](https://img.shields.io/npm/dm/tensile)](https://npmjs.com/package/tensile)\n[![npm](https://img.shields.io/npm/v/tensile)](https://npmjs.com/package/tensile)\n\n# Fastify Plugin for Modern API Development\n\nTensile is a [fastify](https://fastify.dev) plugin that enables the standard features you need to build a modern REST api service. 🎉\n\n🚨 WARNING: This is a work in progress and is not ready for use yet. Please use when we hit 1.0.0!\n\n## Features\n* Caching: Layer 1 / Layer 2 caching built in via [Cacheable](https://cacheable.org)\n* Rate Limiting: Prevent abuse with request rate controls.\n* CORS: Enable cross-origin resource sharing for API clients.\n* Helmet: Harden API security with HTTP headers.\n* Swagger/OpenAPI: Auto-generate API documentation and interactive testing interfaces.\n* Logging: Preset logging via pino-pretty for easy debugging.\n* Maintained on a regular basis!\n\n## Installation\n```bash\nnpm install tensile\n```\n\n# Usage\n```javascript\nimport fastify from 'fastify';\nimport tensile from 'tensile';\n\nconst app = fastify();\n\napp.register(tensile);\n```\n\nThis will add all the features above with the following pre-configured options:\n\n* Caching: Enabled with a default TTL of 60 seconds.\n* Rate Limiting: Enabled with a default limit of 500 requests per minute.\n* CORS: Enabled with default options.\n* Helmet: Enabled with default options.\n* Swagger/OpenAPI: Enabled with `/openapi.json` and a default client at path of `/`.\n\nFor more advanced usage you can initialize Tensile with options and then update the options for each feature using the properties:\n\n# Caching\n\nCaching is provided by [Cacheable](https://cacheable.org) and is enabled by default with a TTL of 60 seconds. You can update the options by setting the `cache` property in the `tensileOptions` object:\n\n```javascript\nconst tensileOptions = {\n  cache: {\n    ttl: 120\n  }\n};\n\napp.register(tensile, tensileOptions);\n```\n\nif you want to disable caching, you can set the `cache` property to `false`:\n\n```javascript\nconst tensileOptions = {\n  cache: false\n};\n\napp.register(tensile, tensileOptions);\n```\n\nThe options are based on `CachableOptions` from [Cacheable](https://cacheable.org) and are passed directly to the `Cacheable` instance:\n\n```typescript\nexport type CacheableOptions = {\n\t/**\n\t * The primary store for the cacheable instance\n\t */\n\tprimary?: Keyv | KeyvStoreAdapter;\n\t/**\n\t * The secondary store for the cacheable instance\n\t */\n\tsecondary?: Keyv | KeyvStoreAdapter;\n\t/**\n\t * Whether to enable statistics for the cacheable instance\n\t */\n\tstats?: boolean;\n\t/**\n\t * Whether the secondary store is non-blocking mode. It is set to false by default.\n\t * If it is set to true then the secondary store will not block the primary store.\n\t */\n\tnonBlocking?: boolean;\n\t/**\n\t * The time-to-live for the cacheable instance and will be used as the default value.\n\t * can be a number in milliseconds or a human-readable format such as `1s` for 1 second or `1h` for 1 hour\n\t * or undefined if there is no time-to-live.\n\t */\n\tttl?: number | string;\n\t/**\n\t * The namespace for the cacheable instance. It can be a string or a function that returns a string.\n\t */\n\tnamespace?: string | (() =\u003e string);\n};\n```\n\nTo use the cache in your routes, you can use the `cache` property on the `fastify` instance:\n\n```javascript\nimport fastify from 'fastify';\nimport tensile from 'tensile';\n\nconst app = fastify();\n\napp.register(tensile);\n\napp.get('/cache-example/:id', async (request, reply) =\u003e {\n    const { id } = request.params;\n    const cacheKey = `cache-example-${id}`;\n    \n    const cachedValue = app.cache.get(cacheKey);\n    \n    if (cachedValue) {\n        return cachedValue;\n    }\n    \n    const newValue = `New value for ${id}`;\n    \n    app.cache.set(cacheKey, newValue);\n    \n    return newValue;\n});\n```\n\n# Rate Limiting\n\nRate limiting is based on `@fastify/rate-limit` is enabled by default with the following settings:\n\n* `limit`: 100 requests per minute\n* `timeWindow`: 60000 milliseconds (1 minute)\n\n```javascript\nconst tensileOptions = {\n  rateLimit: {\n    limit: 200,\n    timeWindow: 60000\n  }\n};\n```\n\nYou can disable rate limiting by setting the `rateLimit` property to `false`:\n\n```javascript\nconst tensileOptions = {\n  rateLimit: false\n};\n```\n\nTo read more about the options for rate limiting, please see the [@fastify/rate-limit documentation](https://github.com/fastify/fastify-rate-limit?tab=readme-ov-file#options).\n\n# CORS\n\nCORS is based on [@fastify/cors] and enabled by default with the following settings for a public API service:\n\n* `origin`: `*` which allows all origins\n* `methods`: GET, POST, PUT, DELETE, OPTIONS, PATCH\n* `allowedHeaders`: 'Content-Type', 'Authorization', 'Accept', 'X-Requested-With'\n* `exposedHeaders`: 'X-RateLimit-Limit', 'X-RateLimit-Remaining', 'X-RateLimit-Reset'\n* `maxAge`: 86400 which will cache the preflight request for 1 day\n\nHere is an example to set the CORS options:\n\n```javascript\nimport fastify from 'fastify';\nimport tensile from 'tensile';\n\nconst app = fastify();\n\nconst tensileOptions = {\n  cors: {\n    origin: 'https://example.com',\n    methods: ['GET', 'POST'],\n    allowedHeaders: ['Content-Type', 'Authorization'],\n    }\n};\n\napp.register(tensile, tensileOptions);\n```\n\n# Helmet\n\nHelmet is based on [@fastify-helmet](https://github.com/fastify/fastify-helmet) and is enabled with the default settings provided. You can update the options by setting the `helmet` property in the `tensileOptions` object:\n\n```javascript\nimport fastify from 'fastify';\nimport tensile from 'tensile';\n\nconst app = fastify();\n\nconst tensileOptions = {\n  helmet: {\n    contentSecurityPolicy: {\n      directives: {\n        defaultSrc: [\"'self'\"],\n        scriptSrc: [\"'self'\", \"'unsafe-inline'\"],\n        objectSrc: [\"'none'\"],\n        upgradeInsecureRequests: true,\n      },\n    },\n  },\n};\n\napp.register(tensile, tensileOptions);\n```\n\n# Swagger/OpenAPI\n\nSwagger/OpenAPI is based on [@fastify/swagger](https://github.com/fastify/fastify-swagger) and is enabled with the following settings:\n\n* `routePrefix`: `/`\n* `openApi`: We use the latest version of OpenAPI (3.0.3) instead of swagger\n* `title`: We get this fron `package.json` and cache it in memory for performance\n* `description`: We get this fron `package.json` and cache it in memory for performance\n* `version`: We get this fron `package.json` and cache it in memory for performance\n\nYou can update the options by setting the `swagger` property in the `tensileOptions` object:\n\n```javascript\nimport fastify from 'fastify';\nimport tensile from 'tensile';\n\nconst app = fastify();\n\nconst tensileOptions = {\n  docs: {\n    routePrefix: '/docs',\n    openApi: {\n      info: {\n        title: 'My API',\n        description: 'API documentation for my API',\n        version: '1.0.0',\n      },\n      servers: [\n        {\n          url: 'http://localhost:3000',\n          description: 'Development server',\n        },\n      ],\n    },\n  },\n};\n```\n\n# Logging\n\nLogging is based on [pino-pretty](https://github.com/pinojs/pino-pretty) and is enabled with the default settings provided. You can update the options by setting the `logging` property in the `tensileOptions` object:\n\n```javascript\nimport fastify from 'fastify';\nimport tensile from 'tensile';\n\nconst app = fastify();\n\nconst tensileOptions = {\n  logging: {\n    prettyPrint: {\n      colorize: true,\n      translateTime: 'SYS:standard',\n    },\n  },\n};\n\napp.register(tensile, tensileOptions);\n```\n\n# Contributing and Code of Conduct\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details. Please see [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.\n\n\n# License\n[MIT \u0026 © Jared Wray](LICENSE)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredwray%2Ftensile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredwray%2Ftensile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredwray%2Ftensile/lists"}