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 | } |
| 73 |
| 74 | type Schemas = AppPlatformComponents["schemas"]; |
| 75 | type UnwrapData<TKey extends keyof Schemas> = |
| 76 | Schemas[TKey] extends { data: infer T } ? T : never; |
| 77 |
| 78 | export type RegisteredAppDetail = Schemas["RegisteredAppDetail"]; |
| 79 | export type RegisteredAppRecord = Omit< |
| 80 | RegisteredAppDetail, |
| 81 | "latestPublishedVersionId" |
| 82 | >; |
| 83 | export type RegisteredAppVersionSummary = Schemas["RegisteredAppVersionSummary"]; |
| 84 | export type WorkspaceInstalledApp = Schemas["InstalledAppSummary"]; |
| 85 | export type WorkspaceAppCatalogItem = Schemas["AppCatalogItem"]; |
| 86 | export type WorkspaceAppsResponse = UnwrapData<"WorkspaceAppsResponse">; |
| 87 |
| 88 | export interface InstallWorkspaceAppInput { |
| 89 | appId: string; |
| 90 | pinnedVersionId?: string; |
| 91 | grantedPermissions?: AppPermission[]; |
| 92 | } |
| 93 |
| 94 | export type InstallWorkspaceAppResponse = UnwrapData<"InstallWorkspaceAppResponse">; |
| 95 |
| 96 | export interface SubmitAppVersionForReviewInput { |
| 97 | storeListed?: boolean; |
| 98 | } |
| 99 |
| 100 | export type SubmitAppVersionForReviewResponse = UnwrapData< |
| 101 | "SubmitAppVersionForReviewResponse" |
| 102 | >; |
| 103 | export type WorkspaceAppPermissionsResponse = UnwrapData< |
| 104 | "WorkspaceAppPermissionsResponse" |
| 105 | >; |
| 106 | export type WorkspaceInstalledAppResponse = UnwrapData< |
| 107 | "WorkspaceInstalledAppResponse" |
| 108 | >; |
| 109 | export type WorkspaceAppSecretsResponse = UnwrapData< |
| 110 | "WorkspaceAppSecretsResponse" |
| 111 | >; |
| 112 | export type WorkspaceAppSecretSummary = WorkspaceAppSecretsResponse["secrets"][number]; |
| 113 | export type CreateWorkspaceAppSecretResponse = UnwrapData< |
| 114 | "CreateWorkspaceAppSecretResponse" |
| 115 | >; |
| 116 | export type WorkspaceAppOauthConnectionsResponse = UnwrapData< |
| 117 | "WorkspaceAppOauthConnectionsResponse" |
| 118 | >; |
| 119 | export type WorkspaceAppOauthConnectionSummary = |
| 120 | WorkspaceAppOauthConnectionsResponse["connections"][number]; |
| 121 | export type CreateWorkspaceAppOauthConnectionResponse = UnwrapData< |
| 122 | "CreateWorkspaceAppOauthConnectionResponse" |
| 123 | >; |
| 124 | export type WorkspaceAppDeliveriesResponse = UnwrapData< |
| 125 | "WorkspaceAppDeliveriesResponse" |
| 126 | >; |
| 127 | export type WorkspaceAppDeliverySummary = |
| 128 | WorkspaceAppDeliveriesResponse["deliveries"][number]; |
| 129 | export type SendWorkspaceAppTestDeliveryResponse = UnwrapData< |
| 130 | "SendWorkspaceAppTestDeliveryResponse" |
| 131 | >; |
| 132 | export type AppFilesListResponse = UnwrapData<"AppFilesListResponse">; |
| 133 | export type AppFileDocumentResponse = UnwrapData<"AppFileDocumentResponse">; |
| 134 | export type AppFileDocumentUpdateResponse = UnwrapData< |
| 135 | "AppFileDocumentUpdateResponse" |
| 136 | >; |
| 137 | export type CreateAppFileResponse = UnwrapData<"CreateAppFileResponse">; |
| 138 | export type ExecuteAppActionResponse = UnwrapData<"ExecuteAppActionResponse">; |
| 139 | export type OkResponse = UnwrapData<"OkResponse">; |
| 140 | export type TabModelRecord = Schemas["TabModelRecord"]; |
| 141 | export type TabModelsResponse = UnwrapData<"TabModelsResponse">; |
| 142 | export type TabChatCompletionResponse = UnwrapData< |
| 143 | "TabChatCompletionResponseEnvelope" |
| 144 | >; |
| 145 | export type UpsertAppIndexDocumentsResponse = UnwrapData< |
| 146 | "UpsertAppIndexDocumentsResponse" |
| 147 | >; |
| 148 | export type DeleteAppIndexDocumentsResponse = UnwrapData< |
| 149 | "DeleteAppIndexDocumentsResponse" |
| 150 | >; |
| 151 | export type EmitAppAmbientEventsResponse = UnwrapData< |
| 152 | "EmitAppAmbientEventsResponse" |
| 153 | >; |
| 154 |
| 155 | export interface OAuthTokenResponse { |
| 156 | access_token: string; |
| 157 | token_type: "Bearer"; |
| 158 | expires_in: number; |
| 159 | refresh_token: string; |
| 160 | scope: string; |
| 161 | } |
| 162 |
| 163 | export interface OAuthUserInfoResponse { |
| 164 | sub: string; |
| 165 | email: string; |
| 166 | email_verified: boolean; |
| 167 | name: string; |
| 168 | given_name: string | null; |
| 169 | family_name: string | null; |
| 170 | picture: string | null; |
| 171 | preferred_username: string | null; |
| 172 | scope: string; |
| 173 | } |
| 174 |
| 175 | export interface UpdateWorkspaceAppPermissionsInput { |
| 176 | grantedPermissions: AppPermission[]; |
| 177 | } |
| 178 |
| 179 | export interface CreateAppFileInput { |
| 180 | name: string; |
| 181 | typeKey?: string; |
| 182 | driveId?: string; |
| 183 | parentId?: string | null; |
| 184 | document?: Record<string, unknown>; |
| 185 | } |
| 186 |
| 187 | export interface ExecuteAppActionInput { |
| 188 | action: { |
| 189 | type: string; |
| 190 | payload?: Record<string, unknown>; |
| 191 | }; |
| 192 | fileId?: string | null; |
| 193 | } |
| 194 |
| 195 | // --------------------------------------------------------------------------- |
| 196 | // Core Platform API — Types |
| 197 | // --------------------------------------------------------------------------- |
| 198 |
| 199 | export interface WorkspaceMember { |
| 200 | id: string; |
| 201 | workspaceMemberId: string; |
| 202 | email: string; |
| 203 | firstName: string | null; |
| 204 | lastName: string | null; |
| 205 | avatarUrl: string | null; |
| 206 | joinedAt: string; |
| 207 | roles: string[]; |
| 208 | } |
| 209 |
| 210 | export interface WorkspaceMembersResponse { |
| 211 | members: WorkspaceMember[]; |
| 212 | } |
| 213 |
| 214 | export interface WorkspaceNoteSummary { |
| 215 | id: string; |
| 216 | driveId: string; |
| 217 | parentId: string | null; |
| 218 | title: string; |
| 219 | body: string; |
| 220 | color: string | null; |
| 221 | createdByUserId: string | null; |
| 222 | createdAt: string; |
| 223 | updatedAt: string; |
| 224 | } |
| 225 |
| 226 | export interface WorkspaceNoteDetail extends WorkspaceNoteSummary { |
| 227 | blocks: unknown[]; |
| 228 | } |
| 229 |
| 230 | export interface WorkspaceNotesListResponse { |
| 231 | notes: WorkspaceNoteSummary[]; |
| 232 | page: { limit: number; hasMore: boolean; nextCursor: string | null }; |
| 233 | } |
| 234 |
| 235 | export interface WorkspaceNoteResponse { |
| 236 | note: WorkspaceNoteSummary; |
| 237 | } |
| 238 |
| 239 | export interface WorkspaceNoteDetailResponse { |
| 240 | note: WorkspaceNoteDetail; |
| 241 | } |
| 242 |
| 243 | export interface ListWorkspaceNotesQuery { |
| 244 | q?: string; |
| 245 | limit?: number; |
| 246 | cursor?: string; |
| 247 | } |
| 248 |
| 249 | export interface CreateWorkspaceNoteInput { |
| 250 | title?: string; |
| 251 | body?: string; |
| 252 | blocks?: unknown[]; |
| 253 | driveId?: string; |
| 254 | parentId?: string | null; |
| 255 | } |
| 256 |
| 257 | export interface UpdateWorkspaceNoteInput { |
| 258 | title?: string; |
| 259 | body?: string; |
| 260 | blocks?: unknown[]; |
| 261 | } |
| 262 |
| 263 | export interface CalendarEventLinkInput { |
| 264 | linkType: "file" | "channel" | "url"; |
| 265 | fileId?: string; |
| 266 | channelId?: string; |
| 267 | url?: string; |
| 268 | label?: string | null; |
| 269 | } |
| 270 |
| 271 | // --------------------------------------------------------------------------- |
| 272 | // Core Platform API — Docs Types |
| 273 | // --------------------------------------------------------------------------- |
| 274 |
| 275 | export interface DocLayout { |
| 276 | mode: "pages"; |
| 277 | pageSize: "letter"; |
| 278 | orientation: "portrait" | "landscape"; |
| 279 | margins: "normal" | "narrow" | "wide"; |
| 280 | backgroundColor: string | null; |
| 281 | showPageNumbers: boolean; |
| 282 | } |
| 283 |
| 284 | export interface WorkspaceDocSummary { |
| 285 | id: string; |
| 286 | driveId: string; |
| 287 | parentId: string | null; |
| 288 | title: string; |
| 289 | excerpt: string; |
| 290 | color: string | null; |
| 291 | layout: DocLayout; |
| 292 | createdByUserId: string | null; |
| 293 | createdAt: string; |
| 294 | updatedAt: string; |
| 295 | } |
| 296 |
| 297 | export interface WorkspaceDocDetail extends Omit<WorkspaceDocSummary, "excerpt"> { |
| 298 | content: Record<string, unknown>; |
| 299 | plainText: string; |
| 300 | } |
| 301 |
| 302 | export interface WorkspaceDocsListResponse { |
| 303 | docs: WorkspaceDocSummary[]; |
| 304 | page: { limit: number; hasMore: boolean; nextCursor: string | null }; |
| 305 | } |
| 306 |
| 307 | export interface WorkspaceDocResponse { |
| 308 | doc: WorkspaceDocSummary; |
| 309 | } |
| 310 |
| 311 | export interface WorkspaceDocDetailResponse { |
| 312 | doc: WorkspaceDocDetail; |
| 313 | } |
| 314 |
| 315 | export interface ListWorkspaceDocsQuery { |
| 316 | q?: string; |
| 317 | limit?: number; |
| 318 | cursor?: string; |
| 319 | } |
| 320 |
| 321 | export interface CreateWorkspaceDocInput { |
| 322 | title?: string; |
| 323 | content?: Record<string, unknown>; |
| 324 | layout?: { |
| 325 | orientation?: "portrait" | "landscape"; |
| 326 | margins?: "normal" | "narrow" | "wide"; |
| 327 | backgroundColor?: string | null; |
| 328 | showPageNumbers?: boolean; |
| 329 | }; |
| 330 | driveId?: string; |
| 331 | parentId?: string | null; |
| 332 | } |
| 333 |
| 334 | export interface UpdateWorkspaceDocInput { |
| 335 | title?: string; |
| 336 | content?: Record<string, unknown>; |
| 337 | layout?: { |
| 338 | orientation?: "portrait" | "landscape"; |
| 339 | margins?: "normal" | "narrow" | "wide"; |
| 340 | backgroundColor?: string | null; |
| 341 | showPageNumbers?: boolean; |
| 342 | }; |
| 343 | } |
| 344 |
| 345 | // --------------------------------------------------------------------------- |
| 346 | // Core Platform API — Drives & Files Types |
| 347 | // --------------------------------------------------------------------------- |
| 348 |
| 349 | export interface DriveMountSummary { |
| 350 | type: "native" | "integration"; |
| 351 | providerKey: string | null; |
| 352 | syncStatus: "idle" | "syncing" | "errored" | "disabled"; |
| 353 | } |
| 354 |
| 355 | export interface WorkspaceDriveSummary { |
| 356 | id: string; |
| 357 | name: string; |
| 358 | slug: string; |
| 359 | kind: "personal" | "shared"; |
| 360 | accessMode: "workspace_default" | "restricted"; |
| 361 | isDefault: boolean; |
| 362 | ownerUserId: string | null; |
| 363 | mount: DriveMountSummary; |
| 364 | createdAt: string; |
| 365 | updatedAt: string; |
| 366 | } |
| 367 |
| 368 | export interface WorkspaceDrivesListResponse { |
| 369 | drives: WorkspaceDriveSummary[]; |
| 370 | } |
| 371 |
| 372 | export interface DriveFileSummary { |
| 373 | id: string; |
| 374 | driveId: string; |
| 375 | parentId: string | null; |
| 376 | name: string; |
| 377 | fileType: string; |
| 378 | mimeType: string | null; |
| 379 | sizeBytes: number | null; |
| 380 | color: string | null; |
| 381 | createdByUserId: string | null; |
| 382 | createdAt: string; |
| 383 | updatedAt: string; |
| 384 | } |
| 385 |
| 386 | export interface DriveFilesListResponse { |
| 387 | files: DriveFileSummary[]; |
| 388 | page: { limit: number; hasMore: boolean; nextCursor: string | null }; |
| 389 | } |
| 390 |
| 391 | export interface ListDriveFilesQuery { |
| 392 | parentId?: string; |
| 393 | fileType?: string; |
| 394 | trashed?: boolean; |
| 395 | limit?: number; |
| 396 | cursor?: string; |
| 397 | } |
| 398 |
| 399 | export interface FileDetail { |
| 400 | id: string; |
| 401 | driveId: string; |
| 402 | parentId: string | null; |
| 403 | name: string; |
| 404 | fileType: string; |
| 405 | mimeType: string | null; |
| 406 | sizeBytes: number | null; |
| 407 | color: string | null; |
| 408 | accessMode: string; |
| 409 | isTrashed: boolean; |
| 410 | createdByUserId: string | null; |
| 411 | createdAt: string; |
| 412 | updatedAt: string; |
| 413 | } |
| 414 |
| 415 | export interface FileDetailResponse { |
| 416 | file: FileDetail; |
| 417 | } |
| 418 |
| 419 | export interface UpdateFileInput { |
| 420 | name?: string; |
| 421 | parentId?: string | null; |
| 422 | color?: "red" | "orange" | "yellow" | "green" | "blue" | "purple" | "pink" | "gray" | null; |
| 423 | } |
| 424 |
| 425 | // --------------------------------------------------------------------------- |
| 426 | // Channels |
| 427 | // --------------------------------------------------------------------------- |
| 428 |
| 429 | export interface ChannelSummary { |
| 430 | id: string; |
| 431 | name: string; |
| 432 | slug: string; |
| 433 | description: string | null; |
| 434 | topic: string | null; |
| 435 | type: "public" | "private"; |
| 436 | isDefault: boolean; |
| 437 | createdAt: string; |
| 438 | updatedAt: string; |
| 439 | } |
| 440 |
| 441 | export interface ChannelListResponse { |
| 442 | channels: ChannelSummary[]; |
| 443 | } |
| 444 |
| 445 | // --------------------------------------------------------------------------- |
| 446 | // Direct Messages |
| 447 | // --------------------------------------------------------------------------- |
| 448 |
| 449 | export interface DmMemberSummary { |
| 450 | userId: string; |
| 451 | firstName: string | null; |
| 452 | lastName: string | null; |
| 453 | email: string; |
| 454 | } |
| 455 |
| 456 | export interface DmSummary { |
| 457 | id: string; |
| 458 | isGroup: boolean; |
| 459 | name: string | null; |
| 460 | members: DmMemberSummary[]; |
| 461 | createdAt: string; |
| 462 | updatedAt: string; |
| 463 | } |
| 464 |
| 465 | export interface DmListResponse { |
| 466 | dms: DmSummary[]; |
| 467 | } |
| 468 |
| 469 | // --------------------------------------------------------------------------- |
| 470 | // Messages |
| 471 | // --------------------------------------------------------------------------- |
| 472 |
| 473 | export interface MessageTextPart { |
| 474 | type: "text"; |
| 475 | text: string; |
| 476 | } |
| 477 |
| 478 | export interface MessageMentionPart { |
| 479 | type: "mention"; |
| 480 | userId: string; |
| 481 | displayName: string; |
| 482 | } |
| 483 |
| 484 | export type MessageContentPart = MessageTextPart | MessageMentionPart; |
| 485 |
| 486 | export interface ContainerMessageSummary { |
| 487 | id: string; |
| 488 | authorUserId: string | null; |
| 489 | messageKind: string; |
| 490 | plaintext: string; |
| 491 | content: MessageContentPart[]; |
| 492 | replyToMessageId: string | null; |
| 493 | editedAt: string | null; |
| 494 | createdAt: string; |
| 495 | updatedAt: string; |
| 496 | } |
| 497 |
| 498 | export interface MessagesListResponse { |
| 499 | messages: ContainerMessageSummary[]; |
| 500 | page: { |
| 501 | limit: number; |
| 502 | hasMore: boolean; |
| 503 | nextCursor: string | null; |
| 504 | }; |
| 505 | } |
| 506 |
| 507 | export interface CalendarRecurrenceRule { |
| 508 | frequency: "daily" | "weekly" | "monthly" | "yearly"; |
| 509 | interval: number; |
| 510 | byDay?: Array<"MO" | "TU" | "WE" | "TH" | "FR" | "SA" | "SU">; |
| 511 | count?: number; |
| 512 | until?: string; |
| 513 | } |
| 514 |
| 515 | export interface CreateCalendarEventInput { |
| 516 | title: string; |
| 517 | description?: string | null; |
| 518 | location?: string | null; |
| 519 | startsAt: string; |
| 520 | endsAt: string; |
| 521 | timeZone: string; |
| 522 | isAllDay?: boolean; |
| 523 | visibility?: "private" | "invitees" | "workspace"; |
| 524 | attendeeUserIds?: string[]; |
| 525 | linkInputs?: CalendarEventLinkInput[]; |
| 526 | recurrenceRule?: CalendarRecurrenceRule | null; |
| 527 | } |
| 528 |
| 529 | export interface UpdateCalendarEventInput { |
| 530 | title?: string; |
| 531 | description?: string | null; |
| 532 | location?: string | null; |
| 533 | startsAt?: string; |
| 534 | endsAt?: string; |
| 535 | timeZone?: string; |
| 536 | isAllDay?: boolean; |
| 537 | visibility?: "private" | "invitees" | "workspace"; |
| 538 | status?: "active" | "canceled"; |
| 539 | attendeeUserIds?: string[]; |
| 540 | linkInputs?: CalendarEventLinkInput[]; |
| 541 | recurrenceRule?: CalendarRecurrenceRule | null; |
| 542 | } |
| 543 |
| 544 | /** |
| 545 | * Calendar events list response — shape matches the server's `listCalendarEvents` output. |
| 546 | */ |
| 547 | export type CalendarEventsListResponse = Record<string, unknown>; |
| 548 |
| 549 | /** |
| 550 | * Calendar event detail response — shape matches the server's `getCalendarEventDetail` output. |
| 551 | */ |
| 552 | export type CalendarEventDetailResponse = Record<string, unknown>; |
| 553 |
| 554 | export interface WorkspaceSearchInput { |
| 555 | query: string; |
| 556 | sourceKinds?: Array< |
| 557 | "file" | "task" | "container_message" | "kairo_message" | "app_document" |
| 558 | >; |
| 559 | limit?: number; |
| 560 | cursor?: string; |
| 561 | } |
| 562 |
| 563 | export interface WorkspaceSearchResult { |
| 564 | id: string; |
| 565 | title: string | null; |
| 566 | snippet: string | null; |
| 567 | sourceKind: string; |
| 568 | sourceId: string; |
| 569 | url: string | null; |
| 570 | score: number; |
| 571 | } |
| 572 |
| 573 | export interface WorkspaceSearchResponse { |
| 574 | results: WorkspaceSearchResult[]; |
| 575 | nextCursor: string | null; |
| 576 | } |
| 577 |
| 578 | export interface TaskboardStatusSummary { |
| 579 | id: string; |
| 580 | key: string; |
| 581 | name: string; |
| 582 | color: string; |
| 583 | isDefault: boolean; |
| 584 | isCompleted: boolean; |
| 585 | sortOrder: number; |
| 586 | } |
| 587 |
| 588 | export interface TaskboardSummary { |
| 589 | id: string; |
| 590 | name: string; |
| 591 | driveId: string; |
| 592 | color: string | null; |
| 593 | identifierPrefix: string | null; |
| 594 | description: string | null; |
| 595 | defaultView: string | null; |
| 596 | statuses: TaskboardStatusSummary[]; |
| 597 | createdAt: string; |
| 598 | updatedAt: string; |
| 599 | } |
| 600 |
| 601 | export interface WorkspaceTaskboardsResponse { |
| 602 | taskboards: TaskboardSummary[]; |
| 603 | } |
| 604 |
| 605 | export interface TaskAssignee { |
| 606 | id: string; |
| 607 | firstName: string | null; |
| 608 | lastName: string | null; |
| 609 | avatarUrl: string | null; |
| 610 | email: string; |
| 611 | } |
| 612 |
| 613 | export interface TaskSummary { |
| 614 | id: string; |
| 615 | taskboardId: string; |
| 616 | taskNumber: number; |
| 617 | identifier: string | null; |
| 618 | title: string; |
| 619 | description: string | null; |
| 620 | status: { |
| 621 | id: string; |
| 622 | key: string; |
| 623 | name: string; |
| 624 | color: string; |
| 625 | isCompleted: boolean; |
| 626 | } | null; |
| 627 | priority: string; |
| 628 | labels: string[]; |
| 629 | dueDate: string | null; |
| 630 | assignees: TaskAssignee[]; |
| 631 | isCompleted: boolean; |
| 632 | completedAt: string | null; |
| 633 | createdByUserId: string | null; |
| 634 | createdAt: string; |
| 635 | updatedAt: string; |
| 636 | } |
| 637 |
| 638 | export interface TaskboardTasksResponse { |
| 639 | tasks: TaskSummary[]; |
| 640 | } |
| 641 |
| 642 | export interface ListTaskboardTasksQuery { |
| 643 | q?: string; |
| 644 | statusId?: string; |
| 645 | assigneeUserId?: string; |
| 646 | limit?: number; |
| 647 | } |
| 648 |
| 649 | export interface CreateTaskInput { |
| 650 | title: string; |
| 651 | description?: string; |
| 652 | statusId?: string; |
| 653 | priority?: "none" | "low" | "medium" | "high" | "urgent"; |
| 654 | dueDate?: string | null; |
| 655 | labels?: string[]; |
| 656 | assigneeUserIds?: string[]; |
| 657 | } |
| 658 |
| 659 | export interface CreateTaskResponse { |
| 660 | task: { |
| 661 | id: string; |
| 662 | taskboardId: string; |
| 663 | title: string; |
| 664 | description: string; |
| 665 | statusId: string; |
| 666 | priority: string; |
| 667 | labels: string[]; |
| 668 | dueDate: string | null; |
| 669 | assigneeUserIds: string[]; |
| 670 | createdByUserId: string; |
| 671 | createdAt: string; |
| 672 | updatedAt: string; |
| 673 | }; |
| 674 | } |
| 675 |
| 676 | export interface UpdateTaskInput { |
| 677 | title?: string; |
| 678 | description?: string; |
| 679 | statusId?: string; |
| 680 | priority?: "none" | "low" | "medium" | "high" | "urgent"; |
| 681 | dueDate?: string | null; |
| 682 | labels?: string[]; |
| 683 | assigneeUserIds?: string[]; |
| 684 | } |
| 685 |
| 686 | function joinUrl(baseUrl: string, path: string): string { |
| 687 | return `${baseUrl.replace(/\/+$/, "")}${path}`; |
| 688 | } |
| 689 |
| 690 | function toRegisterAppInput(payload: ColineAppRegistrationPayload) { |
| 691 | const notificationChannels = payload.manifest.notificationChannels.map((channel) => ({ |
| 692 | key: channel.key, |
| 693 | name: channel.name, |
| 694 | defaultDeliveries: [...channel.defaultDeliveries], |
| 695 | defaultPriority: channel.defaultPriority, |
| 696 | ...(channel.description ? { description: channel.description } : {}), |
| 697 | })); |
| 698 |
| 699 | const ui = |
| 700 | payload.manifest.ui.mode || payload.manifest.ui.homePath || payload.manifest.ui.filePath |
| 701 | ? { |
| 702 | ...(payload.manifest.ui.mode |
| 703 | ? { mode: payload.manifest.ui.mode } |
| 704 | : {}), |
| 705 | ...(payload.manifest.ui.homePath |
| 706 | ? { homePath: payload.manifest.ui.homePath } |
| 707 | : {}), |
| 708 | ...(payload.manifest.ui.filePath |
| 709 | ? { filePath: payload.manifest.ui.filePath } |
| 710 | : {}), |
| 711 | } |
| 712 | : undefined; |
| 713 |
| 714 | const manifest = { |
| 715 | key: payload.manifest.key, |
| 716 | name: payload.manifest.name, |
| 717 | permissions: payload.manifest.permissions, |
| 718 | notificationChannels, |
| 719 | hosting: { |
| 720 | mode: payload.manifest.hosting.mode, |
| 721 | baseUrl: payload.manifest.hosting.baseUrl, |
| 722 | }, |
| 723 | ...(ui ? { ui } : {}), |
| 724 | ...(payload.manifest.description |
| 725 | ? { description: payload.manifest.description } |
| 726 | : {}), |
| 727 | ...(payload.manifest.iconUrl ? { iconUrl: payload.manifest.iconUrl } : {}), |
| 728 | ...(payload.manifest.kairo |
| 729 | ? { |
| 730 | kairo: JSON.parse(JSON.stringify(payload.manifest.kairo)) as Record< |
| 731 | string, |
| 732 | unknown |
| 733 | >, |
| 734 | } |
| 735 | : {}), |
| 736 | }; |
| 737 |
| 738 | const fileTypes = payload.fileTypes.map((fileType) => ({ |
| 739 | typeKey: fileType.typeKey, |
| 740 | name: fileType.name, |
| 741 | storage: fileType.storage, |
| 742 | indexable: fileType.indexable, |
| 743 | homeRenderMode: fileType.homeRenderMode, |
| 744 | ...(fileType.description ? { description: fileType.description } : {}), |
| 745 | })); |
| 746 |
| 747 | return { |
| 748 | version: payload.version, |
| 749 | manifest, |
| 750 | fileTypes, |
| 751 | }; |
| 752 | } |
| 753 |
| 754 | export class ColineApiClient { |
| 755 | private readonly baseUrl: string; |
| 756 | private readonly apiKey: string | undefined; |
| 757 | private readonly fetchImpl: typeof fetch; |
| 758 | private readonly defaultHeaders: HeadersInit | undefined; |
| 759 | private readonly appPlatformClient: AppPlatformClient; |
| 760 |
| 761 | constructor(options: ColineApiClientOptions) { |
| 762 | this.baseUrl = options.baseUrl; |
| 763 | this.apiKey = options.apiKey; |
| 764 | this.fetchImpl = options.fetch ?? fetch; |
| 765 | this.defaultHeaders = options.headers; |
| 766 | this.appPlatformClient = createAppPlatformClient(options); |
| 767 | } |
| 768 |
| 769 | private async unwrapGeneratedResponse<T>( |
| 770 | promise: Promise<{ |
| 771 | data?: { data: T }; |
| 772 | error?: ApiErrorPayload; |
| 773 | response: Response; |
| 774 | }>, |
| 775 | ): Promise<T> { |
| 776 | const { data, error, response } = await promise; |
| 777 |
| 778 | if (error) { |
| 779 | throw new ColineApiError({ |
| 780 | message: error.error?.message ?? `Request failed (${response.status}).`, |
| 781 | type: "api", |
| 782 | status: response.status, |
| 783 | code: error.error?.code ?? null, |
| 784 | }); |
| 785 | } |
| 786 |
| 787 | if (data === undefined) { |
| 788 | throw new ColineApiError({ |
| 789 | message: "Invalid API response.", |
| 790 | type: "api", |
| 791 | status: response.status, |
| 792 | }); |
| 793 | } |
| 794 |
| 795 | return data.data; |
| 796 | } |
| 797 |
| 798 | withApiKey(apiKey: string): ColineApiClient { |
| 799 | const options: ColineApiClientOptions = { |
| 800 | baseUrl: this.baseUrl, |
| 801 | apiKey, |
| 802 | fetch: this.fetchImpl, |
| 803 | }; |
| 804 |
| 805 | if (this.defaultHeaders !== undefined) { |
| 806 | options.headers = this.defaultHeaders; |
| 807 | } |
| 808 |
| 809 | return new ColineApiClient(options); |
| 810 | } |
| 811 |
| 812 | withHeaders(headers: HeadersInit): ColineApiClient { |
| 813 | const mergedHeaders = new Headers(this.defaultHeaders); |
| 814 | new Headers(headers).forEach((value, key) => mergedHeaders.set(key, value)); |
| 815 |
| 816 | const options: ColineApiClientOptions = { |
| 817 | baseUrl: this.baseUrl, |
| 818 | fetch: this.fetchImpl, |
| 819 | headers: mergedHeaders, |
| 820 | }; |
| 821 |
| 822 | if (this.apiKey !== undefined) { |
| 823 | options.apiKey = this.apiKey; |
| 824 | } |
| 825 |
| 826 | return new ColineApiClient(options); |
| 827 | } |
| 828 |
| 829 | buildLoginWithColineAuthorizeUrl(input: { |
| 830 | clientId: string; |
| 831 | redirectUri: string; |
| 832 | scope?: string; |
| 833 | state?: string; |
| 834 | codeChallenge?: string; |
| 835 | codeChallengeMethod?: "S256" | "plain"; |
| 836 | }): string { |
| 837 | const url = new URL("/api/v1/oauth/authorize", this.baseUrl); |
| 838 | url.searchParams.set("response_type", "code"); |
| 839 | url.searchParams.set("client_id", input.clientId); |
| 840 | url.searchParams.set("redirect_uri", input.redirectUri); |
| 841 | if (input.scope) { |
| 842 | url.searchParams.set("scope", input.scope); |
| 843 | } |
| 844 | if (input.state) { |
| 845 | url.searchParams.set("state", input.state); |
| 846 | } |
| 847 | if (input.codeChallenge) { |
| 848 | url.searchParams.set("code_challenge", input.codeChallenge); |
| 849 | } |
| 850 | if (input.codeChallengeMethod) { |
| 851 | url.searchParams.set("code_challenge_method", input.codeChallengeMethod); |
| 852 | } |
| 853 | return url.toString(); |
| 854 | } |
| 855 |
| 856 | async listApps(): Promise<{ apps: RegisteredAppRecord[] }> { |
| 857 | return this.unwrapGeneratedResponse( |
| 858 | this.appPlatformClient.GET("/api/v1/apps"), |
| 859 | ); |
| 860 | } |
| 861 |
| 862 | async getApp(appKey: string): Promise<{ app: RegisteredAppDetail }> { |
| 863 | return this.unwrapGeneratedResponse( |
| 864 | this.appPlatformClient.GET("/api/v1/apps/{appKey}", { |
| 865 | params: { path: { appKey } }, |
| 866 | }), |
| 867 | ); |
| 868 | } |
| 869 |
| 870 | async listAppVersions( |
| 871 | appKey: string, |
| 872 | ): Promise<{ versions: RegisteredAppVersionSummary[] }> { |
| 873 | return this.unwrapGeneratedResponse( |
| 874 | this.appPlatformClient.GET("/api/v1/apps/{appKey}/versions", { |
| 875 | params: { path: { appKey } }, |
| 876 | }), |
| 877 | ); |
| 878 | } |
| 879 |
| 880 | async registerApp( |
| 881 | payload: ColineAppRegistrationPayloadInput, |
| 882 | ): Promise<{ appId: string; appKey: string; versionId: string; version: string }> { |
| 883 | const body = toRegisterAppInput(colineAppRegistrationPayloadSchema.parse(payload)); |
| 884 |
| 885 | return this.unwrapGeneratedResponse( |
| 886 | this.appPlatformClient.POST("/api/v1/apps", { |
| 887 | body, |
| 888 | }), |
| 889 | ); |
| 890 | } |
| 891 |
| 892 | async createAppVersion( |
| 893 | appKey: string, |
| 894 | payload: ColineAppRegistrationPayloadInput, |
| 895 | ): Promise<{ appId: string; appKey: string; versionId: string; version: string }> { |
| 896 | const body = toRegisterAppInput(colineAppRegistrationPayloadSchema.parse(payload)); |
| 897 |
| 898 | return this.unwrapGeneratedResponse( |
| 899 | this.appPlatformClient.POST("/api/v1/apps/{appKey}/versions", { |
| 900 | params: { path: { appKey } }, |
| 901 | body, |
| 902 | }), |
| 903 | ); |
| 904 | } |
| 905 |
| 906 | async submitAppVersionForReview( |
| 907 | appKey: string, |
| 908 | versionId: string, |
| 909 | input: SubmitAppVersionForReviewInput = {}, |
| 910 | ): Promise<SubmitAppVersionForReviewResponse> { |
| 911 | return this.unwrapGeneratedResponse( |
| 912 | this.appPlatformClient.POST( |
| 913 | "/api/v1/apps/{appKey}/versions/{versionId}/submit", |
| 914 | { |
| 915 | params: { path: { appKey, versionId } }, |
| 916 | body: { |
| 917 | ...(input.storeListed !== undefined |
| 918 | ? { storeListed: input.storeListed } |
| 919 | : {}), |
| 920 | }, |
| 921 | }, |
| 922 | ), |
| 923 | ); |
| 924 | } |
| 925 |
| 926 | async listWorkspaceApps(workspaceSlug: string): Promise<WorkspaceAppsResponse> { |
| 927 | return this.unwrapGeneratedResponse( |
| 928 | this.appPlatformClient.GET("/api/v1/workspaces/{workspaceSlug}/apps", { |
| 929 | params: { path: { workspaceSlug } }, |
| 930 | }), |
| 931 | ); |
| 932 | } |
| 933 |
| 934 | async installWorkspaceApp( |
| 935 | workspaceSlug: string, |
| 936 | input: InstallWorkspaceAppInput, |
| 937 | ): Promise<InstallWorkspaceAppResponse> { |
| 938 | const grantedPermissions = input.grantedPermissions |
| 939 | ? input.grantedPermissions.map((permission) => |
| 940 | appPermissionSchema.parse(permission), |
| 941 | ) |
| 942 | : undefined; |
| 943 |
| 944 | return this.unwrapGeneratedResponse( |
| 945 | this.appPlatformClient.POST("/api/v1/workspaces/{workspaceSlug}/apps", { |
| 946 | params: { path: { workspaceSlug } }, |
| 947 | body: { |
| 948 | appId: input.appId, |
| 949 | ...(input.pinnedVersionId |
| 950 | ? { pinnedVersionId: input.pinnedVersionId } |
| 951 | : {}), |
| 952 | ...(grantedPermissions ? { grantedPermissions } : {}), |
| 953 | }, |
| 954 | }), |
| 955 | ); |
| 956 | } |
| 957 |
| 958 | async getWorkspaceAppPermissions( |
| 959 | workspaceSlug: string, |
| 960 | appKey: string, |
| 961 | ): Promise<WorkspaceAppPermissionsResponse> { |
| 962 | return this.unwrapGeneratedResponse( |
| 963 | this.appPlatformClient.GET( |
| 964 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/permissions", |
| 965 | { |
| 966 | params: { path: { workspaceSlug, appKey } }, |
| 967 | }, |
| 968 | ), |
| 969 | ); |
| 970 | } |
| 971 |
| 972 | async getWorkspaceInstalledApp( |
| 973 | workspaceSlug: string, |
| 974 | appKey: string, |
| 975 | ): Promise<WorkspaceInstalledAppResponse> { |
| 976 | return this.unwrapGeneratedResponse( |
| 977 | this.appPlatformClient.GET("/api/v1/workspaces/{workspaceSlug}/apps/{appKey}", { |
| 978 | params: { path: { workspaceSlug, appKey } }, |
| 979 | }), |
| 980 | ); |
| 981 | } |
| 982 |
| 983 | async updateWorkspaceAppPermissions( |
| 984 | workspaceSlug: string, |
| 985 | appKey: string, |
| 986 | input: UpdateWorkspaceAppPermissionsInput, |
| 987 | ): Promise<WorkspaceAppPermissionsResponse> { |
| 988 | return this.unwrapGeneratedResponse( |
| 989 | this.appPlatformClient.PUT( |
| 990 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/permissions", |
| 991 | { |
| 992 | params: { path: { workspaceSlug, appKey } }, |
| 993 | body: { |
| 994 | grantedPermissions: input.grantedPermissions.map((permission) => |
| 995 | appPermissionSchema.parse(permission), |
| 996 | ), |
| 997 | }, |
| 998 | }, |
| 999 | ), |
| 1000 | ); |
| 1001 | } |
| 1002 |
| 1003 | async uninstallWorkspaceApp( |
| 1004 | workspaceSlug: string, |
| 1005 | appKey: string, |
| 1006 | ): Promise<{ ok: true }> { |
| 1007 | return this.unwrapGeneratedResponse( |
| 1008 | this.appPlatformClient.DELETE( |
| 1009 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}", |
| 1010 | { |
| 1011 | params: { path: { workspaceSlug, appKey } }, |
| 1012 | }, |
| 1013 | ), |
| 1014 | ); |
| 1015 | } |
| 1016 |
| 1017 | async listWorkspaceAppSecrets( |
| 1018 | workspaceSlug: string, |
| 1019 | appKey: string, |
| 1020 | ): Promise<WorkspaceAppSecretsResponse> { |
| 1021 | return this.unwrapGeneratedResponse( |
| 1022 | this.appPlatformClient.GET( |
| 1023 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/secrets", |
| 1024 | { |
| 1025 | params: { path: { workspaceSlug, appKey } }, |
| 1026 | }, |
| 1027 | ), |
| 1028 | ); |
| 1029 | } |
| 1030 |
| 1031 | async createWorkspaceAppSecret( |
| 1032 | workspaceSlug: string, |
| 1033 | appKey: string, |
| 1034 | input: { key: string; value: string }, |
| 1035 | ): Promise<CreateWorkspaceAppSecretResponse> { |
| 1036 | return this.unwrapGeneratedResponse( |
| 1037 | this.appPlatformClient.POST( |
| 1038 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/secrets", |
| 1039 | { |
| 1040 | params: { path: { workspaceSlug, appKey } }, |
| 1041 | body: input, |
| 1042 | }, |
| 1043 | ), |
| 1044 | ); |
| 1045 | } |
| 1046 |
| 1047 | async deleteWorkspaceAppSecret( |
| 1048 | workspaceSlug: string, |
| 1049 | appKey: string, |
| 1050 | secretId: string, |
| 1051 | ): Promise<{ ok: true }> { |
| 1052 | return this.unwrapGeneratedResponse( |
| 1053 | this.appPlatformClient.DELETE( |
| 1054 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/secrets/{secretId}", |
| 1055 | { |
| 1056 | params: { path: { workspaceSlug, appKey, secretId } }, |
| 1057 | }, |
| 1058 | ), |
| 1059 | ); |
| 1060 | } |
| 1061 |
| 1062 | async listWorkspaceAppOauthConnections( |
| 1063 | workspaceSlug: string, |
| 1064 | appKey: string, |
| 1065 | ): Promise<WorkspaceAppOauthConnectionsResponse> { |
| 1066 | return this.unwrapGeneratedResponse( |
| 1067 | this.appPlatformClient.GET( |
| 1068 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/oauth-connections", |
| 1069 | { |
| 1070 | params: { path: { workspaceSlug, appKey } }, |
| 1071 | }, |
| 1072 | ), |
| 1073 | ); |
| 1074 | } |
| 1075 |
| 1076 | async createWorkspaceAppOauthConnection( |
| 1077 | workspaceSlug: string, |
| 1078 | appKey: string, |
| 1079 | input: { |
| 1080 | providerKey: string; |
| 1081 | externalAccountId?: string | null; |
| 1082 | accessToken: string; |
| 1083 | refreshToken?: string | null; |
| 1084 | scopes: string[]; |
| 1085 | tokenExpiresAt?: string | null; |
| 1086 | metadata?: Record<string, unknown>; |
| 1087 | }, |
| 1088 | ): Promise<CreateWorkspaceAppOauthConnectionResponse> { |
| 1089 | const body: { |
| 1090 | providerKey: string; |
| 1091 | accessToken: string; |
| 1092 | scopes: string[]; |
| 1093 | externalAccountId?: string; |
| 1094 | refreshToken?: string; |
| 1095 | tokenExpiresAt?: string; |
| 1096 | metadata?: Record<string, unknown>; |
| 1097 | } = { |
| 1098 | providerKey: input.providerKey, |
| 1099 | accessToken: input.accessToken, |
| 1100 | scopes: input.scopes, |
| 1101 | }; |
| 1102 |
| 1103 | if (input.externalAccountId) { |
| 1104 | body.externalAccountId = input.externalAccountId; |
| 1105 | } |
| 1106 | if (input.refreshToken) { |
| 1107 | body.refreshToken = input.refreshToken; |
| 1108 | } |
| 1109 | if (input.tokenExpiresAt) { |
| 1110 | body.tokenExpiresAt = input.tokenExpiresAt; |
| 1111 | } |
| 1112 | if (input.metadata) { |
| 1113 | body.metadata = input.metadata; |
| 1114 | } |
| 1115 |
| 1116 | return this.unwrapGeneratedResponse( |
| 1117 | this.appPlatformClient.POST( |
| 1118 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/oauth-connections", |
| 1119 | { |
| 1120 | params: { path: { workspaceSlug, appKey } }, |
| 1121 | body, |
| 1122 | }, |
| 1123 | ), |
| 1124 | ); |
| 1125 | } |
| 1126 |
| 1127 | async deleteWorkspaceAppOauthConnection( |
| 1128 | workspaceSlug: string, |
| 1129 | appKey: string, |
| 1130 | connectionId: string, |
| 1131 | ): Promise<{ ok: true }> { |
| 1132 | return this.unwrapGeneratedResponse( |
| 1133 | this.appPlatformClient.DELETE( |
| 1134 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/oauth-connections/{connectionId}", |
| 1135 | { |
| 1136 | params: { path: { workspaceSlug, appKey, connectionId } }, |
| 1137 | }, |
| 1138 | ), |
| 1139 | ); |
| 1140 | } |
| 1141 |
| 1142 | async listWorkspaceAppDeliveries( |
| 1143 | workspaceSlug: string, |
| 1144 | appKey: string, |
| 1145 | ): Promise<WorkspaceAppDeliveriesResponse> { |
| 1146 | return this.unwrapGeneratedResponse( |
| 1147 | this.appPlatformClient.GET( |
| 1148 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/deliveries", |
| 1149 | { |
| 1150 | params: { path: { workspaceSlug, appKey } }, |
| 1151 | }, |
| 1152 | ), |
| 1153 | ); |
| 1154 | } |
| 1155 |
| 1156 | async sendWorkspaceAppTestDelivery( |
| 1157 | workspaceSlug: string, |
| 1158 | appKey: string, |
| 1159 | input: { |
| 1160 | eventType: string; |
| 1161 | targetUrl?: string; |
| 1162 | payload: Record<string, unknown>; |
| 1163 | }, |
| 1164 | ): Promise<SendWorkspaceAppTestDeliveryResponse> { |
| 1165 | return this.unwrapGeneratedResponse( |
| 1166 | this.appPlatformClient.POST( |
| 1167 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/deliveries", |
| 1168 | { |
| 1169 | params: { path: { workspaceSlug, appKey } }, |
| 1170 | body: input, |
| 1171 | }, |
| 1172 | ), |
| 1173 | ); |
| 1174 | } |
| 1175 |
| 1176 | async replayWorkspaceAppDelivery( |
| 1177 | workspaceSlug: string, |
| 1178 | appKey: string, |
| 1179 | deliveryId: string, |
| 1180 | ): Promise<SendWorkspaceAppTestDeliveryResponse> { |
| 1181 | return this.unwrapGeneratedResponse( |
| 1182 | this.appPlatformClient.POST( |
| 1183 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/deliveries/{deliveryId}/replay", |
| 1184 | { |
| 1185 | params: { path: { workspaceSlug, appKey, deliveryId } }, |
| 1186 | }, |
| 1187 | ), |
| 1188 | ); |
| 1189 | } |
| 1190 |
| 1191 | async emitAppAmbientEvents( |
| 1192 | workspaceSlug: string, |
| 1193 | appKey: string, |
| 1194 | input: EmitAmbientEventsInputInput, |
| 1195 | ): Promise<EmitAppAmbientEventsResponse> { |
| 1196 | const parsed = emitAmbientEventsInputSchema.parse(input); |
| 1197 | const body = { |
| 1198 | events: parsed.events.map((event) => ({ |
| 1199 | sourceKind: event.sourceKind, |
| 1200 | action: event.action, |
| 1201 | entityType: event.entityType, |
| 1202 | entityId: event.entityId, |
| 1203 | dedupeKey: event.dedupeKey, |
| 1204 | payload: event.payload, |
| 1205 | metadata: event.metadata, |
| 1206 | schemaVersion: event.schemaVersion, |
| 1207 | ...(event.actorUserId ? { actorUserId: event.actorUserId } : {}), |
| 1208 | ...(event.containerType ? { containerType: event.containerType } : {}), |
| 1209 | ...(event.containerId ? { containerId: event.containerId } : {}), |
| 1210 | ...(event.occurredAt |
| 1211 | ? { occurredAt: event.occurredAt.toISOString() } |
| 1212 | : {}), |
| 1213 | })), |
| 1214 | }; |
| 1215 |
| 1216 | return this.unwrapGeneratedResponse( |
| 1217 | this.appPlatformClient.POST( |
| 1218 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/ambient/events", |
| 1219 | { |
| 1220 | params: { path: { workspaceSlug, appKey } }, |
| 1221 | body, |
| 1222 | }, |
| 1223 | ), |
| 1224 | ); |
| 1225 | } |
| 1226 |
| 1227 | async createAppNotification( |
| 1228 | workspaceSlug: string, |
| 1229 | appKey: string, |
| 1230 | input: CreateNotificationInputInput, |
| 1231 | ): Promise<OkResponse> { |
| 1232 | const parsed = createNotificationInputSchema.parse(input); |
| 1233 | const body = { |
| 1234 | channelKey: parsed.channelKey, |
| 1235 | typeKey: parsed.typeKey, |
| 1236 | recipients: parsed.recipients.map((recipient) => ({ |
| 1237 | userId: recipient.userId, |
| 1238 | })), |
| 1239 | title: parsed.title, |
| 1240 | priority: parsed.priority, |
| 1241 | metadata: parsed.metadata, |
| 1242 | ...(parsed.body ? { body: parsed.body } : {}), |
| 1243 | ...(parsed.targetUrl ? { targetUrl: parsed.targetUrl } : {}), |
| 1244 | ...(parsed.icon ? { icon: parsed.icon } : {}), |
| 1245 | ...(parsed.dedupeKey ? { dedupeKey: parsed.dedupeKey } : {}), |
| 1246 | }; |
| 1247 |
| 1248 | return this.unwrapGeneratedResponse( |
| 1249 | this.appPlatformClient.POST( |
| 1250 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/notifications", |
| 1251 | { |
| 1252 | params: { path: { workspaceSlug, appKey } }, |
| 1253 | body, |
| 1254 | }, |
| 1255 | ), |
| 1256 | ); |
| 1257 | } |
| 1258 |
| 1259 | async upsertAppIndexDocuments( |
| 1260 | workspaceSlug: string, |
| 1261 | appKey: string, |
| 1262 | input: BatchUpsertAppIndexDocumentsInput, |
| 1263 | ): Promise<UpsertAppIndexDocumentsResponse> { |
| 1264 | const parsed = batchUpsertAppIndexDocumentsSchema.parse(input); |
| 1265 | const body = { |
| 1266 | documents: parsed.documents.map((document) => ({ |
| 1267 | documentKey: document.documentKey, |
| 1268 | documentType: document.documentType, |
| 1269 | title: document.title, |
| 1270 | body: document.body, |
| 1271 | metadata: document.metadata, |
| 1272 | visibilityMode: document.visibilityMode, |
| 1273 | visibility: document.visibility.map((grant) => ({ |
| 1274 | subjectType: grant.subjectType, |
| 1275 | subjectId: grant.subjectId, |
| 1276 | })), |
| 1277 | ...(document.fileId ? { fileId: document.fileId } : {}), |
| 1278 | ...(document.url ? { url: document.url } : {}), |
| 1279 | })), |
| 1280 | }; |
| 1281 |
| 1282 | return this.unwrapGeneratedResponse( |
| 1283 | this.appPlatformClient.POST( |
| 1284 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/index-documents", |
| 1285 | { |
| 1286 | params: { path: { workspaceSlug, appKey } }, |
| 1287 | body, |
| 1288 | }, |
| 1289 | ), |
| 1290 | ); |
| 1291 | } |
| 1292 |
| 1293 | async deleteAppIndexDocuments( |
| 1294 | workspaceSlug: string, |
| 1295 | appKey: string, |
| 1296 | input: BatchDeleteAppIndexDocumentsInput, |
| 1297 | ): Promise<DeleteAppIndexDocumentsResponse> { |
| 1298 | const body = batchDeleteAppIndexDocumentsSchema.parse(input); |
| 1299 |
| 1300 | return this.unwrapGeneratedResponse( |
| 1301 | this.appPlatformClient.DELETE( |
| 1302 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/index-documents", |
| 1303 | { |
| 1304 | params: { path: { workspaceSlug, appKey } }, |
| 1305 | body, |
| 1306 | }, |
| 1307 | ), |
| 1308 | ); |
| 1309 | } |
| 1310 |
| 1311 | async listAppFiles( |
| 1312 | workspaceSlug: string, |
| 1313 | appKey: string, |
| 1314 | query?: { |
| 1315 | driveId?: string; |
| 1316 | typeKey?: string; |
| 1317 | limit?: number; |
| 1318 | }, |
| 1319 | ): Promise<AppFilesListResponse> { |
| 1320 | return this.unwrapGeneratedResponse( |
| 1321 | this.appPlatformClient.GET( |
| 1322 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files", |
| 1323 | { |
| 1324 | params: { |
| 1325 | path: { workspaceSlug, appKey }, |
| 1326 | ...(query |
| 1327 | ? { |
| 1328 | query: { |
| 1329 | ...(query.driveId ? { driveId: query.driveId } : {}), |
| 1330 | ...(query.typeKey ? { typeKey: query.typeKey } : {}), |
| 1331 | ...(query.limit !== undefined ? { limit: query.limit } : {}), |
| 1332 | }, |
| 1333 | } |
| 1334 | : {}), |
| 1335 | }, |
| 1336 | }, |
| 1337 | ), |
| 1338 | ); |
| 1339 | } |
| 1340 |
| 1341 | async createAppFile( |
| 1342 | workspaceSlug: string, |
| 1343 | appKey: string, |
| 1344 | input: CreateAppFileInput, |
| 1345 | ): Promise<CreateAppFileResponse> { |
| 1346 | return this.unwrapGeneratedResponse( |
| 1347 | this.appPlatformClient.POST( |
| 1348 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files", |
| 1349 | { |
| 1350 | params: { path: { workspaceSlug, appKey } }, |
| 1351 | body: { |
| 1352 | name: input.name, |
| 1353 | ...(input.typeKey ? { typeKey: input.typeKey } : {}), |
| 1354 | ...(input.driveId ? { driveId: input.driveId } : {}), |
| 1355 | ...(input.parentId !== undefined ? { parentId: input.parentId } : {}), |
| 1356 | ...(input.document ? { document: input.document } : {}), |
| 1357 | }, |
| 1358 | }, |
| 1359 | ), |
| 1360 | ); |
| 1361 | } |
| 1362 |
| 1363 | async executeAppAction( |
| 1364 | workspaceSlug: string, |
| 1365 | appKey: string, |
| 1366 | input: ExecuteAppActionInput, |
| 1367 | ): Promise<ExecuteAppActionResponse> { |
| 1368 | return this.unwrapGeneratedResponse( |
| 1369 | this.appPlatformClient.POST( |
| 1370 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/actions", |
| 1371 | { |
| 1372 | params: { path: { workspaceSlug, appKey } }, |
| 1373 | body: { |
| 1374 | action: { |
| 1375 | type: input.action.type, |
| 1376 | ...(input.action.payload ? { payload: input.action.payload } : {}), |
| 1377 | }, |
| 1378 | ...(input.fileId !== undefined ? { fileId: input.fileId } : {}), |
| 1379 | }, |
| 1380 | }, |
| 1381 | ), |
| 1382 | ); |
| 1383 | } |
| 1384 |
| 1385 | async getAppFileDocument( |
| 1386 | workspaceSlug: string, |
| 1387 | appKey: string, |
| 1388 | fileId: string, |
| 1389 | ): Promise<AppFileDocumentResponse> { |
| 1390 | return this.unwrapGeneratedResponse( |
| 1391 | this.appPlatformClient.GET( |
| 1392 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files/{fileId}", |
| 1393 | { |
| 1394 | params: { path: { workspaceSlug, appKey, fileId } }, |
| 1395 | }, |
| 1396 | ), |
| 1397 | ); |
| 1398 | } |
| 1399 |
| 1400 | async updateAppFileDocument( |
| 1401 | workspaceSlug: string, |
| 1402 | appKey: string, |
| 1403 | fileId: string, |
| 1404 | document: Record<string, unknown>, |
| 1405 | ): Promise<AppFileDocumentUpdateResponse> { |
| 1406 | return this.unwrapGeneratedResponse( |
| 1407 | this.appPlatformClient.PATCH( |
| 1408 | "/api/v1/workspaces/{workspaceSlug}/apps/{appKey}/files/{fileId}", |
| 1409 | { |
| 1410 | params: { path: { workspaceSlug, appKey, fileId } }, |
| 1411 | body: { document }, |
| 1412 | }, |
| 1413 | ), |
| 1414 | ); |
| 1415 | } |
| 1416 |
| 1417 | async listTabModels(): Promise<TabModelsResponse> { |
| 1418 | return this.unwrapGeneratedResponse( |
| 1419 | this.appPlatformClient.GET("/api/v1/tab/models"), |
| 1420 | ); |
| 1421 | } |
| 1422 |
| 1423 | async createTabChatCompletion(input: { |
| 1424 | model: string; |
| 1425 | stream?: boolean; |
| 1426 | tab_context: Record<string, unknown>; |
| 1427 | messages?: Array<{ role?: string; content?: string }>; |
| 1428 | }): Promise<TabChatCompletionResponse> { |
| 1429 | return this.unwrapGeneratedResponse( |
| 1430 | this.appPlatformClient.POST("/api/v1/tab/chat/completions", { |
| 1431 | body: input, |
| 1432 | }), |
| 1433 | ); |
| 1434 | } |
| 1435 |
| 1436 | async exchangeOAuthCode(input: { |
| 1437 | clientId: string; |
| 1438 | clientSecret: string; |
| 1439 | code: string; |
| 1440 | redirectUri: string; |
| 1441 | codeVerifier?: string; |
| 1442 | }): Promise<OAuthTokenResponse> { |
| 1443 | const response = await this.fetchImpl(joinUrl(this.baseUrl, "/api/v1/oauth/token"), { |
| 1444 | method: "POST", |
| 1445 | headers: { |
| 1446 | "Content-Type": "application/json", |
| 1447 | }, |
| 1448 | body: JSON.stringify({ |
| 1449 | grant_type: "authorization_code", |
| 1450 | client_id: input.clientId, |
| 1451 | client_secret: input.clientSecret, |
| 1452 | code: input.code, |
| 1453 | redirect_uri: input.redirectUri, |
| 1454 | ...(input.codeVerifier ? { code_verifier: input.codeVerifier } : {}), |
| 1455 | }), |
| 1456 | }); |
| 1457 |
| 1458 | return parseJsonResponse<OAuthTokenResponse>(response); |
| 1459 | } |
| 1460 |
| 1461 | async getOAuthUserInfo(accessToken: string): Promise<OAuthUserInfoResponse> { |
| 1462 | const response = await this.fetchImpl(joinUrl(this.baseUrl, "/api/v1/oauth/userinfo"), { |
| 1463 | method: "GET", |
| 1464 | headers: { |
| 1465 | Authorization: `Bearer ${accessToken}`, |
| 1466 | }, |
| 1467 | }); |
| 1468 |
| 1469 | return parseJsonResponse<OAuthUserInfoResponse>(response); |
| 1470 | } |
| 1471 |
| 1472 | // --------------------------------------------------------------------------- |
| 1473 | // Core Platform API — internal fetch helper |
| 1474 | // --------------------------------------------------------------------------- |
| 1475 |
| 1476 | private async coreRequest<T>( |
| 1477 | method: string, |
| 1478 | path: string, |
| 1479 | body?: unknown, |
| 1480 | ): Promise<T> { |
| 1481 | const headers: Record<string, string> = {}; |
| 1482 | if (this.apiKey) { |
| 1483 | headers["Authorization"] = `Bearer ${this.apiKey}`; |
| 1484 | } |
| 1485 | if (body !== undefined) { |
| 1486 | headers["Content-Type"] = "application/json"; |
| 1487 | } |
| 1488 | if (this.defaultHeaders) { |
| 1489 | new Headers(this.defaultHeaders).forEach((v, k) => { |
| 1490 | headers[k] = v; |
| 1491 | }); |
| 1492 | } |
| 1493 |
| 1494 | const response = await this.fetchImpl(joinUrl(this.baseUrl, path), { |
| 1495 | method, |
| 1496 | headers, |
| 1497 | ...(body !== undefined ? { body: JSON.stringify(body) } : {}), |
| 1498 | }); |
| 1499 |
| 1500 | if (!response.ok) { |
| 1501 | const payload = (await response.json().catch(() => null)) as ApiErrorPayload | null; |
| 1502 | throw new ColineApiError({ |
| 1503 | message: |
| 1504 | payload?.error?.message ?? `Request failed (${response.status}).`, |
| 1505 | type: "api", |
| 1506 | status: response.status, |
| 1507 | code: payload?.error?.code ?? null, |
| 1508 | }); |
| 1509 | } |
| 1510 |
| 1511 | const json = (await response.json().catch(() => null)) as { |
| 1512 | data: T; |
| 1513 | } | null; |
| 1514 |
| 1515 | if (!json || !("data" in json)) { |
| 1516 | throw new ColineApiError({ |
| 1517 | message: "Invalid API response.", |
| 1518 | type: "api", |
| 1519 | status: response.status, |
| 1520 | }); |
| 1521 | } |
| 1522 |
| 1523 | return json.data; |
| 1524 | } |
| 1525 |
| 1526 | // --------------------------------------------------------------------------- |
| 1527 | // Core Platform API — Workspace Members |
| 1528 | // --------------------------------------------------------------------------- |
| 1529 |
| 1530 | async listWorkspaceMembers( |
| 1531 | workspaceId: string, |
| 1532 | ): Promise<WorkspaceMembersResponse> { |
| 1533 | return this.coreRequest<WorkspaceMembersResponse>( |
| 1534 | "GET", |
| 1535 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/members`, |
| 1536 | ); |
| 1537 | } |
| 1538 |
| 1539 | // --------------------------------------------------------------------------- |
| 1540 | // Core Platform API — Notes |
| 1541 | // --------------------------------------------------------------------------- |
| 1542 |
| 1543 | async listWorkspaceNotes( |
| 1544 | workspaceId: string, |
| 1545 | query?: ListWorkspaceNotesQuery, |
| 1546 | ): Promise<WorkspaceNotesListResponse> { |
| 1547 | const params = new URLSearchParams(); |
| 1548 | if (query?.q) params.set("q", query.q); |
| 1549 | if (query?.limit !== undefined) params.set("limit", String(query.limit)); |
| 1550 | if (query?.cursor) params.set("cursor", query.cursor); |
| 1551 | const qs = params.toString(); |
| 1552 | return this.coreRequest<WorkspaceNotesListResponse>( |
| 1553 | "GET", |
| 1554 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes${qs ? `?${qs}` : ""}`, |
| 1555 | ); |
| 1556 | } |
| 1557 |
| 1558 | async createWorkspaceNote( |
| 1559 | workspaceId: string, |
| 1560 | input: CreateWorkspaceNoteInput, |
| 1561 | ): Promise<WorkspaceNoteResponse> { |
| 1562 | return this.coreRequest<WorkspaceNoteResponse>( |
| 1563 | "POST", |
| 1564 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes`, |
| 1565 | { |
| 1566 | ...(input.title !== undefined ? { title: input.title } : {}), |
| 1567 | ...(input.body !== undefined ? { body: input.body } : {}), |
| 1568 | ...(input.blocks !== undefined ? { blocks: input.blocks } : {}), |
| 1569 | ...(input.driveId !== undefined ? { driveId: input.driveId } : {}), |
| 1570 | ...(input.parentId !== undefined ? { parentId: input.parentId } : {}), |
| 1571 | }, |
| 1572 | ); |
| 1573 | } |
| 1574 |
| 1575 | async getWorkspaceNote( |
| 1576 | workspaceId: string, |
| 1577 | noteId: string, |
| 1578 | ): Promise<WorkspaceNoteDetailResponse> { |
| 1579 | return this.coreRequest<WorkspaceNoteDetailResponse>( |
| 1580 | "GET", |
| 1581 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes/${encodeURIComponent(noteId)}`, |
| 1582 | ); |
| 1583 | } |
| 1584 |
| 1585 | async updateWorkspaceNote( |
| 1586 | workspaceId: string, |
| 1587 | noteId: string, |
| 1588 | input: UpdateWorkspaceNoteInput, |
| 1589 | ): Promise<WorkspaceNoteResponse> { |
| 1590 | return this.coreRequest<WorkspaceNoteResponse>( |
| 1591 | "PUT", |
| 1592 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes/${encodeURIComponent(noteId)}`, |
| 1593 | input, |
| 1594 | ); |
| 1595 | } |
| 1596 |
| 1597 | async deleteWorkspaceNote( |
| 1598 | workspaceId: string, |
| 1599 | noteId: string, |
| 1600 | ): Promise<{ ok: true }> { |
| 1601 | return this.coreRequest<{ ok: true }>( |
| 1602 | "DELETE", |
| 1603 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/notes/${encodeURIComponent(noteId)}`, |
| 1604 | ); |
| 1605 | } |
| 1606 |
| 1607 | // --------------------------------------------------------------------------- |
| 1608 | // Core Platform API — Docs |
| 1609 | // --------------------------------------------------------------------------- |
| 1610 |
| 1611 | async listWorkspaceDocs( |
| 1612 | workspaceId: string, |
| 1613 | query?: ListWorkspaceDocsQuery, |
| 1614 | ): Promise<WorkspaceDocsListResponse> { |
| 1615 | const params = new URLSearchParams(); |
| 1616 | if (query?.q) params.set("q", query.q); |
| 1617 | if (query?.limit !== undefined) params.set("limit", String(query.limit)); |
| 1618 | if (query?.cursor) params.set("cursor", query.cursor); |
| 1619 | const qs = params.toString(); |
| 1620 | return this.coreRequest<WorkspaceDocsListResponse>( |
| 1621 | "GET", |
| 1622 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs${qs ? `?${qs}` : ""}`, |
| 1623 | ); |
| 1624 | } |
| 1625 |
| 1626 | async createWorkspaceDoc( |
| 1627 | workspaceId: string, |
| 1628 | input: CreateWorkspaceDocInput, |
| 1629 | ): Promise<WorkspaceDocResponse> { |
| 1630 | return this.coreRequest<WorkspaceDocResponse>( |
| 1631 | "POST", |
| 1632 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs`, |
| 1633 | { |
| 1634 | ...(input.title !== undefined ? { title: input.title } : {}), |
| 1635 | ...(input.content !== undefined ? { content: input.content } : {}), |
| 1636 | ...(input.layout !== undefined ? { layout: input.layout } : {}), |
| 1637 | ...(input.driveId !== undefined ? { driveId: input.driveId } : {}), |
| 1638 | ...(input.parentId !== undefined ? { parentId: input.parentId } : {}), |
| 1639 | }, |
| 1640 | ); |
| 1641 | } |
| 1642 |
| 1643 | async getWorkspaceDoc( |
| 1644 | workspaceId: string, |
| 1645 | docId: string, |
| 1646 | ): Promise<WorkspaceDocDetailResponse> { |
| 1647 | return this.coreRequest<WorkspaceDocDetailResponse>( |
| 1648 | "GET", |
| 1649 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs/${encodeURIComponent(docId)}`, |
| 1650 | ); |
| 1651 | } |
| 1652 |
| 1653 | async updateWorkspaceDoc( |
| 1654 | workspaceId: string, |
| 1655 | docId: string, |
| 1656 | input: UpdateWorkspaceDocInput, |
| 1657 | ): Promise<WorkspaceDocDetailResponse> { |
| 1658 | return this.coreRequest<WorkspaceDocDetailResponse>( |
| 1659 | "PATCH", |
| 1660 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs/${encodeURIComponent(docId)}`, |
| 1661 | input, |
| 1662 | ); |
| 1663 | } |
| 1664 |
| 1665 | async deleteWorkspaceDoc( |
| 1666 | workspaceId: string, |
| 1667 | docId: string, |
| 1668 | ): Promise<{ ok: true }> { |
| 1669 | return this.coreRequest<{ ok: true }>( |
| 1670 | "DELETE", |
| 1671 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/docs/${encodeURIComponent(docId)}`, |
| 1672 | ); |
| 1673 | } |
| 1674 |
| 1675 | // --------------------------------------------------------------------------- |
| 1676 | // Core Platform API — Drives |
| 1677 | // --------------------------------------------------------------------------- |
| 1678 |
| 1679 | async listWorkspaceDrives( |
| 1680 | workspaceId: string, |
| 1681 | ): Promise<WorkspaceDrivesListResponse> { |
| 1682 | return this.coreRequest<WorkspaceDrivesListResponse>( |
| 1683 | "GET", |
| 1684 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/drives`, |
| 1685 | ); |
| 1686 | } |
| 1687 |
| 1688 | // --------------------------------------------------------------------------- |
| 1689 | // Core Platform API — Files |
| 1690 | // --------------------------------------------------------------------------- |
| 1691 |
| 1692 | async listDriveFiles( |
| 1693 | workspaceId: string, |
| 1694 | driveId: string, |
| 1695 | query?: ListDriveFilesQuery, |
| 1696 | ): Promise<DriveFilesListResponse> { |
| 1697 | const params = new URLSearchParams(); |
| 1698 | if (query?.parentId) params.set("parentId", query.parentId); |
| 1699 | if (query?.fileType) params.set("fileType", query.fileType); |
| 1700 | if (query?.trashed !== undefined) params.set("trashed", String(query.trashed)); |
| 1701 | if (query?.limit !== undefined) params.set("limit", String(query.limit)); |
| 1702 | if (query?.cursor) params.set("cursor", query.cursor); |
| 1703 | const qs = params.toString(); |
| 1704 | return this.coreRequest<DriveFilesListResponse>( |
| 1705 | "GET", |
| 1706 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/drives/${encodeURIComponent(driveId)}/files${qs ? `?${qs}` : ""}`, |
| 1707 | ); |
| 1708 | } |
| 1709 |
| 1710 | async getFile( |
| 1711 | workspaceId: string, |
| 1712 | fileId: string, |
| 1713 | ): Promise<FileDetailResponse> { |
| 1714 | return this.coreRequest<FileDetailResponse>( |
| 1715 | "GET", |
| 1716 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/files/${encodeURIComponent(fileId)}`, |
| 1717 | ); |
| 1718 | } |
| 1719 |
| 1720 | async updateFile( |
| 1721 | workspaceId: string, |
| 1722 | fileId: string, |
| 1723 | input: UpdateFileInput, |
| 1724 | ): Promise<FileDetailResponse> { |
| 1725 | return this.coreRequest<FileDetailResponse>( |
| 1726 | "PATCH", |
| 1727 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/files/${encodeURIComponent(fileId)}`, |
| 1728 | input, |
| 1729 | ); |
| 1730 | } |
| 1731 |
| 1732 | async deleteFile( |
| 1733 | workspaceId: string, |
| 1734 | fileId: string, |
| 1735 | ): Promise<{ ok: true }> { |
| 1736 | return this.coreRequest<{ ok: true }>( |
| 1737 | "DELETE", |
| 1738 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/files/${encodeURIComponent(fileId)}`, |
| 1739 | ); |
| 1740 | } |
| 1741 |
| 1742 | // --------------------------------------------------------------------------- |
| 1743 | // Core Platform API — Channels |
| 1744 | // --------------------------------------------------------------------------- |
| 1745 |
| 1746 | async listWorkspaceChannels( |
| 1747 | workspaceId: string, |
| 1748 | ): Promise<ChannelListResponse> { |
| 1749 | return this.coreRequest<ChannelListResponse>( |
| 1750 | "GET", |
| 1751 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/channels`, |
| 1752 | ); |
| 1753 | } |
| 1754 |
| 1755 | async listChannelMessages( |
| 1756 | workspaceId: string, |
| 1757 | channelId: string, |
| 1758 | options?: { limit?: number; cursor?: string }, |
| 1759 | ): Promise<MessagesListResponse> { |
| 1760 | const params = new URLSearchParams(); |
| 1761 | if (options?.limit !== undefined) params.set("limit", String(options.limit)); |
| 1762 | if (options?.cursor) params.set("cursor", options.cursor); |
| 1763 | const qs = params.toString(); |
| 1764 | return this.coreRequest<MessagesListResponse>( |
| 1765 | "GET", |
| 1766 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/channels/${encodeURIComponent(channelId)}/messages${qs ? `?${qs}` : ""}`, |
| 1767 | ); |
| 1768 | } |
| 1769 |
| 1770 | // --------------------------------------------------------------------------- |
| 1771 | // Core Platform API — Direct Messages |
| 1772 | // --------------------------------------------------------------------------- |
| 1773 |
| 1774 | async listWorkspaceDms( |
| 1775 | workspaceId: string, |
| 1776 | ): Promise<DmListResponse> { |
| 1777 | return this.coreRequest<DmListResponse>( |
| 1778 | "GET", |
| 1779 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/dms`, |
| 1780 | ); |
| 1781 | } |
| 1782 |
| 1783 | async listDmMessages( |
| 1784 | workspaceId: string, |
| 1785 | dmId: string, |
| 1786 | options?: { limit?: number; cursor?: string }, |
| 1787 | ): Promise<MessagesListResponse> { |
| 1788 | const params = new URLSearchParams(); |
| 1789 | if (options?.limit !== undefined) params.set("limit", String(options.limit)); |
| 1790 | if (options?.cursor) params.set("cursor", options.cursor); |
| 1791 | const qs = params.toString(); |
| 1792 | return this.coreRequest<MessagesListResponse>( |
| 1793 | "GET", |
| 1794 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/dms/${encodeURIComponent(dmId)}/messages${qs ? `?${qs}` : ""}`, |
| 1795 | ); |
| 1796 | } |
| 1797 |
| 1798 | // --------------------------------------------------------------------------- |
| 1799 | // Core Platform API — Calendar Events |
| 1800 | // --------------------------------------------------------------------------- |
| 1801 |
| 1802 | async listCalendarEvents( |
| 1803 | workspaceId: string, |
| 1804 | range: { start: string; end: string }, |
| 1805 | ): Promise<CalendarEventsListResponse> { |
| 1806 | const params = new URLSearchParams({ |
| 1807 | start: range.start, |
| 1808 | end: range.end, |
| 1809 | }); |
| 1810 | return this.coreRequest<CalendarEventsListResponse>( |
| 1811 | "GET", |
| 1812 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events?${params}`, |
| 1813 | ); |
| 1814 | } |
| 1815 |
| 1816 | async createCalendarEvent( |
| 1817 | workspaceId: string, |
| 1818 | input: CreateCalendarEventInput, |
| 1819 | ): Promise<CalendarEventDetailResponse> { |
| 1820 | return this.coreRequest<CalendarEventDetailResponse>( |
| 1821 | "POST", |
| 1822 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events`, |
| 1823 | input, |
| 1824 | ); |
| 1825 | } |
| 1826 |
| 1827 | async getCalendarEvent( |
| 1828 | workspaceId: string, |
| 1829 | eventId: string, |
| 1830 | ): Promise<CalendarEventDetailResponse> { |
| 1831 | return this.coreRequest<CalendarEventDetailResponse>( |
| 1832 | "GET", |
| 1833 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events/${encodeURIComponent(eventId)}`, |
| 1834 | ); |
| 1835 | } |
| 1836 |
| 1837 | async updateCalendarEvent( |
| 1838 | workspaceId: string, |
| 1839 | eventId: string, |
| 1840 | input: UpdateCalendarEventInput, |
| 1841 | ): Promise<CalendarEventDetailResponse> { |
| 1842 | return this.coreRequest<CalendarEventDetailResponse>( |
| 1843 | "PATCH", |
| 1844 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events/${encodeURIComponent(eventId)}`, |
| 1845 | input, |
| 1846 | ); |
| 1847 | } |
| 1848 |
| 1849 | async deleteCalendarEvent( |
| 1850 | workspaceId: string, |
| 1851 | eventId: string, |
| 1852 | ): Promise<{ ok: true }> { |
| 1853 | return this.coreRequest<{ ok: true }>( |
| 1854 | "DELETE", |
| 1855 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/calendar/events/${encodeURIComponent(eventId)}`, |
| 1856 | ); |
| 1857 | } |
| 1858 |
| 1859 | // --------------------------------------------------------------------------- |
| 1860 | // Core Platform API — Search |
| 1861 | // --------------------------------------------------------------------------- |
| 1862 |
| 1863 | async searchWorkspace( |
| 1864 | workspaceId: string, |
| 1865 | input: WorkspaceSearchInput, |
| 1866 | ): Promise<WorkspaceSearchResponse> { |
| 1867 | return this.coreRequest<WorkspaceSearchResponse>( |
| 1868 | "POST", |
| 1869 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/search`, |
| 1870 | input, |
| 1871 | ); |
| 1872 | } |
| 1873 |
| 1874 | // --------------------------------------------------------------------------- |
| 1875 | // Core Platform API — Taskboards |
| 1876 | // --------------------------------------------------------------------------- |
| 1877 |
| 1878 | async listWorkspaceTaskboards( |
| 1879 | workspaceId: string, |
| 1880 | ): Promise<WorkspaceTaskboardsResponse> { |
| 1881 | return this.coreRequest<WorkspaceTaskboardsResponse>( |
| 1882 | "GET", |
| 1883 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards`, |
| 1884 | ); |
| 1885 | } |
| 1886 |
| 1887 | // --------------------------------------------------------------------------- |
| 1888 | // Core Platform API — Tasks |
| 1889 | // --------------------------------------------------------------------------- |
| 1890 |
| 1891 | async listTaskboardTasks( |
| 1892 | workspaceId: string, |
| 1893 | taskboardId: string, |
| 1894 | query?: ListTaskboardTasksQuery, |
| 1895 | ): Promise<TaskboardTasksResponse> { |
| 1896 | const params = new URLSearchParams(); |
| 1897 | if (query?.q) params.set("q", query.q); |
| 1898 | if (query?.statusId) params.set("statusId", query.statusId); |
| 1899 | if (query?.assigneeUserId) params.set("assigneeUserId", query.assigneeUserId); |
| 1900 | if (query?.limit !== undefined) params.set("limit", String(query.limit)); |
| 1901 | const qs = params.toString(); |
| 1902 | return this.coreRequest<TaskboardTasksResponse>( |
| 1903 | "GET", |
| 1904 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards/${encodeURIComponent(taskboardId)}/tasks${qs ? `?${qs}` : ""}`, |
| 1905 | ); |
| 1906 | } |
| 1907 |
| 1908 | async createTaskboardTask( |
| 1909 | workspaceId: string, |
| 1910 | taskboardId: string, |
| 1911 | input: CreateTaskInput, |
| 1912 | ): Promise<CreateTaskResponse> { |
| 1913 | return this.coreRequest<CreateTaskResponse>( |
| 1914 | "POST", |
| 1915 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards/${encodeURIComponent(taskboardId)}/tasks`, |
| 1916 | input, |
| 1917 | ); |
| 1918 | } |
| 1919 |
| 1920 | async updateTaskboardTask( |
| 1921 | workspaceId: string, |
| 1922 | taskboardId: string, |
| 1923 | taskId: string, |
| 1924 | input: UpdateTaskInput, |
| 1925 | ): Promise<{ ok: true }> { |
| 1926 | return this.coreRequest<{ ok: true }>( |
| 1927 | "PATCH", |
| 1928 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards/${encodeURIComponent(taskboardId)}/tasks/${encodeURIComponent(taskId)}`, |
| 1929 | input, |
| 1930 | ); |
| 1931 | } |
| 1932 |
| 1933 | async deleteTaskboardTask( |
| 1934 | workspaceId: string, |
| 1935 | taskboardId: string, |
| 1936 | taskId: string, |
| 1937 | ): Promise<{ ok: true }> { |
| 1938 | return this.coreRequest<{ ok: true }>( |
| 1939 | "DELETE", |
| 1940 | `/api/v1/workspaces/${encodeURIComponent(workspaceId)}/taskboards/${encodeURIComponent(taskboardId)}/tasks/${encodeURIComponent(taskId)}`, |
| 1941 | ); |
| 1942 | } |
| 1943 | } |
| 1944 |