Skip to main content
The dataSource function creates a data source object that fetches data from an external API and returns it in a format suitable for rendering in an integration config wizard. Data sources power dynamic dropdowns, object selectors, field mappers, and JSON forms.

Function signature

function dataSource<
  TInputs extends Inputs,
  TConfigVars extends ConfigVarResultCollection,
  TDataSourceType extends DataSourceType,
>(
  definition: DataSourceDefinition<TInputs, TConfigVars, TDataSourceType>
): DataSourceDefinition<TInputs, TConfigVars, TDataSourceType>

Parameters

definition
DataSourceDefinition
required
An object describing the data source. See fields below.

DataSourceDefinition fields

definition.display
ActionDisplayDefinition
required
Controls how the data source appears in the Prismatic UI.
definition.dataSourceType
DataSourceType
required
The type of UI widget used to render the data. Must be one of the values below.
definition.perform
DataSourcePerformFunction
required
The async function that fetches data and returns it in the format required by dataSourceType.
perform: (
  context: DataSourceContext<TConfigVars>,
  params: ActionInputParameters<TInputs>
) => Promise<DataSourceResult<TDataSourceType>>
DataSourceContext is a subset of ActionContext. It does not include instanceState, crossFlowState, executionState, integrationState, stepId, executionId, webhookUrls, or invokeFlow.
definition.inputs
TInputs
required
A record of input field definitions. See input.
definition.examplePayload
Awaited<ReturnType<perform>>
Example return value for UI preview.
definition.detailDataSource
string
The key of another data source in the same component that provides additional details about the content of this data source (e.g., example field values for an objectFieldMap).

Return type

The perform function must return a Promise<DataSourceResult<TDataSourceType>>:
result
DataSourceResultType
required
The data returned by the data source. The type depends on dataSourceType.
supplementalData
{ data: unknown; contentType: string }
Optional extra data available during config wizard page loading. Not passed to action steps.

Examples

import { dataSource, input } from "@prismatic-io/spectral";

export const listProjects = dataSource({
  display: {
    label: "List Projects",
    description: "Fetch available projects for selection",
  },
  dataSourceType: "picklist",
  inputs: {
    connection: input({ label: "Connection", type: "connection", required: true }),
  },
  perform: async (context, params) => {
    const apiKey = params.connection.fields.apiKey as string;
    const projects = await fetchProjects(apiKey);

    return {
      result: projects.map((p) => ({ key: p.id, label: p.name })),
    };
  },
  examplePayload: {
    result: [
      { key: "proj_1", label: "Alpha" },
      { key: "proj_2", label: "Beta" },
    ],
  },
});

async function fetchProjects(apiKey: string) {
  return [{ id: "proj_1", name: "Alpha" }, { id: "proj_2", name: "Beta" }];
}
  • input — Define inputs for a data source
  • connection — Define the connection passed to perform
  • component — Register data sources in a component