@dotcms/client 0.0.1-alpha.9 → 0.0.1-beta.10

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.
Files changed (74) hide show
  1. package/README.md +166 -19
  2. package/index.cjs.d.ts +1 -0
  3. package/index.cjs.default.js +1 -0
  4. package/index.cjs.js +914 -0
  5. package/index.cjs.mjs +2 -0
  6. package/index.esm.d.ts +1 -0
  7. package/index.esm.js +903 -0
  8. package/next.cjs.d.ts +1 -0
  9. package/next.cjs.default.js +1 -0
  10. package/next.cjs.js +553 -0
  11. package/next.cjs.mjs +2 -0
  12. package/next.esm.d.ts +1 -0
  13. package/next.esm.js +551 -0
  14. package/package.json +59 -23
  15. package/src/index.d.ts +8 -0
  16. package/src/lib/client/client.d.ts +84 -0
  17. package/src/lib/client/content/builders/collection/collection.d.ts +226 -0
  18. package/src/lib/client/content/builders/query/lucene-syntax/Equals.d.ts +114 -0
  19. package/src/lib/client/content/builders/query/lucene-syntax/Field.d.ts +32 -0
  20. package/src/lib/client/content/builders/query/lucene-syntax/NotOperand.d.ts +26 -0
  21. package/src/lib/client/content/builders/query/lucene-syntax/Operand.d.ts +44 -0
  22. package/src/lib/client/content/builders/query/lucene-syntax/index.d.ts +4 -0
  23. package/src/lib/client/content/builders/query/query.d.ts +76 -0
  24. package/src/lib/client/content/builders/query/utils/index.d.ts +142 -0
  25. package/src/lib/client/content/content-api.d.ts +129 -0
  26. package/src/lib/client/content/shared/const.d.ts +13 -0
  27. package/src/lib/client/content/shared/types.d.ts +138 -0
  28. package/src/lib/client/content/shared/utils.d.ts +20 -0
  29. package/src/lib/client/models/index.d.ts +12 -0
  30. package/src/lib/client/models/types.d.ts +516 -0
  31. package/src/lib/client/navigation/navigation-api.d.ts +31 -0
  32. package/src/lib/client/page/page-api.d.ts +165 -0
  33. package/src/lib/client/page/utils.d.ts +41 -0
  34. package/src/lib/deprecated/editor/listeners/listeners.d.ts +45 -0
  35. package/src/lib/deprecated/editor/models/client.model.d.ts +111 -0
  36. package/src/lib/deprecated/editor/models/editor.model.d.ts +62 -0
  37. package/src/lib/deprecated/editor/models/inline-event.model.d.ts +9 -0
  38. package/src/lib/{editor/models/listeners.model.ts → deprecated/editor/models/listeners.model.d.ts} +17 -8
  39. package/src/lib/deprecated/editor/sdk-editor-vtl.d.ts +1 -0
  40. package/src/lib/deprecated/editor/sdk-editor.d.ts +92 -0
  41. package/src/lib/deprecated/editor/utils/editor.utils.d.ts +159 -0
  42. package/src/lib/deprecated/editor/utils/traditional-vtl.utils.d.ts +4 -0
  43. package/src/lib/deprecated/sdk-js-client.d.ts +276 -0
  44. package/src/lib/utils/graphql/transforms.d.ts +24 -0
  45. package/src/lib/utils/index.d.ts +2 -0
  46. package/src/lib/utils/page/common-utils.d.ts +33 -0
  47. package/src/next.d.ts +1 -0
  48. package/src/types.d.ts +2 -0
  49. package/transforms.cjs.js +1145 -0
  50. package/transforms.esm.js +1139 -0
  51. package/types.cjs.d.ts +1 -0
  52. package/types.cjs.default.js +1 -0
  53. package/types.cjs.js +2 -0
  54. package/types.cjs.mjs +2 -0
  55. package/types.esm.d.ts +1 -0
  56. package/types.esm.js +1 -0
  57. package/.eslintrc.json +0 -18
  58. package/jest.config.ts +0 -15
  59. package/project.json +0 -63
  60. package/src/index.ts +0 -4
  61. package/src/lib/client/sdk-js-client.spec.ts +0 -258
  62. package/src/lib/client/sdk-js-client.ts +0 -297
  63. package/src/lib/editor/listeners/listeners.spec.ts +0 -55
  64. package/src/lib/editor/listeners/listeners.ts +0 -200
  65. package/src/lib/editor/models/client.model.ts +0 -55
  66. package/src/lib/editor/models/editor.model.ts +0 -17
  67. package/src/lib/editor/sdk-editor-vtl.ts +0 -24
  68. package/src/lib/editor/sdk-editor.spec.ts +0 -95
  69. package/src/lib/editor/sdk-editor.ts +0 -70
  70. package/src/lib/editor/utils/editor.utils.spec.ts +0 -164
  71. package/src/lib/editor/utils/editor.utils.ts +0 -151
  72. package/tsconfig.json +0 -22
  73. package/tsconfig.lib.json +0 -10
  74. package/tsconfig.spec.json +0 -9
@@ -0,0 +1,142 @@
1
+ import { Equals } from '../lucene-syntax/Equals';
2
+ import { Field } from '../lucene-syntax/Field';
3
+ import { NotOperand } from '../lucene-syntax/NotOperand';
4
+ import { Operand } from '../lucene-syntax/Operand';
5
+ /**
6
+ * Enum for common Operands
7
+ *
8
+ * @export
9
+ * @enum {number}
10
+ */
11
+ export declare enum OPERAND {
12
+ OR = "OR",
13
+ AND = "AND",
14
+ NOT = "NOT"
15
+ }
16
+ /**
17
+ * This function removes extra spaces from a string.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * sanitizeQuery(" my query "); // Output: "my query"
22
+ * ```
23
+ *
24
+ * @export
25
+ * @param {string} str
26
+ * @return {*} {string}
27
+ */
28
+ export declare function sanitizeQuery(str: string): string;
29
+ /**
30
+ * This function sanitizes a term by adding quotes if it contains spaces.
31
+ * In lucene, a term with spaces should be enclosed in quotes.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * sanitizePhrases(`my term`); // Output: `"my term"`
36
+ * sanitizePhrases(`myterm`); // Output: `myterm`
37
+ * ```
38
+ *
39
+ * @export
40
+ * @param {string} term
41
+ * @return {*} {string}
42
+ */
43
+ export declare function sanitizePhrases(term: string): string;
44
+ /**
45
+ * This function builds a term to be used in a lucene query.
46
+ * We need to sanitize the term before adding it to the query.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const equals = buildEquals("+myField: ", "myValue"); // Current query: "+myField: myValue"
51
+ * ```
52
+ *
53
+ * @export
54
+ * @param {string} query
55
+ * @param {string} term
56
+ * @return {*} {Equals}
57
+ */
58
+ export declare function buildEquals(query: string, term: string): Equals;
59
+ /**
60
+ * This function builds a term to be used in a lucene query.
61
+ * We need to sanitize the raw query before adding it to the query.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const query = "+myField: myValue";
66
+ * const field = buildRawEquals(query, "-myField2: myValue2"); // Current query: "+myField: myValue -myField2: myValue"
67
+ * ```
68
+ *
69
+ * @export
70
+ * @param {string} query
71
+ * @param {string} raw
72
+ * @return {*} {Equals}
73
+ */
74
+ export declare function buildRawEquals(query: string, raw: string): Equals;
75
+ /**
76
+ * This function builds a field to be used in a lucene query.
77
+ * We need to format the field before adding it to the query.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const field = buildField("+myField: ", "myValue"); // Current query: "+myField: myValue"
82
+ * ```
83
+ *
84
+ * @export
85
+ * @param {string} query
86
+ * @param {string} field
87
+ * @return {*} {Field}
88
+ */
89
+ export declare function buildField(query: string, field: string): Field;
90
+ /**
91
+ * This function builds an exclude field to be used in a lucene query.
92
+ * We need to format the field before adding it to the query.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * const query = "+myField: myValue";
97
+ * const field = buildExcludeField(query, "myField2"); // Current query: "+myField: myValue -myField2:"
98
+ * ```
99
+ *
100
+ * @export
101
+ * @param {string} query
102
+ * @param {string} field
103
+ * @return {*} {Field}
104
+ */
105
+ export declare function buildExcludeField(query: string, field: string): Field;
106
+ /**
107
+ * This function builds an operand to be used in a lucene query.
108
+ * We need to format the operand before adding it to the query.
109
+ *
110
+ * @example
111
+ * <caption>E.g. Using the AND operand</caption>
112
+ * ```ts
113
+ * const query = "+myField: myValue";
114
+ * const field = buildOperand(query, OPERAND.AND); // Current query: "+myField: myValue AND"
115
+ * ```
116
+ * @example
117
+ * <caption>E.g. Using the OR operand</caption>
118
+ * ```ts
119
+ * const query = "+myField: myValue";
120
+ * const field = buildOperand(query, OPERAND.OR); // Current query: "+myField: myValue OR"
121
+ * ```
122
+ * @export
123
+ * @param {string} query
124
+ * @param {OPERAND} operand
125
+ * @return {*} {Operand}
126
+ */
127
+ export declare function buildOperand(query: string, operand: OPERAND): Operand;
128
+ /**
129
+ * This function builds a NOT operand to be used in a lucene query.
130
+ * We need to format the operand before adding it to the query.
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * const query = "+myField: myValue";
135
+ * const field = buildNotOperand(query); // Current query: "+myField: myValue NOT"
136
+ * ```
137
+ *
138
+ * @export
139
+ * @param {string} query
140
+ * @return {*} {NotOperand}
141
+ */
142
+ export declare function buildNotOperand(query: string): NotOperand;
@@ -0,0 +1,129 @@
1
+ import { CollectionBuilder } from './builders/collection/collection';
2
+ import { ClientOptions } from '../../deprecated/sdk-js-client';
3
+ /**
4
+ * Creates a builder to filter and fetch a collection of content items.
5
+ * @param contentType - The content type to retrieve.
6
+ * @returns A CollectionBuilder instance for chaining filters and executing the query.
7
+ * @template T - The type of the content items (defaults to unknown).
8
+ *
9
+ * @example Fetch blog posts with async/await
10
+ * ```typescript
11
+ * const response = await client.content
12
+ * .getCollection<BlogPost>('Blog')
13
+ * .limit(10)
14
+ * .page(2)
15
+ * .sortBy([{ field: 'title', order: 'asc' }])
16
+ * .query(q => q.field('author').equals('John Doe'))
17
+ * .depth(1)
18
+ * .fetch();
19
+ *
20
+ * console.log(response.contentlets);
21
+ * ```
22
+ *
23
+ * @example Fetch blog posts with Promise chain
24
+ * ```typescript
25
+ * client.content
26
+ * .getCollection<BlogPost>('Blog')
27
+ * .limit(10)
28
+ * .page(2)
29
+ * .sortBy([{ field: 'title', order: 'asc' }])
30
+ * .query(q => q.field('author').equals('John Doe'))
31
+ * .depth(1)
32
+ * .fetch()
33
+ * .then(response => console.log(response.contentlets))
34
+ * .catch(error => console.error(error));
35
+ * ```
36
+ *
37
+ * @example Using a custom type
38
+ * ```typescript
39
+ * interface BlogPost {
40
+ * summary: string;
41
+ * author: string;
42
+ * title: string;
43
+ * }
44
+ *
45
+ * const posts = await client.content
46
+ * .getCollection<BlogPost>('Blog')
47
+ * .limit(10)
48
+ * .fetch();
49
+ *
50
+ * posts.contentlets.forEach(post => {
51
+ * console.log(post.title, post.author, post.summary);
52
+ * });
53
+ * ```
54
+ */
55
+ export declare class Content {
56
+ #private;
57
+ /**
58
+ * Creates an instance of Content.
59
+ * @param {ClientOptions} requestOptions - The options for the client request.
60
+ * @param {string} serverUrl - The server URL.
61
+ */
62
+ constructor(requestOptions: ClientOptions, serverUrl: string);
63
+ /**
64
+ * Takes a content type and returns a builder to filter and fetch the collection.
65
+ * @param {string} contentType - The content type to get the collection.
66
+ * @return {CollectionBuilder<T>} CollectionBuilder to filter and fetch the collection.
67
+ * @template T - Represents the type of the content type to fetch. Defaults to unknown.
68
+ * @memberof Content
69
+ *
70
+ * @example
71
+ * ```javascript
72
+ * // Using await and async
73
+ * const collectionResponse = await client.content
74
+ * .getCollection('Blog')
75
+ * .limit(10)
76
+ * .page(2)
77
+ * .sortBy([{ field: 'title', order: 'asc' }])
78
+ * .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
79
+ * .depth(1);
80
+ * ```
81
+ * @example
82
+ * ```javascript
83
+ * // Using then and catch
84
+ * client.content
85
+ * .getCollection('Blog')
86
+ * .limit(10)
87
+ * .page(2)
88
+ * .sortBy([{ field: 'title', order: 'asc' }])
89
+ * .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
90
+ * .depth(1)
91
+ * .then((response) => {
92
+ * console.log(response.contentlets);
93
+ * })
94
+ * .catch((error) => {
95
+ * console.error(error);
96
+ * });
97
+ * ```
98
+ * @example
99
+ * ```typescript
100
+ * // Using a specific type for your content
101
+ *
102
+ * type Blog = {
103
+ * summary: string;
104
+ * author: string;
105
+ * title: string;
106
+ * };
107
+ *
108
+ * client.content
109
+ * .getCollection<Blog>('Blog')
110
+ * .limit(10)
111
+ * .page(2)
112
+ * .sortBy([{ field: 'title', order: 'asc' }])
113
+ * .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
114
+ * .depth(1)
115
+ * .then((response) => {
116
+ * response.contentlets.forEach((blog) => {
117
+ * console.log(blog.title);
118
+ * console.log(blog.author);
119
+ * console.log(blog.summary);
120
+ * });
121
+ * })
122
+ * .catch((error) => {
123
+ * console.error(error);
124
+ * });
125
+ * ```
126
+ *
127
+ */
128
+ getCollection<T = unknown>(contentType: string): CollectionBuilder<T>;
129
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Default variant identifier used in the application.
3
+ */
4
+ export declare const DEFAULT_VARIANT_ID = "DEFAULT";
5
+ /**
6
+ * Fields that should not be formatted when sanitizing the query.
7
+ * These fields are essential for maintaining the integrity of the content type.
8
+ */
9
+ export declare const CONTENT_TYPE_MAIN_FIELDS: string[];
10
+ /**
11
+ * URL endpoint for the content API search functionality.
12
+ */
13
+ export declare const CONTENT_API_URL = "/api/content/_search";
@@ -0,0 +1,138 @@
1
+ import { Equals } from '../builders/query/lucene-syntax';
2
+ import { QueryBuilder } from '../builders/query/query';
3
+ /**
4
+ * Model to sort by fields.
5
+ */
6
+ export type SortBy = {
7
+ /**
8
+ * The field to sort by.
9
+ */
10
+ field: string;
11
+ /**
12
+ * The order of sorting: 'asc' for ascending, 'desc' for descending.
13
+ */
14
+ order: 'asc' | 'desc';
15
+ };
16
+ /**
17
+ * Callback to build a query.
18
+ *
19
+ * @callback BuildQuery
20
+ * @param {QueryBuilder} qb - The query builder instance.
21
+ * @returns {Equals} The built query.
22
+ */
23
+ export type BuildQuery = (qb: QueryBuilder) => Equals;
24
+ /**
25
+ * Main fields of a Contentlet (Inherited from the Content Type).
26
+ */
27
+ export interface ContentTypeMainFields {
28
+ hostName: string;
29
+ modDate: string;
30
+ publishDate: string;
31
+ title: string;
32
+ baseType: string;
33
+ inode: string;
34
+ archived: boolean;
35
+ ownerName: string;
36
+ host: string;
37
+ working: boolean;
38
+ locked: boolean;
39
+ stInode: string;
40
+ contentType: string;
41
+ live: boolean;
42
+ owner: string;
43
+ identifier: string;
44
+ publishUserName: string;
45
+ publishUser: string;
46
+ languageId: number;
47
+ creationDate: string;
48
+ url: string;
49
+ titleImage: string;
50
+ modUserName: string;
51
+ hasLiveVersion: boolean;
52
+ folder: string;
53
+ hasTitleImage: boolean;
54
+ sortOrder: number;
55
+ modUser: string;
56
+ __icon__: string;
57
+ contentTypeIcon: string;
58
+ variant: string;
59
+ }
60
+ /**
61
+ * The contentlet has the main fields and the custom fields of the content type.
62
+ *
63
+ * @template T - The custom fields of the content type.
64
+ */
65
+ export type Contentlet<T> = T & ContentTypeMainFields;
66
+ /**
67
+ * Callback for a fulfilled promise.
68
+ *
69
+ * @template T - The type of the response.
70
+ * @callback OnFullfilled
71
+ * @param {GetCollectionResponse<T>} value - The response value.
72
+ * @returns {GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>> | void} The processed response or a promise.
73
+ */
74
+ export type OnFullfilled<T> = ((value: GetCollectionResponse<T>) => GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>> | void) | undefined | null;
75
+ /**
76
+ * Callback for a rejected promise.
77
+ *
78
+ * @callback OnRejected
79
+ * @param {GetCollectionError} error - The error object.
80
+ * @returns {GetCollectionError | PromiseLike<GetCollectionError> | void} The processed error or a promise.
81
+ */
82
+ export type OnRejected = ((error: GetCollectionError) => GetCollectionError | PromiseLike<GetCollectionError> | void) | undefined | null;
83
+ /**
84
+ * Response of the get collection method.
85
+ *
86
+ * @template T - The type of the contentlet.
87
+ */
88
+ export interface GetCollectionResponse<T> {
89
+ /**
90
+ * The list of contentlets.
91
+ */
92
+ contentlets: Contentlet<T>[];
93
+ /**
94
+ * The current page number.
95
+ */
96
+ page: number;
97
+ /**
98
+ * The size of the page.
99
+ */
100
+ size: number;
101
+ /**
102
+ * The total number of contentlets.
103
+ */
104
+ total: number;
105
+ /**
106
+ * The fields by which the contentlets are sorted.
107
+ */
108
+ sortedBy?: SortBy[];
109
+ }
110
+ /**
111
+ * Raw response of the get collection method.
112
+ *
113
+ * @template T - The type of the contentlet.
114
+ */
115
+ export interface GetCollectionRawResponse<T> {
116
+ entity: {
117
+ jsonObjectView: {
118
+ /**
119
+ * The list of contentlets.
120
+ */
121
+ contentlets: Contentlet<T>[];
122
+ };
123
+ /**
124
+ * The size of the results.
125
+ */
126
+ resultsSize: number;
127
+ };
128
+ }
129
+ /**
130
+ * Error object for the get collection method.
131
+ */
132
+ export interface GetCollectionError {
133
+ /**
134
+ * The status code of the error.
135
+ */
136
+ status: number;
137
+ [key: string]: unknown;
138
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @description
3
+ * Sanitizes the query for the given content type.
4
+ * It replaces the fields that are not content type fields with the correct format.
5
+ * Example: +field: -> +contentTypeVar.field:
6
+ *
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * const query = '+field: value';
11
+ * const contentType = 'contentTypeVar';
12
+ * const sanitizedQuery = sanitizeQueryForContentType(query, contentType); // Output: '+contentTypeVar.field: value'
13
+ * ```
14
+ *
15
+ * @export
16
+ * @param {string} query - The query string to be sanitized.
17
+ * @param {string} contentType - The content type to be used for formatting the fields.
18
+ * @returns {string} The sanitized query string.
19
+ */
20
+ export declare function sanitizeQueryForContentType(query: string, contentType: string): string;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A record of HTTP status codes and their corresponding error messages.
3
+ *
4
+ * @type {Record<number, string>}
5
+ * @property {string} 401 - Unauthorized. Check the token and try again.
6
+ * @property {string} 403 - Forbidden. Check the permissions and try again.
7
+ * @property {string} 404 - Not Found. Check the URL and try again.
8
+ * @property {string} 500 - Internal Server Error. Try again later.
9
+ * @property {string} 502 - Bad Gateway. Try again later.
10
+ * @property {string} 503 - Service Unavailable. Try again later.
11
+ */
12
+ export declare const ErrorMessages: Record<number, string>;