@dotcms/client 1.5.5-next.2180 → 1.5.5-next.2245

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +92 -30
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -84,7 +84,7 @@ The `@dotcms/client` is a powerful JavaScript/TypeScript SDK designed to simplif
84
84
  **For Local Development:**
85
85
 
86
86
  - 🐳 [Docker setup guide](https://github.com/dotCMS/core/tree/main/docker/docker-compose-examples/single-node-demo-site)
87
- - 💻 [Local installation guide](https://dev.dotcms.com/docs/quick-start-guide)
87
+ - 💻 [Local installation guide](https://dev.dotcms.com/getting-started/setup/run-locally)
88
88
 
89
89
  #### Create a dotCMS API Key
90
90
 
@@ -100,7 +100,7 @@ This integration requires an API Key with read-only permissions for security bes
100
100
 
101
101
  For detailed instructions, please refer to the [dotCMS API Documentation - Read-only token](https://dev.dotcms.com/docs/rest-api-authentication#ReadOnlyToken).
102
102
 
103
- #### Installation
103
+ ### Installation
104
104
 
105
105
  Install the SDK and required dependencies:
106
106
 
@@ -121,7 +121,7 @@ import { createDotCMSClient } from '@dotcms/client';
121
121
  // Create a client instance
122
122
  const client = createDotCMSClient({
123
123
  dotcmsUrl: 'https://your-dotcms-instance.com',
124
- authToken: 'your-auth-token', // Optional for public content
124
+ authToken: 'your-auth-token',
125
125
  siteId: 'your-site-id' // Optional site identifier
126
126
  });
127
127
 
@@ -361,7 +361,7 @@ const response = await client.ai.search(
361
361
  );
362
362
 
363
363
  // Access results with match scores
364
- resp[onse].results.forEach(result => {
364
+ response.results.forEach(result => {
365
365
  console.log(result.title);
366
366
  console.log('Matches:', result.matches); // Distance and extracted text
367
367
  });
@@ -457,11 +457,8 @@ response.contentlets.forEach(post => {
457
457
  #### Typing AI Search Results
458
458
 
459
459
  ```typescript
460
- import type {
461
- DotCMSAISearchResponse,
462
- DotCMSBasicContentlet,
463
- DISTANCE_FUNCTIONS
464
- } from '@dotcms/types';
460
+ import { DISTANCE_FUNCTIONS } from '@dotcms/types';
461
+ import type { DotCMSAISearchResponse, DotCMSBasicContentlet } from '@dotcms/types';
465
462
 
466
463
  // Define your content type
467
464
  interface Article extends DotCMSBasicContentlet {
@@ -688,6 +685,69 @@ const response = await client.page.get('/about-us', {
688
685
  });
689
686
  ```
690
687
 
688
+ ### How to Enable Page Editing
689
+
690
+ The `@dotcms/client` SDK is responsible for **fetching** your page, while a framework SDK ([`@dotcms/react`](https://www.npmjs.com/package/@dotcms/react) or [`@dotcms/angular`](https://www.npmjs.com/package/@dotcms/angular)) makes that page **editable** inside the [Universal Visual Editor (UVE)](https://dev.dotcms.com/docs/uve-headless-config).
691
+
692
+ The flow is always the same three steps:
693
+
694
+ 1. **Fetch the page** on the server with `client.page.get()`.
695
+ 2. **Connect the page to the editor** with the framework hook/service (`useEditableDotCMSPage` in React, `DotCMSEditablePageService` in Angular).
696
+ 3. **Render the layout** with `DotCMSLayoutBody`, mapping your content types to components.
697
+
698
+ #### 1. Fetch the page with `client.page.get()`
699
+
700
+ Fetch the full page response on the server. The complete response object — not just `pageAsset` — must be forwarded to the editor layer, because it carries the data UVE needs to track changes.
701
+
702
+ ```typescript
703
+ // server-side, e.g. a Next.js Server Component
704
+ import { createDotCMSClient } from '@dotcms/client';
705
+
706
+ const client = createDotCMSClient({
707
+ dotcmsUrl: 'https://your-dotcms-instance.com',
708
+ authToken: 'your-auth-token',
709
+ siteId: 'your-site-id'
710
+ });
711
+
712
+ // Return the whole response so the framework SDK can make it editable
713
+ export async function getPage(path: string) {
714
+ return await client.page.get(path);
715
+ }
716
+ ```
717
+
718
+ #### 2. Make the page editable (React example)
719
+
720
+ Pass the full page response into `useEditableDotCMSPage`. The hook keeps the page in sync with UVE while editing and returns the same `pageAsset` / `content` shape you get from `client.page.get()`, so the component works identically in and out of the editor.
721
+
722
+ ```tsx
723
+ 'use client';
724
+
725
+ import { DotCMSLayoutBody, useEditableDotCMSPage } from '@dotcms/react';
726
+ import { pageComponents } from '@/components/content-types';
727
+
728
+ export function Page({ pageContent }) {
729
+ // `pageContent` is the full response from client.page.get()
730
+ const { pageAsset } = useEditableDotCMSPage(pageContent);
731
+
732
+ return (
733
+ <DotCMSLayoutBody
734
+ page={pageAsset}
735
+ components={pageComponents}
736
+ mode={process.env.NEXT_PUBLIC_DOTCMS_MODE}
737
+ />
738
+ );
739
+ }
740
+ ```
741
+
742
+ > 💡 Using Angular? Use [`DotCMSEditablePageService`](https://www.npmjs.com/package/@dotcms/angular) together with `DotCMSLayoutBody` — the same fetch → make-editable → render flow applies.
743
+
744
+ #### 3. Render the layout with `DotCMSLayoutBody`
745
+
746
+ `DotCMSLayoutBody` renders the page's rows, columns, and containers, and maps each contentlet to one of your components via the `components` prop. When loaded inside UVE it automatically applies the `data-dot-*` attributes that make the page editable — no extra wiring required.
747
+
748
+ #### Working example
749
+
750
+ See the page-editing flow end to end in the official Next.js example — [`examples/nextjs`](https://github.com/dotCMS/core/tree/main/examples/nextjs). In particular, [`src/views/Page.js`](https://github.com/dotCMS/core/blob/main/examples/nextjs/src/views/Page.js) uses `useEditableDotCMSPage` and `DotCMSLayoutBody` exactly as shown above.
691
751
 
692
752
  ## API Reference
693
753
 
@@ -816,14 +876,15 @@ getCollection<T = DotCMSBasicContentlet>(
816
876
 
817
877
  #### Builder Methods
818
878
 
819
- | Method | Arguments | Description |
820
- | ------------ | ----------------------------- | ---------------------------------------- |
821
- | `query()` | `string` \| `BuildQuery` | Filter content using query builder |
822
- | `limit()` | `number` | Set number of items to return |
823
- | `page()` | `number` | Set which page of results to fetch |
824
- | `sortBy()` | `SortBy[]` | Sort by one or more fields |
825
- | `language()` | `number \| string` | Set content language |
826
- | `depth()` | `number` | Set depth of related content |
879
+ | Method | Arguments | Description |
880
+ | --------------------- | ----------------------------- | ------------------------------------------------------------------ |
881
+ | `query()` | `string` \| `BuildQuery` | Filter content using query builder |
882
+ | `limit()` | `number` | Set number of items to return |
883
+ | `page()` | `number` | Set which page of results to fetch |
884
+ | `sortBy()` | `SortBy[]` | Sort by one or more fields |
885
+ | `language()` | `number \| string` | Set content language |
886
+ | `depth()` | `number` | Set depth of related content |
887
+ | `includeSystemHost()` | - | Include content from the System Host alongside the configured site |
827
888
 
828
889
  #### Example
829
890
  ```typescript
@@ -1137,12 +1198,13 @@ DotHttpError: "Network request failed"
1137
1198
 
1138
1199
  ### Choosing the Right Method
1139
1200
 
1140
- The dotCMS Client SDK provides four core methods for fetching data. Use this quick guide to decide which one is best for your use case:
1201
+ The dotCMS Client SDK provides five core methods for fetching data. Use this quick guide to decide which one is best for your use case:
1141
1202
 
1142
1203
  | Method | Use When You Need... | Best For |
1143
1204
  | -------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
1144
1205
  | `client.page.get()` | A full page with layout, containers, and related content | **Rendering entire pages** with a single request. Ideal for headless setups, SSR/SSG frameworks, and cases where you want everything—page structure, content, and navigation—tied to a URL path. |
1145
- | `client.content.getCollection()` | A filtered list of content items from a specific content type | Populating dynamic blocks, lists, search results, widgets, or reusable components. |
1206
+ | `client.content.getCollection()` | A filtered list of content items from a specific content type | Populating dynamic blocks, lists, search results, widgets, or reusable components using the fluent query builder. |
1207
+ | `client.content.query()` | Full control over a raw Lucene query string | Advanced search scenarios where you need direct Lucene syntax without the `getCollection()` query-builder DSL or automatic `contentType.` field prefixing. |
1146
1208
  | `client.ai.search()` | Semantic/AI-powered content discovery based on natural language | **Intelligent search experiences** where users describe what they're looking for in natural language. Great for search features, content recommendations, and finding relevant content by meaning rather than exact keywords. ⚠️ **Experimental API** |
1147
1209
  | `client.navigation.get()` | Only the site's navigation structure (folders and links) | Standalone menus or use cases where navigation is needed outside of page context. |
1148
1210
 
@@ -1156,7 +1218,7 @@ For most use cases, `client.page.get()` is all you need. It lets you retrieve:
1156
1218
 
1157
1219
  All in a single request using GraphQL.
1158
1220
 
1159
- Only use `content.getCollection()` or `navigation.get()` if you have advanced needs, like real-time data fetching or building custom dynamic components.
1221
+ Only use `content.getCollection()`, `content.query()`, or `navigation.get()` if you have advanced needs, like real-time data fetching or building custom dynamic components.
1160
1222
 
1161
1223
  > 🔍 **For comprehensive examples of advanced GraphQL querying including relationships and custom fields,** see the [How to Work with GraphQL](#how-to-work-with-graphql) section.
1162
1224
 
@@ -1165,7 +1227,7 @@ Only use `content.getCollection()` or `navigation.get()` if you have advanced ne
1165
1227
  The SDK follows a client-builder pattern with four main APIs:
1166
1228
 
1167
1229
  - **Page API** (`client.page.get()`) - Fetches complete page content with layout and containers
1168
- - **Content API** (`client.content.getCollection()`) - Builder pattern for querying content collections
1230
+ - **Content API** (`client.content.getCollection()`, `client.content.query()`) - Builder pattern for querying content collections or raw Lucene queries
1169
1231
  - **AI API** (`client.ai.search()`) - AI-powered semantic search using embeddings and vector similarity ⚠️ **Experimental**
1170
1232
  - **Navigation API** (`client.navigation.get()`) - Fetches site navigation structure
1171
1233
 
@@ -1182,7 +1244,7 @@ We offer multiple channels to get help with the dotCMS Client SDK:
1182
1244
  - **GitHub Issues**: For bug reports and feature requests, please [open an issue](https://github.com/dotCMS/core/issues/new/choose) in the GitHub repository.
1183
1245
  - **Community Forum**: Join our [community discussions](https://community.dotcms.com/) to ask questions and share solutions.
1184
1246
  - **Stack Overflow**: Use the tag `dotcms-client` when posting questions.
1185
- - **Enterprise Support**: Enterprise customers can access premium support through the [dotCMS Support Portal](https://helpdesk.dotcms.com/support/).
1247
+ - **Enterprise Support**: Enterprise customers can access premium support through the [dotCMS Support Portal](https://www.dotcms.com/support).
1186
1248
 
1187
1249
  When reporting issues, please include:
1188
1250
 
@@ -1203,6 +1265,14 @@ GitHub pull requests are the preferred method to contribute code to dotCMS. We w
1203
1265
 
1204
1266
  Please ensure your code follows the existing style and includes appropriate tests.
1205
1267
 
1268
+ ## Licensing
1269
+
1270
+ dotCMS is available under either the [Business Source License 1.1 (BSL)](https://www.dotcms.com/bsl) or a commercial license.
1271
+
1272
+ Under the BSL, dotCMS can be used at no cost by individual developers, small businesses or agencies under $5M in total finances, and by larger organizations in non-production environments. Every BSL release automatically converts to GPL v3 four years after its release date. For full terms and FAQs, visit [dotcms.com/bsl](https://www.dotcms.com/bsl) and [dotcms.com/bsl-faq](https://www.dotcms.com/bsl-faq).
1273
+
1274
+ Production use in larger organizations, along with access to managed cloud, SLAs, support, and enterprise capabilities, is available under a commercial license from dotCMS. For details on commercial plans, features, and support options, see [dotcms.com/pricing](https://www.dotcms.com/pricing).
1275
+
1206
1276
  ## Changelog
1207
1277
 
1208
1278
  ### v1.3.0
@@ -1362,11 +1432,3 @@ import { RequestOptions } from '@dotcms/types';
1362
1432
  // After
1363
1433
  import { DotRequestOptions } from '@dotcms/types';
1364
1434
  ```
1365
-
1366
- ## Licensing
1367
-
1368
- dotCMS is available under either the [Business Source License 1.1 (BSL)](https://www.dotcms.com/bsl) or a commercial license.
1369
-
1370
- Under the BSL, dotCMS can be used at no cost by individual developers, small businesses or agencies under $5M in total finances, and by larger organizations in non-production environments. Every BSL release automatically converts to GPL v3 four years after its release date. For full terms and FAQs, visit [dotcms.com/bsl](https://www.dotcms.com/bsl) and [dotcms.com/bsl-faq](https://www.dotcms.com/bsl-faq).
1371
-
1372
- Production use in larger organizations, along with access to managed cloud, SLAs, support, and enterprise capabilities, is available under a commercial license from dotCMS. For details on commercial plans, features, and support options, see [dotcms.com/pricing](https://www.dotcms.com/pricing).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/client",
3
- "version": "1.5.5-next.2180",
3
+ "version": "1.5.5-next.2245",
4
4
  "description": "Official JavaScript library for interacting with DotCMS REST APIs.",
5
5
  "repository": {
6
6
  "type": "git",