import {z} from 'zod' export type GetApi10ResourceAllocationsArgs = {startDate: string, endDate: string, pageSize?: number | undefined, pageToken?: string | undefined, includeFields?: (Array<'member' | 'task' | 'placeholder' | 'duration'>) | undefined, includeAllFields?: boolean | undefined, sortBy?: ('startDate' | 'endDate' | 'allocationType' | 'allocationFor') | undefined, sortOrder?: ('ASC' | 'DESC') | undefined, match?: ('all' | 'any') | undefined, 'memberId.eq'?: string | undefined, 'memberId.oneOf'?: string | undefined, 'memberId.noneOf'?: string | undefined, 'projectId.eq'?: string | undefined, 'projectId.oneOf'?: string | undefined, 'projectId.noneOf'?: string | undefined, 'placeholderId.eq'?: string | undefined, 'placeholderId.oneOf'?: string | undefined, 'placeholderId.noneOf'?: string | undefined}; export type GetApi10ResourceAllocationsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const resourceAllocationTotalDurationPublicResponse = z.object({daysConsider: z.number().int().optional(), seconds: z.number().int().optional(), minutes: z.number().int().optional(), hours: z.number().int().optional()}); export const projectPublicAPIAllocationResponseEntity = z.object({projectId: z.number().int().gte(1).optional(), projectName: z.string().optional()}); export const resourceAllocationTaskPublicAPIEntity = z.object({taskName: z.string().optional(), taskId: z.number().int().optional()}); export const roleResponsePublicAPI = z.object({roleId: z.number().int().optional(), roleName: z.string().optional()}); export const allocationUserPublicAPIResponseEntity = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional(), role: roleResponsePublicAPI.optional()}); export const placeholderResponsePublicAPI = z.object({placeholderId: z.number().int().optional(), placeholderName: z.string().optional(), role: roleResponsePublicAPI.optional()}); export const allocationCreatedByUserPublicAPI = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const allocationUpdatedByUserPublicAPI = z.object({emailId: z.string().optional(), userId: z.number().int().optional(), firstName: z.string().optional(), lastName: z.string().optional()}); export const resourceAllocationFieldPublicResponseAPIEntity = z.object({fieldId: z.number().int().gte(1).optional(), fieldLabel: z.string().optional(), fieldValue: z.object({}).optional(), fieldValueLabel: z.string().optional()}); export const resourceAllocationPublicProjectFinancialsBudgetResponse = z.object({budgetId: z.number().int().gte(1).optional(), budgetName: z.string().optional()}); export const resourceAllocationPublicAPIResponseForExample = z.object({allocationId: z.number().int().gte(1).optional(), startDate: z.string().optional(), endDate: z.string().optional(), secondsPerDay: z.number().int().optional(), minutesPerDay: z.number().int().optional(), hoursPerDay: z.number().int().optional(), duration: resourceAllocationTotalDurationPublicResponse.optional(), allocationType: z.enum(["SOFT", "HARD"]).optional(), allocationFor: z.enum(["TEAM_MEMBER", "PLACEHOLDER"]).optional(), project: projectPublicAPIAllocationResponseEntity.optional(), tasks: z.array(resourceAllocationTaskPublicAPIEntity).optional(), member: allocationUserPublicAPIResponseEntity.optional(), placeholder: placeholderResponsePublicAPI.optional(), createdAt: z.number().int().optional(), updatedAt: z.number().int().optional(), createdBy: allocationCreatedByUserPublicAPI.optional(), updatedBy: allocationUpdatedByUserPublicAPI.optional(), workId: z.number().int().optional(), workType: z.enum(["TASK", "PHASE", "MILESTONE"]).optional(), includeSaturday: z.boolean().optional(), includeSunday: z.boolean().optional(), fields: z.array(resourceAllocationFieldPublicResponseAPIEntity).optional(), budget: resourceAllocationPublicProjectFinancialsBudgetResponse.optional()}); export const examplePaginationResourceAllocations = z.object({pageSize: z.number().int().optional(), hasMore: z.boolean().optional(), totalRecordCount: z.number().int().optional(), nextPage: z.string().optional(), nextPageToken: z.string().optional()}); export const exampleAPIResponseResourceAllocations = z.object({data: z.array(resourceAllocationPublicAPIResponseForExample).optional(), pagination: examplePaginationResourceAllocations.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 all Resource allocations * * GET /1.0/resource-allocations */ export const getApi10ResourceAllocations = async (args: GetApi10ResourceAllocationsArgs, options?: GetApi10ResourceAllocationsOptions) => { 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.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (args.includeFields != null) query.append("includeFields", args.includeFields.join(',')) if (args.includeAllFields != null) query.append("includeAllFields", String(args.includeAllFields)) if (args.sortBy != null) query.append("sortBy", String(args.sortBy)) if (args.sortOrder != null) query.append("sortOrder", String(args.sortOrder)) if (args.match != null) query.append("match", String(args.match)) if (args['memberId.eq'] != null) query.append("memberId.eq", String(args['memberId.eq'])) if (args['memberId.oneOf'] != null) query.append("memberId.oneOf", String(args['memberId.oneOf'])) if (args['memberId.noneOf'] != null) query.append("memberId.noneOf", String(args['memberId.noneOf'])) if (args['projectId.eq'] != null) query.append("projectId.eq", String(args['projectId.eq'])) if (args['projectId.oneOf'] != null) query.append("projectId.oneOf", String(args['projectId.oneOf'])) if (args['projectId.noneOf'] != null) query.append("projectId.noneOf", String(args['projectId.noneOf'])) if (args['placeholderId.eq'] != null) query.append("placeholderId.eq", String(args['placeholderId.eq'])) if (args['placeholderId.oneOf'] != null) query.append("placeholderId.oneOf", String(args['placeholderId.oneOf'])) if (args['placeholderId.noneOf'] != null) query.append("placeholderId.noneOf", String(args['placeholderId.noneOf'])) if (apiKey !== undefined) headers.set("api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/1.0/resource-allocations${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(exampleAPIResponseResourceAllocations, await res.json()) };