cobrili-client 1.0.1 → 1.0.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/README.md CHANGED
@@ -1,15 +1,30 @@
1
1
  # Cobrili-Client
2
2
 
3
- Modern TypeScript API client for Cobrili REST API. Works in both Browser and Node.js environments.
3
+ Modern TypeScript API client for the [Cobrili™](https://acolada.de/produkte/cobrili-2/) Content Delivery System by [Acolada GmbH](https://acolada.de/).
4
+
5
+ Developed by [dictaJet Ingenieurgesellschaft mbH](https://www.dictajet.de/).
6
+
7
+ ## About Cobrili
8
+
9
+ Cobrili™ is an HTML5-based Content Delivery System for online help and e-learning content. Key features include:
10
+
11
+ - Online and offline availability
12
+ - Faceted search and terminology-based search functions
13
+ - Multi-language and multi-variant content delivery
14
+ - Flexible metadata filtering
15
+ - Rich API for integration into software applications
16
+
17
+ This client library provides a TypeScript/JavaScript interface to the Cobrili REST API.
4
18
 
5
19
  ## Features
6
20
 
7
21
  - ✅ Full TypeScript support with type definitions
8
22
  - ✅ Registry-driven API with all methods auto-generated
9
23
  - ✅ Works in Browser and Node.js
10
- - ✅ JSON-based communication
24
+ - ✅ XML-over-JSON communication (handled internally)
11
25
  - ✅ Promise/async-await API
12
26
  - ✅ Configurable base URL and headers
27
+ - ✅ Explicit session initialization
13
28
 
14
29
  ## Installation
15
30
 
@@ -17,9 +32,7 @@ Modern TypeScript API client for Cobrili REST API. Works in both Browser and Nod
17
32
  npm install cobrili-client
18
33
  ```
19
34
 
20
- ## Usage
21
-
22
- ### ES6 Import (Recommended)
35
+ ## Quick Start
23
36
 
24
37
  ```typescript
25
38
  import { createCobriliClient } from 'cobrili-client';
@@ -32,27 +45,123 @@ const client = createCobriliClient({
32
45
  }
33
46
  });
34
47
 
35
- // Login
36
- const loginResult = await client.login({ loginUser: { username: 'user', password: 'pass' } });
48
+ // Initialize session (required before making API calls)
49
+ await client.init();
37
50
 
38
- // Get navigation
39
- const nav = await client.getNavigationWithMetaData({ currentNavigationID: 0 });
51
+ // Now you can make API calls
52
+ const helpsets = await client.getAllHelpsets({
53
+ masterHelpSetApplicationIdentifier: 'MyApp',
54
+ withMetadata: true
55
+ });
40
56
 
41
- // Get content
42
- const content = await client.getContent({ topicID: 12345 });
57
+ if (helpsets.data) {
58
+ console.log('Helpsets:', helpsets.data.helpsetInfos);
59
+ } else {
60
+ console.error('Error:', helpsets.error.message);
61
+ }
43
62
  ```
44
63
 
45
- ### CommonJS
64
+ ## Usage
65
+
66
+ ### Creating the Client
46
67
 
47
- ```javascript
48
- const { createCobriliClient } = require('cobrili-client');
68
+ ```typescript
69
+ import { createCobriliClient } from 'cobrili-client';
49
70
 
50
- const client = createCobriliClient({ baseUrl: 'http://localhost:5000' });
71
+ const client = createCobriliClient({
72
+ baseUrl: 'http://localhost:5000', // Backend server URL
73
+ endpoint: '/api/cobrili', // API endpoint path
74
+ timeout: 30000, // Request timeout in ms
75
+ headers: {}, // Custom headers
76
+ debug: false // Enable debug logging
77
+ });
78
+ ```
79
+
80
+ ### Initialization (Required)
81
+
82
+ The client must be initialized before making API calls. This creates a session with the backend:
83
+
84
+ ```typescript
85
+ // Initialize the session
86
+ await client.init();
87
+
88
+ // Check if initialized
89
+ if (client.isInitialized()) {
90
+ // Ready to make API calls
91
+ }
92
+ ```
93
+
94
+ ### Typical Workflow
95
+
96
+ ```typescript
97
+ // 1. Initialize
98
+ await client.init();
99
+
100
+ // 2. Activate a master helpset
101
+ const masterResult = await client.switchMasterHelpSet({
102
+ masterHelpSetApplicationIdentifier: 'Convotherm',
103
+ initActiveHelpset: true
104
+ });
105
+
106
+ // 3. Get all helpsets
107
+ const helpsetsResult = await client.getAllHelpsets({
108
+ masterHelpSetApplicationIdentifier: 'Convotherm',
109
+ withMetadata: true
110
+ });
111
+
112
+ // 4. Load a specific helpset
113
+ await client.loadActiveHelpset({ helpsetID: 123 });
114
+
115
+ // 5. Get navigation tree
116
+ const navResult = await client.getNavigationWithMetaData({
117
+ currentNavigationID: 0,
118
+ wantedMetaKeys: [],
119
+ useHelpsetMetadataFallback: false
120
+ });
121
+
122
+ // 6. Get topic content
123
+ const contentResult = await client.getContent({ topicID: 456 });
124
+ if (contentResult.data) {
125
+ // contentResult.data.content contains base64-encoded HTML
126
+ }
127
+ ```
128
+
129
+ ## Response Format
130
+
131
+ All API methods return a discriminated union type:
132
+
133
+ ```typescript
134
+ type ApiResponse<T> =
135
+ | { data: T; error?: never } // Success
136
+ | { data?: never; error: CobriliError }; // Error
137
+
138
+ interface CobriliError {
139
+ code: string;
140
+ message: string;
141
+ details?: any;
142
+ }
143
+ ```
144
+
145
+ ### Handling Responses
146
+
147
+ ```typescript
148
+ const result = await client.getAllHelpsets({
149
+ masterHelpSetApplicationIdentifier: 'MyApp',
150
+ withMetadata: true
151
+ });
152
+
153
+ if (result.error) {
154
+ // Handle error
155
+ console.error(`${result.error.code}: ${result.error.message}`);
156
+ } else {
157
+ // Use data
158
+ const helpsets = result.data.helpsetInfos;
159
+ }
51
160
  ```
52
161
 
53
162
  ## API Methods
54
163
 
55
- All methods are auto-generated from the API registry. Import `API_METHODS` for the full list:
164
+ All methods are auto-generated from the API registry:
56
165
 
57
166
  ```typescript
58
167
  import { API_METHODS } from 'cobrili-client';
@@ -61,59 +170,66 @@ import { API_METHODS } from 'cobrili-client';
61
170
  console.log(Object.keys(API_METHODS));
62
171
  ```
63
172
 
64
- ### Authentication
65
- - `login({ loginUser: { username, password } })` - Login with credentials
173
+ ### Session & Authentication
174
+ - `init()` - Initialize session (required first)
175
+ - `isInitialized()` - Check if session is active
176
+ - `login({ loginUser })` - Login with credentials
66
177
  - `logout({})` - Logout
67
178
 
68
- ### Navigation
69
- - `getNavigationWithMetaData({ currentNavigationID })` - Get navigation tree
70
- - `navigateToTopic({ topicID, navigationID })` - Navigate to topic
71
-
72
- ### Content
73
- - `getContent({ topicID })` - Get topic content
74
- - `getTopicForExternalId({ externalIdForTopic, externalIdForHelpset })` - Find topic
179
+ ### Master Helpset
180
+ - `switchMasterHelpSet({ masterHelpSetApplicationIdentifier, initActiveHelpset })` - Activate master
181
+ - `getAllHelpsets({ masterHelpSetApplicationIdentifier, withMetadata })` - Get all helpsets
182
+ - `getAllowedMetaKeysForMasterhelpset({ masterHelpSetApplicationIdentifier })` - Get metadata keys
75
183
 
76
184
  ### Helpset
77
- - `getAllHelpsets({ masterHelpSetApplicationIdentifier, withMetadata })` - Get all helpsets
78
- - `getHomeTopicId({ helpsetID })` - Get home topic
79
185
  - `loadActiveHelpset({ helpsetID })` - Load a helpset
186
+ - `getHelpsetInfoForActiveHelpset({})` - Get active helpset info
187
+ - `getHomeTopicId({ helpsetID })` - Get home topic
80
188
 
81
- ## License
189
+ ### Navigation
190
+ - `getNavigationWithMetaData({ currentNavigationID, wantedMetaKeys })` - Get navigation tree
191
+ - `navigateToTopic({ topicID, navigationID })` - Navigate to topic
82
192
 
83
- MIT
84
- - `historyBack(steps?)` / `historyForward(steps?)` - Navigate history
85
- - `getBookmarkList()` - Get bookmarks
86
- - `addBookmark(topicID, navigationID, title)` - Add bookmark
193
+ ### Content
194
+ - `getContent({ topicID })` - Get topic content (base64-encoded)
195
+ - `getTopicForExternalId({ externalIdForTopic, externalIdForHelpset })` - Find topic by external ID
196
+ - `getMetaValuesForTopics({ externalTopicIDs, wantedMetaKeys })` - Get metadata for topics
87
197
 
88
198
  ### Metadata
89
- - `getUsedMetaValues(metaKey)` - Get meta values
90
- - `getMetaValueForTopic(metaKey, topicID)` - Get meta for topic
91
- - `getMetaKeyWhichRepresentsLanguage()` - Get language key
199
+ - `getPossibleMetaValues({ metaKey })` - Get possible values for a meta key
200
+ - `getMetaValueForTopic({ metaKey, topicID })` - Get meta value for topic
201
+
202
+ ### History & Bookmarks
203
+ - `historyBack({ steps })` / `historyForward({ steps })` - Navigate history
204
+ - `getBookmarkList({})` - Get bookmarks
205
+ - `addBookmark({ topicID, navigationID, title })` - Add bookmark
92
206
 
93
207
  ### System
94
- - `getCurrentCobriliVersion()` - Get version
95
- - `getConfigurationData()` - Get configuration
96
- - `clearStaticCaches()` - Clear caches
97
- - `healthCheck()` - Health check
208
+ - `getCurrentCobriliVersion({})` - Get version
209
+ - `getConfigurationData({})` - Get configuration
210
+ - `clearStaticCaches({})` - Clear caches
98
211
 
99
- ## Response Format
212
+ ## CommonJS
100
213
 
101
- ```typescript
102
- interface ApiResponse<T> {
103
- success: boolean;
104
- data: T;
105
- status: number;
106
- message?: string;
107
- }
214
+ ```javascript
215
+ const { createCobriliClient } = require('cobrili-client');
216
+
217
+ const client = createCobriliClient({ baseUrl: 'http://localhost:5000' });
218
+ await client.init();
108
219
  ```
109
220
 
110
- ## Development
221
+ ## Links
111
222
 
112
- ```bash
113
- npm install
114
- npm run build
115
- ```
223
+ - [Cobrili™ Product Page](https://acolada.de/produkte/cobrili-2/) - Acolada GmbH
224
+ - [dictaJet](https://www.dictajet.de/) - Client developer
225
+ - [npm Package](https://www.npmjs.com/package/cobrili-client)
116
226
 
117
227
  ## License
118
228
 
119
229
  MIT
230
+
231
+ ---
232
+
233
+ **Cobrili™** is a trademark of [Acolada GmbH](https://acolada.de/), Nürnberg, Germany.
234
+
235
+ **cobrili-client** is developed by [dictaJet Ingenieurgesellschaft mbH](https://www.dictajet.de/), Wiesbaden, Germany.