import {z} from 'zod' export type Translations = {values: {[key: string]: string}}; export type ShareAccess = {access: 'NONE' | 'LIMITED_READ' | 'LIMITED_WRITE' | 'STANDARD_READ' | 'STANDARD_WRITE' | 'COMPENSATION_READ' | 'FULL_READ' | 'COMP_PLANNING_PARTICIPANT' | 'COMPENSATION_WRITE' | 'WRITE' | 'COMPENSATION_OWNER' | 'OWNER', userId?: string | undefined, groupId?: string | undefined, everyone?: boolean | undefined, fields?: string | undefined}; export type MessageChannelConfig = {channels: Array<'EMAIL' | 'CHAT' | 'CHAT_SLACK' | 'CHAT_TEAMS'>, alwaysEmail: boolean}; export type GoalProgressUpdateConfig = {schedule: string, messageChannel?: MessageChannelConfig | undefined, message?: string | undefined, messageTr?: Translations | undefined}; export type UpdateGoal = {goalTypeId?: string | undefined, parentGoalId?: string | undefined, originalGoalId?: string | undefined, relatedGoalIds?: Array | undefined, ownerPersonIds?: Array | undefined, supportPersonIds?: Array | undefined, groupIds?: Array | undefined, label?: string | undefined, labelTr?: Translations | undefined, slug?: string | undefined, description?: string | undefined, descriptionTr?: Translations | undefined, startDate?: string | undefined, endDate?: string | undefined, sensitive?: ('GLOBAL' | 'ORG' | 'SENSITIVE' | 'PERSONAL' | 'MANAGER' | 'HIGH' | 'PRIVATE') | undefined, shareAccess?: Array | undefined, progressUpdateConfig?: GoalProgressUpdateConfig | undefined}; export type CreateApiV1OrgOrgIdGoalGoalIdCopyArgs = {orgId: string, goalId: string, body: UpdateGoal}; export type CreateApiV1OrgOrgIdGoalGoalIdCopyOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const translations = z.object({values: z.record(z.string(), z.string())}); export const shareAccess = z.object({access: z.enum(["NONE", "LIMITED_READ", "LIMITED_WRITE", "STANDARD_READ", "STANDARD_WRITE", "COMPENSATION_READ", "FULL_READ", "COMP_PLANNING_PARTICIPANT", "COMPENSATION_WRITE", "WRITE", "COMPENSATION_OWNER", "OWNER"]), userId: z.string().optional(), groupId: z.string().optional(), everyone: z.boolean().optional(), fields: z.string().optional()}); export const messageChannelConfig = z.object({channels: z.array(z.enum(["EMAIL", "CHAT", "CHAT_SLACK", "CHAT_TEAMS"])), alwaysEmail: z.boolean()}); export const goalProgressUpdateConfig = z.object({schedule: z.string(), messageChannel: messageChannelConfig.optional(), message: z.string().optional(), messageTr: translations.optional()}); export const goalTargetActual = z.object({goalTargetId: z.string(), value: z.union([z.string(), z.number(), z.boolean()]).optional()}); export const goalProgressForecast = z.object({goalTargetId: z.string(), type: z.enum(["WORST", "COMMIT", "CALL", "LIKELY", "BEST"]), label: z.string().optional(), value: z.union([z.string(), z.number(), z.boolean()]), labelTr: translations.optional()}); export const goalTargetWithValue = z.object({goalTargetId: z.string(), label: z.string(), value: z.union([z.string(), z.number(), z.boolean()]), color: z.string().optional(), labelTr: translations.optional()}); export const goalProgressSummary = z.object({id: z.string().optional(), percent: z.number().optional(), confidence: z.number().int().optional(), done: z.number().int().optional(), progressAt: z.string().optional(), at: z.string().optional(), actuals: z.array(goalTargetActual).optional(), forecasts: z.array(goalProgressForecast).optional(), targetValues: z.array(goalTargetWithValue).optional(), comment: z.string().optional()}); 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 goal = z.object({id: z.string(), orgId: z.string(), status: z.enum(["DRAFT", "ACTIVE", "DONE"]), goalTypeId: z.string(), parentGoalId: z.string().optional(), originalGoalId: z.string().optional(), relatedGoalIds: z.array(z.string()).optional(), ownerPersonIds: z.array(z.string()).optional(), supportPersonIds: z.array(z.string()).optional(), groupIds: z.array(z.string()).optional(), label: z.string(), labelTr: translations.optional(), slug: z.string(), description: z.string().optional(), descriptionTr: translations.optional(), startDate: z.string(), endDate: z.string(), sensitive: z.enum(["GLOBAL", "ORG", "SENSITIVE", "PERSONAL", "MANAGER", "HIGH", "PRIVATE"]), shareAccess: z.array(shareAccess), progressUpdateConfig: goalProgressUpdateConfig.optional(), progressSummary: goalProgressSummary.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 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 }; /** * Copy a goal and its targets into a new goal * * POST /v1/org/{orgId}/goal/{goalId}/copy */ export const createApiV1OrgOrgIdGoalGoalIdCopy = async (args: CreateApiV1OrgOrgIdGoalGoalIdCopyArgs, options?: CreateApiV1OrgOrgIdGoalGoalIdCopyOptions) => { const {baseUrl = "https://localhost", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/org/${encodeURIComponent(String(args.orgId))}/goal/${encodeURIComponent(String(args.goalId))}/copy${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(goal, await res.json()) };