UNPKG

@openinc/parse-server-opendash

Version:
197 lines (196 loc) 10.2 kB
import type { Cloud as ParseCloud } from "parse"; import { Permission } from "./types"; export { sendSimpleEmail, sendTemplateEmail } from "./hooks/Core_Email"; /** * Initializes the Cloud Code for open.DASH. * This function performs various initialization tasks such as * initializing configuration, setting up email transport, initializing web push, * initializing class schema, setting up default roles, initializing parse lifecycle hooks, * loading default data, initializing cloud functions, and setting up cloud code autoloading. * * @returns {Promise<void>} A promise that resolves when the initialization is complete. */ export declare function init(): Promise<void>; /** * Checks if a user has a specific permission in OD3_Permission. * @param sessionToken - The session token of the user. * @param key - The key of the permission to check. * @returns A promise that resolves to a boolean indicating whether the user has the permission. */ export declare function hasPermission(sessionToken: string, key: string): Promise<boolean>; /** * Checks if the user has the required permission to perform an operation using hasPermission(). * If the user does not have the required permission, an error is thrown. * * @param request - The request object containing the user's session token and masterkey status. * @param key - The permission key required for the operation. * @param message - The error message to be thrown if the user does not have the required permission. * @returns A Promise that resolves if the user has the required permission, or throws an error if not. */ export declare function requirePermission(request: { master?: boolean; sessionToken: string | undefined; }, key: string | null, message: string): Promise<void>; /** * Retrieves the value of a configuration key from OD3_Config. * @param key - The key of the configuration to retrieve. * @returns A promise that resolves to the value of the configuration key, or undefined if not found. */ export declare function getConfig(key: string): Promise<string | undefined>; /** * Retrieves the value of a configuration key from OD3_Config as a boolean * Converts the string value to a boolean value using the following rules: * - "true" or "1" -> true * - "false" or "0" -> false * - undefined/null -> false * - Any other value -> true * * @param key - The key of the configuration value. * @returns A boolean value indicating the configuration value. */ export declare function getConfigBoolean(key: string): Promise<boolean>; /** * Ensures the existence of a role with the specified name. * If the role does not exist, it creates a new role with the given name and options. * If the role already exists, it updates the role with the provided options. * * @param name - The name of the role. * @param options - Optional parameters for the role. * @param options.label - The label for the role. * @param options.acl - The Parse.ACL for the role. * @param options.childRoles - An array of child role names to be associated with the role. * @returns A Promise that resolves when the role is successfully created or updated. */ export declare function ensureRole(name: string, options?: { label?: string; acl?: Parse.ACL; childRoles?: string[]; }): Promise<void>; /** * Ensures that a user has a specific role. * @param user The user to assign the role to. * @param roleName The name of the role. * @param add Specifies whether to add or remove the user from the role. Default is false (remove). */ export declare function ensureUserRole(user: Parse.User, roleName: string, add?: boolean): Promise<void>; /** * Checks if a field is immutable and throws an error if an attempt is made to edit it in a beforeSave hook. * * This will not throw an error if the request is made with the master key. * * @param request - The request object containing the original and object Parse objects, master flag, and session token. * @param fieldName - The name of the field to check for immutability. * @param permissionName - The name of the permission required to edit the field. Defaults to "parse:edit-immutable-fields". * @returns Promise<void> */ export declare function immutableField(request: { original?: Parse.Object; object: Parse.Object; master?: boolean; sessionToken: string | undefined; }, fieldName: string, permissionName?: string | null): Promise<void>; /** * Handles the default beforeSave() logic for a Parse.Object. * * This function will check if a user or tenant field is present in the schema and set the value to the current user and/or the tenant of the current user if not provided. * This will also mark the user and tenant fields as immutable, preventing them from being edited in the future. * * @param request - The Parse.Cloud.BeforeSaveRequest object. * @returns - Returns void. * @throws - Throws an error if the user is not provided. */ export declare function defaultHandler(request: { original?: Parse.Object; object: Parse.Object; user?: Parse.User; master?: boolean; sessionToken: string | undefined; }): Promise<void>; /** * Handles the default Parse.ACL beforeSave() logic for a Parse.Object. * * This function will set the default ACL for the object based on the user and tenant fields. By default, the object will be readable and writable by the tenant role and readable by tenant users. * * @param request - The Parse.Cloud.BeforeSaveRequest object. * @param options - Optional configuration options. * @param options.allowCustomACL - Whether to allow custom ACL (default: false). * @param options.allowTenantUserWrite - Whether to allow tenant users to write (default: false). * @param options.denyTenantUserRead - Whether to deny tenant users from reading (default: false). */ export declare function defaultAclHandler(request: Parse.Cloud.BeforeSaveRequest, options?: { allowCustomACL?: boolean; allowTenantUserWrite?: boolean; denyTenantUserRead?: boolean; }): Promise<void>; type beforeSaveHookType<T extends Parse.Object<Parse.Attributes>> = (request: ParseCloud.BeforeSaveRequest<T> & { sessionToken: string | undefined; }) => Promise<void>; /** * Registers a beforeSave hook for a Parse class. In comparison to Parse.Cloud.beforeSave(), this function allows multiple beforeSave hooks to be registered for the same class. * * @template T - The type of the Parse.Object. * @param {string | { new (): T }} target - The name of the Parse class or the class itself. * @param {beforeSaveHookType<T>} callback - The callback function to be executed before saving the object. * @returns {void} */ export declare function beforeSaveHook<T extends Parse.Object<Parse.Attributes>>(target: string | { new (): T; }, callback: beforeSaveHookType<T>): void; type afterSaveHookType<T extends Parse.Object<Parse.Attributes>> = (request: ParseCloud.AfterSaveRequest<T> & { sessionToken: string | undefined; }) => Promise<void>; /** * Registers a afterSave hook for a Parse class. In comparison to Parse.Cloud.afterSave(), this function allows multiple beforeSave hooks to be registered for the same class. * * @template T - The type of the Parse.Object. * @param {string | { new (): T }} target - The name of the Parse class or the class itself. * @param {afterSaveHookType<T>} callback - The callback function to be executed after saving the object. * @returns {void} */ export declare function afterSaveHook<T extends Parse.Object<Parse.Attributes>>(target: string | { new (): T; }, callback: afterSaveHookType<T>): void; type beforeDeleteHookType<T extends Parse.Object<Parse.Attributes>> = (request: ParseCloud.BeforeDeleteRequest<T> & { sessionToken: string | undefined; }) => Promise<void>; /** * Registers a beforeDelete hook for a Parse class. In comparison to Parse.Cloud.beforeDelete(), this function allows multiple beforeSave hooks to be registered for the same class. * * @template T - The type of the Parse.Object. * @param {string | { new (): T }} target - The name of the Parse class or the class itself. * @param {beforeDeleteHookType<T>} callback - The callback function to be executed before deleting an object. */ export declare function beforeDeleteHook<T extends Parse.Object<Parse.Attributes>>(target: string | { new (): T; }, callback: beforeDeleteHookType<T>): void; type afterDeleteHookType<T extends Parse.Object<Parse.Attributes>> = (request: ParseCloud.AfterDeleteRequest<T> & { sessionToken: string | undefined; }) => Promise<void>; /** * Registers a afterDelete hook for a Parse class. In comparison to Parse.Cloud.afterDelete(), this function allows multiple beforeSave hooks to be registered for the same class. * * @template T - The type of the Parse.Object. * @param {string | { new (): T }} target - The name of the Parse class or the class itself. * @param {afterDeleteHookType<T>} callback - The callback function to be executed after a delete operation. * @returns {void} */ export declare function afterDeleteHook<T extends Parse.Object<Parse.Attributes>>(target: string | { new (): T; }, callback: afterDeleteHookType<T>): void; /** * Autoloads cloud code files from the specified path. Each file MUST export an init() function that takes the file name (without it's extension) as an argument. * * @param path - The path to the directory containing the cloud code files. * @param regex - Optional regular expression to filter the file names. Defaults to /^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$/. * @returns A promise that resolves when all the cloud code files have been loaded and initialized. */ export declare function autoloadCloudCode(path: string, regex?: RegExp): Promise<void>; /** * Ensures that a OD3_Permission with the specified key exists in the database. * If the permission already exists, it updates the ACL if provided. * If the permission does not exist, it creates a new permission with the specified key and ACL. * @param key - The key of the permission. * @param acl - The Parse.ACL to be set for the permission. * @returns The updated or newly created permission. */ export declare function ensurePermission(key: string, acl?: Parse.ACL): Promise<Permission>;