@dotcms/client 0.0.1-beta.20 → 0.0.1-beta.22
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 +49 -9
- package/next.esm.js +49 -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
|
@@ -99,6 +99,7 @@ const buildPageQuery = ({ page, fragments, additionalQueries }) => {
|
|
|
99
99
|
friendlyName
|
|
100
100
|
workingInode
|
|
101
101
|
url
|
|
102
|
+
pageURI
|
|
102
103
|
hasLiveVersion
|
|
103
104
|
deleted
|
|
104
105
|
pageUrl
|
|
@@ -125,6 +126,9 @@ const buildPageQuery = ({ page, fragments, additionalQueries }) => {
|
|
|
125
126
|
canEdit
|
|
126
127
|
canLock
|
|
127
128
|
canRead
|
|
129
|
+
urlContentMap {
|
|
130
|
+
_map
|
|
131
|
+
}
|
|
128
132
|
conLanguage {
|
|
129
133
|
id
|
|
130
134
|
language
|
|
@@ -173,7 +177,24 @@ const buildPageQuery = ({ page, fragments, additionalQueries }) => {
|
|
|
173
177
|
viewAs {
|
|
174
178
|
visitor {
|
|
175
179
|
persona {
|
|
180
|
+
modDate
|
|
181
|
+
inode
|
|
176
182
|
name
|
|
183
|
+
identifier
|
|
184
|
+
keyTag
|
|
185
|
+
photo {
|
|
186
|
+
versionPath
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
persona {
|
|
191
|
+
modDate
|
|
192
|
+
inode
|
|
193
|
+
name
|
|
194
|
+
identifier
|
|
195
|
+
keyTag
|
|
196
|
+
photo {
|
|
197
|
+
versionPath
|
|
177
198
|
}
|
|
178
199
|
}
|
|
179
200
|
language {
|
|
@@ -190,8 +211,8 @@ const buildPageQuery = ({ page, fragments, additionalQueries }) => {
|
|
|
190
211
|
|
|
191
212
|
${fragments ? fragments.join('\n\n') : ''}
|
|
192
213
|
|
|
193
|
-
query PageContent($url: String!, $languageId: String, $mode: String) {
|
|
194
|
-
page: page(url: $url, languageId: $languageId, pageMode: $mode) {
|
|
214
|
+
query PageContent($url: String!, $languageId: String, $mode: String, $personaId: String, $fireRules: Boolean, $publishDate: String, $siteId: String) {
|
|
215
|
+
page: page(url: $url, languageId: $languageId, pageMode: $mode, persona: $personaId, fireRules: $fireRules, publishDate: $publishDate, site: $siteId) {
|
|
195
216
|
...DotCMSPage
|
|
196
217
|
${page ? '...ClientPage' : ''}
|
|
197
218
|
}
|
|
@@ -330,7 +351,14 @@ async function _PageClient_getPageFromAPI(path, params) {
|
|
|
330
351
|
if (!path) {
|
|
331
352
|
throw new Error("The 'path' parameter is required for the Page API");
|
|
332
353
|
}
|
|
333
|
-
|
|
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
|
|
334
362
|
const queryParams = new URLSearchParams(normalizedParams).toString();
|
|
335
363
|
// If the path starts with a slash, remove it to avoid double slashes in the final URL
|
|
336
364
|
// Because the page path is part of api url path
|
|
@@ -344,7 +372,10 @@ async function _PageClient_getPageFromAPI(path, params) {
|
|
|
344
372
|
};
|
|
345
373
|
throw error;
|
|
346
374
|
}
|
|
347
|
-
return response.json().then((data) =>
|
|
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
|
+
}));
|
|
348
379
|
}, _PageClient_getPageFromGraphQL =
|
|
349
380
|
/**
|
|
350
381
|
* Retrieves a personalized page with associated content and navigation.
|
|
@@ -398,7 +429,7 @@ async function _PageClient_getPageFromAPI(path, params) {
|
|
|
398
429
|
* ```
|
|
399
430
|
*/
|
|
400
431
|
async function _PageClient_getPageFromGraphQL(url, options) {
|
|
401
|
-
const { languageId = '1', mode = 'LIVE', graphql = {} } = options || {};
|
|
432
|
+
const { languageId = '1', mode = 'LIVE', siteId = this.siteId, fireRules = false, personaId, publishDate, graphql = {} } = options || {};
|
|
402
433
|
const { page, content = {}, variables, fragments } = graphql;
|
|
403
434
|
const contentQuery = buildQuery(content);
|
|
404
435
|
const completeQuery = buildPageQuery({
|
|
@@ -410,6 +441,10 @@ async function _PageClient_getPageFromGraphQL(url, options) {
|
|
|
410
441
|
url,
|
|
411
442
|
mode,
|
|
412
443
|
languageId,
|
|
444
|
+
personaId,
|
|
445
|
+
fireRules,
|
|
446
|
+
publishDate,
|
|
447
|
+
siteId,
|
|
413
448
|
...variables
|
|
414
449
|
};
|
|
415
450
|
const requestHeaders = this.requestOptions.headers;
|
|
@@ -433,21 +468,26 @@ async function _PageClient_getPageFromGraphQL(url, options) {
|
|
|
433
468
|
return {
|
|
434
469
|
page: pageResponse,
|
|
435
470
|
content: contentResponse,
|
|
436
|
-
|
|
471
|
+
graphql: {
|
|
472
|
+
query: completeQuery,
|
|
473
|
+
variables: requestVariables
|
|
474
|
+
}
|
|
437
475
|
};
|
|
438
476
|
}
|
|
439
477
|
catch (error) {
|
|
440
478
|
const errorMessage = {
|
|
441
479
|
error,
|
|
442
480
|
message: 'Failed to retrieve page data',
|
|
443
|
-
|
|
444
|
-
|
|
481
|
+
graphql: {
|
|
482
|
+
query: completeQuery,
|
|
483
|
+
variables: requestVariables
|
|
484
|
+
}
|
|
445
485
|
};
|
|
446
486
|
throw errorMessage;
|
|
447
487
|
}
|
|
448
488
|
}, _PageClient_mapToBackendParams = function _PageClient_mapToBackendParams(params) {
|
|
449
489
|
const backendParams = {
|
|
450
|
-
hostId: params.siteId
|
|
490
|
+
hostId: params.siteId,
|
|
451
491
|
mode: params.mode,
|
|
452
492
|
language_id: params.languageId ? String(params.languageId) : undefined,
|
|
453
493
|
'com.dotmarketing.persona.id': params.personaId,
|
package/next.esm.js
CHANGED
|
@@ -97,6 +97,7 @@ const buildPageQuery = ({ page, fragments, additionalQueries }) => {
|
|
|
97
97
|
friendlyName
|
|
98
98
|
workingInode
|
|
99
99
|
url
|
|
100
|
+
pageURI
|
|
100
101
|
hasLiveVersion
|
|
101
102
|
deleted
|
|
102
103
|
pageUrl
|
|
@@ -123,6 +124,9 @@ const buildPageQuery = ({ page, fragments, additionalQueries }) => {
|
|
|
123
124
|
canEdit
|
|
124
125
|
canLock
|
|
125
126
|
canRead
|
|
127
|
+
urlContentMap {
|
|
128
|
+
_map
|
|
129
|
+
}
|
|
126
130
|
conLanguage {
|
|
127
131
|
id
|
|
128
132
|
language
|
|
@@ -171,7 +175,24 @@ const buildPageQuery = ({ page, fragments, additionalQueries }) => {
|
|
|
171
175
|
viewAs {
|
|
172
176
|
visitor {
|
|
173
177
|
persona {
|
|
178
|
+
modDate
|
|
179
|
+
inode
|
|
174
180
|
name
|
|
181
|
+
identifier
|
|
182
|
+
keyTag
|
|
183
|
+
photo {
|
|
184
|
+
versionPath
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
persona {
|
|
189
|
+
modDate
|
|
190
|
+
inode
|
|
191
|
+
name
|
|
192
|
+
identifier
|
|
193
|
+
keyTag
|
|
194
|
+
photo {
|
|
195
|
+
versionPath
|
|
175
196
|
}
|
|
176
197
|
}
|
|
177
198
|
language {
|
|
@@ -188,8 +209,8 @@ const buildPageQuery = ({ page, fragments, additionalQueries }) => {
|
|
|
188
209
|
|
|
189
210
|
${fragments ? fragments.join('\n\n') : ''}
|
|
190
211
|
|
|
191
|
-
query PageContent($url: String!, $languageId: String, $mode: String) {
|
|
192
|
-
page: page(url: $url, languageId: $languageId, pageMode: $mode) {
|
|
212
|
+
query PageContent($url: String!, $languageId: String, $mode: String, $personaId: String, $fireRules: Boolean, $publishDate: String, $siteId: String) {
|
|
213
|
+
page: page(url: $url, languageId: $languageId, pageMode: $mode, persona: $personaId, fireRules: $fireRules, publishDate: $publishDate, site: $siteId) {
|
|
193
214
|
...DotCMSPage
|
|
194
215
|
${page ? '...ClientPage' : ''}
|
|
195
216
|
}
|
|
@@ -328,7 +349,14 @@ async function _PageClient_getPageFromAPI(path, params) {
|
|
|
328
349
|
if (!path) {
|
|
329
350
|
throw new Error("The 'path' parameter is required for the Page API");
|
|
330
351
|
}
|
|
331
|
-
|
|
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
|
|
332
360
|
const queryParams = new URLSearchParams(normalizedParams).toString();
|
|
333
361
|
// If the path starts with a slash, remove it to avoid double slashes in the final URL
|
|
334
362
|
// Because the page path is part of api url path
|
|
@@ -342,7 +370,10 @@ async function _PageClient_getPageFromAPI(path, params) {
|
|
|
342
370
|
};
|
|
343
371
|
throw error;
|
|
344
372
|
}
|
|
345
|
-
return response.json().then((data) =>
|
|
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
|
+
}));
|
|
346
377
|
}, _PageClient_getPageFromGraphQL =
|
|
347
378
|
/**
|
|
348
379
|
* Retrieves a personalized page with associated content and navigation.
|
|
@@ -396,7 +427,7 @@ async function _PageClient_getPageFromAPI(path, params) {
|
|
|
396
427
|
* ```
|
|
397
428
|
*/
|
|
398
429
|
async function _PageClient_getPageFromGraphQL(url, options) {
|
|
399
|
-
const { languageId = '1', mode = 'LIVE', graphql = {} } = options || {};
|
|
430
|
+
const { languageId = '1', mode = 'LIVE', siteId = this.siteId, fireRules = false, personaId, publishDate, graphql = {} } = options || {};
|
|
400
431
|
const { page, content = {}, variables, fragments } = graphql;
|
|
401
432
|
const contentQuery = buildQuery(content);
|
|
402
433
|
const completeQuery = buildPageQuery({
|
|
@@ -408,6 +439,10 @@ async function _PageClient_getPageFromGraphQL(url, options) {
|
|
|
408
439
|
url,
|
|
409
440
|
mode,
|
|
410
441
|
languageId,
|
|
442
|
+
personaId,
|
|
443
|
+
fireRules,
|
|
444
|
+
publishDate,
|
|
445
|
+
siteId,
|
|
411
446
|
...variables
|
|
412
447
|
};
|
|
413
448
|
const requestHeaders = this.requestOptions.headers;
|
|
@@ -431,21 +466,26 @@ async function _PageClient_getPageFromGraphQL(url, options) {
|
|
|
431
466
|
return {
|
|
432
467
|
page: pageResponse,
|
|
433
468
|
content: contentResponse,
|
|
434
|
-
|
|
469
|
+
graphql: {
|
|
470
|
+
query: completeQuery,
|
|
471
|
+
variables: requestVariables
|
|
472
|
+
}
|
|
435
473
|
};
|
|
436
474
|
}
|
|
437
475
|
catch (error) {
|
|
438
476
|
const errorMessage = {
|
|
439
477
|
error,
|
|
440
478
|
message: 'Failed to retrieve page data',
|
|
441
|
-
|
|
442
|
-
|
|
479
|
+
graphql: {
|
|
480
|
+
query: completeQuery,
|
|
481
|
+
variables: requestVariables
|
|
482
|
+
}
|
|
443
483
|
};
|
|
444
484
|
throw errorMessage;
|
|
445
485
|
}
|
|
446
486
|
}, _PageClient_mapToBackendParams = function _PageClient_mapToBackendParams(params) {
|
|
447
487
|
const backendParams = {
|
|
448
|
-
hostId: params.siteId
|
|
488
|
+
hostId: params.siteId,
|
|
449
489
|
mode: params.mode,
|
|
450
490
|
language_id: params.languageId ? String(params.languageId) : undefined,
|
|
451
491
|
'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
|
/**
|