import {z} from 'zod' export type CustomtablerecordlinksPostRequest = {requirement?: ({custom_object_links?: ({customers?: Array | undefined}) | undefined}) | undefined}; export type UpdateApiProductsIdArgs = {id: string, body: CustomtablerecordlinksPostRequest}; export type UpdateApiProductsIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const productsPutResponse = z.object({product: z.object({id: z.string().optional(), reference_prefix: z.string().optional(), name: z.string().optional(), product_line: z.boolean().optional(), product_line_type: z.unknown(), created_at: z.string().optional(), updated_at: z.string().optional(), description: z.object({id: z.string().optional(), body: z.string().optional(), notable_id: z.string().optional(), notable_type: z.string().optional(), editor_version: z.number().int().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), attachments: z.array(z.unknown()).optional()}).optional(), url: z.string().optional(), resource: z.string().optional(), children: z.array(z.unknown()).optional(), custom_fields: z.array(z.object({id: z.string().optional(), key: z.string().optional(), name: z.string().optional(), updatedAt: z.string().optional(), type: z.string().optional(), value: z.string().optional()})).optional(), screen_definition_ids: z.object({Approval: z.number().int().optional(), Competitor: z.number().int().optional(), Epic: z.number().int().optional(), Feature: z.number().int().optional(), "Ideas::Idea": z.number().int().optional(), "Ideas::IdeaPortal": z.number().int().optional(), Initiative: z.number().int().optional(), Page: z.number().int().optional(), Project: z.number().int().optional(), Release: z.number().int().optional(), Requirement: z.number().int().optional(), StrategicImperative: z.number().int().optional()}).optional(), screen_definitions: z.array(z.object({id: z.string().optional(), screenable_type: z.string().optional(), name: z.string().optional(), custom_field_definitions: z.string().optional()})).optional(), has_ideas: z.boolean().optional(), has_master_features: z.boolean().optional(), has_epics: z.boolean().optional(), release_workflow: z.object({workflow_type: z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), statusable_type: z.string().optional()}).optional(), feature_workflow: z.object({workflow_type: z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), statusable_type: z.string().optional()}).optional(), initiative_workflow: z.object({workflow_type: z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), statusable_type: z.string().optional()}).optional(), epic_workflow: z.object({workflow_type: z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), statusable_type: z.string().optional()}).optional(), idea_workflow: z.object({workflow_type: z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), statusable_type: z.string().optional()}).optional(), strategic_imperative_workflow: z.object({workflow_type: z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), statusable_type: z.string().optional()}).optional(), page_workflow: z.object({workflow_type: z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), statusable_type: z.string().optional()}).optional(), requirement_workflow: z.object({workflow_type: z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), statusable_type: z.string().optional()}).optional(), key_result_workflow: z.object({workflow_type: z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), statusable_type: z.string().optional()}).optional(), capacity_planning_enabled: z.boolean().optional(), default_capacity_units: z.number().int().optional(), enhanced_capacity_planning_enabled: z.boolean().optional(), workspace_type: z.string().optional(), color: z.string().optional()}).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 }; /** * Create a custom table record link associated with a product * * PUT /products/{id} * * Also accepts auth: ApiKeyAuth, CookieAuth */ export const updateApiProductsId = async (args: UpdateApiProductsIdArgs, options?: UpdateApiProductsIdOptions) => { const {baseUrl = "https://company.aha.io/api/v1", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json; charset=utf-8") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/products/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(productsPutResponse, await res.json()) };