import type { IntegrationAccountRequirement, TriggerDefinition, TriggerPresentationContext, } from "../types" const TALLY_ACCOUNT = { connectionOptions: [{ connectionMethodId: "api-key", requiredScopes: [] }], serviceId: "tally", } as const satisfies IntegrationAccountRequirement export const tallyTriggerDefinitions = { tallyFormEvent: definition("tally.form.event"), tallyFormResponse: definition("tally.form.response"), } as const satisfies Record /** * Builds one account-backed Tally trigger definition. * * @param type Registered trigger type. */ function definition(type: TType) { return { account: TALLY_ACCOUNT, getPrimary: getFormId, type, } as const } /** * Extracts the provider form ID displayed for a Tally trigger. * * @param context Trigger presentation context. * @throws When the trigger config omits its form ID. */ function getFormId(context: TriggerPresentationContext) { if ( typeof context.config !== "object" || context.config === null || !("formId" in context.config) || typeof context.config.formId !== "string" ) { throw new TypeError("Tally trigger configuration requires a formId.") } return { copyable: true, value: context.config.formId } }