gatehouse-ts
    Preparing search index...

    Class PolicyBuilder<Sub, Res, Act, Ctx>

    A fluent builder for creating custom access policies.

    const readOnlyPolicy = new PolicyBuilder<User, Document, string, Context>("ReadOnly")
    .actions(action => action === "read")
    .build();

    Type Parameters

    • Sub

      The type of the subject requesting access

    • Res

      The type of resource being accessed

    • Act

      The type of action being performed

    • Ctx

      Additional contextual information

    Index

    Constructors

    Methods

    • Adds a condition based on the action.

      Parameters

      • pred: (action: Act) => boolean | Promise<boolean>

        Function that evaluates the action and returns true if access should be granted

      Returns PolicyBuilder<Sub, Res, Act, Ctx>

      .actions(action => action === "read" || action === "list")
      
    • Adds a condition based on the context.

      Parameters

      • pred: (ctx: Ctx) => boolean | Promise<boolean>

        Function that evaluates the context and returns true if access should be granted

      Returns PolicyBuilder<Sub, Res, Act, Ctx>

      .context(ctx => ctx.isBusinessHours)
      
    • Adds a condition based on the resource.

      Parameters

      • pred: (res: Res) => boolean | Promise<boolean>

        Function that evaluates the resource and returns true if access should be granted

      Returns PolicyBuilder<Sub, Res, Act, Ctx>

      .resources(doc => doc.isPublic)
      
    • Adds a condition based on the subject.

      Parameters

      • pred: (sub: Sub) => boolean | Promise<boolean>

        Function that evaluates the subject and returns true if access should be granted

      Returns PolicyBuilder<Sub, Res, Act, Ctx>

      .subjects(user => user.roles.includes('admin'))