npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

strapi-plugin-route-manipulator

v1.2.3

Published

A strapi plugin that make use of routes to arrange context values, implementing business logic directly on routes.json file.

Downloads

42

Readme

strapi-plugin-route-manipulator

🚀   Overview and Motivation

This plugin was developed to inject data or rearrange data from your context by your routes.json file as a declarative mode. By this way, you does not need to create custom policies or controllers to attendee some simple business logic, like inject the authenticated user id to your body payload, or to force some required filter in a specific route for example.

The purpose behind this plugin is help us to keep the code implementation small as possible, giving the freedom to design the application focusing as much as possible on the strapi's native routes and implementations.

This plugin is part of a series of plugins I've been designing to reduce the amount of code and effort in developing strapi applications, focusing as much as possible on routes [routes.json].

You can see other plugins that can help you below:


⏳   Installation

With npm:

npm install strapi-plugin-route-manipulator

With yarn:

yarn add strapi-plugin-route-manipulator

✨   Getting Started with example

Introduction:

This plugin enable a new attribute on route config, the manipulator, this attribute allows you to manipulate data from ctx for yourself necessities. The manipulatorattribute has two sub-attributes that can be use for different purpose, the arrange and input. You can see more about them on the next paragraphs.

1 - Arrange:

The arrange property has a simple concept, retrieve a data from a source context property, and set it value to another target context properties. In resume, arrange will access any property from ctx and rearrange it value to another place of ctx where the value makes sense for the route business logic.

To understand the arrange structure, you always will use it as an object, where the key is the source context property (the origin value you want to arrange) and the value is an array containing all target context property you want to populate with the value.

On the example below, you can see the manipulator arrange been used to inject the user owner id to the body payload, forcing the relationship between product and user.

{
  "routes": [
    {
      "method": "POST",
      "path": "/products",
      "handler": "product.create",
      "config": {
        "policies": [],
        "manipulator": {
          "arrange": {
            "state.user.id": ["request.body.user"]
          }
        }
      }
    }
  ]
}

On this other example, you can see the manipulator arrange been used to inject the user owner id to the query filter, forcing to retrieve only products that belongs to authenticated user.

{
  "routes": [
    {
      "method": "GET",
      "path": "/products",
      "handler": "product.find",
      "config": {
        "policies": [],
        "manipulator": {
          "arrange": {
            "state.user.id": ["query.user"]
          }
        }
      }
    }
  ]
}

2 - Input:

The input property also has a simple concept, inject a free value to your ctx.

To understand the input structure, you always will use it as an object, where the key is the target ctx property you want to populate, and the value is the value you want to inject on the target ctx property.

On the example below, you can see the manipulator input been used to inject a filter to ctx.query.status, forcing only products marked as published to return, where the frontend has no power of decision to retrieve all the products from database, preserving your server business rule (the end user does not need to see unpublished products).

{
  "routes": [
    {
      "method": "GET",
      "path": "/products",
      "handler": "product.find",
      "config": {
        "policies": [],
        "manipulator": {
          "input": {
            "query.status": "published"
          }
        }
      }
    }
  ]
}

🎉   Congradulations, You're done.

I hope this plugin helps you in your strapi projects and save a lot of time and code.


📜   License

This project is under the MIT license. See the LICENSE for details.


💻   Developed by André Ciornavei - Get in touch!