import {z} from 'zod' export type BTBExportModelParams = {angleTolerance?: number | undefined, batchAllFlatPatterns?: boolean | undefined, batchFlatPatterns?: boolean | undefined, chordTolerance?: number | undefined, cloudObjectId?: string | undefined, cloudStorageAccountId?: string | undefined, configuration?: string | undefined, destinationName?: string | undefined, documentId: string, documentVersionId?: string | undefined, elementId?: string | undefined, elementIds?: string | undefined, emailLink?: boolean | undefined, emailMessage?: string | undefined, emailSubject?: string | undefined, emailTo?: string | undefined, excludeHiddenEntities?: boolean | undefined, featureIds?: string | undefined, flatPatternAsync?: boolean | undefined, flatten?: boolean | undefined, format: string, fromUserId?: string | undefined, grouping?: string | undefined, ignoreExportRulesForContents?: boolean | undefined, includeBendCenterlines?: boolean | undefined, includeBendLines?: boolean | undefined, includeCboreCsink?: boolean | undefined, includeExportIds?: boolean | undefined, includeFormedCentermarks?: boolean | undefined, includeFormedOutlines?: boolean | undefined, includeSketches?: boolean | undefined, isPartingOut?: boolean | undefined, linkDocumentId?: string | undefined, linkDocumentWorkspaceId?: string | undefined, maxFacetWidth?: number | undefined, microversion?: string | undefined, minFacetWidth?: number | undefined, mode?: string | undefined, occurrencesToExport?: string | undefined, partIds?: string | undefined, partQuery?: string | undefined, password?: string | undefined, passwordRequired?: boolean | undefined, resolution?: string | undefined, scale?: number | undefined, sendCopyToMe?: boolean | undefined, sheetMetalFlat?: boolean | undefined, splinesAsPolylines?: boolean | undefined, storeInDocument?: boolean | undefined, triggerAutoDownload?: boolean | undefined, units?: string | undefined, useYAxisAsUp?: boolean | undefined, userId?: string | undefined, validForDays?: number | undefined, version?: string | undefined, view?: string | undefined, workspaceId?: string | undefined, zipSingleFileOutput?: boolean | undefined}; export type CreateApiDocumentsDDidWvWvidEEidExportArgs = {did: string, linkDocumentId?: string | undefined, wv: 'w' | 'v', wvid: string, eid: string, body: BTBExportModelParams}; export type CreateApiDocumentsDDidWvWvidEEidExportOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const createApiDocumentsDDidWvWvidEEidExportResponse = z.object({}); 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 }; /** * Export document by document ID, workspace or version ID, and tab ID. * * POST /documents/d/{did}/{wv}/{wvid}/e/{eid}/export */ export const createApiDocumentsDDidWvWvidEEidExport = async (args: CreateApiDocumentsDDidWvWvidEEidExportArgs, options?: CreateApiDocumentsDDidWvWvidEEidExportOptions) => { const {baseUrl = "https://api.onshape.com/api/v17", fetch: fetchFn = fetch, OAuth2, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json;charset=UTF-8; qs=0.09") headers.set('accept', "application/json;charset=UTF-8; qs=0.09") if (args.linkDocumentId != null) query.append("linkDocumentId", String(args.linkDocumentId)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/documents/d/${encodeURIComponent(String(args.did))}/${encodeURIComponent(String(args.wv))}/${encodeURIComponent(String(args.wvid))}/e/${encodeURIComponent(String(args.eid))}/export${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(createApiDocumentsDDidWvWvidEEidExportResponse, await res.json()) };