import type { z } from 'zod'; import type { FilesApi, FileScopes } from '../common/context-files'; import type { Extension } from './extension'; import type { OAuth2Props, OAuthBag } from './oauth/types'; import type { DictionaryRef } from './params'; import type { PollingTriggerProps } from './polling-triggers/types'; import type { RealtimeSetupProps, RealtimeTriggerProps } from './realtime-triggers/types'; export type { ZodIssue, ZodSchema } from './params'; import type { ZodSchema } from './params'; export type AnySchema = z.ZodType; export type Infer> = TSchema extends z.ZodType ? (unknown extends z.infer ? TFallback : z.infer) : TFallback; export interface Logger { debug: (...args: unknown[]) => void; info: (...args: unknown[]) => void; warn: (...args: unknown[]) => void; error: (...args: unknown[]) => void; } export type ApiRequestFn = (arg: never) => unknown; export type ProviderPayload = any; type InjectedApiRequestArgs = 'context' | 'logger'; export type BoundApiRequest = TApiRequest extends (arg: infer TArg) => infer TResult ? (arg: Omit) => TResult : (arg: Record) => unknown; export interface ExtensionShape { config: unknown; context: unknown; helpers: unknown; apiRequest: unknown; } export interface HandlerBag { config: TShape['config']; context: TShape['context']; helpers: TShape['helpers']; apiRequest: BoundApiRequest; oauth: OAuthBag; files: FilesApi; filesScope: FileScopes; logger: Logger; } export type BagWithParams = HandlerBag & { params: Infer; }; export type SampleResult = Record | unknown[] | string | number | boolean | null | AnySchema | ((bag: BagWithParams) => unknown); export interface ExtensionProps, TApiRequest extends ApiRequestFn = ApiRequestFn> { id: string; name: string; description: string; logo: string; appearanceColors?: [string, string]; usesFileStorage?: boolean; configItems?: TConfigSchema; initContext?: (bag: { config: Infer; oauth: OAuthBag; }) => TContext; apiRequest?: TApiRequest; helpers?: (bag: Omit; context: TContext; helpers: never; apiRequest: TApiRequest; }>, 'helpers'>) => THelpers; } export type ShapeOf = { config: Infer; context: TContext; helpers: THelpers; apiRequest: TApiRequest; }; export interface DictionaryResultItem { value: string | number | boolean | null; label: string; note?: string; } export type DictionaryResultItems = DictionaryResultItem[]; export interface DictionaryResult { cursor?: string; items: DictionaryResultItems; } export interface DictionaryProps { id: string; category?: string; label?: string; description?: string; criteria?: TCriteria; result?: unknown; oauth2Scopes?: string[]; execute: (bag: HandlerBag & { search?: string; cursor?: unknown; criteria: Infer; }) => DictionaryResult | DictionaryResultItems | Promise; } export interface DynamicParamsDef { criteria: TCriteria; resolve: (bag: HandlerBag & { criteria: Infer; }) => AnySchema | Promise; } export interface ActionProps { category: string; id: string; label: string; description: string; params?: TParams; dynamicParams?: DynamicParamsDef; result: SampleResult; logo?: string; appearanceColors?: [string, string]; oauth2Scopes?: string[]; execute: (bag: BagWithParams) => unknown; } export interface ExtensionApi { dictionary(props: DictionaryProps): DictionaryRef; addAction(props: ActionProps): void; addPollingTrigger(props: PollingTriggerProps): void; setupRealtimeTriggers(props: RealtimeSetupProps): void; addRealtimeTrigger(props: RealtimeTriggerProps): void; setupOauth2(props: OAuth2Props): void; readonly extension: Extension; } export interface AnyShape extends ExtensionShape { config: Record; context: any; helpers: any; apiRequest: (arg: Record) => unknown; } export declare const asRuntimeSchema: (schema?: AnySchema) => ZodSchema | undefined;