@dotcms/client 0.0.1-beta.28 → 0.0.1-beta.29

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.
package/README.md CHANGED
@@ -127,11 +127,30 @@ const pageData = await client.page.get('/your-page-path', {
127
127
  });
128
128
  ```
129
129
 
130
+
131
+ ### Warning
132
+
133
+ If you are updating from a version that is lower than `0.0.1-beta.29`, be aware that the response from the `client.page.get` method changed the access to the page value from `page` to `pageAsset`.
134
+ This change was made to avoid redundancy on access inside of `page` object.
135
+
136
+ #### Before
137
+
138
+ ```javascript
139
+ const { page } = await client.page.get("/")
140
+ ```
141
+
142
+ #### After
143
+
144
+ ```javascript
145
+ const { pageAsset } = await client.page.get("/")
146
+ ```
147
+
148
+
130
149
  #### Example with all options
131
150
 
132
151
  ```javascript
133
152
  // Fetching a page with all available options
134
- const { page, content } = await client.page.get('/about-us', {
153
+ const { pageAsset, content } = await client.page.get('/about-us', {
135
154
  languageId: '1', // Language ID (optional)
136
155
  siteId: 'demo.dotcms.com', // Site ID (optional, defaults to the one provided during initialization)
137
156
  mode: 'PREVIEW_MODE', // ADMIN_MODE, PREVIEW_MODE, or LIVE_MODE (optional)
@@ -172,7 +191,7 @@ const { page, content } = await client.page.get('/about-us', {
172
191
  });
173
192
 
174
193
  // Access page data
175
- console.log(page.containers);
194
+ console.log(pageAsset.containers);
176
195
 
177
196
  // Access content data
178
197
  console.log(content.blogPosts);
package/next.cjs.js CHANGED
@@ -276,7 +276,7 @@ async function fetchGraphQL({ baseURL, body, headers }) {
276
276
  return await response.json();
277
277
  }
278
278
 
279
- var _PageClient_instances, _PageClient_isGraphQLRequest, _PageClient_getPageFromAPI, _PageClient_getPageFromGraphQL, _PageClient_mapToBackendParams;
279
+ var _PageClient_instances, _PageClient_getPageFromGraphQL;
280
280
  /**
281
281
  * Client for interacting with the DotCMS Page API.
282
282
  * Provides methods to retrieve and manipulate pages.
@@ -309,124 +309,69 @@ class PageClient {
309
309
  this.siteId = config.siteId || '';
310
310
  this.dotcmsUrl = config.dotcmsUrl;
311
311
  }
312
+ /**
313
+ * Retrieves a page from DotCMS using GraphQL.
314
+ *
315
+ * @param {string} url - The URL of the page to retrieve
316
+ * @param {DotCMSPageRequestParams} [options] - Options for the request
317
+ * @template T - The type of the page and content, defaults to DotCMSBasicPage and Record<string, unknown> | unknown
318
+ * @returns {Promise<DotCMSComposedPageResponse<T>>} A Promise that resolves to the page data
319
+ *
320
+ * @example Using GraphQL
321
+ * ```typescript
322
+ * const page = await pageClient.get<{ page: MyPageWithBanners; content: { blogPosts: { blogTitle: string } } }>(
323
+ * '/index',
324
+ * {
325
+ * languageId: '1',
326
+ * mode: 'LIVE',
327
+ * graphql: {
328
+ * page: `
329
+ * containers {
330
+ * containerContentlets {
331
+ * contentlets {
332
+ * ... on Banner {
333
+ * ...bannerFragment
334
+ * }
335
+ * }
336
+ * }
337
+ * `,
338
+ * content: {
339
+ * blogPosts: `
340
+ * BlogCollection(limit: 3) {
341
+ * ...blogFragment
342
+ * }
343
+ * `,
344
+ * },
345
+ * fragments: [
346
+ * `
347
+ * fragment bannerFragment on Banner {
348
+ * caption
349
+ * }
350
+ * `,
351
+ * `
352
+ * fragment blogFragment on Blog {
353
+ * title
354
+ * urlTitle
355
+ * }
356
+ * `
357
+ * ]
358
+ * }
359
+ * });
360
+ * ```
361
+ */
312
362
  get(url, options) {
313
- if (!options) {
314
- return transforms.__classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_getPageFromAPI).call(this, url);
315
- }
316
- if (transforms.__classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_isGraphQLRequest).call(this, options)) {
317
- return transforms.__classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_getPageFromGraphQL).call(this, url, options);
318
- }
319
- return transforms.__classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_getPageFromAPI).call(this, url, options);
363
+ return transforms.__classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_getPageFromGraphQL).call(this, url, options);
320
364
  }
321
365
  }
322
- _PageClient_instances = new WeakSet(), _PageClient_isGraphQLRequest = function _PageClient_isGraphQLRequest(options) {
323
- return 'graphql' in options;
324
- }, _PageClient_getPageFromAPI =
325
- /**
326
- * Retrieves all the elements of a Page in your dotCMS system in JSON format.
327
- *
328
- * @param {string} path - The path of the page to retrieve
329
- * @param {PageRequestParams} params - The options for the Page API call
330
- * @returns {Promise<unknown>} A Promise that resolves to the page data
331
- * @throws {Error} Throws an error if the path parameter is missing or if the fetch request fails
332
- * @example
333
- * ```typescript
334
- * // Get a page with default parameters
335
- * const homePage = await pageClient.get('/');
336
- *
337
- * // Get a page with specific language and mode
338
- * const aboutPage = await pageClient.get('/about-us', {
339
- * languageId: 2,
340
- * mode: 'PREVIEW_MODE'
341
- * });
342
- *
343
- * // Get a page with persona targeting
344
- * const productPage = await pageClient.get('/products', {
345
- * personaId: 'persona-123',
346
- * depth: 2
347
- * });
348
- * ```
349
- */
350
- async function _PageClient_getPageFromAPI(path, params) {
351
- if (!path) {
352
- throw new Error("The 'path' parameter is required for the Page API");
353
- }
354
- // If the siteId is not provided, use the one from the config
355
- const completedParams = {
356
- ...(params ?? {}),
357
- siteId: params?.siteId || this.siteId
358
- };
359
- // Map the public parameters to the one used by the API
360
- const normalizedParams = transforms.__classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_mapToBackendParams).call(this, completedParams || {});
361
- // Build the query params
362
- const queryParams = new URLSearchParams(normalizedParams).toString();
363
- // If the path starts with a slash, remove it to avoid double slashes in the final URL
364
- // Because the page path is part of api url path
365
- const pagePath = path.startsWith('/') ? path.slice(1) : path;
366
- const url = `${this.dotcmsUrl}/api/v1/page/json/${pagePath}?${queryParams}`;
367
- const response = await fetch(url, this.requestOptions);
368
- if (!response.ok) {
369
- const error = {
370
- status: response.status,
371
- message: transforms.ErrorMessages[response.status] || response.statusText
372
- };
373
- throw error;
374
- }
375
- return response.json().then((data) => ({
376
- ...data.entity,
377
- params: completedParams // We retrieve the params from the API response, to make the same fetch on UVE
378
- }));
379
- }, _PageClient_getPageFromGraphQL =
366
+ _PageClient_instances = new WeakSet(), _PageClient_getPageFromGraphQL =
380
367
  /**
381
- * Retrieves a personalized page with associated content and navigation.
368
+ * Private implementation method that fetches page data using GraphQL.
369
+ * This method is used internally by the public get() method.
382
370
  *
383
- * @param {Object} options - Options for the personalized page request
384
- * @param {string} options.url - The URL of the page to retrieve
385
- * @param {string} options.languageId - The language ID for the page content
386
- * @param {string} options.mode - The rendering mode for the page
387
- * @param {string} options.pageFragment - GraphQL fragment for page data
388
- * @param {Record<string, string>} options.content - Content queries to include
389
- * @param {Record<string, string>} options.nav - Navigation queries to include
390
- * @returns {Promise<Object>} A Promise that resolves to the personalized page data with content and navigation
391
- * @example
392
- * ```typescript
393
- * // Get a personalized page with content and navigation
394
- * const personalizedPage = await pageClient.getPageFromGraphQL({
395
- * url: '/about-us',
396
- * languageId: '1',
397
- * mode: 'LIVE',
398
- * pageFragment: `
399
- * fragment PageFields on Page {
400
- * title
401
- * description
402
- * modDate
403
- * }
404
- * `,
405
- * content: {
406
- * blogs: `
407
- * search(query: "+contentType: blog", limit: 3) {
408
- * title
409
- * ...on Blog {
410
- * author {
411
- * title
412
- * }
413
- * }
414
- }
415
- * nav: {
416
- * mainNav: `
417
- * query MainNav {
418
- * Nav(identifier: "main-nav") {
419
- * title
420
- * items {
421
- * label
422
- * url
423
- * }
424
- * }
425
- * }
426
- * `
427
- * }
428
- * });
429
- * ```
371
+ * @private
372
+ * @param {string} url - The URL of the page to retrieve
373
+ * @param {DotCMSPageRequestParams} [options] - Options including languageId, mode, and GraphQL parameters
374
+ * @returns {Promise<DotCMSPageResponse>} A Promise that resolves to the page data
430
375
  */
431
376
  async function _PageClient_getPageFromGraphQL(url, options) {
432
377
  const { languageId = '1', mode = 'LIVE', siteId = this.siteId, fireRules = false, personaId, publishDate, graphql = {} } = options || {};
@@ -466,7 +411,7 @@ async function _PageClient_getPageFromGraphQL(url, options) {
466
411
  }
467
412
  const contentResponse = mapResponseData(data, Object.keys(content));
468
413
  return {
469
- page: pageResponse,
414
+ pageAsset: pageResponse,
470
415
  content: contentResponse,
471
416
  graphql: {
472
417
  query: completeQuery,
@@ -485,18 +430,6 @@ async function _PageClient_getPageFromGraphQL(url, options) {
485
430
  };
486
431
  throw errorMessage;
487
432
  }
488
- }, _PageClient_mapToBackendParams = function _PageClient_mapToBackendParams(params) {
489
- const backendParams = {
490
- hostId: params.siteId,
491
- mode: params.mode,
492
- language_id: params.languageId ? String(params.languageId) : undefined,
493
- 'com.dotmarketing.persona.id': params.personaId,
494
- fireRules: params.fireRules ? String(params.fireRules) : undefined,
495
- depth: params.depth ? String(params.depth) : undefined,
496
- publishDate: params.publishDate
497
- };
498
- // Remove undefined values
499
- return Object.fromEntries(Object.entries(backendParams).filter(([_, value]) => value !== undefined));
500
433
  };
501
434
 
502
435
  /**
package/next.esm.js CHANGED
@@ -274,7 +274,7 @@ async function fetchGraphQL({ baseURL, body, headers }) {
274
274
  return await response.json();
275
275
  }
276
276
 
277
- var _PageClient_instances, _PageClient_isGraphQLRequest, _PageClient_getPageFromAPI, _PageClient_getPageFromGraphQL, _PageClient_mapToBackendParams;
277
+ var _PageClient_instances, _PageClient_getPageFromGraphQL;
278
278
  /**
279
279
  * Client for interacting with the DotCMS Page API.
280
280
  * Provides methods to retrieve and manipulate pages.
@@ -307,124 +307,69 @@ class PageClient {
307
307
  this.siteId = config.siteId || '';
308
308
  this.dotcmsUrl = config.dotcmsUrl;
309
309
  }
310
+ /**
311
+ * Retrieves a page from DotCMS using GraphQL.
312
+ *
313
+ * @param {string} url - The URL of the page to retrieve
314
+ * @param {DotCMSPageRequestParams} [options] - Options for the request
315
+ * @template T - The type of the page and content, defaults to DotCMSBasicPage and Record<string, unknown> | unknown
316
+ * @returns {Promise<DotCMSComposedPageResponse<T>>} A Promise that resolves to the page data
317
+ *
318
+ * @example Using GraphQL
319
+ * ```typescript
320
+ * const page = await pageClient.get<{ page: MyPageWithBanners; content: { blogPosts: { blogTitle: string } } }>(
321
+ * '/index',
322
+ * {
323
+ * languageId: '1',
324
+ * mode: 'LIVE',
325
+ * graphql: {
326
+ * page: `
327
+ * containers {
328
+ * containerContentlets {
329
+ * contentlets {
330
+ * ... on Banner {
331
+ * ...bannerFragment
332
+ * }
333
+ * }
334
+ * }
335
+ * `,
336
+ * content: {
337
+ * blogPosts: `
338
+ * BlogCollection(limit: 3) {
339
+ * ...blogFragment
340
+ * }
341
+ * `,
342
+ * },
343
+ * fragments: [
344
+ * `
345
+ * fragment bannerFragment on Banner {
346
+ * caption
347
+ * }
348
+ * `,
349
+ * `
350
+ * fragment blogFragment on Blog {
351
+ * title
352
+ * urlTitle
353
+ * }
354
+ * `
355
+ * ]
356
+ * }
357
+ * });
358
+ * ```
359
+ */
310
360
  get(url, options) {
311
- if (!options) {
312
- return __classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_getPageFromAPI).call(this, url);
313
- }
314
- if (__classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_isGraphQLRequest).call(this, options)) {
315
- return __classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_getPageFromGraphQL).call(this, url, options);
316
- }
317
- return __classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_getPageFromAPI).call(this, url, options);
361
+ return __classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_getPageFromGraphQL).call(this, url, options);
318
362
  }
319
363
  }
320
- _PageClient_instances = new WeakSet(), _PageClient_isGraphQLRequest = function _PageClient_isGraphQLRequest(options) {
321
- return 'graphql' in options;
322
- }, _PageClient_getPageFromAPI =
323
- /**
324
- * Retrieves all the elements of a Page in your dotCMS system in JSON format.
325
- *
326
- * @param {string} path - The path of the page to retrieve
327
- * @param {PageRequestParams} params - The options for the Page API call
328
- * @returns {Promise<unknown>} A Promise that resolves to the page data
329
- * @throws {Error} Throws an error if the path parameter is missing or if the fetch request fails
330
- * @example
331
- * ```typescript
332
- * // Get a page with default parameters
333
- * const homePage = await pageClient.get('/');
334
- *
335
- * // Get a page with specific language and mode
336
- * const aboutPage = await pageClient.get('/about-us', {
337
- * languageId: 2,
338
- * mode: 'PREVIEW_MODE'
339
- * });
340
- *
341
- * // Get a page with persona targeting
342
- * const productPage = await pageClient.get('/products', {
343
- * personaId: 'persona-123',
344
- * depth: 2
345
- * });
346
- * ```
347
- */
348
- async function _PageClient_getPageFromAPI(path, params) {
349
- if (!path) {
350
- throw new Error("The 'path' parameter is required for the Page API");
351
- }
352
- // If the siteId is not provided, use the one from the config
353
- const completedParams = {
354
- ...(params ?? {}),
355
- siteId: params?.siteId || this.siteId
356
- };
357
- // Map the public parameters to the one used by the API
358
- const normalizedParams = __classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_mapToBackendParams).call(this, completedParams || {});
359
- // Build the query params
360
- const queryParams = new URLSearchParams(normalizedParams).toString();
361
- // If the path starts with a slash, remove it to avoid double slashes in the final URL
362
- // Because the page path is part of api url path
363
- const pagePath = path.startsWith('/') ? path.slice(1) : path;
364
- const url = `${this.dotcmsUrl}/api/v1/page/json/${pagePath}?${queryParams}`;
365
- const response = await fetch(url, this.requestOptions);
366
- if (!response.ok) {
367
- const error = {
368
- status: response.status,
369
- message: ErrorMessages[response.status] || response.statusText
370
- };
371
- throw error;
372
- }
373
- return response.json().then((data) => ({
374
- ...data.entity,
375
- params: completedParams // We retrieve the params from the API response, to make the same fetch on UVE
376
- }));
377
- }, _PageClient_getPageFromGraphQL =
364
+ _PageClient_instances = new WeakSet(), _PageClient_getPageFromGraphQL =
378
365
  /**
379
- * Retrieves a personalized page with associated content and navigation.
366
+ * Private implementation method that fetches page data using GraphQL.
367
+ * This method is used internally by the public get() method.
380
368
  *
381
- * @param {Object} options - Options for the personalized page request
382
- * @param {string} options.url - The URL of the page to retrieve
383
- * @param {string} options.languageId - The language ID for the page content
384
- * @param {string} options.mode - The rendering mode for the page
385
- * @param {string} options.pageFragment - GraphQL fragment for page data
386
- * @param {Record<string, string>} options.content - Content queries to include
387
- * @param {Record<string, string>} options.nav - Navigation queries to include
388
- * @returns {Promise<Object>} A Promise that resolves to the personalized page data with content and navigation
389
- * @example
390
- * ```typescript
391
- * // Get a personalized page with content and navigation
392
- * const personalizedPage = await pageClient.getPageFromGraphQL({
393
- * url: '/about-us',
394
- * languageId: '1',
395
- * mode: 'LIVE',
396
- * pageFragment: `
397
- * fragment PageFields on Page {
398
- * title
399
- * description
400
- * modDate
401
- * }
402
- * `,
403
- * content: {
404
- * blogs: `
405
- * search(query: "+contentType: blog", limit: 3) {
406
- * title
407
- * ...on Blog {
408
- * author {
409
- * title
410
- * }
411
- * }
412
- }
413
- * nav: {
414
- * mainNav: `
415
- * query MainNav {
416
- * Nav(identifier: "main-nav") {
417
- * title
418
- * items {
419
- * label
420
- * url
421
- * }
422
- * }
423
- * }
424
- * `
425
- * }
426
- * });
427
- * ```
369
+ * @private
370
+ * @param {string} url - The URL of the page to retrieve
371
+ * @param {DotCMSPageRequestParams} [options] - Options including languageId, mode, and GraphQL parameters
372
+ * @returns {Promise<DotCMSPageResponse>} A Promise that resolves to the page data
428
373
  */
429
374
  async function _PageClient_getPageFromGraphQL(url, options) {
430
375
  const { languageId = '1', mode = 'LIVE', siteId = this.siteId, fireRules = false, personaId, publishDate, graphql = {} } = options || {};
@@ -464,7 +409,7 @@ async function _PageClient_getPageFromGraphQL(url, options) {
464
409
  }
465
410
  const contentResponse = mapResponseData(data, Object.keys(content));
466
411
  return {
467
- page: pageResponse,
412
+ pageAsset: pageResponse,
468
413
  content: contentResponse,
469
414
  graphql: {
470
415
  query: completeQuery,
@@ -483,18 +428,6 @@ async function _PageClient_getPageFromGraphQL(url, options) {
483
428
  };
484
429
  throw errorMessage;
485
430
  }
486
- }, _PageClient_mapToBackendParams = function _PageClient_mapToBackendParams(params) {
487
- const backendParams = {
488
- hostId: params.siteId,
489
- mode: params.mode,
490
- language_id: params.languageId ? String(params.languageId) : undefined,
491
- 'com.dotmarketing.persona.id': params.personaId,
492
- fireRules: params.fireRules ? String(params.fireRules) : undefined,
493
- depth: params.depth ? String(params.depth) : undefined,
494
- publishDate: params.publishDate
495
- };
496
- // Remove undefined values
497
- return Object.fromEntries(Object.entries(backendParams).filter(([_, value]) => value !== undefined));
498
431
  };
499
432
 
500
433
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/client",
3
- "version": "0.0.1-beta.28",
3
+ "version": "0.0.1-beta.29",
4
4
  "description": "Official JavaScript library for interacting with DotCMS REST APIs.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,35 +1,7 @@
1
+ import { DotCMSClientConfig } from '@dotcms/types';
1
2
  import { Content } from './content/content-api';
2
3
  import { NavigationClient } from './navigation/navigation-api';
3
4
  import { PageClient } from './page/page-api';
4
- /**
5
- * Options for configuring fetch requests, excluding body and method properties.
6
- */
7
- export type RequestOptions = Omit<RequestInit, 'body' | 'method'>;
8
- /**
9
- * Configuration options for the DotCMS client.
10
- */
11
- export interface DotCMSClientConfig {
12
- /**
13
- * The URL of the dotCMS instance.
14
- * Ensure to include the protocol (http or https).
15
- * @example `https://demo.dotcms.com`
16
- */
17
- dotcmsUrl: string;
18
- /**
19
- * The authentication token for requests.
20
- * Obtainable from the dotCMS UI.
21
- */
22
- authToken: string;
23
- /**
24
- * The id of the site you want to interact with. Defaults to the default site if not provided.
25
- */
26
- siteId?: string;
27
- /**
28
- * Additional options for the fetch request.
29
- * @example `{ headers: { 'Content-Type': 'application/json' } }`
30
- */
31
- requestOptions?: RequestOptions;
32
- }
33
5
  /**
34
6
  * Client for interacting with the DotCMS REST API.
35
7
  * Provides access to content, page, and navigation functionality.
@@ -1,5 +1,5 @@
1
+ import { RequestOptions } from '@dotcms/types';
1
2
  import { CollectionBuilder } from './builders/collection/collection';
2
- import { ClientOptions } from '../../deprecated/sdk-js-client';
3
3
  /**
4
4
  * Creates a builder to filter and fetch a collection of content items.
5
5
  * @param contentType - The content type to retrieve.
@@ -56,10 +56,10 @@ export declare class Content {
56
56
  #private;
57
57
  /**
58
58
  * Creates an instance of Content.
59
- * @param {ClientOptions} requestOptions - The options for the client request.
59
+ * @param {RequestOptions} requestOptions - The options for the client request.
60
60
  * @param {string} serverUrl - The server URL.
61
61
  */
62
- constructor(requestOptions: ClientOptions, serverUrl: string);
62
+ constructor(requestOptions: RequestOptions, serverUrl: string);
63
63
  /**
64
64
  * Takes a content type and returns a builder to filter and fetch the collection.
65
65
  * @param {string} contentType - The content type to get the collection.
@@ -1,3 +1,4 @@
1
+ import { Contentlet } from '@dotcms/types';
1
2
  import { Equals } from '../builders/query/lucene-syntax';
2
3
  import { QueryBuilder } from '../builders/query/query';
3
4
  /**
@@ -21,48 +22,6 @@ export type SortBy = {
21
22
  * @returns {Equals} The built query.
22
23
  */
23
24
  export type BuildQuery = (qb: QueryBuilder) => Equals;
24
- /**
25
- * Main fields of a Contentlet (Inherited from the Content Type).
26
- */
27
- export interface ContentTypeMainFields {
28
- hostName: string;
29
- modDate: string;
30
- publishDate: string;
31
- title: string;
32
- baseType: string;
33
- inode: string;
34
- archived: boolean;
35
- ownerName: string;
36
- host: string;
37
- working: boolean;
38
- locked: boolean;
39
- stInode: string;
40
- contentType: string;
41
- live: boolean;
42
- owner: string;
43
- identifier: string;
44
- publishUserName: string;
45
- publishUser: string;
46
- languageId: number;
47
- creationDate: string;
48
- url: string;
49
- titleImage: string;
50
- modUserName: string;
51
- hasLiveVersion: boolean;
52
- folder: string;
53
- hasTitleImage: boolean;
54
- sortOrder: number;
55
- modUser: string;
56
- __icon__: string;
57
- contentTypeIcon: string;
58
- variant: string;
59
- }
60
- /**
61
- * The contentlet has the main fields and the custom fields of the content type.
62
- *
63
- * @template T - The custom fields of the content type.
64
- */
65
- export type Contentlet<T> = T & ContentTypeMainFields;
66
25
  /**
67
26
  * Callback for a fulfilled promise.
68
27
  *
@@ -1,20 +1,4 @@
1
- import { DotCMSClientConfig, RequestOptions } from '../client';
2
- interface NavRequestParams {
3
- /**
4
- * The depth of the folder tree to return.
5
- * @example
6
- * `1` returns only the element specified in the path.
7
- * `2` returns the element specified in the path, and if that element is a folder, returns all direct children of that folder.
8
- * `3` returns all children and grandchildren of the element specified in the path.
9
- */
10
- depth?: number;
11
- /**
12
- * The language ID of content to return.
13
- * @example
14
- * `1` (or unspecified) returns content in the default language of the site.
15
- */
16
- languageId?: number;
17
- }
1
+ import { DotCMSClientConfig, DotCMSNavigationRequestParams, RequestOptions } from '@dotcms/types';
18
2
  export declare class NavigationClient {
19
3
  private requestOptions;
20
4
  private BASE_URL;
@@ -25,7 +9,6 @@ export declare class NavigationClient {
25
9
  * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
26
10
  * @throws {Error} - Throws an error if the options are not valid.
27
11
  */
28
- get(path: string, params?: NavRequestParams): Promise<unknown>;
12
+ get(path: string, params?: DotCMSNavigationRequestParams): Promise<unknown>;
29
13
  private mapToBackendParams;
30
14
  }
31
- export {};
@@ -1,71 +1,4 @@
1
- import { DotCMSPageAsset, DotCMSGraphQLPageResponse } from '@dotcms/types';
2
- import { DotCMSClientConfig, RequestOptions } from '../client';
3
- /**
4
- * The parameters for the Page API.
5
- * @public
6
- */
7
- export interface PageRequestParams {
8
- /**
9
- * The id of the site you want to interact with. Defaults to the one from the config if not provided.
10
- */
11
- siteId?: string;
12
- /**
13
- * The mode of the page you want to retrieve. Defaults to the site's default mode if not provided.
14
- */
15
- mode?: 'EDIT_MODE' | 'PREVIEW_MODE' | 'LIVE';
16
- /**
17
- * The language id of the page you want to retrieve. Defaults to the site's default language if not provided.
18
- */
19
- languageId?: number | string;
20
- /**
21
- * The id of the persona for which you want to retrieve the page.
22
- */
23
- personaId?: string;
24
- /**
25
- * Whether to fire the rules set on the page.
26
- */
27
- fireRules?: boolean | string;
28
- /**
29
- * Allows access to related content via the Relationship fields of contentlets on a Page; 0 (default).
30
- */
31
- depth?: 0 | 1 | 2 | 3 | '0' | '1' | '2' | '3';
32
- /**
33
- * The publish date of the page you want to retrieve.
34
- */
35
- publishDate?: string;
36
- /**
37
- * The variant name of the page you want to retrieve.
38
- */
39
- variantName?: string;
40
- }
41
- type StringifyParam<T> = T extends string | number | boolean ? string : never;
42
- type PageToBackendParamsMapping = {
43
- siteId: 'hostId';
44
- languageId: 'language_id';
45
- personaId: 'com.dotmarketing.persona.id';
46
- };
47
- /**
48
- * The private parameters for the Page API.
49
- * @internal
50
- */
51
- export type BackendPageParams = {
52
- [K in keyof PageRequestParams as K extends keyof PageToBackendParamsMapping ? PageToBackendParamsMapping[K] : K]?: StringifyParam<PageRequestParams[K]>;
53
- };
54
- /**
55
- * The options for the GraphQL Page API.
56
- * @public
57
- */
58
- export interface GraphQLPageOptions extends PageRequestParams {
59
- /**
60
- * The GraphQL options for the page.
61
- */
62
- graphql: {
63
- page?: string;
64
- content?: Record<string, string>;
65
- variables?: Record<string, string>;
66
- fragments?: string[];
67
- };
68
- }
1
+ import { DotCMSClientConfig, DotCMSComposedPageResponse, DotCMSExtendedPageResponse, DotCMSPageResponse, DotCMSPageRequestParams, RequestOptions } from '@dotcms/types';
69
2
  /**
70
3
  * Client for interacting with the DotCMS Page API.
71
4
  * Provides methods to retrieve and manipulate pages.
@@ -110,29 +43,22 @@ export declare class PageClient {
110
43
  */
111
44
  constructor(config: DotCMSClientConfig, requestOptions: RequestOptions);
112
45
  /**
113
- * Retrieves a page from DotCMS using either REST API or GraphQL.
114
- * This method is polymorphic and can handle both REST API and GraphQL requests based on the options provided.
46
+ * Retrieves a page from DotCMS using GraphQL.
115
47
  *
116
48
  * @param {string} url - The URL of the page to retrieve
117
- * @param {PageRequestParams | GraphQLPageOptions} [options] - Options for the request
118
- * @returns {Promise<DotCMSPageAsset | DotCMSGraphQLPageResponse>} A Promise that resolves to the page data
119
- *
120
- * @example Using REST API with options
121
- * ```typescript
122
- * const page = await pageClient.get('/about-us', {
123
- * mode: 'PREVIEW_MODE',
124
- * languageId: 1,
125
- * siteId: 'demo.dotcms.com'
126
- * });
127
- * ```
49
+ * @param {DotCMSPageRequestParams} [options] - Options for the request
50
+ * @template T - The type of the page and content, defaults to DotCMSBasicPage and Record<string, unknown> | unknown
51
+ * @returns {Promise<DotCMSComposedPageResponse<T>>} A Promise that resolves to the page data
128
52
  *
129
53
  * @example Using GraphQL
130
54
  * ```typescript
131
- * const page = await pageClient.get('/index', {
132
- * languageId: '1',
133
- * mode: 'LIVE',
134
- * graphql: {
135
- * page: `
55
+ * const page = await pageClient.get<{ page: MyPageWithBanners; content: { blogPosts: { blogTitle: string } } }>(
56
+ * '/index',
57
+ * {
58
+ * languageId: '1',
59
+ * mode: 'LIVE',
60
+ * graphql: {
61
+ * page: `
136
62
  * containers {
137
63
  * containerContentlets {
138
64
  * contentlets {
@@ -164,9 +90,7 @@ export declare class PageClient {
164
90
  * ]
165
91
  * }
166
92
  * });
167
- *```
93
+ * ```
168
94
  */
169
- get<T extends DotCMSPageAsset | DotCMSGraphQLPageResponse = DotCMSPageAsset>(url: string, options?: PageRequestParams): Promise<T>;
170
- get<T extends DotCMSPageAsset | DotCMSGraphQLPageResponse = DotCMSGraphQLPageResponse>(url: string, options?: GraphQLPageOptions): Promise<T>;
95
+ get<T extends DotCMSExtendedPageResponse = DotCMSPageResponse>(url: string, options?: DotCMSPageRequestParams): Promise<DotCMSComposedPageResponse<T>>;
171
96
  }
172
- export {};
@@ -1,6 +1,6 @@
1
+ import { Contentlet } from '@dotcms/types';
1
2
  import { DotCMSPageEditorConfig, ReorderMenuConfig } from './models/editor.model';
2
3
  import { INLINE_EDITING_EVENT_KEY, InlineEditEventData } from './models/inline-event.model';
3
- import { Contentlet } from '../../client/content/shared/types';
4
4
  /**
5
5
  * Updates the navigation in the editor.
6
6
  *
package/transforms.cjs.js CHANGED
@@ -964,7 +964,7 @@ var _Content_requestOptions, _Content_serverUrl;
964
964
  class Content {
965
965
  /**
966
966
  * Creates an instance of Content.
967
- * @param {ClientOptions} requestOptions - The options for the client request.
967
+ * @param {RequestOptions} requestOptions - The options for the client request.
968
968
  * @param {string} serverUrl - The server URL.
969
969
  */
970
970
  constructor(requestOptions, serverUrl) {
@@ -1099,7 +1099,7 @@ const graphqlToPageEntity = (graphQLPageResponse) => {
1099
1099
  },
1100
1100
  containers: parseContainers(containers),
1101
1101
  urlContentMap: urlContentMapData
1102
- };
1102
+ }; // NOTE: This is a rabbit hole and we have to fix this, not in this PR tho.
1103
1103
  };
1104
1104
  /**
1105
1105
  * Parses the containers from the GraphQL response.
package/transforms.esm.js CHANGED
@@ -962,7 +962,7 @@ var _Content_requestOptions, _Content_serverUrl;
962
962
  class Content {
963
963
  /**
964
964
  * Creates an instance of Content.
965
- * @param {ClientOptions} requestOptions - The options for the client request.
965
+ * @param {RequestOptions} requestOptions - The options for the client request.
966
966
  * @param {string} serverUrl - The server URL.
967
967
  */
968
968
  constructor(requestOptions, serverUrl) {
@@ -1097,7 +1097,7 @@ const graphqlToPageEntity = (graphQLPageResponse) => {
1097
1097
  },
1098
1098
  containers: parseContainers(containers),
1099
1099
  urlContentMap: urlContentMapData
1100
- };
1100
+ }; // NOTE: This is a rabbit hole and we have to fix this, not in this PR tho.
1101
1101
  };
1102
1102
  /**
1103
1103
  * Parses the containers from the GraphQL response.