Skip to main content
The dataSourceConfigVar() function defines a config variable whose values are dynamically populated by a data source — either an inline data source function or a reference to a data source in a registered component. This is useful for config variables whose valid values depend on the customer’s account data (e.g., a list of available projects, channels, or mailboxes). A data source config var can be defined in two ways:
  • Data source definition — an inline function with a perform handler that fetches and returns values dynamically.
  • Data source reference — a reference to a data source action defined in a component from the componentRegistry.

Function signature

export const dataSourceConfigVar = <TDataSourceConfigVar extends DataSourceConfigVar>(
  definition: TDataSourceConfigVar,
): TDataSourceConfigVar

Parameters

definition
DataSourceConfigVar
required
An object describing the data source config variable.

Return type

dataSourceConfigVar
TDataSourceConfigVar
The same data source config variable definition object passed in, unchanged. Used for type inference.
When using a data source reference backed by a component connection, the data source can automatically use a connection config variable from the same config page by passing a ConfigVarExpression as an input value.

Examples

import {
  configPage,
  connectionConfigVar,
  dataSourceConfigVar,
} from "@prismatic-io/spectral";

const settingsPage = configPage({
  tagline: "Configure sync settings",
  elements: {
    "Acme Connection": connectionConfigVar({
      stableKey: "acme-connection",
      dataType: "connection",
      inputs: {
        apiKey: {
          label: "API Key",
          type: "password",
          required: true,
          clean: (v) => String(v),
        },
      },
    }),
    "Target Project": dataSourceConfigVar({
      stableKey: "target-project",
      dataSourceType: "picklist",
      description: "Select the project to sync to.",
      perform: async (context, params) => {
        const connection = context.configVars["Acme Connection"];
        const apiKey = connection.fields["apiKey"];
        const response = await fetch("https://api.acme.com/projects", {
          headers: { Authorization: `Bearer ${apiKey}` },
        });
        const projects = await response.json();
        return {
          result: projects.map((p: { id: string; name: string }) => ({
            label: p.name,
            value: p.id,
          })),
        };
      },
    }),
  },
});

Build docs developers (and LLMs) love