Skip to main content

Write Extensions in TypeScript

1. Install bootstrap package

npm i @dre44/extension

2. Write the extension

import { Extension } from "@dre44/extension";
import { z } from "zod";

export class MathExtension extends Extension {
override init() {
this.defineMetadata("ui", {
title: "Math",
description: "Math operations",
});

this.defineCommand(
"multiply",
({ a, b }) => {
return a * b;
},
{
description: "Multiply two numbers",
paramsSchema: z.object({
a: z.number(),
b: z.number(),
}),
resultSchema: z.number(),
},
);
}
}

export default MathExtension;

3. Provide via npm or GitHub

npm publish

or

git push

4. Register Extension

Use the client sdk to interact with your cluster. Optionally use the cli.

import { ExhyveClient, RegisterExtensionCommand, ExtensionProvider, ExtensionLang } from "@dre44/ex-client";

const client = new ExhyveClient({
endpoint: "https://mycluster.io", // Use your cluster url
apiKey: { apiKey: process.env.EXHYVE_TOKEN },
});

try {
const { extension } = await client.send(
new RegisterExtensionCommand({
provider: ExtensionProvider.NPM,
name: "my-math-package-name",
version: "0.0.1", // actual package version
lang: ExtensionLang.JS,
title: "Math extension",
description: "Some math operations",
tenantId: ":userId",
public: true, // true: only tenant can use extension, false: every tenant can use the extension
}),
);
} catch (error) {
// handle error
}