@dotcms/client 0.0.1-beta.4 → 0.0.1-beta.40
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 +516 -153
- package/next.cjs.js +148 -172
- package/next.esm.js +149 -173
- package/package.json +7 -10
- package/src/lib/client/client.d.ts +1 -29
- package/src/lib/client/content/content-api.d.ts +3 -6
- package/src/lib/client/content/shared/types.d.ts +1 -42
- package/src/lib/client/navigation/navigation-api.d.ts +3 -20
- package/src/lib/client/page/page-api.d.ts +14 -84
- package/src/lib/deprecated/editor/sdk-editor.d.ts +1 -1
- package/src/lib/utils/graphql/transforms.d.ts +2 -13
- package/transforms.cjs.js +18 -13
- package/transforms.esm.js +18 -13
- package/src/lib/client/models/types.d.ts +0 -516
- package/src/types.d.ts +0 -2
- package/types.cjs.d.ts +0 -1
- package/types.cjs.default.js +0 -1
- package/types.cjs.js +0 -2
- package/types.cjs.mjs +0 -2
- package/types.esm.d.ts +0 -1
- package/types.esm.js +0 -1
|
@@ -1,70 +1,9 @@
|
|
|
1
|
-
import { DotCMSClientConfig, RequestOptions } from '
|
|
2
|
-
import { DotCMSGraphQLPageResponse, DotCMSPageAsset } from '../models/types';
|
|
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
|
-
export interface GraphQLPageOptions extends PageRequestParams {
|
|
55
|
-
graphql: {
|
|
56
|
-
page?: string;
|
|
57
|
-
content?: Record<string, string>;
|
|
58
|
-
variables?: Record<string, string>;
|
|
59
|
-
fragments?: string[];
|
|
60
|
-
};
|
|
61
|
-
}
|
|
1
|
+
import { DotCMSClientConfig, DotCMSComposedPageResponse, DotCMSExtendedPageResponse, DotCMSPageResponse, DotCMSPageRequestParams, RequestOptions } from '@dotcms/types';
|
|
62
2
|
/**
|
|
63
3
|
* Client for interacting with the DotCMS Page API.
|
|
64
4
|
* Provides methods to retrieve and manipulate pages.
|
|
65
5
|
*/
|
|
66
6
|
export declare class PageClient {
|
|
67
|
-
#private;
|
|
68
7
|
/**
|
|
69
8
|
* Request options including authorization headers.
|
|
70
9
|
* @private
|
|
@@ -103,29 +42,22 @@ export declare class PageClient {
|
|
|
103
42
|
*/
|
|
104
43
|
constructor(config: DotCMSClientConfig, requestOptions: RequestOptions);
|
|
105
44
|
/**
|
|
106
|
-
* Retrieves a page from DotCMS using
|
|
107
|
-
* This method is polymorphic and can handle both REST API and GraphQL requests based on the options provided.
|
|
45
|
+
* Retrieves a page from DotCMS using GraphQL.
|
|
108
46
|
*
|
|
109
47
|
* @param {string} url - The URL of the page to retrieve
|
|
110
|
-
* @param {
|
|
111
|
-
* @
|
|
112
|
-
*
|
|
113
|
-
* @example Using REST API with options
|
|
114
|
-
* ```typescript
|
|
115
|
-
* const page = await pageClient.get('/about-us', {
|
|
116
|
-
* mode: 'PREVIEW_MODE',
|
|
117
|
-
* languageId: 1,
|
|
118
|
-
* siteId: 'demo.dotcms.com'
|
|
119
|
-
* });
|
|
120
|
-
* ```
|
|
48
|
+
* @param {DotCMSPageRequestParams} [options] - Options for the request
|
|
49
|
+
* @template T - The type of the page and content, defaults to DotCMSBasicPage and Record<string, unknown> | unknown
|
|
50
|
+
* @returns {Promise<DotCMSComposedPageResponse<T>>} A Promise that resolves to the page data
|
|
121
51
|
*
|
|
122
52
|
* @example Using GraphQL
|
|
123
53
|
* ```typescript
|
|
124
|
-
* const page = await pageClient.get
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
54
|
+
* const page = await pageClient.get<{ page: MyPageWithBanners; content: { blogPosts: { blogTitle: string } } }>(
|
|
55
|
+
* '/index',
|
|
56
|
+
* {
|
|
57
|
+
* languageId: '1',
|
|
58
|
+
* mode: 'LIVE',
|
|
59
|
+
* graphql: {
|
|
60
|
+
* page: `
|
|
129
61
|
* containers {
|
|
130
62
|
* containerContentlets {
|
|
131
63
|
* contentlets {
|
|
@@ -157,9 +89,7 @@ export declare class PageClient {
|
|
|
157
89
|
* ]
|
|
158
90
|
* }
|
|
159
91
|
* });
|
|
160
|
-
|
|
92
|
+
* ```
|
|
161
93
|
*/
|
|
162
|
-
get(url: string, options?:
|
|
163
|
-
get(url: string, options?: GraphQLPageOptions): Promise<DotCMSGraphQLPageResponse>;
|
|
94
|
+
get<T extends DotCMSExtendedPageResponse = DotCMSPageResponse>(url: string, options?: DotCMSPageRequestParams): Promise<DotCMSComposedPageResponse<T>>;
|
|
164
95
|
}
|
|
165
|
-
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
|
*
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Represents the response from a GraphQL query for a page.
|
|
3
|
-
*
|
|
4
|
-
* @interface GraphQLPageResponse
|
|
5
|
-
* @property {Record<string, unknown>} page - The main page data.
|
|
6
|
-
* @property {unknown} [key: string] - Additional properties that may be included in the response.
|
|
7
|
-
*/
|
|
8
|
-
interface GraphQLPageResponse {
|
|
9
|
-
page: Record<string, unknown>;
|
|
10
|
-
[key: string]: unknown;
|
|
11
|
-
}
|
|
1
|
+
import { DotCMSGraphQLPageResponse, DotCMSPageAsset } from '@dotcms/types';
|
|
12
2
|
/**
|
|
13
3
|
* Transforms a GraphQL Page response to a Page Entity.
|
|
14
4
|
*
|
|
@@ -20,5 +10,4 @@ interface GraphQLPageResponse {
|
|
|
20
10
|
* const pageEntity = graphqlToPageEntity(graphQLPageResponse);
|
|
21
11
|
* ```
|
|
22
12
|
*/
|
|
23
|
-
export declare const graphqlToPageEntity: (graphQLPageResponse:
|
|
24
|
-
export {};
|
|
13
|
+
export declare const graphqlToPageEntity: (graphQLPageResponse: DotCMSGraphQLPageResponse) => DotCMSPageAsset | null;
|
package/transforms.cjs.js
CHANGED
|
@@ -14,7 +14,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
14
14
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
***************************************************************************** */
|
|
17
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
17
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
@@ -924,7 +924,6 @@ var _Content_requestOptions, _Content_serverUrl;
|
|
|
924
924
|
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
925
925
|
* .query(q => q.field('author').equals('John Doe'))
|
|
926
926
|
* .depth(1)
|
|
927
|
-
* .fetch();
|
|
928
927
|
*
|
|
929
928
|
* console.log(response.contentlets);
|
|
930
929
|
* ```
|
|
@@ -938,7 +937,6 @@ var _Content_requestOptions, _Content_serverUrl;
|
|
|
938
937
|
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
939
938
|
* .query(q => q.field('author').equals('John Doe'))
|
|
940
939
|
* .depth(1)
|
|
941
|
-
* .fetch()
|
|
942
940
|
* .then(response => console.log(response.contentlets))
|
|
943
941
|
* .catch(error => console.error(error));
|
|
944
942
|
* ```
|
|
@@ -954,7 +952,6 @@ var _Content_requestOptions, _Content_serverUrl;
|
|
|
954
952
|
* const posts = await client.content
|
|
955
953
|
* .getCollection<BlogPost>('Blog')
|
|
956
954
|
* .limit(10)
|
|
957
|
-
* .fetch();
|
|
958
955
|
*
|
|
959
956
|
* posts.contentlets.forEach(post => {
|
|
960
957
|
* console.log(post.title, post.author, post.summary);
|
|
@@ -964,7 +961,7 @@ var _Content_requestOptions, _Content_serverUrl;
|
|
|
964
961
|
class Content {
|
|
965
962
|
/**
|
|
966
963
|
* Creates an instance of Content.
|
|
967
|
-
* @param {
|
|
964
|
+
* @param {RequestOptions} requestOptions - The options for the client request.
|
|
968
965
|
* @param {string} serverUrl - The server URL.
|
|
969
966
|
*/
|
|
970
967
|
constructor(requestOptions, serverUrl) {
|
|
@@ -1064,6 +1061,7 @@ const ErrorMessages = {
|
|
|
1064
1061
|
503: 'Service Unavailable. Try again later.'
|
|
1065
1062
|
};
|
|
1066
1063
|
|
|
1064
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1067
1065
|
/**
|
|
1068
1066
|
* Transforms a GraphQL Page response to a Page Entity.
|
|
1069
1067
|
*
|
|
@@ -1081,26 +1079,33 @@ const graphqlToPageEntity = (graphQLPageResponse) => {
|
|
|
1081
1079
|
if (!page) {
|
|
1082
1080
|
return null;
|
|
1083
1081
|
}
|
|
1084
|
-
const { layout, template, containers, urlContentMap, viewAs,
|
|
1082
|
+
const { layout, template, containers, urlContentMap, viewAs, host, vanityUrl, runningExperimentId, _map, ...pageAsset } = page;
|
|
1085
1083
|
const data = (_map || {});
|
|
1084
|
+
const typedPageAsset = pageAsset;
|
|
1085
|
+
// To prevent type errors, we cast the urlContentMap to an object
|
|
1086
|
+
const urlContentMapObject = urlContentMap;
|
|
1087
|
+
// Extract the _map data from the urlContentMap object
|
|
1088
|
+
const urlContentMapData = urlContentMapObject?.['_map'];
|
|
1086
1089
|
return {
|
|
1087
1090
|
layout,
|
|
1088
1091
|
template,
|
|
1089
1092
|
viewAs,
|
|
1090
|
-
|
|
1091
|
-
|
|
1093
|
+
vanityUrl,
|
|
1094
|
+
runningExperimentId,
|
|
1095
|
+
site: host,
|
|
1096
|
+
urlContentMap: urlContentMapData,
|
|
1097
|
+
containers: parseContainers(containers),
|
|
1092
1098
|
page: {
|
|
1093
1099
|
...data,
|
|
1094
|
-
...
|
|
1095
|
-
}
|
|
1096
|
-
containers: parseContainers(containers)
|
|
1100
|
+
...typedPageAsset
|
|
1101
|
+
}
|
|
1097
1102
|
};
|
|
1098
1103
|
};
|
|
1099
1104
|
/**
|
|
1100
1105
|
* Parses the containers from the GraphQL response.
|
|
1101
1106
|
*
|
|
1102
|
-
* @param {
|
|
1103
|
-
* @returns {
|
|
1107
|
+
* @param {DotCMSGraphQLPageContainer[]} [containers=[]] - The containers array from the GraphQL response.
|
|
1108
|
+
* @returns {DotCMSPageAssetContainers} The parsed containers.
|
|
1104
1109
|
*/
|
|
1105
1110
|
const parseContainers = (containers = []) => {
|
|
1106
1111
|
return containers.reduce((acc, container) => {
|
package/transforms.esm.js
CHANGED
|
@@ -12,7 +12,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
12
12
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
13
|
PERFORMANCE OF THIS SOFTWARE.
|
|
14
14
|
***************************************************************************** */
|
|
15
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
15
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
@@ -922,7 +922,6 @@ var _Content_requestOptions, _Content_serverUrl;
|
|
|
922
922
|
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
923
923
|
* .query(q => q.field('author').equals('John Doe'))
|
|
924
924
|
* .depth(1)
|
|
925
|
-
* .fetch();
|
|
926
925
|
*
|
|
927
926
|
* console.log(response.contentlets);
|
|
928
927
|
* ```
|
|
@@ -936,7 +935,6 @@ var _Content_requestOptions, _Content_serverUrl;
|
|
|
936
935
|
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
937
936
|
* .query(q => q.field('author').equals('John Doe'))
|
|
938
937
|
* .depth(1)
|
|
939
|
-
* .fetch()
|
|
940
938
|
* .then(response => console.log(response.contentlets))
|
|
941
939
|
* .catch(error => console.error(error));
|
|
942
940
|
* ```
|
|
@@ -952,7 +950,6 @@ var _Content_requestOptions, _Content_serverUrl;
|
|
|
952
950
|
* const posts = await client.content
|
|
953
951
|
* .getCollection<BlogPost>('Blog')
|
|
954
952
|
* .limit(10)
|
|
955
|
-
* .fetch();
|
|
956
953
|
*
|
|
957
954
|
* posts.contentlets.forEach(post => {
|
|
958
955
|
* console.log(post.title, post.author, post.summary);
|
|
@@ -962,7 +959,7 @@ var _Content_requestOptions, _Content_serverUrl;
|
|
|
962
959
|
class Content {
|
|
963
960
|
/**
|
|
964
961
|
* Creates an instance of Content.
|
|
965
|
-
* @param {
|
|
962
|
+
* @param {RequestOptions} requestOptions - The options for the client request.
|
|
966
963
|
* @param {string} serverUrl - The server URL.
|
|
967
964
|
*/
|
|
968
965
|
constructor(requestOptions, serverUrl) {
|
|
@@ -1062,6 +1059,7 @@ const ErrorMessages = {
|
|
|
1062
1059
|
503: 'Service Unavailable. Try again later.'
|
|
1063
1060
|
};
|
|
1064
1061
|
|
|
1062
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1065
1063
|
/**
|
|
1066
1064
|
* Transforms a GraphQL Page response to a Page Entity.
|
|
1067
1065
|
*
|
|
@@ -1079,26 +1077,33 @@ const graphqlToPageEntity = (graphQLPageResponse) => {
|
|
|
1079
1077
|
if (!page) {
|
|
1080
1078
|
return null;
|
|
1081
1079
|
}
|
|
1082
|
-
const { layout, template, containers, urlContentMap, viewAs,
|
|
1080
|
+
const { layout, template, containers, urlContentMap, viewAs, host, vanityUrl, runningExperimentId, _map, ...pageAsset } = page;
|
|
1083
1081
|
const data = (_map || {});
|
|
1082
|
+
const typedPageAsset = pageAsset;
|
|
1083
|
+
// To prevent type errors, we cast the urlContentMap to an object
|
|
1084
|
+
const urlContentMapObject = urlContentMap;
|
|
1085
|
+
// Extract the _map data from the urlContentMap object
|
|
1086
|
+
const urlContentMapData = urlContentMapObject?.['_map'];
|
|
1084
1087
|
return {
|
|
1085
1088
|
layout,
|
|
1086
1089
|
template,
|
|
1087
1090
|
viewAs,
|
|
1088
|
-
|
|
1089
|
-
|
|
1091
|
+
vanityUrl,
|
|
1092
|
+
runningExperimentId,
|
|
1093
|
+
site: host,
|
|
1094
|
+
urlContentMap: urlContentMapData,
|
|
1095
|
+
containers: parseContainers(containers),
|
|
1090
1096
|
page: {
|
|
1091
1097
|
...data,
|
|
1092
|
-
...
|
|
1093
|
-
}
|
|
1094
|
-
containers: parseContainers(containers)
|
|
1098
|
+
...typedPageAsset
|
|
1099
|
+
}
|
|
1095
1100
|
};
|
|
1096
1101
|
};
|
|
1097
1102
|
/**
|
|
1098
1103
|
* Parses the containers from the GraphQL response.
|
|
1099
1104
|
*
|
|
1100
|
-
* @param {
|
|
1101
|
-
* @returns {
|
|
1105
|
+
* @param {DotCMSGraphQLPageContainer[]} [containers=[]] - The containers array from the GraphQL response.
|
|
1106
|
+
* @returns {DotCMSPageAssetContainers} The parsed containers.
|
|
1102
1107
|
*/
|
|
1103
1108
|
const parseContainers = (containers = []) => {
|
|
1104
1109
|
return containers.reduce((acc, container) => {
|