UNPKG

encompassconnect

Version:

An Unofficial, (mostly) typed Node SDK that wraps around Ellie Mae's Encompass RESTful API.

173 lines (172 loc) 7.11 kB
/** * @packageDocumentation * @module EncompassConnectClass */ import { Response, RequestInit } from 'node-fetch'; import { EncompassConnectInitOptions, InternalRequestOptions, PipeLineContract, BatchLoanUpdateContract, BatchUpdate, TokenIntrospection, AuthenticationHook } from './types'; import { LoanService, MilestoneService, SchemaService, UserService } from './services'; declare class EncompassConnect { #private; /** * The username of the account to retrieve tokens with. Only stores the value provided to the constructor. */ username: string; /** * The domain of the Encompass API. */ base: string; loans: LoanService; milestones: MilestoneService; schemas: SchemaService; users: UserService; /** * @ignore */ authBase: string; /** * The version of the Encompass API to send requests to. Defaults to `1`. */ version: number; /** * The User provided hook to be invoked when a token is not yet set. */ onAuthenticate: AuthenticationHook | undefined; onAuthenticateFailure: AuthenticationHook | undefined; constructor({ clientId, APIsecret, instanceId, username, password, onAuthenticate, onAuthenticateFailure, version, }: EncompassConnectInitOptions); /** * Replaces the `#token` property with the provided token value. The instance can be implicitly 'logged out' by setting this value to `null` (if it was not provided a username and password in the constructor). */ setToken(token: string | null): void; /** * @ignore */ private withTokenHeader; /** * @ignore */ private handleAuthFailure; /** * @ignore */ fetchWithRetry(path: string, options?: RequestInit, customOptions?: InternalRequestOptions): Promise<any>; /** * Returns the token that is stored in the instance. */ getToken(): string | null; /** * Exchanges the provided username and password for a bearer token and stores it to the `#token` property of the instance. * If no username and password are provided, it will fallback to the username and password values provided to the constructor. */ getTokenWithCredentials(username?: string, password?: string): Promise<void>; /** * Calls the token introspection API with the provided token. If a token is not provided, it will introspect the token stored to the `#token` property of the instance as a fallback. * If the introspection returns a valid token, it will return the response body of the request, if the token is invalid, returns `null`. */ introspectToken(token?: string): Promise<TokenIntrospection | null>; /** * Returns the result of the 'Get Canonical Names' endpoint. */ getCanonicalNames(): Promise<any>; /** * Generate a pipeline view by calling the `viewPipeline()` method. This method has one required argument, a `PipeLineContract`, and can optionally take a limit value as the second argument: * * ```typescript * // a pipelineContract expects either a loanGuids array, or a filter object: * const commonFilterValues = { * sortOrder: [ * { * canonicalName: 'Loan.LastModified', * order: 'desc' * } * ], * fields: [ * "Loan.LoanAmount", * "Fields.4002" * ], * }; * * const pipelineWithGuids: LoanGuidsPipeLineContract = { * ...commonFilterValues, * loanGuids: [ * 'some-loan-guid-1', * 'some-loan-guid-2', * ], * }; * * const pipelineWithFilter: FilterPipeLineContract = { * ...commonFilterValues, * filter: { * operator: 'and', * terms: [ * { * canonicalName: "Loan.LastModified", * matchType: "greaterThanOrEquals", * value: new Date() * }, * { * canonicalName: "Loan.LoanFolder", * matchType: "exact", * value: "My Pipeline" * } * ] * }, * }; * * const pipelineDataFromGuids = await encompass.viewPipeline(pipelineWithGuids); * * // or with the other contract, and a limit of the first 50 results: * const pipelineDataFromFilter = await encompass.viewPipeline(pipelineWithFilter, 50); * ``` */ viewPipeline(options: PipeLineContract, limit?: number): Promise<any>; /** * The batch update API allows your to apply the same loan data to multiple loans and can be invoked with `batchLoanUpdate()` method. * * This method returns an object that with it's own functionality to check the status of batch update, or to get the request ID if needed. * * Just like viewing a pipeline, either a filter or an array of lan GUIDs can be provided. * ```typescript * const updateData: BatchLoanUpdateContract = { * loanGuids: [ * // array of loan GUIDs to update * ], * loanData: { * // contract of the loan data to apply to each loan * }, * }; * * const exampleBatchUpdate: BatchUpdate = await encompass.batchLoanUpdate(updateData); * * // the return value can be used to check the status: * const latestStatus: BatchUpdateStatus = await exampleBatchUpdate.getUpdateStatus(); * console.log(latestStatus.status) // 'done' or 'error' * * // or if needed you can get the request ID itself: * const exampleBatchUpdateId: string = exampleBatchUpdate.getRequestId(); * ``` */ batchLoanUpdate(options: BatchLoanUpdateContract): Promise<BatchUpdate>; /** * If an API is not available through an explicit method in this class, the `request()` method is a wrapper around fetch that allows you to request any Encompass API endpoint. * * It takes in the same arguments as any [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API, with the exception that the first argument is appended as a path to the Encompass API domain. * ```typescript * // hitting the Get Custom Fields API: * const customFieldsResponse: Response = await encompass.request('/settings/loan/customFields'); * const data = await customFieldsResponse.json(); * console.log(data); * * // or update a contact: * const options: RequestInit = { * method: 'POST', * body: { * firstname: 'contact first name', * lastname: 'contact last name', * }, * }; * await encompass.request('/businessContacts/<some-contact-id>', options); * ``` */ request(url: string, options?: RequestInit): Promise<Response>; } export default EncompassConnect;