@dotcms/client 0.0.1-alpha.3 → 0.0.1-alpha.30
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 +0 -1
- package/package.json +7 -3
- package/src/index.d.ts +6 -2
- package/src/index.js +6 -2
- package/src/index.js.map +1 -1
- package/src/lib/client/content/builders/collection/collection.d.ts +148 -0
- package/src/lib/client/content/builders/collection/collection.js +264 -0
- package/src/lib/client/content/builders/collection/collection.js.map +1 -0
- package/src/lib/client/content/content-api.d.ts +78 -0
- package/src/lib/client/content/content-api.js +87 -0
- package/src/lib/client/content/content-api.js.map +1 -0
- package/src/lib/client/content/shared/const.d.ts +3 -0
- package/src/lib/client/content/shared/const.js +5 -0
- package/src/lib/client/content/shared/const.js.map +1 -0
- package/src/lib/client/content/shared/types.d.ts +62 -0
- package/src/lib/client/content/shared/types.js +2 -0
- package/src/lib/client/content/shared/types.js.map +1 -0
- package/src/lib/client/content/shared/utils.d.ts +12 -0
- package/src/lib/client/content/shared/utils.js +20 -0
- package/src/lib/client/content/shared/utils.js.map +1 -0
- package/src/lib/client/models/index.d.ts +1 -0
- package/src/lib/client/models/index.js +9 -0
- package/src/lib/client/models/index.js.map +1 -0
- package/src/lib/client/models/types.d.ts +5 -0
- package/src/lib/client/models/types.js +2 -0
- package/src/lib/client/models/types.js.map +1 -0
- package/src/lib/{sdk-js-client.d.ts → client/sdk-js-client.d.ts} +33 -23
- package/src/lib/{sdk-js-client.js → client/sdk-js-client.js} +87 -38
- package/src/lib/client/sdk-js-client.js.map +1 -0
- package/src/lib/editor/listeners/listeners.d.ts +46 -0
- package/src/lib/editor/listeners/listeners.js +180 -0
- package/src/lib/editor/listeners/listeners.js.map +1 -0
- package/src/lib/{postMessageToEditor.d.ts → editor/models/client.model.d.ts} +33 -1
- package/src/lib/editor/models/client.model.js +73 -0
- package/src/lib/editor/models/client.model.js.map +1 -0
- package/src/lib/editor/models/editor.model.d.ts +49 -0
- package/src/lib/editor/models/editor.model.js +2 -0
- package/src/lib/editor/models/editor.model.js.map +1 -0
- package/src/lib/editor/models/listeners.model.d.ts +47 -0
- package/src/lib/editor/models/listeners.model.js +26 -0
- package/src/lib/editor/models/listeners.model.js.map +1 -0
- package/src/lib/editor/sdk-editor-vtl.d.ts +6 -0
- package/src/lib/editor/sdk-editor-vtl.js +20 -0
- package/src/lib/editor/sdk-editor-vtl.js.map +1 -0
- package/src/lib/editor/sdk-editor.d.ts +29 -0
- package/src/lib/editor/sdk-editor.js +65 -0
- package/src/lib/editor/sdk-editor.js.map +1 -0
- package/src/lib/editor/utils/editor.utils.d.ts +83 -0
- package/src/lib/editor/utils/editor.utils.js +134 -0
- package/src/lib/editor/utils/editor.utils.js.map +1 -0
- package/src/lib/query-builder/lucene-syntax/Equals.d.ts +83 -0
- package/src/lib/query-builder/lucene-syntax/Equals.js +101 -0
- package/src/lib/query-builder/lucene-syntax/Equals.js.map +1 -0
- package/src/lib/query-builder/lucene-syntax/Field.d.ts +23 -0
- package/src/lib/query-builder/lucene-syntax/Field.js +31 -0
- package/src/lib/query-builder/lucene-syntax/Field.js.map +1 -0
- package/src/lib/query-builder/lucene-syntax/NotOperand.d.ts +22 -0
- package/src/lib/query-builder/lucene-syntax/NotOperand.js +30 -0
- package/src/lib/query-builder/lucene-syntax/NotOperand.js.map +1 -0
- package/src/lib/query-builder/lucene-syntax/Operand.d.ts +44 -0
- package/src/lib/query-builder/lucene-syntax/Operand.js +55 -0
- package/src/lib/query-builder/lucene-syntax/Operand.js.map +1 -0
- package/src/lib/query-builder/lucene-syntax/index.d.ts +4 -0
- package/src/lib/query-builder/lucene-syntax/index.js +5 -0
- package/src/lib/query-builder/lucene-syntax/index.js.map +1 -0
- package/src/lib/query-builder/sdk-query-builder.d.ts +42 -0
- package/src/lib/query-builder/sdk-query-builder.js +54 -0
- package/src/lib/query-builder/sdk-query-builder.js.map +1 -0
- package/src/lib/query-builder/utils/index.d.ts +91 -0
- package/src/lib/query-builder/utils/index.js +115 -0
- package/src/lib/query-builder/utils/index.js.map +1 -0
- package/src/lib/utils/graphql/transforms.d.ts +11 -0
- package/src/lib/utils/graphql/transforms.js +52 -0
- package/src/lib/utils/graphql/transforms.js.map +1 -0
- package/src/lib/utils/index.d.ts +2 -0
- package/src/lib/utils/index.js +3 -0
- package/src/lib/utils/index.js.map +1 -0
- package/src/lib/utils/page/common-utils.d.ts +14 -0
- package/src/lib/utils/page/common-utils.js +12 -0
- package/src/lib/utils/page/common-utils.js.map +1 -0
- package/src/lib/postMessageToEditor.js +0 -41
- package/src/lib/postMessageToEditor.js.map +0 -1
- package/src/lib/sdk-js-client.js.map +0 -1
package/README.md
CHANGED
|
@@ -105,7 +105,6 @@ Always refer to the official [DotCMS documentation](https://www.dotcms.com/docs/
|
|
|
105
105
|
| Installation | [Installation](https://dotcms.com/docs/latest/installation) |
|
|
106
106
|
| Documentation | [Documentation](https://dotcms.com/docs/latest/table-of-contents) |
|
|
107
107
|
| Videos | [Helpful Videos](http://dotcms.com/videos/) |
|
|
108
|
-
| Code Examples | [Codeshare](https://dotcms.com/codeshare/) |
|
|
109
108
|
| Forums/Listserv | [via Google Groups](https://groups.google.com/forum/#!forum/dotCMS) |
|
|
110
109
|
| Twitter | @dotCMS |
|
|
111
110
|
| Main Site | [dotCMS.com](https://dotcms.com/) |
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcms/client",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.30",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Official JavaScript library for interacting with DotCMS REST APIs.",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/dotCMS/core.git#master"
|
|
9
9
|
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "nx run sdk-client:build:js; cd ../../../../dotCMS/src/main/webapp/html/js/editor-js; rm -rf src package.json *.esm.d.ts"
|
|
12
|
+
},
|
|
10
13
|
"keywords": [
|
|
11
14
|
"dotCMS",
|
|
12
15
|
"CMS",
|
|
@@ -21,5 +24,6 @@
|
|
|
21
24
|
},
|
|
22
25
|
"homepage": "https://github.com/dotCMS/core/tree/master/core-web/libs/sdk/client/README.md",
|
|
23
26
|
"module": "./src/index.js",
|
|
24
|
-
"main": "./src/index.js"
|
|
25
|
-
|
|
27
|
+
"main": "./src/index.js",
|
|
28
|
+
"types": "./src/index.d.ts"
|
|
29
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export * from './lib/sdk-js-client';
|
|
2
|
-
export * from './lib/
|
|
1
|
+
export * from './lib/client/sdk-js-client';
|
|
2
|
+
export * from './lib/editor/sdk-editor';
|
|
3
|
+
export * from './lib/editor/models/editor.model';
|
|
4
|
+
export * from './lib/editor/models/client.model';
|
|
5
|
+
export * from './lib/query-builder/sdk-query-builder';
|
|
6
|
+
export * from './lib/utils';
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
export * from './lib/sdk-js-client';
|
|
2
|
-
export * from './lib/
|
|
1
|
+
export * from './lib/client/sdk-js-client';
|
|
2
|
+
export * from './lib/editor/sdk-editor';
|
|
3
|
+
export * from './lib/editor/models/editor.model';
|
|
4
|
+
export * from './lib/editor/models/client.model';
|
|
5
|
+
export * from './lib/query-builder/sdk-query-builder';
|
|
6
|
+
export * from './lib/utils';
|
|
3
7
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/sdk/client/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/sdk/client/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,uCAAuC,CAAC;AACtD,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { ClientOptions } from '../../../sdk-js-client';
|
|
2
|
+
import { GetCollectionResponse, BuildQuery, SortBy, GetCollectionError, OnFullfilled, OnRejected } from '../../shared/types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Builder to filter and fetch content from the content API for an specific content type
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @class CollectionBuilder
|
|
8
|
+
* @template T Represents the type of the content type to fetch. Defaults to unknown
|
|
9
|
+
*/
|
|
10
|
+
export declare class CollectionBuilder<T = unknown> {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(requestOptions: ClientOptions, serverUrl: string, contentType: string);
|
|
13
|
+
/**
|
|
14
|
+
* This method returns the sort query in this format: field order, field order, ...
|
|
15
|
+
*
|
|
16
|
+
* @readonly
|
|
17
|
+
* @private
|
|
18
|
+
* @memberof CollectionBuilder
|
|
19
|
+
*/
|
|
20
|
+
private get sort();
|
|
21
|
+
private get offset();
|
|
22
|
+
private get url();
|
|
23
|
+
/**
|
|
24
|
+
* This method returns the current query built
|
|
25
|
+
*
|
|
26
|
+
* @readonly
|
|
27
|
+
* @private
|
|
28
|
+
* @memberof CollectionBuilder
|
|
29
|
+
*/
|
|
30
|
+
private get currentQuery();
|
|
31
|
+
/**
|
|
32
|
+
* Takes a language id and filters the content by that language.
|
|
33
|
+
*
|
|
34
|
+
* The language id defaults to 1
|
|
35
|
+
*
|
|
36
|
+
*
|
|
37
|
+
* @param {number | string} languageId The language id to filter the content by
|
|
38
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
39
|
+
* @memberof CollectionBuilder
|
|
40
|
+
*/
|
|
41
|
+
language(languageId: number | string): this;
|
|
42
|
+
/**
|
|
43
|
+
* The retrieved content will have the rendered HTML
|
|
44
|
+
*
|
|
45
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
46
|
+
* @memberof CollectionBuilder
|
|
47
|
+
*/
|
|
48
|
+
render(): this;
|
|
49
|
+
/**
|
|
50
|
+
* Takes an array of constrains to sort the content by field an specific order
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```javascript
|
|
54
|
+
* // This will sort the content by title in ascending order
|
|
55
|
+
* // and by modDate in descending order
|
|
56
|
+
* const sortBy = [{ field: 'title', order: 'asc' }, { field: 'modDate', order: 'desc' }]
|
|
57
|
+
*
|
|
58
|
+
* client.content.getCollection("Blog").sortBy(sortBy)
|
|
59
|
+
*```
|
|
60
|
+
*
|
|
61
|
+
* @param {SortBy[]} sortBy Array of constrains to sort the content by
|
|
62
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
63
|
+
* @memberof CollectionBuilder
|
|
64
|
+
*/
|
|
65
|
+
sortBy(sortBy: SortBy[]): this;
|
|
66
|
+
/**
|
|
67
|
+
* Takes a number that represents the max amount of content to fetch
|
|
68
|
+
*
|
|
69
|
+
* `limit` is set to 10 by default
|
|
70
|
+
*
|
|
71
|
+
* @param {number} limit The max amount of content to fetch
|
|
72
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
73
|
+
* @memberof CollectionBuilder
|
|
74
|
+
*/
|
|
75
|
+
limit(limit: number): this;
|
|
76
|
+
/**
|
|
77
|
+
* Takes a number that represents the page to fetch
|
|
78
|
+
*
|
|
79
|
+
* @param {number} page The page to fetch
|
|
80
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
81
|
+
* @memberof CollectionBuilder
|
|
82
|
+
*/
|
|
83
|
+
page(page: number): this;
|
|
84
|
+
/**
|
|
85
|
+
* Takes a string that represents a {@link https://www.dotcms.com/docs/latest/content-search-syntax#Lucene Lucene Query} that is used to filter the content to fetch.
|
|
86
|
+
*
|
|
87
|
+
* The string is not validated, so be cautious when using it.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} query A {@link https://www.dotcms.com/docs/latest/content-search-syntax#Lucene Lucene Query} String
|
|
90
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
91
|
+
* @memberof CollectionBuilder
|
|
92
|
+
*/
|
|
93
|
+
query(query: string): this;
|
|
94
|
+
/**
|
|
95
|
+
* Takes a function that recieves a QueryBuilder to buid a query for content filtering.
|
|
96
|
+
* @example
|
|
97
|
+
*```javascript
|
|
98
|
+
* // This will filter the content by title equals 'Hello World' or 'Hello World 2'
|
|
99
|
+
* client.content.getCollection("Activity").query((queryBuilder) =>
|
|
100
|
+
* queryBuilder.field('title').equals('Hello World').or().equals('Hello World 2')
|
|
101
|
+
* );
|
|
102
|
+
*```
|
|
103
|
+
* @param {BuildQuery} buildQuery A function that receives a QueryBuilder instance and returns a valid query
|
|
104
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
105
|
+
* @memberof CollectionBuilder
|
|
106
|
+
*/
|
|
107
|
+
query(buildQuery: BuildQuery): this;
|
|
108
|
+
/**
|
|
109
|
+
* The retrieved content will be draft content
|
|
110
|
+
*
|
|
111
|
+
* The default value is false to fetch content that is not on draft
|
|
112
|
+
*
|
|
113
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
114
|
+
* @memberof CollectionBuilder
|
|
115
|
+
*/
|
|
116
|
+
draft(): this;
|
|
117
|
+
/**
|
|
118
|
+
* Takes a string that represents a variant ID of content created with the {@link https://www.dotcms.com/docs/latest/experiments-and-a-b-testing A/B Testing} feature
|
|
119
|
+
*
|
|
120
|
+
* `variantId` defaults to "DEFAULT" to fetch content that is not part of an A/B test
|
|
121
|
+
*
|
|
122
|
+
* @param {string} variantId A string that represents a variant ID
|
|
123
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
124
|
+
* @memberof CollectionBuilder
|
|
125
|
+
*/
|
|
126
|
+
variant(variantId: string): this;
|
|
127
|
+
/**
|
|
128
|
+
* Takes a number that represents the depth of the relationships of a content
|
|
129
|
+
*
|
|
130
|
+
* The `depth` is set to 0 by default and the max supported value is 3.
|
|
131
|
+
*
|
|
132
|
+
* @param {number} depth The depth of the relationships of a content
|
|
133
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
134
|
+
* @memberof CollectionBuilder
|
|
135
|
+
*/
|
|
136
|
+
depth(depth: number): this;
|
|
137
|
+
/**
|
|
138
|
+
* Executes the fetch and returns a promise that resolves to the content or rejects to an error
|
|
139
|
+
*
|
|
140
|
+
* @param {OnFullfilled} [onfulfilled] A callback that is called when the fetch is successful
|
|
141
|
+
* @param {OnRejected} [onrejected] A callback that is called when the fetch fails
|
|
142
|
+
* @return {Promise<GetCollectionResponse<T> | GetCollectionError>} A promise that resolves to the content or rejects to an error
|
|
143
|
+
* @memberof CollectionBuilder
|
|
144
|
+
*/
|
|
145
|
+
then(onfulfilled?: OnFullfilled<T>, onrejected?: OnRejected): Promise<GetCollectionResponse<T> | GetCollectionError>;
|
|
146
|
+
private formatResponse;
|
|
147
|
+
private fetch;
|
|
148
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
var _CollectionBuilder_page, _CollectionBuilder_limit, _CollectionBuilder_depth, _CollectionBuilder_render, _CollectionBuilder_sortBy, _CollectionBuilder_contentType, _CollectionBuilder_defaultQuery, _CollectionBuilder_query, _CollectionBuilder_rawQuery, _CollectionBuilder_languageId, _CollectionBuilder_draft, _CollectionBuilder_serverUrl, _CollectionBuilder_requestOptions;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { Equals } from '../../../../query-builder/lucene-syntax';
|
|
4
|
+
import { QueryBuilder } from '../../../../query-builder/sdk-query-builder';
|
|
5
|
+
import { CONTENT_API_URL } from '../../shared/const';
|
|
6
|
+
import { sanitizeQueryForContentType } from '../../shared/utils';
|
|
7
|
+
/**
|
|
8
|
+
* Creates a Builder to filter and fetch content from the content API for an specific content type
|
|
9
|
+
*
|
|
10
|
+
* @export
|
|
11
|
+
* @class CollectionBuilder
|
|
12
|
+
* @template T Represents the type of the content type to fetch. Defaults to unknown
|
|
13
|
+
*/
|
|
14
|
+
export class CollectionBuilder {
|
|
15
|
+
constructor(requestOptions, serverUrl, contentType) {
|
|
16
|
+
_CollectionBuilder_page.set(this, 1);
|
|
17
|
+
_CollectionBuilder_limit.set(this, 10);
|
|
18
|
+
_CollectionBuilder_depth.set(this, 0);
|
|
19
|
+
_CollectionBuilder_render.set(this, false);
|
|
20
|
+
_CollectionBuilder_sortBy.set(this, void 0);
|
|
21
|
+
_CollectionBuilder_contentType.set(this, void 0);
|
|
22
|
+
_CollectionBuilder_defaultQuery.set(this, void 0);
|
|
23
|
+
_CollectionBuilder_query.set(this, void 0);
|
|
24
|
+
_CollectionBuilder_rawQuery.set(this, void 0);
|
|
25
|
+
_CollectionBuilder_languageId.set(this, 1);
|
|
26
|
+
_CollectionBuilder_draft.set(this, false);
|
|
27
|
+
_CollectionBuilder_serverUrl.set(this, void 0);
|
|
28
|
+
_CollectionBuilder_requestOptions.set(this, void 0);
|
|
29
|
+
__classPrivateFieldSet(this, _CollectionBuilder_requestOptions, requestOptions, "f");
|
|
30
|
+
__classPrivateFieldSet(this, _CollectionBuilder_serverUrl, serverUrl, "f");
|
|
31
|
+
__classPrivateFieldSet(this, _CollectionBuilder_contentType, contentType, "f");
|
|
32
|
+
// We need to build the default query with the contentType field
|
|
33
|
+
__classPrivateFieldSet(this, _CollectionBuilder_defaultQuery, new QueryBuilder().field('contentType').equals(__classPrivateFieldGet(this, _CollectionBuilder_contentType, "f")), "f");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* This method returns the sort query in this format: field order, field order, ...
|
|
37
|
+
*
|
|
38
|
+
* @readonly
|
|
39
|
+
* @private
|
|
40
|
+
* @memberof CollectionBuilder
|
|
41
|
+
*/
|
|
42
|
+
get sort() {
|
|
43
|
+
return __classPrivateFieldGet(this, _CollectionBuilder_sortBy, "f")?.map((sort) => `${sort.field} ${sort.order}`).join(',');
|
|
44
|
+
}
|
|
45
|
+
get offset() {
|
|
46
|
+
// This could end in an empty response
|
|
47
|
+
return __classPrivateFieldGet(this, _CollectionBuilder_limit, "f") * (__classPrivateFieldGet(this, _CollectionBuilder_page, "f") - 1);
|
|
48
|
+
}
|
|
49
|
+
get url() {
|
|
50
|
+
return `${__classPrivateFieldGet(this, _CollectionBuilder_serverUrl, "f")}${CONTENT_API_URL}`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* This method returns the current query built
|
|
54
|
+
*
|
|
55
|
+
* @readonly
|
|
56
|
+
* @private
|
|
57
|
+
* @memberof CollectionBuilder
|
|
58
|
+
*/
|
|
59
|
+
get currentQuery() {
|
|
60
|
+
return __classPrivateFieldGet(this, _CollectionBuilder_query, "f") ?? __classPrivateFieldGet(this, _CollectionBuilder_defaultQuery, "f");
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Takes a language id and filters the content by that language.
|
|
64
|
+
*
|
|
65
|
+
* The language id defaults to 1
|
|
66
|
+
*
|
|
67
|
+
*
|
|
68
|
+
* @param {number | string} languageId The language id to filter the content by
|
|
69
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
70
|
+
* @memberof CollectionBuilder
|
|
71
|
+
*/
|
|
72
|
+
language(languageId) {
|
|
73
|
+
__classPrivateFieldSet(this, _CollectionBuilder_languageId, languageId, "f");
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The retrieved content will have the rendered HTML
|
|
78
|
+
*
|
|
79
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
80
|
+
* @memberof CollectionBuilder
|
|
81
|
+
*/
|
|
82
|
+
render() {
|
|
83
|
+
__classPrivateFieldSet(this, _CollectionBuilder_render, true, "f");
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Takes an array of constrains to sort the content by field an specific order
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```javascript
|
|
91
|
+
* // This will sort the content by title in ascending order
|
|
92
|
+
* // and by modDate in descending order
|
|
93
|
+
* const sortBy = [{ field: 'title', order: 'asc' }, { field: 'modDate', order: 'desc' }]
|
|
94
|
+
*
|
|
95
|
+
* client.content.getCollection("Blog").sortBy(sortBy)
|
|
96
|
+
*```
|
|
97
|
+
*
|
|
98
|
+
* @param {SortBy[]} sortBy Array of constrains to sort the content by
|
|
99
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
100
|
+
* @memberof CollectionBuilder
|
|
101
|
+
*/
|
|
102
|
+
sortBy(sortBy) {
|
|
103
|
+
__classPrivateFieldSet(this, _CollectionBuilder_sortBy, sortBy, "f");
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Takes a number that represents the max amount of content to fetch
|
|
108
|
+
*
|
|
109
|
+
* `limit` is set to 10 by default
|
|
110
|
+
*
|
|
111
|
+
* @param {number} limit The max amount of content to fetch
|
|
112
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
113
|
+
* @memberof CollectionBuilder
|
|
114
|
+
*/
|
|
115
|
+
limit(limit) {
|
|
116
|
+
__classPrivateFieldSet(this, _CollectionBuilder_limit, limit, "f");
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Takes a number that represents the page to fetch
|
|
121
|
+
*
|
|
122
|
+
* @param {number} page The page to fetch
|
|
123
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
124
|
+
* @memberof CollectionBuilder
|
|
125
|
+
*/
|
|
126
|
+
page(page) {
|
|
127
|
+
__classPrivateFieldSet(this, _CollectionBuilder_page, page, "f");
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
query(arg) {
|
|
131
|
+
if (typeof arg === 'string') {
|
|
132
|
+
__classPrivateFieldSet(this, _CollectionBuilder_rawQuery, arg, "f");
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
if (typeof arg !== 'function') {
|
|
136
|
+
throw new Error(`Parameter for query method should be a buildQuery function or a string.\nExample:\nclient.content.getCollection('Activity').query((queryBuilder) => queryBuilder.field('title').equals('Hello World'))\nor\nclient.content.getCollection('Activity').query('+Activity.title:"Hello World"') \nSee documentation for more information.`);
|
|
137
|
+
}
|
|
138
|
+
const builtQuery = arg(new QueryBuilder());
|
|
139
|
+
// This can be use in Javascript so we cannot rely on the type checking
|
|
140
|
+
if (builtQuery instanceof Equals) {
|
|
141
|
+
__classPrivateFieldSet(this, _CollectionBuilder_query, builtQuery.raw(this.currentQuery.build()), "f");
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
throw new Error('Provided query is not valid. A query should end in an equals method call.\nExample:\n(queryBuilder) => queryBuilder.field("title").equals("Hello World")\nSee documentation for more information.');
|
|
145
|
+
}
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The retrieved content will be draft content
|
|
150
|
+
*
|
|
151
|
+
* The default value is false to fetch content that is not on draft
|
|
152
|
+
*
|
|
153
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
154
|
+
* @memberof CollectionBuilder
|
|
155
|
+
*/
|
|
156
|
+
draft() {
|
|
157
|
+
__classPrivateFieldSet(this, _CollectionBuilder_draft, true, "f");
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Takes a string that represents a variant ID of content created with the {@link https://www.dotcms.com/docs/latest/experiments-and-a-b-testing A/B Testing} feature
|
|
162
|
+
*
|
|
163
|
+
* `variantId` defaults to "DEFAULT" to fetch content that is not part of an A/B test
|
|
164
|
+
*
|
|
165
|
+
* @param {string} variantId A string that represents a variant ID
|
|
166
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
167
|
+
* @memberof CollectionBuilder
|
|
168
|
+
*/
|
|
169
|
+
variant(variantId) {
|
|
170
|
+
__classPrivateFieldSet(this, _CollectionBuilder_query, this.currentQuery.field('variant').equals(variantId), "f");
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Takes a number that represents the depth of the relationships of a content
|
|
175
|
+
*
|
|
176
|
+
* The `depth` is set to 0 by default and the max supported value is 3.
|
|
177
|
+
*
|
|
178
|
+
* @param {number} depth The depth of the relationships of a content
|
|
179
|
+
* @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
|
|
180
|
+
* @memberof CollectionBuilder
|
|
181
|
+
*/
|
|
182
|
+
depth(depth) {
|
|
183
|
+
if (depth < 0 || depth > 3) {
|
|
184
|
+
throw new Error('Depth value must be between 0 and 3');
|
|
185
|
+
}
|
|
186
|
+
__classPrivateFieldSet(this, _CollectionBuilder_depth, depth, "f");
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Executes the fetch and returns a promise that resolves to the content or rejects to an error
|
|
191
|
+
*
|
|
192
|
+
* @param {OnFullfilled} [onfulfilled] A callback that is called when the fetch is successful
|
|
193
|
+
* @param {OnRejected} [onrejected] A callback that is called when the fetch fails
|
|
194
|
+
* @return {Promise<GetCollectionResponse<T> | GetCollectionError>} A promise that resolves to the content or rejects to an error
|
|
195
|
+
* @memberof CollectionBuilder
|
|
196
|
+
*/
|
|
197
|
+
then(onfulfilled, onrejected) {
|
|
198
|
+
return this.fetch().then(async (response) => {
|
|
199
|
+
const data = await response.json();
|
|
200
|
+
if (response.ok) {
|
|
201
|
+
const formattedResponse = this.formatResponse(data);
|
|
202
|
+
const finalResponse = typeof onfulfilled === 'function'
|
|
203
|
+
? onfulfilled(formattedResponse)
|
|
204
|
+
: formattedResponse;
|
|
205
|
+
return finalResponse;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
// Fetch does not reject on server errors, so we only have to bubble up the error as a normal fetch
|
|
209
|
+
return {
|
|
210
|
+
status: response.status,
|
|
211
|
+
...data
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}, onrejected);
|
|
215
|
+
}
|
|
216
|
+
// Formats the response to the desired format
|
|
217
|
+
formatResponse(data) {
|
|
218
|
+
const contentlets = data.entity.jsonObjectView.contentlets;
|
|
219
|
+
const total = data.entity.resultsSize;
|
|
220
|
+
const mappedResponse = {
|
|
221
|
+
contentlets,
|
|
222
|
+
total,
|
|
223
|
+
page: __classPrivateFieldGet(this, _CollectionBuilder_page, "f"),
|
|
224
|
+
size: contentlets.length
|
|
225
|
+
};
|
|
226
|
+
return __classPrivateFieldGet(this, _CollectionBuilder_sortBy, "f")
|
|
227
|
+
? {
|
|
228
|
+
...mappedResponse,
|
|
229
|
+
sortedBy: __classPrivateFieldGet(this, _CollectionBuilder_sortBy, "f")
|
|
230
|
+
}
|
|
231
|
+
: mappedResponse;
|
|
232
|
+
}
|
|
233
|
+
// Calls the content API to fetch the content
|
|
234
|
+
fetch() {
|
|
235
|
+
const finalQuery = this.currentQuery
|
|
236
|
+
.field('languageId')
|
|
237
|
+
.equals(__classPrivateFieldGet(this, _CollectionBuilder_languageId, "f").toString())
|
|
238
|
+
.field('live')
|
|
239
|
+
.equals((!__classPrivateFieldGet(this, _CollectionBuilder_draft, "f")).toString())
|
|
240
|
+
.build();
|
|
241
|
+
const sanitizedQuery = sanitizeQueryForContentType(finalQuery, __classPrivateFieldGet(this, _CollectionBuilder_contentType, "f"));
|
|
242
|
+
const query = __classPrivateFieldGet(this, _CollectionBuilder_rawQuery, "f") ? `${sanitizedQuery} ${__classPrivateFieldGet(this, _CollectionBuilder_rawQuery, "f")}` : sanitizedQuery;
|
|
243
|
+
return fetch(this.url, {
|
|
244
|
+
...__classPrivateFieldGet(this, _CollectionBuilder_requestOptions, "f"),
|
|
245
|
+
method: 'POST',
|
|
246
|
+
headers: {
|
|
247
|
+
...__classPrivateFieldGet(this, _CollectionBuilder_requestOptions, "f").headers,
|
|
248
|
+
'Content-Type': 'application/json'
|
|
249
|
+
},
|
|
250
|
+
body: JSON.stringify({
|
|
251
|
+
query,
|
|
252
|
+
render: __classPrivateFieldGet(this, _CollectionBuilder_render, "f"),
|
|
253
|
+
sort: this.sort,
|
|
254
|
+
limit: __classPrivateFieldGet(this, _CollectionBuilder_limit, "f"),
|
|
255
|
+
offset: this.offset,
|
|
256
|
+
depth: __classPrivateFieldGet(this, _CollectionBuilder_depth, "f")
|
|
257
|
+
//userId: This exist but we currently don't use it
|
|
258
|
+
//allCategoriesInfo: This exist but we currently don't use it
|
|
259
|
+
})
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
_CollectionBuilder_page = new WeakMap(), _CollectionBuilder_limit = new WeakMap(), _CollectionBuilder_depth = new WeakMap(), _CollectionBuilder_render = new WeakMap(), _CollectionBuilder_sortBy = new WeakMap(), _CollectionBuilder_contentType = new WeakMap(), _CollectionBuilder_defaultQuery = new WeakMap(), _CollectionBuilder_query = new WeakMap(), _CollectionBuilder_rawQuery = new WeakMap(), _CollectionBuilder_languageId = new WeakMap(), _CollectionBuilder_draft = new WeakMap(), _CollectionBuilder_serverUrl = new WeakMap(), _CollectionBuilder_requestOptions = new WeakMap();
|
|
264
|
+
//# sourceMappingURL=collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection.js","sourceRoot":"","sources":["../../../../../../../../../../libs/sdk/client/src/lib/client/content/builders/collection/collection.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yCAAyC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAUrD,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE;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E,IAAI,CAAC,IAAI;gBACf,KAAK,EAAE,uBAAA,IAAI,gCAAO;gBAClB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,KAAK,EAAE,uBAAA,IAAI,gCAAO;gBAClB,kDAAkD;gBAClD,6DAA6D;aAChE,CAAC;SACL,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { CollectionBuilder } from './builders/collection/collection';
|
|
2
|
+
import { ClientOptions } from '../sdk-js-client';
|
|
3
|
+
/**
|
|
4
|
+
* Content classs exposes the content api methods
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @class Content
|
|
8
|
+
*/
|
|
9
|
+
export declare class Content {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(requestOptions: ClientOptions, serverUrl: string);
|
|
12
|
+
/**
|
|
13
|
+
* Takes a content type and returns a builder to filter and fetch the collection
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```javascript
|
|
17
|
+
* // Using await and async
|
|
18
|
+
* const collectionResponse = await client.content
|
|
19
|
+
* .getCollection('Blog')
|
|
20
|
+
* .limit(10)
|
|
21
|
+
* .page(2)
|
|
22
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
23
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
24
|
+
* .depth(1);
|
|
25
|
+
* ```
|
|
26
|
+
* @example
|
|
27
|
+
* ```javascript
|
|
28
|
+
* // Using then and catch
|
|
29
|
+
* client.content
|
|
30
|
+
* .getCollection('Blog')
|
|
31
|
+
* .limit(10)
|
|
32
|
+
* .page(2)
|
|
33
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
34
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
35
|
+
* .depth(1)
|
|
36
|
+
* .then((response) => {
|
|
37
|
+
* console.log(response.contentlets);
|
|
38
|
+
* })
|
|
39
|
+
* .catch((error) => {
|
|
40
|
+
* console.error(error);
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // Using an specific type for your content
|
|
46
|
+
*
|
|
47
|
+
* type Blog = {
|
|
48
|
+
* summary: string;
|
|
49
|
+
* author: string;
|
|
50
|
+
* title: string;
|
|
51
|
+
* };
|
|
52
|
+
*
|
|
53
|
+
* client.content
|
|
54
|
+
* .getCollection<Blog>('Blog')
|
|
55
|
+
* .limit(10)
|
|
56
|
+
* .page(2)
|
|
57
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
58
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
59
|
+
* .depth(1)
|
|
60
|
+
* .then((response) => {
|
|
61
|
+
* response.contentlets.forEach((blog) => {
|
|
62
|
+
* console.log(blog.title);
|
|
63
|
+
* console.log(blog.author);
|
|
64
|
+
* console.log(blog.summary);
|
|
65
|
+
* });
|
|
66
|
+
* })
|
|
67
|
+
* .catch((error) => {
|
|
68
|
+
* console.error(error);
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @param {string} contentType The content type to get the collection
|
|
73
|
+
* @return {CollectionBuilder} CollectionBuilder to filter and fetch the collection
|
|
74
|
+
* @template T Represents the type of the content type to fetch. Defaults to unknown
|
|
75
|
+
* @memberof Content
|
|
76
|
+
*/
|
|
77
|
+
getCollection<T = unknown>(contentType: string): CollectionBuilder<T>;
|
|
78
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var _Content_requestOptions, _Content_serverUrl;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { CollectionBuilder } from './builders/collection/collection';
|
|
4
|
+
/**
|
|
5
|
+
* Content classs exposes the content api methods
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @class Content
|
|
9
|
+
*/
|
|
10
|
+
export class Content {
|
|
11
|
+
constructor(requestOptions, serverUrl) {
|
|
12
|
+
_Content_requestOptions.set(this, void 0);
|
|
13
|
+
_Content_serverUrl.set(this, void 0);
|
|
14
|
+
__classPrivateFieldSet(this, _Content_requestOptions, requestOptions, "f");
|
|
15
|
+
__classPrivateFieldSet(this, _Content_serverUrl, serverUrl, "f");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Takes a content type and returns a builder to filter and fetch the collection
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```javascript
|
|
22
|
+
* // Using await and async
|
|
23
|
+
* const collectionResponse = await client.content
|
|
24
|
+
* .getCollection('Blog')
|
|
25
|
+
* .limit(10)
|
|
26
|
+
* .page(2)
|
|
27
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
28
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
29
|
+
* .depth(1);
|
|
30
|
+
* ```
|
|
31
|
+
* @example
|
|
32
|
+
* ```javascript
|
|
33
|
+
* // Using then and catch
|
|
34
|
+
* client.content
|
|
35
|
+
* .getCollection('Blog')
|
|
36
|
+
* .limit(10)
|
|
37
|
+
* .page(2)
|
|
38
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
39
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
40
|
+
* .depth(1)
|
|
41
|
+
* .then((response) => {
|
|
42
|
+
* console.log(response.contentlets);
|
|
43
|
+
* })
|
|
44
|
+
* .catch((error) => {
|
|
45
|
+
* console.error(error);
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Using an specific type for your content
|
|
51
|
+
*
|
|
52
|
+
* type Blog = {
|
|
53
|
+
* summary: string;
|
|
54
|
+
* author: string;
|
|
55
|
+
* title: string;
|
|
56
|
+
* };
|
|
57
|
+
*
|
|
58
|
+
* client.content
|
|
59
|
+
* .getCollection<Blog>('Blog')
|
|
60
|
+
* .limit(10)
|
|
61
|
+
* .page(2)
|
|
62
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
63
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
64
|
+
* .depth(1)
|
|
65
|
+
* .then((response) => {
|
|
66
|
+
* response.contentlets.forEach((blog) => {
|
|
67
|
+
* console.log(blog.title);
|
|
68
|
+
* console.log(blog.author);
|
|
69
|
+
* console.log(blog.summary);
|
|
70
|
+
* });
|
|
71
|
+
* })
|
|
72
|
+
* .catch((error) => {
|
|
73
|
+
* console.error(error);
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @param {string} contentType The content type to get the collection
|
|
78
|
+
* @return {CollectionBuilder} CollectionBuilder to filter and fetch the collection
|
|
79
|
+
* @template T Represents the type of the content type to fetch. Defaults to unknown
|
|
80
|
+
* @memberof Content
|
|
81
|
+
*/
|
|
82
|
+
getCollection(contentType) {
|
|
83
|
+
return new CollectionBuilder(__classPrivateFieldGet(this, _Content_requestOptions, "f"), __classPrivateFieldGet(this, _Content_serverUrl, "f"), contentType);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
_Content_requestOptions = new WeakMap(), _Content_serverUrl = new WeakMap();
|
|
87
|
+
//# sourceMappingURL=content-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-api.js","sourceRoot":"","sources":["../../../../../../../../libs/sdk/client/src/lib/client/content/content-api.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAIrE;;;;;GAKG;AACH,MAAM,OAAO,OAAO;IAIhB,YAAY,cAA6B,EAAE,SAAiB;QAH5D,0CAA+B;QAC/B,qCAAmB;QAGf,uBAAA,IAAI,2BAAmB,cAAc,MAAA,CAAC;QACtC,uBAAA,IAAI,sBAAc,SAAS,MAAA,CAAC;IAChC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgEG;IACH,aAAa,CAAc,WAAmB;QAC1C,OAAO,IAAI,iBAAiB,CAAI,uBAAA,IAAI,+BAAgB,EAAE,uBAAA,IAAI,0BAAW,EAAE,WAAW,CAAC,CAAC;IACxF,CAAC;CACJ"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const DEFAULT_VARIANT_ID = 'DEFAULT';
|
|
2
|
+
// Fields that we don't want to format when sanitizing the query
|
|
3
|
+
export const CONTENT_TYPE_MAIN_FIELDS = ['live', 'variant', 'contentType', 'languageId'];
|
|
4
|
+
export const CONTENT_API_URL = '/api/content/_search';
|
|
5
|
+
//# sourceMappingURL=const.js.map
|