import {z} from 'zod' export type GetApiActionRepositoryActionDefinitionsArgs = {id?: string | undefined, name?: string | undefined, nameLike?: string | undefined, nameLikeIgnoreCase?: string | undefined, key?: string | undefined, keyLike?: string | undefined, deploymentId?: string | undefined, version?: number | undefined, latest?: boolean | undefined, accessibleByUser?: string | undefined, accessibleByGroup?: string | undefined, supportsChannel?: string | undefined, supportsChannels?: string | undefined, scopeType?: string | undefined, global?: boolean | undefined, tenantId?: string | undefined, sort?: ('id' | 'name' | 'creationTime' | 'updateTime' | 'tenantId') | undefined}; export type GetApiActionRepositoryActionDefinitionsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const actionDefinitionResponse = z.object({id: z.string(), name: z.string().optional(), key: z.string(), version: z.number().int(), deploymentId: z.string().optional(), tenantId: z.string().optional(), resourceName: z.string().optional(), description: z.string().optional(), formKey: z.string().optional(), scopeType: z.string().optional(), scopeId: z.string().optional(), confirmationMessage: z.string().optional(), confirmationTitle: z.string().optional(), theme: z.string().optional(), icon: z.string().optional(), sample: z.string().optional(), help: z.string().optional(), botKey: z.string().optional(), global: z.boolean(), priority: z.number().int().optional(), groupId: z.string().optional(), actionInstanceId: z.string().optional(), startDate: z.string().optional(), formInstanceId: z.string().optional(), translations: z.record(z.string(), z.record(z.string(), z.string())).optional()}); export const dataResponseActionDefinitionResponse = z.object({data: z.array(actionDefinitionResponse).optional(), total: z.number().int().optional(), start: z.number().int().optional(), sort: z.string().optional(), order: z.string().optional(), size: z.number().int().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Query action definitions * * GET /action-repository/action-definitions */ export const getApiActionRepositoryActionDefinitions = async (args: GetApiActionRepositoryActionDefinitionsArgs, options?: GetApiActionRepositoryActionDefinitionsOptions) => { const {baseUrl = "http://localhost:8090/action-api", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.id != null) query.append("id", String(args.id)) if (args.name != null) query.append("name", String(args.name)) if (args.nameLike != null) query.append("nameLike", String(args.nameLike)) if (args.nameLikeIgnoreCase != null) query.append("nameLikeIgnoreCase", String(args.nameLikeIgnoreCase)) if (args.key != null) query.append("key", String(args.key)) if (args.keyLike != null) query.append("keyLike", String(args.keyLike)) if (args.deploymentId != null) query.append("deploymentId", String(args.deploymentId)) if (args.version != null) query.append("version", String(args.version)) if (args.latest != null) query.append("latest", String(args.latest)) if (args.accessibleByUser != null) query.append("accessibleByUser", String(args.accessibleByUser)) if (args.accessibleByGroup != null) query.append("accessibleByGroup", String(args.accessibleByGroup)) if (args.supportsChannel != null) query.append("supportsChannel", String(args.supportsChannel)) if (args.supportsChannels != null) query.append("supportsChannels", String(args.supportsChannels)) if (args.scopeType != null) query.append("scopeType", String(args.scopeType)) if (args.global != null) query.append("global", String(args.global)) if (args.tenantId != null) query.append("tenantId", String(args.tenantId)) if (args.sort != null) query.append("sort", String(args.sort)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/action-repository/action-definitions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(dataResponseActionDefinitionResponse, await res.json()) };