@dotcms/client 0.0.1-alpha.4 → 0.0.1-alpha.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/.eslintrc.json +18 -0
- package/README.md +17 -6
- package/jest.config.ts +15 -0
- package/package.json +5 -5
- 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.ts +84 -0
- package/src/lib/editor/models/editor.model.ts +53 -0
- package/src/lib/editor/models/listeners.model.ts +50 -0
- 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.ts +148 -0
- package/src/lib/query-builder/lucene-syntax/Field.ts +40 -0
- package/src/lib/query-builder/lucene-syntax/NotOperand.ts +34 -0
- package/src/lib/query-builder/lucene-syntax/Operand.ts +58 -0
- package/src/lib/query-builder/lucene-syntax/index.ts +4 -0
- 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/index.ts +2 -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/src/index.d.ts +0 -2
- package/src/index.js +0 -3
- package/src/index.js.map +0 -1
- package/src/lib/postMessageToEditor.d.ts +0 -50
- package/src/lib/postMessageToEditor.js +0 -42
- package/src/lib/postMessageToEditor.js.map +0 -1
- package/src/lib/sdk-js-client.d.ts +0 -183
- package/src/lib/sdk-js-client.js +0 -145
- package/src/lib/sdk-js-client.js.map +0 -1
package/src/lib/sdk-js-client.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
function isValidUrl(url) {
|
|
2
|
-
try {
|
|
3
|
-
new URL(url);
|
|
4
|
-
return true;
|
|
5
|
-
}
|
|
6
|
-
catch (error) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* `DotCmsClient` is a TypeScript class that provides methods to interact with the DotCMS REST API.
|
|
12
|
-
* It requires a configuration object on instantiation, which includes the DotCMS URL, site ID, and authentication token.
|
|
13
|
-
*
|
|
14
|
-
* @class DotCmsClient
|
|
15
|
-
*
|
|
16
|
-
* @property {ClientConfig} config - The configuration object for the DotCMS client.
|
|
17
|
-
*
|
|
18
|
-
* @method constructor(config: ClientConfig) - Constructs a new instance of the DotCmsClient class.
|
|
19
|
-
*
|
|
20
|
-
* @method page.get(options: PageApiOptions): Promise<unknown> - Retrieves all the elements of any Page in your dotCMS system in JSON format.
|
|
21
|
-
*
|
|
22
|
-
* @method nav.get(options: NavApiOptions = { depth: 0, path: '/', languageId: 1 }): Promise<unknown> - Retrieves information about the dotCMS file and folder tree.
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
export class DotCmsClient {
|
|
26
|
-
constructor(config = { dotcmsUrl: '', authToken: '', requestOptions: {}, siteId: '' }) {
|
|
27
|
-
this.page = {
|
|
28
|
-
/**
|
|
29
|
-
* `page.get` is an asynchronous method of the `DotCmsClient` class that retrieves all the elements of any Page in your dotCMS system in JSON format.
|
|
30
|
-
* It takes a `PageApiOptions` object as a parameter and returns a Promise that resolves to the response from the DotCMS API.
|
|
31
|
-
*
|
|
32
|
-
* The Page API enables you to retrieve all the elements of any Page in your dotCMS system.
|
|
33
|
-
* The elements may be retrieved in JSON format.
|
|
34
|
-
*
|
|
35
|
-
* @link https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas
|
|
36
|
-
* @async
|
|
37
|
-
* @param {PageApiOptions} options - The options for the Page API call.
|
|
38
|
-
* @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
|
|
39
|
-
* @throws {Error} - Throws an error if the options are not valid.
|
|
40
|
-
*/
|
|
41
|
-
get: async (options) => {
|
|
42
|
-
this.validatePageOptions(options);
|
|
43
|
-
const queryParamsObj = {};
|
|
44
|
-
for (const [key, value] of Object.entries(options)) {
|
|
45
|
-
if (value === undefined || key === 'path' || key === 'siteId')
|
|
46
|
-
continue;
|
|
47
|
-
if (key === 'personaId') {
|
|
48
|
-
queryParamsObj['com.dotmarketing.persona.id'] = String(value);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
queryParamsObj[key] = String(value);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const queryHostId = options.siteId ?? this.config.siteId ?? '';
|
|
55
|
-
if (queryHostId) {
|
|
56
|
-
queryParamsObj['host_id'] = queryHostId;
|
|
57
|
-
}
|
|
58
|
-
const queryParams = new URLSearchParams(queryParamsObj).toString();
|
|
59
|
-
const formattedPath = options.path.startsWith('/') ? options.path : `/${options.path}`;
|
|
60
|
-
const url = `${this.config.dotcmsUrl}/api/v1/page/json${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
|
|
61
|
-
const response = await fetch(url, this.requestOptions);
|
|
62
|
-
return response.json();
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
this.nav = {
|
|
66
|
-
/**
|
|
67
|
-
* `nav.get` is an asynchronous method of the `DotCmsClient` class that retrieves information about the dotCMS file and folder tree.
|
|
68
|
-
* It takes a `NavApiOptions` object as a parameter (with default values) and returns a Promise that resolves to the response from the DotCMS API.
|
|
69
|
-
*
|
|
70
|
-
* The navigation REST API enables you to retrieve information about the dotCMS file and folder tree through REST API calls.
|
|
71
|
-
* @link https://www.dotcms.com/docs/latest/navigation-rest-api
|
|
72
|
-
* @async
|
|
73
|
-
* @param {NavApiOptions} options - The options for the Nav API call. Defaults to `{ depth: 0, path: '/', languageId: 1 }`.
|
|
74
|
-
* @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
|
|
75
|
-
* @throws {Error} - Throws an error if the options are not valid.
|
|
76
|
-
*/
|
|
77
|
-
get: async (options = { depth: 0, path: '/', languageId: 1 }) => {
|
|
78
|
-
this.validateNavOptions(options);
|
|
79
|
-
// Extract the 'path' from the options and prepare the rest as query parameters
|
|
80
|
-
const { path, ...queryParamsOptions } = options;
|
|
81
|
-
const queryParamsObj = {};
|
|
82
|
-
Object.entries(queryParamsOptions).forEach(([key, value]) => {
|
|
83
|
-
if (value !== undefined) {
|
|
84
|
-
queryParamsObj[key] = String(value);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
const queryParams = new URLSearchParams(queryParamsObj).toString();
|
|
88
|
-
// Format the URL correctly depending on the 'path' value
|
|
89
|
-
const formattedPath = path === '/' ? '/' : `/${path}`;
|
|
90
|
-
const url = `${this.config.dotcmsUrl}/api/v1/nav${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
|
|
91
|
-
const response = await fetch(url, this.requestOptions);
|
|
92
|
-
return response.json();
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
if (!config.dotcmsUrl) {
|
|
96
|
-
throw new Error("Invalid configuration - 'dotcmsUrl' is required");
|
|
97
|
-
}
|
|
98
|
-
if (!isValidUrl(config.dotcmsUrl)) {
|
|
99
|
-
throw new Error("Invalid configuration - 'dotcmsUrl' must be a valid URL");
|
|
100
|
-
}
|
|
101
|
-
if (!config.authToken) {
|
|
102
|
-
throw new Error("Invalid configuration - 'authToken' is required");
|
|
103
|
-
}
|
|
104
|
-
this.config = config;
|
|
105
|
-
this.requestOptions = {
|
|
106
|
-
...this.config.requestOptions,
|
|
107
|
-
headers: {
|
|
108
|
-
Authorization: `Bearer ${this.config.authToken}`,
|
|
109
|
-
...this.config.requestOptions?.headers
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
validatePageOptions(options) {
|
|
114
|
-
if (!options.path) {
|
|
115
|
-
throw new Error("The 'path' parameter is required for the Page API");
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
validateNavOptions(options) {
|
|
119
|
-
if (!options.path) {
|
|
120
|
-
throw new Error("The 'path' parameter is required for the Nav API");
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* `dotcmsClient` is an object that provides a method to initialize the DotCMS SDK client.
|
|
126
|
-
* It has a single method `init` which takes a configuration object and returns an instance of the `DotCmsClient` class.
|
|
127
|
-
*
|
|
128
|
-
* @namespace dotcmsClient
|
|
129
|
-
*
|
|
130
|
-
* @method init(config: ClientConfig): DotCmsClient - Initializes the SDK client.
|
|
131
|
-
*/
|
|
132
|
-
export const dotcmsClient = {
|
|
133
|
-
/**
|
|
134
|
-
* `init` is a method of the `dotcmsClient` object that initializes the SDK client.
|
|
135
|
-
* It takes a configuration object as a parameter and returns an instance of the `DotCmsClient` class.
|
|
136
|
-
*
|
|
137
|
-
* @method init
|
|
138
|
-
* @param {ClientConfig} config - The configuration object for the DotCMS client.
|
|
139
|
-
* @returns {DotCmsClient} - An instance of the {@link DotCmsClient} class.
|
|
140
|
-
*/
|
|
141
|
-
init: (config) => {
|
|
142
|
-
return new DotCmsClient(config);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
//# sourceMappingURL=sdk-js-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-js-client.js","sourceRoot":"","sources":["../../../../../../libs/sdk/client/src/lib/sdk-js-client.ts"],"names":[],"mappings":"AAkHA,SAAS,UAAU,CAAC,GAAW;IAC3B,IAAI;QACA,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAEb,OAAO,IAAI,CAAC;KACf;IAAC,OAAO,KAAK,EAAE;QACZ,OAAO,KAAK,CAAC;KAChB;AACL,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,YAAY;IAIrB,YACI,SAAuB,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QAyB3F,SAAI,GAAG;YACH;;;;;;;;;;;;eAYG;YACH,GAAG,EAAE,KAAK,EAAE,OAAuB,EAAoB,EAAE;gBACrD,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;gBAElC,MAAM,cAAc,GAA2B,EAAE,CAAC;gBAClD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;oBAChD,IAAI,KAAK,KAAK,SAAS,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,QAAQ;wBAAE,SAAS;oBAExE,IAAI,GAAG,KAAK,WAAW,EAAE;wBACrB,cAAc,CAAC,6BAA6B,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;qBACjE;yBAAM;wBACH,cAAc,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;qBACvC;iBACJ;gBAED,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;gBAE/D,IAAI,WAAW,EAAE;oBACb,cAAc,CAAC,SAA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