Class ApiContext

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.

Hierarchy

  • ApiContext

Constructors

Accessors

  • get contextLevel(): ApiContextLevel
  • Get the current SDK context level.

    Returns ApiContextLevel

  • get environment(): null | string
  • Get the current environment in the context.

    Returns null | string

  • get environmentContext(): {
        envId: string;
        projId: string;
    }
  • Get the API project and environment parameters from an environment-level context.

    Returns {
        envId: string;
        projId: string;
    }

    An object containing the project and environment IDs.

    • envId: string
    • projId: string

    Throws

    PermitContextError If the API context is not set to environment level or the project or environment is null.

  • get organization(): null | string
  • Get the current organization in the context.

    Returns null | string

  • get project(): null | string
  • Get the current project in the context.

    Returns null | string

Methods

  • Do not call this method directly!

    Parameters

    • org: string
    • Optional project: string
    • Optional environment: string

    Returns void

  • Set the context to environment level.

    Parameters

    • org: string

      The organization key.

    • project: string

      The project key.

    • environment: string

      The environment key.

    Returns void

  • Set the context to organization level.

    Parameters

    • org: string

      The organization key.

    Returns void

  • Set the context to project level.

    Parameters

    • org: string

      The organization key.

    • project: string

      The project key.

    Returns void

Generated using TypeDoc