import type { APIOptions, Permission, NewPermission, SubscribeListener, BazaarMessage, Contact, User, GrantedPermission, PermissionTemplate, Doc, BasicLink, ContextOptions, CollectionGetAllOptions, CollectionQueryOptions, SharingNotification, Notification, CreateNotification, Org, Team, PermissionGroup, LinksQuery, PermissionsQuery, GrantedPermissionsQuery, NewPermissionGroup, EmailMessage, CalendarInvite } from "../types"; /** * The class that encapsulates the low level data API * @internal */ export declare class API { /** * Version of the API */ private version; /** * URI for the Data API, Bazaar's realtime data storage service. */ private bazaarUri; /** * Local storage key names, namespaced in the constructor */ private tokenKeyName; /** * A Socket.IO connection to the Data API */ private dataApi; /** * 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 */ onConnect: () => Promise; /** * A callback to do something when a Data API connection error occurs */ onConnectError: (message: string) => Promise; /** * The modal and iframe element to perform actions within the BazaarApp context */ private modal; private iframe; constructor(options: APIOptions, onConnect: () => Promise, onConnectError: (message: string) => Promise); /** * Creates a Data API connection with an auth token */ connect(): void; /** * Makes sure a connection to the Data API has been made. */ private waitForConnection; /** * Promisifies a Data API emit event * * @param event - A Data API event name, like `collections:create` * @param payload - */ private asyncEmit; /** * Create context * * @param options - An optional object for specifying query options. * @returns BazaarMessage */ createContext(options?: ContextOptions): Promise<{ message: string; }>; /** * Gets a collection doc * * @param collectionName - The name of the collection to read * @param docId - The doc ID * @param options - An optional object for specifying query options. * @returns Specify a doc ID to get a specific doc, otherwise all docs are returned. Specify a user ID to operate on a collection owned by that user ID. Otherwise operates on a collection owned by the authenticated user. */ collectionGetOne(collectionName: string, docId: string, options?: ContextOptions): Promise<{ data: T | null; }>; /** * Gets all collection documents for a given filter. * * @param collectionName - The name of the collection to read. * @param options - An optional object for specifying query options. * @returns Returns a specific document if a `docId` is specified; otherwise, returns all documents. If a `userId` is specified, it operates on a collection owned by that user ID. Otherwise, it operates on a collection owned by the authenticated user. */ collectionGetAll(collectionName: string, options?: CollectionGetAllOptions): Promise<{ data: T[]; }>; /** * Subscribes to doc changes. * * @param collectionName - The name of the collection to subscribe to * @param docId - The document ID * @param options - An optional object for specifying query options. * @param listener - The callback function that receives document change events. * @returns An unsubscribe function */ collectionSubscribeOne(collectionName: string, docId: string, options: ContextOptions, listener: SubscribeListener): Promise<() => Promise>; /** * Subscribes to collection changes. Private by default, or public with read permission. * * @param collectionName - The name of the collection to subscribe to. * @param options - An optional object for specifying query options. * @param listener - The callback function that receives document change events. * @returns An unsubscribe function */ collectionSubscribeAll(collectionName: string, options: CollectionQueryOptions, listener: SubscribeListener): Promise<() => Promise>; /** * Inserts a collection doc. * * @param collectionName - The name of the collection to operate on. * @param doc - The doc to insert. * @param options - An optional object for specifying query options. * @returns Where `data` is the array of new doc IDs (only generated IDs) */ collectionInsertOne(collectionName: string, doc: object, options?: ContextOptions): Promise<{ data: string; }>; /** * Updates all collection docs, or a single doc if doc ID exists. * * @param collectionName - The name of the collection to operate on. * @param docId - ID of document to update * @param doc - Document changes * @param options - An optional object for specifying query options. */ collectionUpdateOne(collectionName: string, docId: string, doc: object, options?: ContextOptions): Promise; /** * Replaces a collection doc. Private by default, or public with insert, update, delete permissions. * * @param collectionName - The name of the collection to operate on. * @param docId - ID of document to replace. * @param doc - The new doc. * @param options - An optional object for specifying query options. */ collectionReplaceOne(collectionName: string, docId: string, doc: object, options?: ContextOptions): Promise; /** * Deletes a doc * * @param collectionName - The name of the collection to operate on. * @param docId - ID of document to delete * @param options - An optional object for specifying query options. */ collectionDeleteOne(collectionName: string, docId: string, options?: ContextOptions): Promise; /** * Deletes all collection docs matching an optional filter. * * @param collectionName - The name of the collection to operate on. * @param options - An optional object for specifying query options. */ collectionDeleteAll(collectionName: string, options?: CollectionQueryOptions): Promise; /** * Creates a collection. */ collectionsCreate(collectionName: string, options?: ContextOptions): Promise; /** * Drops a collection. */ collectionsDrop(collectionName: string, options?: ContextOptions): Promise; /** * Lists all collection names. * @returns Where `data` is an array of collection names */ collectionsList(options?: ContextOptions): Promise<{ data: string[]; }>; /** * Lists permissions. * * @param query - If no options are set, all permissions are returned. * @param options - database ID options. * @returns All permissions matching query options. */ permissionsList(query?: PermissionsQuery, options?: ContextOptions): Promise<{ data: Permission[]; }>; /** * Creates a permission. */ permissionsCreate(permission: NewPermission, notification: SharingNotification, options?: ContextOptions): Promise<{ id: string; }>; /** * Deletes a permission. * * @param permissionId - The ID of the permission to delete. */ permissionsDelete(permissionId: string, options?: ContextOptions): Promise; /** * Creates a permission link. */ linksCreate(permission: PermissionTemplate, description?: string, limit?: number, options?: ContextOptions): Promise<{ data: BasicLink; }>; /** * Lists permission links. * * @param query - If no options are set, all links are returned. * @param options - database ID options. * @returns Where `data` is an array of links */ linksList(query?: LinksQuery, options?: ContextOptions): Promise<{ data: BasicLink[]; }>; /** * Subscribes to link changes * * @param query - * @param options - * @param listener - The callback function that receives link change events. * @returns An unsubscribe function */ linksSubscribe(query: LinksQuery, options: ContextOptions, listener: SubscribeListener): Promise<() => Promise>; /** * Deletes permission links. */ linksDelete(linkId: string): Promise; /** * Lists granted permissions * * @returns a list of granted permissions */ grantedPermissionsList(query: GrantedPermissionsQuery, options: ContextOptions): Promise<{ data: GrantedPermission[]; }>; /** * Subscribes to granted permissions changes * * @param listener - The callback function that receives granted permissions change events. * @returns An unsubscribe function */ grantedPermissionsSubscribe(query: GrantedPermissionsQuery, options: ContextOptions, listener: SubscribeListener): Promise<() => Promise>; /** * Deletes a granted permission * * @param grantedPermissionId - The ID of the granted permission to delete */ grantedPermissionsDelete(grantedPermissionId: string): Promise; /** * Get a group * * @param groupId - The ID of the group to get. */ groupsGet(groupId: string, options?: ContextOptions): Promise<{ data: PermissionGroup; }>; /** * Lists groups. * * @param options - database ID options. * @returns All groups matching query. */ groupsList(options?: ContextOptions): Promise<{ data: PermissionGroup[]; }>; /** * Creates a group. */ groupsCreate(group: NewPermissionGroup, options?: ContextOptions): Promise<{ id: string; }>; /** * Add member to a group. * * @param groupId - The ID of the group * @param userId - The ID of the user * @param options - database ID options. */ groupsAddMember(groupId: string, userId: string, options?: ContextOptions): Promise; /** * Remove member from a group. * * @param groupId - The ID of the group * @param userId - The ID of the user * @param options - database ID options. * */ groupsRemoveMember(groupId: string, userId: string, options?: ContextOptions): Promise; /** * Deletes a group. * * @param groupId - The ID of the group to delete. */ groupsDelete(groupId: string, options?: ContextOptions): Promise; /** * Creates a notification. */ notificationsCreate(notification: CreateNotification): Promise<{ data: Notification; }>; /** * Lists notifications. * * @param options - If no options are set, all non-hidden notifications are returned. * @returns Where `data` is an array of notifications */ 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): Promise<() => Promise>; /** * Hides notifications. */ notificationsHide(notificationId: string): Promise; /** * Deletes notifications. */ notificationsDelete(notificationId: string): Promise; /** * 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; }>; /** * Lists contacts * @returns a list of contacts */ contactsList(): Promise<{ data: Contact[]; }>; /** * Subscribes to contacts changes * * @param listener - The callback function that receives contact change events. * @returns An unsubscribe function */ contactsSubscribe(listener: SubscribeListener): Promise<() => Promise>; /** * Gets all orgs user is member/admin. */ organizationsList(): Promise<{ data: Org[]; }>; /** * Gets the org info for a given ID or handle. * @param payload - The ID or handle of the org, requires one of the two. */ organizationsGet(payload: { userId?: string; handle?: string; }): Promise<{ data: Org; }>; /** * Lists teams * @returns a list of teams */ teamsList(payload: { type?: "user" | "org"; }): Promise<{ data: Team[]; }>; /** * Send email message * @returns */ emailSendMessage(emailMessage: EmailMessage): Promise<{ message: string; }>; /** * Send email event * @returns */ emailSendCalendarInvite(calendarInvite: CalendarInvite): Promise<{ message: string; }>; private onModalMessage; private onModalClose; private closeModal; /** * Opens a modal */ openModal(path: string, onMessage?: ((msg: string) => void) | undefined, onClose?: (() => void) | undefined): void; /** * Creates and appends a modal to the DOM */ initializeModal(): void; }