@dotcms/client 1.2.0 → 1.2.1-next.2
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 +418 -58
- package/index.esm.js +419 -59
- package/package.json +5 -5
- 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 +3 -10
- 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/client/page/utils.d.ts +1 -1
- package/src/lib/utils/params/utils.d.ts +25 -0
- package/index.esm.d.ts +0 -1
- package/internal.esm.d.ts +0 -1
- /package/{index.cjs.d.ts → index.d.ts} +0 -0
- /package/{internal.cjs.d.ts → internal.d.ts} +0 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { DotCMSClientConfig, DotRequestOptions, DotHttpClient, DotCMSAISearchParams, DotCMSBasicContentlet } from '@dotcms/types';
|
|
2
|
+
import { AISearch } from './search/search';
|
|
3
|
+
import { BaseApiClient } from '../base/base-api';
|
|
4
|
+
/**
|
|
5
|
+
* Client for interacting with the DotCMS AI API.
|
|
6
|
+
* Provides methods to interact with AI features.
|
|
7
|
+
* @experimental This client is experimental and may be subject to change.
|
|
8
|
+
*/
|
|
9
|
+
export declare class AIClient extends BaseApiClient {
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new AIClient instance.
|
|
12
|
+
*
|
|
13
|
+
* @param {DotCMSClientConfig} config - Configuration options for the DotCMS client
|
|
14
|
+
* @param {DotRequestOptions} requestOptions - Options for fetch requests including authorization headers
|
|
15
|
+
* @param {DotHttpClient} httpClient - HTTP client for making requests
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const aiClient = new AIClient(
|
|
19
|
+
* {
|
|
20
|
+
* dotcmsUrl: 'https://demo.dotcms.com',
|
|
21
|
+
* authToken: 'your-auth-token',
|
|
22
|
+
* siteId: 'demo.dotcms.com'
|
|
23
|
+
* },
|
|
24
|
+
* {
|
|
25
|
+
* headers: {
|
|
26
|
+
* Authorization: 'Bearer your-auth-token'
|
|
27
|
+
* }
|
|
28
|
+
* },
|
|
29
|
+
* httpClient
|
|
30
|
+
* );
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
constructor(config: DotCMSClientConfig, requestOptions: DotRequestOptions, httpClient: DotHttpClient);
|
|
34
|
+
/**
|
|
35
|
+
* Performs an AI-powered search.
|
|
36
|
+
*
|
|
37
|
+
* @param params - Search parameters with query and AI configuration
|
|
38
|
+
* @returns Promise with search results
|
|
39
|
+
* @experimental This method is experimental and may be subject to change.
|
|
40
|
+
* @template T - The type of the contentlet.
|
|
41
|
+
* @param prompt - The prompt for the search.
|
|
42
|
+
* @param indexName - The name of the index you want to search in.
|
|
43
|
+
* @param params - Search parameters with query and AI configuration.
|
|
44
|
+
* @example
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const response = await client.ai.search('machine learning articles', 'content_index', {
|
|
48
|
+
* query: {
|
|
49
|
+
* limit: 20,
|
|
50
|
+
* contentType: 'BlogPost',
|
|
51
|
+
* languageId: "1" // or 1
|
|
52
|
+
* },
|
|
53
|
+
* config: {
|
|
54
|
+
* threshold: 0.7
|
|
55
|
+
* }
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* client.ai.search('machine learning articles', 'content_index', {
|
|
61
|
+
* query: {
|
|
62
|
+
* limit: 20,
|
|
63
|
+
* contentType: 'BlogPost',
|
|
64
|
+
* languageId: "1" // or 1
|
|
65
|
+
* },
|
|
66
|
+
* config: {
|
|
67
|
+
* threshold: 0.7,
|
|
68
|
+
* distanceFunction: DISTANCE_FUNCTIONS.cosine
|
|
69
|
+
* }
|
|
70
|
+
* }).then((response) => {
|
|
71
|
+
* console.log(response.results);
|
|
72
|
+
* }).catch((error) => {
|
|
73
|
+
* console.error(error);
|
|
74
|
+
* });
|
|
75
|
+
*/
|
|
76
|
+
search<T extends DotCMSBasicContentlet>(prompt: string, indexName: string, params?: DotCMSAISearchParams): AISearch<T>;
|
|
77
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { DotCMSAISearchParams, DotCMSBasicContentlet, DotCMSClientConfig, DotErrorAISearch, DotHttpClient, DotRequestOptions, DotCMSAISearchResponse } from '@dotcms/types';
|
|
2
|
+
import { BaseApiClient } from '../../base/base-api';
|
|
3
|
+
import { OnFullfilled, OnRejected } from '../shared/types';
|
|
4
|
+
/**
|
|
5
|
+
* Class for executing AI searches.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of the contentlet.
|
|
8
|
+
* @param config - The configuration for the client.
|
|
9
|
+
* @param requestOptions - The request options for the client.
|
|
10
|
+
* @param httpClient - The HTTP client for the client.
|
|
11
|
+
* @param params - The parameters for the search.
|
|
12
|
+
* @param prompt - The prompt for the search.
|
|
13
|
+
*/
|
|
14
|
+
export declare class AISearch<T extends DotCMSBasicContentlet> extends BaseApiClient {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(config: DotCMSClientConfig, requestOptions: DotRequestOptions, httpClient: DotHttpClient, prompt: string, indexName: string, params?: DotCMSAISearchParams);
|
|
17
|
+
/**
|
|
18
|
+
* Executes the AI search and returns a promise with the search results.
|
|
19
|
+
*
|
|
20
|
+
* @param onfulfilled - Callback function to handle the search results.
|
|
21
|
+
* @param onrejected - Callback function to handle the search error.
|
|
22
|
+
* @returns Promise with the search results or the error.
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const results = await client.ai.search('machine learning articles', 'content_index', {
|
|
26
|
+
* query: {
|
|
27
|
+
* limit: 20,
|
|
28
|
+
* contentType: 'BlogPost',
|
|
29
|
+
* languageId: '1' // or 1
|
|
30
|
+
* },
|
|
31
|
+
* config: {
|
|
32
|
+
* threshold: 0.7
|
|
33
|
+
* }
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* client.ai.search('machine learning articles', 'content_index', {
|
|
39
|
+
* query: {
|
|
40
|
+
* limit: 20,
|
|
41
|
+
* contentType: 'BlogPost',
|
|
42
|
+
* languageId: '1' // or 1
|
|
43
|
+
* },
|
|
44
|
+
* config: {
|
|
45
|
+
* threshold: 0.7
|
|
46
|
+
* }
|
|
47
|
+
* }).then((results) => {
|
|
48
|
+
* console.log(results);
|
|
49
|
+
* }).catch((error) => {
|
|
50
|
+
* console.error(error);
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
then(onfulfilled?: OnFullfilled<T>, onrejected?: OnRejected): Promise<DotCMSAISearchResponse<T> | DotErrorAISearch>;
|
|
55
|
+
private fetch;
|
|
56
|
+
/**
|
|
57
|
+
* Builds URLSearchParams from the SDK interface, mapping to backend parameter names.
|
|
58
|
+
* Only includes parameters that have values.
|
|
59
|
+
*
|
|
60
|
+
* @param params - Search parameters with SDK naming
|
|
61
|
+
* @returns URLSearchParams with backend parameter names
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
private buildSearchParams;
|
|
65
|
+
}
|
|
@@ -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
|
*
|
|
@@ -256,7 +249,7 @@ export declare class CollectionBuilder<T = unknown> {
|
|
|
256
249
|
*
|
|
257
250
|
* @example
|
|
258
251
|
* // For draft content without site constraint:
|
|
259
|
-
* // Returns: "+contentType:Blog +languageId:1 +live:false"
|
|
252
|
+
* // Returns: "+contentType:Blog +languageId:1 +(live:false AND working:true AND deleted:false)"
|
|
260
253
|
*
|
|
261
254
|
* @example
|
|
262
255
|
* // For content with explicit exclusion of current site (site ID 123):
|
|
@@ -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;
|
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
package/internal.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/internal";
|
|
File without changes
|
|
File without changes
|