import { BazaarApp } from ".."; /** * Options for initializing a BazaarApp instance */ export type BazaarOptions = { appId: string; /** * The URI the auth server redirects to with an auth code after login request approval. */ loginRedirectUri: string; /** * Public URI for the API & OAuth server. */ bazaarUri?: string; /** * Provide a callback to handle a successful login. * * e.g. Set state, redirect, etc. */ onLogin?: (bzr: BazaarApp) => Promise; /** * Provide a callback to handle a failed login. E.g. invalid authorization code. * * e.g. Set state, redirect, etc. */ onLoginError?: (bzr: BazaarApp, message: string) => Promise; /** * Provide a callback to handle API connections. Will be called after login and any subsequent re-connection. */ onApiConnect?: (bzr: BazaarApp) => Promise; /** * Provide a callback to handle failed data API connections. E.g. unauthorized, or expired token. */ onApiConnectError?: (bzr: BazaarApp, message: string) => Promise; }; export type AuthOptions = Omit; export type APIOptions = Omit; export declare enum GranteeType { USER = "user", ANY = "any", GROUP = "group", ORG = "org" } export type BasePermission = { id: string; collectionName: string; types: PermissionType[]; filter?: FilterObject; }; export type AnyPermission = Prettify; export type UserPermission = Prettify; export type GroupPermission = Prettify; export type OrgPermission = Prettify; export type Permission = AnyPermission | UserPermission | GroupPermission | OrgPermission; /** * Represents a permission object that is yet to be persisted. * It has the same structure as {@link Permission} but without the `id` field. */ export type NewPermission = Omit | Omit | Omit | Omit; /** * Represents the foundational structure of a permission template. * It's derived from the {@link BasePermission} and does not include the ID. */ export type PermissionTemplate = Omit; /** * */ export declare enum PermissionType { READ = "read", INSERT = "insert", UPDATE = "update", DELETE = "delete" } /** * */ export type PermissionGroup = { id: string; label: string; members: string[]; }; export type NewPermissionGroup = Omit; /** * Represents the options for sending notifications. */ export declare enum SendNotification { /** * Send an notification if the target user does not use the app. * This is akin to inviting the target user to use the app. */ INVITE_ONLY = "invite-only", /** * Always send an notification to the target user */ ALWAYS = "always", /** * Never send an notification 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; }; /** * */ export type Notification = { id: string; senderId: string; message: string; ts: Date; hidden: boolean; }; /** * */ export type CreateNotification = { recipientId: string; sendMessage?: SendNotification; message: string; }; /** * */ export type GrantedPermission = { id: string; /** * ID of the resource owner (the sharer) */ ownerId: string; permission: Permission; }; /** * */ export type Link = { id: string; permission: PermissionTemplate; limit: number; description: string; users: string[]; url: string; }; export type BasicLink = Omit; /** * The possible login types. */ export declare enum LoginType { /** * Default login type. * Do pop-up login, if the pop-up fails to open, fallback to redirect. */ POPUP_FALLBACK = "popup_fallback", /** * Do pop-up login only. Do not fallback to redirect. */ POPUP = "popup", /** * Do redirect login. Do not open a pop-up. */ REDIRECT = "redirect" } /** * */ export type Doc = { id: string; }; /** * */ export type AnyDoc = Prettify; export type DeepPartial = { [P in keyof T]?: T[P] extends (infer U)[] ? DeepPartial[] : T[P] extends object | undefined ? DeepPartial : T[P]; }; /** * */ export type RawSubscribeListener = (changes: { newDoc: T | null; oldDoc: T | null; }) => void; /** * */ export type SubscribeListener = { onAdd?: (doc: T) => void; onChange?: (oldDoc: T, newDoc: T) => void; onDelete?: (doc: T) => void; onInitial?: (doc: T) => void; }; /** * */ export type BazaarMessage = { message: string; }; /** * A FilterComparison is an object, that applies a set of comparison operators. * Multiple properties are combined with AND. Most comparison operators are self-explanatory * logical operators except for contains, which checks if an element is part of an array. */ export type FilterComparison = { /** Equal */ $eq?: string | number; /** Not equal */ $ne?: string | number; /** Greater than */ $gt?: string | number; /** Greater than or equal */ $ge?: string | number; /** Less than */ $lt?: string | number; /** Less than or equal */ $le?: string | number; /** Selects docs where an array field contains the specified value. */ $contains?: string | number; }; /** * A FilterObject is an object that either maps * - string keys to string | number | boolean | null. This corresponds to an equality operation * - string keys to FilterComparison. This corresponds to the operation defined in FilterComparison * - $and to FilterObject[]. This combines the result of each FilterObject in the array with AND * - $or to FilterObject[]. This combines the result of each FilterObject in the array with OR * - $not to FilterObject. This applies NOT to the result of the FilterObject * * All fields in a FilterObject are combined with an AND. * * @example * The FilterObject * ``` * { * $or: [ * { * height: { * $gt: 80, * $lt: 140, * }, * }, * { * weight: { * $gt: 10, * $lt: 25, * }, * }, * ], * age: { $lt: 12 }, * } * ``` * would result in "((height \> 80 AND height \< 140) OR (weight \> 10 AND weight \< 25)) AND (age \< 12)" */ export type FilterObject = { $and?: FilterObject[]; $or?: FilterObject[]; $not?: FilterObject; [field: string]: FilterComparison | string | number | boolean | null | FilterObject | FilterObject[]; }; /** * An OrderBy object specifies orderings of results. * @example * ``` * { height: "desc", age: "asc" } * ``` */ export type OrderBy = { [field: string]: OrderByType; }; /** * */ export declare enum OrderByType { ASC = "asc", DESC = "desc" } /** * */ export type User = { id: string; name: string; handle: string; email: string | undefined; }; /** * */ export type Contact = { id: string; /** * Flag to signal if contact is connected (you are trusted by this contact) */ connected: boolean; /** * The resolved user object */ user: User; }; export type Org = { id: string; name: string; handle: string; primaryTeam: Team; active: boolean; admins: string[]; }; /** * */ export type Team = { id: string; name: string; ownerType: "user" | "org"; ownerId: string; primary: boolean; admins: string[]; members: string[]; }; export type CollectionOptions = { onCreate?: () => Promise; }; /** * Options that helps identify the context. Used for several methods in {@link API} * Currently the context is only determined by the ownerId */ export type ContextOptions = { ownerId?: string; }; /** * Options for {@link API.collectionSubscribeAll} and {@link API.collectionDeleteAll} */ export type CollectionQueryOptions = Prettify; /** * Options for {@link API.collectionGetAll} */ export type CollectionGetAllOptions = Prettify; export type PermissionsQuery = { collectionName?: string; granteeType?: GranteeType; granteeId?: string; type?: PermissionType; }; export type LinksQuery = { collectionName?: string; type?: PermissionType; }; export type GrantedPermissionsQuery = { collectionName?: string; ownerId?: string; type?: PermissionType; }; export type EmailAttachement = { filename: string; content: string; }; export type IcalEvent = { method: "publish" | "request" | "reply" | "cancel"; content: string; }; export type EmailMessage = { toUserIds: string[]; subject: string; text?: string; html?: string; attachements?: EmailAttachement[]; icalEvent?: IcalEvent; }; export type CalendarInvite = { userIds: string[]; eventName: string; message: string; startTs: Date; endTs: Date; location?: string; }; type Prettify = { [K in keyof T]: T[K]; } & {}; export {};