{"id":15988,"library":"contensis-core-api","title":"Contensis Core API Library","description":"The `contensis-core-api` package, currently at version 1.2.2, serves as a foundational dependency library within the Contensis ecosystem. Written in TypeScript, it provides common types, interfaces, and base methods shared across higher-level Contensis client libraries, specifically `contensis-delivery-api` and `contensis-management-api`. Its primary purpose is to offer standardized HTTP request handling, error structures, and data models that ensure consistency and reduce code duplication across various Contensis API interactions. While not typically consumed directly by most application developers, it provides the underlying infrastructure for interacting with the Contensis HTTP Delivery API and Management API. As a core dependency, its release cadence is usually tied to the evolution of the broader Contensis API clients, adhering to semantic versioning for internal changes.","status":"active","version":"1.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/contensis/contensis-core-api","tags":["javascript","contensis","api","typescript"],"install":[{"cmd":"npm install contensis-core-api","lang":"bash","label":"npm"},{"cmd":"yarn add contensis-core-api","lang":"bash","label":"yarn"},{"cmd":"pnpm add contensis-core-api","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primarily used internally by Contensis client libraries, but available for custom low-level HTTP handling.","wrong":"const HttpClient = require('contensis-core-api').HttpClient;","symbol":"HttpClient","correct":"import { HttpClient } from 'contensis-core-api';"},{"note":"Enum defining standard HTTP verbs (e.g., 'GET', 'POST').","wrong":"import { HTTP_METHOD } from 'contensis-core-api';","symbol":"HttpMethod","correct":"import { HttpMethod } from 'contensis-core-api';"},{"note":"Base class for API-related errors, useful for custom error handling logic when interacting with Contensis APIs at a lower level.","wrong":"import { ApiError } from 'contensis-core-api';","symbol":"CallError","correct":"import { CallError } from 'contensis-core-api';"}],"quickstart":{"code":"import { HttpClient, HttpMethod, CallError, IHttpClient } from 'contensis-core-api';\n\ninterface MyApiOptions {\n  rootUrl: string;\n  accessToken: string;\n}\n\n// Demonstrating how to set up a basic HttpClient (typically abstracted by higher-level Contensis clients)\nclass CustomContensisHttpClient implements IHttpClient {\n  private client: HttpClient;\n\n  constructor(options: MyApiOptions) {\n    this.client = new HttpClient(options.rootUrl);\n    // In a real scenario, authentication headers would be added here or via middleware\n    this.client.setDefaultHeader('Authorization', `Bearer ${options.accessToken}`);\n  }\n\n  async request<T>(method: HttpMethod, path: string, options?: RequestInit): Promise<T> {\n    try {\n      const response = await this.client.request<T>(method, path, options);\n      console.log(`Successfully made ${method} request to ${path}`);\n      return response;\n    } catch (error) {\n      if (error instanceof CallError) {\n        console.error(`API Call Error: ${error.message} (Status: ${error.status})`);\n      } else {\n        console.error('An unexpected error occurred:', error);\n      }\n      throw error;\n    }\n  }\n}\n\n// Example usage (conceptual, as direct use is rare)\nconst myClient = new CustomContensisHttpClient({\n  rootUrl: process.env.CONTENSIS_ROOT_URL ?? 'https://api.contensis.com',\n  accessToken: process.env.CONTENSIS_ACCESS_TOKEN ?? 'YOUR_ACCESS_TOKEN_HERE'\n});\n\nasync function fetchData() {\n  try {\n    // This is a simplified example; actual paths and types would vary.\n    // Higher-level Contensis SDKs (`contensis-delivery-api`) provide structured methods.\n    const data = await myClient.request<any>(HttpMethod.GET, '/some/api/path');\n    console.log('Received data:', data);\n  } catch (e) {\n    console.log('Failed to fetch data via core client.');\n  }\n}\n\nfetchData();\n","lang":"typescript","description":"Illustrates the usage of core types like `HttpClient`, `HttpMethod`, and `CallError`, demonstrating a low-level HTTP request pattern. This package is typically a dependency and not used directly for API calls by end-user applications."},"warnings":[{"fix":"For interacting with Contensis APIs, prefer `contensis-delivery-api` for read-only content or `contensis-management-api` for content management operations.","message":"This package is a core dependency for other Contensis client libraries (`contensis-delivery-api`, `contensis-management-api`). Direct consumption by application developers is generally not recommended, as the higher-level SDKs provide a more abstracted and feature-rich interface for interacting with the Contensis CMS.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always check the release notes and migration guides for `contensis-delivery-api` and `contensis-management-api` when updating to a new major version of any Contensis SDK. Pay attention to type definition changes and API instantiation methods.","message":"Major version updates of `contensis-core-api` typically coincide with breaking changes in the consuming client libraries. Changes in internal types, interfaces, or HTTP client behavior in this core package can propagate as breaking changes in the higher-level SDKs. Developers should consult the changelog of `contensis-delivery-api` or `contensis-management-api` when upgrading.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure your Node.js environment meets the minimum requirement. For client-side usage, ensure your build process correctly handles browser compatibility.","message":"The package requires Node.js >=12, as specified in its `engines` field. Using it with older Node.js versions may lead to runtime errors due to unsupported syntax or built-in features (like `fetch` polyfills in consuming libraries).","severity":"gotcha","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Use ES module `import` syntax: `import { HttpClient } from 'contensis-core-api';`. If in a CommonJS environment, configure your project for ESM or ensure your transpiler handles `import`/`export` correctly.","cause":"Attempting to `require` an ESM-only module or using incorrect CommonJS syntax for named exports. The `contensis-core-api` package is written in TypeScript and likely built for ESM, though it might provide CJS bundles.","error":"TypeError: (0 , contensis_core_api_1.HttpClient) is not a constructor"},{"fix":"Ensure `contensis-core-api` is installed (`npm install contensis-core-api` or `yarn add contensis-core-api`). Verify `tsconfig.json` includes `\"compilerOptions\": { \"moduleResolution\": \"Node\" }` and implicitly or explicitly includes `node_modules` in its `include` path.","cause":"TypeScript compiler cannot locate the package's type definitions. This can happen if the package is not installed, or if `tsconfig.json` is not correctly configured to include `node_modules/@types` or the package's own types.","error":"TS2307: Cannot find module 'contensis-core-api' or its corresponding type declarations."}],"ecosystem":"npm"}