@dotcms/client 1.0.6-next.3 → 1.0.6-next.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.
- package/README.md +279 -8
- package/index.cjs.js +214 -88
- package/index.esm.js +214 -88
- package/internal.cjs.js +3 -4
- package/internal.esm.js +3 -4
- package/package.json +1 -1
- package/src/lib/client/adapters/fetch-http-client.d.ts +66 -0
- package/src/lib/client/client.d.ts +1 -0
- package/src/lib/client/content/builders/collection/collection.d.ts +8 -7
- package/src/lib/client/content/content-api.d.ts +4 -3
- package/src/lib/client/content/shared/types.d.ts +6 -16
- package/src/lib/client/navigation/navigation-api.d.ts +6 -4
- package/src/lib/client/page/page-api.d.ts +12 -4
- package/src/lib/client/page/utils.d.ts +11 -8
- package/src/lib/utils/graphql/transforms.d.ts +2 -2
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { DotCMSClientConfig } from '@dotcms/types';
|
|
2
|
-
import { GetCollectionResponse, BuildQuery, SortBy,
|
|
3
|
-
export type ClientOptions = Omit<RequestInit, 'body' | 'method'>;
|
|
1
|
+
import { DotHttpClient, DotRequestOptions, DotCMSClientConfig, DotErrorContent } from '@dotcms/types';
|
|
2
|
+
import { GetCollectionResponse, BuildQuery, SortBy, OnFullfilled, OnRejected } from '../../shared/types';
|
|
4
3
|
/**
|
|
5
4
|
* Creates a Builder to filter and fetch content from the content API for a specific content type.
|
|
6
5
|
*
|
|
@@ -15,9 +14,10 @@ export declare class CollectionBuilder<T = unknown> {
|
|
|
15
14
|
* @param {ClientOptions} requestOptions Options for the client request.
|
|
16
15
|
* @param {DotCMSClientConfig} config The client configuration.
|
|
17
16
|
* @param {string} contentType The content type to fetch.
|
|
17
|
+
* @param {DotHttpClient} httpClient HTTP client for making requests.
|
|
18
18
|
* @memberof CollectionBuilder
|
|
19
19
|
*/
|
|
20
|
-
constructor(requestOptions:
|
|
20
|
+
constructor(requestOptions: DotRequestOptions, config: DotCMSClientConfig, contentType: string, httpClient: DotHttpClient);
|
|
21
21
|
/**
|
|
22
22
|
* Returns the sort query in the format: field order, field order, ...
|
|
23
23
|
*
|
|
@@ -211,10 +211,10 @@ export declare class CollectionBuilder<T = unknown> {
|
|
|
211
211
|
*
|
|
212
212
|
* @param {OnFullfilled} [onfulfilled] A callback that is called when the fetch is successful.
|
|
213
213
|
* @param {OnRejected} [onrejected] A callback that is called when the fetch fails.
|
|
214
|
-
* @return {Promise<GetCollectionResponse<T> |
|
|
214
|
+
* @return {Promise<GetCollectionResponse<T> | DotErrorContent>} A promise that resolves to the content or rejects with an error.
|
|
215
215
|
* @memberof CollectionBuilder
|
|
216
216
|
*/
|
|
217
|
-
then(onfulfilled?: OnFullfilled<T>, onrejected?: OnRejected): Promise<GetCollectionResponse<T> |
|
|
217
|
+
then(onfulfilled?: OnFullfilled<T>, onrejected?: OnRejected): Promise<GetCollectionResponse<T> | DotErrorContent>;
|
|
218
218
|
/**
|
|
219
219
|
* Formats the response to the desired format.
|
|
220
220
|
*
|
|
@@ -228,7 +228,8 @@ export declare class CollectionBuilder<T = unknown> {
|
|
|
228
228
|
* Calls the content API to fetch the content.
|
|
229
229
|
*
|
|
230
230
|
* @private
|
|
231
|
-
* @return {Promise<
|
|
231
|
+
* @return {Promise<GetCollectionRawResponse<T>>} The fetch response data.
|
|
232
|
+
* @throws {DotHttpError} When the HTTP request fails.
|
|
232
233
|
* @memberof CollectionBuilder
|
|
233
234
|
*/
|
|
234
235
|
private fetch;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DotRequestOptions, DotHttpClient, DotCMSClientConfig } from '@dotcms/types';
|
|
2
2
|
import { CollectionBuilder } from './builders/collection/collection';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a builder to filter and fetch a collection of content items.
|
|
@@ -53,10 +53,11 @@ export declare class Content {
|
|
|
53
53
|
#private;
|
|
54
54
|
/**
|
|
55
55
|
* Creates an instance of Content.
|
|
56
|
-
* @param {
|
|
56
|
+
* @param {DotRequestOptions} requestOptions - The options for the client request.
|
|
57
57
|
* @param {string} serverUrl - The server URL.
|
|
58
|
+
* @param {DotHttpClient} httpClient - HTTP client for making requests.
|
|
58
59
|
*/
|
|
59
|
-
constructor(config: DotCMSClientConfig, requestOptions:
|
|
60
|
+
constructor(config: DotCMSClientConfig, requestOptions: DotRequestOptions, httpClient: DotHttpClient);
|
|
60
61
|
/**
|
|
61
62
|
* Takes a content type and returns a builder to filter and fetch the collection.
|
|
62
63
|
* @param {string} contentType - The content type to get the collection.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Contentlet } from '@dotcms/types';
|
|
1
|
+
import { Contentlet, DotErrorContent } from '@dotcms/types';
|
|
2
2
|
import { Equals } from '../builders/query/lucene-syntax';
|
|
3
3
|
import { QueryBuilder } from '../builders/query/query';
|
|
4
4
|
/**
|
|
@@ -28,17 +28,17 @@ export type BuildQuery = (qb: QueryBuilder) => Equals;
|
|
|
28
28
|
* @template T - The type of the response.
|
|
29
29
|
* @callback OnFullfilled
|
|
30
30
|
* @param {GetCollectionResponse<T>} value - The response value.
|
|
31
|
-
* @returns {GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>>
|
|
31
|
+
* @returns {GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>>} The processed response or a promise.
|
|
32
32
|
*/
|
|
33
|
-
export type OnFullfilled<T> = ((value: GetCollectionResponse<T>) => GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>>
|
|
33
|
+
export type OnFullfilled<T> = ((value: GetCollectionResponse<T>) => GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>>) | undefined | null;
|
|
34
34
|
/**
|
|
35
35
|
* Callback for a rejected promise.
|
|
36
36
|
*
|
|
37
37
|
* @callback OnRejected
|
|
38
|
-
* @param {
|
|
39
|
-
* @returns {
|
|
38
|
+
* @param {DotErrorContent} error - The content error object.
|
|
39
|
+
* @returns {DotErrorContent | PromiseLike<DotErrorContent>} The processed error or a promise.
|
|
40
40
|
*/
|
|
41
|
-
export type OnRejected = ((error:
|
|
41
|
+
export type OnRejected = ((error: DotErrorContent) => DotErrorContent | PromiseLike<DotErrorContent>) | undefined | null;
|
|
42
42
|
/**
|
|
43
43
|
* Response of the get collection method.
|
|
44
44
|
*
|
|
@@ -85,13 +85,3 @@ export interface GetCollectionRawResponse<T> {
|
|
|
85
85
|
resultsSize: number;
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Error object for the get collection method.
|
|
90
|
-
*/
|
|
91
|
-
export interface GetCollectionError {
|
|
92
|
-
/**
|
|
93
|
-
* The status code of the error.
|
|
94
|
-
*/
|
|
95
|
-
status: number;
|
|
96
|
-
[key: string]: unknown;
|
|
97
|
-
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { DotCMSClientConfig, DotCMSNavigationRequestParams,
|
|
1
|
+
import { DotCMSClientConfig, DotCMSNavigationRequestParams, DotRequestOptions, DotCMSNavigationItem, DotHttpClient } from '@dotcms/types';
|
|
2
2
|
export declare class NavigationClient {
|
|
3
3
|
private requestOptions;
|
|
4
4
|
private BASE_URL;
|
|
5
|
-
|
|
5
|
+
private httpClient;
|
|
6
|
+
constructor(config: DotCMSClientConfig, requestOptions: DotRequestOptions, httpClient: DotHttpClient);
|
|
6
7
|
/**
|
|
7
8
|
* Retrieves information about the dotCMS file and folder tree.
|
|
8
|
-
* @param {
|
|
9
|
+
* @param {string} path - The path to retrieve navigation for.
|
|
10
|
+
* @param {DotCMSNavigationRequestParams} params - The options for the Navigation API call.
|
|
9
11
|
* @returns {Promise<DotCMSNavigationItem[]>} - A Promise that resolves to the response from the DotCMS API.
|
|
10
|
-
* @throws {
|
|
12
|
+
* @throws {DotErrorNavigation} - Throws a navigation-specific error if the request fails.
|
|
11
13
|
*/
|
|
12
14
|
get(path: string, params?: DotCMSNavigationRequestParams): Promise<DotCMSNavigationItem[]>;
|
|
13
15
|
private mapToBackendParams;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DotCMSClientConfig,
|
|
1
|
+
import { DotCMSClientConfig, DotCMSPageRequestParams, DotCMSPageResponse, DotCMSExtendedPageResponse, DotCMSComposedPageResponse, DotHttpClient, DotRequestOptions } from '@dotcms/types';
|
|
2
2
|
/**
|
|
3
3
|
* Client for interacting with the DotCMS Page API.
|
|
4
4
|
* Provides methods to retrieve and manipulate pages.
|
|
@@ -19,11 +19,17 @@ export declare class PageClient {
|
|
|
19
19
|
* @private
|
|
20
20
|
*/
|
|
21
21
|
private dotcmsUrl;
|
|
22
|
+
/**
|
|
23
|
+
* HTTP client for making requests.
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
private httpClient;
|
|
22
27
|
/**
|
|
23
28
|
* Creates a new PageClient instance.
|
|
24
29
|
*
|
|
25
30
|
* @param {DotCMSClientConfig} config - Configuration options for the DotCMS client
|
|
26
|
-
* @param {
|
|
31
|
+
* @param {DotRequestOptions} requestOptions - Options for fetch requests including authorization headers
|
|
32
|
+
* @param {DotHttpClient} httpClient - HTTP client for making requests
|
|
27
33
|
* @example
|
|
28
34
|
* ```typescript
|
|
29
35
|
* const pageClient = new PageClient(
|
|
@@ -36,11 +42,12 @@ export declare class PageClient {
|
|
|
36
42
|
* headers: {
|
|
37
43
|
* Authorization: 'Bearer your-auth-token'
|
|
38
44
|
* }
|
|
39
|
-
* }
|
|
45
|
+
* },
|
|
46
|
+
* httpClient
|
|
40
47
|
* );
|
|
41
48
|
* ```
|
|
42
49
|
*/
|
|
43
|
-
constructor(config: DotCMSClientConfig, requestOptions:
|
|
50
|
+
constructor(config: DotCMSClientConfig, requestOptions: DotRequestOptions, httpClient: DotHttpClient);
|
|
44
51
|
/**
|
|
45
52
|
* Retrieves a page from DotCMS using GraphQL.
|
|
46
53
|
*
|
|
@@ -48,6 +55,7 @@ export declare class PageClient {
|
|
|
48
55
|
* @param {DotCMSPageRequestParams} [options] - Options for the request
|
|
49
56
|
* @template T - The type of the page and content, defaults to DotCMSBasicPage and Record<string, unknown> | unknown
|
|
50
57
|
* @returns {Promise<DotCMSComposedPageResponse<T>>} A Promise that resolves to the page data
|
|
58
|
+
* @throws {DotErrorPage} - Throws a page-specific error if the request fails or page is not found
|
|
51
59
|
*
|
|
52
60
|
* @example Using GraphQL
|
|
53
61
|
* ```typescript
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DotHttpClient, DotGraphQLApiResponse } from '@dotcms/types';
|
|
1
2
|
/**
|
|
2
3
|
* Builds a GraphQL query for retrieving page content from DotCMS.
|
|
3
4
|
*
|
|
@@ -20,22 +21,24 @@ export declare function buildQuery(queryData: Record<string, string>): string;
|
|
|
20
21
|
/**
|
|
21
22
|
* Filters response data to include only specified keys.
|
|
22
23
|
*
|
|
23
|
-
* @param {Record<string,
|
|
24
|
+
* @param {Record<string, unknown> | undefined} responseData - Original response data object
|
|
24
25
|
* @param {string[]} keys - Array of keys to extract from the response data
|
|
25
|
-
* @returns {Record<string,
|
|
26
|
+
* @returns {Record<string, unknown> | undefined} New object containing only the specified keys
|
|
26
27
|
*/
|
|
27
|
-
export declare function
|
|
28
|
+
export declare function mapContentResponse(responseData: Record<string, unknown> | undefined, keys: string[]): Record<string, unknown> | undefined;
|
|
28
29
|
/**
|
|
29
30
|
* Executes a GraphQL query against the DotCMS API.
|
|
30
31
|
*
|
|
31
32
|
* @param {Object} options - Options for the fetch request
|
|
32
33
|
* @param {string} options.body - GraphQL query string
|
|
33
34
|
* @param {Record<string, string>} options.headers - HTTP headers for the request
|
|
34
|
-
* @
|
|
35
|
-
* @
|
|
35
|
+
* @param {DotHttpClient} options.httpClient - HTTP client for making requests
|
|
36
|
+
* @returns {Promise<DotGraphQLApiResponse>} Parsed JSON response from the GraphQL API
|
|
37
|
+
* @throws {DotHttpError} If the HTTP request fails (non-2xx status or network error)
|
|
36
38
|
*/
|
|
37
|
-
export declare function fetchGraphQL({ baseURL, body, headers }: {
|
|
39
|
+
export declare function fetchGraphQL({ baseURL, body, headers, httpClient }: {
|
|
38
40
|
baseURL: string;
|
|
39
41
|
body: string;
|
|
40
|
-
headers
|
|
41
|
-
|
|
42
|
+
headers?: HeadersInit;
|
|
43
|
+
httpClient: DotHttpClient;
|
|
44
|
+
}): Promise<DotGraphQLApiResponse>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DotCMSGraphQLPage, DotCMSPageAsset } from '@dotcms/types';
|
|
2
2
|
/**
|
|
3
3
|
* Transforms a GraphQL Page response to a Page Entity.
|
|
4
4
|
*
|
|
@@ -10,4 +10,4 @@ import { DotCMSGraphQLPageResponse, DotCMSPageAsset } from '@dotcms/types';
|
|
|
10
10
|
* const pageEntity = graphqlToPageEntity(graphQLPageResponse);
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
|
-
export declare const graphqlToPageEntity: (
|
|
13
|
+
export declare const graphqlToPageEntity: (page: DotCMSGraphQLPage) => DotCMSPageAsset | null;
|