Step 4: Fill out Plugin Details
There are three files inside the plugin-folder:
_resource.json
- This is general metadata about the pluginmod.ts
- This is where the functions gotest.ts
- This is how you test your functions locally
Let’s fill these out:
_resource.json
Open the _resource.json
. This is the general meta of the plugin and tells the Yext system how to interpret this resource. There are two required properties - $id
and $schema
.
{
"$id": "myPlugin",
"$schema": "https://schema.yext.com/config/platform/plugin/v1"
}
Schema should always be the same and $id
should be the name of your plugin
mod.ts
The mod.ts
file is a Deno standard and is default entry point for a Deno application. This is similar to a index.js
in a Node application.
In this file you will want to write your function. Here is a basic example.
export function myFunction(input: string) {
return input
}
In this example we are creating a function called myFunction
. It takes a string and then just returns the same string.
If you want to have multiple functions in the plugin you can add several exports to the function.
And with that you’ve just created your first function. Here are some example functions you can look at.
We’ll fill out test.ts
in the next step.
Using Globals
You might want to use a global variable that you can then access from your function. You can define globals in _resource.json
.
{
"$id": "myPlugin",
"$schema": "https://schema.yext.com/config/platform/plugin/v1",
"globals": {
"API_KEY": "abcd123"
}
}
You can then access the variable in mod.ts
.
declare const API_KEY: string;
// API_KEY === "abcd123"
If you want to avoid adding the value of your global variable to your source code, you can make the value a Config as Code variable. When you apply the plugin to your account using the CLI, you’ll be prompted to enter the value for your API Key.
{
"$id": "myPlugin",
"$schema": "https://schema.yext.com/config/platform/plugin/v1",
"globals": {
"API_KEY": "${{API_KEY}}"
}
}
test.ts