Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@dotcms/types

Package Overview
Dependencies
Maintainers
1
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dotcms/types - npm Package Compare versions

Comparing version
1.0.6-next.3
to
1.0.6-next.4
+31
src/lib/content/public.d.ts
import { DotHttpError } from '../client/public';
/**
* Content API specific error class
* Wraps HTTP errors and adds content-specific context including query information
*/
export declare class DotErrorContent extends Error {
readonly httpError?: DotHttpError;
readonly contentType: string;
readonly operation: string;
readonly query?: string;
constructor(message: string, contentType: string, operation: string, httpError?: DotHttpError, query?: string);
/**
* Serializes the error to a plain object for logging or transmission
*/
toJSON(): {
name: string;
message: string;
contentType: string;
operation: string;
httpError: {
name: string;
message: string;
status: number;
statusText: string;
data: unknown;
stack: string | undefined;
} | undefined;
query: string | undefined;
stack: string | undefined;
};
}
import { DotHttpError } from '../client/public';
/**
* Navigation API specific error class
* Wraps HTTP errors and adds navigation-specific context
*/
export declare class DotErrorNavigation extends Error {
readonly httpError?: DotHttpError;
readonly path: string;
constructor(message: string, path: string, httpError?: DotHttpError);
/**
* Serializes the error to a plain object for logging or transmission
*/
toJSON(): {
name: string;
message: string;
path: string;
httpError: {
name: string;
message: string;
status: number;
statusText: string;
data: unknown;
stack: string | undefined;
} | undefined;
stack: string | undefined;
};
}
/**
* The parameters for the Navigation API.
* @public
*/
export interface DotCMSNavigationRequestParams {
/**
* The depth of the folder tree to return.
* @example
* `1` returns only the element specified in the path.
* `2` returns the element specified in the path, and if that element is a folder, returns all direct children of that folder.
* `3` returns all children and grandchildren of the element specified in the path.
*/
depth?: number;
/**
* The language ID of content to return.
* @example
* `1` (or unspecified) returns content in the default language of the site.
*/
languageId?: number;
}
/**
* Represents a navigation item in the DotCMS navigation structure
*
* @interface DotCMSNavigationItem
* @property {string} [code] - Optional unique code identifier for the navigation item
* @property {string} folder - The folder path where this navigation item is located
* @property {DotCMSNavigationItem[]} [children] - Optional array of child navigation items
* @property {string} host - The host/site this navigation item belongs to
* @property {number} languageId - The language ID for this navigation item
* @property {string} href - The URL/link that this navigation item points to
* @property {string} title - The display title of the navigation item
* @property {string} type - The type of navigation item
* @property {number} hash - Hash value for the navigation item
* @property {string} target - The target attribute for the link (e.g. "_blank", "_self")
* @property {number} order - The sort order position of this item in the navigation
*/
export interface DotCMSNavigationItem {
code?: string;
folder: string;
children?: DotCMSNavigationItem[];
host: string;
languageId: number;
href: string;
title: string;
type: string;
hash: number;
target: string;
order: number;
}
+239
-0

@@ -125,3 +125,242 @@ 'use strict';

/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Page API specific error class
* Wraps HTTP errors and adds page-specific context including GraphQL information
*/
class DotErrorPage extends Error {
constructor(message, httpError, graphql) {
super(message);
this.name = 'DotCMSPageError';
this.httpError = httpError;
this.graphql = graphql;
// Ensure proper prototype chain for instanceof checks
Object.setPrototypeOf(this, DotErrorPage.prototype);
}
/**
* Serializes the error to a plain object for logging or transmission
*/
toJSON() {
return {
name: this.name,
message: this.message,
httpError: this.httpError?.toJSON(),
graphql: this.graphql,
stack: this.stack
};
}
}
/**
* Standardized HTTP error class for all HTTP client implementations
*/
class DotHttpError extends Error {
constructor(details) {
super(details.message);
this.name = 'DotHttpError';
this.status = details.status;
this.statusText = details.statusText;
this.data = details.data;
// Ensure proper prototype chain for instanceof checks
Object.setPrototypeOf(this, DotHttpError.prototype);
}
/**
* Serializes the error to a plain object for logging or transmission
*/
toJSON() {
return {
name: this.name,
message: this.message,
status: this.status,
statusText: this.statusText,
data: this.data,
stack: this.stack
};
}
}
/**
* Abstract base class for HTTP client implementations.
* Provides common error handling utilities and enforces HttpError contract.
*
* @example
* ```typescript
* // Fetch API example
* export class FetchHttpClient extends BaseHttpClient {
* async request<T>(url: string, options?: DotRequestOptions): Promise<T> {
* try {
* const response = await fetch(url, options);
*
* if (!response.ok) {
* // Parse response body and headers
* let errorBody: string | unknown;
* try {
* const contentType = response.headers.get('content-type');
* if (contentType?.includes('application/json')) {
* errorBody = await response.json();
* } else {
* errorBody = await response.text();
* }
* } catch {
* errorBody = response.statusText;
* }
*
* const headers: Record<string, string> = {};
* response.headers.forEach((value, key) => {
* headers[key] = value;
* });
*
* throw this.createHttpError(
* response.status,
* response.statusText,
* headers,
* errorBody
* );
* }
*
* return response.json();
* } catch (error) {
* if (error instanceof TypeError) {
* throw this.createNetworkError(error);
* }
* throw error;
* }
* }
* }
*
* // Axios example
* export class AxiosHttpClient extends BaseHttpClient {
* async request<T>(url: string, options?: DotRequestOptions): Promise<T> {
* try {
* const response = await axios(url, options);
* return response.data;
* } catch (error) {
* if (axios.isAxiosError(error)) {
* throw this.createHttpError(
* error.response?.status || 0,
* error.response?.statusText || 'Network Error',
* error.response?.headers,
* error.response?.data
* );
* }
* throw this.createNetworkError(error);
* }
* }
* }
* ```
*/
class BaseHttpClient {
/**
* Creates a standardized HttpError from HTTP response details.
* Handles parsing of error response body automatically.
*
* @param status - HTTP status code
* @param statusText - HTTP status text
* @param headers - Response headers (optional)
* @param body - Response body (optional)
* @param customMessage - Optional custom error message
* @returns HttpError instance with parsed response data
*/
createHttpError(status, statusText, headers, body, customMessage) {
let errorData = body;
// If body is a string, try to parse as JSON
if (typeof body === 'string') {
try {
const contentType = headers?.['content-type'] || headers?.['Content-Type'];
if (contentType?.includes('application/json')) {
errorData = JSON.parse(body);
} else {
errorData = body;
}
} catch {
errorData = body;
}
}
return new DotHttpError({
status,
statusText,
message: customMessage || `HTTP ${status}: ${statusText}`,
data: errorData
});
}
/**
* Creates a standardized HttpError for network/connection errors.
*
* @param originalError - The original network error
* @returns HttpError instance representing a network error
*/
createNetworkError(originalError) {
return new DotHttpError({
status: 0,
// Network error status
statusText: 'Network Error',
message: `Network error: ${originalError.message}`,
data: originalError
});
}
}
/**
* Content API specific error class
* Wraps HTTP errors and adds content-specific context including query information
*/
class DotErrorContent extends Error {
constructor(message, contentType, operation, httpError, query) {
super(message);
this.name = 'DotCMSContentError';
this.contentType = contentType;
this.operation = operation;
this.httpError = httpError;
this.query = query;
// Ensure proper prototype chain for instanceof checks
Object.setPrototypeOf(this, DotErrorContent.prototype);
}
/**
* Serializes the error to a plain object for logging or transmission
*/
toJSON() {
return {
name: this.name,
message: this.message,
contentType: this.contentType,
operation: this.operation,
httpError: this.httpError?.toJSON(),
query: this.query,
stack: this.stack
};
}
}
/**
* Navigation API specific error class
* Wraps HTTP errors and adds navigation-specific context
*/
class DotErrorNavigation extends Error {
constructor(message, path, httpError) {
super(message);
this.name = 'DotNavigationError';
this.path = path;
this.httpError = httpError;
// Ensure proper prototype chain for instanceof checks
Object.setPrototypeOf(this, DotErrorNavigation.prototype);
}
/**
* Serializes the error to a plain object for logging or transmission
*/
toJSON() {
return {
name: this.name,
message: this.message,
path: this.path,
httpError: this.httpError?.toJSON(),
stack: this.stack
};
}
}
exports.BaseHttpClient = BaseHttpClient;
exports.DEVELOPMENT_MODE = DEVELOPMENT_MODE;
exports.DotErrorContent = DotErrorContent;
exports.DotErrorNavigation = DotErrorNavigation;
exports.DotErrorPage = DotErrorPage;
exports.DotHttpError = DotHttpError;
exports.PRODUCTION_MODE = PRODUCTION_MODE;
+235
-1

@@ -123,2 +123,236 @@ /**

export { DEVELOPMENT_MODE, DotCMSUVEAction, PRODUCTION_MODE, UVEEventType, UVE_MODE };
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Page API specific error class
* Wraps HTTP errors and adds page-specific context including GraphQL information
*/
class DotErrorPage extends Error {
constructor(message, httpError, graphql) {
super(message);
this.name = 'DotCMSPageError';
this.httpError = httpError;
this.graphql = graphql;
// Ensure proper prototype chain for instanceof checks
Object.setPrototypeOf(this, DotErrorPage.prototype);
}
/**
* Serializes the error to a plain object for logging or transmission
*/
toJSON() {
return {
name: this.name,
message: this.message,
httpError: this.httpError?.toJSON(),
graphql: this.graphql,
stack: this.stack
};
}
}
/**
* Standardized HTTP error class for all HTTP client implementations
*/
class DotHttpError extends Error {
constructor(details) {
super(details.message);
this.name = 'DotHttpError';
this.status = details.status;
this.statusText = details.statusText;
this.data = details.data;
// Ensure proper prototype chain for instanceof checks
Object.setPrototypeOf(this, DotHttpError.prototype);
}
/**
* Serializes the error to a plain object for logging or transmission
*/
toJSON() {
return {
name: this.name,
message: this.message,
status: this.status,
statusText: this.statusText,
data: this.data,
stack: this.stack
};
}
}
/**
* Abstract base class for HTTP client implementations.
* Provides common error handling utilities and enforces HttpError contract.
*
* @example
* ```typescript
* // Fetch API example
* export class FetchHttpClient extends BaseHttpClient {
* async request<T>(url: string, options?: DotRequestOptions): Promise<T> {
* try {
* const response = await fetch(url, options);
*
* if (!response.ok) {
* // Parse response body and headers
* let errorBody: string | unknown;
* try {
* const contentType = response.headers.get('content-type');
* if (contentType?.includes('application/json')) {
* errorBody = await response.json();
* } else {
* errorBody = await response.text();
* }
* } catch {
* errorBody = response.statusText;
* }
*
* const headers: Record<string, string> = {};
* response.headers.forEach((value, key) => {
* headers[key] = value;
* });
*
* throw this.createHttpError(
* response.status,
* response.statusText,
* headers,
* errorBody
* );
* }
*
* return response.json();
* } catch (error) {
* if (error instanceof TypeError) {
* throw this.createNetworkError(error);
* }
* throw error;
* }
* }
* }
*
* // Axios example
* export class AxiosHttpClient extends BaseHttpClient {
* async request<T>(url: string, options?: DotRequestOptions): Promise<T> {
* try {
* const response = await axios(url, options);
* return response.data;
* } catch (error) {
* if (axios.isAxiosError(error)) {
* throw this.createHttpError(
* error.response?.status || 0,
* error.response?.statusText || 'Network Error',
* error.response?.headers,
* error.response?.data
* );
* }
* throw this.createNetworkError(error);
* }
* }
* }
* ```
*/
class BaseHttpClient {
/**
* Creates a standardized HttpError from HTTP response details.
* Handles parsing of error response body automatically.
*
* @param status - HTTP status code
* @param statusText - HTTP status text
* @param headers - Response headers (optional)
* @param body - Response body (optional)
* @param customMessage - Optional custom error message
* @returns HttpError instance with parsed response data
*/
createHttpError(status, statusText, headers, body, customMessage) {
let errorData = body;
// If body is a string, try to parse as JSON
if (typeof body === 'string') {
try {
const contentType = headers?.['content-type'] || headers?.['Content-Type'];
if (contentType?.includes('application/json')) {
errorData = JSON.parse(body);
} else {
errorData = body;
}
} catch {
errorData = body;
}
}
return new DotHttpError({
status,
statusText,
message: customMessage || `HTTP ${status}: ${statusText}`,
data: errorData
});
}
/**
* Creates a standardized HttpError for network/connection errors.
*
* @param originalError - The original network error
* @returns HttpError instance representing a network error
*/
createNetworkError(originalError) {
return new DotHttpError({
status: 0,
// Network error status
statusText: 'Network Error',
message: `Network error: ${originalError.message}`,
data: originalError
});
}
}
/**
* Content API specific error class
* Wraps HTTP errors and adds content-specific context including query information
*/
class DotErrorContent extends Error {
constructor(message, contentType, operation, httpError, query) {
super(message);
this.name = 'DotCMSContentError';
this.contentType = contentType;
this.operation = operation;
this.httpError = httpError;
this.query = query;
// Ensure proper prototype chain for instanceof checks
Object.setPrototypeOf(this, DotErrorContent.prototype);
}
/**
* Serializes the error to a plain object for logging or transmission
*/
toJSON() {
return {
name: this.name,
message: this.message,
contentType: this.contentType,
operation: this.operation,
httpError: this.httpError?.toJSON(),
query: this.query,
stack: this.stack
};
}
}
/**
* Navigation API specific error class
* Wraps HTTP errors and adds navigation-specific context
*/
class DotErrorNavigation extends Error {
constructor(message, path, httpError) {
super(message);
this.name = 'DotNavigationError';
this.path = path;
this.httpError = httpError;
// Ensure proper prototype chain for instanceof checks
Object.setPrototypeOf(this, DotErrorNavigation.prototype);
}
/**
* Serializes the error to a plain object for logging or transmission
*/
toJSON() {
return {
name: this.name,
message: this.message,
path: this.path,
httpError: this.httpError?.toJSON(),
stack: this.stack
};
}
}
export { BaseHttpClient, DEVELOPMENT_MODE, DotCMSUVEAction, DotErrorContent, DotErrorNavigation, DotErrorPage, DotHttpError, PRODUCTION_MODE, UVEEventType, UVE_MODE };
+1
-1
{
"name": "@dotcms/types",
"version": "1.0.6-next.3",
"version": "1.0.6-next.4",
"keywords": [

@@ -5,0 +5,0 @@ "dotCMS",

+162
-42

@@ -16,2 +16,18 @@ # DotCMS Type Definition Library

## Table of Contents
- [Installation](#installation)
- [Overview](#overview)
- [Commonly Used Types](#commonly-used-types)
- [Type Hierarchy (Jump to Definitions)](#type-hierarchy-jump-to-definitions)
- [dotCMS Content & Pages](#dotcms-content--pages)
- [Universal Visual Editor (UVE)](#universal-visual-editor-uve)
- [Block Editor](#block-editor)
- [Client & HTTP](#client--http)
- [Error Handling](#error-handling)
- [Type Usage](#type-usage)
- [Error Type Checking](#error-type-checking)
- [About](#about)
- [Changelog](#changelog)
## Commonly Used Types

@@ -24,3 +40,8 @@

UVEEventType,
DotCMSInlineEditingPayload
DotCMSInlineEditingPayload,
DotHttpClient,
DotHttpError,
DotErrorPage,
DotErrorContent,
DotErrorNavigation
} from '@dotcms/types';

@@ -31,59 +52,138 @@ ```

### Page Types
### dotCMS Content & Pages
* [DotCMSPageAsset](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L18)
**Page:**
* [DotCMSPage](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L515)
* [DotCMSPageAssetContainer](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L138)
* [DotCMSSite](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L733)
* [DotCMSTemplate](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L432)
* [DotCMSViewAs](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L598)
* [DotCMSVanityUrl](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L80)
* [DotCMSURLContentMap](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L41)
* [DotCMSLayout](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L622)
* [DotCMSPageContainerContentlets](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L1139)
* [DotCMSPageResponse](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L1175)
* [DotCMSComposedPageAsset](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L1189)
* [DotCMSComposedContent](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L1195)
* [DotCMSComposedPageResponse](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L1199)
* [DotCMSClientPageGetResponse](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L1208)
| Type | Description |
|------|-------------|
| [DotCMSPageAsset](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L18) | Complete page with layout and content |
| [DotCMSPage](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L515) | Core page data |
| [DotCMSPageResponse](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L1175) | API response for page requests |
| [DotGraphQLApiResponse](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L1186) | GraphQL API response structure |
### Block Editor Types
**Content:**
* [BlockEditorContent](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/components/block-editor-renderer/public.ts#L38)
| Type | Description |
|------|-------------|
| [DotCMSBasicContentlet](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L1141) | Basic contentlet structure |
* [BlockEditorNode](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/components/block-editor-renderer/public.ts#L18)
* [BlockEditorMark](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/components/block-editor-renderer/public.ts#L7)
**Site & Layout:**
### Editor & UVE Types
| Type | Description |
|------|-------------|
| [DotCMSSite](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L733) | Site information |
| [DotCMSTemplate](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L432) | Page templates |
| [DotCMSLayout](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L622) | Page layout structure |
| [DotCMSPageAssetContainer](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L138) | Container definitions |
* [UVEState](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L30)
**Navigation:**
* [UVE\_MODE](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L55)
* [UVEEventHandler](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L67)
* [UVEEventSubscriber](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L90)
| Type | Description |
|------|-------------|
| [DotCMSNavigationItem](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/nav/public.ts#L73) | Navigation structure item with hierarchy support |
| [DotCMSVanityUrl](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L80) | URL rewrites and vanity URLs |
| [DotCMSURLContentMap](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L41) | URL to content mapping |
* [UVEEventSubscription](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L81)
* [UVEUnsubscribeFunction](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L73)
* [UVEEventType](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L169)
### Universal Visual Editor (UVE)
* [UVEEventPayloadMap](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L199)
* [DotCMSPageRendererMode](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L44)
* [DotCMSUVEAction](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L98)
**Editor State:**
### Events
| Type | Description |
|------|-------------|
| [UVEState](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L30) | Current editor state |
| [UVE_MODE](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L55) | Editor modes (EDIT, PREVIEW, PUBLISHED) |
| [DotCMSPageRendererMode](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L44) | Page rendering modes |
* [DotCMSInlineEditingPayload](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/events/public.ts#L13)
**Editor Events:**
* [DotCMSInlineEditingType](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/events/public.ts#L1)
| Type | Description |
|------|-------------|
| [UVEEventHandler](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L67) | Event handler functions |
| [UVEEventSubscriber](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L90) | Event subscription management |
| [UVEEventType](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L169) | Available event types |
| [UVEEventPayloadMap](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/editor/public.ts#L199) | Event payload definitions |
### Client Request Types
**Inline Editing:**
* [DotCMSPageRequestParams](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/client/public.ts#L35)
| Type | Description |
|------|-------------|
| [DotCMSInlineEditingPayload](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/events/public.ts#L13) | Inline editing data |
| [DotCMSInlineEditingType](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/events/public.ts#L1) | Types of inline editing |
* [DotCMSGraphQLParams](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/client/public.ts#L7)
* [RequestOptions](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/client/public.ts#L84)
* [DotCMSClientConfig](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/client/public.ts#L89)
* [DotCMSNavigationRequestParams](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/client/public.ts#L119)
### Block Editor
| Type | Description |
|------|-------------|
| [BlockEditorContent](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/components/block-editor-renderer/public.ts#L38) | Block editor content structure |
| [BlockEditorNode](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/components/block-editor-renderer/public.ts#L18) | Individual blocks/nodes |
| [BlockEditorMark](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/components/block-editor-renderer/public.ts#L7) | Text formatting marks |
### Client & HTTP
**HTTP Client:**
| Type | Description |
|------|-------------|
| [DotHttpClient](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/client/public.ts#L108) | HTTP client interface for custom implementations |
| [BaseHttpClient](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/client/public.ts#L196) | Abstract base class with error handling utilities |
**Client Configuration:**
| Type | Description |
|------|-------------|
| [DotCMSClientConfig](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/client/public.ts#L395) | Client configuration options |
| [DotRequestOptions](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/client/public.ts#L383) | HTTP request options |
| [DotCMSPageRequestParams](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/client/public.ts#L378) | Page request parameters |
| [DotCMSGraphQLParams](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/client/public.ts#L280) | GraphQL query parameters |
| [DotCMSNavigationRequestParams](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/nav/public.ts#L39) | Navigation request options |
### Error Handling
**Base Error Types:**
| Type | Description |
|------|-------------|
| [HttpErrorDetails](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/client/public.ts#L6) | HTTP error details interface |
| [DotHttpError](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/client/public.ts#L26) | Standardized HTTP error class |
**Domain-Specific Errors:**
| Type | Description |
|------|-------------|
| [DotErrorPage](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/page/public.ts#L1253) | Page API errors with GraphQL context |
| [DotErrorContent](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/content/public.ts#L7) | Content API specific error handling |
| [DotErrorNavigation](https://github.com/dotCMS/core/blob/main/core-web/libs/sdk/types/src/lib/nav/public.ts#L7) | Navigation API error handling |
## Type Usage
### Error Type Checking
```typescript
import {
DotHttpError,
DotErrorPage,
DotErrorContent,
DotErrorNavigation
} from '@dotcms/types';
// Type-safe error handling
if (error instanceof DotHttpError) {
// Access standardized HTTP error properties
console.error(`HTTP ${error.status}: ${error.statusText}`);
console.error('Response data:', error.data);
}
if (error instanceof DotErrorPage) {
// Page-specific error with GraphQL context
console.error('GraphQL query:', error.graphql?.query);
}
if (error instanceof DotErrorContent) {
// Content-specific error context
console.error(`${error.operation} failed for ${error.contentType}`);
}
```
> **Note**: For complete implementation examples and usage patterns, see the [@dotcms/client](../client/README.md) package documentation.
## About

@@ -98,3 +198,23 @@

* types
* cms
* cms
* content-management-system
## Changelog
### [1.1.1]
#### Added
- `DotHttpClient` interface for custom HTTP client implementations
- `BaseHttpClient` abstract class with built-in error handling utilities
- `DotHttpError` class for standardized HTTP error handling
- `DotErrorPage` class for page-specific errors with GraphQL query context
- `DotErrorContent` class for content API errors with operation details
- `DotErrorNavigation` class for navigation-specific error handling
- `DotGraphQLApiResponse` interface for GraphQL API responses
- `HttpErrorDetails` interface for HTTP error standardization
- All error classes include `toJSON()` methods for easy logging and serialization
#### Changed
- Renamed `RequestOptions` to `DotRequestOptions` for better naming consistency
- Renamed `DotCMSGraphQLPageResponse` to `DotGraphQLApiResponse` for clarity
- Enhanced `DotCMSClientConfig` to support custom `httpClient` implementations

@@ -6,1 +6,3 @@ export * from './lib/components/block-editor-renderer/public';

export * from './lib/client/public';
export * from './lib/content/public';
export * from './lib/nav/public';
import { UVE_MODE } from '../editor/public';
/**
* Standardized HTTP error details
*/
export interface HttpErrorDetails {
status: number;
statusText: string;
message: string;
data?: unknown;
}
/**
* Standardized HTTP error class for all HTTP client implementations
*/
export declare class DotHttpError extends Error implements HttpErrorDetails {
status: number;
statusText: string;
data?: unknown;
constructor(details: HttpErrorDetails);
/**
* Serializes the error to a plain object for logging or transmission
*/
toJSON(): {
name: string;
message: string;
status: number;
statusText: string;
data: unknown;
stack: string | undefined;
};
}
/**
* Interface for HTTP client implementations.
* Allows the SDK to work with different HTTP libraries.
*
* @important IMPLEMENTATION REQUIREMENTS:
* - ALL implementations MUST throw HttpError instances for failed requests
* - NEVER throw generic Error or other error types
* - Include response status, statusText, and message in HttpError
* - Attempt to parse error response body and include in HttpError.data
* - Handle network errors by wrapping them in HttpError (use createNetworkError helper)
*
* @example
* ```typescript
* // CORRECT - Throws HttpError
* if (!response.ok) {
* throw new HttpError({
* status: response.status,
* statusText: response.statusText,
* message: `Request failed: ${response.status}`,
* data: await response.json()
* });
* }
*
* // WRONG - Throws generic Error
* if (!response.ok) {
* throw new Error(`HTTP ${response.status}`);
* }
* ```
*/
export interface DotHttpClient {
/**
* Makes an HTTP request.
*
* @template T - The expected response type
* @param url - The URL to request
* @param options - Request options (method, headers, body, etc.)
* @returns A promise that resolves with the response data
* @throws {DotHttpError} When the request fails (non-2xx status or network error)
*
* @important IMPLEMENTATION REQUIREMENTS:
* - MUST throw DotHttpError instances for failed requests, never generic Error objects
* - Include response status, statusText, and message in DotHttpError
* - Attempt to parse error response body and include in DotHttpError.data
* - Handle network errors by wrapping them in DotHttpError
* - Consumers expect DotHttpError with status, statusText, and data properties for proper error handling
*/
request<T = unknown>(url: string, options?: DotRequestOptions): Promise<T>;
}
/**
* Abstract base class for HTTP client implementations.
* Provides common error handling utilities and enforces HttpError contract.
*
* @example
* ```typescript
* // Fetch API example
* export class FetchHttpClient extends BaseHttpClient {
* async request<T>(url: string, options?: DotRequestOptions): Promise<T> {
* try {
* const response = await fetch(url, options);
*
* if (!response.ok) {
* // Parse response body and headers
* let errorBody: string | unknown;
* try {
* const contentType = response.headers.get('content-type');
* if (contentType?.includes('application/json')) {
* errorBody = await response.json();
* } else {
* errorBody = await response.text();
* }
* } catch {
* errorBody = response.statusText;
* }
*
* const headers: Record<string, string> = {};
* response.headers.forEach((value, key) => {
* headers[key] = value;
* });
*
* throw this.createHttpError(
* response.status,
* response.statusText,
* headers,
* errorBody
* );
* }
*
* return response.json();
* } catch (error) {
* if (error instanceof TypeError) {
* throw this.createNetworkError(error);
* }
* throw error;
* }
* }
* }
*
* // Axios example
* export class AxiosHttpClient extends BaseHttpClient {
* async request<T>(url: string, options?: DotRequestOptions): Promise<T> {
* try {
* const response = await axios(url, options);
* return response.data;
* } catch (error) {
* if (axios.isAxiosError(error)) {
* throw this.createHttpError(
* error.response?.status || 0,
* error.response?.statusText || 'Network Error',
* error.response?.headers,
* error.response?.data
* );
* }
* throw this.createNetworkError(error);
* }
* }
* }
* ```
*/
export declare abstract class BaseHttpClient implements DotHttpClient {
/**
* Makes an HTTP request.
*
* @template T - The expected response type
* @param url - The URL to request
* @param options - Request options (method, headers, body, etc.)
* @returns A promise that resolves with the response data
* @throws {DotHttpError} When the request fails (non-2xx status or network error)
*
* @important IMPLEMENTATION REQUIREMENTS:
* - MUST throw DotHttpError instances for failed requests, never generic Error objects
* - Include response status, statusText, and message in DotHttpError
* - Attempt to parse error response body and include in DotHttpError.data
* - Handle network errors by wrapping them in DotHttpError using createNetworkError()
* - Use createHttpError() helper for HTTP response errors
*/
abstract request<T = unknown>(url: string, options?: DotRequestOptions): Promise<T>;
/**
* Creates a standardized HttpError from HTTP response details.
* Handles parsing of error response body automatically.
*
* @param status - HTTP status code
* @param statusText - HTTP status text
* @param headers - Response headers (optional)
* @param body - Response body (optional)
* @param customMessage - Optional custom error message
* @returns HttpError instance with parsed response data
*/
protected createHttpError(status: number, statusText: string, headers?: Record<string, string>, body?: string | unknown, customMessage?: string): DotHttpError;
/**
* Creates a standardized HttpError for network/connection errors.
*
* @param originalError - The original network error
* @returns HttpError instance representing a network error
*/
protected createNetworkError(originalError: Error): DotHttpError;
}
/**
* The GraphQL parameters for a page request.

@@ -78,5 +263,27 @@ * @public

/**
* Options for configuring fetch requests, excluding body and method properties.
* Options for configuring HTTP requests in the DotCMS client.
*
* Extends the native `RequestInit` interface from the Fetch API, providing all standard
* fetch options including headers, credentials, cache settings, and more. This type is
* used throughout the DotCMS client for configuring HTTP requests consistently.
*
* @example
* ```typescript
* const options: DotRequestOptions = {
* method: 'POST',
* headers: {
* 'Content-Type': 'application/json',
* 'Authorization': 'Bearer your-token'
* },
* body: JSON.stringify({ name: 'John' }),
* credentials: 'include',
* cache: 'no-cache'
* };
*
* const result = await httpClient.request('/api/content', options);
* ```
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options RequestInit} - MDN documentation for RequestInit
*/
export type RequestOptions = Omit<RequestInit, 'body' | 'method'>;
export type DotRequestOptions = RequestInit;
/**

@@ -105,23 +312,9 @@ * Configuration options for the DotCMS client.

*/
requestOptions?: RequestOptions;
}
/**
* The parameters for the Navigation API.
* @public
*/
export interface DotCMSNavigationRequestParams {
requestOptions?: DotRequestOptions;
/**
* The depth of the folder tree to return.
* @example
* `1` returns only the element specified in the path.
* `2` returns the element specified in the path, and if that element is a folder, returns all direct children of that folder.
* `3` returns all children and grandchildren of the element specified in the path.
* Custom HTTP client implementation.
* If not provided, the default FetchHttpClient will be used.
* @example `{ httpClient: new AxiosHttpClient() }`
*/
depth?: number;
/**
* The language ID of content to return.
* @example
* `1` (or unspecified) returns content in the default language of the site.
*/
languageId?: number;
httpClient?: DotHttpClient;
}

@@ -0,1 +1,2 @@

import { DotHttpError } from '../client/public';
/**

@@ -369,31 +370,2 @@ * Represents a map of container identifiers to their container objects

/**
* Represents a navigation item in the DotCMS navigation structure
*
* @interface DotCMSNavigationItem
* @property {string} [code] - Optional unique code identifier for the navigation item
* @property {string} folder - The folder path where this navigation item is located
* @property {DotCMSNavigationItem[]} [children] - Optional array of child navigation items
* @property {string} host - The host/site this navigation item belongs to
* @property {number} languageId - The language ID for this navigation item
* @property {string} href - The URL/link that this navigation item points to
* @property {string} title - The display title of the navigation item
* @property {string} type - The type of navigation item
* @property {number} hash - Hash value for the navigation item
* @property {string} target - The target attribute for the link (e.g. "_blank", "_self")
* @property {number} order - The sort order position of this item in the navigation
*/
export interface DotCMSNavigationItem {
code?: string;
folder: string;
children?: DotCMSNavigationItem[];
host: string;
languageId: number;
href: string;
title: string;
type: string;
hash: number;
target: string;
order: number;
}
/**
* Represents a template in DotCMS that defines the layout and structure of pages

@@ -1148,2 +1120,12 @@ *

/**
* dotCMS's GraphQL API response with a page and content query
*/
export interface DotGraphQLApiResponse {
data: {
page: DotCMSGraphQLPage;
content?: Record<string, unknown>;
};
errors?: DotCMSGraphQLError[];
}
/**
* Represents a GraphQL error

@@ -1163,14 +1145,2 @@ * @interface DotCMSGraphQLError

/**
* Represents the complete response from a page query from the GraphQL API
*/
export interface DotCMSGraphQLPageResponse {
page: DotCMSGraphQLPage;
content?: Record<string, unknown> | unknown;
errors?: DotCMSGraphQLError;
graphql: {
query: string;
variables: Record<string, unknown>;
};
}
/**
* Represents the complete response from a page query

@@ -1195,2 +1165,37 @@ */

export type DotCMSClientPageGetResponse<T extends DotCMSExtendedPageResponse> = Promise<DotCMSComposedPageResponse<T>>;
/**
* Page API specific error class
* Wraps HTTP errors and adds page-specific context including GraphQL information
*/
export declare class DotErrorPage extends Error {
readonly httpError?: DotHttpError;
readonly graphql?: {
query: string;
variables: Record<string, unknown>;
};
constructor(message: string, httpError?: DotHttpError, graphql?: {
query: string;
variables: Record<string, unknown>;
});
/**
* Serializes the error to a plain object for logging or transmission
*/
toJSON(): {
name: string;
message: string;
httpError: {
name: string;
message: string;
status: number;
statusText: string;
data: unknown;
stack: string | undefined;
} | undefined;
graphql: {
query: string;
variables: Record<string, unknown>;
} | undefined;
stack: string | undefined;
};
}
export {};