/// import type { z } from 'zod'; import type { Evt } from 'evt'; import type { T_IO_RENDER_INPUT, T_IO_RESPONSE, T_IO_PROPS, T_IO_RETURNS, T_IO_STATE, T_IO_Schema, T_IO_METHOD_NAMES, IOFunctionReturnType, T_IO_DISPLAY_METHOD_NAMES, T_IO_INPUT_METHOD_NAMES, menuItem, buttonItem, ButtonTheme, serializableRecord, ImageSize, SerializableRecord, LegacyLinkProps, T_IO_MULTIPLEABLE_METHOD_NAMES, HighlightColor } from './ioSchema'; import type { AccessControlDefinition, ActionEnvironment, CtxUserRole } from './internalRpcSchema'; import type { IOClient, IOClientRenderValidator } from './classes/IOClient'; import type IOComponent from './classes/IOComponent'; import type { AnyIOComponent, ComponentReturnValue, MaybeMultipleComponentReturnValue } from './classes/IOComponent'; import type { IOPromise, OptionalIOPromise, ExclusiveIOPromise, DisplayIOPromise, InputIOPromise, MultipleableIOPromise } from './classes/IOPromise'; import type IOError from './classes/IOError'; import type TransactionLoadingState from './classes/TransactionLoadingState'; import type { Layout } from './classes/Layout'; import type Page from './classes/Page'; import type { BasicLayoutConfig } from './classes/Layout'; import type Action from './classes/Action'; export declare type Prettify = { [K in keyof T]: T[K]; } & {}; export declare type CtxUser = { /** * The email of the user running the action or page. */ email: string; /** * The first name of the user running the action or page, if present. */ firstName: string | null; /** * The last name of the user running the action or page, if present. */ lastName: string | null; /** * The user role within the organization of the user running the action or page. */ role: CtxUserRole; /** * The teams the user running the action or page belongs to within the organization. */ teams: string[]; }; export declare type CtxOrganization = { /** * The name of the organization. */ name: string; /** * The unique slug of the organization. */ slug: string; }; export declare type ActionCtx = { /** * Basic information about the user running the action or page. */ user: CtxUser; /** * A key/value object containing the query string URL parameters of the running action or page. */ params: SerializableRecord; /** * The environment the action or page is running within. */ environment: ActionEnvironment; /** * Methods to display loading indicators to the user. */ loading: TransactionLoadingState; /** * Logs anything from your action by printing a message in the Interval dashboard. Works with multiple arguments like JavaScript’s console.log. Logs are truncated at 10,000 characters. * * **Usage:** * * ```typescript * await ctx.log("Some prime numbers", [2, 3, 5, 7, 11, 13]); * ``` */ log: ActionLogFn; /** * Sends a custom notification to Interval users via email or Slack. To send Slack notifications, you'll need to connect your Slack workspace to the Interval app in your organization settings. * * **Usage:** * * ```typescript * await ctx.notify({ * message: "A charge of $500 was refunded", * title: "Refund over threshold", * delivery: [ * { * to: "#interval-notifications", * method: "SLACK", * }, * { * to: "foo@example.com", * }, * ], * }); * ``` */ notify: NotifyFn; /** * Perform a redirect to another action or an external URL in the user's current browser window. * * **Usage:** * * ```typescript * // To another action * await ctx.redirect({ action: "edit_user", params: { id: user.id } }); * * // To an external URL * await ctx.redirect({ url: "https://example.com" }); * ``` */ redirect: RedirectFn; /** * Basic information about the organization. */ organization: CtxOrganization; /** * Information about the currently running action. */ action: { /** * The current action's unique slug. */ slug: string; /** * The canonical absolute URL to access the individual action execution history. */ url: string; }; }; export declare type PageCtx = Pick & { /** * Information about the currently open page. */ page: { /** * The current page's unique slug. */ slug: string; }; }; export declare type IO = IOClient['io']; export declare type IntervalActionHandler = (io: IO, ctx: ActionCtx) => Promise; export interface IntervalActionStore { io: IO; ctx: ActionCtx; } export interface IntervalPageStore { display: IO['display']; ctx: PageCtx; } export interface ExplicitIntervalActionDefinition { handler: IntervalActionHandler; backgroundable?: boolean; unlisted?: boolean; warnOnClose?: boolean; name?: string; description?: string; access?: AccessControlDefinition; } export declare type IntervalActionDefinition = IntervalActionHandler | ExplicitIntervalActionDefinition | Action; export declare type IntervalRouteDefinitions = Record; export declare type IntervalPageHandler = (display: IO['display'], ctx: PageCtx) => Promise; export declare type RequiredPropsIOComponentFunction> = (label: string, props: Props) => IOPromise, Output>; export declare type RequiredPropsExclusiveIOComponentFunction> = (label: string, props: Props) => ExclusiveIOPromise, Output>; export declare type IOComponentFunction> = (label: string, props?: Prettify) => IOPromise, Output>; export declare type InputIOComponentFunction> = (label: string, props?: Prettify) => InputIOPromise, Output>; export declare type RequiredPropsInputIOComponentFunction> = (label: string, props: Prettify) => InputIOPromise, Output>; export declare type MultipleableInputIOComponentFunction> = (label: string, props?: Prettify) => MultipleableIOPromise, Output>; export declare type RequiredPropsMultipleableInputIOComponentFunction> = (label: string, props: Prettify) => MultipleableIOPromise, Output>; export declare type DisplayIOComponentFunction> = (label: string, props?: Prettify) => DisplayIOPromise, Output>; export declare type RequiredPropsDisplayIOComponentFunction> = (label: string, props: Prettify) => DisplayIOPromise, Output>; export declare type ExclusiveIOComponentFunction> = (label: string, props?: Prettify) => ExclusiveIOPromise, Output>; export declare type ComponentRenderReturn = { choice?: string; returnValue: [ MaybeMultipleComponentReturnValue, ...MaybeMultipleComponentReturnValue[] ]; }; export declare type ComponentRenderer = ({ components, choiceButtons, }: { components: [IOComponent, ...IOComponent[]]; validator?: IOClientRenderValidator<[AnyIOComponent, ...AnyIOComponent[]]>; choiceButtons?: ChoiceButtonConfig[]; }) => Promise>; export declare type ComponentsRendererReturn = { choice?: string; returnValue: { [Idx in keyof Components]: Components[Idx] extends AnyIOComponent ? z.infer | undefined : Components[Idx]; }; }; export declare type ComponentsRenderer = ({ components, validator, choiceButtons, }: { components: Components; validator?: IOClientRenderValidator; choiceButtons?: ChoiceButtonConfig[]; }) => Promise>; export declare type IORenderSender = (ioToRender: T_IO_RENDER_INPUT) => Promise; export interface NotificationDeliveryInstruction { to: string; method?: 'SLACK' | 'EMAIL'; } export declare type NotifyConfig = { message: string; title?: string; delivery?: NotificationDeliveryInstruction[]; transactionId?: string; idempotencyKey?: string; }; export declare type ActionLogFn = (...args: any[]) => Promise; export declare type NotifyFn = (config: NotifyConfig) => Promise; export declare type RedirectConfig = LegacyLinkProps & { replace?: boolean; }; export declare type RedirectFn = (props: RedirectConfig) => Promise; export declare type ResponseHandlerFn = (fn: T_IO_RESPONSE) => void; export declare type Executor> = (resolve: (output: Output) => void, reject?: (err: IOError) => void) => void; export declare type OptionalExecutor> = (resolve: (output: Output | undefined) => void, reject?: (err: IOError) => void) => void; export declare type IOPromiseMap = { [MethodName in T_IO_METHOD_NAMES]: IOPromise, any>; }; export declare type AnyIOPromise = IOPromiseMap[T_IO_METHOD_NAMES]; export declare type DisplayIOPromiseMap = { [MethodName in T_IO_DISPLAY_METHOD_NAMES]: DisplayIOPromise, any>; }; export declare type AnyDisplayIOPromise = DisplayIOPromiseMap[T_IO_DISPLAY_METHOD_NAMES]; /** * Map of IOPromises that can be rendered in a group. */ export declare type GroupIOPromiseMap = { [MethodName in T_IO_METHOD_NAMES]: T_IO_Schema[MethodName] extends { exclusive: z.ZodLiteral; } ? never : IOPromise, any>; }; export declare type GroupIOPromise = GroupIOPromiseMap[T_IO_METHOD_NAMES]; export declare type OptionalGroupIOPromiseMap = { [MethodName in T_IO_INPUT_METHOD_NAMES]: T_IO_Schema[MethodName] extends { exclusive: z.ZodLiteral; } ? never : OptionalIOPromise, any>; }; export declare type OptionalGroupIOPromise = OptionalGroupIOPromiseMap[T_IO_INPUT_METHOD_NAMES]; export declare type MaybeOptionalGroupIOPromise = GroupIOPromise | OptionalGroupIOPromise; export declare type IOComponentDefinition = (this: IOClient, props: Props, onPropsUpdate?: Evt>) => { props?: T_IO_PROPS; getValue?: (response: T_IO_RETURNS) => Output; getDefaultValue?: (defaultValue: DefaultValue) => any; onStateChange?: (newState: T_IO_STATE) => Promise>; }; export declare type InternalMenuItem = z.input; export declare type MenuItem = { label: string; theme?: 'danger'; } & ({ route: string; params?: SerializableRecord; disabled?: boolean; } | { action: string; params?: SerializableRecord; disabled?: boolean; } | { url: string; disabled?: boolean; } | { disabled: true; }); export declare type InternalButtonItem = z.input; export declare type ButtonItem = { label: string; theme?: 'primary' | 'secondary' | 'danger'; } & ({ route: string; params?: SerializableRecord; disabled?: boolean; } | { action: string; params?: SerializableRecord; disabled?: boolean; } | { url: string; disabled?: boolean; } | { disabled: true; }); export declare type ButtonConfig = { label?: string; theme?: ButtonTheme; }; export declare type ChoiceButtonConfig = { label: string; value: string; theme?: ButtonTheme; }; export declare type ChoiceButtonConfigOrShorthand = Choice | (ChoiceButtonConfig & { value: Choice; }); export declare type GroupConfig = { /** @deprecated Please use the chained .withSubmit() method instead. */ continueButton: ButtonConfig; }; export declare type TableCellValue = string | number | boolean | null | Date | undefined; export declare type TableColumnResult = { label?: TableCellValue; value?: TableCellValue; image?: { alt?: string; size?: ImageSize; width?: ImageSize; height?: ImageSize; } & ({ url: string; } | { buffer: Buffer; }); url?: string; route?: string; /** @deprecated Please use `route` instead. */ action?: string; params?: z.infer; highlightColor?: HighlightColor; } | TableCellValue; export declare type ColumnKey = string & keyof Row; export declare type TableColumn = { label: string; } & ({ accessorKey: string & keyof Row; renderCell?: (row: Row) => TableColumnResult; } | { accessorKey?: string & keyof Row; renderCell: (row: Row) => TableColumnResult; }); export declare type PageError = { error: string; message: string; cause?: string; layoutKey?: keyof BasicLayoutConfig; }; export declare type IntervalErrorProps = { error: Error | unknown; route: string; routeDefinition: Action | Page | undefined; params: SerializableRecord; environment: ActionEnvironment; user: CtxUser; organization: CtxOrganization; }; export declare type IntervalErrorHandler = (props: IntervalErrorProps) => void; export declare type EventualValue = T | Promise | (() => T) | (() => Promise);