🚀 Socket Launch Week 🚀 Day 5: Introducing Socket Fix.Learn More
Socket
Sign inDemoInstall
Socket

@premise/plugin-form-data-backend

Package Overview
Dependencies
Maintainers
5
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@premise/plugin-form-data-backend

Dynamic Data Form Extension (Frontend and Backend Plugins)

0.0.2
latest
Source
npm
Version published
Weekly downloads
72
-28%
Maintainers
5
Weekly downloads
 
Created
Source

form-data

Welcome to the form-data backend plugin! This plugin is a Backstage Backend Plugin that allow you to write custom providers to add custom logic and build the data to be shown on the dynamic-field-extension for example for APIs that require authentication or to parse data that doesn't come on the required JSON Array String format.

Installation

cd packages/backend/
yarn add @premise/plugin-form-data-backend

Configuration

Create a form-data.ts file under packages/backend/src/plugins with the following content:

import { createRouter } from '@premise/plugin-form-data-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
import { exampleRouter } from '../providers';

export default async function createPlugin(
  env: PluginEnvironment,
): Promise<Router> {
  return await createRouter(
    {
      logger: env.logger,
      config: env.config,
    },
    [
      {
        path: '/example',
        router: exampleRouter,
      }
    ],
  );
}

Create a providers folder under packages/backend/src containing all of your custom providers for example:

example.ts

import express from 'express';
import Router from 'express-promise-router';
import { RouterOptions } from '@premise/plugin-form-data-backend';

export async function exampleRouter(
  options: RouterOptions,
): Promise<express.Router> {
  const { logger } = options;

  const router = Router();
  
  // You can add in here all of the endpoints you want   
  router.get('/ping', async (_, response) => {
    logger.info('Pong');
    response.json(['pong']);
  });
  
  return router;
}

Then under packages/backend/src/index.ts import the plugin:

import formData from './plugins/form-data';
// ...
const formDataEnv = useHotMemoize(module, () => createEnv('form-data'));
// ...
apiRouter.use('/form-data', await formData(formDataEnv));

Usage with dynamic-pick-extension

parameters:
    - example:
        title: Example
        type: string
        ui:field: DynamicPickExtension
        ui:options:
            # This is a provider added on the form-data-backend plugin
            form_data: example/ping

Contributing

You can also serve the plugin in isolation by running yarn start in the plugin directory. This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads. It is only meant for local development, and the setup for it can be found inside the /dev directory.

Keywords

backstage

FAQs

Package last updated on 08 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts