// ── SDK v2 — AppsClient ──────────────────────────────────────────────────────── // // Covers: // GET /v2/apps // POST /v2/apps // GET /v2/apps/:id // PATCH /v2/apps/:id // DELETE /v2/apps/:id // GET /v2/apps/:id/settings // POST /v2/apps/:id/settings // GET /v2/apps/:id/settings/:sid // PATCH /v2/apps/:id/settings/:sid // DELETE /v2/apps/:id/settings/:sid import type { Fetcher } from "../http/fetcher"; import type { RequestOptions } from "../http/types"; import type { App, AppCreate, AppUpdate, AppSettings, AppSettingsCreate, AppSettingsUpdate, ListParams, Paginated, } from "../types/index"; export class AppsClient { constructor(private readonly fetcher: Fetcher) {} // ── Apps CRUD ───────────────────────────────────────────────────────────────── /** * Lists apps with cursor pagination and optional DSL filtering. * * @example * ```ts * const page = await client.apps.list({ q: "team_id.eq:'team-abc'" }); * ``` */ list(params?: ListParams, opts?: RequestOptions): Promise> { return this.fetcher.list("/apps", params, opts); } /** * Creates a new app. * * @example * ```ts * const app = await client.apps.create({ team_id: "team-abc", name: "My App" }); * ``` */ create(data: AppCreate, opts?: RequestOptions): Promise { return this.fetcher.post("/apps", data, opts); } /** * Gets a single app by ID. * * @throws {NotFoundError} when no app with `id` exists. */ get(id: string, opts?: RequestOptions): Promise { return this.fetcher.get(`/apps/${id}`, undefined, opts); } /** * Partially updates an app. * * @throws {NotFoundError} when no app with `id` exists. */ update(id: string, data: AppUpdate, opts?: RequestOptions): Promise { return this.fetcher.patch(`/apps/${id}`, data, opts); } /** * Deletes an app and all its settings. * * @throws {NotFoundError} when no app with `id` exists. */ delete(id: string, opts?: RequestOptions): Promise { return this.fetcher.delete(`/apps/${id}`, opts); } // ── App Settings ────────────────────────────────────────────────────────────── /** * Lists settings entries for an app. * * @example * ```ts * const page = await client.apps.listSettings(appId); * ``` */ listSettings( appId: string, params?: ListParams, opts?: RequestOptions, ): Promise> { return this.fetcher.list(`/apps/${appId}/settings`, params, opts); } /** * Creates a new settings entry for an app. * * @example * ```ts * const settings = await client.apps.createSettings(appId, { * key: "api_token", * value: "sk-...", * }); * ``` */ createSettings( appId: string, data: AppSettingsCreate, opts?: RequestOptions, ): Promise { return this.fetcher.post(`/apps/${appId}/settings`, data, opts); } /** * Gets a single settings entry by ID. * * @throws {NotFoundError} when the settings entry doesn't exist. */ getSettings(appId: string, settingsId: string, opts?: RequestOptions): Promise { return this.fetcher.get( `/apps/${appId}/settings/${settingsId}`, undefined, opts, ); } /** * Updates a settings entry. * * @throws {NotFoundError} when the settings entry doesn't exist. */ updateSettings( appId: string, settingsId: string, data: AppSettingsUpdate, opts?: RequestOptions, ): Promise { return this.fetcher.patch( `/apps/${appId}/settings/${settingsId}`, data, opts, ); } /** * Deletes a settings entry. * * @throws {NotFoundError} when the settings entry doesn't exist. */ deleteSettings(appId: string, settingsId: string, opts?: RequestOptions): Promise { return this.fetcher.delete(`/apps/${appId}/settings/${settingsId}`, opts); } }