contentful-sdk-core

  • Version 9.0.0
  • Published
  • 32.1 kB
  • 5 dependencies
  • MIT license

Install

npm i contentful-sdk-core
yarn add contentful-sdk-core
pnpm add contentful-sdk-core

Overview

Core modules for the Contentful JS SDKs

Index

Functions

function createHttpClient

createHttpClient: (
axios: AxiosStatic,
options: CreateHttpClientParams
) => AxiosInstance;
  • Create pre-configured axios instance

    Parameter axios

    Axios library

    Parameter options

    Initialization parameters for the HTTP client {AxiosInstance} Initialized axios instance

function createRequestConfig

createRequestConfig: ({ query }: { query: Record<string, any> }) => Config;
  • Creates request parameters configuration by parsing an existing query object

    Parameter query

    {Object} Config object with params property, ready to be used in axios

function enforceObjPath

enforceObjPath: (obj: any, path: string) => boolean;

    function errorHandler

    errorHandler: (errorResponse: any) => never;
    • Handles errors received from the server. Parses the error into a more useful format, places it in an exception and throws it. See https://www.contentful.com/developers/docs/references/errors/ for more details on the data received on the errorResponse.data property and the expected error codes.

    function freezeSys

    freezeSys: <T extends FreezeObject>(obj: T) => T;

      function getUserAgentHeader

      getUserAgentHeader: (
      sdk: string,
      application?: string,
      integration?: string,
      feature?: string
      ) => string;

        function toPlainObject

        toPlainObject: <T = Record<string, unknown>, R = T>(
        data: T
        ) => T & { toPlainObject(): R };
        • Mixes in a method to return just a plain object with no additional methods

          Parameter data

          Any plain JSON response returned from the API Enhanced object with toPlainObject method

        Type Aliases

        type AxiosInstance

        type AxiosInstance = OriginalAxiosInstance & {
        httpClientParams: CreateHttpClientParams;
        cloneWithNewParams: (params: Partial<CreateHttpClientParams>) => AxiosInstance;
        defaults: DefaultOptions;
        };

          type CreateHttpClientParams

          type CreateHttpClientParams = {
          /** Access Token or an async function that returns Access Token */
          accessToken: string | (() => Promise<string>);
          /** Space ID */
          space?: string;
          /**
          * Requests will be made over http instead of the default https
          * @default false
          */
          insecure?: boolean;
          /**
          * API host
          */
          host?: string;
          /** HTTP agent for node */
          httpAgent?: AxiosRequestConfig['httpAgent'];
          /** HTTPS agent for node */
          httpsAgent?: AxiosRequestConfig['httpsAgent'];
          /** Axios adapter to handle requests */
          adapter?: AxiosRequestConfig['adapter'];
          /** Axios proxy config */
          proxy?: AxiosRequestConfig['proxy'];
          /** Gets called on every request triggered by the SDK, takes the axios request config as an argument */
          requestLogger?: DefaultOptions['requestLogger'];
          /** Gets called on every response, takes axios response object as an argument */
          responseLogger?: DefaultOptions['responseLogger'];
          /** Request interceptor */
          onBeforeRequest?: (
          value: InternalAxiosRequestConfig
          ) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>;
          /** Error handler */
          onError?: (error: any) => any;
          /** A log handler function to process given log messages & errors. Receives the log level (error, warning & info) and the actual log data (Error object or string). (Default can be found here: https://github.com/contentful/contentful-sdk-core/blob/master/lib/create-http-client.js) */
          logHandler?: DefaultOptions['logHandler'];
          /** Optional additional headers */
          headers?: AxiosRequestHeaders | Record<string, AxiosHeaderValue>;
          defaultHostname?: string;
          /**
          * If we should retry on errors and 429 rate limit exceptions
          * @default true
          */
          retryOnError?: boolean;
          /**
          * Optional number of retries before failure
          * @default 5
          */
          retryLimit?: number;
          /**
          * Optional number of milliseconds before the request times out.
          * @default 30000
          */
          timeout?: number;
          basePath?: string;
          baseURL?: string;
          /**
          * Optional maximum content length in bytes
          * @default 1073741824 i.e 1GB
          */
          maxContentLength?: number;
          /**
          * Optional maximum body length in bytes
          * @default 1073741824 i.e 1GB
          */
          maxBodyLength?: number;
          /**
          * Optional maximum number of requests per second (rate-limit)
          * @desc should represent the max of your current plan's rate limit
          * @default 0 = no throttling
          * @param 1-30 (fixed number of limit), 'auto' (calculated limit based on current tier), '0%' - '100%' (calculated % limit based on tier)
          */
          throttle?: 'auto' | string | number;
          /**
          * Optional how often the current request has been retried
          * @default 0
          */
          attempt?: number;
          };

            Package Files (9)

            Dependencies (5)

            Dev Dependencies (25)

            Peer Dependencies (0)

            No peer dependencies.

            Badge

            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/contentful-sdk-core.

            • Markdown
              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/contentful-sdk-core)
            • HTML
              <a href="https://www.jsdocs.io/package/contentful-sdk-core"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>