{"id":21645192,"url":"https://github.com/strapi-community/strapi-plugin-transformer","last_synced_at":"2025-03-17T16:10:44.299Z","repository":{"id":38274629,"uuid":"458045286","full_name":"strapi-community/strapi-plugin-transformer","owner":"strapi-community","description":"A plugin for Strapi Headless CMS that provides the ability to transform the API request or response.","archived":false,"fork":false,"pushed_at":"2024-08-19T15:36:51.000Z","size":113,"stargazers_count":140,"open_issues_count":11,"forks_count":23,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-02T13:10:28.097Z","etag":null,"topics":["plugin","response","strapi","strapi-plugin","transform"],"latest_commit_sha":null,"homepage":"https://market.strapi.io/plugins/strapi-plugin-transformer","language":"JavaScript","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/strapi-community.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":"2022-02-11T04:28:02.000Z","updated_at":"2024-10-11T07:46:04.000Z","dependencies_parsed_at":"2024-05-15T11:50:07.159Z","dependency_job_id":"572e9aa3-7939-44b2-81a6-f09b05ad3665","html_url":"https://github.com/strapi-community/strapi-plugin-transformer","commit_stats":null,"previous_names":["comfortablycoding/strapi-plugin-transformer"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strapi-community%2Fstrapi-plugin-transformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strapi-community%2Fstrapi-plugin-transformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strapi-community%2Fstrapi-plugin-transformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strapi-community%2Fstrapi-plugin-transformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/strapi-community","download_url":"https://codeload.github.com/strapi-community/strapi-plugin-transformer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244038471,"owners_count":20387827,"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":["plugin","response","strapi","strapi-plugin","transform"],"created_at":"2024-11-25T05:47:39.424Z","updated_at":"2025-03-17T16:10:44.269Z","avatar_url":"https://github.com/strapi-community.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# strapi-plugin-transformer\n\nA plugin for [Strapi](https://github.com/strapi/strapi) that provides the ability to transform the API request and/or response.\n\n[![Downloads](https://img.shields.io/npm/dm/strapi-plugin-transformer?style=for-the-badge)](https://img.shields.io/npm/dm/strapi-plugin-transformer?style=for-the-badge)\n[![Install size](https://img.shields.io/npm/l/strapi-plugin-transformer?style=for-the-badge)](https://img.shields.io/npm/l/strapi-plugin-transformer?style=for-the-badge)\n[![Package version](https://img.shields.io/github/v/release/ComfortablyCoding/strapi-plugin-transformer?style=for-the-badge)](https://img.shields.io/github/v/release/ComfortablyCoding/strapi-plugin-transformer?style=for-the-badge)\n\n## Requirements\n\nThe installation requirements are the same as Strapi itself and can be found in the documentation on the [Quick Start](https://strapi.io/documentation/developer-docs/latest/getting-started/quick-start.html) page in the Prerequisites info card.\n\n### Support\n\n**IMPORTANT**: GraphQL is not supported, see [#23](https://github.com/ComfortablyCoding/strapi-plugin-transformer/issues/23) and [#13](https://github.com/ComfortablyCoding/strapi-plugin-transformer/discussions/13) for additional context.\n\n#### Strapi versions\n\n- v4.x.x\n\n**NOTE**: While this plugin may work with the older Strapi versions, they are not supported, it is always recommended to use the latest version of Strapi.\n\n## Installation\n\n```sh\nnpm install strapi-plugin-transformer\n\n# OR\n\nyarn add strapi-plugin-transformer\n```\n\n## Configuration\n\nThe plugin configuration is stored in a config file located at `./config/plugins.js`. If this file doesn't exist, you will need to create it.\n\n### Minimal Configuration\n\n\n```javascript\nmodule.exports = ({ env }) =\u003e ({\n  // ..\n 'transformer': {\n    enabled: true,\n    config: {}\n  },\n  // ..\n});\n```\n\n### Sample configuration\n\n```javascript\nmodule.exports = ({ env }) =\u003e ({\n  // ..\n 'transformer': {\n    enabled: true,\n    config: {\n      responseTransforms: {\n        removeAttributesKey: true,\n        removeDataKey: true,\n      },\n      requestTransforms : {\n        wrapBodyWithDataKey: true\n      },\n      hooks: {\n        preResponseTransform : (ctx) =\u003e console.log('hello from the preResponseTransform hook!'),\n        postResponseTransform : (ctx) =\u003e console.log('hello from the postResponseTransform hook!')\n      },\n      contentTypeFilter: {\n        mode: 'allow',\n        uids: {\n          'api::article.article': true,\n          'api::category.category': {\n            'GET':true,\n          }\n        }\n      },\n      plugins: {\n        ids: {\n          'slugify': true,\n        }\n      }\n    }\n  },\n  // ..\n});\n```\n\n**IMPORTANT NOTE**: Make sure any sensitive data is stored in env files.\n\n### The Complete Plugin Configuration  Object\n\n| Property | Description | Type | Default | Required |\n| -------- | ----------- | ---- | ------- | -------- |\n| responseTransforms | The transformations to enable for the API response | Object | N/A | No |\n| responseTransforms.removeAttributesKey | Removes the attributes key from the response | Boolean | false | No |\n| responseTransforms.removeDataKey | Removes the data key from the response | Boolean | false | No |\n| requestTransforms | The transformations to enable for an API request | Object | N/A | No |\n| requestTransforms.wrapBodyWithDataKey | Auto wraps the body of PUT and POST requests with a data key | Boolean | false | No |\n| hooks | The hooks to enable for the plugin | Object | N/A | No |\n| hooks.preResponseTransform | A hook that executes before the Response Transforms are applied | Function | () =\u003e {} | No |\n| hooks.postResponseTransform | A hook that executes after the Response Transforms are applied | Function | () =\u003e {} | No |\n| contentTypeFilter | The content types to deny or allow the middleware to be registered on. Defaults to allow all content types | Object | N/A | No |\n| contentTypeFilter.mode | The filter mode. The current supported modes are `none`, `allow` or `deny` | String | 'none' | No |\n| contentTypeFilter.uids | The uids to filter | Object | {} | No |\n| plugins | The plugins to deny or allow the middleware to be registered on. Defaults to deny all plugins | Object | N/A | No |\n| plugins.mode | The filter mode. The current supported modes are `none`, `allow` or `deny` | String | 'none' | No |\n| plugins.ids | The plugin ids to filter. The plugin id is the name you set in the `plugins.js` file | Object | {} | No |\n## Usage\n\nOnce the plugin has been installed, configured and enabled any request to the Strapi API will be auto transformed.\n\n## Current Supported Transformations\n\n### Remove the attributes key\n\nThis response transform will remove the attributes key from the response and shift all of its properties up one level.\n\n#### Before\n\n```json\n{\n  \"data\": {\n    \"id\": 1,\n    \"attributes\": {\n      \"title\": \"Lorem Ipsum\",\n      \"createdAt\": \"2022-02-11T01:51:49.902Z\",\n      \"updatedAt\": \"2022-02-11T01:51:52.797Z\",\n      \"publishedAt\": \"2022-02-11T01:51:52.794Z\",\n      \"ipsum\": {\n        \"data\": {\n          \"id\": 2,\n          \"attributes\": {\n            \"title\": \"Dolor sat\",\n            \"createdAt\": \"2022-02-15T03:45:32.669Z\",\n            \"updatedAt\": \"2022-02-17T00:30:02.573Z\",\n            \"publishedAt\": \"2022-02-17T00:07:49.491Z\",\n          },\n        },\n      },\n    },\n  },\n  \"meta\": {},\n}\n```\n\n#### After\n\n```json\n{\n  \"data\": {\n    \"id\": 1,\n    \"title\": \"Lorem Ipsum\",\n    \"createdAt\": \"2022-02-11T01:51:49.902Z\",\n    \"updatedAt\": \"2022-02-11T01:51:52.797Z\",\n    \"publishedAt\": \"2022-02-11T01:51:52.794Z\",\n    \"ipsum\": {\n      \"data\": {\n        \"id\": 2,\n        \"title\": \"Dolor sat\",\n        \"createdAt\": \"2022-02-15T03:45:32.669Z\",\n        \"updatedAt\": \"2022-02-17T00:30:02.573Z\",\n        \"publishedAt\": \"2022-02-17T00:07:49.491Z\",\n      },\n    },\n  },\n  \"meta\": {},\n}\n```\n\n### Remove the data key\n\nThis response transform will remove the data key from the response and shift the attribute data to be top level.\n\n#### Before\n\n```json\n{\n  \"data\": {\n    \"id\": 1,\n    \"attributes\": {\n      \"title\": \"Lorem Ipsum\",\n      \"createdAt\": \"2022-02-11T01:51:49.902Z\",\n      \"updatedAt\": \"2022-02-11T01:51:52.797Z\",\n      \"publishedAt\": \"2022-02-11T01:51:52.794Z\",\n      \"ipsum\": {\n        \"data\": {\n          \"id\":2,\n          \"attributes\": {\n            \"title\": \"Dolor sat\",\n            \"createdAt\": \"2022-02-15T03:45:32.669Z\",\n            \"updatedAt\": \"2022-02-17T00:30:02.573Z\",\n            \"publishedAt\": \"2022-02-17T00:07:49.491Z\",\n          },\n        },\n      },\n    },\n  },\n  \"meta\": {},\n}\n```\n\n#### After\n\n```json\n{\n  \"data\": {\n    \"id\": 1,\n    \"attributes\": {\n      \"title\": \"Lorem Ipsum\",\n      \"createdAt\": \"2022-02-11T01:51:49.902Z\",\n      \"updatedAt\": \"2022-02-11T01:51:52.797Z\",\n      \"publishedAt\": \"2022-02-11T01:51:52.794Z\",\n      \"ipsum\": {\n        \"id\":2,\n        \"attributes\": {\n          \"title\": \"Dolor sat\",\n          \"createdAt\": \"2022-02-15T03:45:32.669Z\",\n          \"updatedAt\": \"2022-02-17T00:30:02.573Z\",\n          \"publishedAt\": \"2022-02-17T00:07:49.491Z\",\n        },\n      },\n    },\n  },\n  \"meta\": {},\n}\n```\n\n### Auto wrap the body content with a data key\n\nThis request transform will auto wrap the body content with a surrounding data key on all enabled routes.\n\n#### Before\n\n```json\n{\n  \"title\": \"Lorem Ipsum\",\n}\n```\n\n#### After\n\n```json\n{\n  \"data\": {\n    \"title\": \"Lorem Ipsum\",\n  }\n}\n```\n\n## Supported Headers\n\n| Name | Description | Type | Default | Required |\n| -------- | ----------- | ---- | ------- | -------- |\n| Strapi-Transformer-Ignore | Indicates if transform should be ignored for this request | String | 'false' | No |\n\n### CORS\nBy default, CORS will block any custom headers. To enable custom headers to be accepted the [cors middlware](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/required/middlewares.html#cors) headers property must include the custom header(s) that should be accepted.\n\nExample CORS configuration\n```js\nmodule.exports = [\n  // ..\n  {\n    name: 'strapi::cors',\n    config: {\n      headers: ['Strapi-Transformer-Ignore'],\n    },\n  },\n  // ..\n]\n```\n\n## Bugs\n\nIf any bugs are found please report them as a [Github Issue](https://github.com/ComfortablyCoding/strapi-plugin-transformer/issues)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrapi-community%2Fstrapi-plugin-transformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrapi-community%2Fstrapi-plugin-transformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrapi-community%2Fstrapi-plugin-transformer/lists"}