cobrili-client 1.0.2 → 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.
Files changed (2) hide show
  1. package/README.md +165 -69
  2. package/package.json +1 -1
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,108 +45,191 @@ 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
+ });
51
78
  ```
52
79
 
53
- ## API Methods
80
+ ### Initialization (Required)
54
81
 
55
- All methods are auto-generated from the API registry. Import `API_METHODS` for the full list:
82
+ The client must be initialized before making API calls. This creates a session with the backend:
56
83
 
57
84
  ```typescript
58
- import { API_METHODS } from 'cobrili-client';
85
+ // Initialize the session
86
+ await client.init();
59
87
 
60
- // List all available methods
61
- console.log(Object.keys(API_METHODS));
88
+ // Check if initialized
89
+ if (client.isInitialized()) {
90
+ // Ready to make API calls
91
+ }
62
92
  ```
63
93
 
64
- ### Authentication
65
- - `login({ loginUser: { username, password } })` - Login with credentials
66
- - `logout({})` - Logout
94
+ ### Typical Workflow
67
95
 
68
- ### Navigation
69
- - `getNavigationWithMetaData({ currentNavigationID })` - Get navigation tree
70
- - `navigateToTopic({ topicID, navigationID })` - Navigate to topic
96
+ ```typescript
97
+ // 1. Initialize
98
+ await client.init();
71
99
 
72
- ### Content
73
- - `getContent({ topicID })` - Get topic content
74
- - `getTopicForExternalId({ externalIdForTopic, externalIdForHelpset })` - Find topic
100
+ // 2. Activate a master helpset
101
+ const masterResult = await client.switchMasterHelpSet({
102
+ masterHelpSetApplicationIdentifier: 'Convotherm',
103
+ initActiveHelpset: true
104
+ });
75
105
 
76
- ### Helpset
77
- - `getAllHelpsets({ masterHelpSetApplicationIdentifier, withMetadata })` - Get all helpsets
78
- - `getHomeTopicId({ helpsetID })` - Get home topic
79
- - `loadActiveHelpset({ helpsetID })` - Load a helpset
106
+ // 3. Get all helpsets
107
+ const helpsetsResult = await client.getAllHelpsets({
108
+ masterHelpSetApplicationIdentifier: 'Convotherm',
109
+ withMetadata: true
110
+ });
80
111
 
81
- ### Bookmarks
82
- - `historyBack(steps?)` / `historyForward(steps?)` - Navigate history
83
- - `getBookmarkList()` - Get bookmarks
84
- - `addBookmark(topicID, navigationID, title)` - Add bookmark
112
+ // 4. Load a specific helpset
113
+ await client.loadActiveHelpset({ helpsetID: 123 });
85
114
 
86
- ### Metadata
87
- - `getUsedMetaValues(metaKey)` - Get meta values
88
- - `getMetaValueForTopic(metaKey, topicID)` - Get meta for topic
89
- - `getMetaKeyWhichRepresentsLanguage()` - Get language key
115
+ // 5. Get navigation tree
116
+ const navResult = await client.getNavigationWithMetaData({
117
+ currentNavigationID: 0,
118
+ wantedMetaKeys: [],
119
+ useHelpsetMetadataFallback: false
120
+ });
90
121
 
91
- ### System
92
- - `getCurrentCobriliVersion()` - Get version
93
- - `getConfigurationData()` - Get configuration
94
- - `clearStaticCaches()` - Clear caches
95
- - `healthCheck()` - Health check
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
+ ```
96
128
 
97
129
  ## Response Format
98
130
 
131
+ All API methods return a discriminated union type:
132
+
99
133
  ```typescript
100
- interface ApiResponse<T> {
101
- success: boolean;
102
- data: T;
103
- status: number;
104
- message?: string;
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;
105
142
  }
106
143
  ```
107
144
 
108
- ## Development
145
+ ### Handling Responses
109
146
 
110
- ```bash
111
- # Install dependencies
112
- npm install
147
+ ```typescript
148
+ const result = await client.getAllHelpsets({
149
+ masterHelpSetApplicationIdentifier: 'MyApp',
150
+ withMetadata: true
151
+ });
113
152
 
114
- # Build the package
115
- npm run build
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
+ }
160
+ ```
116
161
 
117
- # Watch mode for development
118
- npm run dev
162
+ ## API Methods
119
163
 
120
- # Run tests
121
- npm run test
164
+ All methods are auto-generated from the API registry:
122
165
 
123
- # Type check
124
- npm run type-check
166
+ ```typescript
167
+ import { API_METHODS } from 'cobrili-client';
125
168
 
126
- # Lint
127
- npm run lint
169
+ // List all available methods
170
+ console.log(Object.keys(API_METHODS));
128
171
  ```
129
172
 
130
- ## Publishing
173
+ ### Session & Authentication
174
+ - `init()` - Initialize session (required first)
175
+ - `isInitialized()` - Check if session is active
176
+ - `login({ loginUser })` - Login with credentials
177
+ - `logout({})` - Logout
131
178
 
132
- ```bash
133
- npm run build
134
- npm publish
179
+ ### Master Helpset
180
+ - `switchMasterHelpSet({ masterHelpSetApplicationIdentifier, initActiveHelpset })` - Activate master
181
+ - `getAllHelpsets({ masterHelpSetApplicationIdentifier, withMetadata })` - Get all helpsets
182
+ - `getAllowedMetaKeysForMasterhelpset({ masterHelpSetApplicationIdentifier })` - Get metadata keys
183
+
184
+ ### Helpset
185
+ - `loadActiveHelpset({ helpsetID })` - Load a helpset
186
+ - `getHelpsetInfoForActiveHelpset({})` - Get active helpset info
187
+ - `getHomeTopicId({ helpsetID })` - Get home topic
188
+
189
+ ### Navigation
190
+ - `getNavigationWithMetaData({ currentNavigationID, wantedMetaKeys })` - Get navigation tree
191
+ - `navigateToTopic({ topicID, navigationID })` - Navigate to topic
192
+
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
197
+
198
+ ### Metadata
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
206
+
207
+ ### System
208
+ - `getCurrentCobriliVersion({})` - Get version
209
+ - `getConfigurationData({})` - Get configuration
210
+ - `clearStaticCaches({})` - Clear caches
211
+
212
+ ## CommonJS
213
+
214
+ ```javascript
215
+ const { createCobriliClient } = require('cobrili-client');
216
+
217
+ const client = createCobriliClient({ baseUrl: 'http://localhost:5000' });
218
+ await client.init();
135
219
  ```
136
220
 
221
+ ## Links
222
+
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)
226
+
137
227
  ## License
138
228
 
139
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cobrili-client",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Modern TypeScript API client for Cobrili REST API - works in Browser and Node.js",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",