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.
- package/README.md +165 -69
- 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
|
|
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
|
|
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
|
-
##
|
|
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
|
-
//
|
|
36
|
-
|
|
48
|
+
// Initialize session (required before making API calls)
|
|
49
|
+
await client.init();
|
|
37
50
|
|
|
38
|
-
//
|
|
39
|
-
const
|
|
51
|
+
// Now you can make API calls
|
|
52
|
+
const helpsets = await client.getAllHelpsets({
|
|
53
|
+
masterHelpSetApplicationIdentifier: 'MyApp',
|
|
54
|
+
withMetadata: true
|
|
55
|
+
});
|
|
40
56
|
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
### Creating the Client
|
|
46
67
|
|
|
47
|
-
```
|
|
48
|
-
|
|
68
|
+
```typescript
|
|
69
|
+
import { createCobriliClient } from 'cobrili-client';
|
|
49
70
|
|
|
50
|
-
const client = createCobriliClient({
|
|
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
|
-
|
|
80
|
+
### Initialization (Required)
|
|
54
81
|
|
|
55
|
-
|
|
82
|
+
The client must be initialized before making API calls. This creates a session with the backend:
|
|
56
83
|
|
|
57
84
|
```typescript
|
|
58
|
-
|
|
85
|
+
// Initialize the session
|
|
86
|
+
await client.init();
|
|
59
87
|
|
|
60
|
-
//
|
|
61
|
-
|
|
88
|
+
// Check if initialized
|
|
89
|
+
if (client.isInitialized()) {
|
|
90
|
+
// Ready to make API calls
|
|
91
|
+
}
|
|
62
92
|
```
|
|
63
93
|
|
|
64
|
-
###
|
|
65
|
-
- `login({ loginUser: { username, password } })` - Login with credentials
|
|
66
|
-
- `logout({})` - Logout
|
|
94
|
+
### Typical Workflow
|
|
67
95
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
96
|
+
```typescript
|
|
97
|
+
// 1. Initialize
|
|
98
|
+
await client.init();
|
|
71
99
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
100
|
+
// 2. Activate a master helpset
|
|
101
|
+
const masterResult = await client.switchMasterHelpSet({
|
|
102
|
+
masterHelpSetApplicationIdentifier: 'Convotherm',
|
|
103
|
+
initActiveHelpset: true
|
|
104
|
+
});
|
|
75
105
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
106
|
+
// 3. Get all helpsets
|
|
107
|
+
const helpsetsResult = await client.getAllHelpsets({
|
|
108
|
+
masterHelpSetApplicationIdentifier: 'Convotherm',
|
|
109
|
+
withMetadata: true
|
|
110
|
+
});
|
|
80
111
|
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
115
|
+
// 5. Get navigation tree
|
|
116
|
+
const navResult = await client.getNavigationWithMetaData({
|
|
117
|
+
currentNavigationID: 0,
|
|
118
|
+
wantedMetaKeys: [],
|
|
119
|
+
useHelpsetMetadataFallback: false
|
|
120
|
+
});
|
|
90
121
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
data:
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
145
|
+
### Handling Responses
|
|
109
146
|
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
|
|
147
|
+
```typescript
|
|
148
|
+
const result = await client.getAllHelpsets({
|
|
149
|
+
masterHelpSetApplicationIdentifier: 'MyApp',
|
|
150
|
+
withMetadata: true
|
|
151
|
+
});
|
|
113
152
|
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
118
|
-
npm run dev
|
|
162
|
+
## API Methods
|
|
119
163
|
|
|
120
|
-
|
|
121
|
-
npm run test
|
|
164
|
+
All methods are auto-generated from the API registry:
|
|
122
165
|
|
|
123
|
-
|
|
124
|
-
|
|
166
|
+
```typescript
|
|
167
|
+
import { API_METHODS } from 'cobrili-client';
|
|
125
168
|
|
|
126
|
-
|
|
127
|
-
|
|
169
|
+
// List all available methods
|
|
170
|
+
console.log(Object.keys(API_METHODS));
|
|
128
171
|
```
|
|
129
172
|
|
|
130
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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.
|