import {z} from 'zod' export type AppCustomDataUpdateRequest = {file_name?: (string | null) | undefined, active?: (boolean | null) | undefined, labels?: (Array | null) | undefined}; export type UpdateApiV1AppsCustomDataAppIdFilesFileIdArgs = {app_id: string, file_id: string, body: AppCustomDataUpdateRequest}; export type UpdateApiV1AppsCustomDataAppIdFilesFileIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const appCustomDataState = z.enum(["CREATED", "PENDING", "QUEUED", "QUEUED_FOR_RECONCILIATION", "SYNC_FAILED", "FAILED", "INDEXED", "DELETING"]); export const appLabel = z.object({name: z.string(), description: z.string().nullable().optional(), color: z.string().nullable().optional(), id: z.string()}); export const appCustomData = z.object({id: z.string().nullable().optional(), app_id: z.string().nullable().optional(), tenant_id: z.string(), carbon_object_id: z.union([z.string(), z.number().int()]).nullable().optional(), carbon_data_source_type: z.string().nullable().optional(), carbon_last_synced_on: z.string().nullable().optional(), file_name: z.union([z.string().min(1).max(2083), z.string()]), file_mime: z.string().nullable().optional(), file_size: z.number().int().nullable().optional(), external_url: z.union([z.string().min(1).max(2083), z.string()]).nullable().optional(), data_type: z.enum(["file", "url"]), active: z.boolean().optional(), state: appCustomDataState.optional(), labels: z.array(appLabel).optional(), added_on: z.string().optional(), modified_on: z.string().nullable().optional(), deleted_on: z.string().nullable().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 }; /** * Update App Custom Data * * PUT /v1/apps/custom-data/{app_id}/files/{file_id} */ export const updateApiV1AppsCustomDataAppIdFilesFileId = async (args: UpdateApiV1AppsCustomDataAppIdFilesFileIdArgs, options: UpdateApiV1AppsCustomDataAppIdFilesFileIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/apps/custom-data/${encodeURIComponent(String(args.app_id))}/files/${encodeURIComponent(String(args.file_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(appCustomData, await res.json()) };