import {z} from 'zod' export type EdgeScriptTypes2 = 0 | 1 | 2; export type GetApiComputeScriptArgs = {type?: (Array | null) | undefined, page?: number | undefined, perPage?: number | undefined, search?: (string | null) | undefined, includeLinkedPullzones?: boolean | undefined, integrationId?: (number | null) | undefined}; export type GetApiComputeScriptOptions = {baseUrl?: string | undefined, AccessKey?: string | undefined, fetch?: typeof fetch | undefined}; export const edgeScriptTypes = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const edgeScriptVariableModel = z.object({Id: z.number().int().optional(), Name: z.string().nullable().optional(), Required: z.boolean().optional(), DefaultValue: z.string().nullable().optional()}); export const linkedPullZone = z.object({Id: z.number().int().optional(), PullZoneName: z.string().nullable().optional(), DefaultHostname: z.string().nullable().optional()}); export const sourceCodeRepositorySettingsModel = z.object({Id: z.number().int().nullable().optional(), Name: z.string().nullable().optional(), Private: z.boolean().optional(), TemplateUrl: z.string().nullable().optional()}); export const deployConfigurationModel = z.object({Branch: z.string().nullable().optional(), InstallCommand: z.string().nullable().optional(), BuildCommand: z.string().nullable().optional(), EntryFile: z.string().nullable().optional(), CreateWorkflow: z.boolean().optional()}); export const sourceCodeIntegrationModel = z.object({IntegrationId: z.number().int().optional(), RepositorySettings: sourceCodeRepositorySettingsModel.nullable().optional(), DeployConfiguration: deployConfigurationModel.nullable().optional()}); export const edgeScriptModel = z.object({Id: z.number().int().optional(), Name: z.string().nullable().optional(), LastModified: z.string().optional(), ScriptType: edgeScriptTypes.optional(), CurrentReleaseId: z.number().int().optional(), EdgeScriptVariables: z.array(edgeScriptVariableModel).nullable().optional(), Deleted: z.boolean().optional(), LinkedPullZones: z.array(linkedPullZone).nullable().optional(), Integration: sourceCodeIntegrationModel.nullable().optional(), DefaultHostname: z.string().nullable().optional(), SystemHostname: z.string().nullable().optional(), DeploymentKey: z.string().nullable().optional(), RepositoryId: z.number().int().nullable().optional(), IntegrationId: z.number().int().nullable().optional(), MonthlyCost: z.number().optional(), MonthlyRequestCount: z.number().int().optional(), MonthlyCpuTime: z.number().int().optional()}); export const paginationListModelOfEdgeScriptModel = z.object({Items: z.array(edgeScriptModel).nullable().optional(), CurrentPage: z.number().int().optional(), TotalItems: z.number().int().optional(), HasMoreItems: z.boolean().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 }; /** * List Edge Scripts * * GET /compute/script * * Also accepts auth: bearer */ export const getApiComputeScript = async (args: GetApiComputeScriptArgs, options?: GetApiComputeScriptOptions) => { const {baseUrl = "https://api.bunny.net", fetch: fetchFn = fetch, AccessKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.type ?? []) query.append("type", String(item)) if (args.page != null) query.append("page", String(args.page)) if (args.perPage != null) query.append("perPage", String(args.perPage)) if (args.search != null) query.append("search", String(args.search)) if (args.includeLinkedPullzones != null) query.append("includeLinkedPullzones", String(args.includeLinkedPullzones)) if (args.integrationId != null) query.append("integrationId", String(args.integrationId)) if (AccessKey !== undefined) headers.set("AccessKey", AccessKey) const url = `${baseUrl.replace(/\/+$/, '')}/compute/script${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(paginationListModelOfEdgeScriptModel, await res.json()) };