UNPKG

ministry-platform-provider

Version:

TypeScript client library for Ministry Platform API integration

179 lines (178 loc) 8.82 kB
import { TableQueryParams, ProcedureInfo, CommunicationInfo, Communication, MessageInfo, DomainInfo, GlobalFilterItem, GlobalFilterParams, TableRecord, FileDescription, FileUploadParams, FileUpdateParams, TableMetadata, QueryParams } from "./Interfaces/mpProviderInterfaces.js"; /** * ministryPlatformProvider - Core Provider Singleton * * Central orchestrator for all Ministry Platform operations using the Singleton pattern. * Manages service instances and provides a unified interface for: * - Table operations (CRUD) * - Stored procedure execution * - Communication/messaging * - File management * - Metadata operations * - Domain configuration * * All services share a single MinistryPlatformClient instance for consistent * authentication and configuration management. */ export declare class ministryPlatformProvider { private static instance; private client; private tableService; private procedureService; private communicationService; private metadataService; private domainService; private fileService; /** * Private constructor for Singleton pattern * Initializes the core client and all specialized service instances */ private constructor(); /** * Returns the singleton instance of the Ministry Platform provider * Creates the instance on first call, returns existing instance on subsequent calls * @returns The singleton ministryPlatformProvider instance */ static getInstance(): ministryPlatformProvider; /** * Returns the basic information about the current domain. * @returns Promise with the domain information */ getDomainInfo(): Promise<DomainInfo>; /** * Returns the lookup values to be used as global filters. * @param params Optional parameters for the global filters request * @returns Promise with an array of global filter items */ getGlobalFilters(params?: GlobalFilterParams): Promise<GlobalFilterItem[]>; /** * Triggers an update of the metadata cache on all servers and in all applications. * @returns Promise with the response from the API */ refreshMetadata(): Promise<void>; /** * Returns the list of tables available to the current user with basic metadata. * @param search Optional search term to filter tables * @returns Promise with an array of TableInfo objects */ getTables(search?: string): Promise<TableMetadata[]>; /** * Returns the list of records from the specified table satisfying the provided search criteria. * @param table Table to retrieve records from * @param params Query parameters for filtering, sorting, etc. * @returns Promise with an array of records */ getTableRecords<T>(table: string, params?: TableQueryParams): Promise<T[]>; /** * Creates new records in the specified table. * @param table Table where records need to be created * @param records Array of records to be added to the table * @param params Additional query parameters * @returns Promise with the created records */ createTableRecords<T extends TableRecord = TableRecord>(table: string, records: T[], params?: Pick<TableQueryParams, '$select' | '$userId'>): Promise<T[]>; /** * Updates provided records in the specified table. * @param table Table where records need to be updated * @param records Array of records to be updated in the table * @param params Additional query parameters * @returns Promise with the updated records */ updateTableRecords<T extends TableRecord = TableRecord>(table: string, records: T[], params?: Pick<TableQueryParams, '$select' | '$userId' | '$allowCreate'>): Promise<T[]>; /** * Deletes multiple records from the specified table. * @param table Table where records need to be deleted * @param ids Array of identifiers corresponding to records to be deleted * @param params Additional query parameters * @returns Promise with the deleted records */ deleteTableRecords<T extends TableRecord = TableRecord>(table: string, ids: number[], params?: Pick<TableQueryParams, '$select' | '$userId'>): Promise<T[]>; /** * Returns the list of procedures available to the current user with basic metadata. * @param search Optional search term to filter procedures * @returns Promise with an array of ProcedureInfo objects */ getProcedures(search?: string): Promise<ProcedureInfo[]>; /** * Executes the requested stored procedure retrieving parameters from the query string. * @param procedure Stored procedure name * @param params Query parameters to pass to the procedure * @returns Promise with the procedure results */ executeProcedure(procedure: string, params?: QueryParams): Promise<unknown[][]>; /** * Executes the requested stored procedure with provided parameters in the request body. * @param procedure Stored procedure name * @param parameters Parameters to be used for calling stored procedure * @returns Promise with the procedure results */ executeProcedureWithBody(procedure: string, parameters: Record<string, unknown>): Promise<unknown[][]>; /** * Creates a new communication, immediately renders it and schedules for delivery. * Supports both simple JSON communication and multipart form data with file attachments. * @param communication Communication information object * @param attachments Optional array of file attachments * @returns Promise with the created communication */ createCommunication(communication: CommunicationInfo, attachments?: File[]): Promise<Communication>; /** * Creates email messages from the provided information and immediately schedules them for delivery. * Supports both simple JSON message and multipart form data with file attachments. * @param message Message information object * @param attachments Optional array of file attachments * @returns Promise with the created communication */ sendMessage(message: MessageInfo, attachments?: File[]): Promise<Communication>; /** * Returns the metadata (descriptions) of the files attached to the specified record. * @param table Table name where the record exists * @param recordId ID of the record to get files for * @param defaultOnly Optional flag to return only default files * @returns Promise with an array of file descriptions */ getFilesByRecord(table: string, recordId: number, defaultOnly?: boolean): Promise<FileDescription[]>; /** * Uploads and attaches multiple files to the specified record. * @param table Table name where the record exists * @param recordId ID of the record to attach files to * @param files Array of files to upload * @param params Optional upload parameters * @returns Promise with an array of uploaded file descriptions */ uploadFiles(table: string, recordId: number, files: File[], params?: FileUploadParams): Promise<FileDescription[]>; /** * Updates the content and/or metadata of the file corresponding to provided identifier. * @param fileId ID of the file to update * @param file Optional new file content * @param params Optional update parameters * @returns Promise with the updated file description */ updateFile(fileId: number, file?: File, params?: FileUpdateParams): Promise<FileDescription>; /** * Deletes the file corresponding to provided identifier. * @param fileId ID of the file to delete * @param userId Optional user ID for auditing * @returns Promise that resolves when file is deleted */ deleteFile(fileId: number, userId?: number): Promise<void>; /** * Returns the content of the file corresponding to provided globally unique identifier. * This method does NOT require authentication. * @param uniqueFileId Globally unique file identifier * @param thumbnail Optional flag to get thumbnail version * @returns Promise with the file content as a Blob */ getFileContentByUniqueId(uniqueFileId: string, thumbnail?: boolean): Promise<Blob>; /** * Returns the file metadata (description) corresponding to provided database identifier. * @param fileId Database ID of the file * @returns Promise with the file description */ getFileMetadata(fileId: number): Promise<FileDescription>; /** * Returns the file metadata (description) corresponding to provided globally unique identifier. * @param uniqueFileId Globally unique file identifier * @returns Promise with the file description */ getFileMetadataByUniqueId(uniqueFileId: string): Promise<FileDescription>; }