// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../core/resource'; import * as CompletionsAPI from './chat/completions'; import { APIPromise } from '../core/api-promise'; import { CursorPage, type CursorPageParams, PagePromise } from '../core/pagination'; import { RequestOptions } from '../internal/request-options'; import { path } from '../internal/utils/path'; export class Credentials extends APIResource { /** * Create a new credential for storing sensitive data like API keys, tokens, or * other secrets. */ create(body: CredentialCreateParams, options?: RequestOptions): APIPromise { return this._client.post('/v5/credentials', { body, ...options }); } /** * Retrieve a specific credential by its unique identifier. */ retrieve(credentialID: string, options?: RequestOptions): APIPromise { return this._client.get(path`/v5/credentials/${credentialID}`, options); } /** * Update an existing credential's properties including name, description, type, * payload, and metadata. */ update( credentialID: string, body: CredentialUpdateParams, options?: RequestOptions, ): APIPromise { return this._client.patch(path`/v5/credentials/${credentialID}`, { body, ...options }); } /** * Retrieve a paginated list of all credentials for the current account with * optional name filtering. */ list( query: CredentialListParams | null | undefined = {}, options?: RequestOptions, ): PagePromise { return this._client.getAPIList('/v5/credentials', CursorPage, { query, ...options }); } /** * Permanently delete a credential and all its associated data. */ delete(credentialID: string, options?: RequestOptions): APIPromise { return this._client.delete(path`/v5/credentials/${credentialID}`, options); } /** * Retrieve the plaintext payload of a credential by its ID. */ decrypt(credentialID: string, options?: RequestOptions): APIPromise { return this._client.post(path`/v5/credentials/${credentialID}/secret`, options); } /** * Retrieve the plaintext payload of a credential by its name. */ decryptByName(credentialName: string, options?: RequestOptions): APIPromise { return this._client.post(path`/v5/credentials/name/${credentialName}/secret`, options); } /** * Retrieve a specific credential by its name. */ retrieveByName(credentialName: string, options?: RequestOptions): APIPromise { return this._client.get(path`/v5/credentials/name/${credentialName}`, options); } } export type CredentialsCursorPage = CursorPage; export interface Credential { id: string; created_at: string; created_by_identity_type: string | null; created_by_user_id: string | null; credential_metadata: { [key: string]: unknown } | null; description: string | null; name: string; type: string; updated_at: string; object?: string; } export interface CredentialSecret { result: string; object?: string; } export interface CredentialDeleteResponse { id: string; deleted: boolean; object?: string; } export interface CredentialCreateParams { /** * User-friendly name for the credential */ name: string; /** * The credential payload to be encrypted */ payload: string; /** * Type of credential: key or json */ type: string; /** * Optional unencrypted credential_metadata */ credential_metadata?: { [key: string]: unknown }; /** * Optional description */ description?: string; } export interface CredentialUpdateParams { /** * Optional unencrypted credential_metadata */ credential_metadata?: { [key: string]: unknown }; /** * Optional description */ description?: string; /** * User-friendly name for the credential */ name?: string; /** * The credential payload to be encrypted */ payload?: string; /** * Type of credential: key or json */ type?: string; } export interface CredentialListParams extends CursorPageParams { /** * Filter credentials by name */ name?: string; sort_by?: string; sort_order?: CompletionsAPI.SortOrder; } export declare namespace Credentials { export { type Credential as Credential, type CredentialSecret as CredentialSecret, type CredentialDeleteResponse as CredentialDeleteResponse, type CredentialsCursorPage as CredentialsCursorPage, type CredentialCreateParams as CredentialCreateParams, type CredentialUpdateParams as CredentialUpdateParams, type CredentialListParams as CredentialListParams, }; }