@bzr/bazaar
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -29,2 +29,6 @@ import { API } from "./raw"; | ||
/** | ||
* @alpha | ||
*/ | ||
private mirrorAll; | ||
/** | ||
* @returns The doc ID | ||
@@ -31,0 +35,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
import type { GrantedPermission, Link, NewPermission, Notification, PermissionTemplate, PermissionType, SubscribeListener } from "../types"; | ||
import { type GrantedPermission, type Link, type NewPermission, type PermissionTemplate, type PermissionType, type SharingNotification, type SubscribeListener } from "../types"; | ||
import { API } from "./raw"; | ||
@@ -10,12 +10,9 @@ /** | ||
private linkUri; | ||
private appId; | ||
constructor(api: API, uri: string, appId: string); | ||
constructor(api: API, uri: string); | ||
/** | ||
* Opens the permission modal | ||
* Creates permission for a collection query and a user. | ||
* @param {NewPermission} permission "Specifies the permission to be created" | ||
* @param {SharingNotification} notification "Specifies if/how the user is notified. Defaults to {createNotification: false, sendMessage: SendNotification.Never}" | ||
*/ | ||
openModal(permission: PermissionTemplate): void; | ||
/** | ||
* Creates permission for a collection. | ||
*/ | ||
create(permission: NewPermission, notification?: Notification): Promise<{ | ||
create(permission: NewPermission, notification?: SharingNotification): Promise<{ | ||
id: string; | ||
@@ -45,6 +42,7 @@ }>; | ||
*/ | ||
create: (permission: PermissionTemplate, limit?: number) => Promise<{ | ||
create: (permission: PermissionTemplate, description?: string, limit?: number) => Promise<{ | ||
id: string; | ||
permission: PermissionTemplate; | ||
limit: number; | ||
description: string; | ||
users: string[]; | ||
@@ -60,2 +58,6 @@ url: string; | ||
}) => Promise<Link[]>; | ||
/** | ||
* Subscribes to links changes | ||
* @returns an unsubscribe function | ||
*/ | ||
subscribe: (options: { | ||
@@ -66,3 +68,3 @@ collectionName?: string; | ||
/** | ||
* Deletes permissions for a table | ||
* Deletes a link | ||
*/ | ||
@@ -69,0 +71,0 @@ delete: (linkId: string) => Promise<import("../types").BazaarMessage>; |
@@ -1,2 +0,2 @@ | ||
import type { APIOptions, Permission, NewPermission, Notification, SubscribeListener, BazaarMessage, Contact, User, GrantedPermission, PermissionType, PermissionTemplate, Doc, BasicLink, CollectionCommonOptions, CollectionGetAllOptions, CollectionCommonAllOptions } from "../types"; | ||
import type { APIOptions, Permission, NewPermission, SubscribeListener, BazaarMessage, Contact, User, GrantedPermission, PermissionType, PermissionTemplate, Doc, BasicLink, CollectionCommonOptions, CollectionGetAllOptions, CollectionCommonAllOptions, SharingNotification, Notification, CreateNotification } from "../types"; | ||
/** | ||
@@ -24,2 +24,10 @@ * The class that encapsulates the low level data API | ||
/** | ||
* ID attribute of the dialog HTML element | ||
*/ | ||
private modalId; | ||
/** | ||
* ID attribute of the style HTML element for the modal styles | ||
*/ | ||
private modalStylesId; | ||
/** | ||
* A callback to do something upon Data API connection | ||
@@ -168,3 +176,3 @@ */ | ||
*/ | ||
permissionsCreate(permission: NewPermission, notification: Notification): Promise<{ | ||
permissionsCreate(permission: NewPermission, notification: SharingNotification): Promise<{ | ||
id: string; | ||
@@ -181,3 +189,3 @@ }>; | ||
*/ | ||
linksCreate(permission: PermissionTemplate, limit?: number): Promise<{ | ||
linksCreate(permission: PermissionTemplate, description?: string, limit?: number): Promise<{ | ||
data: BasicLink; | ||
@@ -242,7 +250,50 @@ }>; | ||
/** | ||
* Adds a user ID to your contacts | ||
* Creates a notification. | ||
*/ | ||
notificationsCreate(notification: CreateNotification): Promise<{ | ||
data: Notification; | ||
}>; | ||
/** | ||
* Lists notifications. | ||
* | ||
* @param userID - The ID of the user | ||
* @param options - If no options are set, all non-hidden notifications are returned. | ||
* @returns Where `data` is an array of notifications | ||
*/ | ||
usersGet(userId?: string): Promise<{ | ||
notificationsList(options?: { | ||
includeHidden?: boolean; | ||
senderId?: string; | ||
startTs?: Date; | ||
endTs?: Date; | ||
}): Promise<{ | ||
data: Notification[]; | ||
}>; | ||
/** | ||
* Subscribes to notification changes | ||
* | ||
* @param options - | ||
* @param listener - The callback function that receives notification change events. | ||
* @returns An unsubscribe function | ||
*/ | ||
notificationsSubscribe(options: { | ||
includeHidden?: boolean; | ||
senderId?: string; | ||
startTs?: Date; | ||
endTs?: Date; | ||
}, listener: SubscribeListener<Notification>): Promise<() => Promise<BazaarMessage>>; | ||
/** | ||
* Hides notifications. | ||
*/ | ||
notificationsHide(notificationId: string): Promise<BazaarMessage>; | ||
/** | ||
* Deletes notifications. | ||
*/ | ||
notificationsDelete(notificationId: string): Promise<BazaarMessage>; | ||
/** | ||
* Gets the user info for a given ID or handle. | ||
* @param payload - The ID or handle of the user, defaults to logged in user's ID. | ||
*/ | ||
usersGet(payload?: { | ||
userId?: string; | ||
handle?: string; | ||
}): Promise<{ | ||
data: User; | ||
@@ -270,2 +321,6 @@ }>; | ||
openModal(path: string, onMessage?: ((msg: string) => void) | null): void; | ||
/** | ||
* Creates and appends a modal to the DOM | ||
*/ | ||
initializeModal(): void; | ||
} |
@@ -15,6 +15,9 @@ import type { Contact, SubscribeListener } from "../types"; | ||
/** | ||
* Gets the user info for a given ID. | ||
* @param userID - The ID of the user, defaults to logged in user's ID. | ||
* Gets the user info for a given ID or handle. | ||
* @param query - The ID or handle of the user, defaults to logged in user's ID. | ||
*/ | ||
getUser(userId?: string): Promise<import("../types").User>; | ||
getUser(query?: { | ||
userId?: string; | ||
handle?: string; | ||
}): Promise<import("../types").User>; | ||
/** | ||
@@ -21,0 +24,0 @@ * Contacts |
@@ -112,2 +112,10 @@ import io from 'socket.io-client'; | ||
/** | ||
* ID attribute of the dialog HTML element | ||
*/ | ||
this.modalId = "bazaar-modal"; | ||
/** | ||
* ID attribute of the style HTML element for the modal styles | ||
*/ | ||
this.modalStylesId = "bazaar-modal-styles"; | ||
/** | ||
* Makes sure a connection to the Data API has been made. | ||
@@ -162,32 +170,2 @@ */ | ||
this.connect(); | ||
// Initialize modal | ||
this.modal = document.createElement("dialog"); | ||
this.modal.style.width = "min(700px, 100vw)"; | ||
this.modal.style.borderWidth = "0"; | ||
this.modal.style.padding = "0"; | ||
this.modal.style.margin = "auto"; | ||
const header = document.createElement("div"); | ||
header.style.width = "100%"; | ||
header.style.display = "flex"; | ||
header.style.alignItems = "flex-end"; | ||
this.modal.appendChild(header); | ||
const button = document.createElement("button"); | ||
button.style.marginLeft = "auto"; | ||
button.style.borderWidth = "0"; | ||
button.style.backgroundColor = "white"; | ||
button.innerHTML = "X"; | ||
button.onclick = () => this.closeModal(); | ||
header.appendChild(button); | ||
this.iframe = document.createElement("iframe"); | ||
// Note: using a sandbox with allow-scripts and allow-same-origin | ||
// is unsecure like not having a sandbox. | ||
// We should strive to remove the allow-same-origin by | ||
// passing/using the auth token via other means | ||
// this.iframe.sandbox.add("allow-scripts"); // Required to run the Bazaar page | ||
// this.iframe.sandbox.add("allow-same-origin"); // Required to read the token from local storage | ||
this.iframe.style.width = "100%"; | ||
this.iframe.style.height = "min(700px, 100vh)"; | ||
this.iframe.style.borderWidth = "0"; | ||
this.modal.appendChild(this.iframe); | ||
document.body.appendChild(this.modal); | ||
} | ||
@@ -416,3 +394,2 @@ /** | ||
return __awaiter(this, void 0, void 0, function* () { | ||
console.log("this", this); | ||
return this.asyncEmit(this.version + ":permissions:create", { permission, notification }); | ||
@@ -434,6 +411,5 @@ }); | ||
*/ | ||
linksCreate(permission, limit = 0) { | ||
linksCreate(permission, description = "", limit = 0) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
console.log("this", this); | ||
return this.asyncEmit(this.version + ":links:create", { permission, limit }); | ||
return this.asyncEmit(this.version + ":links:create", { permission, description, limit }); | ||
}); | ||
@@ -517,15 +493,66 @@ } | ||
// | ||
// Social API | ||
// Notifications API | ||
// | ||
/** | ||
* Adds a user ID to your contacts | ||
* Creates a notification. | ||
*/ | ||
notificationsCreate(notification) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.asyncEmit(this.version + ":notifications:create", { notification }); | ||
}); | ||
} | ||
/** | ||
* Lists notifications. | ||
* | ||
* @param userID - The ID of the user | ||
* @param options - If no options are set, all non-hidden notifications are returned. | ||
* @returns Where `data` is an array of notifications | ||
*/ | ||
usersGet(userId) { | ||
notificationsList(options = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let payload = {}; | ||
if (userId) { | ||
payload = { userId }; | ||
} | ||
return this.asyncEmit(this.version + ":notifications:list", options); | ||
}); | ||
} | ||
/** | ||
* Subscribes to notification changes | ||
* | ||
* @param options - | ||
* @param listener - The callback function that receives notification change events. | ||
* @returns An unsubscribe function | ||
*/ | ||
notificationsSubscribe(options = {}, listener) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = (yield this.asyncEmit(this.version + ":notifications:subscribe", options)); // where data is the subscription handle | ||
const subscriptionHandle = response.data; | ||
this.dataApi.on(subscriptionHandle, listener); | ||
return () => __awaiter(this, void 0, void 0, function* () { | ||
this.dataApi.off(subscriptionHandle, listener); | ||
return this.asyncEmit(this.version + ":notifications:unsubscribe", subscriptionHandle); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Hides notifications. | ||
*/ | ||
notificationsHide(notificationId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.asyncEmit(this.version + ":notifications:hide", { notificationId }); | ||
}); | ||
} | ||
/** | ||
* Deletes notifications. | ||
*/ | ||
notificationsDelete(notificationId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.asyncEmit(this.version + ":notifications:delete", { notificationId }); | ||
}); | ||
} | ||
// | ||
// Social API | ||
// | ||
/** | ||
* Gets the user info for a given ID or handle. | ||
* @param payload - The ID or handle of the user, defaults to logged in user's ID. | ||
*/ | ||
usersGet(payload = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.asyncEmit(this.version + ":users:get", payload); | ||
@@ -572,2 +599,3 @@ }); | ||
openModal(path, onMessage = null) { | ||
this.initializeModal(); | ||
this.iframe.src = this.bazaarUri + path; | ||
@@ -587,2 +615,49 @@ this.modal.showModal(); | ||
} | ||
/** | ||
* Creates and appends a modal to the DOM | ||
*/ | ||
initializeModal() { | ||
const modal = document.getElementById(this.modalId); | ||
if (modal) | ||
return; | ||
// Initialize modal | ||
this.modal = document.createElement("dialog"); | ||
this.modal.setAttribute("id", this.modalId); | ||
// Needed to hide a white bar at the bottom of the dialog | ||
this.modal.style.backgroundColor = "oklch(.178606 .034249 265.754874)"; // --b3 | ||
this.modal.style.width = "min(700px, 100vw)"; | ||
this.modal.style.borderWidth = "0"; | ||
this.modal.style.padding = "0"; | ||
this.modal.style.margin = "auto"; | ||
this.modal.style.borderRadius = "1rem"; | ||
const style = document.createElement("style"); | ||
style.id = this.modalStylesId; | ||
document.head.appendChild(style); | ||
// The ::backdrop pseudo property cannot be added with the `.style` syntax | ||
style.sheet.insertRule(`#${this.modalId}::backdrop { | ||
background: rgba(0,0,0,.8); | ||
} `, 0); | ||
const button = document.createElement("button"); | ||
button.style.borderWidth = "0"; | ||
button.style.fontWeight = "bold"; | ||
button.style.fontSize = "32px"; | ||
button.style.right = "8px"; | ||
button.style.top = "5px"; | ||
button.style.background = "transparent"; | ||
button.style.cursor = "pointer"; | ||
button.style.position = "fixed"; | ||
button.style.zIndex = "10"; | ||
button.style.color = "oklch(.841536 .007965 265.754874)"; // --bc | ||
button.innerHTML = "×"; | ||
button.autofocus = true; | ||
button.ariaLabel = "Close Bazaar modal"; | ||
button.onclick = () => this.closeModal(); | ||
this.modal.appendChild(button); | ||
this.iframe = document.createElement("iframe"); | ||
this.iframe.style.width = "100%"; | ||
this.iframe.style.minHeight = "80vh"; | ||
this.iframe.style.borderWidth = "0"; | ||
this.modal.appendChild(this.iframe); | ||
document.body.appendChild(this.modal); | ||
} | ||
} | ||
@@ -639,2 +714,49 @@ | ||
/** | ||
* @alpha | ||
*/ | ||
mirrorAll(filter, data, mirrorOptions = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const docs = yield this.getAll(filter); | ||
if (mirrorOptions.onAdd) { | ||
for (const doc of docs) { | ||
mirrorOptions.onAdd(doc).catch((err) => console.log("failed onAdd:", err)); | ||
} | ||
} | ||
data.push(...docs); | ||
return yield this.subscribeAll(filter, (changes) => { | ||
if (!changes.oldDoc) { | ||
// New doc | ||
data.push(changes.newDoc); | ||
if (mirrorOptions.onAdd) { | ||
mirrorOptions.onAdd(changes.newDoc).catch((err) => console.log("failed onAdd:", err)); | ||
} | ||
return; | ||
} | ||
const idx = data.findIndex((doc) => doc.id === changes.oldDoc.id); | ||
if (!changes.newDoc) { | ||
// Deleted doc | ||
if (idx > -1) { | ||
data.splice(idx, 1); | ||
} | ||
if (mirrorOptions.onDelete) { | ||
mirrorOptions.onDelete(changes.oldDoc).catch((err) => console.log("failed onDelete:", err)); | ||
} | ||
return; | ||
} | ||
// Changed doc | ||
if (idx > -1) { | ||
data[idx] = changes.newDoc; | ||
} | ||
else { | ||
// It is missing for some reason, add it. | ||
data.push(changes.newDoc); | ||
} | ||
if (mirrorOptions.onChange) { | ||
mirrorOptions.onChange(changes.oldDoc, changes.newDoc).catch((err) => console.log("failed onChange:", err)); | ||
} | ||
return; | ||
}); | ||
}); | ||
} | ||
/** | ||
* @returns The doc ID | ||
@@ -736,2 +858,58 @@ */ | ||
/** | ||
* | ||
*/ | ||
var PermissionType; | ||
(function (PermissionType) { | ||
PermissionType["READ"] = "read"; | ||
PermissionType["INSERT"] = "insert"; | ||
PermissionType["UPDATE"] = "update"; | ||
PermissionType["DELETE"] = "delete"; | ||
})(PermissionType || (PermissionType = {})); | ||
/** | ||
* Represents the options for sending notifications. | ||
*/ | ||
var SendNotification; | ||
(function (SendNotification) { | ||
/** | ||
* Send an invitation if the target user does not use the app | ||
*/ | ||
SendNotification["INVITE_ONLY"] = "invite-only"; | ||
/** | ||
* Always send an invitation to the target user | ||
*/ | ||
SendNotification["ALWAYS"] = "always"; | ||
/** | ||
* Never send an invitation to the target user | ||
*/ | ||
SendNotification["NEVER"] = "never"; | ||
})(SendNotification || (SendNotification = {})); | ||
/** | ||
* The possible login types. | ||
*/ | ||
var LoginType; | ||
(function (LoginType) { | ||
/** | ||
* Default login type. | ||
* Do pop-up login, if the pop-up fails to open, fallback to redirect. | ||
*/ | ||
LoginType["POPUP_FALLBACK"] = "popup_fallback"; | ||
/** | ||
* Do pop-up login only. Do not fallback to redirect. | ||
*/ | ||
LoginType["POPUP"] = "popup"; | ||
/** | ||
* Do redirect login. Do not open a pop-up. | ||
*/ | ||
LoginType["REDIRECT"] = "redirect"; | ||
})(LoginType || (LoginType = {})); | ||
/** | ||
* | ||
*/ | ||
var OrderByType; | ||
(function (OrderByType) { | ||
OrderByType["ASC"] = "asc"; | ||
OrderByType["DESC"] = "desc"; | ||
})(OrderByType || (OrderByType = {})); | ||
/** | ||
* The class that encapsulates the permissions API | ||
@@ -741,3 +919,3 @@ * @internal | ||
class PermissionsAPI { | ||
constructor(api, uri, appId) { | ||
constructor(api, uri) { | ||
/** | ||
@@ -750,4 +928,4 @@ * Links | ||
*/ | ||
create: (permission, limit = 0) => __awaiter(this, void 0, void 0, function* () { | ||
const { data: basicLink } = yield this.api.linksCreate(permission, limit); | ||
create: (permission, description = "", limit = 0) => __awaiter(this, void 0, void 0, function* () { | ||
const { data: basicLink } = yield this.api.linksCreate(permission, description, limit); | ||
return Object.assign({ url: this.linkUri + basicLink.id }, basicLink); | ||
@@ -766,2 +944,6 @@ }), | ||
}), | ||
/** | ||
* Subscribes to links changes | ||
* @returns an unsubscribe function | ||
*/ | ||
subscribe: (options = {}, listener) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -781,3 +963,3 @@ const newListener = (newChanges) => { | ||
/** | ||
* Deletes permissions for a table | ||
* Deletes a link | ||
*/ | ||
@@ -805,16 +987,9 @@ delete: (linkId) => __awaiter(this, void 0, void 0, function* () { | ||
this.linkUri = (uri || bazaarUri) + linkPath; | ||
this.appId = appId; | ||
} | ||
/** | ||
* Opens the permission modal | ||
* Creates permission for a collection query and a user. | ||
* @param {NewPermission} permission "Specifies the permission to be created" | ||
* @param {SharingNotification} notification "Specifies if/how the user is notified. Defaults to {createNotification: false, sendMessage: SendNotification.Never}" | ||
*/ | ||
openModal(permission) { | ||
// this.modal.showModal(); | ||
this.api.openModal(`/m/permission?appId=${this.appId}&permission=${JSON.stringify(permission)}`); | ||
return; | ||
} | ||
/** | ||
* Creates permission for a collection. | ||
*/ | ||
create(permission, notification = { enabled: false }) { | ||
create(permission, notification = { createNotification: false, sendMessage: SendNotification.NEVER }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -886,8 +1061,8 @@ return this.api.permissionsCreate(permission, notification); | ||
/** | ||
* Gets the user info for a given ID. | ||
* @param userID - The ID of the user, defaults to logged in user's ID. | ||
* Gets the user info for a given ID or handle. | ||
* @param query - The ID or handle of the user, defaults to logged in user's ID. | ||
*/ | ||
getUser(userId) { | ||
getUser(query = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield this.api.usersGet(userId); | ||
const res = yield this.api.usersGet(query); | ||
return res.data; | ||
@@ -899,41 +1074,2 @@ }); | ||
/** | ||
* @beta | ||
*/ | ||
var PermissionType; | ||
(function (PermissionType) { | ||
PermissionType["READ"] = "read"; | ||
PermissionType["INSERT"] = "insert"; | ||
PermissionType["UPDATE"] = "update"; | ||
PermissionType["DELETE"] = "delete"; | ||
})(PermissionType || (PermissionType = {})); | ||
/** | ||
* The possible login types. | ||
* @beta | ||
*/ | ||
var LoginType; | ||
(function (LoginType) { | ||
/** | ||
* Default login type. | ||
* Do pop-up login, if the pop-up fails to open, fallback to redirect. | ||
*/ | ||
LoginType["POPUP_FALLBACK"] = "popup_fallback"; | ||
/** | ||
* Do pop-up login only. Do not fallback to redirect. | ||
*/ | ||
LoginType["POPUP"] = "popup"; | ||
/** | ||
* Do redirect login. Do not open a pop-up. | ||
*/ | ||
LoginType["REDIRECT"] = "redirect"; | ||
})(LoginType || (LoginType = {})); | ||
/** | ||
* @beta | ||
*/ | ||
var OrderByType; | ||
(function (OrderByType) { | ||
OrderByType["ASC"] = "asc"; | ||
OrderByType["DESC"] = "desc"; | ||
})(OrderByType || (OrderByType = {})); | ||
/** | ||
* The class that deals with login and authentication | ||
@@ -1222,4 +1358,54 @@ */ | ||
/** | ||
* The class that encapsulates the notification API | ||
* @internal | ||
*/ | ||
class NotificationsAPI { | ||
constructor(api) { | ||
this.api = api; | ||
} | ||
/** | ||
* Creates notification for a target user. | ||
*/ | ||
create(notification) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.api.notificationsCreate(notification); | ||
}); | ||
} | ||
/** | ||
* Lists notifications. | ||
* @returns All notifications for this app and user | ||
*/ | ||
list(options = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield this.api.notificationsList(options); | ||
return res.data; | ||
}); | ||
} | ||
subscribe(options = {}, listener) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.api.notificationsSubscribe(options, listener); | ||
}); | ||
} | ||
/** | ||
* Hides notification with a given ID | ||
* @param notificationId - ID of the notification to hide | ||
*/ | ||
hide(notificationId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.api.notificationsHide(notificationId); | ||
}); | ||
} | ||
/** | ||
* Deletes notification with a given ID | ||
* @param notificationId - ID of the notification to delete | ||
*/ | ||
delete(notificationId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.api.notificationsDelete(notificationId); | ||
}); | ||
} | ||
} | ||
/** | ||
* The primary class of the Bazaar JS SDK to help you more easily build web apps with Bazaar. | ||
* @beta | ||
*/ | ||
@@ -1261,3 +1447,4 @@ class BazaarApp { | ||
this.collections = new CollectionsAPI(this.api); | ||
this.permissions = new PermissionsAPI(this.api, options.bazaarUri, options.appId); | ||
this.permissions = new PermissionsAPI(this.api, options.bazaarUri); | ||
this.notifications = new NotificationsAPI(this.api); | ||
this.social = new SocialAPI(this.api); | ||
@@ -1264,0 +1451,0 @@ } |
@@ -18,6 +18,5 @@ import { CollectionAPI } from "./api/collection"; | ||
export { OrderByType, PermissionType, LoginType } from "./types"; | ||
export type { User, Contact, Permission, NewPermission, PermissionTemplate, GrantedPermission, FilterObject, FilterComparison, OrderBy, BazaarMessage, Link, Doc, AnyDoc, SubscribeListener, BazaarOptions, } from "./types"; | ||
export type { User, Contact, Permission, NewPermission, PermissionTemplate, GrantedPermission, SendNotification, SharingNotification, FilterObject, FilterComparison, OrderBy, BazaarMessage, Link, Doc, AnyDoc, SubscribeListener, BazaarOptions, MirrorOptions, } from "./types"; | ||
/** | ||
* The primary class of the Bazaar JS SDK to help you more easily build web apps with Bazaar. | ||
* @beta | ||
*/ | ||
@@ -42,2 +41,7 @@ export declare class BazaarApp { | ||
/** | ||
* Access to the notifications API | ||
* @alpha | ||
*/ | ||
private notifications; | ||
/** | ||
* Access to the social API | ||
@@ -44,0 +48,0 @@ */ |
import { BazaarApp } from ".."; | ||
/** | ||
* Options for initializing a BazaarApp instance | ||
* @beta | ||
*/ | ||
@@ -41,3 +40,2 @@ export type BazaarOptions = { | ||
* Represents a complete permission object which includes both the `id` field and `userId` for user association. | ||
* @beta | ||
*/ | ||
@@ -54,3 +52,2 @@ export type Permission = { | ||
* It has the same structure as {@link Permission} but without the `id` field. | ||
* @beta | ||
*/ | ||
@@ -61,7 +58,6 @@ export type NewPermission = Omit<Permission, "id">; | ||
* It's derived from the {@link NewPermission} and does not include user association. | ||
* @beta | ||
*/ | ||
export type PermissionTemplate = Omit<NewPermission, "userId">; | ||
/** | ||
* @beta | ||
* | ||
*/ | ||
@@ -75,11 +71,50 @@ export declare enum PermissionType { | ||
/** | ||
* @beta | ||
* Represents the options for sending notifications. | ||
*/ | ||
export type Notification = { | ||
enabled: boolean; | ||
export declare enum SendNotification { | ||
/** | ||
* Send an invitation if the target user does not use the app | ||
*/ | ||
INVITE_ONLY = "invite-only", | ||
/** | ||
* Always send an invitation to the target user | ||
*/ | ||
ALWAYS = "always", | ||
/** | ||
* Never send an invitation to the target user | ||
*/ | ||
NEVER = "never" | ||
} | ||
/** | ||
* | ||
*/ | ||
export type SharingNotification = { | ||
createNotification: boolean; | ||
sendMessage: SendNotification; | ||
/** | ||
* Defaults to "X shared something with you in app Y" | ||
*/ | ||
message?: string; | ||
}; | ||
/** | ||
* @beta | ||
* | ||
*/ | ||
export type Notification = { | ||
id: string; | ||
senderId: string; | ||
message: string; | ||
ts: Date; | ||
hidden: boolean; | ||
}; | ||
/** | ||
* | ||
*/ | ||
export type CreateNotification = { | ||
userId: string; | ||
sendMessage?: SendNotification; | ||
message: string; | ||
}; | ||
/** | ||
* | ||
*/ | ||
export type GrantedPermission = { | ||
@@ -94,3 +129,3 @@ id: string; | ||
/** | ||
* @beta | ||
* | ||
*/ | ||
@@ -101,2 +136,3 @@ export type Link = { | ||
limit: number; | ||
description: string; | ||
users: string[]; | ||
@@ -108,3 +144,2 @@ url: string; | ||
* The possible login types. | ||
* @beta | ||
*/ | ||
@@ -127,3 +162,3 @@ export declare enum LoginType { | ||
/** | ||
* @beta | ||
* | ||
*/ | ||
@@ -134,3 +169,3 @@ export type Doc = { | ||
/** | ||
* @beta | ||
* | ||
*/ | ||
@@ -141,3 +176,3 @@ export type AnyDoc = Doc & { | ||
/** | ||
* @beta | ||
* | ||
*/ | ||
@@ -149,3 +184,3 @@ export type SubscribeListener<T extends Doc> = (changes: { | ||
/** | ||
* @beta | ||
* | ||
*/ | ||
@@ -159,3 +194,2 @@ export type BazaarMessage = { | ||
* logical operators except for contains, which checks if an element is part of an array. | ||
* @beta | ||
*/ | ||
@@ -210,4 +244,2 @@ export type FilterComparison = { | ||
* would result in "((height \> 80 AND height \< 140) OR (weight \> 10 AND weight \< 25)) AND (age \< 12)" | ||
* | ||
* @beta | ||
*/ | ||
@@ -226,4 +258,2 @@ export type FilterObject = { | ||
* ``` | ||
* | ||
* @beta | ||
*/ | ||
@@ -234,3 +264,3 @@ export type OrderBy = { | ||
/** | ||
* @beta | ||
* | ||
*/ | ||
@@ -242,3 +272,3 @@ export declare enum OrderByType { | ||
/** | ||
* @beta | ||
* | ||
*/ | ||
@@ -248,6 +278,7 @@ export type User = { | ||
name: string; | ||
handle: string; | ||
email: string | undefined; | ||
}; | ||
/** | ||
* @beta | ||
* | ||
*/ | ||
@@ -297,1 +328,9 @@ export type Contact = { | ||
}; | ||
/** | ||
* @alpha | ||
*/ | ||
export type MirrorOptions<T extends Doc> = { | ||
onAdd?: (doc: T) => Promise<void>; | ||
onChange?: (oldDoc: T, newDoc: T) => Promise<void>; | ||
onDelete?: (doc: T) => Promise<void>; | ||
}; |
@@ -19,2 +19,4 @@ /** | ||
} | ||
export declare function isNoAppUserError(e: Error): boolean; | ||
export declare function isNoPermissionError(e: Error): boolean; | ||
/** | ||
@@ -21,0 +23,0 @@ * Generates a secure random string using the browser crypto functions |
{ | ||
"name": "@bzr/bazaar", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "The Bazaar SDK. Conveniently use Bazaar with your app in the browser.", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -0,1 +1,4 @@ | ||
[![NPM Version](https://img.shields.io/npm/v/bzr/bazaar.svg?style=flat)](https://www.npmjs.com/package/@bzr/bazaar) | ||
[![NPM License](https://img.shields.io/npm/l/all-contributors.svg?style=flat)](https://github.com/bzr-sys/bazaar-js/blob/master/LICENSE) | ||
# The Bazaar JavaScript SDK | ||
@@ -29,2 +32,6 @@ | ||
## Environments | ||
The option `bazaarUri` will default to `https://cloud.bzr.dev` unless `NODE_ENV=development`. In a dev environment, it defaults to `http://localhost:3377`, the location of the [mock Bazaar server](https://www.npmjs.com/package/@bzr/bazaar-mock). | ||
## Next.js Caveats | ||
@@ -31,0 +38,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
171335
16
2887
69