import {z} from 'zod' export type AdaptekApiApplicationFoldersFolderType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22; export type AdaptekApiApplicationFilesUpdateDocumentModel = {fileId?: number | undefined, type?: AdaptekApiApplicationFoldersFolderType | undefined, filename?: (string | null) | undefined, userId?: number | undefined, objectId?: number | undefined, isDeleted?: boolean | undefined, folderId?: number | undefined}; export type CreateApiV1SalesForceDocumentsUpdateArgs = {body: AdaptekApiApplicationFilesUpdateDocumentModel}; export type CreateApiV1SalesForceDocumentsUpdateOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const adaptekApiApplicationFoldersFolderType = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8), z.literal(9), z.literal(10), z.literal(11), z.literal(12), z.literal(13), z.literal(14), z.literal(15), z.literal(16), z.literal(17), z.literal(18), z.literal(19), z.literal(20), z.literal(21), z.literal(22)]); export const adaptekApiApplicationFoldersGenericFile = z.object({id: z.number().int().optional(), holdingCompanyId: z.number().int().optional(), employeeCreatedId: z.number().int().optional(), createdBy: z.string().nullable().optional(), employeeModifiedId: z.number().int().optional(), modifiedBy: z.string().nullable().optional(), dateModified: z.string().optional(), dateCreated: z.string().optional(), displayName: z.string().nullable().optional(), physicalName: z.string().optional(), fileSizeInBytes: z.number().int().optional(), folder: z.lazy(() => adaptekApiApplicationFoldersGenericFolder.optional()), folderTypeId: adaptekApiApplicationFoldersFolderType.optional(), folderId: z.number().int().optional(), isReadByAgent: z.boolean().nullable().optional(), isReadByConsumer: z.boolean().nullable().optional(), isDeleted: z.boolean().optional()}); export const adaptekApiApplicationFoldersGenericFolder: z.ZodType = z.object({genericModelId: z.number().int().optional(), folderId: z.number().int().optional(), parentFolderId: z.number().int().nullable().optional(), folderName: z.string().nullable().optional(), isArchived: z.boolean().optional(), folderType: adaptekApiApplicationFoldersFolderType.optional(), divisionType: z.number().int().nullable().optional(), dateCreated: z.string().nullable().optional(), isReadOnly: z.boolean().optional(), consumerCreatedId: z.number().int().nullable().optional(), filesNotOpenedCount: z.number().int().optional(), isDeleted: z.boolean().optional(), childFolders: z.array(z.lazy(() => adaptekApiApplicationFoldersGenericFolder)).nullable().optional(), files: z.array(adaptekApiApplicationFoldersGenericFile).nullable().optional()}); export const createApiV1SalesForceDocumentsUpdateResponse = z.array(adaptekApiApplicationFoldersGenericFolder); 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 }; /** * POST /v1/SalesForce/documents/update */ export const createApiV1SalesForceDocumentsUpdate = async (args: CreateApiV1SalesForceDocumentsUpdateArgs, options: CreateApiV1SalesForceDocumentsUpdateOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/SalesForce/documents/update${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiV1SalesForceDocumentsUpdateResponse, await res.json()) };