Javascript SDK

RecordPermissions

Access control for a record.

const permissions = {
  read: [{entity: "julie.baq.run"}],
};

Static fields

  • public RecordPermissions

    • Public permissions preset.

    • {"read": "public"}
      
  • private RecordPermissions

    • Private permissions preset.
  • readonly(author: Entity, others: Entity[]): RecordPermissions

    • Create read-only permissions for specific users.
  • toReadEntities(permissions: RecordPermissions): Entity[]

    • Find the entities with read access in a permissions object.

Properties

  • read “public” | EntityLink[] optional

    • Read permissions for the record.

    • Accepts a special value of "public".

    • Defaults to the record’s author.

  • write EntityLink[] optional

    • Write (update / delete) permissions for the record.

    • Every entity in write should be included in read.

    • Default to the record’s author.

  • notify EntityLink[] optional

    • Entities to notify.

    • Defaults to the entities in read.

For common use-cases, presets are provided on the RecordPermissions type. Here we create a public Post record­ visible to all.

import {RecordPermissions} from "@baqhub/sdk";
import {PostRecord} from "./baq/postRecord.js";

const postRecord = PostRecord.new(
  "julie.baq.run",
  {text: "Hi everyone!"},
  {permissions: RecordPermissions.public}
);

For more advanced situations, permissions can be crafted by hand to fit the need. Here we create a Task record­ with read access for the author and more two people, but we only notify one of them.

import {TaskRecord} from "./baq/taskRecord.js";

const taskRecord = TaskRecord.new(
  "paul.baq.run",
  {
    title: "Make new BAQ app!",
    completed: false,
  },
  {
    read: [
      {entity: "paul.baq.run"},
      {entity: "henry.baq.run"},
      {entity: "sean.baq.run"},
    ],
    notify: [{entity: "henry.baq.run"}],
  }
);
© 2024 Quentez