@dotcms/client 0.0.1-beta.20 → 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.
- package/README.md +3 -3
- package/next.cjs.js +31 -9
- package/next.esm.js +31 -9
- package/package.json +1 -1
- package/src/lib/client/models/types.d.ts +6 -0
- package/src/lib/client/page/page-api.d.ts +7 -0
- package/transforms.cjs.js +6 -2
- package/transforms.esm.js +6 -2
package/README.md
CHANGED
|
@@ -95,13 +95,13 @@ The @dotcms/client package is compatible with the following browsers:
|
|
|
95
95
|
### ES Modules
|
|
96
96
|
|
|
97
97
|
```javascript
|
|
98
|
-
import {
|
|
98
|
+
import { createDotCMSClient } from '@dotcms/client/next';
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
### CommonJS
|
|
102
102
|
|
|
103
103
|
```javascript
|
|
104
|
-
const {
|
|
104
|
+
const { createDotCMSClient } = require('@dotcms/client/next');
|
|
105
105
|
```
|
|
106
106
|
|
|
107
107
|
### Initialization
|
|
@@ -109,7 +109,7 @@ const { dotCMSCreateClient } = require('@dotcms/client');
|
|
|
109
109
|
First, initialize the client with your dotCMS instance details.
|
|
110
110
|
|
|
111
111
|
```javascript
|
|
112
|
-
const client =
|
|
112
|
+
const client = createDotCMSClient({
|
|
113
113
|
dotcmsUrl: 'https://your-dotcms-instance.com',
|
|
114
114
|
authToken: 'your-auth-token',
|
|
115
115
|
siteId: 'your-site-id'
|
package/next.cjs.js
CHANGED
|
@@ -125,6 +125,9 @@ const buildPageQuery = ({ page, fragments, additionalQueries }) => {
|
|
|
125
125
|
canEdit
|
|
126
126
|
canLock
|
|
127
127
|
canRead
|
|
128
|
+
urlContentMap {
|
|
129
|
+
_map
|
|
130
|
+
}
|
|
128
131
|
conLanguage {
|
|
129
132
|
id
|
|
130
133
|
language
|
|
@@ -190,8 +193,8 @@ const buildPageQuery = ({ page, fragments, additionalQueries }) => {
|
|
|
190
193
|
|
|
191
194
|
${fragments ? fragments.join('\n\n') : ''}
|
|
192
195
|
|
|
193
|
-
query PageContent($url: String!, $languageId: String, $mode: String) {
|
|
194
|
-
page: page(url: $url, languageId: $languageId, pageMode: $mode) {
|
|
196
|
+
query PageContent($url: String!, $languageId: String, $mode: String, $personaId: String, $fireRules: Boolean, $publishDate: String, $siteId: String) {
|
|
197
|
+
page: page(url: $url, languageId: $languageId, pageMode: $mode, persona: $personaId, fireRules: $fireRules, publishDate: $publishDate, site: $siteId) {
|
|
195
198
|
...DotCMSPage
|
|
196
199
|
${page ? '...ClientPage' : ''}
|
|
197
200
|
}
|
|
@@ -330,7 +333,14 @@ async function _PageClient_getPageFromAPI(path, params) {
|
|
|
330
333
|
if (!path) {
|
|
331
334
|
throw new Error("The 'path' parameter is required for the Page API");
|
|
332
335
|
}
|
|
333
|
-
|
|
336
|
+
// If the siteId is not provided, use the one from the config
|
|
337
|
+
const completedParams = {
|
|
338
|
+
...(params ?? {}),
|
|
339
|
+
siteId: params?.siteId || this.siteId
|
|
340
|
+
};
|
|
341
|
+
// Map the public parameters to the one used by the API
|
|
342
|
+
const normalizedParams = transforms.__classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_mapToBackendParams).call(this, completedParams || {});
|
|
343
|
+
// Build the query params
|
|
334
344
|
const queryParams = new URLSearchParams(normalizedParams).toString();
|
|
335
345
|
// If the path starts with a slash, remove it to avoid double slashes in the final URL
|
|
336
346
|
// Because the page path is part of api url path
|
|
@@ -344,7 +354,10 @@ async function _PageClient_getPageFromAPI(path, params) {
|
|
|
344
354
|
};
|
|
345
355
|
throw error;
|
|
346
356
|
}
|
|
347
|
-
return response.json().then((data) =>
|
|
357
|
+
return response.json().then((data) => ({
|
|
358
|
+
...data.entity,
|
|
359
|
+
params: completedParams // We retrieve the params from the API response, to make the same fetch on UVE
|
|
360
|
+
}));
|
|
348
361
|
}, _PageClient_getPageFromGraphQL =
|
|
349
362
|
/**
|
|
350
363
|
* Retrieves a personalized page with associated content and navigation.
|
|
@@ -398,7 +411,7 @@ async function _PageClient_getPageFromAPI(path, params) {
|
|
|
398
411
|
* ```
|
|
399
412
|
*/
|
|
400
413
|
async function _PageClient_getPageFromGraphQL(url, options) {
|
|
401
|
-
const { languageId = '1', mode = 'LIVE', graphql = {} } = options || {};
|
|
414
|
+
const { languageId = '1', mode = 'LIVE', siteId = this.siteId, fireRules = false, personaId, publishDate, graphql = {} } = options || {};
|
|
402
415
|
const { page, content = {}, variables, fragments } = graphql;
|
|
403
416
|
const contentQuery = buildQuery(content);
|
|
404
417
|
const completeQuery = buildPageQuery({
|
|
@@ -410,6 +423,10 @@ async function _PageClient_getPageFromGraphQL(url, options) {
|
|
|
410
423
|
url,
|
|
411
424
|
mode,
|
|
412
425
|
languageId,
|
|
426
|
+
personaId,
|
|
427
|
+
fireRules,
|
|
428
|
+
publishDate,
|
|
429
|
+
siteId,
|
|
413
430
|
...variables
|
|
414
431
|
};
|
|
415
432
|
const requestHeaders = this.requestOptions.headers;
|
|
@@ -433,21 +450,26 @@ async function _PageClient_getPageFromGraphQL(url, options) {
|
|
|
433
450
|
return {
|
|
434
451
|
page: pageResponse,
|
|
435
452
|
content: contentResponse,
|
|
436
|
-
|
|
453
|
+
graphql: {
|
|
454
|
+
query: completeQuery,
|
|
455
|
+
variables: requestVariables
|
|
456
|
+
}
|
|
437
457
|
};
|
|
438
458
|
}
|
|
439
459
|
catch (error) {
|
|
440
460
|
const errorMessage = {
|
|
441
461
|
error,
|
|
442
462
|
message: 'Failed to retrieve page data',
|
|
443
|
-
|
|
444
|
-
|
|
463
|
+
graphql: {
|
|
464
|
+
query: completeQuery,
|
|
465
|
+
variables: requestVariables
|
|
466
|
+
}
|
|
445
467
|
};
|
|
446
468
|
throw errorMessage;
|
|
447
469
|
}
|
|
448
470
|
}, _PageClient_mapToBackendParams = function _PageClient_mapToBackendParams(params) {
|
|
449
471
|
const backendParams = {
|
|
450
|
-
hostId: params.siteId
|
|
472
|
+
hostId: params.siteId,
|
|
451
473
|
mode: params.mode,
|
|
452
474
|
language_id: params.languageId ? String(params.languageId) : undefined,
|
|
453
475
|
'com.dotmarketing.persona.id': params.personaId,
|
package/next.esm.js
CHANGED
|
@@ -123,6 +123,9 @@ const buildPageQuery = ({ page, fragments, additionalQueries }) => {
|
|
|
123
123
|
canEdit
|
|
124
124
|
canLock
|
|
125
125
|
canRead
|
|
126
|
+
urlContentMap {
|
|
127
|
+
_map
|
|
128
|
+
}
|
|
126
129
|
conLanguage {
|
|
127
130
|
id
|
|
128
131
|
language
|
|
@@ -188,8 +191,8 @@ const buildPageQuery = ({ page, fragments, additionalQueries }) => {
|
|
|
188
191
|
|
|
189
192
|
${fragments ? fragments.join('\n\n') : ''}
|
|
190
193
|
|
|
191
|
-
query PageContent($url: String!, $languageId: String, $mode: String) {
|
|
192
|
-
page: page(url: $url, languageId: $languageId, pageMode: $mode) {
|
|
194
|
+
query PageContent($url: String!, $languageId: String, $mode: String, $personaId: String, $fireRules: Boolean, $publishDate: String, $siteId: String) {
|
|
195
|
+
page: page(url: $url, languageId: $languageId, pageMode: $mode, persona: $personaId, fireRules: $fireRules, publishDate: $publishDate, site: $siteId) {
|
|
193
196
|
...DotCMSPage
|
|
194
197
|
${page ? '...ClientPage' : ''}
|
|
195
198
|
}
|
|
@@ -328,7 +331,14 @@ async function _PageClient_getPageFromAPI(path, params) {
|
|
|
328
331
|
if (!path) {
|
|
329
332
|
throw new Error("The 'path' parameter is required for the Page API");
|
|
330
333
|
}
|
|
331
|
-
|
|
334
|
+
// If the siteId is not provided, use the one from the config
|
|
335
|
+
const completedParams = {
|
|
336
|
+
...(params ?? {}),
|
|
337
|
+
siteId: params?.siteId || this.siteId
|
|
338
|
+
};
|
|
339
|
+
// Map the public parameters to the one used by the API
|
|
340
|
+
const normalizedParams = __classPrivateFieldGet(this, _PageClient_instances, "m", _PageClient_mapToBackendParams).call(this, completedParams || {});
|
|
341
|
+
// Build the query params
|
|
332
342
|
const queryParams = new URLSearchParams(normalizedParams).toString();
|
|
333
343
|
// If the path starts with a slash, remove it to avoid double slashes in the final URL
|
|
334
344
|
// Because the page path is part of api url path
|
|
@@ -342,7 +352,10 @@ async function _PageClient_getPageFromAPI(path, params) {
|
|
|
342
352
|
};
|
|
343
353
|
throw error;
|
|
344
354
|
}
|
|
345
|
-
return response.json().then((data) =>
|
|
355
|
+
return response.json().then((data) => ({
|
|
356
|
+
...data.entity,
|
|
357
|
+
params: completedParams // We retrieve the params from the API response, to make the same fetch on UVE
|
|
358
|
+
}));
|
|
346
359
|
}, _PageClient_getPageFromGraphQL =
|
|
347
360
|
/**
|
|
348
361
|
* Retrieves a personalized page with associated content and navigation.
|
|
@@ -396,7 +409,7 @@ async function _PageClient_getPageFromAPI(path, params) {
|
|
|
396
409
|
* ```
|
|
397
410
|
*/
|
|
398
411
|
async function _PageClient_getPageFromGraphQL(url, options) {
|
|
399
|
-
const { languageId = '1', mode = 'LIVE', graphql = {} } = options || {};
|
|
412
|
+
const { languageId = '1', mode = 'LIVE', siteId = this.siteId, fireRules = false, personaId, publishDate, graphql = {} } = options || {};
|
|
400
413
|
const { page, content = {}, variables, fragments } = graphql;
|
|
401
414
|
const contentQuery = buildQuery(content);
|
|
402
415
|
const completeQuery = buildPageQuery({
|
|
@@ -408,6 +421,10 @@ async function _PageClient_getPageFromGraphQL(url, options) {
|
|
|
408
421
|
url,
|
|
409
422
|
mode,
|
|
410
423
|
languageId,
|
|
424
|
+
personaId,
|
|
425
|
+
fireRules,
|
|
426
|
+
publishDate,
|
|
427
|
+
siteId,
|
|
411
428
|
...variables
|
|
412
429
|
};
|
|
413
430
|
const requestHeaders = this.requestOptions.headers;
|
|
@@ -431,21 +448,26 @@ async function _PageClient_getPageFromGraphQL(url, options) {
|
|
|
431
448
|
return {
|
|
432
449
|
page: pageResponse,
|
|
433
450
|
content: contentResponse,
|
|
434
|
-
|
|
451
|
+
graphql: {
|
|
452
|
+
query: completeQuery,
|
|
453
|
+
variables: requestVariables
|
|
454
|
+
}
|
|
435
455
|
};
|
|
436
456
|
}
|
|
437
457
|
catch (error) {
|
|
438
458
|
const errorMessage = {
|
|
439
459
|
error,
|
|
440
460
|
message: 'Failed to retrieve page data',
|
|
441
|
-
|
|
442
|
-
|
|
461
|
+
graphql: {
|
|
462
|
+
query: completeQuery,
|
|
463
|
+
variables: requestVariables
|
|
464
|
+
}
|
|
443
465
|
};
|
|
444
466
|
throw errorMessage;
|
|
445
467
|
}
|
|
446
468
|
}, _PageClient_mapToBackendParams = function _PageClient_mapToBackendParams(params) {
|
|
447
469
|
const backendParams = {
|
|
448
|
-
hostId: params.siteId
|
|
470
|
+
hostId: params.siteId,
|
|
449
471
|
mode: params.mode,
|
|
450
472
|
language_id: params.languageId ? String(params.languageId) : undefined,
|
|
451
473
|
'com.dotmarketing.persona.id': params.personaId,
|
package/package.json
CHANGED
|
@@ -63,6 +63,8 @@ export interface DotCMSPageAsset<T = unknown> {
|
|
|
63
63
|
urlContentMap?: T extends {
|
|
64
64
|
urlContentMap: infer U;
|
|
65
65
|
} ? Contentlet<U> : Contentlet<T>;
|
|
66
|
+
/** The parameters used to fetch the page */
|
|
67
|
+
params?: Record<string, unknown>;
|
|
66
68
|
}
|
|
67
69
|
export interface DotPageAssetLayoutRow {
|
|
68
70
|
identifier: number;
|
|
@@ -566,5 +568,9 @@ export interface DotCMSGraphQLPageResponse<TContent = Record<string, any>> {
|
|
|
566
568
|
page: DotCMSBasicGraphQLPage;
|
|
567
569
|
content?: TContent;
|
|
568
570
|
errors?: DotCMSGraphQLError;
|
|
571
|
+
graphql: {
|
|
572
|
+
query: string;
|
|
573
|
+
variables: Record<string, unknown>;
|
|
574
|
+
};
|
|
569
575
|
}
|
|
570
576
|
export {};
|
|
@@ -51,7 +51,14 @@ type PageToBackendParamsMapping = {
|
|
|
51
51
|
export type BackendPageParams = {
|
|
52
52
|
[K in keyof PageRequestParams as K extends keyof PageToBackendParamsMapping ? PageToBackendParamsMapping[K] : K]?: StringifyParam<PageRequestParams[K]>;
|
|
53
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* The options for the GraphQL Page API.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
54
58
|
export interface GraphQLPageOptions extends PageRequestParams {
|
|
59
|
+
/**
|
|
60
|
+
* The GraphQL options for the page.
|
|
61
|
+
*/
|
|
55
62
|
graphql: {
|
|
56
63
|
page?: string;
|
|
57
64
|
content?: Record<string, string>;
|
package/transforms.cjs.js
CHANGED
|
@@ -1083,17 +1083,21 @@ const graphqlToPageEntity = (graphQLPageResponse) => {
|
|
|
1083
1083
|
}
|
|
1084
1084
|
const { layout, template, containers, urlContentMap, viewAs, site, _map, ...pageAsset } = page;
|
|
1085
1085
|
const data = (_map || {});
|
|
1086
|
+
// To prevent type errors, we cast the urlContentMap to an object
|
|
1087
|
+
const urlContentMapObject = urlContentMap;
|
|
1088
|
+
// Extract the _map data from the urlContentMap object
|
|
1089
|
+
const urlContentMapData = urlContentMapObject?.['_map'];
|
|
1086
1090
|
return {
|
|
1087
1091
|
layout,
|
|
1088
1092
|
template,
|
|
1089
1093
|
viewAs,
|
|
1090
|
-
urlContentMap,
|
|
1091
1094
|
site,
|
|
1092
1095
|
page: {
|
|
1093
1096
|
...data,
|
|
1094
1097
|
...pageAsset
|
|
1095
1098
|
},
|
|
1096
|
-
containers: parseContainers(containers)
|
|
1099
|
+
containers: parseContainers(containers),
|
|
1100
|
+
urlContentMap: urlContentMapData
|
|
1097
1101
|
};
|
|
1098
1102
|
};
|
|
1099
1103
|
/**
|
package/transforms.esm.js
CHANGED
|
@@ -1081,17 +1081,21 @@ const graphqlToPageEntity = (graphQLPageResponse) => {
|
|
|
1081
1081
|
}
|
|
1082
1082
|
const { layout, template, containers, urlContentMap, viewAs, site, _map, ...pageAsset } = page;
|
|
1083
1083
|
const data = (_map || {});
|
|
1084
|
+
// To prevent type errors, we cast the urlContentMap to an object
|
|
1085
|
+
const urlContentMapObject = urlContentMap;
|
|
1086
|
+
// Extract the _map data from the urlContentMap object
|
|
1087
|
+
const urlContentMapData = urlContentMapObject?.['_map'];
|
|
1084
1088
|
return {
|
|
1085
1089
|
layout,
|
|
1086
1090
|
template,
|
|
1087
1091
|
viewAs,
|
|
1088
|
-
urlContentMap,
|
|
1089
1092
|
site,
|
|
1090
1093
|
page: {
|
|
1091
1094
|
...data,
|
|
1092
1095
|
...pageAsset
|
|
1093
1096
|
},
|
|
1094
|
-
containers: parseContainers(containers)
|
|
1097
|
+
containers: parseContainers(containers),
|
|
1098
|
+
urlContentMap: urlContentMapData
|
|
1095
1099
|
};
|
|
1096
1100
|
};
|
|
1097
1101
|
/**
|