UNPKG

bc-node-sdk

Version:

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

53 lines (52 loc) 2.87 kB
import { RequestCookies } from "next/dist/compiled/@edge-runtime/cookies"; import IApiParams from "../../domain/contracts/api/IApiParams"; import ApiService from "./ApiService"; import { Contracts } from "../.."; export default abstract class BaseApiController { protected cacheManager: Contracts.Caching.ICacheManager; /** * Constructor * @param {Contracts.Caching.ICacheManager} cacheManager - The cache manager to be used for caching data. */ constructor(cacheManager: Contracts.Caching.ICacheManager); protected abstract handleRequest(request: IApiParams, method: string): any; protected abstract get(request: IApiParams): any; protected abstract post(request: IApiParams): any; protected abstract put(request: IApiParams): any; protected abstract delete(request: IApiParams): any; protected abstract patch(request: IApiParams): any; /** * Retrieves the SSO user ID from the provided request cookies. * * @param cookies - The request cookies containing the SSO user ID. * @returns An object with the SSO user ID extracted from the cookies. */ protected requestCookies(cookies: RequestCookies): any; /** * Retrieves the authorization header from the given cookies and returns it as a string. * * @param cookies - The cookies containing the SSO user id. * @returns The authorization header string. */ /** * Extracts the authorization header and additional user information from the provided cookies and headers. * * This function retrieves the SSO user ID from the cookies or headers, decrypts it, and fetches the * authentication parameters from the cache. It constructs an authorization header and additional user * details if the token is available. If cookies contain language and domain ID, they are also extracted. * * @param cookies - The cookies containing potential user information such as SSO user ID and language. * @param headers - The headers containing potential user information, used if cookies do not provide it. * @returns A promise that resolves to an object with the authorization header and additional user details * such as DomainId, OrgId, UserName, UserId, Email, and OrgCode. Returns default values if no * valid token is found. */ protected authorizationHeaderFromRequestCookies(cookies: RequestCookies, headers: Headers, cacheManager: Contracts.Caching.ICacheManager): Promise<any>; /** * Returns an instance of the ApiService configured with the specified base URL. * * @param baseUrl - The base URL to be used for the API service instance. * @returns An instance of the ApiService class. */ protected serviceInstance(baseUrl: string): ApiService; }