The Coline App SDK: apps, tools, file types and surfaces that run inside Coline workspaces, and public websites with Coline Sites. TypeScript, with an in-memory test workspace. MIT.
| 6 | emitAmbientEventsInputSchema, |
| 7 | appPermissionSchema, |
| 8 | type AppPermission, |
| 9 | type BatchDeleteAppIndexDocumentsInput, |
| 10 | type BatchUpsertAppIndexDocumentsInput, |
| 11 | type ColineAppRegistrationPayload, |
| 12 | type ColineAppRegistrationPayloadInput, |
| 13 | type CreateNotificationInputInput, |
| 14 | type EmitAmbientEventsInputInput, |
| 15 | } from "./manifest"; |
| 16 | import { ColineApiError } from "./errors"; |
| 17 | import type { components as AppPlatformComponents } from "./generated/app-platform-v1"; |
| 18 | import { |
| 19 | createAppPlatformClient, |
| 20 | type AppPlatformClient, |
| 21 | } from "./app-platform-client"; |
| 22 |
| 23 | interface ApiErrorPayload { |
| 24 | error?: { |
| 25 | code?: string; |
| 26 | message?: string; |
| 27 | }; |
| 28 | } |
| 29 |
| 30 | async function parseJsonResponse<T>(response: Response): Promise<T> { |
| 31 | const payload = (await response.json().catch(() => null)) as T | null; |
| 32 |
| 33 | if (!response.ok) { |
| 34 | const errorMessage = |
| 35 | payload && |
| 36 | typeof payload === "object" && |
| 37 | "error_description" in payload && |
| 38 | typeof (payload as Record<string, unknown>)["error_description"] === "string" |
| 39 | ? ((payload as Record<string, unknown>)["error_description"] as string) |
| 40 | : `Request failed (${response.status}).`; |
| 41 |
| 42 | throw new ColineApiError({ |
| 43 | message: errorMessage, |
| 44 | type: "oauth", |
| 45 | status: response.status, |
| 46 | code: |
| 47 | payload && |
| 48 | typeof payload === "object" && |
| 49 | "error" in payload && |
| 50 | typeof (payload as Record<string, unknown>)["error"] === "string" |
| 51 | ? ((payload as Record<string, unknown>)["error"] as string) |
| 52 | : null, |
| 53 | }); |
| 54 | } |
| 55 |
| 56 | if (!payload) { |
| 57 | throw new ColineApiError({ |
| 58 | message: "Invalid JSON response.", |
| 59 | type: "oauth", |
| 60 | status: response.status, |
| 61 | }); |
| 62 | } |
| 63 |
| 64 | return payload; |
| 65 | } |
| 66 |
| 67 | export interface ColineApiClientOptions { |
| 68 | baseUrl: string; |
| 69 | apiKey?: string; |
| 70 | fetch?: typeof fetch; |
| 71 | headers?: HeadersInit; |
| 72 | /** Maximum number of automatic retries on 429 / 5xx responses (default: 0). */ |
| 73 | maxRetries?: number; |
| 74 | /** Log requests and responses to console for debugging. */ |
| 75 | debug?: boolean; |
| 76 | } |
| 77 |
| 78 | type Schemas = AppPlatformComponents["schemas"]; |
| 79 | type UnwrapData<TKey extends keyof Schemas> = |
| 80 | Schemas[TKey] extends { data: infer T } ? T : never; |
| 81 |
| 82 | export type RegisteredAppDetail = Schemas["RegisteredAppDetail"]; |
| 83 | export type RegisteredAppRecord = Omit< |
| 84 | RegisteredAppDetail, |
| 85 | "latestPublishedVersionId" |
| 86 | >; |
| 87 | export type RegisteredAppVersionSummary = Schemas["RegisteredAppVersionSummary"]; |
| 88 | export type WorkspaceInstalledApp = Schemas["InstalledAppSummary"]; |
| 89 | export type WorkspaceAppCatalogItem = Schemas["AppCatalogItem"]; |
| 90 | export type WorkspaceAppsResponse = UnwrapData<"WorkspaceAppsResponse">; |
| 91 |
| 92 | export interface InstallWorkspaceAppInput { |
| 93 | appId: string; |
| 94 | pinnedVersionId?: string; |
| 95 | grantedPermissions?: AppPermission[]; |
| 96 | } |
| 97 |
| 98 | export type InstallWorkspaceAppResponse = UnwrapData<"InstallWorkspaceAppResponse">; |
| 99 |
| 100 | export interface SubmitAppVersionForReviewInput { |
| 101 | storeListed?: boolean; |
| 102 | } |
| 103 |
| 104 | export type SubmitAppVersionForReviewResponse = UnwrapData< |
| 105 | "SubmitAppVersionForReviewResponse" |
| 106 | >; |
| 107 | export type WorkspaceAppPermissionsResponse = UnwrapData< |
| 108 | "WorkspaceAppPermissionsResponse" |
| 109 | >; |
| 110 | export type WorkspaceInstalledAppResponse = UnwrapData< |
| 111 | "WorkspaceInstalledAppResponse" |
| 112 | >; |
| 113 | export type WorkspaceAppSecretsResponse = UnwrapData< |
| 114 | "WorkspaceAppSecretsResponse" |
| 115 | >; |
| 116 | export type WorkspaceAppSecretSummary = WorkspaceAppSecretsResponse["secrets"][number]; |
| 117 | export type CreateWorkspaceAppSecretResponse = UnwrapData< |
| 118 | "CreateWorkspaceAppSecretResponse" |
| 119 | >; |
| 120 | export type WorkspaceAppOauthConnectionsResponse = UnwrapData< |
| 121 | "WorkspaceAppOauthConnectionsResponse" |
| 122 | >; |
| 123 | export type WorkspaceAppOauthConnectionSummary = |
| 124 | WorkspaceAppOauthConnectionsResponse["connections"][number]; |
| 125 | export type CreateWorkspaceAppOauthConnectionResponse = UnwrapData< |
| 126 | "CreateWorkspaceAppOauthConnectionResponse" |
| 127 | >; |
| 128 | export type WorkspaceAppDeliveriesResponse = UnwrapData< |
| 129 | "WorkspaceAppDeliveriesResponse" |
| 130 | >; |
| 131 | export type WorkspaceAppDeliverySummary = |
| 132 | WorkspaceAppDeliveriesResponse["deliveries"][number]; |
| 133 | export type SendWorkspaceAppTestDeliveryResponse = UnwrapData< |
| 134 | "SendWorkspaceAppTestDeliveryResponse" |
| 135 | >; |
| 136 | export type AppFilesListResponse = UnwrapData<"AppFilesListResponse">; |
| 137 | export type AppFileDocumentResponse = UnwrapData<"AppFileDocumentResponse">; |
| 138 | export type AppFileDocumentUpdateResponse = UnwrapData< |
| 139 | "AppFileDocumentUpdateResponse" |
| 140 | >; |
| 141 | export type CreateAppFileResponse = UnwrapData<"CreateAppFileResponse">; |
| 142 | export type ExecuteAppActionResponse = UnwrapData<"ExecuteAppActionResponse">; |
| 143 | export type OkResponse = UnwrapData<"OkResponse">; |
| 144 | export type TabModelRecord = Schemas["TabModelRecord"]; |
| 145 | export type TabModelsResponse = UnwrapData<"TabModelsResponse">; |
| 146 | export type TabChatCompletionResponse = UnwrapData< |
| 147 | "TabChatCompletionResponseEnvelope" |
| 148 | >; |
| 149 | export type UpsertAppIndexDocumentsResponse = UnwrapData< |
| 150 | "UpsertAppIndexDocumentsResponse" |
| 151 | >; |
| 152 | export type DeleteAppIndexDocumentsResponse = UnwrapData< |
| 153 | "DeleteAppIndexDocumentsResponse" |
| 154 | >; |
| 155 | export type EmitAppAmbientEventsResponse = UnwrapData< |
| 156 | "EmitAppAmbientEventsResponse" |
| 157 | >; |
| 158 |
| 159 | export interface OAuthTokenResponse { |
| 160 | access_token: string; |
| 161 | token_type: "Bearer"; |
| 162 | expires_in: number; |
| 163 | refresh_token: string; |
| 164 | scope: string; |
| 165 | } |
| 166 |
| 167 | export interface OAuthUserInfoResponse { |
| 168 | sub: string; |
| 169 | email: string; |
| 170 | email_verified: boolean; |
| 171 | name: string; |
| 172 | given_name: string | null; |
| 173 | family_name: string | null; |
| 174 | picture: string | null; |
| 175 | preferred_username: string | null; |
| 176 | scope: string; |
| 177 | } |
| 178 |
| 179 | export interface UpdateWorkspaceAppPermissionsInput { |
| 180 | grantedPermissions: AppPermission[]; |
| 181 | } |
| 182 |
| 183 | export interface CreateWorkspaceAppSecretInput { |
| 184 | key: string; |
| 185 | value: string; |
| 186 | } |
| 187 |
| 188 | export interface CreateWorkspaceAppOauthConnectionInput { |
| 189 | providerKey: string; |
| 190 | externalAccountId?: string | null; |
| 191 | accessToken: string; |
| 192 | refreshToken?: string | null; |
| 193 | scopes: string[]; |
| 194 | tokenExpiresAt?: string | null; |
| 195 | metadata?: Record<string, unknown>; |
| 196 | } |
| 197 |
| 198 | export interface SendWorkspaceAppTestDeliveryInput { |
| 199 | eventType: string; |
| 200 | targetUrl?: string; |
| 201 | payload: Record<string, unknown>; |
| 202 | } |
| 203 |
| 204 | export interface ListAppFilesQuery { |
| 205 | driveId?: string; |
| 206 | typeKey?: string; |
| 207 | limit?: number; |
| 208 | } |
| 209 |
| 210 | export interface CreateAppFileInput { |
| 211 | name: string; |
| 212 | typeKey?: string; |
| 213 | driveId?: string; |
| 214 | parentId?: string | null; |
| 215 | document?: Record<string, unknown>; |
| 216 | } |
| 217 |
| 218 | export interface ExecuteAppActionInput { |
| 219 | action: { |
| 220 | type: string; |
| 221 | payload?: Record<string, unknown>; |
| 222 | }; |
| 223 | fileId?: string | null; |
| 224 | } |
| 225 |
| 226 | // --------------------------------------------------------------------------- |
| 227 | // Core Platform API — Types |
| 228 | // --------------------------------------------------------------------------- |
| 229 |
| 230 | export interface WorkspaceMember { |
| 231 | id: string; |
| 232 | workspaceMemberId: string; |
| 233 | email: string; |
| 234 | firstName: string | null; |
| 235 | lastName: string | null; |
| 236 | avatarUrl: string | null; |
| 237 | joinedAt: string; |
| 238 | roles: string[]; |
| 239 | } |
| 240 |
| 241 | export interface WorkspaceMembersResponse { |
| 242 | members: WorkspaceMember[]; |
| 243 | } |
| 244 |
| 245 | export interface WorkspaceNoteSummary { |
| 246 | id: string; |
| 247 | driveId: string; |
| 248 | parentId: string | null; |
| 249 | title: string; |
| 250 | body: string; |
| 251 | color: string | null; |
| 252 | createdByUserId: string | null; |
| 253 | createdAt: string; |
| 254 | updatedAt: string; |
| 255 | } |
| 256 |
| 257 | export interface WorkspaceNoteDetail extends WorkspaceNoteSummary { |
| 258 | blocks: unknown[]; |
| 259 | } |
| 260 |
| 261 | export interface WorkspaceNotesListResponse { |
| 262 | notes: WorkspaceNoteSummary[]; |
| 263 | page: { limit: number; hasMore: boolean; nextCursor: string | null }; |
| 264 | } |
| 265 |
| 266 | export interface WorkspaceNoteResponse { |
| 267 | note: WorkspaceNoteSummary; |
| 268 | } |
| 269 |
| 270 | export interface WorkspaceNoteDetailResponse { |
| 271 | note: WorkspaceNoteDetail; |
| 272 | } |
| 273 |
| 274 | export interface ListWorkspaceNotesQuery { |
| 275 | q?: string; |
| 276 | limit?: number; |
| 277 | cursor?: string; |
| 278 | } |
| 279 |
| 280 | export interface CreateWorkspaceNoteInput { |
| 281 | title?: string; |
| 282 | body?: string; |
| 283 | blocks?: unknown[]; |
| 284 | driveId?: string; |
| 285 | parentId?: string | null; |
| 286 | } |
| 287 |
| 288 | export interface UpdateWorkspaceNoteInput { |
| 289 | title?: string; |
| 290 | body?: string; |
| 291 | blocks?: unknown[]; |
| 292 | } |
| 293 |
| 294 | export interface CalendarEventLinkInput { |
| 295 | linkType: "file" | "channel" | "url"; |
| 296 | fileId?: string; |
| 297 | channelId?: string; |
| 298 | url?: string; |
| 299 | label?: string | null; |
| 300 | } |
| 301 |
| 302 | // --------------------------------------------------------------------------- |
| 303 | // Core Platform API — Docs Types |
| 304 | // --------------------------------------------------------------------------- |
| 305 |
| 306 | export interface DocLayout { |
| 307 | mode: "pages"; |
| 308 | pageSize: "letter"; |
| 309 | orientation: "portrait" | "landscape"; |
| 310 | margins: "normal" | "narrow" | "wide"; |
| 311 | backgroundColor: string | null; |
| 312 | showPageNumbers: boolean; |
| 313 | } |
| 314 |
| 315 | export interface WorkspaceDocSummary { |
| 316 | id: string; |
| 317 | driveId: string; |
| 318 | parentId: string | null; |
| 319 | title: string; |
| 320 | excerpt: string; |
| 321 | color: string | null; |
| 322 | layout: DocLayout; |
| 323 | createdByUserId: string | null; |
| 324 | createdAt: string; |
| 325 | updatedAt: string; |
| 326 | } |
| 327 |
| 328 | export interface WorkspaceDocDetail extends Omit<WorkspaceDocSummary, "excerpt"> { |
| 329 | content: Record<string, unknown>; |
| 330 | plainText: string; |
| 331 | } |
| 332 |
| 333 | export interface WorkspaceDocsListResponse { |
| 334 | docs: WorkspaceDocSummary[]; |
| 335 | page: { limit: number; hasMore: boolean; nextCursor: string | null }; |
| 336 | } |
| 337 |
| 338 | export interface WorkspaceDocResponse { |
| 339 | doc: WorkspaceDocSummary; |
| 340 | } |
| 341 |
| 342 | export interface WorkspaceDocDetailResponse { |
| 343 | doc: WorkspaceDocDetail; |
| 344 | } |
| 345 |
| 346 | export interface ListWorkspaceDocsQuery { |
| 347 | q?: string; |
| 348 | limit?: number; |
| 349 | cursor?: string; |
| 350 | } |
| 351 |
| 352 | export interface CreateWorkspaceDocInput { |
| 353 | title?: string; |
| 354 | content?: Record<string, unknown>; |
| 355 | layout?: { |
| 356 | orientation?: "portrait" | "landscape"; |
| 357 | margins?: "normal" | "narrow" | "wide"; |
| 358 | backgroundColor?: string | null; |
| 359 | showPageNumbers?: boolean; |
| 360 | }; |
| 361 | driveId?: string; |
| 362 | parentId?: string | null; |
| 363 | } |
| 364 |
| 365 | export interface UpdateWorkspaceDocInput { |
| 366 | title?: string; |
| 367 | content?: Record<string, unknown>; |
| 368 | layout?: { |
| 369 | orientation?: "portrait" | "landscape"; |
| 370 | margins?: "normal" | "narrow" | "wide"; |
| 371 | backgroundColor?: string | null; |
| 372 | showPageNumbers?: boolean; |
| 373 | }; |
| 374 | } |
| 375 |
| 376 | // --------------------------------------------------------------------------- |
| 377 | // Core Platform API — Drives & Files Types |
| 378 | // --------------------------------------------------------------------------- |
| 379 |
| 380 | export interface DriveMountSummary { |
| 381 | type: "native" | "integration"; |
| 382 | providerKey: string | null; |
| 383 | syncStatus: "idle" | "syncing" | "errored" | "disabled"; |
| 384 | } |
| 385 |
| 386 | export interface WorkspaceDriveSummary { |
| 387 | id: string; |
| 388 | name: string; |
| 389 | slug: string; |
| 390 | kind: "personal" | "shared"; |
| 391 | accessMode: "workspace_default" | "restricted"; |
| 392 | isDefault: boolean; |
| 393 | ownerUserId: string | null; |
| 394 | mount: DriveMountSummary; |
| 395 | createdAt: string; |
| 396 | updatedAt: string; |
| 397 | } |
| 398 |
| 399 | export interface WorkspaceDrivesListResponse { |
| 400 | drives: WorkspaceDriveSummary[]; |
| 401 | } |
| 402 |
| 403 | export interface DriveFileSummary { |
| 404 | id: string; |
| 405 | driveId: string; |
| 406 | parentId: string | null; |
| 407 | name: string; |
| 408 | fileType: string; |
| 409 | mimeType: string | null; |
| 410 | sizeBytes: number | null; |
| 411 | color: string | null; |
| 412 | createdByUserId: string | null; |
| 413 | createdAt: string; |
| 414 | updatedAt: string; |
| 415 | } |
| 416 |
| 417 | export interface DriveFilesListResponse { |
| 418 | files: DriveFileSummary[]; |
| 419 | page: { limit: number; hasMore: boolean; nextCursor: string | null }; |
| 420 | } |
| 421 |
| 422 | export interface ListDriveFilesQuery { |
| 423 | parentId?: string; |
| 424 | fileType?: string; |
| 425 | trashed?: boolean; |
| 426 | limit?: number; |
| 427 | cursor?: string; |
| 428 | } |
| 429 |
| 430 | export interface FileDetail { |
| 431 | id: string; |
| 432 | driveId: string; |
| 433 | parentId: string | null; |
| 434 | name: string; |
| 435 | fileType: string; |
| 436 | mimeType: string | null; |
| 437 | sizeBytes: number | null; |
| 438 | color: string | null; |
| 439 | accessMode: string; |
| 440 | isTrashed: boolean; |
| 441 | createdByUserId: string | null; |
| 442 | createdAt: string; |
| 443 | updatedAt: string; |
| 444 | } |
| 445 |
| 446 | export interface FileDetailResponse { |
| 447 | file: FileDetail; |
| 448 | } |
| 449 |
| 450 | export interface UpdateFileInput { |
| 451 | name?: string; |
| 452 | parentId?: string | null; |
| 453 | color?: "red" | "orange" | "yellow" | "green" | "blue" | "purple" | "pink" | "gray" | null; |
| 454 | } |
| 455 |
| 456 | // --------------------------------------------------------------------------- |
| 457 | // Channels |
| 458 | // --------------------------------------------------------------------------- |
| 459 |
| 460 | export interface ChannelSummary { |
| 461 | id: string; |
| 462 | name: string; |
| 463 | slug: string; |
| 464 | description: string | null; |
| 465 | topic: string | null; |
| 466 | type: "public" | "private"; |
| 467 | isDefault: boolean; |
| 468 | createdAt: string; |
| 469 | updatedAt: string; |
| 470 | } |
| 471 |
| 472 | export interface ChannelListResponse { |
| 473 | channels: ChannelSummary[]; |
| 474 | } |
| 475 |
| 476 | // --------------------------------------------------------------------------- |
| 477 | // Direct Messages |
| 478 | // --------------------------------------------------------------------------- |
| 479 |
| 480 | export interface DmMemberSummary { |
| 481 | userId: string; |
| 482 | firstName: string | null; |
| 483 | lastName: string | null; |
| 484 | email: string; |
| 485 | } |
| 486 |
| 487 | export interface DmSummary { |
| 488 | id: string; |
| 489 | isGroup: boolean; |
| 490 | name: string | null; |
| 491 | members: DmMemberSummary[]; |
| 492 | createdAt: string; |
| 493 | updatedAt: string; |
| 494 | } |
| 495 |
| 496 | export interface DmListResponse { |
| 497 | dms: DmSummary[]; |
| 498 | } |
| 499 |
| 500 | // --------------------------------------------------------------------------- |
| 501 | // Messages |
| 502 | // --------------------------------------------------------------------------- |
| 503 |
| 504 | export interface MessageTextPart { |
| 505 | type: "text"; |
| 506 | text: string; |
| 507 | } |
| 508 |
| 509 | export interface MessageMentionPart { |
| 510 | type: "mention"; |
| 511 | userId: string; |
| 512 | displayName: string; |
| 513 | } |
| 514 |
| 515 | export type MessageContentPart = MessageTextPart | MessageMentionPart; |
| 516 |
| 517 | export interface ContainerMessageSummary { |
| 518 | id: string; |
| 519 | authorUserId: string | null; |
| 520 | messageKind: string; |
| 521 | plaintext: string; |
| 522 | content: MessageContentPart[]; |
| 523 | replyToMessageId: string | null; |
| 524 | editedAt: string | null; |
| 525 | createdAt: string; |
| 526 | updatedAt: string; |
| 527 | } |
| 528 |
| 529 | export interface MessagesListResponse { |
| 530 | messages: ContainerMessageSummary[]; |
| 531 | page: { |
| 532 | limit: number; |
| 533 | hasMore: boolean; |
| 534 | nextCursor: string | null; |
| 535 | }; |
| 536 | } |
| 537 |
| 538 | export interface SendMessageInput { |
| 539 | content: MessageContentPart[]; |
| 540 | replyToMessageId?: string | null; |
| 541 | threadRootMessageId?: string | null; |
| 542 | } |
| 543 |
| 544 | export interface SendMessageResponse { |
| 545 | message: ContainerMessageSummary; |
| 546 | } |
| 547 |
| 548 | export interface MessageDetailResponse { |
| 549 | message: ContainerMessageSummary & { |
| 550 | containerType: string; |
| 551 | containerId: string; |
| 552 | }; |
| 553 | } |
| 554 |
| 555 | export interface EditMessageInput { |
| 556 | content: MessageContentPart[]; |
| 557 | } |
| 558 |
| 559 | export interface ThreadResponse { |
| 560 | rootMessage: MessageDetailResponse["message"]; |
| 561 | replies: ContainerMessageSummary[]; |
| 562 | } |
| 563 |
| 564 | export interface ThreadReplyInput { |
| 565 | content: MessageContentPart[]; |
| 566 | } |
| 567 |
| 568 | export interface ReactionResponse { |
| 569 | messageId: string; |
| 570 | emoji: string; |
| 571 | count: number; |
| 572 | } |
| 573 |
| 574 | export interface PinResponse { |
| 575 | messageId: string; |
| 576 | pinned: boolean; |
| 577 | } |
| 578 |
| 579 | export interface CalendarRecurrenceRule { |
| 580 | frequency: "daily" | "weekly" | "monthly" | "yearly"; |
| 581 | interval: number; |
| 582 | byDay?: Array<"MO" | "TU" | "WE" | "TH" | "FR" | "SA" | "SU">; |
| 583 | count?: number; |
| 584 | until?: string; |
| 585 | } |
| 586 |
| 587 | export interface CreateCalendarEventInput { |
| 588 | title: string; |
| 589 | description?: string | null; |
| 590 | location?: string | null; |
| 591 | startsAt: string; |
| 592 | endsAt: string; |
| 593 | timeZone: string; |
| 594 | isAllDay?: boolean; |
| 595 | visibility?: "private" | "invitees" | "workspace"; |
| 596 | attendeeUserIds?: string[]; |
| 597 | linkInputs?: CalendarEventLinkInput[]; |
| 598 | recurrenceRule?: CalendarRecurrenceRule | null; |
| 599 | } |
| 600 |
| 601 | export interface UpdateCalendarEventInput { |
| 602 | title?: string; |
| 603 | description?: string | null; |
| 604 | location?: string | null; |
| 605 | startsAt?: string; |
| 606 | endsAt?: string; |
| 607 | timeZone?: string; |
| 608 | isAllDay?: boolean; |
| 609 | visibility?: "private" | "invitees" | "workspace"; |
| 610 | status?: "active" | "canceled"; |
| 611 | attendeeUserIds?: string[]; |
| 612 | linkInputs?: CalendarEventLinkInput[]; |
| 613 | recurrenceRule?: CalendarRecurrenceRule | null; |
| 614 | } |
| 615 |
| 616 | /** |
| 617 | * Calendar events list response — shape matches the server's `listCalendarEvents` output. |
| 618 | */ |
| 619 | export type CalendarEventsListResponse = Record<string, unknown>; |
| 620 |
| 621 | /** |
| 622 | * Calendar event detail response — shape matches the server's `getCalendarEventDetail` output. |
| 623 | */ |
| 624 | export type CalendarEventDetailResponse = Record<string, unknown>; |
| 625 |
| 626 | export interface WorkspaceSearchInput { |
| 627 | query: string; |
| 628 | sourceKinds?: Array< |
| 629 | "file" | "task" | "container_message" | "kairo_message" | "app_document" |
| 630 | >; |
| 631 | limit?: number; |
| 632 | cursor?: string; |
| 633 | } |
| 634 |
| 635 | export interface WorkspaceSearchResult { |
| 636 | id: string; |
| 637 | title: string | null; |
| 638 | snippet: string | null; |
| 639 | sourceKind: string; |
| 640 | sourceId: string; |
| 641 | url: string | null; |
| 642 | score: number; |
| 643 | } |
| 644 |
| 645 | export interface WorkspaceSearchResponse { |
| 646 | results: WorkspaceSearchResult[]; |
| 647 | nextCursor: string | null; |
| 648 | } |
| 649 |
| 650 | export interface TaskboardStatusSummary { |
| 651 | id: string; |
| 652 | key: string; |
| 653 | name: string; |
| 654 | color: string; |
| 655 | isDefault: boolean; |
| 656 | isCompleted: boolean; |
| 657 | sortOrder: number; |
| 658 | } |
| 659 |
| 660 | export interface TaskboardSummary { |
| 661 | id: string; |
| 662 | name: string; |
| 663 | driveId: string; |
| 664 | color: string | null; |
| 665 | identifierPrefix: string | null; |
| 666 | description: string | null; |
| 667 | defaultView: string | null; |
| 668 | statuses: TaskboardStatusSummary[]; |
| 669 | createdAt: string; |
| 670 | updatedAt: string; |
| 671 | } |
| 672 |
| 673 | export interface WorkspaceTaskboardsResponse { |
| 674 | taskboards: TaskboardSummary[]; |
| 675 | } |
| 676 |
| 677 | export interface TaskAssignee { |
| 678 | id: string; |
| 679 | firstName: string | null; |
| 680 | lastName: string | null; |
| 681 | avatarUrl: string | null; |
| 682 | email: string; |
| 683 | } |
| 684 |
| 685 | export interface TaskSummary { |
| 686 | id: string; |
| 687 | taskboardId: string; |
| 688 | taskNumber: number; |
| 689 | identifier: string | null; |
| 690 | title: string; |
| 691 | description: string | null; |
| 692 | status: { |
| 693 | id: string; |
| 694 | key: string; |
| 695 | name: string; |
| 696 | color: string; |
| 697 | isCompleted: boolean; |
| 698 | } | null; |
| 699 | priority: string; |
| 700 | labels: string[]; |
| 701 | dueDate: string | null; |
| 702 | assignees: TaskAssignee[]; |
| 703 | isCompleted: boolean; |
| 704 | completedAt: string | null; |
| 705 | createdByUserId: string | null; |
| 706 | createdAt: string; |
| 707 | updatedAt: string; |
| 708 | } |
| 709 |
| 710 | export interface TaskboardTasksResponse { |
| 711 | tasks: TaskSummary[]; |
| 712 | } |
| 713 |
| 714 | export interface ListTaskboardTasksQuery { |
| 715 | q?: string; |
| 716 | statusId?: string; |
| 717 | assigneeUserId?: string; |
| 718 | limit?: number; |
| 719 | } |
| 720 |
| 721 | export interface CreateTaskInput { |
| 722 | title: string; |
| 723 | description?: string; |
| 724 | statusId?: string; |
| 725 | priority?: "none" | "low" | "medium" | "high" | "urgent"; |
| 726 | dueDate?: string | null; |
| 727 | labels?: string[]; |
| 728 | assigneeUserIds?: string[]; |
| 729 | } |
| 730 |
| 731 | export interface CreateTaskResponse { |
| 732 | task: { |
| 733 | id: string; |
| 734 | taskboardId: string; |
| 735 | title: string; |
| 736 | description: string; |
| 737 | statusId: string; |
| 738 | priority: string; |
| 739 | labels: string[]; |
| 740 | dueDate: string | null; |
| 741 | assigneeUserIds: string[]; |
| 742 | createdByUserId: string; |
| 743 | createdAt: string; |
| 744 | updatedAt: string; |
| 745 | }; |
| 746 | } |
| 747 |
| 748 | export interface UpdateTaskInput { |
| 749 | title?: string; |
| 750 | description?: string; |
| 751 | statusId?: string; |
| 752 | priority?: "none" | "low" | "medium" | "high" | "urgent"; |
| 753 | dueDate?: string | null; |
| 754 | labels?: string[]; |
| 755 | assigneeUserIds?: string[]; |
| 756 | } |
| 757 |
| 758 | // --------------------------------------------------------------------------- |
| 759 | // Pagination helper |
| 760 | // --------------------------------------------------------------------------- |
| 761 |
| 762 | /** |
| 763 | * A page from a paginated endpoint. |
| 764 | */ |
| 765 | export interface Page<T> { |
| 766 | items: T[]; |
| 767 | nextCursor: string | null; |
| 768 | hasMore: boolean; |
| 769 | } |
| 770 |
| 771 | /** |
| 772 | * Async generator that auto-fetches subsequent pages from a paginated Coline |
| 773 | * endpoint. Yields one item at a time. |
| 774 | * |
| 775 | * @example |
| 776 | * ```ts |
| 777 | * const ws = coline.workspace("ws_123"); |
| 778 | * for await (const note of ws.paginateNotes({ limit: 50 })) { |
| 779 | * console.log(note.title); |
| 780 | * } |
| 781 | * ``` |
| 782 | */ |
| 783 | export async function* paginate<T>( |
| 784 | fetchPage: (cursor: string | undefined) => Promise<Page<T>>, |
| 785 | ): AsyncGenerator<T, void, undefined> { |
| 786 | let cursor: string | undefined = undefined; |
| 787 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
| 788 | while (true) { |
| 789 | const page = await fetchPage(cursor); |
| 790 | for (const item of page.items) { |
| 791 | yield item; |
| 792 | } |
| 793 | if (!page.hasMore || page.nextCursor === null) break; |
| 794 | cursor = page.nextCursor; |
| 795 | } |
| 796 | } |
| 797 |
| 798 | // --------------------------------------------------------------------------- |
| 799 | // Retry + backoff helper |
| 800 | // --------------------------------------------------------------------------- |
| 801 |
| 802 | function isRetryableStatus(status: number): boolean { |
| 803 | return status === 429 || status >= 500; |
| 804 | } |
| 805 |
| 806 | async function sleep(ms: number): Promise<void> { |
| 807 | return new Promise((resolve) => setTimeout(resolve, ms)); |
| 808 | } |
| 809 |
| 810 | function joinUrl(baseUrl: string, path: string): string { |
| 811 | return `${baseUrl.replace(/\/+$/, "")}${path}`; |
| 812 | } |
| 813 |
| 814 | function toRegisterAppInput(payload: ColineAppRegistrationPayload) { |
| 815 | const notificationChannels = payload.manifest.notificationChannels.map((channel) => ({ |
| 816 | key: channel.key, |
| 817 | name: channel.name, |
| 818 | defaultDeliveries: [...channel.defaultDeliveries], |
| 819 | defaultPriority: channel.defaultPriority, |
| 820 | ...(channel.description ? { description: channel.description } : {}), |
| 821 | })); |
| 822 |
| 823 | const ui = |
| 824 | payload.manifest.ui.mode || payload.manifest.ui.homePath || payload.manifest.ui.filePath |
| 825 | ? { |
| 826 | ...(payload.manifest.ui.mode |
| 827 | ? { mode: payload.manifest.ui.mode } |
| 828 | : {}), |
| 829 | ...(payload.manifest.ui.homePath |
| 830 | ? { homePath: payload.manifest.ui.homePath } |
| 831 | : {}), |
| 832 | ...(payload.manifest.ui.filePath |
| 833 | ? { filePath: payload.manifest.ui.filePath } |
| 834 | : {}), |
| 835 | } |
| 836 | : undefined; |
| 837 |
| 838 | const manifest = { |
| 839 | key: payload.manifest.key, |
| 840 | name: payload.manifest.name, |
| 841 | permissions: payload.manifest.permissions, |
| 842 | notificationChannels, |
| 843 | hosting: { |
| 844 | mode: payload.manifest.hosting.mode, |
| 845 | baseUrl: payload.manifest.hosting.baseUrl, |
| 846 | }, |
| 847 | ...(ui ? { ui } : {}), |
| 848 | ...(payload.manifest.description |
| 849 | ? { description: payload.manifest.description } |
| 850 | : {}), |
| 851 | ...(payload.manifest.iconUrl ? { iconUrl: payload.manifest.iconUrl } : {}), |
| 852 | ...(payload.manifest.kairo |
| 853 | ? { |
| 854 | kairo: JSON.parse(JSON.stringify(payload.manifest.kairo)) as Record< |
| 855 | string, |
| 856 | unknown |
| 857 | >, |
| 858 | } |
| 859 | : {}), |
| 860 | }; |
| 861 |
| 862 | const fileTypes = payload.fileTypes.map((fileType) => ({ |
| 863 | typeKey: fileType.typeKey, |
| 864 | name: fileType.name, |
| 865 | storage: fileType.storage, |
| 866 | indexable: fileType.indexable, |
| 867 | homeRenderMode: fileType.homeRenderMode, |
| 868 | ...(fileType.description ? { description: fileType.description } : {}), |
| 869 | })); |
| 870 |
| 871 | return { |
| 872 | version: payload.version, |
| 873 | manifest, |
| 874 | fileTypes, |
| 875 | }; |
| 876 | } |
| 877 |
| 878 | export class ColineApiClient { |
| 879 | private readonly baseUrl: string; |
| 880 | private readonly apiKey: string | undefined; |
| 881 | private readonly fetchImpl: typeof fetch; |
| 882 | private readonly defaultHeaders: HeadersInit | undefined; |
| 883 | private readonly appPlatformClient: AppPlatformClient; |
| 884 | private readonly maxRetries: number; |
| 885 | private readonly debug: boolean; |
| 886 |
| 887 | constructor(options: ColineApiClientOptions) { |
| 888 | this.baseUrl = options.baseUrl; |
| 889 | this.apiKey = options.apiKey; |
| 890 | this.fetchImpl = options.fetch ?? fetch; |
| 891 | this.defaultHeaders = options.headers; |
| 892 | this.maxRetries = options.maxRetries ?? 0; |
| 893 | this.debug = options.debug ?? false; |
| 894 | this.appPlatformClient = createAppPlatformClient(options); |
| 895 | } |
| 896 |
| 897 | private async unwrapGeneratedResponse<T>( |
| 898 | promise: Promise<{ |
| 899 | data?: { data: T }; |
| 900 | error?: ApiErrorPayload; |
| 901 | response: Response; |
| 902 | }>, |
| 903 | ): Promise<T> { |
| 904 | const { data, error, response } = await promise; |
| 905 |
| 906 | if (error) { |
| 907 | throw new ColineApiError({ |
| 908 | message: error.error?.message ?? `Request failed (${response.status}).`, |
| 909 | type: "api", |
| 910 | status: response.status, |
| 911 | code: error.error?.code ?? null, |
| 912 | }); |
| 913 | } |
| 914 |
| 915 | if (data === undefined) { |
| 916 | throw new ColineApiError({ |
| 917 | message: "Invalid API response.", |
| 918 | type: "api", |
| 919 | status: response.status, |
| 920 | }); |
| 921 | } |
| 922 |
| 923 | return data.data; |
| 924 | } |
| 925 |
| 926 | withApiKey(apiKey: string): ColineApiClient { |
| 927 | const options: ColineApiClientOptions = { |
| 928 | baseUrl: this.baseUrl, |
| 929 | apiKey, |
| 930 | fetch: this.fetchImpl, |
| 931 | maxRetries: this.maxRetries, |
| 932 | debug: this.debug, |
| 933 | }; |
| 934 |
| 935 | if (this.defaultHeaders !== undefined) { |
| 936 | options.headers = this.defaultHeaders; |
| 937 | } |
| 938 |
| 939 | return new ColineApiClient(options); |
| 940 | } |
| 941 |
| 942 | withHeaders(headers: HeadersInit): ColineApiClient { |
| 943 | const mergedHeaders = new Headers(this.defaultHeaders); |
| 944 | new Headers(headers).forEach((value, key) => mergedHeaders.set(key, value)); |
| 945 |
| 946 | const options: ColineApiClientOptions = { |
| 947 | baseUrl: this.baseUrl, |
| 948 | fetch: this.fetchImpl, |
| 949 | headers: mergedHeaders, |
| 950 | maxRetries: this.maxRetries, |
| 951 | debug: this.debug, |
| 952 | }; |
| 953 |
| 954 | if (this.apiKey !== undefined) { |
| 955 | options.apiKey = this.apiKey; |
| 956 | } |
| 957 |
| 958 | return new ColineApiClient(options); |
| 959 | } |
| 960 |
| 961 | buildLoginWithColineAuthorizeUrl(input: { |
| 962 | clientId: string; |
| 963 | redirectUri: string; |
| 964 | scope?: string; |
| 965 | state?: string; |
| 966 | codeChallenge?: string; |
| 967 | codeChallengeMethod?: "S256" | "plain"; |
| 968 | }): string { |
| 969 | const url = new URL("/api/v1/oauth/authorize", this.baseUrl); |
| 970 | url.searchParams.set("response_type", "code"); |
| 971 | url.searchParams.set("client_id", input.clientId); |
| 972 | url.searchParams.set("redirect_uri", input.redirectUri); |
| 973 | if (input.scope) { |
| 974 | url.searchParams.set("scope", input.scope); |
| 975 | } |
| 976 | if (input.state) { |
| 977 | url.searchParams.set("state", input.state); |
| 978 | } |
| 979 | if (input.codeChallenge) { |
| 980 | url.searchParams.set("code_challenge", input.codeChallenge); |
| 981 | } |
| 982 | if (input.codeChallengeMethod) { |
| 983 | url.searchParams.set("code_challenge_method", input.codeChallengeMethod); |
| 984 | } |
| 985 | return url.toString(); |
| 986 | } |
| 987 |
| 988 | async listApps(): Promise<{ apps: RegisteredAppRecord[] }> { |
| 989 | return this.unwrapGeneratedResponse( |
| 990 | this.appPlatformClient.GET("/api/v1/apps"), |
| 991 | ); |
| 992 | } |
| 993 |
| 994 | async getApp(appKey: string): Promise<{ app: RegisteredAppDetail }> { |
| 995 | return this.unwrapGeneratedResponse( |
| 996 | this.appPlatformClient.GET("/api/v1/apps/{appKey}", { |
| 997 | params: { path: { appKey } }, |
| 998 | }), |
| 999 | ); |
| 1000 | } |
| 1001 |
| 1002 | async listAppVersions( |
| 1003 | appKey: string, |
| 1004 | ): Promise<{ versions: RegisteredAppVersionSummary[] }> { |
| 1005 | return this.unwrapGeneratedResponse( |
| 1006 | this.appPlatformClient.GET("/api/v1/apps/{appKey}/versions", { |
| 1007 | params: { path: { appKey } }, |
| 1008 | }), |
| 1009 | ); |
| 1010 | } |
| 1011 |
| 1012 | async registerApp( |
| 1013 | payload: ColineAppRegistrationPayloadInput, |
| 1014 | ): Promise<{ appId: string; appKey: string; versionId: string; version: string }> { |
| 1015 | const body = toRegisterAppInput(colineAppRegistrationPayloadSchema.parse(payload)); |
| 1016 |
| 1017 | return this.unwrapGeneratedResponse( |
| 1018 | this.appPlatformClient.POST("/api/v1/apps", { |
| 1019 | body, |
| 1020 | }), |
| 1021 | ); |
| 1022 | } |
| 1023 |
| 1024 | async createAppVersion( |
| 1025 | appKey: string, |
| 1026 | payload: ColineAppRegistrationPayloadInput, |
| 1027 | ): Promise<{ appId: string; appKey: string; versionId: string; version: string }> { |
| 1028 | const body = toRegisterAppInput(colineAppRegistrationPayloadSchema.parse(payload)); |
| 1029 |
| 1030 | return this.unwrapGeneratedResponse( |
| 1031 | this.appPlatformClient.POST("/api/v1/apps/{appKey}/versions", { |
| 1032 | params: { path: { appKey } }, |
| 1033 | body, |
| 1034 | }), |
| 1035 | ); |
| 1036 | } |
| 1037 |
| 1038 | async submitAppVersionForReview( |
| 1039 | appKey: string, |
| 1040 | versionId: string, |
| 1041 | input: SubmitAppVersionForReviewInput = {}, |
| 1042 | ): Promise<SubmitAppVersionForReviewResponse> { |
| 1043 | return this.unwrapGeneratedResponse( |
| 1044 | this.appPlatformClient.POST( |
| 1045 | "/api/v1/apps/{appKey}/versions/{versionId}/submit", |
| 1046 | { |
| 1047 | params: { path: { appKey, versionId } }, |
| 1048 | body: { |
| 1049 | ...(input.storeListed !== undefined |
| 1050 | ? { storeListed: input.storeListed } |
| 1051 | : {}), |
| 1052 | }, |
| 1053 | }, |
| 1054 | ), |
| 1055 | ); |
| 1056 | } |
| 1057 |
| 1058 | async listWorkspaceApps(workspaceSlug: string): Promise<WorkspaceAppsResponse> { |
| 1059 | return this.unwrapGeneratedResponse( |
| 1060 | this.appPlatformClient.GET("/api/v1/workspaces/{workspaceSlug}/apps", { |
| 1061 | params: { path: { workspaceSlug } }, |
| 1062 | }), |
| 1063 | ); |
| 1064 | } |
| 1065 |
| 1066 | async installWorkspaceApp( |
| 1067 | workspaceSlug: string, |
| 1068 | input: InstallWorkspaceAppInput, |
| 1069 | ): Promise<InstallWorkspaceAppResponse> { |
| 1070 | const grantedPermissions = input.grantedPermissions |
| 1071 | ? input.grantedPermissions.map((permission) => |
| 1072 | appPermissionSchema.parse(permission), |
| 1073 | ) |
| 1074 | : undefined; |
| 1075 |
| 1076 | return this.unwrapGeneratedResponse( |
| 1077 | this.appPlatformClient.POST("/api/v1/workspaces/{workspaceSlug}/apps", { |
| 1078 | params: { path: { workspaceSlug } }, |
| 1079 | body: { |
| 1080 | appId: input.appId, |
| 1081 | ...(input.pinnedVersionId |
| 1082 | ? { pinnedVersionId: input.pinnedVersionId } |
| 1083 | : {}), |
| 1084 | ...(grantedPermissions ? { grantedPermissions } : {}), |
| 1085 | }, |
| 1086 | }), |
| 1087 | ); |
| 1088 | } |
| 1089 |
| 1090 | async getWorkspaceAppPermissions( |
| 1091 | workspaceSlug: string, |
| 1092 | appKey: string, |
| 1093 | ): Promise<WorkspaceAppPermissionsResponse> { |
| 1094 | return this.unwrapGeneratedResponse( |
| 1095 | this.appPlatformClient.GET( |
| 1096 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/permissions", |
| 1097 | { |
| 1098 | params: { path: { workspaceSlug, appKey } }, |
| 1099 | }, |
| 1100 | ), |
| 1101 | ); |
| 1102 | } |
| 1103 |
| 1104 | async getWorkspaceInstalledApp( |
| 1105 | workspaceSlug: string, |
| 1106 | appKey: string, |
| 1107 | ): Promise<WorkspaceInstalledAppResponse> { |
| 1108 | return this.unwrapGeneratedResponse( |
| 1109 | this.appPlatformClient.GET("/api/v1/workspaces/{workspaceSlug}/apps/{appKey}", { |
| 1110 | params: { path: { workspaceSlug, appKey } }, |
| 1111 | }), |
| 1112 | ); |
| 1113 | } |
| 1114 |
| 1115 | async updateWorkspaceAppPermissions( |
| 1116 | workspaceSlug: string, |
| 1117 | appKey: string, |
| 1118 | input: UpdateWorkspaceAppPermissionsInput, |
| 1119 | ): Promise<WorkspaceAppPermissionsResponse> { |
| 1120 | return this.unwrapGeneratedResponse( |
| 1121 | this.appPlatformClient.PUT( |
| 1122 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/permissions", |
| 1123 | { |
| 1124 | params: { path: { workspaceSlug, appKey } }, |
| 1125 | body: { |
| 1126 | grantedPermissions: input.grantedPermissions.map((permission) => |
| 1127 | appPermissionSchema.parse(permission), |
| 1128 | ), |
| 1129 | }, |
| 1130 | }, |
| 1131 | ), |
| 1132 | ); |
| 1133 | } |
| 1134 |
| 1135 | async uninstallWorkspaceApp( |
| 1136 | workspaceSlug: string, |
| 1137 | appKey: string, |
| 1138 | ): Promise<{ ok: true }> { |
| 1139 | return this.unwrapGeneratedResponse( |
| 1140 | this.appPlatformClient.DELETE( |
| 1141 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}", |
| 1142 | { |
| 1143 | params: { path: { workspaceSlug, appKey } }, |
| 1144 | }, |
| 1145 | ), |
| 1146 | ); |
| 1147 | } |
| 1148 |
| 1149 | async listWorkspaceAppSecrets( |
| 1150 | workspaceSlug: string, |
| 1151 | appKey: string, |
| 1152 | ): Promise<WorkspaceAppSecretsResponse> { |
| 1153 | return this.unwrapGeneratedResponse( |
| 1154 | this.appPlatformClient.GET( |
| 1155 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/secrets", |
| 1156 | { |
| 1157 | params: { path: { workspaceSlug, appKey } }, |
| 1158 | }, |
| 1159 | ), |
| 1160 | ); |
| 1161 | } |
| 1162 |
| 1163 | async createWorkspaceAppSecret( |
| 1164 | workspaceSlug: string, |
| 1165 | appKey: string, |
| 1166 | input: CreateWorkspaceAppSecretInput, |
| 1167 | ): Promise<CreateWorkspaceAppSecretResponse> { |
| 1168 | return this.unwrapGeneratedResponse( |
| 1169 | this.appPlatformClient.POST( |
| 1170 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/secrets", |
| 1171 | { |
| 1172 | params: { path: { workspaceSlug, appKey } }, |
| 1173 | body: input, |
| 1174 | }, |
| 1175 | ), |
| 1176 | ); |
| 1177 | } |
| 1178 |
| 1179 | async deleteWorkspaceAppSecret( |
| 1180 | workspaceSlug: string, |
| 1181 | appKey: string, |
| 1182 | secretId: string, |
| 1183 | ): Promise<{ ok: true }> { |
| 1184 | return this.unwrapGeneratedResponse( |
| 1185 | this.appPlatformClient.DELETE( |
| 1186 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/secrets/{secretId}", |
| 1187 | { |
| 1188 | params: { path: { workspaceSlug, appKey, secretId } }, |
| 1189 | }, |
| 1190 | ), |
| 1191 | ); |
| 1192 | } |
| 1193 |
| 1194 | async listWorkspaceAppOauthConnections( |
| 1195 | workspaceSlug: string, |
| 1196 | appKey: string, |
| 1197 | ): Promise<WorkspaceAppOauthConnectionsResponse> { |
| 1198 | return this.unwrapGeneratedResponse( |
| 1199 | this.appPlatformClient.GET( |
| 1200 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/oauth-connections", |
| 1201 | { |
| 1202 | params: { path: { workspaceSlug, appKey } }, |
| 1203 | }, |
| 1204 | ), |
| 1205 | ); |
| 1206 | } |
| 1207 |
| 1208 | async createWorkspaceAppOauthConnection( |
| 1209 | workspaceSlug: string, |
| 1210 | appKey: string, |
| 1211 | input: CreateWorkspaceAppOauthConnectionInput, |
| 1212 | ): Promise<CreateWorkspaceAppOauthConnectionResponse> { |
| 1213 | const body: { |
| 1214 | providerKey: string; |
| 1215 | accessToken: string; |
| 1216 | scopes: string[]; |
| 1217 | externalAccountId?: string; |
| 1218 | refreshToken?: string; |
| 1219 | tokenExpiresAt?: string; |
| 1220 | metadata?: Record<string, unknown>; |
| 1221 | } = { |
| 1222 | providerKey: input.providerKey, |
| 1223 | accessToken: input.accessToken, |
| 1224 | scopes: input.scopes, |
| 1225 | }; |
| 1226 |
| 1227 | if (input.externalAccountId) { |
| 1228 | body.externalAccountId = input.externalAccountId; |
| 1229 | } |
| 1230 | if (input.refreshToken) { |
| 1231 | body.refreshToken = input.refreshToken; |
| 1232 | } |
| 1233 | if (input.tokenExpiresAt) { |
| 1234 | body.tokenExpiresAt = input.tokenExpiresAt; |
| 1235 | } |
| 1236 | if (input.metadata) { |
| 1237 | body.metadata = input.metadata; |
| 1238 | } |
| 1239 |
| 1240 | return this.unwrapGeneratedResponse( |
| 1241 | this.appPlatformClient.POST( |
| 1242 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/oauth-connections", |
| 1243 | { |
| 1244 | params: { path: { workspaceSlug, appKey } }, |
| 1245 | body, |
| 1246 | }, |
| 1247 | ), |
| 1248 | ); |
| 1249 | } |
| 1250 |
| 1251 | async deleteWorkspaceAppOauthConnection( |
| 1252 | workspaceSlug: string, |
| 1253 | appKey: string, |
| 1254 | connectionId: string, |
| 1255 | ): Promise<{ ok: true }> { |
| 1256 | return this.unwrapGeneratedResponse( |
| 1257 | this.appPlatformClient.DELETE( |
| 1258 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/oauth-connections/{connectionId}", |
| 1259 | { |
| 1260 | params: { path: { workspaceSlug, appKey, connectionId } }, |
| 1261 | }, |
| 1262 | ), |
| 1263 | ); |
| 1264 | } |
| 1265 |
| 1266 | async listWorkspaceAppDeliveries( |
| 1267 | workspaceSlug: string, |
| 1268 | appKey: string, |
| 1269 | ): Promise<WorkspaceAppDeliveriesResponse> { |
| 1270 | return this.unwrapGeneratedResponse( |
| 1271 | this.appPlatformClient.GET( |
| 1272 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/deliveries", |
| 1273 | { |
| 1274 | params: { path: { workspaceSlug, appKey } }, |
| 1275 | }, |
| 1276 | ), |
| 1277 | ); |
| 1278 | } |
| 1279 |
| 1280 | async sendWorkspaceAppTestDelivery( |
| 1281 | workspaceSlug: string, |
| 1282 | appKey: string, |
| 1283 | input: SendWorkspaceAppTestDeliveryInput, |
| 1284 | ): Promise<SendWorkspaceAppTestDeliveryResponse> { |
| 1285 | return this.unwrapGeneratedResponse( |
| 1286 | this.appPlatformClient.POST( |
| 1287 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/deliveries", |
| 1288 | { |
| 1289 | params: { path: { workspaceSlug, appKey } }, |
| 1290 | body: input, |
| 1291 | }, |
| 1292 | ), |
| 1293 | ); |
| 1294 | } |
| 1295 |
| 1296 | async replayWorkspaceAppDelivery( |
| 1297 | workspaceSlug: string, |
| 1298 | appKey: string, |
| 1299 | deliveryId: string, |
| 1300 | ): Promise<SendWorkspaceAppTestDeliveryResponse> { |
| 1301 | return this.unwrapGeneratedResponse( |
| 1302 | this.appPlatformClient.POST( |
| 1303 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/deliveries/{deliveryId}/replay", |
| 1304 | { |
| 1305 | params: { path: { workspaceSlug, appKey, deliveryId } }, |
| 1306 | }, |
| 1307 | ), |
| 1308 | ); |
| 1309 | } |
| 1310 |
| 1311 | async emitAppAmbientEvents( |
| 1312 | workspaceSlug: string, |
| 1313 | appKey: string, |
| 1314 | input: EmitAmbientEventsInputInput, |
| 1315 | ): Promise<EmitAppAmbientEventsResponse> { |
| 1316 | const parsed = emitAmbientEventsInputSchema.parse(input); |
| 1317 | const body = { |
| 1318 | events: parsed.events.map((event) => ({ |
| 1319 | sourceKind: event.sourceKind, |
| 1320 | action: event.action, |
| 1321 | entityType: event.entityType, |
| 1322 | entityId: event.entityId, |
| 1323 | dedupeKey: event.dedupeKey, |
| 1324 | payload: event.payload, |
| 1325 | metadata: event.metadata, |
| 1326 | schemaVersion: event.schemaVersion, |
| 1327 | ...(event.actorUserId ? { actorUserId: event.actorUserId } : {}), |
| 1328 | ...(event.containerType ? { containerType: event.containerType } : {}), |
| 1329 | ...(event.containerId ? { containerId: event.containerId } : {}), |
| 1330 | ...(event.occurredAt |
| 1331 | ? { occurredAt: event.occurredAt.toISOString() } |
| 1332 | : {}), |
| 1333 | })), |
| 1334 | }; |
| 1335 |
| 1336 | return this.unwrapGeneratedResponse( |
| 1337 | this.appPlatformClient.POST( |
| 1338 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/ambient/events", |
| 1339 | { |
| 1340 | params: { path: { workspaceSlug, appKey } }, |
| 1341 | body, |
| 1342 | }, |
| 1343 | ), |
| 1344 | ); |
| 1345 | } |
| 1346 |
| 1347 | async createAppNotification( |
| 1348 | workspaceSlug: string, |
| 1349 | appKey: string, |
| 1350 | input: CreateNotificationInputInput, |
| 1351 | ): Promise<OkResponse> { |
| 1352 | const parsed = createNotificationInputSchema.parse(input); |
| 1353 | const body = { |
| 1354 | channelKey: parsed.channelKey, |
| 1355 | typeKey: parsed.typeKey, |
| 1356 | recipients: parsed.recipients.map((recipient) => ({ |
| 1357 | userId: recipient.userId, |
| 1358 | })), |
| 1359 | title: parsed.title, |
| 1360 | priority: parsed.priority, |
| 1361 | metadata: parsed.metadata, |
| 1362 | ...(parsed.body ? { body: parsed.body } : {}), |
| 1363 | ...(parsed.targetUrl ? { targetUrl: parsed.targetUrl } : {}), |
| 1364 | ...(parsed.icon ? { icon: parsed.icon } : {}), |
| 1365 | ...(parsed.dedupeKey ? { dedupeKey: parsed.dedupeKey } : {}), |
| 1366 | }; |
| 1367 |
| 1368 | return this.unwrapGeneratedResponse( |
| 1369 | this.appPlatformClient.POST( |
| 1370 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/notifications", |
| 1371 | { |
| 1372 | params: { path: { workspaceSlug, appKey } }, |
| 1373 | body, |
| 1374 | }, |
| 1375 | ), |
| 1376 | ); |
| 1377 | } |
| 1378 |
| 1379 | async upsertAppIndexDocuments( |
| 1380 | workspaceSlug: string, |
| 1381 | appKey: string, |
| 1382 | input: BatchUpsertAppIndexDocumentsInput, |
| 1383 | ): Promise<UpsertAppIndexDocumentsResponse> { |
| 1384 | const parsed = batchUpsertAppIndexDocumentsSchema.parse(input); |
| 1385 | const body = { |
| 1386 | documents: parsed.documents.map((document) => ({ |
| 1387 | documentKey: document.documentKey, |
| 1388 | documentType: document.documentType, |
| 1389 | title: document.title, |
| 1390 | body: document.body, |
| 1391 | metadata: document.metadata, |
| 1392 | visibilityMode: document.visibilityMode, |
| 1393 | visibility: document.visibility.map((grant) => ({ |
| 1394 | subjectType: grant.subjectType, |
| 1395 | subjectId: grant.subjectId, |
| 1396 | })), |
| 1397 | ...(document.fileId ? { fileId: document.fileId } : {}), |
| 1398 | ...(document.url ? { url: document.url } : {}), |
| 1399 | })), |
| 1400 | }; |
| 1401 |
| 1402 | return this.unwrapGeneratedResponse( |
| 1403 | this.appPlatformClient.POST( |
| 1404 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/index-documents", |
| 1405 | { |
| 1406 | params: { path: { workspaceSlug, appKey } }, |
| 1407 | body, |
| 1408 | }, |
| 1409 | ), |
| 1410 | ); |
| 1411 | } |
| 1412 |
| 1413 | async deleteAppIndexDocuments( |
| 1414 | workspaceSlug: string, |
| 1415 | appKey: string, |
| 1416 | input: BatchDeleteAppIndexDocumentsInput, |
| 1417 | ): Promise<DeleteAppIndexDocumentsResponse> { |
| 1418 | const body = batchDeleteAppIndexDocumentsSchema.parse(input); |
| 1419 |
| 1420 | return this.unwrapGeneratedResponse( |
| 1421 | this.appPlatformClient.DELETE( |
| 1422 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/index-documents", |
| 1423 | { |
| 1424 | params: { path: { workspaceSlug, appKey } }, |
| 1425 | body, |
| 1426 | }, |
| 1427 | ), |
| 1428 | ); |
| 1429 | } |
| 1430 |
| 1431 | async listAppFiles( |
| 1432 | workspaceSlug: string, |
| 1433 | appKey: string, |
| 1434 | query?: ListAppFilesQuery, |
| 1435 | ): Promise<AppFilesListResponse> { |
| 1436 | return this.unwrapGeneratedResponse( |
| 1437 | this.appPlatformClient.GET( |
| 1438 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files", |
| 1439 | { |
| 1440 | params: { |
| 1441 | path: { workspaceSlug, appKey }, |
| 1442 | ...(query |
| 1443 | ? { |
| 1444 | query: { |
| 1445 | ...(query.driveId ? { driveId: query.driveId } : {}), |
| 1446 | ...(query.typeKey ? { typeKey: query.typeKey } : {}), |
| 1447 | ...(query.limit !== undefined ? { limit: query.limit } : {}), |
| 1448 | }, |
| 1449 | } |
| 1450 | : {}), |
| 1451 | }, |
| 1452 | }, |
| 1453 | ), |
| 1454 | ); |
| 1455 | } |
| 1456 |
| 1457 | async createAppFile( |
| 1458 | workspaceSlug: string, |
| 1459 | appKey: string, |
| 1460 | input: CreateAppFileInput, |
| 1461 | ): Promise<CreateAppFileResponse> { |
| 1462 | return this.unwrapGeneratedResponse( |
| 1463 | this.appPlatformClient.POST( |
| 1464 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files", |
| 1465 | { |
| 1466 | params: { path: { workspaceSlug, appKey } }, |
| 1467 | body: { |
| 1468 | name: input.name, |
| 1469 | ...(input.typeKey ? { typeKey: input.typeKey } : {}), |
| 1470 | ...(input.driveId ? { driveId: input.driveId } : {}), |
| 1471 | ...(input.parentId !== undefined ? { parentId: input.parentId } : {}), |
| 1472 | ...(input.document ? { document: input.document } : {}), |
| 1473 | }, |
| 1474 | }, |
| 1475 | ), |
| 1476 | ); |
| 1477 | } |
| 1478 |
| 1479 | async executeAppAction( |
| 1480 | workspaceSlug: string, |
| 1481 | appKey: string, |
| 1482 | input: ExecuteAppActionInput, |
| 1483 | ): Promise<ExecuteAppActionResponse> { |
| 1484 | return this.unwrapGeneratedResponse( |
| 1485 | this.appPlatformClient.POST( |
| 1486 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/actions", |
| 1487 | { |
| 1488 | params: { path: { workspaceSlug, appKey } }, |
| 1489 | body: { |
| 1490 | action: { |
| 1491 | type: input.action.type, |
| 1492 | ...(input.action.payload ? { payload: input.action.payload } : {}), |
| 1493 | }, |
| 1494 | ...(input.fileId !== undefined ? { fileId: input.fileId } : {}), |
| 1495 | }, |
| 1496 | }, |
| 1497 | ), |
| 1498 | ); |
| 1499 | } |
| 1500 |
| 1501 | async getAppFileDocument( |
| 1502 | workspaceSlug: string, |
| 1503 | appKey: string, |
| 1504 | fileId: string, |
| 1505 | ): Promise<AppFileDocumentResponse> { |
| 1506 | return this.unwrapGeneratedResponse( |
| 1507 | this.appPlatformClient.GET( |
| 1508 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files/{fileId}", |
| 1509 | { |
| 1510 | params: { path: { workspaceSlug, appKey, fileId } }, |
| 1511 | }, |
| 1512 | ), |
| 1513 | ); |
| 1514 | } |
| 1515 |
| 1516 | async updateAppFileDocument( |
| 1517 | workspaceSlug: string, |
| 1518 | appKey: string, |
| 1519 | fileId: string, |
| 1520 | document: Record<string, unknown>, |
| 1521 | ): Promise<AppFileDocumentUpdateResponse> { |
| 1522 | return this.unwrapGeneratedResponse( |
| 1523 | this.appPlatformClient.PATCH( |
| 1524 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files/{fileId}", |
| 1525 | { |
| 1526 | params: { path: { workspaceSlug, appKey, fileId } }, |
| 1527 | body: { document }, |
| 1528 | }, |
| 1529 | ), |
| 1530 | ); |
| 1531 | } |
| 1532 |
| 1533 | async deleteAppFile( |
| 1534 | workspaceSlug: string, |
| 1535 | appKey: string, |
| 1536 | fileId: string, |
| 1537 | ): Promise<OkResponse> { |
| 1538 | return this.unwrapGeneratedResponse( |
| 1539 | this.appPlatformClient.DELETE( |
| 1540 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files/{fileId}", |
| 1541 | { |
| 1542 | params: { path: { workspaceSlug, appKey, fileId } }, |
| 1543 | }, |
| 1544 | ), |
| 1545 | ); |
| 1546 | } |
| 1547 |
| 1548 | async listTabModels(): Promise<TabModelsResponse> { |
| 1549 | return this.unwrapGeneratedResponse( |
| 1550 | this.appPlatformClient.GET("/api/v1/tab/models"), |
| 1551 | ); |
| 1552 | } |
| 1553 |
| 1554 | async createTabChatCompletion(input: { |
| 1555 | model: string; |
| 1556 | stream?: boolean; |
| 1557 | tab_context: Record<string, unknown>; |
| 1558 | messages?: Array<{ role?: string; content?: string }>; |
| 1559 | }): Promise<TabChatCompletionResponse> { |
| 1560 | return this.unwrapGeneratedResponse( |
| 1561 | this.appPlatformClient.POST("/api/v1/tab/chat/completions", { |
| 1562 | body: input, |
| 1563 | }), |
| 1564 | ); |
| 1565 | } |
| 1566 |
| 1567 | async exchangeOAuthCode(input: { |
| 1568 | clientId: string; |
| 1569 | clientSecret: string; |
| 1570 | code: string; |
| 1571 | redirectUri: string; |
| 1572 | codeVerifier?: string; |
| 1573 | }): Promise<OAuthTokenResponse> { |
| 1574 | const response = await this.fetchImpl(joinUrl(this.baseUrl, "/api/v1/oauth/token"), { |
| 1575 | method: "POST", |
| 1576 | headers: { |
| 1577 | "Content-Type": "application/json", |
| 1578 | }, |
| 1579 | body: JSON.stringify({ |
| 1580 | grant_type: "authorization_code", |
| 1581 | client_id: input.clientId, |
| 1582 | client_secret: input.clientSecret, |
| 1583 | code: input.code, |
| 1584 | redirect_uri: input.redirectUri, |
| 1585 | ...(input.codeVerifier ? { code_verifier: input.codeVerifier } : {}), |
| 1586 | }), |
| 1587 | }); |
| 1588 |
| 1589 | return parseJsonResponse<OAuthTokenResponse>(response); |
| 1590 | } |
| 1591 |
| 1592 | async getOAuthUserInfo(accessToken: string): Promise<OAuthUserInfoResponse> { |
| 1593 | const response = await this.fetchImpl(joinUrl(this.baseUrl, "/api/v1/oauth/userinfo"), { |
| 1594 | method: "GET", |
| 1595 | headers: { |
| 1596 | Authorization: `Bearer ${accessToken}`, |
| 1597 | }, |
| 1598 | }); |
| 1599 |
| 1600 | return parseJsonResponse<OAuthUserInfoResponse>(response); |
| 1601 | } |
| 1602 |
| 1603 | // --------------------------------------------------------------------------- |
| 1604 | // Core Platform API — internal fetch helper |
| 1605 | // --------------------------------------------------------------------------- |
| 1606 |
| 1607 | private async coreRequest<T>( |
| 1608 | method: string, |
| 1609 | path: string, |
| 1610 | body?: unknown, |
| 1611 | ): Promise<T> { |
| 1612 | const url = joinUrl(this.baseUrl, path); |
| 1613 | const headers: Record<string, string> = {}; |
| 1614 | if (this.apiKey) { |
| 1615 | headers["Authorization"] = `Bearer ${this.apiKey}`; |
| 1616 | } |
| 1617 | if (body !== undefined) { |
| 1618 | headers["Content-Type"] = "application/json"; |
| 1619 | } |
| 1620 | if (this.defaultHeaders) { |
| 1621 | new Headers(this.defaultHeaders).forEach((v, k) => { |
| 1622 | headers[k] = v; |
| 1623 | }); |
| 1624 | } |
| 1625 |
| 1626 | const requestInit: RequestInit = { |
| 1627 | method, |
| 1628 | headers, |
| 1629 | ...(body !== undefined ? { body: JSON.stringify(body) } : {}), |
| 1630 | }; |
| 1631 |
| 1632 | if (this.debug) { |
| 1633 | console.debug(`[coline-sdk] ${method} ${path}`, body !== undefined ? { body } : ""); |
| 1634 | } |
| 1635 |
| 1636 | let lastError: ColineApiError | undefined; |
| 1637 |
| 1638 | for (let attempt = 0; attempt <= this.maxRetries; attempt++) { |
| 1639 | if (attempt > 0) { |
| 1640 | // Exponential backoff: 500ms, 1s, 2s, 4s ... |
| 1641 | const delayMs = Math.min(500 * Math.pow(2, attempt - 1), 30_000); |
| 1642 | if (this.debug) { |
| 1643 | console.debug(`[coline-sdk] retry ${attempt}/${this.maxRetries} after ${delayMs}ms`); |
| 1644 | } |
| 1645 | await sleep(delayMs); |
| 1646 | } |
| 1647 |
| 1648 | const response = await this.fetchImpl(url, requestInit); |
| 1649 |
| 1650 | if (!response.ok) { |
| 1651 | const payload = (await response.json().catch(() => null)) as ApiErrorPayload | null; |
| 1652 | const error = new ColineApiError({ |
| 1653 | message: |
| 1654 | payload?.error?.message ?? `Request failed (${response.status}).`, |
| 1655 | type: "api", |
| 1656 | status: response.status, |
| 1657 | code: payload?.error?.code ?? null, |
| 1658 | }); |
| 1659 |
| 1660 | // Retry on 429 (rate limit) and 5xx (server errors) |
| 1661 | if (isRetryableStatus(response.status) && attempt < this.maxRetries) { |
| 1662 | lastError = error; |
| 1663 | continue; |
| 1664 | } |
| 1665 |
| 1666 | if (this.debug) { |
| 1667 | console.debug(`[coline-sdk] ${method} ${path} → ${response.status}`, payload); |
| 1668 | } |
| 1669 |
| 1670 | throw error; |
| 1671 | } |
| 1672 |
| 1673 | const json = (await response.json().catch(() => null)) as { |
| 1674 | data: T; |
| 1675 | } | null; |
| 1676 |
| 1677 | if (!json || !("data" in json)) { |
| 1678 | throw new ColineApiError({ |
| 1679 | message: "Invalid API response.", |
| 1680 | type: "api", |
| 1681 | status: response.status, |
| 1682 | }); |
| 1683 | } |
| 1684 |
| 1685 | if (this.debug) { |
| 1686 | console.debug(`[coline-sdk] ${method} ${path} → ${response.status} OK`); |
| 1687 | } |
| 1688 |
| 1689 | return json.data; |
| 1690 | } |
| 1691 |
| 1692 | // Should not reach here, but safety net |
| 1693 | throw lastError ?? new ColineApiError({ |
| 1694 | message: "Max retries exceeded.", |
| 1695 | type: "api", |
| 1696 | status: 0, |
| 1697 | }); |
| 1698 | } |
| 1699 |
| 1700 | // --------------------------------------------------------------------------- |
| 1701 | // Core Platform API — Workspace Members |
| 1702 | // --------------------------------------------------------------------------- |
| 1703 |
| 1704 | async listWorkspaceMembers( |
| 1705 | workspaceId: string, |
| 1706 | ): Promise<WorkspaceMembersResponse> { |
| 1707 | return this.coreRequest<WorkspaceMembersResponse>( |
| 1708 | "GET", |
| 1709 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/members`, |
| 1710 | ); |
| 1711 | } |
| 1712 |
| 1713 | // --------------------------------------------------------------------------- |
| 1714 | // Core Platform API — Notes |
| 1715 | // --------------------------------------------------------------------------- |
| 1716 |
| 1717 | async listWorkspaceNotes( |
| 1718 | workspaceId: string, |
| 1719 | query?: ListWorkspaceNotesQuery, |
| 1720 | ): Promise<WorkspaceNotesListResponse> { |
| 1721 | const params = new URLSearchParams(); |
| 1722 | if (query?.q) params.set("q", query.q); |
| 1723 | if (query?.limit !== undefined) params.set("limit", String(query.limit)); |
| 1724 | if (query?.cursor) params.set("cursor", query.cursor); |
| 1725 | const qs = params.toString(); |
| 1726 | return this.coreRequest<WorkspaceNotesListResponse>( |
| 1727 | "GET", |
| 1728 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes${qs ? `?${qs}` : ""}`, |
| 1729 | ); |
| 1730 | } |
| 1731 |
| 1732 | async createWorkspaceNote( |
| 1733 | workspaceId: string, |
| 1734 | input: CreateWorkspaceNoteInput, |
| 1735 | ): Promise<WorkspaceNoteResponse> { |
| 1736 | return this.coreRequest<WorkspaceNoteResponse>( |
| 1737 | "POST", |
| 1738 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes`, |
| 1739 | { |
| 1740 | ...(input.title !== undefined ? { title: input.title } : {}), |
| 1741 | ...(input.body !== undefined ? { body: input.body } : {}), |
| 1742 | ...(input.blocks !== undefined ? { blocks: input.blocks } : {}), |
| 1743 | ...(input.driveId !== undefined ? { driveId: input.driveId } : {}), |
| 1744 | ...(input.parentId !== undefined ? { parentId: input.parentId } : {}), |
| 1745 | }, |
| 1746 | ); |
| 1747 | } |
| 1748 |
| 1749 | async getWorkspaceNote( |
| 1750 | workspaceId: string, |
| 1751 | noteId: string, |
| 1752 | ): Promise<WorkspaceNoteDetailResponse> { |
| 1753 | return this.coreRequest<WorkspaceNoteDetailResponse>( |
| 1754 | "GET", |
| 1755 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes/${encodeURIComponent(noteId)}`, |
| 1756 | ); |
| 1757 | } |
| 1758 |
| 1759 | async updateWorkspaceNote( |
| 1760 | workspaceId: string, |
| 1761 | noteId: string, |
| 1762 | input: UpdateWorkspaceNoteInput, |
| 1763 | ): Promise<WorkspaceNoteResponse> { |
| 1764 | return this.coreRequest<WorkspaceNoteResponse>( |
| 1765 | "PUT", |
| 1766 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes/${encodeURIComponent(noteId)}`, |
| 1767 | input, |
| 1768 | ); |
| 1769 | } |
| 1770 |
| 1771 | async deleteWorkspaceNote( |
| 1772 | workspaceId: string, |
| 1773 | noteId: string, |
| 1774 | ): Promise<{ ok: true }> { |
| 1775 | return this.coreRequest<{ ok: true }>( |
| 1776 | "DELETE", |
| 1777 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes/${encodeURIComponent(noteId)}`, |
| 1778 | ); |
| 1779 | } |
| 1780 |
| 1781 | // --------------------------------------------------------------------------- |
| 1782 | // Core Platform API — Docs |
| 1783 | // --------------------------------------------------------------------------- |
| 1784 |
| 1785 | async listWorkspaceDocs( |
| 1786 | workspaceId: string, |
| 1787 | query?: ListWorkspaceDocsQuery, |
| 1788 | ): Promise<WorkspaceDocsListResponse> { |
| 1789 | const params = new URLSearchParams(); |
| 1790 | if (query?.q) params.set("q", query.q); |
| 1791 | if (query?.limit !== undefined) params.set("limit", String(query.limit)); |
| 1792 | if (query?.cursor) params.set("cursor", query.cursor); |
| 1793 | const qs = params.toString(); |
| 1794 | return this.coreRequest<WorkspaceDocsListResponse>( |
| 1795 | "GET", |
| 1796 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs${qs ? `?${qs}` : ""}`, |
| 1797 | ); |
| 1798 | } |
| 1799 |
| 1800 | async createWorkspaceDoc( |
| 1801 | workspaceId: string, |
| 1802 | input: CreateWorkspaceDocInput, |
| 1803 | ): Promise<WorkspaceDocResponse> { |
| 1804 | return this.coreRequest<WorkspaceDocResponse>( |
| 1805 | "POST", |
| 1806 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs`, |
| 1807 | { |
| 1808 | ...(input.title !== undefined ? { title: input.title } : {}), |
| 1809 | ...(input.content !== undefined ? { content: input.content } : {}), |
| 1810 | ...(input.layout !== undefined ? { layout: input.layout } : {}), |
| 1811 | ...(input.driveId !== undefined ? { driveId: input.driveId } : {}), |
| 1812 | ...(input.parentId !== undefined ? { parentId: input.parentId } : {}), |
| 1813 | }, |
| 1814 | ); |
| 1815 | } |
| 1816 |
| 1817 | async getWorkspaceDoc( |
| 1818 | workspaceId: string, |
| 1819 | docId: string, |
| 1820 | ): Promise<WorkspaceDocDetailResponse> { |
| 1821 | return this.coreRequest<WorkspaceDocDetailResponse>( |
| 1822 | "GET", |
| 1823 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs/${encodeURIComponent(docId)}`, |
| 1824 | ); |
| 1825 | } |
| 1826 |
| 1827 | async updateWorkspaceDoc( |
| 1828 | workspaceId: string, |
| 1829 | docId: string, |
| 1830 | input: UpdateWorkspaceDocInput, |
| 1831 | ): Promise<WorkspaceDocDetailResponse> { |
| 1832 | return this.coreRequest<WorkspaceDocDetailResponse>( |
| 1833 | "PATCH", |
| 1834 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs/${encodeURIComponent(docId)}`, |
| 1835 | input, |
| 1836 | ); |
| 1837 | } |
| 1838 |
| 1839 | async deleteWorkspaceDoc( |
| 1840 | workspaceId: string, |
| 1841 | docId: string, |
| 1842 | ): Promise<{ ok: true }> { |
| 1843 | return this.coreRequest<{ ok: true }>( |
| 1844 | "DELETE", |
| 1845 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs/${encodeURIComponent(docId)}`, |
| 1846 | ); |
| 1847 | } |
| 1848 |
| 1849 | // --------------------------------------------------------------------------- |
| 1850 | // Core Platform API — Drives |
| 1851 | // --------------------------------------------------------------------------- |
| 1852 |
| 1853 | async listWorkspaceDrives( |
| 1854 | workspaceId: string, |
| 1855 | ): Promise<WorkspaceDrivesListResponse> { |
| 1856 | return this.coreRequest<WorkspaceDrivesListResponse>( |
| 1857 | "GET", |
| 1858 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/drives`, |
| 1859 | ); |
| 1860 | } |
| 1861 |
| 1862 | // --------------------------------------------------------------------------- |
| 1863 | // Core Platform API — Files |
| 1864 | // --------------------------------------------------------------------------- |
| 1865 |
| 1866 | async listDriveFiles( |
| 1867 | workspaceId: string, |
| 1868 | driveId: string, |
| 1869 | query?: ListDriveFilesQuery, |
| 1870 | ): Promise<DriveFilesListResponse> { |
| 1871 | const params = new URLSearchParams(); |
| 1872 | if (query?.parentId) params.set("parentId", query.parentId); |
| 1873 | if (query?.fileType) params.set("fileType", query.fileType); |
| 1874 | if (query?.trashed !== undefined) params.set("trashed", String(query.trashed)); |
| 1875 | if (query?.limit !== undefined) params.set("limit", String(query.limit)); |
| 1876 | if (query?.cursor) params.set("cursor", query.cursor); |
| 1877 | const qs = params.toString(); |
| 1878 | return this.coreRequest<DriveFilesListResponse>( |
| 1879 | "GET", |
| 1880 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/drives/${encodeURIComponent(driveId)}/files${qs ? `?${qs}` : ""}`, |
| 1881 | ); |
| 1882 | } |
| 1883 |
| 1884 | async getFile( |
| 1885 | workspaceId: string, |
| 1886 | fileId: string, |
| 1887 | ): Promise<FileDetailResponse> { |
| 1888 | return this.coreRequest<FileDetailResponse>( |
| 1889 | "GET", |
| 1890 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/files/${encodeURIComponent(fileId)}`, |
| 1891 | ); |
| 1892 | } |
| 1893 |
| 1894 | async updateFile( |
| 1895 | workspaceId: string, |
| 1896 | fileId: string, |
| 1897 | input: UpdateFileInput, |
| 1898 | ): Promise<FileDetailResponse> { |
| 1899 | return this.coreRequest<FileDetailResponse>( |
| 1900 | "PATCH", |
| 1901 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/files/${encodeURIComponent(fileId)}`, |
| 1902 | input, |
| 1903 | ); |
| 1904 | } |
| 1905 |
| 1906 | async deleteFile( |
| 1907 | workspaceId: string, |
| 1908 | fileId: string, |
| 1909 | ): Promise<{ ok: true }> { |
| 1910 | return this.coreRequest<{ ok: true }>( |
| 1911 | "DELETE", |
| 1912 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/files/${encodeURIComponent(fileId)}`, |
| 1913 | ); |
| 1914 | } |
| 1915 |
| 1916 | // --------------------------------------------------------------------------- |
| 1917 | // Core Platform API — Channels |
| 1918 | // --------------------------------------------------------------------------- |
| 1919 |
| 1920 | async listWorkspaceChannels( |
| 1921 | workspaceId: string, |
| 1922 | ): Promise<ChannelListResponse> { |
| 1923 | return this.coreRequest<ChannelListResponse>( |
| 1924 | "GET", |
| 1925 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/channels`, |
| 1926 | ); |
| 1927 | } |
| 1928 |
| 1929 | async listChannelMessages( |
| 1930 | workspaceId: string, |
| 1931 | channelId: string, |
| 1932 | options?: { limit?: number; cursor?: string }, |
| 1933 | ): Promise<MessagesListResponse> { |
| 1934 | const params = new URLSearchParams(); |
| 1935 | if (options?.limit !== undefined) params.set("limit", String(options.limit)); |
| 1936 | if (options?.cursor) params.set("cursor", options.cursor); |
| 1937 | const qs = params.toString(); |
| 1938 | return this.coreRequest<MessagesListResponse>( |
| 1939 | "GET", |
| 1940 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/channels/${encodeURIComponent(channelId)}/messages${qs ? `?${qs}` : ""}`, |
| 1941 | ); |
| 1942 | } |
| 1943 |
| 1944 | // --------------------------------------------------------------------------- |
| 1945 | // Core Platform API — Direct Messages |
| 1946 | // --------------------------------------------------------------------------- |
| 1947 |
| 1948 | async listWorkspaceDms( |
| 1949 | workspaceId: string, |
| 1950 | ): Promise<DmListResponse> { |
| 1951 | return this.coreRequest<DmListResponse>( |
| 1952 | "GET", |
| 1953 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/dms`, |
| 1954 | ); |
| 1955 | } |
| 1956 |
| 1957 | async listDmMessages( |
| 1958 | workspaceId: string, |
| 1959 | dmId: string, |
| 1960 | options?: { limit?: number; cursor?: string }, |
| 1961 | ): Promise<MessagesListResponse> { |
| 1962 | const params = new URLSearchParams(); |
| 1963 | if (options?.limit !== undefined) params.set("limit", String(options.limit)); |
| 1964 | if (options?.cursor) params.set("cursor", options.cursor); |
| 1965 | const qs = params.toString(); |
| 1966 | return this.coreRequest<MessagesListResponse>( |
| 1967 | "GET", |
| 1968 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/dms/${encodeURIComponent(dmId)}/messages${qs ? `?${qs}` : ""}`, |
| 1969 | ); |
| 1970 | } |
| 1971 |
| 1972 | async sendDmMessage( |
| 1973 | workspaceId: string, |
| 1974 | dmId: string, |
| 1975 | input: SendMessageInput, |
| 1976 | ): Promise<SendMessageResponse> { |
| 1977 | return this.coreRequest<SendMessageResponse>( |
| 1978 | "POST", |
| 1979 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/dms/${encodeURIComponent(dmId)}/messages`, |
| 1980 | input, |
| 1981 | ); |
| 1982 | } |
| 1983 |
| 1984 | async sendChannelMessage( |
| 1985 | workspaceId: string, |
| 1986 | channelId: string, |
| 1987 | input: SendMessageInput, |
| 1988 | ): Promise<SendMessageResponse> { |
| 1989 | return this.coreRequest<SendMessageResponse>( |
| 1990 | "POST", |
| 1991 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/channels/${encodeURIComponent(channelId)}/messages`, |
| 1992 | input, |
| 1993 | ); |
| 1994 | } |
| 1995 |
| 1996 | // --------------------------------------------------------------------------- |
| 1997 | // Core Platform API — Messages (cross-container) |
| 1998 | // --------------------------------------------------------------------------- |
| 1999 |
| 2000 | async getMessage( |
| 2001 | workspaceId: string, |
| 2002 | messageId: string, |
| 2003 | ): Promise<MessageDetailResponse> { |
| 2004 | return this.coreRequest<MessageDetailResponse>( |
| 2005 | "GET", |
| 2006 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}`, |
| 2007 | ); |
| 2008 | } |
| 2009 |
| 2010 | async editMessage( |
| 2011 | workspaceId: string, |
| 2012 | messageId: string, |
| 2013 | input: EditMessageInput, |
| 2014 | ): Promise<MessageDetailResponse> { |
| 2015 | return this.coreRequest<MessageDetailResponse>( |
| 2016 | "PATCH", |
| 2017 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}`, |
| 2018 | input, |
| 2019 | ); |
| 2020 | } |
| 2021 |
| 2022 | async deleteMessage( |
| 2023 | workspaceId: string, |
| 2024 | messageId: string, |
| 2025 | ): Promise<{ ok: true }> { |
| 2026 | return this.coreRequest<{ ok: true }>( |
| 2027 | "DELETE", |
| 2028 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}`, |
| 2029 | ); |
| 2030 | } |
| 2031 |
| 2032 | async getThread( |
| 2033 | workspaceId: string, |
| 2034 | messageId: string, |
| 2035 | ): Promise<ThreadResponse> { |
| 2036 | return this.coreRequest<ThreadResponse>( |
| 2037 | "GET", |
| 2038 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}/thread`, |
| 2039 | ); |
| 2040 | } |
| 2041 |
| 2042 | async replyToThread( |
| 2043 | workspaceId: string, |
| 2044 | messageId: string, |
| 2045 | input: ThreadReplyInput, |
| 2046 | ): Promise<SendMessageResponse> { |
| 2047 | return this.coreRequest<SendMessageResponse>( |
| 2048 | "POST", |
| 2049 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}/thread`, |
| 2050 | input, |
| 2051 | ); |
| 2052 | } |
| 2053 |
| 2054 | async addReaction( |
| 2055 | workspaceId: string, |
| 2056 | messageId: string, |
| 2057 | emoji: string, |
| 2058 | ): Promise<ReactionResponse> { |
| 2059 | return this.coreRequest<ReactionResponse>( |
| 2060 | "PUT", |
| 2061 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}/reactions/${encodeURIComponent(emoji)}`, |
| 2062 | ); |
| 2063 | } |
| 2064 |
| 2065 | async removeReaction( |
| 2066 | workspaceId: string, |
| 2067 | messageId: string, |
| 2068 | emoji: string, |
| 2069 | ): Promise<{ ok: true }> { |
| 2070 | return this.coreRequest<{ ok: true }>( |
| 2071 | "DELETE", |
| 2072 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}/reactions/${encodeURIComponent(emoji)}`, |
| 2073 | ); |
| 2074 | } |
| 2075 |
| 2076 | async pinMessage( |
| 2077 | workspaceId: string, |
| 2078 | messageId: string, |
| 2079 | ): Promise<PinResponse> { |
| 2080 | return this.coreRequest<PinResponse>( |
| 2081 | "PUT", |
| 2082 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}/pin`, |
| 2083 | ); |
| 2084 | } |
| 2085 |
| 2086 | async unpinMessage( |
| 2087 | workspaceId: string, |
| 2088 | messageId: string, |
| 2089 | ): Promise<PinResponse> { |
| 2090 | return this.coreRequest<PinResponse>( |
| 2091 | "DELETE", |
| 2092 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/messages/${encodeURIComponent(messageId)}/pin`, |
| 2093 | ); |
| 2094 | } |
| 2095 |
| 2096 | // --------------------------------------------------------------------------- |
| 2097 | // Core Platform API — Calendar Events |
| 2098 | // --------------------------------------------------------------------------- |
| 2099 |
| 2100 | async listCalendarEvents( |
| 2101 | workspaceId: string, |
| 2102 | range: { start: string; end: string }, |
| 2103 | ): Promise<CalendarEventsListResponse> { |
| 2104 | const params = new URLSearchParams({ |
| 2105 | start: range.start, |
| 2106 | end: range.end, |
| 2107 | }); |
| 2108 | return this.coreRequest<CalendarEventsListResponse>( |
| 2109 | "GET", |
| 2110 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events?${params}`, |
| 2111 | ); |
| 2112 | } |
| 2113 |
| 2114 | async createCalendarEvent( |
| 2115 | workspaceId: string, |
| 2116 | input: CreateCalendarEventInput, |
| 2117 | ): Promise<CalendarEventDetailResponse> { |
| 2118 | return this.coreRequest<CalendarEventDetailResponse>( |
| 2119 | "POST", |
| 2120 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events`, |
| 2121 | input, |
| 2122 | ); |
| 2123 | } |
| 2124 |
| 2125 | async getCalendarEvent( |
| 2126 | workspaceId: string, |
| 2127 | eventId: string, |
| 2128 | ): Promise<CalendarEventDetailResponse> { |
| 2129 | return this.coreRequest<CalendarEventDetailResponse>( |
| 2130 | "GET", |
| 2131 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events/${encodeURIComponent(eventId)}`, |
| 2132 | ); |
| 2133 | } |
| 2134 |
| 2135 | async updateCalendarEvent( |
| 2136 | workspaceId: string, |
| 2137 | eventId: string, |
| 2138 | input: UpdateCalendarEventInput, |
| 2139 | ): Promise<CalendarEventDetailResponse> { |
| 2140 | return this.coreRequest<CalendarEventDetailResponse>( |
| 2141 | "PATCH", |
| 2142 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events/${encodeURIComponent(eventId)}`, |
| 2143 | input, |
| 2144 | ); |
| 2145 | } |
| 2146 |
| 2147 | async deleteCalendarEvent( |
| 2148 | workspaceId: string, |
| 2149 | eventId: string, |
| 2150 | ): Promise<{ ok: true }> { |
| 2151 | return this.coreRequest<{ ok: true }>( |
| 2152 | "DELETE", |
| 2153 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events/${encodeURIComponent(eventId)}`, |
| 2154 | ); |
| 2155 | } |
| 2156 |
| 2157 | // --------------------------------------------------------------------------- |
| 2158 | // Core Platform API — Search |
| 2159 | // --------------------------------------------------------------------------- |
| 2160 |
| 2161 | async searchWorkspace( |
| 2162 | workspaceId: string, |
| 2163 | input: WorkspaceSearchInput, |
| 2164 | ): Promise<WorkspaceSearchResponse> { |
| 2165 | return this.coreRequest<WorkspaceSearchResponse>( |
| 2166 | "POST", |
| 2167 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/search`, |
| 2168 | input, |
| 2169 | ); |
| 2170 | } |
| 2171 |
| 2172 | // --------------------------------------------------------------------------- |
| 2173 | // Core Platform API — Taskboards |
| 2174 | // --------------------------------------------------------------------------- |
| 2175 |
| 2176 | async listWorkspaceTaskboards( |
| 2177 | workspaceId: string, |
| 2178 | ): Promise<WorkspaceTaskboardsResponse> { |
| 2179 | return this.coreRequest<WorkspaceTaskboardsResponse>( |
| 2180 | "GET", |
| 2181 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards`, |
| 2182 | ); |
| 2183 | } |
| 2184 |
| 2185 | // --------------------------------------------------------------------------- |
| 2186 | // Core Platform API — Tasks |
| 2187 | // --------------------------------------------------------------------------- |
| 2188 |
| 2189 | async listTaskboardTasks( |
| 2190 | workspaceId: string, |
| 2191 | taskboardId: string, |
| 2192 | query?: ListTaskboardTasksQuery, |
| 2193 | ): Promise<TaskboardTasksResponse> { |
| 2194 | const params = new URLSearchParams(); |
| 2195 | if (query?.q) params.set("q", query.q); |
| 2196 | if (query?.statusId) params.set("statusId", query.statusId); |
| 2197 | if (query?.assigneeUserId) params.set("assigneeUserId", query.assigneeUserId); |
| 2198 | if (query?.limit !== undefined) params.set("limit", String(query.limit)); |
| 2199 | const qs = params.toString(); |
| 2200 | return this.coreRequest<TaskboardTasksResponse>( |
| 2201 | "GET", |
| 2202 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards/${encodeURIComponent(taskboardId)}/tasks${qs ? `?${qs}` : ""}`, |
| 2203 | ); |
| 2204 | } |
| 2205 |
| 2206 | async createTaskboardTask( |
| 2207 | workspaceId: string, |
| 2208 | taskboardId: string, |
| 2209 | input: CreateTaskInput, |
| 2210 | ): Promise<CreateTaskResponse> { |
| 2211 | return this.coreRequest<CreateTaskResponse>( |
| 2212 | "POST", |
| 2213 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards/${encodeURIComponent(taskboardId)}/tasks`, |
| 2214 | input, |
| 2215 | ); |
| 2216 | } |
| 2217 |
| 2218 | async updateTaskboardTask( |
| 2219 | workspaceId: string, |
| 2220 | taskboardId: string, |
| 2221 | taskId: string, |
| 2222 | input: UpdateTaskInput, |
| 2223 | ): Promise<{ ok: true }> { |
| 2224 | return this.coreRequest<{ ok: true }>( |
| 2225 | "PATCH", |
| 2226 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards/${encodeURIComponent(taskboardId)}/tasks/${encodeURIComponent(taskId)}`, |
| 2227 | input, |
| 2228 | ); |
| 2229 | } |
| 2230 |
| 2231 | async deleteTaskboardTask( |
| 2232 | workspaceId: string, |
| 2233 | taskboardId: string, |
| 2234 | taskId: string, |
| 2235 | ): Promise<{ ok: true }> { |
| 2236 | return this.coreRequest<{ ok: true }>( |
| 2237 | "DELETE", |
| 2238 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards/${encodeURIComponent(taskboardId)}/tasks/${encodeURIComponent(taskId)}`, |
| 2239 | ); |
| 2240 | } |
| 2241 |
| 2242 | // --------------------------------------------------------------------------- |
| 2243 | // Workspace-scoped client |
| 2244 | // --------------------------------------------------------------------------- |
| 2245 |
| 2246 | /** |
| 2247 | * Returns a publisher-scoped handle for a specific app key. |
| 2248 | * |
| 2249 | * @example |
| 2250 | * ```ts |
| 2251 | * const app = coline.app("com.example.notes"); |
| 2252 | * const versions = await app.listVersions(); |
| 2253 | * await app.submitVersionForReview("ver_123", { storeListed: true }); |
| 2254 | * ``` |
| 2255 | */ |
| 2256 | app(appKey: string): PublishedAppHandle { |
| 2257 | return new PublishedAppHandle(this, appKey); |
| 2258 | } |
| 2259 |
| 2260 | /** |
| 2261 | * Returns a workspace-scoped client that drops the `workspaceId` first |
| 2262 | * argument from every workspace method. |
| 2263 | * |
| 2264 | * @example |
| 2265 | * ```ts |
| 2266 | * const ws = coline.workspace("ws_abc123"); |
| 2267 | * const notes = await ws.listNotes({ limit: 10 }); |
| 2268 | * const thread = await ws.getThread(messageId); |
| 2269 | * for await (const note of ws.paginateNotes()) { |
| 2270 | * console.log(note.title); |
| 2271 | * } |
| 2272 | * ``` |
| 2273 | */ |
| 2274 | workspace(workspaceId: string): ColineWorkspace { |
| 2275 | return new ColineWorkspace(this, workspaceId); |
| 2276 | } |
| 2277 | } |
| 2278 |
| 2279 | // --------------------------------------------------------------------------- |
| 2280 | // Workspace-scoped client — removes workspaceId boilerplate |
| 2281 | // --------------------------------------------------------------------------- |
| 2282 |
| 2283 | /** |
| 2284 | * A convenience wrapper around `ColineApiClient` that binds a workspace ID |
| 2285 | * so you don't have to pass it to every call. |
| 2286 | * |
| 2287 | * Get one via `client.workspace("ws_abc123")`. |
| 2288 | */ |
| 2289 | export class ColineWorkspace { |
| 2290 | constructor( |
| 2291 | private readonly client: ColineApiClient, |
| 2292 | readonly workspaceId: string, |
| 2293 | ) {} |
| 2294 |
| 2295 | // -- Installed Apps & App Runtime ----------------------------------------- |
| 2296 |
| 2297 | listApps() { |
| 2298 | return this.client.listWorkspaceApps(this.workspaceId); |
| 2299 | } |
| 2300 |
| 2301 | installApp(input: InstallWorkspaceAppInput) { |
| 2302 | return this.client.installWorkspaceApp(this.workspaceId, input); |
| 2303 | } |
| 2304 |
| 2305 | // -- Members --------------------------------------------------------------- |
| 2306 |
| 2307 | listMembers() { |
| 2308 | return this.client.listWorkspaceMembers(this.workspaceId); |
| 2309 | } |
| 2310 |
| 2311 | // -- Notes ----------------------------------------------------------------- |
| 2312 |
| 2313 | listNotes(query?: ListWorkspaceNotesQuery) { |
| 2314 | return this.client.listWorkspaceNotes(this.workspaceId, query); |
| 2315 | } |
| 2316 |
| 2317 | createNote(input: CreateWorkspaceNoteInput) { |
| 2318 | return this.client.createWorkspaceNote(this.workspaceId, input); |
| 2319 | } |
| 2320 |
| 2321 | getNote(noteId: string) { |
| 2322 | return this.client.getWorkspaceNote(this.workspaceId, noteId); |
| 2323 | } |
| 2324 |
| 2325 | updateNote(noteId: string, input: UpdateWorkspaceNoteInput) { |
| 2326 | return this.client.updateWorkspaceNote(this.workspaceId, noteId, input); |
| 2327 | } |
| 2328 |
| 2329 | deleteNote(noteId: string) { |
| 2330 | return this.client.deleteWorkspaceNote(this.workspaceId, noteId); |
| 2331 | } |
| 2332 |
| 2333 | /** Async generator that auto-paginates through all notes. */ |
| 2334 | paginateNotes(query?: Omit<ListWorkspaceNotesQuery, "cursor">) { |
| 2335 | return paginate<WorkspaceNoteSummary>(async (cursor) => { |
| 2336 | const res = await this.listNotes({ ...query, ...(cursor !== undefined ? { cursor } : {}) }); |
| 2337 | return { |
| 2338 | items: res.notes, |
| 2339 | nextCursor: res.page.nextCursor, |
| 2340 | hasMore: res.page.hasMore, |
| 2341 | }; |
| 2342 | }); |
| 2343 | } |
| 2344 |
| 2345 | // -- Docs ------------------------------------------------------------------ |
| 2346 |
| 2347 | listDocs(query?: ListWorkspaceDocsQuery) { |
| 2348 | return this.client.listWorkspaceDocs(this.workspaceId, query); |
| 2349 | } |
| 2350 |
| 2351 | createDoc(input: CreateWorkspaceDocInput) { |
| 2352 | return this.client.createWorkspaceDoc(this.workspaceId, input); |
| 2353 | } |
| 2354 |
| 2355 | getDoc(docId: string) { |
| 2356 | return this.client.getWorkspaceDoc(this.workspaceId, docId); |
| 2357 | } |
| 2358 |
| 2359 | updateDoc(docId: string, input: UpdateWorkspaceDocInput) { |
| 2360 | return this.client.updateWorkspaceDoc(this.workspaceId, docId, input); |
| 2361 | } |
| 2362 |
| 2363 | deleteDoc(docId: string) { |
| 2364 | return this.client.deleteWorkspaceDoc(this.workspaceId, docId); |
| 2365 | } |
| 2366 |
| 2367 | /** Async generator that auto-paginates through all docs. */ |
| 2368 | paginateDocs(query?: Omit<ListWorkspaceDocsQuery, "cursor">) { |
| 2369 | return paginate<WorkspaceDocSummary>(async (cursor) => { |
| 2370 | const res = await this.listDocs({ ...query, ...(cursor !== undefined ? { cursor } : {}) }); |
| 2371 | return { |
| 2372 | items: res.docs, |
| 2373 | nextCursor: res.page.nextCursor, |
| 2374 | hasMore: res.page.hasMore, |
| 2375 | }; |
| 2376 | }); |
| 2377 | } |
| 2378 |
| 2379 | // -- Drives & Files -------------------------------------------------------- |
| 2380 |
| 2381 | listDrives() { |
| 2382 | return this.client.listWorkspaceDrives(this.workspaceId); |
| 2383 | } |
| 2384 |
| 2385 | listDriveFiles(driveId: string, query?: ListDriveFilesQuery) { |
| 2386 | return this.client.listDriveFiles(this.workspaceId, driveId, query); |
| 2387 | } |
| 2388 |
| 2389 | getFile(fileId: string) { |
| 2390 | return this.client.getFile(this.workspaceId, fileId); |
| 2391 | } |
| 2392 |
| 2393 | updateFile(fileId: string, input: UpdateFileInput) { |
| 2394 | return this.client.updateFile(this.workspaceId, fileId, input); |
| 2395 | } |
| 2396 |
| 2397 | deleteFile(fileId: string) { |
| 2398 | return this.client.deleteFile(this.workspaceId, fileId); |
| 2399 | } |
| 2400 |
| 2401 | // -- Channels -------------------------------------------------------------- |
| 2402 |
| 2403 | listChannels() { |
| 2404 | return this.client.listWorkspaceChannels(this.workspaceId); |
| 2405 | } |
| 2406 |
| 2407 | listChannelMessages(channelId: string, query?: { cursor?: string; limit?: number }) { |
| 2408 | return this.client.listChannelMessages(this.workspaceId, channelId, query); |
| 2409 | } |
| 2410 |
| 2411 | sendChannelMessage(channelId: string, input: SendMessageInput) { |
| 2412 | return this.client.sendChannelMessage(this.workspaceId, channelId, input); |
| 2413 | } |
| 2414 |
| 2415 | // -- Direct Messages ------------------------------------------------------- |
| 2416 |
| 2417 | listDms() { |
| 2418 | return this.client.listWorkspaceDms(this.workspaceId); |
| 2419 | } |
| 2420 |
| 2421 | listDmMessages(dmId: string, query?: { cursor?: string; limit?: number }) { |
| 2422 | return this.client.listDmMessages(this.workspaceId, dmId, query); |
| 2423 | } |
| 2424 |
| 2425 | sendDmMessage(dmId: string, input: SendMessageInput) { |
| 2426 | return this.client.sendDmMessage(this.workspaceId, dmId, input); |
| 2427 | } |
| 2428 |
| 2429 | // -- Messages -------------------------------------------------------------- |
| 2430 |
| 2431 | getMessage(messageId: string) { |
| 2432 | return this.client.getMessage(this.workspaceId, messageId); |
| 2433 | } |
| 2434 |
| 2435 | editMessage(messageId: string, input: EditMessageInput) { |
| 2436 | return this.client.editMessage(this.workspaceId, messageId, input); |
| 2437 | } |
| 2438 |
| 2439 | deleteMessage(messageId: string) { |
| 2440 | return this.client.deleteMessage(this.workspaceId, messageId); |
| 2441 | } |
| 2442 |
| 2443 | getThread(messageId: string) { |
| 2444 | return this.client.getThread(this.workspaceId, messageId); |
| 2445 | } |
| 2446 |
| 2447 | replyToThread(messageId: string, input: ThreadReplyInput) { |
| 2448 | return this.client.replyToThread(this.workspaceId, messageId, input); |
| 2449 | } |
| 2450 |
| 2451 | addReaction(messageId: string, emoji: string) { |
| 2452 | return this.client.addReaction(this.workspaceId, messageId, emoji); |
| 2453 | } |
| 2454 |
| 2455 | removeReaction(messageId: string, emoji: string) { |
| 2456 | return this.client.removeReaction(this.workspaceId, messageId, emoji); |
| 2457 | } |
| 2458 |
| 2459 | pinMessage(messageId: string) { |
| 2460 | return this.client.pinMessage(this.workspaceId, messageId); |
| 2461 | } |
| 2462 |
| 2463 | unpinMessage(messageId: string) { |
| 2464 | return this.client.unpinMessage(this.workspaceId, messageId); |
| 2465 | } |
| 2466 |
| 2467 | // -- Calendar Events ------------------------------------------------------- |
| 2468 |
| 2469 | listCalendarEvents(range: { start: string; end: string }) { |
| 2470 | return this.client.listCalendarEvents(this.workspaceId, range); |
| 2471 | } |
| 2472 |
| 2473 | createCalendarEvent(input: CreateCalendarEventInput) { |
| 2474 | return this.client.createCalendarEvent(this.workspaceId, input); |
| 2475 | } |
| 2476 |
| 2477 | getCalendarEvent(eventId: string) { |
| 2478 | return this.client.getCalendarEvent(this.workspaceId, eventId); |
| 2479 | } |
| 2480 |
| 2481 | updateCalendarEvent(eventId: string, input: UpdateCalendarEventInput) { |
| 2482 | return this.client.updateCalendarEvent(this.workspaceId, eventId, input); |
| 2483 | } |
| 2484 |
| 2485 | deleteCalendarEvent(eventId: string) { |
| 2486 | return this.client.deleteCalendarEvent(this.workspaceId, eventId); |
| 2487 | } |
| 2488 |
| 2489 | // -- Search ---------------------------------------------------------------- |
| 2490 |
| 2491 | search(input: WorkspaceSearchInput) { |
| 2492 | return this.client.searchWorkspace(this.workspaceId, input); |
| 2493 | } |
| 2494 |
| 2495 | // -- Taskboards & Tasks ---------------------------------------------------- |
| 2496 |
| 2497 | listTaskboards() { |
| 2498 | return this.client.listWorkspaceTaskboards(this.workspaceId); |
| 2499 | } |
| 2500 |
| 2501 | listTasks(taskboardId: string, query?: ListTaskboardTasksQuery) { |
| 2502 | return this.client.listTaskboardTasks(this.workspaceId, taskboardId, query); |
| 2503 | } |
| 2504 |
| 2505 | createTask(taskboardId: string, input: CreateTaskInput) { |
| 2506 | return this.client.createTaskboardTask(this.workspaceId, taskboardId, input); |
| 2507 | } |
| 2508 |
| 2509 | updateTask(taskboardId: string, taskId: string, input: UpdateTaskInput) { |
| 2510 | return this.client.updateTaskboardTask(this.workspaceId, taskboardId, taskId, input); |
| 2511 | } |
| 2512 |
| 2513 | deleteTask(taskboardId: string, taskId: string) { |
| 2514 | return this.client.deleteTaskboardTask(this.workspaceId, taskboardId, taskId); |
| 2515 | } |
| 2516 |
| 2517 | // --------------------------------------------------------------------------- |
| 2518 | // Resource handles — chainable accessors for individual resources |
| 2519 | // --------------------------------------------------------------------------- |
| 2520 |
| 2521 | /** |
| 2522 | * Get a handle to a specific note. |
| 2523 | * @example |
| 2524 | * ```ts |
| 2525 | * const body = await ws.note("note_123").get(); |
| 2526 | * await ws.note("note_123").update({ title: "New title" }); |
| 2527 | * await ws.note("note_123").delete(); |
| 2528 | * ``` |
| 2529 | */ |
| 2530 | note(noteId: string): NoteHandle { |
| 2531 | return new NoteHandle(this, noteId); |
| 2532 | } |
| 2533 |
| 2534 | /** |
| 2535 | * Get a handle to a specific doc. |
| 2536 | * @example |
| 2537 | * ```ts |
| 2538 | * const doc = await ws.doc("doc_456").get(); |
| 2539 | * await ws.doc("doc_456").update({ title: "Updated" }); |
| 2540 | * ``` |
| 2541 | */ |
| 2542 | doc(docId: string): DocHandle { |
| 2543 | return new DocHandle(this, docId); |
| 2544 | } |
| 2545 |
| 2546 | /** |
| 2547 | * Get a handle to a specific file. |
| 2548 | * @example |
| 2549 | * ```ts |
| 2550 | * const file = await ws.file("file_789").get(); |
| 2551 | * await ws.file("file_789").update({ name: "renamed.pdf" }); |
| 2552 | * await ws.file("file_789").delete(); |
| 2553 | * ``` |
| 2554 | */ |
| 2555 | file(fileId: string): FileHandle { |
| 2556 | return new FileHandle(this, fileId); |
| 2557 | } |
| 2558 |
| 2559 | /** |
| 2560 | * Get a handle to a specific message. |
| 2561 | * @example |
| 2562 | * ```ts |
| 2563 | * const msg = await ws.message("msg_123").get(); |
| 2564 | * await ws.message("msg_123").edit({ content: Message.text("updated").build() }); |
| 2565 | * await ws.message("msg_123").react("👍"); |
| 2566 | * await ws.message("msg_123").pin(); |
| 2567 | * const thread = await ws.message("msg_123").thread(); |
| 2568 | * await ws.message("msg_123").reply(Message.text("reply!").toInput()); |
| 2569 | * ``` |
| 2570 | */ |
| 2571 | message(messageId: string): MessageHandle { |
| 2572 | return new MessageHandle(this, messageId); |
| 2573 | } |
| 2574 |
| 2575 | /** |
| 2576 | * Get a handle to a specific channel. |
| 2577 | * @example |
| 2578 | * ```ts |
| 2579 | * const messages = await ws.channel("ch_123").messages(); |
| 2580 | * await ws.channel("ch_123").send(Message.text("hello!").toInput()); |
| 2581 | * ``` |
| 2582 | */ |
| 2583 | channel(channelId: string): ChannelHandle { |
| 2584 | return new ChannelHandle(this, channelId); |
| 2585 | } |
| 2586 |
| 2587 | /** |
| 2588 | * Get a handle to a specific DM. |
| 2589 | * @example |
| 2590 | * ```ts |
| 2591 | * await ws.dm("dm_456").send(Message.text("hey!").toInput()); |
| 2592 | * ``` |
| 2593 | */ |
| 2594 | dm(dmId: string): DmHandle { |
| 2595 | return new DmHandle(this, dmId); |
| 2596 | } |
| 2597 |
| 2598 | /** |
| 2599 | * Get a handle to a specific calendar event. |
| 2600 | * @example |
| 2601 | * ```ts |
| 2602 | * const event = await ws.event("evt_789").get(); |
| 2603 | * await ws.event("evt_789").update({ title: "Moved" }); |
| 2604 | * await ws.event("evt_789").delete(); |
| 2605 | * ``` |
| 2606 | */ |
| 2607 | event(eventId: string): CalendarEventHandle { |
| 2608 | return new CalendarEventHandle(this, eventId); |
| 2609 | } |
| 2610 |
| 2611 | /** |
| 2612 | * Get a handle to a specific taskboard. |
| 2613 | * @example |
| 2614 | * ```ts |
| 2615 | * const tasks = await ws.taskboard("tb_123").listTasks(); |
| 2616 | * await ws.taskboard("tb_123").createTask({ title: "New task" }); |
| 2617 | * await ws.taskboard("tb_123").task("task_456").update({ priority: "high" }); |
| 2618 | * ``` |
| 2619 | */ |
| 2620 | taskboard(taskboardId: string): TaskboardHandle { |
| 2621 | return new TaskboardHandle(this, taskboardId); |
| 2622 | } |
| 2623 |
| 2624 | /** |
| 2625 | * Get a handle to a workspace-installed app and its runtime surfaces. |
| 2626 | * |
| 2627 | * @example |
| 2628 | * ```ts |
| 2629 | * await ws.installApp({ appId: "app_123" }); |
| 2630 | * const crm = ws.app("acme-crm"); |
| 2631 | * const files = await crm.listFiles({ limit: 20 }); |
| 2632 | * await crm.file("file_123").updateDocument({ status: "active" }); |
| 2633 | * ``` |
| 2634 | */ |
| 2635 | app(appKey: string): WorkspaceAppHandle { |
| 2636 | return new WorkspaceAppHandle(this.client, this.workspaceId, appKey); |
| 2637 | } |
| 2638 | } |
| 2639 |
| 2640 | // --------------------------------------------------------------------------- |
| 2641 | // Resource handles |
| 2642 | // --------------------------------------------------------------------------- |
| 2643 |
| 2644 | export class PublishedAppHandle { |
| 2645 | constructor( |
| 2646 | private readonly client: ColineApiClient, |
| 2647 | readonly key: string, |
| 2648 | ) {} |
| 2649 |
| 2650 | get() { return this.client.getApp(this.key); } |
| 2651 | listVersions() { return this.client.listAppVersions(this.key); } |
| 2652 | createVersion(payload: ColineAppRegistrationPayloadInput) { |
| 2653 | return this.client.createAppVersion(this.key, payload); |
| 2654 | } |
| 2655 | submitVersionForReview( |
| 2656 | versionId: string, |
| 2657 | input: SubmitAppVersionForReviewInput = {}, |
| 2658 | ) { |
| 2659 | return this.client.submitAppVersionForReview(this.key, versionId, input); |
| 2660 | } |
| 2661 | } |
| 2662 |
| 2663 | export class WorkspaceAppHandle { |
| 2664 | constructor( |
| 2665 | private readonly client: ColineApiClient, |
| 2666 | readonly workspaceId: string, |
| 2667 | readonly key: string, |
| 2668 | ) {} |
| 2669 |
| 2670 | get() { |
| 2671 | return this.client.getWorkspaceInstalledApp(this.workspaceId, this.key); |
| 2672 | } |
| 2673 |
| 2674 | getPermissions() { |
| 2675 | return this.client.getWorkspaceAppPermissions(this.workspaceId, this.key); |
| 2676 | } |
| 2677 |
| 2678 | updatePermissions(input: UpdateWorkspaceAppPermissionsInput) { |
| 2679 | return this.client.updateWorkspaceAppPermissions(this.workspaceId, this.key, input); |
| 2680 | } |
| 2681 |
| 2682 | uninstall() { |
| 2683 | return this.client.uninstallWorkspaceApp(this.workspaceId, this.key); |
| 2684 | } |
| 2685 |
| 2686 | listSecrets() { |
| 2687 | return this.client.listWorkspaceAppSecrets(this.workspaceId, this.key); |
| 2688 | } |
| 2689 |
| 2690 | createSecret(input: CreateWorkspaceAppSecretInput) { |
| 2691 | return this.client.createWorkspaceAppSecret(this.workspaceId, this.key, input); |
| 2692 | } |
| 2693 |
| 2694 | deleteSecret(secretId: string) { |
| 2695 | return this.client.deleteWorkspaceAppSecret(this.workspaceId, this.key, secretId); |
| 2696 | } |
| 2697 |
| 2698 | listOauthConnections() { |
| 2699 | return this.client.listWorkspaceAppOauthConnections(this.workspaceId, this.key); |
| 2700 | } |
| 2701 |
| 2702 | createOauthConnection(input: CreateWorkspaceAppOauthConnectionInput) { |
| 2703 | return this.client.createWorkspaceAppOauthConnection(this.workspaceId, this.key, input); |
| 2704 | } |
| 2705 |
| 2706 | deleteOauthConnection(connectionId: string) { |
| 2707 | return this.client.deleteWorkspaceAppOauthConnection( |
| 2708 | this.workspaceId, |
| 2709 | this.key, |
| 2710 | connectionId, |
| 2711 | ); |
| 2712 | } |
| 2713 |
| 2714 | listDeliveries() { |
| 2715 | return this.client.listWorkspaceAppDeliveries(this.workspaceId, this.key); |
| 2716 | } |
| 2717 |
| 2718 | sendTestDelivery(input: SendWorkspaceAppTestDeliveryInput) { |
| 2719 | return this.client.sendWorkspaceAppTestDelivery(this.workspaceId, this.key, input); |
| 2720 | } |
| 2721 |
| 2722 | replayDelivery(deliveryId: string) { |
| 2723 | return this.client.replayWorkspaceAppDelivery(this.workspaceId, this.key, deliveryId); |
| 2724 | } |
| 2725 |
| 2726 | emitAmbientEvents(input: EmitAmbientEventsInputInput) { |
| 2727 | return this.client.emitAppAmbientEvents(this.workspaceId, this.key, input); |
| 2728 | } |
| 2729 |
| 2730 | createNotification(input: CreateNotificationInputInput) { |
| 2731 | return this.client.createAppNotification(this.workspaceId, this.key, input); |
| 2732 | } |
| 2733 |
| 2734 | upsertIndexDocuments(input: BatchUpsertAppIndexDocumentsInput) { |
| 2735 | return this.client.upsertAppIndexDocuments(this.workspaceId, this.key, input); |
| 2736 | } |
| 2737 |
| 2738 | deleteIndexDocuments(input: BatchDeleteAppIndexDocumentsInput) { |
| 2739 | return this.client.deleteAppIndexDocuments(this.workspaceId, this.key, input); |
| 2740 | } |
| 2741 |
| 2742 | listFiles(query?: ListAppFilesQuery) { |
| 2743 | return this.client.listAppFiles(this.workspaceId, this.key, query); |
| 2744 | } |
| 2745 |
| 2746 | createFile(input: CreateAppFileInput) { |
| 2747 | return this.client.createAppFile(this.workspaceId, this.key, input); |
| 2748 | } |
| 2749 |
| 2750 | executeAction(input: ExecuteAppActionInput) { |
| 2751 | return this.client.executeAppAction(this.workspaceId, this.key, input); |
| 2752 | } |
| 2753 |
| 2754 | file(fileId: string): WorkspaceAppFileHandle { |
| 2755 | return new WorkspaceAppFileHandle(this.client, this.workspaceId, this.key, fileId); |
| 2756 | } |
| 2757 | } |
| 2758 |
| 2759 | export class WorkspaceAppFileHandle { |
| 2760 | constructor( |
| 2761 | private readonly client: ColineApiClient, |
| 2762 | readonly workspaceId: string, |
| 2763 | readonly appKey: string, |
| 2764 | readonly id: string, |
| 2765 | ) {} |
| 2766 |
| 2767 | get() { |
| 2768 | return this.client.getAppFileDocument(this.workspaceId, this.appKey, this.id); |
| 2769 | } |
| 2770 |
| 2771 | updateDocument(document: Record<string, unknown>) { |
| 2772 | return this.client.updateAppFileDocument( |
| 2773 | this.workspaceId, |
| 2774 | this.appKey, |
| 2775 | this.id, |
| 2776 | document, |
| 2777 | ); |
| 2778 | } |
| 2779 |
| 2780 | delete() { |
| 2781 | return this.client.deleteAppFile(this.workspaceId, this.appKey, this.id); |
| 2782 | } |
| 2783 | } |
| 2784 |
| 2785 | export class NoteHandle { |
| 2786 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 2787 | get() { return this.ws.getNote(this.id); } |
| 2788 | update(input: UpdateWorkspaceNoteInput) { return this.ws.updateNote(this.id, input); } |
| 2789 | delete() { return this.ws.deleteNote(this.id); } |
| 2790 | } |
| 2791 |
| 2792 | export class DocHandle { |
| 2793 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 2794 | get() { return this.ws.getDoc(this.id); } |
| 2795 | update(input: UpdateWorkspaceDocInput) { return this.ws.updateDoc(this.id, input); } |
| 2796 | delete() { return this.ws.deleteDoc(this.id); } |
| 2797 | } |
| 2798 |
| 2799 | export class FileHandle { |
| 2800 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 2801 | get() { return this.ws.getFile(this.id); } |
| 2802 | update(input: UpdateFileInput) { return this.ws.updateFile(this.id, input); } |
| 2803 | delete() { return this.ws.deleteFile(this.id); } |
| 2804 | } |
| 2805 |
| 2806 | export class MessageHandle { |
| 2807 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 2808 | get() { return this.ws.getMessage(this.id); } |
| 2809 | edit(input: EditMessageInput) { return this.ws.editMessage(this.id, input); } |
| 2810 | delete() { return this.ws.deleteMessage(this.id); } |
| 2811 | thread() { return this.ws.getThread(this.id); } |
| 2812 | reply(input: ThreadReplyInput) { return this.ws.replyToThread(this.id, input); } |
| 2813 | react(emoji: string) { return this.ws.addReaction(this.id, emoji); } |
| 2814 | unreact(emoji: string) { return this.ws.removeReaction(this.id, emoji); } |
| 2815 | pin() { return this.ws.pinMessage(this.id); } |
| 2816 | unpin() { return this.ws.unpinMessage(this.id); } |
| 2817 | } |
| 2818 |
| 2819 | export class ChannelHandle { |
| 2820 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 2821 | messages(query?: { cursor?: string; limit?: number }) { |
| 2822 | return this.ws.listChannelMessages(this.id, query); |
| 2823 | } |
| 2824 | send(input: SendMessageInput) { return this.ws.sendChannelMessage(this.id, input); } |
| 2825 | } |
| 2826 |
| 2827 | export class DmHandle { |
| 2828 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 2829 | messages(query?: { cursor?: string; limit?: number }) { |
| 2830 | return this.ws.listDmMessages(this.id, query); |
| 2831 | } |
| 2832 | send(input: SendMessageInput) { return this.ws.sendDmMessage(this.id, input); } |
| 2833 | } |
| 2834 |
| 2835 | export class CalendarEventHandle { |
| 2836 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 2837 | get() { return this.ws.getCalendarEvent(this.id); } |
| 2838 | update(input: UpdateCalendarEventInput) { return this.ws.updateCalendarEvent(this.id, input); } |
| 2839 | delete() { return this.ws.deleteCalendarEvent(this.id); } |
| 2840 | } |
| 2841 |
| 2842 | export class TaskboardHandle { |
| 2843 | constructor(private readonly ws: ColineWorkspace, readonly id: string) {} |
| 2844 | listTasks(query?: ListTaskboardTasksQuery) { return this.ws.listTasks(this.id, query); } |
| 2845 | createTask(input: CreateTaskInput) { return this.ws.createTask(this.id, input); } |
| 2846 | task(taskId: string): TaskHandle { return new TaskHandle(this.ws, this.id, taskId); } |
| 2847 | } |
| 2848 |
| 2849 | export class TaskHandle { |
| 2850 | constructor( |
| 2851 | private readonly ws: ColineWorkspace, |
| 2852 | private readonly taskboardId: string, |
| 2853 | readonly id: string, |
| 2854 | ) {} |
| 2855 | update(input: UpdateTaskInput) { return this.ws.updateTask(this.taskboardId, this.id, input); } |
| 2856 | delete() { return this.ws.deleteTask(this.taskboardId, this.id); } |
| 2857 | } |
| 2858 |