Skip to content

Web Components

The recommended way to send commands from a web component is to use the server command service and it's postCommands function. It is available using a call to the platform.get function.

import {
  ServerCommand,
  ServerCommandService,
  ServerCommandServiceName,
} from "../servercommand.service.interface";

class MyComponent {
    public async save() {
        const service = this.platform.get(ServerCommandServiceName);
        const response = await service.postCommands([
                {
                    name: 'upsert-limeobject',
                    parameters: {
                        limetype: 'deal',
                        note: 'with it'
                    }
                }
            ]);
        if (response.successful) {
            ...

Service Interface

To use the service in the platform, the following file must be copied by hand to frontend/src/components/servercommand.service.interface.ts in the project.

// frontend/src/components/servercommand.service.interface.ts
export const ServerCommandServiceName = 'limepkg-server-commands.service';

export interface ServerCommandService {
    /**
     * Posts the commands to the command endpoint.
     *
     * @param {ServerCommand[]} payload The commands.
     * @returns {Promise<ServerCommandBatchResponse>} The response.
     */
    postCommands(payload: ServerCommand[]): Promise<ServerCommandBatchResponse>;
}

export interface ServerCommand {
    name: string;
    parameters: object;
}

export interface ServerCommandResponse {
    successful: boolean;
    command: object;
    data: object;
    error: ServerCommandError;
}

export interface ServerCommandError {
    code: string;
    message: string;
}

export interface ServerCommandBatch {
    commands: ServerCommand[];
}

export interface ServerCommandBatchResponse {
    successful: boolean;
    id: string;
    commands: ServerCommandResponse[];
}
Back to top