UNPKG

@squidcloud/client

Version:

A typescript implementation of the Squid client

154 lines (153 loc) 5.13 kB
import { SquidRegion } from '../../internal-common/src/public-types/regions.public-types'; /** * Options for creating a ManagementClient. * @category ManagementClient */ export interface ManagementClientOptions { /** The management API key (starts with 'squid_mgmt_') */ apiKey: string; /** The Squid region to connect to */ consoleRegion: SquidRegion; } /** * Request to create a new organization. * @category ManagementClient */ export interface ManagementCreateOrganizationRequest { /** Name of the organization (2-50 characters) */ name: string; } /** * Response from creating a new organization. * @category ManagementClient */ export interface ManagementCreateOrganizationResponse { /** The ID of the created organization */ organizationId: string; } /** * Request to create a new application. * @category ManagementClient */ export interface ManagementCreateApplicationRequest { /** The organization ID to create the application in */ organizationId: string; /** Name of the application */ name: string; /** Squid region (e.g., 'us-east-1.aws'). The cloud provider is parsed from this. */ region: SquidRegion; } /** * Response from creating a new application. * @category ManagementClient */ export interface ManagementCreateApplicationResponse { /** The ID of the created application */ appId: string; /** The API key for the dev environment */ devApiKey: string; /** The API key for the prod environment */ prodApiKey: string; } /** * Request to rename an organization. * @category ManagementClient */ export interface ManagementRenameOrganizationRequest { /** The ID of the organization to rename */ organizationId: string; /** New name for the organization (2-50 characters) */ name: string; } /** * Request to rename an application. * @category ManagementClient */ export interface ManagementRenameApplicationRequest { /** The ID of the application to rename */ appId: string; /** New name for the application */ name: string; } /** * Client for programmatic management of Squid organizations and applications. * * Use this client to automate organization and application management * using management API keys (created in the Squid Console Profile Settings). * * @example * ```typescript * const client = new ManagementClient({ * apiKey: 'squid_mgmt_xxx...', * region: 'us-east-1.aws' * }); * * // Create an organization * const { organizationId } = await client.createOrganization({ name: 'My Org' }); * * // Create an application * const { appId } = await client.createApplication({ * organizationId, * name: 'My App', * region: 'us-east-1.aws' * }); * * // Delete an application * await client.deleteApplication('my-app-id'); * ``` * * @category ManagementClient */ export declare class ManagementClient { private readonly apiKey; private readonly consoleRegion; /** * Creates a new ManagementClient. * * @param options - Configuration options including API key and region * @throws Error if the API key does not start with 'squid_mgmt_' */ constructor(options: ManagementClientOptions); /** * Creates a new organization. * The user associated with the management API key becomes the admin of the new organization. * * @param request - The organization creation request * @returns The created organization's ID * @throws Error if organization name is invalid or key is unauthorized */ createOrganization(request: ManagementCreateOrganizationRequest): Promise<ManagementCreateOrganizationResponse>; /** * Creates a new application in an organization. * Requires the user to be an admin in the target organization. * * @param request - The application creation request * @returns The created application's ID and API keys * @throws Error if user is not admin or organization quota reached */ createApplication(request: ManagementCreateApplicationRequest): Promise<ManagementCreateApplicationResponse>; /** * Deletes an application. * Requires the user to be an admin in the application's organization. * * @param appId - The ID of the application to delete * @throws Error if user is not admin or application not found */ deleteApplication(appId: string): Promise<void>; /** * Renames an organization. * Requires the user to be an admin in the organization. * * @param request - The rename request containing organizationId and new name * @throws Error if user is not admin or organization not found */ renameOrganization(request: ManagementRenameOrganizationRequest): Promise<void>; /** * Renames an application. * Requires the user to be an admin in the application's organization. * * @param request - The rename request containing appId and new name * @throws Error if user is not admin or application not found */ renameApplication(request: ManagementRenameApplicationRequest): Promise<void>; }