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

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 (46) hide show
  1. package/index.cjs.js +102 -1238
  2. package/index.esm.js +86 -1221
  3. package/next.cjs.d.ts +1 -0
  4. package/next.cjs.default.js +1 -0
  5. package/next.cjs.js +553 -0
  6. package/next.cjs.mjs +2 -0
  7. package/next.esm.d.ts +1 -0
  8. package/next.esm.js +551 -0
  9. package/package.json +32 -7
  10. package/src/index.d.ts +6 -6
  11. package/src/lib/client/client.d.ts +84 -0
  12. package/src/lib/client/content/builders/collection/collection.d.ts +1 -1
  13. package/src/lib/client/content/content-api.d.ts +1 -1
  14. package/src/lib/client/content/shared/types.d.ts +2 -2
  15. package/src/lib/client/models/types.d.ts +513 -10
  16. package/src/lib/client/navigation/navigation-api.d.ts +31 -0
  17. package/src/lib/client/page/page-api.d.ts +165 -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/page/common-utils.d.ts +1 -1
  23. package/src/next.d.ts +1 -0
  24. package/src/types.d.ts +2 -0
  25. package/transforms.cjs.js +1145 -0
  26. package/transforms.esm.js +1139 -0
  27. package/types.cjs.d.ts +1 -0
  28. package/types.cjs.default.js +1 -0
  29. package/types.cjs.js +2 -0
  30. package/types.cjs.mjs +2 -0
  31. package/types.esm.d.ts +1 -0
  32. package/types.esm.js +1 -0
  33. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Equals.d.ts +0 -0
  34. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Field.d.ts +0 -0
  35. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/NotOperand.d.ts +0 -0
  36. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Operand.d.ts +0 -0
  37. /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/index.d.ts +0 -0
  38. /package/src/lib/{query-builder/sdk-query-builder.d.ts → client/content/builders/query/query.d.ts} +0 -0
  39. /package/src/lib/{query-builder → client/content/builders/query}/utils/index.d.ts +0 -0
  40. /package/src/lib/{editor → deprecated/editor}/listeners/listeners.d.ts +0 -0
  41. /package/src/lib/{editor → deprecated/editor}/models/editor.model.d.ts +0 -0
  42. /package/src/lib/{editor → deprecated/editor}/models/inline-event.model.d.ts +0 -0
  43. /package/src/lib/{editor → deprecated/editor}/models/listeners.model.d.ts +0 -0
  44. /package/src/lib/{editor → deprecated/editor}/sdk-editor-vtl.d.ts +0 -0
  45. /package/src/lib/{editor → deprecated/editor}/utils/editor.utils.d.ts +0 -0
  46. /package/src/lib/{editor → deprecated/editor}/utils/traditional-vtl.utils.d.ts +0 -0
@@ -0,0 +1,165 @@
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
+ export interface GraphQLPageOptions extends PageRequestParams {
55
+ graphql: {
56
+ page?: string;
57
+ content?: Record<string, string>;
58
+ variables?: Record<string, string>;
59
+ fragments?: string[];
60
+ };
61
+ }
62
+ /**
63
+ * Client for interacting with the DotCMS Page API.
64
+ * Provides methods to retrieve and manipulate pages.
65
+ */
66
+ export declare class PageClient {
67
+ #private;
68
+ /**
69
+ * Request options including authorization headers.
70
+ * @private
71
+ */
72
+ private requestOptions;
73
+ /**
74
+ * Site ID for page requests.
75
+ * @private
76
+ */
77
+ private siteId;
78
+ /**
79
+ * DotCMS URL for page requests.
80
+ * @private
81
+ */
82
+ private dotcmsUrl;
83
+ /**
84
+ * Creates a new PageClient instance.
85
+ *
86
+ * @param {DotCMSClientConfig} config - Configuration options for the DotCMS client
87
+ * @param {RequestOptions} requestOptions - Options for fetch requests including authorization headers
88
+ * @example
89
+ * ```typescript
90
+ * const pageClient = new PageClient(
91
+ * {
92
+ * dotcmsUrl: 'https://demo.dotcms.com',
93
+ * authToken: 'your-auth-token',
94
+ * siteId: 'demo.dotcms.com'
95
+ * },
96
+ * {
97
+ * headers: {
98
+ * Authorization: 'Bearer your-auth-token'
99
+ * }
100
+ * }
101
+ * );
102
+ * ```
103
+ */
104
+ constructor(config: DotCMSClientConfig, requestOptions: RequestOptions);
105
+ /**
106
+ * Retrieves a page from DotCMS using either REST API or GraphQL.
107
+ * This method is polymorphic and can handle both REST API and GraphQL requests based on the options provided.
108
+ *
109
+ * @param {string} url - The URL of the page to retrieve
110
+ * @param {PageRequestParams | GraphQLPageOptions} [options] - Options for the request
111
+ * @returns {Promise<DotCMSPageAsset | DotCMSGraphQLPageResponse>} A Promise that resolves to the page data
112
+ *
113
+ * @example Using REST API with options
114
+ * ```typescript
115
+ * const page = await pageClient.get('/about-us', {
116
+ * mode: 'PREVIEW_MODE',
117
+ * languageId: 1,
118
+ * siteId: 'demo.dotcms.com'
119
+ * });
120
+ * ```
121
+ *
122
+ * @example Using GraphQL
123
+ * ```typescript
124
+ * const page = await pageClient.get('/index', {
125
+ * languageId: '1',
126
+ * mode: 'LIVE',
127
+ * graphql: {
128
+ * page: `
129
+ * containers {
130
+ * containerContentlets {
131
+ * contentlets {
132
+ * ... on Banner {
133
+ * ...bannerFragment
134
+ * }
135
+ * }
136
+ * }
137
+ * `,
138
+ * content: {
139
+ * blogPosts: `
140
+ * BlogCollection(limit: 3) {
141
+ * ...blogFragment
142
+ * }
143
+ * `,
144
+ * },
145
+ * fragments: [
146
+ * `
147
+ * fragment bannerFragment on Banner {
148
+ * caption
149
+ * }
150
+ * `,
151
+ * `
152
+ * fragment blogFragment on Blog {
153
+ * title
154
+ * urlTitle
155
+ * }
156
+ * `
157
+ * ]
158
+ * }
159
+ * });
160
+ *```
161
+ */
162
+ get(url: string, options?: PageRequestParams): Promise<DotCMSPageAsset>;
163
+ get(url: string, options?: GraphQLPageOptions): Promise<DotCMSGraphQLPageResponse>;
164
+ }
165
+ 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';