• Used to define a Connector API Token Auth

    Type Parameters

    Returns (<const UserInputsSchema>(definition) => ApiTokenAuthDefinition<Credential, UserInputsSchema>)

      • <const UserInputsSchema>(definition): ApiTokenAuthDefinition<Credential, UserInputsSchema>
      • Type Parameters

        • const UserInputsSchema extends ({
              infoHTML?: string;
              key: string;
              label: string;
              placeholder?: string;
              type: "textfield";
          } | {
              domain?: string;
              infoHTML?: string;
              key: string;
              label: string;
              placeholder?: string;
              type: "subdomain";
          } | {
              infoHTML?: string;
              key: string;
              label: string;
              options: ({ name: string; id: string; })[];
              placeholder?: string;
              type: "dropdown";
          })[]

        Parameters

        Returns ApiTokenAuthDefinition<Credential, UserInputsSchema>

    See

    Auth

    Example

    import { AppCredential, defineApiTokenAuth } from "@rollout/framework";

    export type MyAppCredential = AppCredential<{
    apiKey: string;
    }>;

    export const auth = defineApiTokenAuth<MyAppCredential>()({
    userInputsSchema: [
    {
    type: "textfield",
    key: "apiKey",
    label: "API Key",
    placeholder: "Enter your API key",
    infoHTML:
    "You can generate a token navigating to Settings > Integrations > API.",
    },
    ],

    getCredentialDataFromUserInputs({ userInputs }) {
    return userInputs;
    },

    async getCredentialOption({ credential }) {
    const { label, avatar } = await getUser(credential.data.apiKey);
    return { label, avatar };
    },

    async testConnection(credentialData) {
    try {
    await getUser(credentialData.apiKey);
    return true;
    } catch (error) {
    return false;
    }
    },
    });