bc-node-sdk
Version:
BetterCommerce's NodeJS SDK encapsulates the base framework for all the Next.js applications.
44 lines (43 loc) • 2.39 kB
TypeScript
import { AxiosRequestConfig } from "../infrastructure/api";
import { ReadonlyHeaders } from "next/dist/server/web/spec-extension/adapters/headers";
import { ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies";
/**
* Class {@link ApiUtil} encapsulates utility methods required to make API calls and handle responses.
*/
export default abstract class ApiUtil {
/**
* Makes an API call using the provided Axios request configuration.
* Logs the request configuration information.
*
* @param {AxiosRequestConfig<any>} config - The Axios request configuration object.
* @returns {Promise<any>} The result of the API call.
*/
static callApi(config: AxiosRequestConfig<any>): Promise<import("axios").AxiosResponse<any, any>>;
/**
* Generates a headers object from the given cookies by extracting all cookies into a
* JavaScript object where each property is a cookie name and the corresponding value is
* the cookie's value.
*
* @param {ReadonlyRequestCookies} cookies - The cookies object to get the headers 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 generateNextApiHeaders(cookies: ReadonlyRequestCookies): any;
/**
* Generates the base URL from the given headers by combining the 'x-forwarded-proto' and 'host' headers.
*
* @param {ReadonlyHeaders} headers - The headers object to get the base URL from.
* @returns {string} The base URL of the Next.js API endpoint.
*/
static getAppBaseUrl(headers: any): string;
/**
* Generates the full URL of a Next.js API endpoint by combining the base URL
* (obtained from the headers) with the endpoint URL and any additional parameters.
*
* @param {string} endpointUrl - The URL of the Next.js API endpoint.
* @param {ReadonlyHeaders} headers - The headers object to get the base URL from.
* @param {Object} moreParams - Additional parameters to include in the URL. Defaults to an empty object.
* @returns {string} The full URL of the Next.js API endpoint.
*/
static generateNextApiEndpointUrl(endpointUrl: string, headers: ReadonlyHeaders, moreParams?: Object): string;
}