UNPKG

attio-js

Version:

Developer-friendly & type-safe JS/TS SDK based on the official OpenAPI spec of Attio.

486 lines (441 loc) 13.9 kB
/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export type TaskId = { /** * The ID of the workspace the task belongs to. */ workspaceId: string; /** * The ID of the task. */ taskId: string; }; export type LinkedRecord = { /** * The ID of the parent object the task refers to. At present, only `people` and `companies` are supported. */ targetObjectId: string; /** * The ID of the parent record the task refers to. */ targetRecordId: string; }; /** * The type of actor. [Read more information on actor types here](/docs/actors). */ export const TaskReferencedActorType = { ApiToken: "api-token", WorkspaceMember: "workspace-member", System: "system", App: "app", } as const; /** * The type of actor. [Read more information on actor types here](/docs/actors). */ export type TaskReferencedActorType = ClosedEnum< typeof TaskReferencedActorType >; export type Assignee = { /** * The type of actor. [Read more information on actor types here](/docs/actors). */ referencedActorType: TaskReferencedActorType; /** * The ID of the workspace member actor assigned to this task. */ referencedActorId: string; }; /** * The type of actor. [Read more information on actor types here](/docs/actors). */ export const TaskType = { ApiToken: "api-token", WorkspaceMember: "workspace-member", System: "system", App: "app", } as const; /** * The type of actor. [Read more information on actor types here](/docs/actors). */ export type TaskType = ClosedEnum<typeof TaskType>; /** * The actor that created this task. */ export type TaskCreatedByActor = { /** * An ID to identify the actor. */ id?: string | null | undefined; /** * The type of actor. [Read more information on actor types here](/docs/actors). */ type?: TaskType | null | undefined; }; export type Task = { id: TaskId; /** * The plaintext representation of the task content. Inline linked records will appear as "@record name" and are returned in the `linked_records` property. */ contentPlaintext: string; /** * The deadline date of the task. Returned as an ISO 8601 timestamp. */ deadlineAt: string | null; /** * Whether the task has been completed. */ isCompleted: boolean; /** * Records linked to the task. Creating record links within task content text is not possible via the API at present. */ linkedRecords: Array<LinkedRecord>; /** * Workspace members assigned to this task. */ assignees: Array<Assignee>; /** * The actor that created this task. */ createdByActor: TaskCreatedByActor; /** * When the task was created. */ createdAt: string; }; /** @internal */ export const TaskId$inboundSchema: z.ZodType<TaskId, z.ZodTypeDef, unknown> = z .object({ workspace_id: z.string(), task_id: z.string(), }).transform((v) => { return remap$(v, { "workspace_id": "workspaceId", "task_id": "taskId", }); }); /** @internal */ export type TaskId$Outbound = { workspace_id: string; task_id: string; }; /** @internal */ export const TaskId$outboundSchema: z.ZodType< TaskId$Outbound, z.ZodTypeDef, TaskId > = z.object({ workspaceId: z.string(), taskId: z.string(), }).transform((v) => { return remap$(v, { workspaceId: "workspace_id", taskId: "task_id", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace TaskId$ { /** @deprecated use `TaskId$inboundSchema` instead. */ export const inboundSchema = TaskId$inboundSchema; /** @deprecated use `TaskId$outboundSchema` instead. */ export const outboundSchema = TaskId$outboundSchema; /** @deprecated use `TaskId$Outbound` instead. */ export type Outbound = TaskId$Outbound; } export function taskIdToJSON(taskId: TaskId): string { return JSON.stringify(TaskId$outboundSchema.parse(taskId)); } export function taskIdFromJSON( jsonString: string, ): SafeParseResult<TaskId, SDKValidationError> { return safeParse( jsonString, (x) => TaskId$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'TaskId' from JSON`, ); } /** @internal */ export const LinkedRecord$inboundSchema: z.ZodType< LinkedRecord, z.ZodTypeDef, unknown > = z.object({ target_object_id: z.string(), target_record_id: z.string(), }).transform((v) => { return remap$(v, { "target_object_id": "targetObjectId", "target_record_id": "targetRecordId", }); }); /** @internal */ export type LinkedRecord$Outbound = { target_object_id: string; target_record_id: string; }; /** @internal */ export const LinkedRecord$outboundSchema: z.ZodType< LinkedRecord$Outbound, z.ZodTypeDef, LinkedRecord > = z.object({ targetObjectId: z.string(), targetRecordId: z.string(), }).transform((v) => { return remap$(v, { targetObjectId: "target_object_id", targetRecordId: "target_record_id", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace LinkedRecord$ { /** @deprecated use `LinkedRecord$inboundSchema` instead. */ export const inboundSchema = LinkedRecord$inboundSchema; /** @deprecated use `LinkedRecord$outboundSchema` instead. */ export const outboundSchema = LinkedRecord$outboundSchema; /** @deprecated use `LinkedRecord$Outbound` instead. */ export type Outbound = LinkedRecord$Outbound; } export function linkedRecordToJSON(linkedRecord: LinkedRecord): string { return JSON.stringify(LinkedRecord$outboundSchema.parse(linkedRecord)); } export function linkedRecordFromJSON( jsonString: string, ): SafeParseResult<LinkedRecord, SDKValidationError> { return safeParse( jsonString, (x) => LinkedRecord$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'LinkedRecord' from JSON`, ); } /** @internal */ export const TaskReferencedActorType$inboundSchema: z.ZodNativeEnum< typeof TaskReferencedActorType > = z.nativeEnum(TaskReferencedActorType); /** @internal */ export const TaskReferencedActorType$outboundSchema: z.ZodNativeEnum< typeof TaskReferencedActorType > = TaskReferencedActorType$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace TaskReferencedActorType$ { /** @deprecated use `TaskReferencedActorType$inboundSchema` instead. */ export const inboundSchema = TaskReferencedActorType$inboundSchema; /** @deprecated use `TaskReferencedActorType$outboundSchema` instead. */ export const outboundSchema = TaskReferencedActorType$outboundSchema; } /** @internal */ export const Assignee$inboundSchema: z.ZodType< Assignee, z.ZodTypeDef, unknown > = z.object({ referenced_actor_type: TaskReferencedActorType$inboundSchema, referenced_actor_id: z.string(), }).transform((v) => { return remap$(v, { "referenced_actor_type": "referencedActorType", "referenced_actor_id": "referencedActorId", }); }); /** @internal */ export type Assignee$Outbound = { referenced_actor_type: string; referenced_actor_id: string; }; /** @internal */ export const Assignee$outboundSchema: z.ZodType< Assignee$Outbound, z.ZodTypeDef, Assignee > = z.object({ referencedActorType: TaskReferencedActorType$outboundSchema, referencedActorId: z.string(), }).transform((v) => { return remap$(v, { referencedActorType: "referenced_actor_type", referencedActorId: "referenced_actor_id", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace Assignee$ { /** @deprecated use `Assignee$inboundSchema` instead. */ export const inboundSchema = Assignee$inboundSchema; /** @deprecated use `Assignee$outboundSchema` instead. */ export const outboundSchema = Assignee$outboundSchema; /** @deprecated use `Assignee$Outbound` instead. */ export type Outbound = Assignee$Outbound; } export function assigneeToJSON(assignee: Assignee): string { return JSON.stringify(Assignee$outboundSchema.parse(assignee)); } export function assigneeFromJSON( jsonString: string, ): SafeParseResult<Assignee, SDKValidationError> { return safeParse( jsonString, (x) => Assignee$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Assignee' from JSON`, ); } /** @internal */ export const TaskType$inboundSchema: z.ZodNativeEnum<typeof TaskType> = z .nativeEnum(TaskType); /** @internal */ export const TaskType$outboundSchema: z.ZodNativeEnum<typeof TaskType> = TaskType$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace TaskType$ { /** @deprecated use `TaskType$inboundSchema` instead. */ export const inboundSchema = TaskType$inboundSchema; /** @deprecated use `TaskType$outboundSchema` instead. */ export const outboundSchema = TaskType$outboundSchema; } /** @internal */ export const TaskCreatedByActor$inboundSchema: z.ZodType< TaskCreatedByActor, z.ZodTypeDef, unknown > = z.object({ id: z.nullable(z.string()).optional(), type: z.nullable(TaskType$inboundSchema).optional(), }); /** @internal */ export type TaskCreatedByActor$Outbound = { id?: string | null | undefined; type?: string | null | undefined; }; /** @internal */ export const TaskCreatedByActor$outboundSchema: z.ZodType< TaskCreatedByActor$Outbound, z.ZodTypeDef, TaskCreatedByActor > = z.object({ id: z.nullable(z.string()).optional(), type: z.nullable(TaskType$outboundSchema).optional(), }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace TaskCreatedByActor$ { /** @deprecated use `TaskCreatedByActor$inboundSchema` instead. */ export const inboundSchema = TaskCreatedByActor$inboundSchema; /** @deprecated use `TaskCreatedByActor$outboundSchema` instead. */ export const outboundSchema = TaskCreatedByActor$outboundSchema; /** @deprecated use `TaskCreatedByActor$Outbound` instead. */ export type Outbound = TaskCreatedByActor$Outbound; } export function taskCreatedByActorToJSON( taskCreatedByActor: TaskCreatedByActor, ): string { return JSON.stringify( TaskCreatedByActor$outboundSchema.parse(taskCreatedByActor), ); } export function taskCreatedByActorFromJSON( jsonString: string, ): SafeParseResult<TaskCreatedByActor, SDKValidationError> { return safeParse( jsonString, (x) => TaskCreatedByActor$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'TaskCreatedByActor' from JSON`, ); } /** @internal */ export const Task$inboundSchema: z.ZodType<Task, z.ZodTypeDef, unknown> = z .object({ id: z.lazy(() => TaskId$inboundSchema), content_plaintext: z.string(), deadline_at: z.nullable(z.string()), is_completed: z.boolean(), linked_records: z.array(z.lazy(() => LinkedRecord$inboundSchema)), assignees: z.array(z.lazy(() => Assignee$inboundSchema)), created_by_actor: z.lazy(() => TaskCreatedByActor$inboundSchema), created_at: z.string(), }).transform((v) => { return remap$(v, { "content_plaintext": "contentPlaintext", "deadline_at": "deadlineAt", "is_completed": "isCompleted", "linked_records": "linkedRecords", "created_by_actor": "createdByActor", "created_at": "createdAt", }); }); /** @internal */ export type Task$Outbound = { id: TaskId$Outbound; content_plaintext: string; deadline_at: string | null; is_completed: boolean; linked_records: Array<LinkedRecord$Outbound>; assignees: Array<Assignee$Outbound>; created_by_actor: TaskCreatedByActor$Outbound; created_at: string; }; /** @internal */ export const Task$outboundSchema: z.ZodType<Task$Outbound, z.ZodTypeDef, Task> = z.object({ id: z.lazy(() => TaskId$outboundSchema), contentPlaintext: z.string(), deadlineAt: z.nullable(z.string()), isCompleted: z.boolean(), linkedRecords: z.array(z.lazy(() => LinkedRecord$outboundSchema)), assignees: z.array(z.lazy(() => Assignee$outboundSchema)), createdByActor: z.lazy(() => TaskCreatedByActor$outboundSchema), createdAt: z.string(), }).transform((v) => { return remap$(v, { contentPlaintext: "content_plaintext", deadlineAt: "deadline_at", isCompleted: "is_completed", linkedRecords: "linked_records", createdByActor: "created_by_actor", createdAt: "created_at", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace Task$ { /** @deprecated use `Task$inboundSchema` instead. */ export const inboundSchema = Task$inboundSchema; /** @deprecated use `Task$outboundSchema` instead. */ export const outboundSchema = Task$outboundSchema; /** @deprecated use `Task$Outbound` instead. */ export type Outbound = Task$Outbound; } export function taskToJSON(task: Task): string { return JSON.stringify(Task$outboundSchema.parse(task)); } export function taskFromJSON( jsonString: string, ): SafeParseResult<Task, SDKValidationError> { return safeParse( jsonString, (x) => Task$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Task' from JSON`, ); }