@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,276 @@
1
+ import { Content } from '../client/content/content-api';
2
+ export type ClientOptions = Omit<RequestInit, 'body' | 'method'>;
3
+ export interface ClientConfig {
4
+ /**
5
+ * The URL of the dotCMS instance.
6
+ *
7
+ * @description This is the URL of the dotCMS instance you want to interact with. Ensure to include the protocol (http or https).
8
+ * @example `https://demo.dotcms.com`
9
+ * @type {string}
10
+ * @required
11
+ */
12
+ dotcmsUrl: string;
13
+ /**
14
+ * The id of the site you want to interact with. If not provided, it will use the default site.
15
+ *
16
+ * More information here: {@link https://www.dotcms.com/docs/latest/multi-site-management}
17
+ *
18
+ * @description To get the site id, go to the site you want to interact with and copy the id from the History tab.
19
+ * @type {string}
20
+ * @optional
21
+ */
22
+ siteId?: string;
23
+ /**
24
+ * The authentication token to use for the requests.
25
+ *
26
+ * @description You can get the auth token from our UI {@link https://www.dotcms.com/docs/latest/rest-api-authentication#creating-an-api-token-in-the-ui}
27
+ * @type {string}
28
+ * @required
29
+ */
30
+ authToken: string;
31
+ /**
32
+ * Additional options to pass to the fetch request.
33
+ *
34
+ * @description These options will be used in the fetch request. Any option can be specified except for 'body' and 'method' which are omitted.
35
+ * @example `{ headers: { 'Content-Type': 'application/json' } }`
36
+ * @type {ClientOptions}
37
+ * @optional
38
+ */
39
+ requestOptions?: ClientOptions;
40
+ }
41
+ export type PageApiOptions = {
42
+ /**
43
+ * The path of the page you want to retrieve.
44
+ * @type {string}
45
+ */
46
+ path: string;
47
+ /**
48
+ * The id of the site you want to interact with. If not provided, the one from the config will be used.
49
+ *
50
+ * More information here: {@link https://www.dotcms.com/docs/latest/multi-site-management}
51
+ * @type {string}
52
+ * @optional
53
+ */
54
+ siteId?: string;
55
+ /**
56
+ * The mode of the page you want to retrieve. If not provided, will use the default mode of the site.
57
+ *
58
+ * More information here: {@link https://www.dotcms.com/docs/latest/page-viewing-modes}
59
+ * @type {string}
60
+ * @optional
61
+ */
62
+ mode?: 'EDIT_MODE' | 'PREVIEW_MODE' | 'LIVE';
63
+ /**
64
+ * The language id of the page you want to retrieve. If not provided, will use the default language of the site.
65
+ * @type {number}
66
+ * @optional
67
+ */
68
+ language_id?: number;
69
+ /**
70
+ * The id of the persona you want to retrieve the page for.
71
+ *
72
+ * More information here: {@link https://www.dotcms.com/docs/latest/personas}
73
+ * @type {string}
74
+ * @optional
75
+ */
76
+ personaId?: string;
77
+ /**
78
+ * If you want to fire the rules set on the page.
79
+ *
80
+ * More information here: {@link https://www.dotcms.com/docs/latest/adding-rules-to-pages}
81
+ *
82
+ * @type {boolean}
83
+ * @optional
84
+ */
85
+ fireRules?: boolean;
86
+ /**
87
+ * Allows access to related content via the Relationship fields of contentlets on a Page; 0 (default).
88
+ * @type {number}
89
+ * @optional
90
+ */
91
+ depth?: number;
92
+ };
93
+ type NavApiOptions = {
94
+ /**
95
+ * The root path to begin traversing the folder tree.
96
+ * @example
97
+ * `/api/v1/nav/` starts from the root of the site
98
+ * @example
99
+ * `/about-us` starts from the "About Us" folder
100
+ * @type {string}
101
+ */
102
+ path: string;
103
+ /**
104
+ * The depth of the folder tree to return.
105
+ * @example
106
+ * `1` returns only the element specified in the path.
107
+ * @example
108
+ * `2` returns the element specified in the path, and if that element is a folder, returns all direct children of that folder.
109
+ * @example
110
+ * `3` returns all children and grandchildren of the element specified in the path.
111
+ * @type {number}
112
+ * @optional
113
+ */
114
+ depth?: number;
115
+ /**
116
+ * The language ID of content to return.
117
+ * @example
118
+ * `1` (or unspecified) returns content in the default language of the site.
119
+ * @link https://www.dotcms.com/docs/latest/system-language-properties#DefaultLanguage
120
+ * @link https://www.dotcms.com/docs/latest/adding-and-editing-languages#LanguageID
121
+ * @type {number}
122
+ * @optional
123
+ */
124
+ languageId?: number;
125
+ };
126
+ /**
127
+ * `DotCmsClient` is a TypeScript class that provides methods to interact with the DotCMS REST API.
128
+ * DotCMS is a hybrid-headless CMS and digital experience platform.
129
+ *
130
+ * @class DotCmsClient
131
+ * @property {ClientConfig} config - The configuration object for the DotCMS client.
132
+ * @property {Content} content - Provides methods to interact with content in DotCMS.
133
+ *
134
+ * @method constructor(config: ClientConfig) - Constructs a new instance of the DotCmsClient class.
135
+ *
136
+ * @method page.get(options: PageApiOptions): Promise<PageApiResponse> - Retrieves all the elements of any Page in your dotCMS system in JSON format.
137
+ * The Page API enables you to retrieve page information, layout, template, content blocks, and more.
138
+ * @see {@link https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas}
139
+ *
140
+ * @method nav.get(options: NavApiOptions = { depth: 0, path: '/', languageId: 1 }): Promise<NavApiResponse> - Retrieves information about the dotCMS file and folder tree.
141
+ * The Navigation API allows you to fetch the site structure and menu items.
142
+ * @see {@link https://www.dotcms.com/docs/latest/navigation-rest-api}
143
+ *
144
+ * @method content.get(options: ContentApiOptions): Promise<ContentApiResponse> - Retrieves content items based on specified criteria.
145
+ * The Content API allows you to query and retrieve content by ID, inode, or using Lucene queries.
146
+ * @see {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying}
147
+ *
148
+ * @method editor.on(action: string, callbackFn: (payload: unknown) => void) - Allows you to react to actions issued by the Universal Visual Editor (UVE).
149
+ * @method editor.off(action: string) - Stops listening to an action issued by UVE.
150
+ *
151
+ * @static
152
+ * @method init(config: ClientConfig): DotCmsClient - Initializes and returns a DotCmsClient instance.
153
+ * @method dotcmsUrl: string - Retrieves the DotCMS URL from the instance configuration.
154
+ *
155
+ * @example <caption>Basic usage</caption>
156
+ * ```javascript
157
+ * const client = DotCmsClient.init({ dotcmsUrl: 'https://demo.dotcms.com', authToken: 'your-auth-token' });
158
+ *
159
+ * // Get a page
160
+ * client.page.get({ path: '/about-us' }).then(response => console.log(response));
161
+ *
162
+ * // Get navigation
163
+ * client.nav.get({ path: '/about-us', depth: 2 }).then(response => console.log(response));
164
+ *
165
+ * // Get content
166
+ * client.content.get({ query: '+contentType:Blog +languageId:1', limit: 10 }).then(response => console.log(response));
167
+ *
168
+ * // Listen to editor changes
169
+ * client.editor.on('changes', (payload) => console.log('Changes detected:', payload));
170
+ * ```
171
+ */
172
+ export declare class DotCmsClient {
173
+ #private;
174
+ static instance: DotCmsClient;
175
+ dotcmsUrl?: string;
176
+ content: Content;
177
+ constructor(config?: ClientConfig);
178
+ page: {
179
+ /**
180
+ * `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.
181
+ * It takes a `PageApiOptions` object as a parameter and returns a Promise that resolves to the response from the DotCMS API.
182
+ *
183
+ * The Page API enables you to retrieve all the elements of any Page in your dotCMS system.
184
+ * The elements may be retrieved in JSON format.
185
+ *
186
+ * @link https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas
187
+ * @async
188
+ * @param {PageApiOptions} options - The options for the Page API call.
189
+ * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
190
+ * @throws {Error} - Throws an error if the options are not valid.
191
+ * @example
192
+ * ```ts
193
+ * const client = new DotCmsClient({ dotcmsUrl: 'https://your.dotcms.com', authToken: 'your-auth-token', siteId: 'your-site-id' });
194
+ * client.page.get({ path: '/about-us' }).then(response => console.log(response));
195
+ * ```
196
+ */
197
+ get: (options: PageApiOptions) => Promise<unknown>;
198
+ };
199
+ editor: {
200
+ /**
201
+ * `editor.on` is an asynchronous method of the `DotCmsClient` class that allows you to react to actions issued by the UVE.
202
+ *
203
+ * NOTE: This is being used by the development team - This logic is probably varied or moved to another function/object.
204
+ * @param {string} action - The name of the action emitted by UVE.
205
+ * @param {function} callbackFn - The function to execute when the UVE emits the action.
206
+ * @example
207
+ * ```ts
208
+ * client.editor.on('changes', (payload) => {
209
+ * console.log('Changes detected:', payload);
210
+ * });
211
+ * ```
212
+ */
213
+ on: (action: string, callbackFn: (payload: unknown) => void) => void;
214
+ /**
215
+ * `editor.off` is a synchronous method of the `DotCmsClient` class that allows you to stop listening and reacting to an action issued by UVE.
216
+ *
217
+ * NOTE: This is being used by the development team - This logic is probably varied or moved to another function/object.
218
+ * @param {string} action - The name of the action to stop listening to.
219
+ * @example
220
+ * ```ts
221
+ * client.editor.off('changes');
222
+ * ```
223
+ */
224
+ off: (action: string) => void;
225
+ };
226
+ nav: {
227
+ /**
228
+ * `nav.get` is an asynchronous method of the `DotCmsClient` class that retrieves information about the dotCMS file and folder tree.
229
+ * It takes a `NavApiOptions` object as a parameter (with default values) and returns a Promise that resolves to the response from the DotCMS API.
230
+ *
231
+ * The navigation REST API enables you to retrieve information about the dotCMS file and folder tree through REST API calls.
232
+ * @link https://www.dotcms.com/docs/latest/navigation-rest-api
233
+ * @async
234
+ * @param {NavApiOptions} options - The options for the Nav API call. Defaults to `{ depth: 0, path: '/', languageId: 1 }`.
235
+ * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
236
+ * @throws {Error} - Throws an error if the options are not valid.
237
+ * @example
238
+ * ```ts
239
+ * const client = new DotCmsClient({ dotcmsUrl: 'https://your.dotcms.com', authToken: 'your-auth-token', siteId: 'your-site-id' }});
240
+ * client.nav.get({ path: '/about-us', depth: 2 }).then(response => console.log(response));
241
+ * ```
242
+ */
243
+ get: (options?: NavApiOptions) => Promise<unknown>;
244
+ };
245
+ /**
246
+ * Initializes the DotCmsClient instance with the provided configuration.
247
+ * If an instance already exists, it returns the existing instance.
248
+ *
249
+ * @param {ClientConfig} config - The configuration object for the DotCMS client.
250
+ * @returns {DotCmsClient} - The initialized DotCmsClient instance.
251
+ * @example
252
+ * ```ts
253
+ * const client = DotCmsClient.init({ dotcmsUrl: 'https://demo.dotcms.com', authToken: 'your-auth-token' });
254
+ * ```
255
+ */
256
+ static init(config: ClientConfig): DotCmsClient;
257
+ /**
258
+ * Retrieves the DotCMS URL from the instance configuration.
259
+ *
260
+ * @returns {string} - The DotCMS URL.
261
+ */
262
+ static get dotcmsUrl(): string;
263
+ /**
264
+ * Throws an error if the path is not valid.
265
+ *
266
+ * @returns {string} - The authentication token.
267
+ */
268
+ private validatePageOptions;
269
+ /**
270
+ * Throws an error if the path is not valid.
271
+ *
272
+ * @returns {string} - The authentication token.
273
+ */
274
+ private validateNavOptions;
275
+ }
276
+ export {};
@@ -0,0 +1,24 @@
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
+ }
12
+ /**
13
+ * Transforms a GraphQL Page response to a Page Entity.
14
+ *
15
+ * @param {GraphQLPageResponse} graphQLPageResponse - The GraphQL Page response object.
16
+ * @returns {object|null} The transformed Page Entity or null if the page is not present.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const pageEntity = graphqlToPageEntity(graphQLPageResponse);
21
+ * ```
22
+ */
23
+ export declare const graphqlToPageEntity: (graphQLPageResponse: GraphQLPageResponse) => any;
24
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './graphql/transforms';
2
+ export * from './page/common-utils';
@@ -0,0 +1,33 @@
1
+ import { PageApiOptions } from '../../deprecated/sdk-js-client';
2
+ /**
3
+ * Interface representing the properties for page request parameters.
4
+ *
5
+ * @export
6
+ * @interface PageRequestParamsProps
7
+ */
8
+ export interface PageRequestParamsProps {
9
+ /**
10
+ * The API endpoint path.
11
+ * @type {string}
12
+ */
13
+ path: string;
14
+ /**
15
+ * The query parameters for the API request.
16
+ * Can be an object with key-value pairs or a URLSearchParams instance.
17
+ * @type {{ [key: string]: unknown } | URLSearchParams}
18
+ */
19
+ params: {
20
+ [key: string]: unknown;
21
+ } | URLSearchParams;
22
+ }
23
+ /**
24
+ * Generates the page request parameters to be used in the API call.
25
+ *
26
+ * @param {PageRequestParamsProps} PageRequestParamsProps - The properties for the page request.
27
+ * @returns {PageApiOptions} The options for the page API.
28
+ * @example
29
+ * ```ts
30
+ * const pageApiOptions = getPageRequestParams({ path: '/api/v1/page', params: queryParams });
31
+ * ```
32
+ */
33
+ export declare const getPageRequestParams: ({ path, params }: PageRequestParamsProps) => PageApiOptions;
package/src/next.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { createDotCMSClient } from './lib/client/client';
package/src/types.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { DotCMSPageAsset, DotCMSGraphQLPageResponse } from './lib/client/models/types';
2
+ export { Contentlet } from './lib/client/content/shared/types';