UNPKG

@cobuildlab/8base-utils

Version:

This is package to deal with common scenarios working with 8base platform

75 lines (74 loc) 2.7 kB
import { ResponseBody } from './types'; /** * Validates a value for null, undefined or blank. * * @param {any}value - The Value. * @param {string} errorPrefix - An error prefix. * @private */ export declare const _validateNullOrUndefinedOrBlank: (value: any, errorPrefix: string) => void | never; /** * Validates that an object has a valid fileId property. * * @param {object}file - The object to be validated. * @param errorPrefix - An error prefix for the Error. * @private */ export declare const _validateFile: (file: any, errorPrefix: string) => void | never; /** * Validates that an object is a valid list of objects with fileId properties. * * @param {Array}files - The objects to be validated. * @param errorPrefix - An error prefix for the Error. * @private */ export declare const _validateFiles: (files: any, errorPrefix: string) => void | never; /** * Validates that an object has a valid id property. * * @param {object}obj - The object to be validated. * @param errorPrefix - An error prefix for the Error. * @private */ export declare const _validateReference: (obj: any, errorPrefix: string) => void | never; /** * Validates that an object is a valid list of objects with id properties. * * @param {Array}objs - The objects to be validated. * @param errorPrefix - An error prefix for the Error. * @private */ export declare const _validateReferences: (objs: any, errorPrefix: string) => void | never; /** * Parses the GraphQL error to JSON to get its message. * If a GraphQL message is not found, it will return the error's message instead. * * @param {Error} error - The graphql error. * @returns {string} The error with the parsed message. */ export declare function getMessageFromGraphQLError(error: Error): string; /** * Http response builder. * * @param code - Http status code. * @param message - Message to response. * @param headers - Http headers. * @returns Response object. */ export declare const responseBuilder: (code?: number, message?: string | undefined, headers?: Record<string, unknown> | undefined) => ResponseBody; /** * Checks that the current environment is the one given. * * @param env - The environment in which code is running, production|development|test. * * @returns Result of comparing the equality between the given env and the current NODE_ENV. */ export declare const isEnvironment: (env: string) => boolean; /** * Logs the error in Cloud Function. * * @param title - Title of the error to. * @param err - The error object thrown. * @param data - Data to identify the function state in the moment of the error. */ export declare const report: (title: string, err: Error, data?: {}) => void;