import {z} from 'zod' export type CreateApiV6SftpDestinationsSftpDestinationIdSyncArgs = {sftpDestinationId: string}; export type CreateApiV6SftpDestinationsSftpDestinationIdSyncOptions = {baseUrl?: string | undefined, HEADER?: string | undefined, fetch?: typeof fetch | undefined}; export const zonedDateTime = z.string(); export const externalSftpDestinationResponse = z.object({created_date: zonedDateTime, dropbox_path: z.string(), extole_key_id: z.string(), host: z.string(), id: z.string(), name: z.string(), partner_key_id: z.string().nullable(), port: z.number().int(), type: z.literal("EXTERNAL"), updated_date: zonedDateTime, username: z.string(), key_id: z.string()}); export const localSftpDestinationResponse = z.object({created_date: zonedDateTime, dropbox_path: z.string(), extole_key_id: z.string(), host: z.string(), id: z.string(), name: z.string(), partner_key_id: z.string().nullable(), port: z.number().int(), type: z.literal("LOCAL"), updated_date: zonedDateTime, username: z.string(), file_processing_enabled: z.boolean(), key_ids: z.array(z.string())}); export const sftpDestinationResponse = z.discriminatedUnion("type", [externalSftpDestinationResponse, localSftpDestinationResponse]); 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 }; /** * Sync an SFTP destination * * POST /v6/sftp-destinations/{sftpDestinationId}/sync * * Also accepts auth: QUERY, COOKIE */ export const createApiV6SftpDestinationsSftpDestinationIdSync = async (args: CreateApiV6SftpDestinationsSftpDestinationIdSyncArgs, options?: CreateApiV6SftpDestinationsSftpDestinationIdSyncOptions) => { const {baseUrl = "https://api.extole.io", fetch: fetchFn = fetch, HEADER} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HEADER !== undefined) headers.set("Authorization", HEADER) const url = `${baseUrl.replace(/\/+$/, '')}/v6/sftp-destinations/${encodeURIComponent(String(args.sftpDestinationId))}/sync${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(sftpDestinationResponse, await res.json()) };