@dotcms/client 0.0.1-beta.2 → 0.0.1-beta.21

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 (47) hide show
  1. package/README.md +164 -36
  2. package/index.cjs.js +102 -1238
  3. package/index.esm.js +86 -1221
  4. package/next.cjs.d.ts +1 -0
  5. package/next.cjs.default.js +1 -0
  6. package/next.cjs.js +575 -0
  7. package/next.cjs.mjs +2 -0
  8. package/next.esm.d.ts +1 -0
  9. package/next.esm.js +573 -0
  10. package/package.json +32 -7
  11. package/src/index.d.ts +6 -6
  12. package/src/lib/client/client.d.ts +84 -0
  13. package/src/lib/client/content/builders/collection/collection.d.ts +1 -1
  14. package/src/lib/client/content/content-api.d.ts +1 -1
  15. package/src/lib/client/content/shared/types.d.ts +2 -2
  16. package/src/lib/client/models/types.d.ts +573 -10
  17. package/src/lib/client/navigation/navigation-api.d.ts +31 -0
  18. package/src/lib/client/page/page-api.d.ts +172 -0
  19. package/src/lib/client/page/utils.d.ts +41 -0
  20. package/src/lib/{editor → deprecated/editor}/models/client.model.d.ts +13 -0
  21. package/src/lib/{editor → deprecated/editor}/sdk-editor.d.ts +1 -1
  22. package/src/lib/{client → deprecated}/sdk-js-client.d.ts +1 -1
  23. package/src/lib/utils/page/common-utils.d.ts +1 -1
  24. package/src/next.d.ts +1 -0
  25. package/src/types.d.ts +2 -0
  26. package/transforms.cjs.js +1149 -0
  27. package/transforms.esm.js +1143 -0
  28. package/types.cjs.d.ts +1 -0
  29. package/types.cjs.default.js +1 -0
  30. package/types.cjs.js +2 -0
  31. package/types.cjs.mjs +2 -0
  32. package/types.esm.d.ts +1 -0
  33. package/types.esm.js +1 -0
  34. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Equals.d.ts +0 -0
  35. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Field.d.ts +0 -0
  36. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/NotOperand.d.ts +0 -0
  37. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Operand.d.ts +0 -0
  38. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/index.d.ts +0 -0
  39. /package/src/lib/{query-builder/sdk-query-builder.d.ts → client/content/builders/query/query.d.ts} +0 -0
  40. /package/src/lib/{query-builder → client/content/builders/query}/utils/index.d.ts +0 -0
  41. /package/src/lib/{editor → deprecated/editor}/listeners/listeners.d.ts +0 -0
  42. /package/src/lib/{editor → deprecated/editor}/models/editor.model.d.ts +0 -0
  43. /package/src/lib/{editor → deprecated/editor}/models/inline-event.model.d.ts +0 -0
  44. /package/src/lib/{editor → deprecated/editor}/models/listeners.model.d.ts +0 -0
  45. /package/src/lib/{editor → deprecated/editor}/sdk-editor-vtl.d.ts +0 -0
  46. /package/src/lib/{editor → deprecated/editor}/utils/editor.utils.d.ts +0 -0
  47. /package/src/lib/{editor → deprecated/editor}/utils/traditional-vtl.utils.d.ts +0 -0
package/README.md CHANGED
@@ -2,15 +2,67 @@
2
2
 
3
3
  The `@dotcms/client` is a JavaScript/TypeScript library for interacting with a dotCMS instance. It allows you to easily fetch pages, content, and navigation information in JSON format, as well as to make complex queries on content collections.
4
4
 
5
+ > **⚠️ IMPORTANT:** Versions published under the `next` tag (`npm install @dotcms/client@next`) are experimental, in beta, and not code complete. For the current stable and functional version, please use `latest` (`npm install @dotcms/client@latest`). Once we release the stable version, we will provide a migration guide from the alpha to stable version. The current alpha version (under `latest`) will continue to work, allowing you to migrate progressively at your own pace.
6
+
5
7
  This client library provides a streamlined, promise-based interface to fetch pages and navigation API.
6
8
 
9
+ ## Table of Contents
10
+
11
+ - [Features](#features)
12
+ - [What's New](#whats-new)
13
+ - [What's Being Deprecated](#whats-being-deprecated)
14
+ - [Installation](#installation)
15
+ - [Browser Compatibility](#browser-compatibility)
16
+ - [Usage](#usage)
17
+ - [ES Modules](#es-modules)
18
+ - [CommonJS](#commonjs)
19
+ - [Initialization](#initialization)
20
+ - [Fetching a Page](#fetching-a-page)
21
+ - [Example with all options](#example-with-all-options)
22
+ - [Fetching Navigation](#fetching-navigation)
23
+ - [Legacy Navigation Example](#legacy-navigation-example)
24
+ - [Fetching a Collection of Content](#fetching-a-collection-of-content)
25
+ - [Basic Usage](#basic-usage)
26
+ - [Sorting Content](#sorting-content)
27
+ - [Filtering by Language](#filtering-by-language)
28
+ - [Using Complex Queries](#using-complex-queries)
29
+ - [Fetching Draft Content](#fetching-draft-content)
30
+ - [Setting Depth for Relationships](#setting-depth-for-relationships)
31
+ - [Combining Multiple Methods](#combining-multiple-methods)
32
+ - [Error Handling Example](#error-handling-example)
33
+ - [Pagination](#pagination)
34
+ - [API Reference](#api-reference)
35
+ - [Contributing](#contributing)
36
+ - [Licensing](#licensing)
37
+ - [Support](#support)
38
+ - [Documentation](#documentation)
39
+ - [Getting Help](#getting-help)
40
+
7
41
  ## Features
8
42
 
9
43
  - Easy-to-use methods to interact with [dotCMS pages](https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas) and the [Navigation API](https://www.dotcms.com/docs/latest/navigation-rest-api).
10
44
  - Support for custom actions to communicate with the dotCMS page editor.
11
45
  - Comprehensive TypeScript typings for better development experience.
12
46
 
13
- # dotCMS API Client
47
+ ## What's New
48
+
49
+ - **Improved Collection Builder API:** Enhanced content fetching with a fluent builder pattern
50
+ - **TypeScript Support:** Comprehensive type definitions for better developer experience
51
+ - **Promise-based API:** Modern, async/await compatible interface for all API calls
52
+ - **Performance Optimizations:** Faster response times and reduced memory footprint
53
+ - **New Client Creation:** The `dotCMSCreateClient()` function replaces `DotCmsClient.init()` for better functional programming
54
+
55
+ > **Note:** Some deprecated features are being phased out. See [API Reference](#api-reference) for details.
56
+
57
+ ## What's Being Deprecated
58
+
59
+ - **Legacy Editor APIs:** The `postMessageToEditor`, `initEditor`, and related functions are being phased out
60
+ - **Direct Content API:** The `content.get()` method is being replaced by the more powerful `content.getCollection()`
61
+ - **Callback-based APIs:** All callback-based methods are being replaced with Promise-based alternatives
62
+ - **DotCmsClient.init:** The static `DotCmsClient.init()` method is replaced by the `dotCMSCreateClient()` function
63
+ - **client.editor:** The editor functionality has been completely moved to the `@dotcms/uve` package
64
+
65
+ > **Note:** Deprecated items will continue to work for backward compatibility but will be removed in future major versions.
14
66
 
15
67
  ## Installation
16
68
 
@@ -24,7 +76,17 @@ Or using Yarn:
24
76
 
25
77
  ```bash
26
78
  yarn add @dotcms/client
27
- ```
79
+
80
+
81
+ ## Browser Compatibility
82
+
83
+ The @dotcms/client package is compatible with the following browsers:
84
+
85
+ | Browser | Minimum Version | TLS Version |
86
+ |---------|----------------|-------------|
87
+ | Chrome | Latest 2 versions | TLS 1.2+ |
88
+ | Edge | Latest 2 versions | TLS 1.2+ |
89
+ | Firefox | Latest 2 versions | TLS 1.2+ |
28
90
 
29
91
  ## Usage
30
92
 
@@ -33,13 +95,13 @@ yarn add @dotcms/client
33
95
  ### ES Modules
34
96
 
35
97
  ```javascript
36
- import { DotCmsClient } from '@dotcms/client';
98
+ import { createDotCMSClient } from '@dotcms/client/next';
37
99
  ```
38
100
 
39
101
  ### CommonJS
40
102
 
41
103
  ```javascript
42
- const { DotCmsClient } = require('@dotcms/client');
104
+ const { createDotCMSClient } = require('@dotcms/client/next');
43
105
  ```
44
106
 
45
107
  ### Initialization
@@ -47,7 +109,7 @@ const { DotCmsClient } = require('@dotcms/client');
47
109
  First, initialize the client with your dotCMS instance details.
48
110
 
49
111
  ```javascript
50
- const client = DotCmsClient.init({
112
+ const client = createDotCMSClient({
51
113
  dotcmsUrl: 'https://your-dotcms-instance.com',
52
114
  authToken: 'your-auth-token',
53
115
  siteId: 'your-site-id'
@@ -59,18 +121,101 @@ const client = DotCmsClient.init({
59
121
  You can retrieve the elements of any page in your dotCMS system in JSON format using the `client.page.get()` method.
60
122
 
61
123
  ```javascript
62
- const pageData = await client.page.get({
63
- path: '/your-page-path',
64
- language_id: 1,
124
+ const pageData = await client.page.get('/your-page-path', {
125
+ languageId: '1',
65
126
  personaId: 'optional-persona-id'
66
127
  });
67
128
  ```
68
129
 
130
+ #### Example with all options
131
+
132
+ ```javascript
133
+ // Fetching a page with all available options
134
+ const { page, content } = await client.page.get('/about-us', {
135
+ languageId: '1', // Language ID (optional)
136
+ siteId: 'demo.dotcms.com', // Site ID (optional, defaults to the one provided during initialization)
137
+ mode: 'PREVIEW_MODE', // ADMIN_MODE, PREVIEW_MODE, or LIVE_MODE (optional)
138
+ personaId: '123', // Persona ID for personalization (optional)
139
+ device: 'smartphone', // Device for responsive rendering (optional)
140
+ graphql: { // Extend page and/or content response (optional)
141
+ page: `
142
+ containers {
143
+ containerContentlets {
144
+ uuid
145
+ contentlets {
146
+ title
147
+ }
148
+ }
149
+ }
150
+ `,
151
+ content: {
152
+ blogPosts: `
153
+ search(query: "+contentType:Blog", limit: 3) {
154
+ title
155
+ identifier
156
+ ...blogFragment
157
+ }
158
+ `,
159
+ },
160
+ fragments: [
161
+ `
162
+ fragment blogFragment on Blog {
163
+ urlTitle
164
+ blogContent {
165
+ json
166
+ }
167
+ }
168
+
169
+ `
170
+ ]
171
+ }
172
+ });
173
+
174
+ // Access page data
175
+ console.log(page.containers);
176
+
177
+ // Access content data
178
+ console.log(content.blogPosts);
179
+ ```
180
+
69
181
  ### Fetching Navigation
70
182
 
71
- Retrieve the dotCMS file and folder tree to get information about the navigation structure.
183
+ The new API allows you to fetch navigation data using GraphQL through the page.get method:
72
184
 
73
185
  ```javascript
186
+ // Fetch navigation using the page.get method with GraphQL
187
+ const { content } = await client.page.get('/', {
188
+ languageId: '1',
189
+ graphql: {
190
+ content: {
191
+ nav: `
192
+ query {
193
+ nav {
194
+ identifier
195
+ path
196
+ label
197
+ children {
198
+ identifier
199
+ path
200
+ label
201
+ }
202
+ }
203
+ }
204
+ `
205
+ }
206
+ }
207
+ });
208
+
209
+ // Access navigation data
210
+ console.log(content.nav);
211
+ ```
212
+
213
+ > **Note:** The legacy `client.nav.get()` method is still available but deprecated.
214
+
215
+ #### Legacy Navigation Example
216
+
217
+ ```javascript
218
+ // Legacy approach - still works but is deprecated
74
219
  const navData = await client.nav.get({
75
220
  path: '/',
76
221
  depth: 2,
@@ -84,12 +229,12 @@ The `getCollection` method allows you to fetch a collection of content items (so
84
229
 
85
230
  #### Basic Usage
86
231
 
87
- Heres a simple example to fetch content from a collection:
232
+ Here's a simple example to fetch content from a collection:
88
233
 
89
234
  ```typescript
90
- import { DotCmsClient } from '@dotcms/client';
235
+ import { dotCMSCreateClient } from '@dotcms/client';
91
236
 
92
- const client = DotCmsClient.init({
237
+ const client = dotCMSCreateClient({
93
238
  dotcmsUrl: 'https://your-dotcms-instance.com',
94
239
  authToken: 'your-auth-token'
95
240
  });
@@ -175,7 +320,7 @@ const combinedResponse = await client.content
175
320
 
176
321
  ## Error Handling Example
177
322
 
178
- To handle errors gracefully, you can use a `try-catch` block around your API calls. Heres an example:
323
+ To handle errors gracefully, you can use a `try-catch` block around your API calls. Here's an example:
179
324
 
180
325
  ```typescript
181
326
  try {
@@ -206,29 +351,12 @@ const paginatedResponse = await client.content
206
351
 
207
352
  Detailed documentation of the `@dotcms/client` methods, parameters, and types can be found below:
208
353
 
209
- ### `DotCmsClient.init(config: ClientConfig): DotCmsClient`
210
-
211
- Initializes the dotCMS client with the specified configuration.
212
-
213
- ### `DotCmsClient.page.get(options: PageApiOptions): Promise<unknown>`
214
-
215
- Retrieves the specified page's elements from your dotCMS system in JSON format.
216
-
217
- ### `DotCmsClient.nav.get(options: NavApiOptions): Promise<unknown>`
218
-
219
- Retrieves information about the dotCMS file and folder tree.
220
-
221
- ### `DotCmsClient.content.getCollection(contentType: string): CollectionBuilder<T>`
222
-
223
- Creates a builder to filter and fetches a collection of content items for a specific content type.
224
-
225
- #### Parameters
226
-
227
- `contentType` (string): The content type to retrieve.
228
-
229
- #### Returns
230
-
231
- `CollectionBuilder<T>`: A builder instance for chaining filters and executing the query.
354
+ | Method | Description | Parameters | Returns |
355
+ |--------|-------------|------------|---------|
356
+ | `dotCMSCreateClient(config)` | Initializes the dotCMS client | `config: DotCMSClientConfig` | `DotCMSClient` |
357
+ | `client.page.get(path, options)` | Retrieves page elements | `path: string, options: PageApiOptions` | `Promise<{page: any, content: any}>` |
358
+ | `client.nav.get(options)` | Retrieves navigation structure | `options: NavApiOptions` | `Promise<unknown>` |
359
+ | `client.content.getCollection(contentType)` | Builds a query for content | `contentType: string` | `CollectionBuilder<T>` |
232
360
 
233
361
  ## Contributing
234
362