import {z} from 'zod' export type GetApi10TimeEntriesTimeEntryIdArgs = {timeEntryId: number, includeFields?: (Array<'notes' | 'sourceType' | 'deleted' | 'status' | 'submittedBy' | 'submittedAt' | 'approvedBy' | 'approvedAt' | 'rejectedBy' | 'rejectedAt' | 'costRate' | 'billRate'>) | undefined, includeAllFields?: boolean | undefined}; export type GetApi10TimeEntriesTimeEntryIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const timeEntryProjectPublicAPIResponseEntity = z.object({projectName: z.string().optional(), projectId: z.number().int().optional()}); export const timeEntryTaskPublicAPI = z.object({taskName: z.string().optional(), taskId: z.number().int().optional()}); export const timeEntryPhasePublicAPIResponseEntity = z.object({phaseId: z.number().int().optional(), phaseName: z.string().optional()}); export const timeEntryCreatedByPublicResponse = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const timeEntryUpdatedByPublicResponse = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const userPublicAPIResponseEntity = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const timeEntryCategoryPublicAPI = z.object({categoryName: z.string().optional(), categoryId: z.number().int().optional()}); export const timeEntrySubmittedByPublicResponse = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const timeEntryApprovedByPublicResponse = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const timeEntryRejectedByPublicResponse = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const timeEntryCostRatePublicAPI = z.object({rate: z.number().optional(), currency: z.string().optional()}); export const timeEntryBillRatePublicAPI = z.object({rate: z.number().optional(), currency: z.string().optional()}); export const timeEntryPublicProjectFinancialsBudgetResponse = z.object({budgetId: z.number().int().gte(1).optional(), budgetName: z.string().optional()}); export const timeEntryFieldPublicResponseAPIEntity = z.object({fieldId: z.number().int().gte(1).optional(), fieldLabel: z.string().optional(), fieldValue: z.object({}).optional(), fieldValueLabel: z.string().optional()}); export const timeEntryPublicAPIResponseEntity = z.object({timeEntryId: z.number().int().gte(1).optional(), date: z.string().optional(), minutes: z.number().int().gte(1).lte(1440).optional(), activityName: z.string().optional(), project: timeEntryProjectPublicAPIResponseEntity.optional(), task: timeEntryTaskPublicAPI.optional(), projectPhase: timeEntryPhasePublicAPIResponseEntity.optional(), createdAt: z.number().int().optional(), updatedAt: z.number().int().optional(), createdBy: timeEntryCreatedByPublicResponse.optional(), updatedBy: timeEntryUpdatedByPublicResponse.optional(), billable: z.boolean().optional(), user: userPublicAPIResponseEntity.optional(), notes: z.string().optional(), category: timeEntryCategoryPublicAPI.optional(), sourceType: z.enum(["GOOGLE_CALENDAR", "OUTLOOK_CALENDAR", "TASK", "PROJECT", "PHASE", "ADHOC", "MILESTONE"]).optional(), status: z.enum(["NOT_SUBMITTED", "SUBMITTED", "APPROVED", "REJECTED"]).optional(), submittedBy: timeEntrySubmittedByPublicResponse.optional(), submittedAt: z.number().int().optional(), approvedBy: timeEntryApprovedByPublicResponse.optional(), approvedAt: z.number().int().optional(), rejectedBy: timeEntryRejectedByPublicResponse.optional(), rejectedAt: z.number().int().optional(), deleted: z.boolean().optional(), costRate: timeEntryCostRatePublicAPI.optional(), billRate: timeEntryBillRatePublicAPI.optional(), budget: timeEntryPublicProjectFinancialsBudgetResponse.optional(), fields: z.array(timeEntryFieldPublicResponseAPIEntity).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 a time entry * * GET /1.0/time-entries/{timeEntryId} */ export const getApi10TimeEntriesTimeEntryId = async (args: GetApi10TimeEntriesTimeEntryIdArgs, options?: GetApi10TimeEntriesTimeEntryIdOptions) => { 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/time-entries/${encodeURIComponent(String(args.timeEntryId))}${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(timeEntryPublicAPIResponseEntity, await res.json()) };