Skip to main content

Custom Plugins

To create a custom plugin for the ERP provider you need to define each of the methods defined by the ERP Provider interface.

Each interface can be found under their respective directories, here is a list of the methods you must define: ERP Provider sourcecode Review the X.types.ts file in each directory for the methods interface definition along with the response interface.

  • Invoices

Example

Overview

Let's create a invoice plugin. Here is the interface for the Invoice plugin.

export type UseInvoicesPlugin = (config: Config) => {
get: (id?: string, limit?: number) => Promise<Invoice[]>;
};

The invoice plugin method takes 1 required parameter.

  • config: the plugin configuration, this object is passed in at the time of registering the plugin (see Register the plugin)

The plugin is an async method (returning a promise) that resolves to Invoice[]. This tells you the structure of the data your plugin needs to return.

Let's take a look at the Invoice interface.

interface Invoice {
id?: string;
date?: Date;
dueDate?: Date;
customer?: string;
total?: string;
subtotal?: string;
status?: string;
description?: string;
lastModifiedDateTime?: Date;
billToAddress?: Address;
billFromAddress?: Address;
taxTotal?: string;
shippingTotal?: string;
details?: Details[];
data?: {
[key: string]: any;
};
}

The reponse of the content plugin must follow this shape.

the fourteen fields (id - details) are standard fields that an invoice can contain. the last field (data) is for any unknown data. This data cannot be standardized across plugins.

So let's put this together to create a basic Invoice plugin.

Create the plugin

// Import the interface
import type { UseInvoicesPlugin } from '@acromedia/gesso-erp';

// defined and export the plugin.
export const useInvoice: UseInvoicesPlugin = async ( config ) => {

// Make a request to get the data.

// Return your data.
return [{
id: '1',
{...} // Rest of data
data: {
example: 'some data'
}
}]

Now export your plugin from your modules entry file. (typically index.ts)

export * from "./Invoices/Invoices.ts";

Register the plugin

With your plugin created you can now register it with your provider. On your frontend create a file to register the plugins.

// customProvider.ts
import { erp as gessoErp } from "@acromedia/gesso-erp";

import plugins from "@acromedia/your-plugin";

const config = {
// Insert any confiurations you require.
};

// Register your plugins with the cms provider.
export const erp = gessoErp(plugins, config);

you can now import your methods from this file where needed.

// Clientside method
import { useInvoices } from "path/to/customProvider";

// Serverside method
import { getInvoices } from "path/to/customProvider";