@dotcms/client 0.0.1-alpha.37 → 0.0.1-alpha.39
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/.eslintrc.json +18 -0
- package/README.md +4 -4
- package/jest.config.ts +15 -0
- package/package.json +3 -15
- package/project.json +72 -0
- package/src/index.ts +30 -0
- package/src/lib/client/content/builders/collection/collection.spec.ts +515 -0
- package/src/lib/client/content/builders/collection/collection.ts +416 -0
- package/src/lib/client/content/content-api.ts +139 -0
- package/src/lib/client/content/shared/const.ts +15 -0
- package/src/lib/client/content/shared/types.ts +155 -0
- package/src/lib/client/content/shared/utils.ts +28 -0
- package/src/lib/client/models/index.ts +19 -0
- package/src/lib/client/models/types.ts +14 -0
- package/src/lib/client/sdk-js-client.spec.ts +483 -0
- package/src/lib/client/sdk-js-client.ts +442 -0
- package/src/lib/editor/listeners/listeners.spec.ts +119 -0
- package/src/lib/editor/listeners/listeners.ts +223 -0
- package/src/lib/editor/models/{client.model.d.ts → client.model.ts} +19 -16
- package/src/lib/editor/models/{editor.model.d.ts → editor.model.ts} +9 -5
- package/src/lib/editor/models/{listeners.model.d.ts → listeners.model.ts} +9 -6
- package/src/lib/editor/sdk-editor-vtl.ts +31 -0
- package/src/lib/editor/sdk-editor.spec.ts +116 -0
- package/src/lib/editor/sdk-editor.ts +105 -0
- package/src/lib/editor/utils/editor.utils.spec.ts +206 -0
- package/src/lib/editor/utils/editor.utils.ts +258 -0
- package/src/lib/query-builder/lucene-syntax/{Equals.d.ts → Equals.ts} +83 -18
- package/src/lib/query-builder/lucene-syntax/Field.ts +40 -0
- package/src/lib/query-builder/lucene-syntax/{NotOperand.d.ts → NotOperand.ts} +18 -6
- package/src/lib/query-builder/lucene-syntax/{Operand.d.ts → Operand.ts} +21 -7
- package/src/lib/query-builder/sdk-query-builder.spec.ts +159 -0
- package/src/lib/query-builder/sdk-query-builder.ts +87 -0
- package/src/lib/query-builder/utils/index.ts +179 -0
- package/src/lib/utils/graphql/transforms.spec.ts +150 -0
- package/src/lib/utils/graphql/transforms.ts +99 -0
- package/src/lib/utils/page/common-utils.spec.ts +37 -0
- package/src/lib/utils/page/common-utils.ts +64 -0
- package/tsconfig.json +22 -0
- package/tsconfig.lib.json +13 -0
- package/tsconfig.spec.json +9 -0
- package/index.cjs.d.ts +0 -1
- package/index.cjs.default.js +0 -1
- package/index.cjs.js +0 -1490
- package/index.cjs.mjs +0 -2
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -1481
- package/src/index.d.ts +0 -6
- package/src/lib/client/content/builders/collection/collection.d.ts +0 -148
- package/src/lib/client/content/content-api.d.ts +0 -78
- package/src/lib/client/content/shared/const.d.ts +0 -3
- package/src/lib/client/content/shared/types.d.ts +0 -62
- package/src/lib/client/content/shared/utils.d.ts +0 -12
- package/src/lib/client/models/index.d.ts +0 -1
- package/src/lib/client/models/types.d.ts +0 -5
- package/src/lib/client/sdk-js-client.d.ts +0 -193
- package/src/lib/editor/listeners/listeners.d.ts +0 -46
- package/src/lib/editor/sdk-editor-vtl.d.ts +0 -6
- package/src/lib/editor/sdk-editor.d.ts +0 -29
- package/src/lib/editor/utils/editor.utils.d.ts +0 -83
- package/src/lib/query-builder/lucene-syntax/Field.d.ts +0 -23
- package/src/lib/query-builder/sdk-query-builder.d.ts +0 -42
- package/src/lib/query-builder/utils/index.d.ts +0 -91
- package/src/lib/utils/graphql/transforms.d.ts +0 -11
- package/src/lib/utils/page/common-utils.d.ts +0 -11
- /package/src/lib/query-builder/lucene-syntax/{index.d.ts → index.ts} +0 -0
- /package/src/lib/utils/{index.d.ts → index.ts} +0 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/**
|
|
3
|
+
* Represents the response from a GraphQL query for a page.
|
|
4
|
+
*
|
|
5
|
+
* @interface GraphQLPageResponse
|
|
6
|
+
* @property {Record<string, unknown>} page - The main page data.
|
|
7
|
+
* @property {unknown} [key: string] - Additional properties that may be included in the response.
|
|
8
|
+
*/
|
|
9
|
+
interface GraphQLPageResponse {
|
|
10
|
+
page: Record<string, unknown>;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Transforms a GraphQL Page response to a Page Entity.
|
|
16
|
+
*
|
|
17
|
+
* @param {GraphQLPageResponse} graphQLPageResponse - The GraphQL Page response object.
|
|
18
|
+
* @returns {object|null} The transformed Page Entity or null if the page is not present.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const pageEntity = graphqlToPageEntity(graphQLPageResponse);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export const graphqlToPageEntity = (graphQLPageResponse: GraphQLPageResponse) => {
|
|
26
|
+
const { page } = graphQLPageResponse;
|
|
27
|
+
|
|
28
|
+
// If there is no page, return null
|
|
29
|
+
if (!page) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const { layout, template, containers, urlContentMap, viewAs, site, _map, ...pageAsset } = page;
|
|
34
|
+
const data = (_map || {}) as Record<string, unknown>;
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
layout,
|
|
38
|
+
template,
|
|
39
|
+
viewAs,
|
|
40
|
+
urlContentMap,
|
|
41
|
+
site,
|
|
42
|
+
page: {
|
|
43
|
+
...data,
|
|
44
|
+
...pageAsset
|
|
45
|
+
},
|
|
46
|
+
containers: parseContainers(containers as [])
|
|
47
|
+
} as any;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Parses the containers from the GraphQL response.
|
|
52
|
+
*
|
|
53
|
+
* @param {Array<Record<string, unknown>>} [containers=[]] - The containers array from the GraphQL response.
|
|
54
|
+
* @returns {Record<string, unknown>} The parsed containers.
|
|
55
|
+
*/
|
|
56
|
+
const parseContainers = (containers: Record<string, unknown>[] = []) => {
|
|
57
|
+
return containers.reduce((acc: Record<string, unknown>, container: Record<string, unknown>) => {
|
|
58
|
+
const { path, identifier, containerStructures, containerContentlets, ...rest } = container;
|
|
59
|
+
|
|
60
|
+
const key = (path || identifier) as string;
|
|
61
|
+
|
|
62
|
+
acc[key] = {
|
|
63
|
+
containerStructures,
|
|
64
|
+
container: {
|
|
65
|
+
path,
|
|
66
|
+
identifier,
|
|
67
|
+
...rest
|
|
68
|
+
},
|
|
69
|
+
contentlets: parseContentletsToUuidMap(containerContentlets as [])
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return acc;
|
|
73
|
+
}, {});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Parses the contentlets from the GraphQL response.
|
|
78
|
+
*
|
|
79
|
+
* @param {Array<Record<string, unknown>>} containerContentlets - The contentlets array from the GraphQL response.
|
|
80
|
+
* @returns {Record<string, Array<Record<string, unknown>>>} The parsed contentlets mapped by UUID.
|
|
81
|
+
*/
|
|
82
|
+
const parseContentletsToUuidMap = (containerContentlets: Record<string, unknown>[] = []) => {
|
|
83
|
+
return containerContentlets.reduce((acc, containerContentlet) => {
|
|
84
|
+
const { uuid, contentlets } = containerContentlet as {
|
|
85
|
+
uuid: string;
|
|
86
|
+
contentlets: Record<string, unknown>[];
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// TODO: This is a temporary solution, we need to find a better way to handle this.
|
|
90
|
+
acc[uuid] = contentlets.map(({ _map = {}, ...rest }) => {
|
|
91
|
+
return {
|
|
92
|
+
...(_map as Record<string, unknown>),
|
|
93
|
+
...rest
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
return acc;
|
|
98
|
+
}, {});
|
|
99
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getPageRequestParams } from './common-utils';
|
|
2
|
+
|
|
3
|
+
describe('Common Utils', () => {
|
|
4
|
+
it('should return the correct Request Params', () => {
|
|
5
|
+
const pageRequestParams = getPageRequestParams({
|
|
6
|
+
path: 'test',
|
|
7
|
+
params: {
|
|
8
|
+
personaId: '123',
|
|
9
|
+
language_id: '1',
|
|
10
|
+
mode: 'LIVE',
|
|
11
|
+
variantName: 'default'
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
expect(pageRequestParams).toEqual({
|
|
16
|
+
path: 'test',
|
|
17
|
+
mode: 'LIVE',
|
|
18
|
+
language_id: '1',
|
|
19
|
+
variantName: 'default',
|
|
20
|
+
personaId: '123'
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should return the correct Request Params with empty params', () => {
|
|
25
|
+
const pageRequestParams = getPageRequestParams({
|
|
26
|
+
path: 'test',
|
|
27
|
+
params: {
|
|
28
|
+
personaId: '',
|
|
29
|
+
language_id: '',
|
|
30
|
+
mode: '',
|
|
31
|
+
variantName: ''
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
expect(pageRequestParams).toEqual({ path: 'test' });
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { PageApiOptions } from '../../client/sdk-js-client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interface representing the properties for page request parameters.
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @interface PageRequestParamsProps
|
|
8
|
+
*/
|
|
9
|
+
export interface PageRequestParamsProps {
|
|
10
|
+
/**
|
|
11
|
+
* The API endpoint path.
|
|
12
|
+
* @type {string}
|
|
13
|
+
*/
|
|
14
|
+
path: string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The query parameters for the API request.
|
|
18
|
+
* Can be an object with key-value pairs or a URLSearchParams instance.
|
|
19
|
+
* @type {{ [key: string]: unknown } | URLSearchParams}
|
|
20
|
+
*/
|
|
21
|
+
params: { [key: string]: unknown } | URLSearchParams;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Generates the page request parameters to be used in the API call.
|
|
26
|
+
*
|
|
27
|
+
* @param {PageRequestParamsProps} PageRequestParamsProps - The properties for the page request.
|
|
28
|
+
* @returns {PageApiOptions} The options for the page API.
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const pageApiOptions = getPageRequestParams({ path: '/api/v1/page', params: queryParams });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export const getPageRequestParams = ({
|
|
35
|
+
path = '',
|
|
36
|
+
params = {}
|
|
37
|
+
}: PageRequestParamsProps): PageApiOptions => {
|
|
38
|
+
const copiedParams: PageRequestParamsProps['params'] =
|
|
39
|
+
params instanceof URLSearchParams ? Object.fromEntries(params.entries()) : { ...params };
|
|
40
|
+
|
|
41
|
+
const finalParams: Record<string, unknown> = {};
|
|
42
|
+
const dotMarketingPersonaId = copiedParams['com.dotmarketing.persona.id'] || '';
|
|
43
|
+
|
|
44
|
+
if (copiedParams['mode']) {
|
|
45
|
+
finalParams['mode'] = copiedParams['mode'];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (copiedParams['language_id']) {
|
|
49
|
+
finalParams['language_id'] = copiedParams['language_id'];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (copiedParams['variantName']) {
|
|
53
|
+
finalParams['variantName'] = copiedParams['variantName'];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (copiedParams['personaId'] || dotMarketingPersonaId) {
|
|
57
|
+
finalParams['personaId'] = copiedParams['personaId'] || dotMarketingPersonaId;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
path,
|
|
62
|
+
...finalParams
|
|
63
|
+
};
|
|
64
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"forceConsistentCasingInFileNames": true,
|
|
6
|
+
"strict": true,
|
|
7
|
+
"noImplicitOverride": true,
|
|
8
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
9
|
+
"noImplicitReturns": true,
|
|
10
|
+
"noFallthroughCasesInSwitch": true
|
|
11
|
+
},
|
|
12
|
+
"files": [],
|
|
13
|
+
"include": [],
|
|
14
|
+
"references": [
|
|
15
|
+
{
|
|
16
|
+
"path": "./tsconfig.lib.json"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"path": "./tsconfig.spec.json"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../../dist/out-tsc",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"types": [""],
|
|
7
|
+
"target": "es2020",
|
|
8
|
+
"module": "es2020",
|
|
9
|
+
"moduleResolution": "node"
|
|
10
|
+
},
|
|
11
|
+
"include": ["src/**/*.ts"],
|
|
12
|
+
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
|
|
13
|
+
}
|
package/index.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
package/index.cjs.default.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
exports._default = require('./index.cjs.js').default;
|