Sharing

Bazaar comes with a powerful Sharing API, empowering developers to implement sharing and collaboration in their applications.

With the database-per-user architecture, users can interact with their data by default. The Sharing API facilitates granting access to other users. Permissions can be granted to docs and collections with filters to deliver precise control.

Share a document with a user with read permissions:

const newPermission = {
collectionName: "example-collection-name",
userId: "example-user-id",
types: ["read"],
filter: {
id: "example-doc-id",
},
};
const { id } = await bzr.permissions.create(newPermission);

The Sharing API is simple to use but caters to complex scenarios. Subscribe to change events to react to granted permissions changes in realtime.

Subscribe to change events for a granted permission for a collection:

bzr.permissions.granted.subscribe(
{ collectionName: "example-collection-name" },
async ({ oldDoc, newDoc }) => {
if (oldDoc === null && newDoc) {
// Granted permission added
}
if (oldDoc && newDoc === null) {
// Granted permission removed
}
}
);

Create share links and similarly subscribe to receive change events when a link is created, updated, deleted, or redeemed in realtime.

Create a share link for a doc will all permissions:

const permissionTemplate = {
collectionName: "example-collection-name",
types: ["read", "insert", "update", "delete"],
filter: {
id: "example-doc-id",
},
};
const { url } = await bzr.permissions.links.create(permissionTemplate);

Sharing can also be managed through a Bazaar modal:

const permissionTemplate = {
collectionName: "example-collection-name",
types: ["read", "insert", "update", "delete"],
filter: {
id: "example-doc-id",
},
};
bzr.permissions.openModal(permissionTemplate);

TODO screenshot modal.