/** * The `ApiKeyLevel` enum represents the access level of a Permit API Key. */ export declare enum ApiKeyLevel { /** * Wait for initialization of the API key. */ WAIT_FOR_INIT = "WAIT_FOR_INIT", /** * Organization level API key authorization. * Using an API key of this scope will allow the SDK user to modify * all projects and environments under the organization / workspace. */ ORGANIZATION_LEVEL_API_KEY = "ORGANIZATION_LEVEL_API_KEY", /** * Project level API key authorization. * Using an API key of this scope will allow the SDK user to modify * a single project and the environments under that project. */ PROJECT_LEVEL_API_KEY = "PROJECT_LEVEL_API_KEY", /** * Environment level API key authorization. * Using an API key of this scope will allow the SDK user to modify * a single Permit environment. */ ENVIRONMENT_LEVEL_API_KEY = "ENVIRONMENT_LEVEL_API_KEY" } export declare const API_ACCESS_LEVELS: ApiKeyLevel[]; export declare enum ApiContextLevel { /** * Signifies that the context is not set yet. */ WAIT_FOR_INIT = 0, /** * When running in this context level, the SDK knows the current organization. */ ORGANIZATION = 1, /** * When running in this context level, the SDK knows the current organization and project. */ PROJECT = 2, /** * When running in this context level, the SDK knows the current organization, project and environment. */ ENVIRONMENT = 3 } /** * The `PermitContextError` class represents an error that occurs when an API method * is called with insufficient context (not knowing in what environment, project or * organization the API call is being made). * Some of the input for the API method is provided via the SDK context. * If the context is missing some data required for a method - the API call will fail. */ export declare class PermitContextError extends Error { constructor(message: string); } /** * The `PermitContextChangeError` will be thrown when the user is trying to set the * SDK context to an object that the current API Key cannot access (and if allowed, * such API calls will result in 401). Instead, the SDK throws this exception. */ export declare class PermitContextChangeError extends Error { constructor(message: string); } /** * The `ApiContext` class represents the required known context for an API method. * Since the Permit API hierarchy is deeply nested, it is less convenient to specify * the full object hierarchy in every request. * For example, in order to list roles, the user needs to specify the (id or key) of the: * - the org * - the project * - then environment * in which the roles are located under. * Instead, the SDK can "remember" the current context and "auto-complete" the details * from that context. * We then get this kind of experience: * ``` * await permit.api.roles.list() * ``` * We can only run this function if the current context already knows the org, project, * and environments that we want to run under, and that is why this method assumes * we are running under a `ApiContextLevel.ENVIRONMENT` context. */ export declare class ApiContext { private _level; private _permittedOrganization; private _permittedProject; private _permittedEnvironment; private _contextLevel; private _organization; private _project; private _environment; constructor(); /** * Do not call this method directly! */ _saveApiKeyAccessibleScope(org: string, project?: string, environment?: string): void; /** * Get the current API key access level. */ get permittedAccessLevel(): ApiKeyLevel; /** * Get the current API key level. * @deprecated replaced with permit.config.apiContext.permittedAccessLevel */ get level(): ApiKeyLevel; /** * Get the current SDK context level. */ get contextLevel(): ApiContextLevel; /** * Get the current organization in the context. */ get organization(): string | null; /** * Get the current project in the context. */ get project(): string | null; /** * Get the current environment in the context. */ get environment(): string | null; private verifyCanAccessOrg; private verifyCanAccessProject; private verifyCanAccessEnvironment; /** * Set the context to organization level. * @param org The organization key. */ setOrganizationLevelContext(org: string): void; /** * Set the context to project level. * @param org The organization key. * @param project The project key. */ setProjectLevelContext(org: string, project: string): void; /** * Set the context to environment level. * @param org The organization key. * @param project The project key. * @param environment The environment key. */ setEnvironmentLevelContext(org: string, project: string, environment: string): void; /** * Get the API project and environment parameters from an environment-level context. * @returns An object containing the project and environment IDs. * @throws {@link PermitContextError} If the API context is not set to environment level or the project or environment is null. */ get environmentContext(): { projId: string; envId: string; }; }