import {z} from 'zod' export type GetApi10ProjectsProjectIdArgs = {projectId: number, includeFields?: (Array<'annualizedRecurringRevenue' | 'projectFee' | 'allocatedHours' | 'allocatedMinutes' | 'budgetedHours' | 'percentageBudgetedHoursConsumed' | 'percentageBudgetConsumed' | 'billableHours' | 'billableMinutes' | 'nonBillableHours' | 'nonBillableMinutes' | 'trackedHours' | 'trackedMinutes' | 'progressPercentage' | 'startDateActual' | 'dueDateActual' | 'currentPhase' | 'autoAllocation' | 'sources' | 'inferredProgress' | 'plannedDuration' | 'projectAgeInDays' | 'customersInvited' | 'customersJoined' | 'externalReferenceId' | 'metrics' | 'remainingMinutes' | 'remainingHours'>) | undefined, includeAllFields?: boolean | undefined}; export type GetApi10ProjectsProjectIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const importPublicAPIResponseEntity = z.object({prefix: z.string().optional(), startDate: z.string().optional(), templateId: z.number().int().optional(), templateName: z.string().optional()}); export const projectVendorUserPublicAPI = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const projectCustomerUserPublicAPI = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const projectCustomerChampionUserPublicAPI = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const projectResponseMembersResponse = z.object({members: z.array(projectVendorUserPublicAPI).optional(), customers: z.array(projectCustomerUserPublicAPI).optional(), customerChampion: projectCustomerChampionUserPublicAPI.optional()}); export const projectPhasePublicLiteAPIResponseEntity = z.object({phaseId: z.number().int().optional(), phaseName: z.string().optional()}); export const projectOwnerUserPublicResponse = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const projectPublicUpdatedByResponse = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const projectPartnerCompanyPublicAPIResponseEntity = z.object({companyId: z.number().int().gte(1).optional(), companyName: z.string().optional(), companyUrl: z.string().optional()}); export const projectPublicCreatedByResponse = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const projectFieldPublicResponseAPIEntity = z.object({fieldId: z.number().int().gte(1).optional(), fieldLabel: z.string().optional(), fieldValue: z.string().optional(), fieldValueLabel: z.string().optional()}); export const customerCompanyProjectPublicResponse = z.object({companyId: z.number().int().gte(1).optional(), companyName: z.string().optional(), companyUrl: z.string().optional()}); export const projectStatusPublicResponse = z.object({value: z.number().int().gte(1).optional(), label: z.string().optional()}); export const fixedFeeFinancialsPublicResponse = z.object({fixedFee: z.number().optional()}); export const projectRateCardPublicResponse = z.object({rateCardId: z.number().int().optional(), rateCardName: z.string().optional()}); export const timeAndMaterialFinancialsPublicResponse = z.object({rateCard: projectRateCardPublicResponse.optional(), projectBudget: z.number().gte(1).optional()}); export const subscriptionFinancialsPublicResponse = z.object({subscriptionFrequency: z.enum(["MONTHLY", "QUARTERLY", "YEARLY", "HALF_YEARLY"]).optional(), subscriptionStartDate: z.string().optional(), periodMinutes: z.number().int().gte(1).optional(), periodBudget: z.number().optional(), noOfPeriods: z.number().int().gte(1).optional()}); export const projectFinancialsMetrics = z.object({actualRevenue: z.number().optional(), estimatedRevenue: z.number().optional(), actualCost: z.number().optional(), estimatedCost: z.number().optional(), actualProfit: z.number().optional(), estimatedProfit: z.number().optional(), actualProfitMargin: z.number().optional(), estimatedProfitMargin: z.number().optional(), estimateAtCompletion: z.number().optional(), estimationToCompletionInHours: z.number().optional()}); export const projectFinancialsPublicResponse = z.object({contractType: z.enum(["FIXED_FEE", "TIME_AND_MATERIAL", "SUBSCRIPTION", "NON_BILLABLE"]).optional(), revenueRecognitionType: z.string().optional(), fixedFeeContract: fixedFeeFinancialsPublicResponse.optional(), timeAndMaterialContract: timeAndMaterialFinancialsPublicResponse.optional(), subscriptionContract: subscriptionFinancialsPublicResponse.optional(), metrics: projectFinancialsMetrics.optional()}); export const projectPublicAPIResponseEntity = z.object({sources: z.array(importPublicAPIResponseEntity).optional(), dueDate: z.string().optional(), autoAllocation: z.boolean().optional(), dueDateActual: z.string().optional(), teamMembers: projectResponseMembersResponse.optional(), createdAt: z.number().int().optional(), archived: z.boolean().optional(), inferredProgress: z.enum(["ON_TRACK", "AHEAD_OF_TIME", "RUNNING_LATE", "NONE"]).optional(), plannedDurationInDays: z.number().int().optional(), currentPhases: z.array(projectPhasePublicLiteAPIResponseEntity).optional(), customersInvited: z.number().int().optional(), currency: z.enum(["AFN", "ALL", "DZD", "ARS", "AMD", "AUD", "AZN", "BHD", "BDT", "BYN", "BZD", "BOB", "BAM", "BWP", "BRL", "GBP", "BND", "BGN", "BIF", "KHR", "CAD", "CVE", "XAF", "CLP", "CNY", "COP", "KMF", "CDF", "CRC", "HRK", "CZK", "DKK", "DJF", "DOP", "EGP", "ERN", "EEK", "ETB", "EUR", "GEL", "GHS", "GTQ", "GNF", "HNL", "HKD", "HUF", "ISK", "INR", "IDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KWD", "LVL", "LBP", "LYD", "LTL", "MOP", "MKD", "MGA", "MYR", "MUR", "MXN", "MDL", "MAD", "MZN", "MMK", "NAD", "NPR", "TWD", "NZD", "NIO", "NGN", "NOK", "OMR", "PKR", "PAB", "PYG", "PEN", "PHP", "PLN", "QAR", "RON", "RUB", "RWF", "SAR", "RSD", "SGD", "SOS", "ZAR", "KRW", "LKR", "SDG", "SEK", "CHF", "SYP", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "USD", "UGX", "UAH", "AED", "UYU", "UZS", "VEF", "VND", "XOF", "YER", "ZMK", "ZWL"]).optional(), updatedAt: z.number().int().optional(), owner: projectOwnerUserPublicResponse.optional(), budgetedHours: z.number().optional(), updatedBy: projectPublicUpdatedByResponse.optional(), partnerCompanies: z.array(projectPartnerCompanyPublicAPIResponseEntity).optional(), visibility: z.enum(["EVERYONE", "MEMBERS", "GROUP"]).optional(), annualizedRecurringRevenue: z.number().int().optional(), allocatedHours: z.number().int().optional(), trackedHours: z.number().int().optional(), projectAgeInDays: z.number().int().optional(), createdBy: projectPublicCreatedByResponse.optional(), projectFee: z.number().int().optional(), customersJoined: z.number().int().optional(), progressPercentage: z.number().int().optional(), projectName: z.string().optional(), fields: z.array(projectFieldPublicResponseAPIEntity).optional(), projectId: z.number().int().gte(1).optional(), startDate: z.string().optional(), customer: customerCompanyProjectPublicResponse.optional(), status: projectStatusPublicResponse.optional(), startDateActual: z.string().optional(), percentageBudgetedHoursConsumed: z.number().optional(), percentageBudgetConsumed: z.number().optional(), trackedMinutes: z.number().optional(), allocatedMinutes: z.number().optional(), billableHours: z.number().int().optional(), billableMinutes: z.number().optional(), nonBillableHours: z.number().int().optional(), nonBillableMinutes: z.number().optional(), remainingHours: z.number().int().optional(), remainingMinutes: z.number().int().optional(), externalReferenceId: z.string().optional(), financials: projectFinancialsPublicResponse.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 }; /** * Get project by Id * * GET /1.0/projects/{projectId} */ export const getApi10ProjectsProjectId = async (args: GetApi10ProjectsProjectIdArgs, options?: GetApi10ProjectsProjectIdOptions) => { const {baseUrl = "https://api.rocketlane.com/api", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.includeFields != null) query.append("includeFields", args.includeFields.join(',')) if (args.includeAllFields != null) query.append("includeAllFields", String(args.includeAllFields)) if (apiKey !== undefined) headers.set("api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/1.0/projects/${encodeURIComponent(String(args.projectId))}${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(projectPublicAPIResponseEntity, await res.json()) };