import {z} from 'zod' export type BTPropertyValueParam = {propertyId?: string | undefined, value?: Record | undefined}; export type BTReleasePackageItemParams = {configuration?: string | undefined, documentId?: string | undefined, elementId?: string | undefined, elementType?: number | undefined, flatPartId?: string | undefined, href?: string | undefined, id?: string | undefined, parentId?: string | undefined, partId?: string | undefined, partIdentity?: string | undefined, partNumber?: string | undefined, properties?: Array | undefined, revisionId?: string | undefined, versionId?: string | undefined, workspaceId?: string | undefined}; export type BTReleasePackageParams = {items?: Array | undefined}; export type CreateApiReleasepackagesReleaseWfidArgs = {wfid: string, debugMode?: boolean | undefined, body: BTReleasePackageParams}; export type CreateApiReleasepackagesReleaseWfidOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const createApiReleasepackagesReleaseWfidResponse = 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 }; /** * Create a new release candidate for one or more items. * * POST /releasepackages/release/{wfid} */ export const createApiReleasepackagesReleaseWfid = async (args: CreateApiReleasepackagesReleaseWfidArgs, options?: CreateApiReleasepackagesReleaseWfidOptions) => { 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.debugMode != null) query.append("debugMode", String(args.debugMode)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/releasepackages/release/${encodeURIComponent(String(args.wfid))}${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(createApiReleasepackagesReleaseWfidResponse, await res.json()) };