import {z} from 'zod' export type GetApiEntitiesProjectsIdArgs = {id: string, expand?: string | undefined}; export type GetApiEntitiesProjectsIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const project = z.object({is_delete_protected: z.boolean(), id: z.string(), is_deleted: z.boolean().optional(), modified: z.string().optional(), created: z.string().optional(), account: z.string().optional(), currency_exchange_rates_list: z.string().optional(), owner: z.string(), project_type: z.string(), unit: z.string(), account_id: z.string().optional(), currency_exchange_rates_list_id: z.string().optional(), description: z.string().optional(), end_date: z.string(), name: z.string(), owner_id: z.string(), project_type_id: z.string().optional(), share_mode: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)]).optional(), start_date: z.string().optional(), unit_id: z.string().optional(), revision: z.number().int().optional(), revenue_goal: z.object({base_value: z.number(), currency_id: z.string(), value_foreign: z.number()}), documents: z.array(z.string()).optional(), sharing_units: z.array(z.string()).optional(), sharing_clients: z.array(z.string()).optional(), primary_contact: z.string().optional(), contact_relations: z.array(z.string()).optional(), tags: z.array(z.string()).optional(), static_profiles: z.array(z.string()).optional(), objectives: z.array(z.string()).optional(), is_favorite: z.boolean(), status: z.union([z.literal(1), z.literal(2), z.literal(4)]), completion_rate: z.number().optional(), activities_total: z.number().optional(), activities_completed: z.number().optional(), formatted_name: z.string(), modified_by_user: z.string().optional()}); export const getApiEntitiesProjectsIdResponse = z.object({success: z.boolean().optional(), data: project.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 }; /** * Projects.get * * GET /entities/Projects/{id} */ export const getApiEntitiesProjectsId = async (args: GetApiEntitiesProjectsIdArgs, options?: GetApiEntitiesProjectsIdOptions) => { const {baseUrl = "https://us-east.api.coevera.com/api/v100/rest/spaces/your_space_id", fetch: fetchFn = fetch, basicAuth} = 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 (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/entities/Projects/${encodeURIComponent(String(args.id))}${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(getApiEntitiesProjectsIdResponse, await res.json()) };