@dotcms/client 0.0.1-beta.2 → 0.0.1-beta.21

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 (47) hide show
  1. package/README.md +164 -36
  2. package/index.cjs.js +102 -1238
  3. package/index.esm.js +86 -1221
  4. package/next.cjs.d.ts +1 -0
  5. package/next.cjs.default.js +1 -0
  6. package/next.cjs.js +575 -0
  7. package/next.cjs.mjs +2 -0
  8. package/next.esm.d.ts +1 -0
  9. package/next.esm.js +573 -0
  10. package/package.json +32 -7
  11. package/src/index.d.ts +6 -6
  12. package/src/lib/client/client.d.ts +84 -0
  13. package/src/lib/client/content/builders/collection/collection.d.ts +1 -1
  14. package/src/lib/client/content/content-api.d.ts +1 -1
  15. package/src/lib/client/content/shared/types.d.ts +2 -2
  16. package/src/lib/client/models/types.d.ts +573 -10
  17. package/src/lib/client/navigation/navigation-api.d.ts +31 -0
  18. package/src/lib/client/page/page-api.d.ts +172 -0
  19. package/src/lib/client/page/utils.d.ts +41 -0
  20. package/src/lib/{editor → deprecated/editor}/models/client.model.d.ts +13 -0
  21. package/src/lib/{editor → deprecated/editor}/sdk-editor.d.ts +1 -1
  22. package/src/lib/{client → deprecated}/sdk-js-client.d.ts +1 -1
  23. package/src/lib/utils/page/common-utils.d.ts +1 -1
  24. package/src/next.d.ts +1 -0
  25. package/src/types.d.ts +2 -0
  26. package/transforms.cjs.js +1149 -0
  27. package/transforms.esm.js +1143 -0
  28. package/types.cjs.d.ts +1 -0
  29. package/types.cjs.default.js +1 -0
  30. package/types.cjs.js +2 -0
  31. package/types.cjs.mjs +2 -0
  32. package/types.esm.d.ts +1 -0
  33. package/types.esm.js +1 -0
  34. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Equals.d.ts +0 -0
  35. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Field.d.ts +0 -0
  36. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/NotOperand.d.ts +0 -0
  37. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Operand.d.ts +0 -0
  38. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/index.d.ts +0 -0
  39. /package/src/lib/{query-builder/sdk-query-builder.d.ts → client/content/builders/query/query.d.ts} +0 -0
  40. /package/src/lib/{query-builder → client/content/builders/query}/utils/index.d.ts +0 -0
  41. /package/src/lib/{editor → deprecated/editor}/listeners/listeners.d.ts +0 -0
  42. /package/src/lib/{editor → deprecated/editor}/models/editor.model.d.ts +0 -0
  43. /package/src/lib/{editor → deprecated/editor}/models/inline-event.model.d.ts +0 -0
  44. /package/src/lib/{editor → deprecated/editor}/models/listeners.model.d.ts +0 -0
  45. /package/src/lib/{editor → deprecated/editor}/sdk-editor-vtl.d.ts +0 -0
  46. /package/src/lib/{editor → deprecated/editor}/utils/editor.utils.d.ts +0 -0
  47. /package/src/lib/{editor → deprecated/editor}/utils/traditional-vtl.utils.d.ts +0 -0
@@ -0,0 +1,31 @@
1
+ import { DotCMSClientConfig, RequestOptions } from '../client';
2
+ interface NavRequestParams {
3
+ /**
4
+ * The depth of the folder tree to return.
5
+ * @example
6
+ * `1` returns only the element specified in the path.
7
+ * `2` returns the element specified in the path, and if that element is a folder, returns all direct children of that folder.
8
+ * `3` returns all children and grandchildren of the element specified in the path.
9
+ */
10
+ depth?: number;
11
+ /**
12
+ * The language ID of content to return.
13
+ * @example
14
+ * `1` (or unspecified) returns content in the default language of the site.
15
+ */
16
+ languageId?: number;
17
+ }
18
+ export declare class NavigationClient {
19
+ private requestOptions;
20
+ private BASE_URL;
21
+ constructor(config: DotCMSClientConfig, requestOptions: RequestOptions);
22
+ /**
23
+ * Retrieves information about the dotCMS file and folder tree.
24
+ * @param {NavigationApiOptions} options - The options for the Navigation API call. Defaults to `{ depth: 0, path: '/', languageId: 1 }`.
25
+ * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
26
+ * @throws {Error} - Throws an error if the options are not valid.
27
+ */
28
+ get(path: string, params?: NavRequestParams): Promise<unknown>;
29
+ private mapToBackendParams;
30
+ }
31
+ export {};
@@ -0,0 +1,172 @@
1
+ import { DotCMSClientConfig, RequestOptions } from '../client';
2
+ import { DotCMSGraphQLPageResponse, DotCMSPageAsset } from '../models/types';
3
+ /**
4
+ * The parameters for the Page API.
5
+ * @public
6
+ */
7
+ export interface PageRequestParams {
8
+ /**
9
+ * The id of the site you want to interact with. Defaults to the one from the config if not provided.
10
+ */
11
+ siteId?: string;
12
+ /**
13
+ * The mode of the page you want to retrieve. Defaults to the site's default mode if not provided.
14
+ */
15
+ mode?: 'EDIT_MODE' | 'PREVIEW_MODE' | 'LIVE';
16
+ /**
17
+ * The language id of the page you want to retrieve. Defaults to the site's default language if not provided.
18
+ */
19
+ languageId?: number | string;
20
+ /**
21
+ * The id of the persona for which you want to retrieve the page.
22
+ */
23
+ personaId?: string;
24
+ /**
25
+ * Whether to fire the rules set on the page.
26
+ */
27
+ fireRules?: boolean | string;
28
+ /**
29
+ * Allows access to related content via the Relationship fields of contentlets on a Page; 0 (default).
30
+ */
31
+ depth?: 0 | 1 | 2 | 3 | '0' | '1' | '2' | '3';
32
+ /**
33
+ * The publish date of the page you want to retrieve.
34
+ */
35
+ publishDate?: string;
36
+ /**
37
+ * The variant name of the page you want to retrieve.
38
+ */
39
+ variantName?: string;
40
+ }
41
+ type StringifyParam<T> = T extends string | number | boolean ? string : never;
42
+ type PageToBackendParamsMapping = {
43
+ siteId: 'hostId';
44
+ languageId: 'language_id';
45
+ personaId: 'com.dotmarketing.persona.id';
46
+ };
47
+ /**
48
+ * The private parameters for the Page API.
49
+ * @internal
50
+ */
51
+ export type BackendPageParams = {
52
+ [K in keyof PageRequestParams as K extends keyof PageToBackendParamsMapping ? PageToBackendParamsMapping[K] : K]?: StringifyParam<PageRequestParams[K]>;
53
+ };
54
+ /**
55
+ * The options for the GraphQL Page API.
56
+ * @public
57
+ */
58
+ export interface GraphQLPageOptions extends PageRequestParams {
59
+ /**
60
+ * The GraphQL options for the page.
61
+ */
62
+ graphql: {
63
+ page?: string;
64
+ content?: Record<string, string>;
65
+ variables?: Record<string, string>;
66
+ fragments?: string[];
67
+ };
68
+ }
69
+ /**
70
+ * Client for interacting with the DotCMS Page API.
71
+ * Provides methods to retrieve and manipulate pages.
72
+ */
73
+ export declare class PageClient {
74
+ #private;
75
+ /**
76
+ * Request options including authorization headers.
77
+ * @private
78
+ */
79
+ private requestOptions;
80
+ /**
81
+ * Site ID for page requests.
82
+ * @private
83
+ */
84
+ private siteId;
85
+ /**
86
+ * DotCMS URL for page requests.
87
+ * @private
88
+ */
89
+ private dotcmsUrl;
90
+ /**
91
+ * Creates a new PageClient instance.
92
+ *
93
+ * @param {DotCMSClientConfig} config - Configuration options for the DotCMS client
94
+ * @param {RequestOptions} requestOptions - Options for fetch requests including authorization headers
95
+ * @example
96
+ * ```typescript
97
+ * const pageClient = new PageClient(
98
+ * {
99
+ * dotcmsUrl: 'https://demo.dotcms.com',
100
+ * authToken: 'your-auth-token',
101
+ * siteId: 'demo.dotcms.com'
102
+ * },
103
+ * {
104
+ * headers: {
105
+ * Authorization: 'Bearer your-auth-token'
106
+ * }
107
+ * }
108
+ * );
109
+ * ```
110
+ */
111
+ constructor(config: DotCMSClientConfig, requestOptions: RequestOptions);
112
+ /**
113
+ * Retrieves a page from DotCMS using either REST API or GraphQL.
114
+ * This method is polymorphic and can handle both REST API and GraphQL requests based on the options provided.
115
+ *
116
+ * @param {string} url - The URL of the page to retrieve
117
+ * @param {PageRequestParams | GraphQLPageOptions} [options] - Options for the request
118
+ * @returns {Promise<DotCMSPageAsset | DotCMSGraphQLPageResponse>} A Promise that resolves to the page data
119
+ *
120
+ * @example Using REST API with options
121
+ * ```typescript
122
+ * const page = await pageClient.get('/about-us', {
123
+ * mode: 'PREVIEW_MODE',
124
+ * languageId: 1,
125
+ * siteId: 'demo.dotcms.com'
126
+ * });
127
+ * ```
128
+ *
129
+ * @example Using GraphQL
130
+ * ```typescript
131
+ * const page = await pageClient.get('/index', {
132
+ * languageId: '1',
133
+ * mode: 'LIVE',
134
+ * graphql: {
135
+ * page: `
136
+ * containers {
137
+ * containerContentlets {
138
+ * contentlets {
139
+ * ... on Banner {
140
+ * ...bannerFragment
141
+ * }
142
+ * }
143
+ * }
144
+ * `,
145
+ * content: {
146
+ * blogPosts: `
147
+ * BlogCollection(limit: 3) {
148
+ * ...blogFragment
149
+ * }
150
+ * `,
151
+ * },
152
+ * fragments: [
153
+ * `
154
+ * fragment bannerFragment on Banner {
155
+ * caption
156
+ * }
157
+ * `,
158
+ * `
159
+ * fragment blogFragment on Blog {
160
+ * title
161
+ * urlTitle
162
+ * }
163
+ * `
164
+ * ]
165
+ * }
166
+ * });
167
+ *```
168
+ */
169
+ get(url: string, options?: PageRequestParams): Promise<DotCMSPageAsset>;
170
+ get(url: string, options?: GraphQLPageOptions): Promise<DotCMSGraphQLPageResponse>;
171
+ }
172
+ export {};
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Builds a GraphQL query for retrieving page content from DotCMS.
3
+ *
4
+ * @param {string} pageQuery - Custom fragment fields to include in the ClientPage fragment
5
+ * @param {string} additionalQueries - Additional GraphQL queries to include in the main query
6
+ * @returns {string} Complete GraphQL query string for page content
7
+ */
8
+ export declare const buildPageQuery: ({ page, fragments, additionalQueries }: {
9
+ page?: string;
10
+ fragments?: string[];
11
+ additionalQueries?: string;
12
+ }) => string;
13
+ /**
14
+ * Converts a record of query strings into a single GraphQL query string.
15
+ *
16
+ * @param {Record<string, string>} queryData - Object containing named query strings
17
+ * @returns {string} Combined query string or empty string if no queryData provided
18
+ */
19
+ export declare function buildQuery(queryData: Record<string, string>): string;
20
+ /**
21
+ * Filters response data to include only specified keys.
22
+ *
23
+ * @param {Record<string, string>} responseData - Original response data object
24
+ * @param {string[]} keys - Array of keys to extract from the response data
25
+ * @returns {Record<string, string>} New object containing only the specified keys
26
+ */
27
+ export declare function mapResponseData(responseData: Record<string, string>, keys: string[]): Record<string, string>;
28
+ /**
29
+ * Executes a GraphQL query against the DotCMS API.
30
+ *
31
+ * @param {Object} options - Options for the fetch request
32
+ * @param {string} options.body - GraphQL query string
33
+ * @param {Record<string, string>} options.headers - HTTP headers for the request
34
+ * @returns {Promise<any>} Parsed JSON response from the GraphQL API
35
+ * @throws {Error} If the HTTP response is not successful
36
+ */
37
+ export declare function fetchGraphQL({ baseURL, body, headers }: {
38
+ baseURL: string;
39
+ body: string;
40
+ headers: Record<string, string>;
41
+ }): Promise<any>;
@@ -95,4 +95,17 @@ export interface DotUVE {
95
95
  reorderMenu: typeof reorderMenu;
96
96
  lastScrollYPosition: number;
97
97
  }
98
+ /**
99
+ * Represents a listener for DotcmsClientListener.
100
+ *
101
+ * @typedef {Object} DotcmsClientListener
102
+ * @property {string} action - The action that triggers the event.
103
+ * @property {string} event - The name of the event.
104
+ * @property {function(...args: any[]): void} callback - The callback function to handle the event.
105
+ */
106
+ export type DotcmsClientListener = {
107
+ action: string;
108
+ event: string;
109
+ callback: (...args: any[]) => void;
110
+ };
98
111
  export {};
@@ -1,6 +1,6 @@
1
1
  import { DotCMSPageEditorConfig, ReorderMenuConfig } from './models/editor.model';
2
2
  import { INLINE_EDITING_EVENT_KEY, InlineEditEventData } from './models/inline-event.model';
3
- import { Contentlet } from '../client/content/shared/types';
3
+ import { Contentlet } from '../../client/content/shared/types';
4
4
  /**
5
5
  * Updates the navigation in the editor.
6
6
  *
@@ -1,4 +1,4 @@
1
- import { Content } from './content/content-api';
1
+ import { Content } from '../client/content/content-api';
2
2
  export type ClientOptions = Omit<RequestInit, 'body' | 'method'>;
3
3
  export interface ClientConfig {
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { PageApiOptions } from '../../client/sdk-js-client';
1
+ import { PageApiOptions } from '../../deprecated/sdk-js-client';
2
2
  /**
3
3
  * Interface representing the properties for page request parameters.
4
4
  *
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';