UNPKG

bc-node-sdk

Version:

BetterCommerce's NodeJS SDK encapsulates the base framework for all the Next.js applications.

61 lines (60 loc) 2.93 kB
import { ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies"; /** * Class {@link AppUtil} encapsulates the utility methods for various application-related tasks. */ export default abstract class AppUtil { /** * Retrieves the user id from the given SSO user id. * * @param ssoUserId the SSO user id to decrypt * @returns the user id if the decryption is successful, otherwise an empty string */ static getLoggedInUserId(ssoUserId: string): string; /** * Returns all cookies from the given cookie object as a JavaScript object. * @param {ReadonlyRequestCookies} cookies The cookie object to get the cookies from. * @returns {object} A JavaScript object containing all the cookies, where each * property is a cookie name and the corresponding value is the cookie's value. */ static allCookies(cookies: ReadonlyRequestCookies): any; /** * Disables React Developer Tools. * * This method is a modified version of the method described in * https://stackoverflow.com/questions/56708167/how-to-disable-react-devtools-in-production-mode * to disable React Developer Tools without causing a console error. * * It replaces all properties of the global hook with a no-op function or a null * value, except for the 'renderers' property which is replaced with a new Map * to prevent a console error when the dev tools try to iterate over it. */ static disableReactDevTools(): void; /** * Counts the number of decimal places of a given number. * @param {number} value The number to count the decimal places of. * @returns {number} The number of decimal places of the given number. */ static countDecimals(value: number): number; /** * Sanitizes the given amount by converting it to an integer representation of the lowest currency unit. * * This function handles amounts with up to two decimal places. If the amount has more than two decimals, * it is rounded to two decimal places before conversion. The sanitized amount is returned as an integer * by multiplying the value by 100 to handle the currency in the lowest denomination (e.g., cents for USD). * * @param value - The monetary amount to be sanitized. * @returns The sanitized amount as an integer. */ static sanitizeAmount(value: number): number; /** * Logs information to the console when in development mode. * @param info The information to be logged. * @param tag An optional tag to prepend to the log message. */ static logInfo(info: any, tag?: string): void; /** * Logs an error to the console when in development mode. * @param error The error object or message to be logged. */ static logError(error: any): void; }