import {z} from 'zod' export type GetApiOdataProposalsProposalIdAttachmentsAttachmentIdServiceGetThumbnailWidthWidthHeightHeightModeModeImageFormatImageFormatArgs = {imageFormat: string, mode: string, height: number, width: number, attachmentId: number, proposalId: number, $expand?: string | undefined, $select?: string | undefined, $filter?: string | undefined, $orderby?: string | undefined, $top?: number | undefined, $skip?: number | undefined, $count?: boolean | undefined}; export type GetApiOdataProposalsProposalIdAttachmentsAttachmentIdServiceGetThumbnailWidthWidthHeightHeightModeModeImageFormatImageFormatOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const systemCollectionsGenericKeyValuePairSystemStringSystemCollectionsGenericIEnumerableSystemString = z.object({Key: z.string().optional(), Value: z.array(z.string()).optional()}); export const systemNetHttpByteArrayContent = z.object({Headers: z.array(systemCollectionsGenericKeyValuePairSystemStringSystemCollectionsGenericIEnumerableSystemString).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 }; /** * Retrieve Attachment Thumbnail * * GET /odata/proposals({proposalId})/attachments({attachmentId})/Service.GetThumbnail(width={width},height={height},mode={mode},imageFormat={imageFormat}) */ export const getApiOdataProposalsProposalIdAttachmentsAttachmentIdServiceGetThumbnailWidthWidthHeightHeightModeModeImageFormatImageFormat = async (args: GetApiOdataProposalsProposalIdAttachmentsAttachmentIdServiceGetThumbnailWidthWidthHeightHeightModeModeImageFormatImageFormatArgs, options?: GetApiOdataProposalsProposalIdAttachmentsAttachmentIdServiceGetThumbnailWidthWidthHeightHeightModeModeImageFormatImageFormatOptions) => { const {baseUrl = "https://sb2api.servicechannel.com/v3", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.$expand != null) query.append("$expand", String(args.$expand)) if (args.$select != null) query.append("$select", String(args.$select)) if (args.$filter != null) query.append("$filter", String(args.$filter)) if (args.$orderby != null) query.append("$orderby", String(args.$orderby)) if (args.$top != null) query.append("$top", String(args.$top)) if (args.$skip != null) query.append("$skip", String(args.$skip)) if (args.$count != null) query.append("$count", String(args.$count)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/odata/proposals(${encodeURIComponent(String(args.proposalId))})/attachments(${encodeURIComponent(String(args.attachmentId))})/Service.GetThumbnail(width=${encodeURIComponent(String(args.width))},height=${encodeURIComponent(String(args.height))},mode=${encodeURIComponent(String(args.mode))},imageFormat=${encodeURIComponent(String(args.imageFormat))})${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(systemNetHttpByteArrayContent, await res.json()) };