// ── SDK v2 — IntegrationsClient ──────────────────────────────────────────────── // // Covers: // POST /v2/integrations // GET /v2/integrations // GET /v2/integrations/:id // GET /v2/integrations/:id/config // PATCH /v2/integrations/:id // DELETE /v2/integrations/:id import type { Fetcher } from "../http/fetcher"; import type { RequestOptions } from "../http/types"; import type { Integration, IntegrationCreate, IntegrationUpdate, ListParams, Paginated, } from "../types/index"; export class IntegrationsClient { constructor(private readonly fetcher: Fetcher) {} /** * Lists integrations with cursor pagination and optional DSL filtering. * * @example * ```ts * const page = await client.integrations.list({ q: "team_id.eq:'team-abc'" }); * ``` */ list(params?: ListParams, opts?: RequestOptions): Promise> { return this.fetcher.list("/integrations", params, opts); } /** * Creates a new integration. * Authorization header values inside `config` are encrypted at rest (AES-256-GCM). * * @example * ```ts * const integration = await client.integrations.create({ * team_id: "team-abc", * name: "Slack Notifications", * type: "slack", * config: { webhook_url: "https://hooks.slack.com/..." }, * }); * ``` */ create(data: IntegrationCreate, opts?: RequestOptions): Promise { return this.fetcher.post("/integrations", data, opts); } /** * Gets a single integration by ID. * Authorization header values in `config` are returned masked as `"[encrypted]"`. * * @throws {NotFoundError} when no integration with `id` exists. */ get(id: string, opts?: RequestOptions): Promise { return this.fetcher.get(`/integrations/${id}`, undefined, opts); } /** * Gets an integration with its decrypted config. * Use only server-side — never expose decrypted credentials to the browser. * * @throws {NotFoundError} when no integration with `id` exists. */ getConfig(id: string, opts?: RequestOptions): Promise { return this.fetcher.get(`/integrations/${id}/config`, undefined, opts); } /** * Partially updates an integration. * If `config` is provided, Authorization header values are re-encrypted before storage. * * @throws {NotFoundError} when no integration with `id` exists. */ update(id: string, data: IntegrationUpdate, opts?: RequestOptions): Promise { return this.fetcher.patch(`/integrations/${id}`, data, opts); } /** * Deletes an integration. * * @throws {NotFoundError} when no integration with `id` exists. */ delete(id: string, opts?: RequestOptions): Promise { return this.fetcher.delete(`/integrations/${id}`, opts); } }