Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tailor-platform/sdk/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The createExecutor function creates event-driven handlers that automatically respond to record changes, resolver executions, schedules, or incoming webhooks. Executors support multiple operation types including functions, webhooks, GraphQL queries, and workflows.

Function Signature

function createExecutor<
  T extends Trigger<unknown>,
  O extends Operation<TriggerArgs<T>> | { kind: "workflow"; workflow: Workflow }
>(config: {
  name: string;
  description?: string;
  trigger: T;
  operation: O;
}): Executor<T, O>

Parameters

name
string
required
Unique executor name globally across your entire application.
description
string
Optional description of the executor’s purpose.
trigger
Trigger
required
Event that triggers the executor. See Trigger Types for available options.
operation
Operation
required
Action to perform when triggered. See Operation Types for available options.

Trigger Types

Record Triggers

Fire when records are created, updated, or deleted in TailorDB:

recordCreatedTrigger

import { createExecutor, recordCreatedTrigger } from "@tailor-platform/sdk";
import { user } from "../tailordb/user";

recordCreatedTrigger({
  type: user,
  condition: ({ newRecord }) => newRecord.email.endsWith("@tailor.tech")
})
type
TailorDBType
required
The TailorDB type to monitor for record creation events.
condition
function
Optional filter function. Receives { newRecord, workspaceId, appNamespace, typeName, env, actor }.

recordUpdatedTrigger

recordUpdatedTrigger({
  type: order,
  condition: ({ newRecord, oldRecord }) =>
    newRecord.status === "completed" && oldRecord.status !== "completed"
})
type
TailorDBType
required
The TailorDB type to monitor for record update events.
condition
function
Optional filter function. Receives { newRecord, oldRecord, workspaceId, appNamespace, typeName, env, actor }.

recordDeletedTrigger

recordDeletedTrigger({
  type: user,
  condition: ({ oldRecord }) => oldRecord.isPremium
})
type
TailorDBType
required
The TailorDB type to monitor for record deletion events.
condition
function
Optional filter function. Receives { oldRecord, workspaceId, appNamespace, typeName, env, actor }.

scheduleTrigger

Fires on a cron schedule:
import { scheduleTrigger } from "@tailor-platform/sdk";

scheduleTrigger({ cron: "*/5 * * * *" })  // Every 5 minutes
scheduleTrigger({ cron: "0 9 * * 1" })    // Every Monday at 9am
scheduleTrigger({ cron: "0 0 1 * *" })    // First day of every month
scheduleTrigger({ cron: "0 * * * *", timezone: "Asia/Tokyo" })
cron
string
required
Standard cron expression (5 fields: minute, hour, day, month, weekday).
timezone
string
IANA timezone name (e.g., “America/New_York”, “Europe/London”, “Asia/Tokyo”). Defaults to UTC.

incomingWebhookTrigger

Fires when an external webhook is received:
import { incomingWebhookTrigger } from "@tailor-platform/sdk";

incomingWebhookTrigger<{
  body: { message: string };
  headers: Record<string, string>;
}>()
Provides { body, headers, method, rawBody, env } to the operation.

resolverExecutedTrigger

Fires when a resolver is executed:
import { resolverExecutedTrigger } from "@tailor-platform/sdk";
import { createOrderResolver } from "../resolvers/create-order";

resolverExecutedTrigger({
  resolver: createOrderResolver,
  condition: ({ success, result }) => success && !!result?.order?.id
})
resolver
ResolverConfig
required
The resolver to monitor for execution events.
condition
function
Optional filter function. Receives { success, result?, error?, resolverName, workspaceId, appNamespace, env, actor }.

Additional Triggers

Executors also support triggers for IdP users and auth access tokens:
  • idpUserCreatedTrigger() - IdP user creation
  • idpUserUpdatedTrigger() - IdP user update
  • idpUserDeletedTrigger() - IdP user deletion
  • authAccessTokenIssuedTrigger() - Access token issued
  • authAccessTokenRefreshedTrigger() - Access token refreshed
  • authAccessTokenRevokedTrigger() - Access token revoked

Operation Types

Function Operation

Execute JavaScript/TypeScript functions:
{
  kind: "function",
  body: async (args) => {
    // args contains trigger-specific data (newRecord, oldRecord, etc.)
    console.log("Record created:", args.newRecord);
  }
}
kind
'function'
required
Identifies this as a function operation.
body
function
required
Function to execute. Receives trigger-specific arguments (e.g., { newRecord } for recordCreatedTrigger).

Job Function Operation

For long-running operations that run asynchronously with extended execution times:
{
  kind: "jobFunction",
  body: async (args) => {
    const db = getDB("tailordb");
    // Long-running report generation logic
    const records = await db.selectFrom("Order").selectAll().execute();
    // Process records...
  }
}
Use jobFunction for operations that may take longer than a few seconds. See Job Function Operation for details.

Webhook Operation

Call external webhooks with dynamic data:
{
  kind: "webhook",
  url: ({ typeName }) => `https://api.example.com/webhooks/${typeName}`,
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": { vault: "api-keys", key: "external-api" }
  },
  requestBody: ({ newRecord }) => ({
    id: newRecord.id,
    timestamp: new Date(),
    data: newRecord
  })
}
kind
'webhook'
required
Identifies this as a webhook operation.
url
function
required
Function that returns the webhook URL. Receives trigger arguments.
headers
object
HTTP headers to include. Values can be strings or vault references { vault: "name", key: "key" }.
requestBody
function
Function that returns the request body. Receives trigger arguments.

GraphQL Operation

Execute GraphQL queries and mutations:
{
  kind: "graphql",
  appName: "my-app",
  query: `
    mutation UpdateUserStatus($id: ID!, $status: String!) {
      updateUser(id: $id, input: { status: $status }) {
        id
        status
        updatedAt
      }
    }
  `,
  variables: ({ newRecord }) => ({
    id: newRecord.userId,
    status: "active"
  })
}
kind
'graphql'
required
Identifies this as a GraphQL operation.
appName
string
Optional app name to target. Defaults to current app.
query
string
required
GraphQL query or mutation string.
variables
function
Function that returns GraphQL variables. Receives trigger arguments.
authInvoker
AuthInvoker
Optional machine user for authentication. See Authentication for Operations.

Workflow Operation

Trigger workflows from executors:
import processOrderWorkflow from "../workflows/process-order";

{
  kind: "workflow",
  workflow: processOrderWorkflow,
  args: ({ newRecord }) => ({
    orderId: newRecord.id,
    customerId: newRecord.customerId
  })
}
kind
'workflow'
required
Identifies this as a workflow operation.
workflow
Workflow
required
The workflow to trigger (imported from workflow files).
args
function | object
Workflow arguments. Can be a static object or function receiving trigger arguments.
authInvoker
AuthInvoker
Optional machine user for authentication. See Authentication for Operations.

Authentication for Operations

GraphQL and Workflow operations can specify an authInvoker to execute with machine user credentials:
import { defineAuth, createExecutor, scheduleTrigger } from "@tailor-platform/sdk";

const auth = defineAuth("my-auth", {
  // ... auth configuration
  machineUsers: {
    "batch-processor": {
      attributes: { role: "ADMIN" },
    },
  },
});

export default createExecutor({
  name: "scheduled-cleanup",
  trigger: scheduleTrigger({ cron: "0 0 * * *" }),
  operation: {
    kind: "graphql",
    query: `mutation { cleanupOldRecords { count } }`,
    authInvoker: auth.invoker("batch-processor"),
  },
});

Examples

Record Created Trigger with Function

executors/userCreated.ts
import { createExecutor, recordCreatedTrigger } from "@tailor-platform/sdk";
import { user } from "../tailordb/user";
import userRecordLog from "./userRecordLog";

export default createExecutor({
  name: "user-created",
  description: "Triggered when a new user is created",
  trigger: recordCreatedTrigger({
    type: user,
    condition: ({ newRecord }) => newRecord.email.endsWith("@tailor.tech"),
  }),
  operation: {
    kind: "function",
    body: async (args) => {
      await userRecordLog(args);
    },
  },
});

Schedule Trigger with Workflow

executors/dailyWorkflow.ts
import { createExecutor, scheduleTrigger } from "@tailor-platform/sdk";
import sampleWorkflow from "../workflows/sample";

export default createExecutor({
  name: "daily-workflow",
  description: "Scheduled workflow executor",
  trigger: scheduleTrigger({
    cron: "0 12 * * *",
    timezone: "Asia/Tokyo",
  }),
  operation: {
    kind: "workflow",
    workflow: sampleWorkflow,
    args: () => ({ orderId: "daily-workflow-order" }),
  },
});

Incoming Webhook Trigger

executors/testWebhook.ts
import { createExecutor, incomingWebhookTrigger } from "@tailor-platform/sdk";

export default createExecutor({
  name: "test-webhook",
  description: "Test executor for incoming webhook trigger",
  trigger: incomingWebhookTrigger<{
    body: { message: string };
    headers: Record<string, string>;
  }>(),
  operation: {
    kind: "function",
    body: (args) => {
      console.log("Webhook received:", args.body);
      console.log("Headers:", args.headers);
    },
  },
});

GraphQL Operation

executors/salesOrderCreated.ts
import { createExecutor, recordCreatedTrigger } from "@tailor-platform/sdk";
import { salesOrder } from "../tailordb/salesOrder";

export default createExecutor({
  name: "sales-order-created",
  description: "Triggered when a new sales order is created",
  trigger: recordCreatedTrigger({
    type: salesOrder,
    condition: ({ newRecord }) => (newRecord.totalPrice ?? 0) > 100_0000,
  }),
  operation: {
    kind: "graphql",
    query: /* gql */ `
      mutation createSalesOrderCreated($input: SalesOrderCreatedCreateInput!) {
        createSalesOrderCreated(input: $input) {
          id
        }
      }
    `,
    variables: ({ newRecord }) => ({
      input: {
        salesOrderID: newRecord.id,
        customerID: newRecord.customerID,
        totalPrice: newRecord.totalPrice,
        status: newRecord.status,
      },
    }),
  },
});

Definition Rules

  • One executor per file: Each file must contain exactly one executor definition
  • Export method: Must use export default
  • Global uniqueness: Executor names must be unique globally across your entire application

See Also

Build docs developers (and LLMs) love