import {z} from 'zod' export type GetApiV1AccountAccountSlugProjectProjectSlugActionsArgs = {accountSlug: string, projectSlug: string}; export type GetApiV1AccountAccountSlugProjectProjectSlugActionsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const web3ActionVersion = z.object({id: z.string(), index: z.number(), actionId: z.string(), parentActionId: z.string().optional(), runtime: z.string(), function: z.string(), triggerType: z.enum(["ALERT", "BLOCK", "PERIODIC", "TRANSACTION", "WEBHOOK", "TRANSACTIONSIMPLE"]), trigger: z.object({}), commitish: z.string().optional(), source: z.string(), createdAt: z.string(), deployRequested: z.boolean(), deployError: z.string().optional(), invocationType: z.enum(["SYNC", "ASYNC"])}); export const web3ActionResponse = z.object({id: z.string(), projectId: z.string(), name: z.string(), description: z.string(), status: z.enum(["DEPLOYED", "PUBLISHED"]), stopped: z.boolean(), editable: z.boolean(), createdAt: z.string(), version: web3ActionVersion, deliveryChannels: z.array(z.unknown()).optional()}); export const web3ActionsGetResponse = z.array(web3ActionResponse); 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 }; /** * Get details for all Web3 Actions * * GET /v1/account/{accountSlug}/project/{projectSlug}/actions * * Also accepts auth: BearerAuth */ export const getApiV1AccountAccountSlugProjectProjectSlugActions = async (args: GetApiV1AccountAccountSlugProjectProjectSlugActionsArgs, options?: GetApiV1AccountAccountSlugProjectProjectSlugActionsOptions) => { const {baseUrl = "https://api.tenderly.co/api", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-Access-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/account/${encodeURIComponent(String(args.accountSlug))}/project/${encodeURIComponent(String(args.projectSlug))}/actions${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(web3ActionsGetResponse, await res.json()) };