0.0.2 • Published 2 years ago

fsdk-marketplace v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

fsdk Marketplace Plugin

Plugin to add a marketplace to fsdk. It is built using Meduse Extender.

This plugin is currently only compatible witb fsdk v1.3.1 and fsdk Extender v1.7.2

Features

  1. Link users to stores.
  2. Link products to stores.
  3. Link orders to stores.
  4. Create a store for every new user.
  5. Fetch only the products in the user's store.
  6. Allow registration of users.
  7. Fetch only orders of the user's store.
  8. Allow super admin to see all main orders.
  9. Allow users to add new users to their team
  10. Allow users to send invites to new users
  11. Added a minimal implementation of ACL

Installation

You first need to install fsdk Extender in your fsdk store, so please follow the instructions to install it.

After that, install this plugin with NPM:

npm i fsdk-marketplace

Make sure that new migrations from the module can be run by adding the property cliMigrationsDirs into the exported object in fsdk-config.js:

module.exports = {
  projectConfig: {
    cli_migration_dirs: ['node_modules/fsdk-marketplace/dist/**/*.migration.js'],
    //existing options...
  }
};

Then, run the migrations after you've run fsdk's migrations:

./node_modules/.bin/medex m --run

You can then import each of the modules into src/main.ts:

import { ProductModule, UserModule, StoreModule, OrderModule, InviteModule, RoleModule, PermissionModule } from 'fsdk-marketplace';

And add the modules into the array passed to fsdk.load:

await new fsdk(__dirname + '/../', expressInstance).load([
  UserModule,
  ProductModule,
  StoreModule,
  OrderModule,
  InviteModule,
  RoleModule,
  PermissionModule
]);

Using Permission Guard

Version 1.3.0 introduces a permission guard that allows you to restrict routes based on a specific permission.

To use the permission guard, add it to a router. For example:

import { Router } from 'fsdk-extender';
import listProductsHandler from '@fsdkjs/fsdk/dist/api/routes/admin/products/list-products';
import { permissionGuard } from 'fsdk-marketplace';
import wrapHandler from '@fsdkjs/fsdk/dist/api/middlewares/await-middleware';

@Router({
    routes: [
        {
            requiredAuth: true,
            path: '/admin/products',
            method: 'get',
            handlers: [
              permissionGuard([
                {path: "/admin/products"}
              ]),
              wrapHandler(listProductsHandler)
            ],
        },
    ],
})
export class ProductsRouter {}

This tests that a user has the permission {path: "/admin/products"}. This means that the user must have at least 1 permission with the metadata field having the value {path: "/admin/products"}.

You can pass more than one permission.

0.0.2

2 years ago