cobrili-client 1.0.2 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +167 -74
  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,123 +32,201 @@ 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';
26
39
 
27
40
  const client = createCobriliClient({
28
- baseUrl: 'http://localhost:5000',
29
- endpoint: '/api/cobrili',
30
- headers: {
31
- 'Authorization': 'Basic ' + btoa('user:pass')
32
- }
41
+ baseUrl: 'https://your-server.com',
42
+ endpoint: '/api/cobrili'
33
43
  });
34
44
 
35
- // Login
36
- const loginResult = await client.login({ loginUser: { username: 'user', password: 'pass' } });
45
+ // Initialize session (required before making API calls)
46
+ await client.init();
37
47
 
38
- // Get navigation
39
- const nav = await client.getNavigationWithMetaData({ currentNavigationID: 0 });
48
+ // Now you can make API calls
49
+ const helpsets = await client.getAllHelpsets({
50
+ masterHelpSetApplicationIdentifier: 'MyApp',
51
+ withMetadata: true
52
+ });
40
53
 
41
- // Get content
42
- const content = await client.getContent({ topicID: 12345 });
54
+ if (helpsets.data) {
55
+ console.log('Helpsets:', helpsets.data.helpsetInfos);
56
+ } else {
57
+ console.error('Error:', helpsets.error.message);
58
+ }
43
59
  ```
44
60
 
45
- ### CommonJS
61
+ ## Usage
46
62
 
47
- ```javascript
48
- const { createCobriliClient } = require('cobrili-client');
63
+ ### Creating the Client
64
+
65
+ ```typescript
66
+ import { createCobriliClient } from 'cobrili-client';
49
67
 
50
- const client = createCobriliClient({ baseUrl: 'http://localhost:5000' });
68
+ const client = createCobriliClient({
69
+ baseUrl: 'https://your-server.com', // Backend server URL
70
+ endpoint: '/api/cobrili', // API endpoint path
71
+ timeout: 30000, // Request timeout in ms (optional)
72
+ headers: {}, // Custom headers (optional)
73
+ debug: false // Enable debug logging (optional)
74
+ });
51
75
  ```
52
76
 
53
- ## API Methods
77
+ ### Initialization (Required)
54
78
 
55
- All methods are auto-generated from the API registry. Import `API_METHODS` for the full list:
79
+ The client must be initialized before making API calls. This creates a session with the backend:
56
80
 
57
81
  ```typescript
58
- import { API_METHODS } from 'cobrili-client';
82
+ // Initialize the session
83
+ await client.init();
59
84
 
60
- // List all available methods
61
- console.log(Object.keys(API_METHODS));
85
+ // Check if initialized
86
+ if (client.isInitialized()) {
87
+ // Ready to make API calls
88
+ }
62
89
  ```
63
90
 
64
- ### Authentication
65
- - `login({ loginUser: { username, password } })` - Login with credentials
66
- - `logout({})` - Logout
91
+ ### Typical Workflow
67
92
 
68
- ### Navigation
69
- - `getNavigationWithMetaData({ currentNavigationID })` - Get navigation tree
70
- - `navigateToTopic({ topicID, navigationID })` - Navigate to topic
93
+ ```typescript
94
+ // 1. Initialize
95
+ await client.init();
71
96
 
72
- ### Content
73
- - `getContent({ topicID })` - Get topic content
74
- - `getTopicForExternalId({ externalIdForTopic, externalIdForHelpset })` - Find topic
97
+ // 2. Activate a master helpset
98
+ const masterResult = await client.switchMasterHelpSet({
99
+ masterHelpSetApplicationIdentifier: 'Convotherm',
100
+ initActiveHelpset: true
101
+ });
75
102
 
76
- ### Helpset
77
- - `getAllHelpsets({ masterHelpSetApplicationIdentifier, withMetadata })` - Get all helpsets
78
- - `getHomeTopicId({ helpsetID })` - Get home topic
79
- - `loadActiveHelpset({ helpsetID })` - Load a helpset
103
+ // 3. Get all helpsets
104
+ const helpsetsResult = await client.getAllHelpsets({
105
+ masterHelpSetApplicationIdentifier: 'Convotherm',
106
+ withMetadata: true
107
+ });
80
108
 
81
- ### Bookmarks
82
- - `historyBack(steps?)` / `historyForward(steps?)` - Navigate history
83
- - `getBookmarkList()` - Get bookmarks
84
- - `addBookmark(topicID, navigationID, title)` - Add bookmark
109
+ // 4. Load a specific helpset
110
+ await client.loadActiveHelpset({ helpsetID: 123 });
85
111
 
86
- ### Metadata
87
- - `getUsedMetaValues(metaKey)` - Get meta values
88
- - `getMetaValueForTopic(metaKey, topicID)` - Get meta for topic
89
- - `getMetaKeyWhichRepresentsLanguage()` - Get language key
112
+ // 5. Get navigation tree
113
+ const navResult = await client.getNavigationWithMetaData({
114
+ currentNavigationID: 0,
115
+ wantedMetaKeys: [],
116
+ useHelpsetMetadataFallback: false
117
+ });
90
118
 
91
- ### System
92
- - `getCurrentCobriliVersion()` - Get version
93
- - `getConfigurationData()` - Get configuration
94
- - `clearStaticCaches()` - Clear caches
95
- - `healthCheck()` - Health check
119
+ // 6. Get topic content
120
+ const contentResult = await client.getContent({ topicID: 456 });
121
+ if (contentResult.data) {
122
+ // contentResult.data.content contains base64-encoded HTML
123
+ }
124
+ ```
96
125
 
97
126
  ## Response Format
98
127
 
128
+ All API methods return a discriminated union type:
129
+
99
130
  ```typescript
100
- interface ApiResponse<T> {
101
- success: boolean;
102
- data: T;
103
- status: number;
104
- message?: string;
131
+ type ApiResponse<T> =
132
+ | { data: T; error?: never } // Success
133
+ | { data?: never; error: CobriliError }; // Error
134
+
135
+ interface CobriliError {
136
+ code: string;
137
+ message: string;
138
+ details?: any;
105
139
  }
106
140
  ```
107
141
 
108
- ## Development
142
+ ### Handling Responses
109
143
 
110
- ```bash
111
- # Install dependencies
112
- npm install
144
+ ```typescript
145
+ const result = await client.getAllHelpsets({
146
+ masterHelpSetApplicationIdentifier: 'MyApp',
147
+ withMetadata: true
148
+ });
113
149
 
114
- # Build the package
115
- npm run build
150
+ if (result.error) {
151
+ // Handle error
152
+ console.error(`${result.error.code}: ${result.error.message}`);
153
+ } else {
154
+ // Use data
155
+ const helpsets = result.data.helpsetInfos;
156
+ }
157
+ ```
116
158
 
117
- # Watch mode for development
118
- npm run dev
159
+ ## API Methods
119
160
 
120
- # Run tests
121
- npm run test
161
+ All methods are auto-generated from the API registry:
122
162
 
123
- # Type check
124
- npm run type-check
163
+ ```typescript
164
+ import { API_METHODS } from 'cobrili-client';
125
165
 
126
- # Lint
127
- npm run lint
166
+ // List all available methods
167
+ console.log(Object.keys(API_METHODS));
128
168
  ```
129
169
 
130
- ## Publishing
170
+ ### Session & Authentication
171
+ - `init()` - Initialize session (required first)
172
+ - `isInitialized()` - Check if session is active
173
+ - `login({ loginUser })` - Login with credentials
174
+ - `logout({})` - Logout
131
175
 
132
- ```bash
133
- npm run build
134
- npm publish
176
+ ### Master Helpset
177
+ - `switchMasterHelpSet({ masterHelpSetApplicationIdentifier, initActiveHelpset })` - Activate master
178
+ - `getAllHelpsets({ masterHelpSetApplicationIdentifier, withMetadata })` - Get all helpsets
179
+ - `getAllowedMetaKeysForMasterhelpset({ masterHelpSetApplicationIdentifier })` - Get metadata keys
180
+
181
+ ### Helpset
182
+ - `loadActiveHelpset({ helpsetID })` - Load a helpset
183
+ - `getHelpsetInfoForActiveHelpset({})` - Get active helpset info
184
+ - `getHomeTopicId({ helpsetID })` - Get home topic
185
+
186
+ ### Navigation
187
+ - `getNavigationWithMetaData({ currentNavigationID, wantedMetaKeys })` - Get navigation tree
188
+ - `navigateToTopic({ topicID, navigationID })` - Navigate to topic
189
+
190
+ ### Content
191
+ - `getContent({ topicID })` - Get topic content (base64-encoded)
192
+ - `getTopicForExternalId({ externalIdForTopic, externalIdForHelpset })` - Find topic by external ID
193
+ - `getMetaValuesForTopics({ externalTopicIDs, wantedMetaKeys })` - Get metadata for topics
194
+
195
+ ### Metadata
196
+ - `getPossibleMetaValues({ metaKey })` - Get possible values for a meta key
197
+ - `getMetaValueForTopic({ metaKey, topicID })` - Get meta value for topic
198
+
199
+ ### History & Bookmarks
200
+ - `historyBack({ steps })` / `historyForward({ steps })` - Navigate history
201
+ - `getBookmarkList({})` - Get bookmarks
202
+ - `addBookmark({ topicID, navigationID, title })` - Add bookmark
203
+
204
+ ### System
205
+ - `getCurrentCobriliVersion({})` - Get version
206
+ - `getConfigurationData({})` - Get configuration
207
+ - `clearStaticCaches({})` - Clear caches
208
+
209
+ ## CommonJS
210
+
211
+ ```javascript
212
+ const { createCobriliClient } = require('cobrili-client');
213
+
214
+ const client = createCobriliClient({ baseUrl: 'https://your-server.com' });
215
+ await client.init();
135
216
  ```
136
217
 
218
+ ## Links
219
+
220
+ - [Cobrili™ Product Page](https://acolada.de/produkte/cobrili-2/) - Acolada GmbH
221
+ - [dictaJet](https://www.dictajet.de/) - Client developer
222
+ - [npm Package](https://www.npmjs.com/package/cobrili-client)
223
+
137
224
  ## License
138
225
 
139
226
  MIT
227
+
228
+ ---
229
+
230
+ **Cobrili™** is a trademark of [Acolada GmbH](https://acolada.de/), Nürnberg, Germany.
231
+
232
+ **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.4",
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",