@dotcms/client 0.0.1-beta.3 → 0.0.1-beta.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.
Files changed (41) hide show
  1. package/README.md +183 -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 +526 -0
  7. package/next.cjs.mjs +2 -0
  8. package/next.esm.d.ts +1 -0
  9. package/next.esm.js +524 -0
  10. package/package.json +26 -7
  11. package/src/index.d.ts +6 -6
  12. package/src/lib/client/client.d.ts +56 -0
  13. package/src/lib/client/content/builders/collection/collection.d.ts +1 -1
  14. package/src/lib/client/content/content-api.d.ts +3 -3
  15. package/src/lib/client/content/shared/types.d.ts +3 -44
  16. package/src/lib/client/navigation/navigation-api.d.ts +14 -0
  17. package/src/lib/client/page/page-api.d.ts +96 -0
  18. package/src/lib/client/page/utils.d.ts +41 -0
  19. package/src/lib/{editor → deprecated/editor}/models/client.model.d.ts +13 -0
  20. package/src/lib/{editor → deprecated/editor}/sdk-editor.d.ts +1 -1
  21. package/src/lib/{client → deprecated}/sdk-js-client.d.ts +1 -1
  22. package/src/lib/utils/graphql/transforms.d.ts +2 -13
  23. package/src/lib/utils/page/common-utils.d.ts +1 -1
  24. package/src/next.d.ts +1 -0
  25. package/transforms.cjs.js +1150 -0
  26. package/transforms.esm.js +1144 -0
  27. package/src/lib/client/models/types.d.ts +0 -13
  28. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Equals.d.ts +0 -0
  29. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Field.d.ts +0 -0
  30. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/NotOperand.d.ts +0 -0
  31. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Operand.d.ts +0 -0
  32. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/index.d.ts +0 -0
  33. /package/src/lib/{query-builder/sdk-query-builder.d.ts → client/content/builders/query/query.d.ts} +0 -0
  34. /package/src/lib/{query-builder → client/content/builders/query}/utils/index.d.ts +0 -0
  35. /package/src/lib/{editor → deprecated/editor}/listeners/listeners.d.ts +0 -0
  36. /package/src/lib/{editor → deprecated/editor}/models/editor.model.d.ts +0 -0
  37. /package/src/lib/{editor → deprecated/editor}/models/inline-event.model.d.ts +0 -0
  38. /package/src/lib/{editor → deprecated/editor}/models/listeners.model.d.ts +0 -0
  39. /package/src/lib/{editor → deprecated/editor}/sdk-editor-vtl.d.ts +0 -0
  40. /package/src/lib/{editor → deprecated/editor}/utils/editor.utils.d.ts +0 -0
  41. /package/src/lib/{editor → deprecated/editor}/utils/traditional-vtl.utils.d.ts +0 -0
@@ -1,5 +1,6 @@
1
- import { Equals } from '../../../query-builder/lucene-syntax';
2
- import { QueryBuilder } from '../../../query-builder/sdk-query-builder';
1
+ import { Contentlet } from '@dotcms/types';
2
+ import { Equals } from '../builders/query/lucene-syntax';
3
+ import { QueryBuilder } from '../builders/query/query';
3
4
  /**
4
5
  * Model to sort by fields.
5
6
  */
@@ -21,48 +22,6 @@ export type SortBy = {
21
22
  * @returns {Equals} The built query.
22
23
  */
23
24
  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
25
  /**
67
26
  * Callback for a fulfilled promise.
68
27
  *
@@ -0,0 +1,14 @@
1
+ import { DotCMSClientConfig, DotCMSNavigationRequestParams, RequestOptions } from '@dotcms/types';
2
+ export declare class NavigationClient {
3
+ private requestOptions;
4
+ private BASE_URL;
5
+ constructor(config: DotCMSClientConfig, requestOptions: RequestOptions);
6
+ /**
7
+ * Retrieves information about the dotCMS file and folder tree.
8
+ * @param {NavigationApiOptions} options - The options for the Navigation API call. Defaults to `{ depth: 0, path: '/', languageId: 1 }`.
9
+ * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
10
+ * @throws {Error} - Throws an error if the options are not valid.
11
+ */
12
+ get(path: string, params?: DotCMSNavigationRequestParams): Promise<unknown>;
13
+ private mapToBackendParams;
14
+ }
@@ -0,0 +1,96 @@
1
+ import { DotCMSClientConfig, DotCMSComposedPageResponse, DotCMSExtendedPageResponse, DotCMSPageResponse, DotCMSPageRequestParams, RequestOptions } from '@dotcms/types';
2
+ /**
3
+ * Client for interacting with the DotCMS Page API.
4
+ * Provides methods to retrieve and manipulate pages.
5
+ */
6
+ export declare class PageClient {
7
+ #private;
8
+ /**
9
+ * Request options including authorization headers.
10
+ * @private
11
+ */
12
+ private requestOptions;
13
+ /**
14
+ * Site ID for page requests.
15
+ * @private
16
+ */
17
+ private siteId;
18
+ /**
19
+ * DotCMS URL for page requests.
20
+ * @private
21
+ */
22
+ private dotcmsUrl;
23
+ /**
24
+ * Creates a new PageClient instance.
25
+ *
26
+ * @param {DotCMSClientConfig} config - Configuration options for the DotCMS client
27
+ * @param {RequestOptions} requestOptions - Options for fetch requests including authorization headers
28
+ * @example
29
+ * ```typescript
30
+ * const pageClient = new PageClient(
31
+ * {
32
+ * dotcmsUrl: 'https://demo.dotcms.com',
33
+ * authToken: 'your-auth-token',
34
+ * siteId: 'demo.dotcms.com'
35
+ * },
36
+ * {
37
+ * headers: {
38
+ * Authorization: 'Bearer your-auth-token'
39
+ * }
40
+ * }
41
+ * );
42
+ * ```
43
+ */
44
+ constructor(config: DotCMSClientConfig, requestOptions: RequestOptions);
45
+ /**
46
+ * Retrieves a page from DotCMS using GraphQL.
47
+ *
48
+ * @param {string} url - The URL of the page to retrieve
49
+ * @param {DotCMSPageRequestParams} [options] - Options for the request
50
+ * @template T - The type of the page and content, defaults to DotCMSBasicPage and Record<string, unknown> | unknown
51
+ * @returns {Promise<DotCMSComposedPageResponse<T>>} A Promise that resolves to the page data
52
+ *
53
+ * @example Using GraphQL
54
+ * ```typescript
55
+ * const page = await pageClient.get<{ page: MyPageWithBanners; content: { blogPosts: { blogTitle: string } } }>(
56
+ * '/index',
57
+ * {
58
+ * languageId: '1',
59
+ * mode: 'LIVE',
60
+ * graphql: {
61
+ * page: `
62
+ * containers {
63
+ * containerContentlets {
64
+ * contentlets {
65
+ * ... on Banner {
66
+ * ...bannerFragment
67
+ * }
68
+ * }
69
+ * }
70
+ * `,
71
+ * content: {
72
+ * blogPosts: `
73
+ * BlogCollection(limit: 3) {
74
+ * ...blogFragment
75
+ * }
76
+ * `,
77
+ * },
78
+ * fragments: [
79
+ * `
80
+ * fragment bannerFragment on Banner {
81
+ * caption
82
+ * }
83
+ * `,
84
+ * `
85
+ * fragment blogFragment on Blog {
86
+ * title
87
+ * urlTitle
88
+ * }
89
+ * `
90
+ * ]
91
+ * }
92
+ * });
93
+ * ```
94
+ */
95
+ get<T extends DotCMSExtendedPageResponse = DotCMSPageResponse>(url: string, options?: DotCMSPageRequestParams): Promise<DotCMSComposedPageResponse<T>>;
96
+ }
@@ -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
+ import { Contentlet } from '@dotcms/types';
1
2
  import { DotCMSPageEditorConfig, ReorderMenuConfig } from './models/editor.model';
2
3
  import { INLINE_EDITING_EVENT_KEY, InlineEditEventData } from './models/inline-event.model';
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,14 +1,4 @@
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
- }
1
+ import { DotCMSGraphQLPageResponse } from '@dotcms/types';
12
2
  /**
13
3
  * Transforms a GraphQL Page response to a Page Entity.
14
4
  *
@@ -20,5 +10,4 @@ interface GraphQLPageResponse {
20
10
  * const pageEntity = graphqlToPageEntity(graphQLPageResponse);
21
11
  * ```
22
12
  */
23
- export declare const graphqlToPageEntity: (graphQLPageResponse: GraphQLPageResponse) => any;
24
- export {};
13
+ export declare const graphqlToPageEntity: (graphQLPageResponse: DotCMSGraphQLPageResponse) => any;
@@ -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';