@dotcms/client 1.2.0-next.3 → 1.2.0-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 +538 -13
- package/index.cjs.js +379 -43
- package/index.esm.js +380 -44
- package/package.json +1 -1
- package/src/lib/client/ai/ai-api.d.ts +77 -0
- package/src/lib/client/ai/search/search.d.ts +65 -0
- package/src/lib/client/ai/shared/const.d.ts +16 -0
- package/src/lib/client/ai/shared/types.d.ts +18 -0
- package/src/lib/client/base/base-api.d.ts +42 -0
- package/src/lib/client/client.d.ts +6 -0
- package/src/lib/client/content/builders/collection/collection.d.ts +2 -9
- package/src/lib/client/content/content-api.d.ts +3 -3
- package/src/lib/client/navigation/navigation-api.d.ts +8 -3
- package/src/lib/client/page/page-api.d.ts +2 -21
- package/src/lib/utils/params/utils.d.ts +25 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default values for AI configuration
|
|
3
|
+
*/
|
|
4
|
+
export declare const DEFAULT_AI_CONFIG: {
|
|
5
|
+
readonly threshold: 0.5;
|
|
6
|
+
readonly distanceFunction: "<=>";
|
|
7
|
+
readonly responseLength: 1024;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Default values for search query
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_QUERY: {
|
|
13
|
+
readonly limit: 1000;
|
|
14
|
+
readonly offset: 0;
|
|
15
|
+
readonly indexName: "default";
|
|
16
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DotCMSAISearchResponse, DotCMSBasicContentlet, DotErrorAISearch } from '@dotcms/types';
|
|
2
|
+
/**
|
|
3
|
+
* Callback for a fulfilled promise.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of the response.
|
|
6
|
+
* @callback OnFullfilled
|
|
7
|
+
* @param {DotCMSAISearchResponse} value - The response value.
|
|
8
|
+
* @returns {DotCMSAISearchResponse | PromiseLike<DotCMSAISearchResponse>} The processed response or a promise.
|
|
9
|
+
*/
|
|
10
|
+
export type OnFullfilled<T extends DotCMSBasicContentlet> = ((value: DotCMSAISearchResponse<T>) => DotCMSAISearchResponse<T> | PromiseLike<DotCMSAISearchResponse<T>>) | undefined | null;
|
|
11
|
+
/**
|
|
12
|
+
* Callback for a rejected promise.
|
|
13
|
+
*
|
|
14
|
+
* @callback OnRejected
|
|
15
|
+
* @param {DotErrorAISearch} error - The AI search error object.
|
|
16
|
+
* @returns {DotErrorAISearch | PromiseLike<DotErrorAISearch>} The processed error or a promise.
|
|
17
|
+
*/
|
|
18
|
+
export type OnRejected = ((error: DotErrorAISearch) => DotErrorAISearch | PromiseLike<DotErrorAISearch>) | undefined | null;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DotCMSClientConfig, DotHttpClient, DotRequestOptions } from '@dotcms/types';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all DotCMS API clients.
|
|
4
|
+
* Provides common constructor parameters and properties that all API clients need.
|
|
5
|
+
* Uses JavaScript private fields (#) for true runtime privacy.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class BaseApiClient {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new API client instance.
|
|
11
|
+
*
|
|
12
|
+
* @param {DotCMSClientConfig} config - Configuration options for the DotCMS client
|
|
13
|
+
* @param {DotRequestOptions} requestOptions - Options for fetch requests including authorization headers
|
|
14
|
+
* @param {DotHttpClient} httpClient - HTTP client for making requests
|
|
15
|
+
*/
|
|
16
|
+
constructor(config: DotCMSClientConfig, requestOptions: DotRequestOptions | undefined, httpClient: DotHttpClient);
|
|
17
|
+
/**
|
|
18
|
+
* Gets the request options including authorization headers.
|
|
19
|
+
* @protected
|
|
20
|
+
*/
|
|
21
|
+
protected get requestOptions(): DotRequestOptions;
|
|
22
|
+
/**
|
|
23
|
+
* Gets the DotCMS client configuration.
|
|
24
|
+
* @protected
|
|
25
|
+
*/
|
|
26
|
+
protected get config(): DotCMSClientConfig;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the HTTP client for making requests.
|
|
29
|
+
* @protected
|
|
30
|
+
*/
|
|
31
|
+
protected get httpClient(): DotHttpClient;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the DotCMS URL from config.
|
|
34
|
+
* @protected
|
|
35
|
+
*/
|
|
36
|
+
protected get dotcmsUrl(): string;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the site ID from config.
|
|
39
|
+
* @protected
|
|
40
|
+
*/
|
|
41
|
+
protected get siteId(): string;
|
|
42
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DotCMSClientConfig } from '@dotcms/types';
|
|
2
|
+
import { AIClient } from './ai/ai-api';
|
|
2
3
|
import { Content } from './content/content-api';
|
|
3
4
|
import { NavigationClient } from './navigation/navigation-api';
|
|
4
5
|
import { PageClient } from './page/page-api';
|
|
@@ -22,6 +23,11 @@ declare class DotCMSClient {
|
|
|
22
23
|
* Client for navigation-related operations.
|
|
23
24
|
*/
|
|
24
25
|
nav: NavigationClient;
|
|
26
|
+
/**
|
|
27
|
+
* Client for AI-related operations.
|
|
28
|
+
* @experimental This client is experimental and may be subject to change.
|
|
29
|
+
*/
|
|
30
|
+
ai: AIClient;
|
|
25
31
|
/**
|
|
26
32
|
* Creates a new DotCMS client instance.
|
|
27
33
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DotHttpClient, DotRequestOptions, DotCMSClientConfig, DotErrorContent } from '@dotcms/types';
|
|
2
|
+
import { BaseApiClient } from '../../../base/base-api';
|
|
2
3
|
import { GetCollectionResponse, BuildQuery, SortBy, OnFullfilled, OnRejected } from '../../shared/types';
|
|
3
4
|
/**
|
|
4
5
|
* Creates a Builder to filter and fetch content from the content API for a specific content type.
|
|
@@ -7,7 +8,7 @@ import { GetCollectionResponse, BuildQuery, SortBy, OnFullfilled, OnRejected } f
|
|
|
7
8
|
* @class CollectionBuilder
|
|
8
9
|
* @template T Represents the type of the content type to fetch. Defaults to unknown.
|
|
9
10
|
*/
|
|
10
|
-
export declare class CollectionBuilder<T = unknown> {
|
|
11
|
+
export declare class CollectionBuilder<T = unknown> extends BaseApiClient {
|
|
11
12
|
#private;
|
|
12
13
|
/**
|
|
13
14
|
* Creates an instance of CollectionBuilder.
|
|
@@ -42,14 +43,6 @@ export declare class CollectionBuilder<T = unknown> {
|
|
|
42
43
|
* @memberof CollectionBuilder
|
|
43
44
|
*/
|
|
44
45
|
private get url();
|
|
45
|
-
/**
|
|
46
|
-
* Returns the site ID from the configuration.
|
|
47
|
-
*
|
|
48
|
-
* @readonly
|
|
49
|
-
* @private
|
|
50
|
-
* @memberof CollectionBuilder
|
|
51
|
-
*/
|
|
52
|
-
private get siteId();
|
|
53
46
|
/**
|
|
54
47
|
* Returns the current query built.
|
|
55
48
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DotRequestOptions, DotHttpClient, DotCMSClientConfig } from '@dotcms/types';
|
|
2
2
|
import { CollectionBuilder } from './builders/collection/collection';
|
|
3
|
+
import { BaseApiClient } from '../base/base-api';
|
|
3
4
|
/**
|
|
4
5
|
* Creates a builder to filter and fetch a collection of content items.
|
|
5
6
|
* @param contentType - The content type to retrieve.
|
|
@@ -49,12 +50,11 @@ import { CollectionBuilder } from './builders/collection/collection';
|
|
|
49
50
|
* });
|
|
50
51
|
* ```
|
|
51
52
|
*/
|
|
52
|
-
export declare class Content {
|
|
53
|
-
#private;
|
|
53
|
+
export declare class Content extends BaseApiClient {
|
|
54
54
|
/**
|
|
55
55
|
* Creates an instance of Content.
|
|
56
|
+
* @param {DotCMSClientConfig} config - Configuration options for the DotCMS client
|
|
56
57
|
* @param {DotRequestOptions} requestOptions - The options for the client request.
|
|
57
|
-
* @param {string} serverUrl - The server URL.
|
|
58
58
|
* @param {DotHttpClient} httpClient - HTTP client for making requests.
|
|
59
59
|
*/
|
|
60
60
|
constructor(config: DotCMSClientConfig, requestOptions: DotRequestOptions, httpClient: DotHttpClient);
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { DotCMSClientConfig, DotCMSNavigationRequestParams, DotRequestOptions, DotCMSNavigationItem, DotHttpClient } from '@dotcms/types';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { BaseApiClient } from '../base/base-api';
|
|
3
|
+
export declare class NavigationClient extends BaseApiClient {
|
|
4
4
|
private BASE_URL;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new NavigationClient instance.
|
|
7
|
+
* @param {DotCMSClientConfig} config - Configuration options for the DotCMS client
|
|
8
|
+
* @param {DotRequestOptions} requestOptions - Options for fetch requests including authorization headers
|
|
9
|
+
* @param {DotHttpClient} httpClient - HTTP client for making requests
|
|
10
|
+
*/
|
|
6
11
|
constructor(config: DotCMSClientConfig, requestOptions: DotRequestOptions, httpClient: DotHttpClient);
|
|
7
12
|
/**
|
|
8
13
|
* Retrieves information about the dotCMS file and folder tree.
|
|
@@ -1,29 +1,10 @@
|
|
|
1
1
|
import { DotCMSClientConfig, DotCMSPageRequestParams, DotCMSPageResponse, DotCMSExtendedPageResponse, DotCMSComposedPageResponse, DotHttpClient, DotRequestOptions } from '@dotcms/types';
|
|
2
|
+
import { BaseApiClient } from '../base/base-api';
|
|
2
3
|
/**
|
|
3
4
|
* Client for interacting with the DotCMS Page API.
|
|
4
5
|
* Provides methods to retrieve and manipulate pages.
|
|
5
6
|
*/
|
|
6
|
-
export declare class PageClient {
|
|
7
|
-
/**
|
|
8
|
-
* Request options including authorization headers.
|
|
9
|
-
* @private
|
|
10
|
-
*/
|
|
11
|
-
private requestOptions;
|
|
12
|
-
/**
|
|
13
|
-
* Site ID for page requests.
|
|
14
|
-
* @private
|
|
15
|
-
*/
|
|
16
|
-
private siteId;
|
|
17
|
-
/**
|
|
18
|
-
* DotCMS URL for page requests.
|
|
19
|
-
* @private
|
|
20
|
-
*/
|
|
21
|
-
private dotcmsUrl;
|
|
22
|
-
/**
|
|
23
|
-
* HTTP client for making requests.
|
|
24
|
-
* @private
|
|
25
|
-
*/
|
|
26
|
-
private httpClient;
|
|
7
|
+
export declare class PageClient extends BaseApiClient {
|
|
27
8
|
/**
|
|
28
9
|
* Creates a new PageClient instance.
|
|
29
10
|
*
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for AI search parameter mapping and processing
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Appends mapped parameters to URLSearchParams based on a mapping configuration.
|
|
6
|
+
* Only includes parameters that have defined values.
|
|
7
|
+
*
|
|
8
|
+
* @param searchParams - The URLSearchParams object to append to
|
|
9
|
+
* @param sourceObject - The source object containing values
|
|
10
|
+
* @param mapping - Array of [targetKey, sourceKey] pairs for parameter mapping, or [key] to use same key
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const params = new URLSearchParams();
|
|
14
|
+
* const query = { limit: 10, offset: 0, siteId: 'default', indexName: 'content' };
|
|
15
|
+
* const mapping = [
|
|
16
|
+
* ['searchLimit', 'limit'], // Maps limit -> searchLimit
|
|
17
|
+
* ['searchOffset', 'offset'], // Maps offset -> searchOffset
|
|
18
|
+
* ['site', 'siteId'], // Maps siteId -> site
|
|
19
|
+
* ['indexName'] // Uses indexName -> indexName (same key)
|
|
20
|
+
* ];
|
|
21
|
+
* appendMappedParams(params, query, mapping);
|
|
22
|
+
* // Results in: searchLimit=10&searchOffset=0&site=default&indexName=content
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function appendMappedParams<T extends object>(searchParams: URLSearchParams, sourceObject: T, mapping: Array<Array<string>>): void;
|