@c-rex/services 0.1.1 → 0.1.3
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/dist/index.d.mts +136 -6
- package/dist/index.d.ts +136 -6
- package/dist/index.js +366 -97
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +367 -98
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
import { CrexApi } from '@c-rex/core';
|
|
2
2
|
import { Method } from 'axios';
|
|
3
|
-
import { informationUnitsRenditions, DirectoryNodes,
|
|
3
|
+
import { informationUnitsRenditions, DirectoryNodes, DirectoryNodesResponse, informationUnitsResponse, informationUnitsItems, LanguageAndCountries } from '@c-rex/interfaces';
|
|
4
4
|
|
|
5
5
|
type QueryParams = {
|
|
6
6
|
key: string;
|
|
7
7
|
value: string;
|
|
8
8
|
};
|
|
9
|
+
type FileRenditionType = {
|
|
10
|
+
format: string;
|
|
11
|
+
link: string;
|
|
12
|
+
};
|
|
9
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Base service class that provides common functionality for API interactions.
|
|
16
|
+
* All specific service classes extend this base class.
|
|
17
|
+
*/
|
|
10
18
|
declare class BaseService {
|
|
11
19
|
protected api: CrexApi;
|
|
12
20
|
private endpoint;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new instance of BaseService.
|
|
23
|
+
*
|
|
24
|
+
* @param endpoint - The API endpoint URL for this service
|
|
25
|
+
*/
|
|
13
26
|
constructor(endpoint: string);
|
|
27
|
+
/**
|
|
28
|
+
* Makes an API request to the specified endpoint.
|
|
29
|
+
*
|
|
30
|
+
* @param options - Request configuration options
|
|
31
|
+
* @param options.path - Optional path to append to the endpoint
|
|
32
|
+
* @param options.params - Optional query parameters to include in the request
|
|
33
|
+
* @param options.method - HTTP method to use (defaults to 'get')
|
|
34
|
+
* @param options.transformer - Optional function to transform the response data
|
|
35
|
+
* @returns The response data, optionally transformed
|
|
36
|
+
* @throws Error if the API request fails
|
|
37
|
+
*/
|
|
14
38
|
protected request<T>({ path, method, params, headers, transformer, }: {
|
|
15
39
|
path?: string;
|
|
16
40
|
method?: Method;
|
|
@@ -20,41 +44,147 @@ declare class BaseService {
|
|
|
20
44
|
}): Promise<T>;
|
|
21
45
|
}
|
|
22
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Service for interacting with renditions in the API.
|
|
49
|
+
* Provides methods to retrieve and process different types of renditions.
|
|
50
|
+
*/
|
|
23
51
|
declare class RenditionsService extends BaseService {
|
|
24
52
|
constructor();
|
|
25
|
-
|
|
26
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves the HTML rendition from a list of renditions.
|
|
55
|
+
* Filters for renditions with format 'application/xhtml+xml' and rel 'view'.
|
|
56
|
+
*
|
|
57
|
+
* @param renditions - Array of rendition objects to process
|
|
58
|
+
* @returns A promise that resolves to the HTML content as a string, or empty string if no suitable rendition is found
|
|
59
|
+
* @throws Error if the API request fails
|
|
60
|
+
*/
|
|
61
|
+
getHTMLRendition({ renditions }: {
|
|
62
|
+
renditions: informationUnitsRenditions[];
|
|
63
|
+
}): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Processes a list of renditions and categorizes them into files to download and files to open.
|
|
66
|
+
* Excludes renditions with formats 'application/xhtml+xml', 'application/json', and 'application/llm+xml'.
|
|
67
|
+
*
|
|
68
|
+
* @param renditions - Array of rendition objects to process
|
|
69
|
+
* @returns An object containing arrays of file renditions categorized as 'filesToDownload' and 'filesToOpen'
|
|
70
|
+
*/
|
|
71
|
+
getFileRenditions: ({ renditions }: {
|
|
72
|
+
renditions: informationUnitsRenditions[];
|
|
73
|
+
}) => {
|
|
74
|
+
filesToDownload: FileRenditionType[];
|
|
75
|
+
filesToOpen: FileRenditionType[];
|
|
76
|
+
};
|
|
27
77
|
}
|
|
28
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Service for interacting with directory nodes in the API.
|
|
81
|
+
* Provides methods to retrieve directory node information.
|
|
82
|
+
*/
|
|
29
83
|
declare class DirectoryNodesService extends BaseService {
|
|
30
84
|
constructor();
|
|
85
|
+
/**
|
|
86
|
+
* Retrieves a specific directory node by its ID.
|
|
87
|
+
*
|
|
88
|
+
* @param id - The unique identifier of the directory node
|
|
89
|
+
* @returns A promise that resolves to the directory node data
|
|
90
|
+
* @throws Error if the API request fails
|
|
91
|
+
*/
|
|
31
92
|
getItem(id: string): Promise<DirectoryNodes>;
|
|
93
|
+
/**
|
|
94
|
+
* Retrieves a list of directory nodes based on specified filters.
|
|
95
|
+
*
|
|
96
|
+
* @param options - Options for filtering the directory nodes list
|
|
97
|
+
* @param options.filters - Optional array of filter strings to apply
|
|
98
|
+
* @returns A promise that resolves to the directory nodes response
|
|
99
|
+
* @throws Error if the API request fails
|
|
100
|
+
*/
|
|
101
|
+
getList({ filters, }: {
|
|
102
|
+
filters?: string[];
|
|
103
|
+
}): Promise<DirectoryNodesResponse>;
|
|
32
104
|
}
|
|
33
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Service for interacting with document types in the API.
|
|
108
|
+
* Provides methods to retrieve document type information.
|
|
109
|
+
*/
|
|
34
110
|
declare class DocumentTypesService extends BaseService {
|
|
35
111
|
constructor();
|
|
112
|
+
/**
|
|
113
|
+
* Retrieves document type labels for the specified fields.
|
|
114
|
+
* The labels are restricted to English language (EN-us).
|
|
115
|
+
*
|
|
116
|
+
* @param fields - Array of field names to retrieve labels for
|
|
117
|
+
* @returns A promise that resolves to an array of label strings
|
|
118
|
+
* @throws Error if the API request fails
|
|
119
|
+
*/
|
|
36
120
|
getLabels(fields: string[]): Promise<string[]>;
|
|
37
121
|
}
|
|
38
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Service for interacting with information units in the API.
|
|
125
|
+
* Provides methods to retrieve and search information units.
|
|
126
|
+
*/
|
|
39
127
|
declare class InformationUnitsService extends BaseService {
|
|
40
128
|
constructor();
|
|
129
|
+
/**
|
|
130
|
+
* Retrieves a list of information units based on specified criteria.
|
|
131
|
+
*
|
|
132
|
+
* @param options - Options for filtering and paginating the information units list
|
|
133
|
+
* @param options.queries - Optional search query string
|
|
134
|
+
* @param options.page - Optional page number for pagination (defaults to 1)
|
|
135
|
+
* @param options.fields - Optional array of fields to include in the response
|
|
136
|
+
* @param options.filters - Optional array of filter strings to apply
|
|
137
|
+
* @param options.languages - Optional array of language codes to filter by
|
|
138
|
+
* @returns A promise that resolves to the information units response
|
|
139
|
+
* @throws Error if the API request fails
|
|
140
|
+
*/
|
|
41
141
|
getList({ queries, page, fields, filters, languages }: {
|
|
42
142
|
queries?: string;
|
|
43
143
|
page?: number;
|
|
44
144
|
filters?: string[];
|
|
45
145
|
fields?: string[];
|
|
46
146
|
languages?: string[];
|
|
47
|
-
}): Promise<
|
|
147
|
+
}): Promise<informationUnitsResponse>;
|
|
148
|
+
/**
|
|
149
|
+
* Retrieves a specific information unit by its ID.
|
|
150
|
+
* Includes renditions, directory nodes, version information, titles, languages, and labels.
|
|
151
|
+
*
|
|
152
|
+
* @param options - Options for retrieving the information unit
|
|
153
|
+
* @param options.id - The unique identifier of the information unit
|
|
154
|
+
* @returns A promise that resolves to the information unit data
|
|
155
|
+
* @throws Error if the API request fails
|
|
156
|
+
*/
|
|
48
157
|
getItem({ id }: {
|
|
49
158
|
id: string;
|
|
50
159
|
}): Promise<informationUnitsItems>;
|
|
51
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Retrieves autocomplete suggestions based on a query prefix.
|
|
162
|
+
*
|
|
163
|
+
* @param options - Options for retrieving suggestions
|
|
164
|
+
* @param options.query - The query prefix to get suggestions for
|
|
165
|
+
* @param options.language - The language of the suggestions
|
|
166
|
+
* @returns A promise that resolves to an array of suggestion strings
|
|
167
|
+
* @throws Error if the API request fails
|
|
168
|
+
*/
|
|
169
|
+
getSuggestions({ query, language }: {
|
|
52
170
|
query: string;
|
|
171
|
+
language: string;
|
|
53
172
|
}): Promise<string[]>;
|
|
54
173
|
}
|
|
55
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Service for interacting with language-related functionality in the API.
|
|
177
|
+
* Provides methods to retrieve language and country information.
|
|
178
|
+
*/
|
|
56
179
|
declare class LanguageService extends BaseService {
|
|
57
|
-
constructor(
|
|
180
|
+
constructor();
|
|
181
|
+
/**
|
|
182
|
+
* Retrieves a list of available languages and their associated countries.
|
|
183
|
+
* Transforms the API response to include language code, country code, and original value.
|
|
184
|
+
*
|
|
185
|
+
* @returns A promise that resolves to an array of language and country objects
|
|
186
|
+
* @throws Error if the API request fails
|
|
187
|
+
*/
|
|
58
188
|
getLanguagesAndCountries(): Promise<LanguageAndCountries[]>;
|
|
59
189
|
}
|
|
60
190
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
import { CrexApi } from '@c-rex/core';
|
|
2
2
|
import { Method } from 'axios';
|
|
3
|
-
import { informationUnitsRenditions, DirectoryNodes,
|
|
3
|
+
import { informationUnitsRenditions, DirectoryNodes, DirectoryNodesResponse, informationUnitsResponse, informationUnitsItems, LanguageAndCountries } from '@c-rex/interfaces';
|
|
4
4
|
|
|
5
5
|
type QueryParams = {
|
|
6
6
|
key: string;
|
|
7
7
|
value: string;
|
|
8
8
|
};
|
|
9
|
+
type FileRenditionType = {
|
|
10
|
+
format: string;
|
|
11
|
+
link: string;
|
|
12
|
+
};
|
|
9
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Base service class that provides common functionality for API interactions.
|
|
16
|
+
* All specific service classes extend this base class.
|
|
17
|
+
*/
|
|
10
18
|
declare class BaseService {
|
|
11
19
|
protected api: CrexApi;
|
|
12
20
|
private endpoint;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new instance of BaseService.
|
|
23
|
+
*
|
|
24
|
+
* @param endpoint - The API endpoint URL for this service
|
|
25
|
+
*/
|
|
13
26
|
constructor(endpoint: string);
|
|
27
|
+
/**
|
|
28
|
+
* Makes an API request to the specified endpoint.
|
|
29
|
+
*
|
|
30
|
+
* @param options - Request configuration options
|
|
31
|
+
* @param options.path - Optional path to append to the endpoint
|
|
32
|
+
* @param options.params - Optional query parameters to include in the request
|
|
33
|
+
* @param options.method - HTTP method to use (defaults to 'get')
|
|
34
|
+
* @param options.transformer - Optional function to transform the response data
|
|
35
|
+
* @returns The response data, optionally transformed
|
|
36
|
+
* @throws Error if the API request fails
|
|
37
|
+
*/
|
|
14
38
|
protected request<T>({ path, method, params, headers, transformer, }: {
|
|
15
39
|
path?: string;
|
|
16
40
|
method?: Method;
|
|
@@ -20,41 +44,147 @@ declare class BaseService {
|
|
|
20
44
|
}): Promise<T>;
|
|
21
45
|
}
|
|
22
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Service for interacting with renditions in the API.
|
|
49
|
+
* Provides methods to retrieve and process different types of renditions.
|
|
50
|
+
*/
|
|
23
51
|
declare class RenditionsService extends BaseService {
|
|
24
52
|
constructor();
|
|
25
|
-
|
|
26
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves the HTML rendition from a list of renditions.
|
|
55
|
+
* Filters for renditions with format 'application/xhtml+xml' and rel 'view'.
|
|
56
|
+
*
|
|
57
|
+
* @param renditions - Array of rendition objects to process
|
|
58
|
+
* @returns A promise that resolves to the HTML content as a string, or empty string if no suitable rendition is found
|
|
59
|
+
* @throws Error if the API request fails
|
|
60
|
+
*/
|
|
61
|
+
getHTMLRendition({ renditions }: {
|
|
62
|
+
renditions: informationUnitsRenditions[];
|
|
63
|
+
}): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Processes a list of renditions and categorizes them into files to download and files to open.
|
|
66
|
+
* Excludes renditions with formats 'application/xhtml+xml', 'application/json', and 'application/llm+xml'.
|
|
67
|
+
*
|
|
68
|
+
* @param renditions - Array of rendition objects to process
|
|
69
|
+
* @returns An object containing arrays of file renditions categorized as 'filesToDownload' and 'filesToOpen'
|
|
70
|
+
*/
|
|
71
|
+
getFileRenditions: ({ renditions }: {
|
|
72
|
+
renditions: informationUnitsRenditions[];
|
|
73
|
+
}) => {
|
|
74
|
+
filesToDownload: FileRenditionType[];
|
|
75
|
+
filesToOpen: FileRenditionType[];
|
|
76
|
+
};
|
|
27
77
|
}
|
|
28
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Service for interacting with directory nodes in the API.
|
|
81
|
+
* Provides methods to retrieve directory node information.
|
|
82
|
+
*/
|
|
29
83
|
declare class DirectoryNodesService extends BaseService {
|
|
30
84
|
constructor();
|
|
85
|
+
/**
|
|
86
|
+
* Retrieves a specific directory node by its ID.
|
|
87
|
+
*
|
|
88
|
+
* @param id - The unique identifier of the directory node
|
|
89
|
+
* @returns A promise that resolves to the directory node data
|
|
90
|
+
* @throws Error if the API request fails
|
|
91
|
+
*/
|
|
31
92
|
getItem(id: string): Promise<DirectoryNodes>;
|
|
93
|
+
/**
|
|
94
|
+
* Retrieves a list of directory nodes based on specified filters.
|
|
95
|
+
*
|
|
96
|
+
* @param options - Options for filtering the directory nodes list
|
|
97
|
+
* @param options.filters - Optional array of filter strings to apply
|
|
98
|
+
* @returns A promise that resolves to the directory nodes response
|
|
99
|
+
* @throws Error if the API request fails
|
|
100
|
+
*/
|
|
101
|
+
getList({ filters, }: {
|
|
102
|
+
filters?: string[];
|
|
103
|
+
}): Promise<DirectoryNodesResponse>;
|
|
32
104
|
}
|
|
33
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Service for interacting with document types in the API.
|
|
108
|
+
* Provides methods to retrieve document type information.
|
|
109
|
+
*/
|
|
34
110
|
declare class DocumentTypesService extends BaseService {
|
|
35
111
|
constructor();
|
|
112
|
+
/**
|
|
113
|
+
* Retrieves document type labels for the specified fields.
|
|
114
|
+
* The labels are restricted to English language (EN-us).
|
|
115
|
+
*
|
|
116
|
+
* @param fields - Array of field names to retrieve labels for
|
|
117
|
+
* @returns A promise that resolves to an array of label strings
|
|
118
|
+
* @throws Error if the API request fails
|
|
119
|
+
*/
|
|
36
120
|
getLabels(fields: string[]): Promise<string[]>;
|
|
37
121
|
}
|
|
38
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Service for interacting with information units in the API.
|
|
125
|
+
* Provides methods to retrieve and search information units.
|
|
126
|
+
*/
|
|
39
127
|
declare class InformationUnitsService extends BaseService {
|
|
40
128
|
constructor();
|
|
129
|
+
/**
|
|
130
|
+
* Retrieves a list of information units based on specified criteria.
|
|
131
|
+
*
|
|
132
|
+
* @param options - Options for filtering and paginating the information units list
|
|
133
|
+
* @param options.queries - Optional search query string
|
|
134
|
+
* @param options.page - Optional page number for pagination (defaults to 1)
|
|
135
|
+
* @param options.fields - Optional array of fields to include in the response
|
|
136
|
+
* @param options.filters - Optional array of filter strings to apply
|
|
137
|
+
* @param options.languages - Optional array of language codes to filter by
|
|
138
|
+
* @returns A promise that resolves to the information units response
|
|
139
|
+
* @throws Error if the API request fails
|
|
140
|
+
*/
|
|
41
141
|
getList({ queries, page, fields, filters, languages }: {
|
|
42
142
|
queries?: string;
|
|
43
143
|
page?: number;
|
|
44
144
|
filters?: string[];
|
|
45
145
|
fields?: string[];
|
|
46
146
|
languages?: string[];
|
|
47
|
-
}): Promise<
|
|
147
|
+
}): Promise<informationUnitsResponse>;
|
|
148
|
+
/**
|
|
149
|
+
* Retrieves a specific information unit by its ID.
|
|
150
|
+
* Includes renditions, directory nodes, version information, titles, languages, and labels.
|
|
151
|
+
*
|
|
152
|
+
* @param options - Options for retrieving the information unit
|
|
153
|
+
* @param options.id - The unique identifier of the information unit
|
|
154
|
+
* @returns A promise that resolves to the information unit data
|
|
155
|
+
* @throws Error if the API request fails
|
|
156
|
+
*/
|
|
48
157
|
getItem({ id }: {
|
|
49
158
|
id: string;
|
|
50
159
|
}): Promise<informationUnitsItems>;
|
|
51
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Retrieves autocomplete suggestions based on a query prefix.
|
|
162
|
+
*
|
|
163
|
+
* @param options - Options for retrieving suggestions
|
|
164
|
+
* @param options.query - The query prefix to get suggestions for
|
|
165
|
+
* @param options.language - The language of the suggestions
|
|
166
|
+
* @returns A promise that resolves to an array of suggestion strings
|
|
167
|
+
* @throws Error if the API request fails
|
|
168
|
+
*/
|
|
169
|
+
getSuggestions({ query, language }: {
|
|
52
170
|
query: string;
|
|
171
|
+
language: string;
|
|
53
172
|
}): Promise<string[]>;
|
|
54
173
|
}
|
|
55
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Service for interacting with language-related functionality in the API.
|
|
177
|
+
* Provides methods to retrieve language and country information.
|
|
178
|
+
*/
|
|
56
179
|
declare class LanguageService extends BaseService {
|
|
57
|
-
constructor(
|
|
180
|
+
constructor();
|
|
181
|
+
/**
|
|
182
|
+
* Retrieves a list of available languages and their associated countries.
|
|
183
|
+
* Transforms the API response to include language code, country code, and original value.
|
|
184
|
+
*
|
|
185
|
+
* @returns A promise that resolves to an array of language and country objects
|
|
186
|
+
* @throws Error if the API request fails
|
|
187
|
+
*/
|
|
58
188
|
getLanguagesAndCountries(): Promise<LanguageAndCountries[]>;
|
|
59
189
|
}
|
|
60
190
|
|