import {z} from 'zod' export type GetApiV1OrgOrgIdAllocationJobJobIdArgs = {orgId: string, jobId: string, date?: string | undefined}; export type GetApiV1OrgOrgIdAllocationJobJobIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const attribution = z.object({principalUserId: z.string().optional(), agentUserIds: z.array(z.string()).optional(), eventId: z.string().optional(), aiChatId: z.string().optional(), aiToolUseId: z.string().optional(), channel: z.enum(["WEB", "MOBILE", "SLACK", "TEAMS", "MCP"]).optional()}); export const groupAllocation = z.object({id: z.string(), orgId: z.string(), jobId: z.string(), groupId: z.string(), groupTypeId: z.string(), allocation: z.number(), effectiveDate: z.string(), endDate: z.string().optional(), notes: z.string().optional(), derivedFromTeamAllocation: z.boolean().optional(), createId: z.string().optional(), createBehalfId: z.string().optional(), createAttribution: attribution.optional(), createAt: z.string().optional(), updateId: z.string().optional(), updateBehalfId: z.string().optional(), updateAttribution: attribution.optional(), updateAt: z.string().optional(), deleteId: z.string().optional(), deleteBehalfId: z.string().optional(), deleteAttribution: attribution.optional(), deleteAt: z.string().optional()}); export const getApiV1OrgOrgIdAllocationJobJobIdResponse = z.array(groupAllocation); 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 job's allocations on a date, across every group type * * GET /v1/org/{orgId}/allocation/job/{jobId} */ export const getApiV1OrgOrgIdAllocationJobJobId = async (args: GetApiV1OrgOrgIdAllocationJobJobIdArgs, options?: GetApiV1OrgOrgIdAllocationJobJobIdOptions) => { const {baseUrl = "https://localhost", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.date != null) query.append("date", String(args.date)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/org/${encodeURIComponent(String(args.orgId))}/allocation/job/${encodeURIComponent(String(args.jobId))}${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(getApiV1OrgOrgIdAllocationJobJobIdResponse, await res.json()) };