cdsclient-lib 0.0.2 → 0.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 (62) hide show
  1. package/README.md +19 -20
  2. package/dist/lib/cjs/client.d.ts +304 -0
  3. package/dist/lib/cjs/client.js +916 -0
  4. package/dist/lib/cjs/client.js.map +1 -0
  5. package/dist/lib/cjs/enums.d.ts +23 -0
  6. package/dist/lib/cjs/enums.js +28 -0
  7. package/dist/lib/cjs/enums.js.map +1 -0
  8. package/dist/lib/cjs/errors.d.ts +20 -0
  9. package/dist/lib/cjs/errors.js +25 -0
  10. package/dist/lib/cjs/errors.js.map +1 -0
  11. package/dist/lib/cjs/event/channelstates.d.ts +24 -0
  12. package/dist/lib/cjs/event/channelstates.js +28 -0
  13. package/dist/lib/cjs/event/channelstates.js.map +1 -0
  14. package/dist/lib/cjs/event/eventprovider.d.ts +40 -0
  15. package/dist/lib/cjs/event/eventprovider.js +62 -0
  16. package/dist/lib/cjs/event/eventprovider.js.map +1 -0
  17. package/dist/lib/cjs/event/events.d.ts +32 -0
  18. package/dist/lib/cjs/event/events.js +38 -0
  19. package/dist/lib/cjs/event/events.js.map +1 -0
  20. package/dist/lib/cjs/index.d.ts +23 -0
  21. package/dist/lib/cjs/index.js +68 -0
  22. package/dist/lib/cjs/index.js.map +1 -0
  23. package/dist/lib/cjs/interfaces.d.ts +162 -0
  24. package/dist/lib/cjs/interfaces.js +20 -0
  25. package/dist/lib/cjs/interfaces.js.map +1 -0
  26. package/dist/lib/cjs/models.d.ts +198 -0
  27. package/dist/lib/cjs/models.js +234 -0
  28. package/dist/lib/cjs/models.js.map +1 -0
  29. package/dist/lib/cjs/wsclient.d.ts +99 -0
  30. package/dist/lib/cjs/wsclient.js +330 -0
  31. package/dist/lib/cjs/wsclient.js.map +1 -0
  32. package/dist/lib/es6/client.d.ts +304 -0
  33. package/dist/lib/es6/client.js +876 -0
  34. package/dist/lib/es6/client.js.map +1 -0
  35. package/dist/lib/es6/enums.d.ts +23 -0
  36. package/dist/lib/es6/enums.js +25 -0
  37. package/dist/lib/es6/enums.js.map +1 -0
  38. package/dist/lib/es6/errors.d.ts +20 -0
  39. package/dist/lib/es6/errors.js +25 -0
  40. package/dist/lib/es6/errors.js.map +1 -0
  41. package/dist/lib/es6/event/channelstates.d.ts +24 -0
  42. package/dist/lib/es6/event/channelstates.js +25 -0
  43. package/dist/lib/es6/event/channelstates.js.map +1 -0
  44. package/dist/lib/es6/event/eventprovider.d.ts +40 -0
  45. package/dist/lib/es6/event/eventprovider.js +57 -0
  46. package/dist/lib/es6/event/eventprovider.js.map +1 -0
  47. package/dist/lib/es6/event/events.d.ts +32 -0
  48. package/dist/lib/es6/event/events.js +35 -0
  49. package/dist/lib/es6/event/events.js.map +1 -0
  50. package/dist/lib/es6/index.d.ts +23 -0
  51. package/dist/lib/es6/index.js +23 -0
  52. package/dist/lib/es6/index.js.map +1 -0
  53. package/dist/lib/es6/interfaces.d.ts +162 -0
  54. package/dist/lib/es6/interfaces.js +19 -0
  55. package/dist/lib/es6/interfaces.js.map +1 -0
  56. package/dist/lib/es6/models.d.ts +198 -0
  57. package/dist/lib/es6/models.js +201 -0
  58. package/dist/lib/es6/models.js.map +1 -0
  59. package/dist/lib/es6/wsclient.d.ts +99 -0
  60. package/dist/lib/es6/wsclient.js +292 -0
  61. package/dist/lib/es6/wsclient.js.map +1 -0
  62. package/package.json +28 -14
package/README.md CHANGED
@@ -153,49 +153,48 @@ const initializeSocketClient = (dispatch, data) => {
153
153
  # Build
154
154
  ---
155
155
 
156
- 1. Simple compile - Generate output files
156
+ ## 1. Simple compile - Generate output files
157
157
 
158
- ```shell
158
+ ```bash
159
159
  npm run build
160
160
  ```
161
161
 
162
+ This will build outputs for es6 & commonjs in the `dist/lib` directory.
162
163
 
164
+ </br>
163
165
 
164
- 2. Compile (Platform specific)
166
+ ## 2. Create package for installing locally
165
167
 
166
168
  **Linux**
167
169
 
168
170
 
169
- ```shell
170
- npm run build_linux
171
+ ```bash
172
+ npm run pack:output
171
173
  ```
172
174
 
175
+ This will create a `tgz` file in the build folder. This file can be used to install the dependency locally.
173
176
 
174
- **Windows**
175
-
176
- ```shell
177
- npm run build_win
177
+ ```bash
178
+ npm install /path-to/build/cdsclient-lib-0.0.2.tgz
178
179
  ```
179
180
 
180
181
 
181
- 3. Distribute compiled files for linux to react client project
182
+ **Windows**
182
183
 
183
- > When building alongside `Cloudisense` main project folder
184
+ TO DO
184
185
 
185
- **Linux**
186
+ </br>
186
187
 
188
+ ## 3. Distribute the library on `npm`
187
189
 
188
- ```shell
189
- TO DO
190
- ```
190
+ The final step is to publish this on `npm`, so that it can be installed directly from there.
191
191
 
192
- **Windows**
192
+ * **Login:**: Type `npm login` at the console to initiate login. This will open a browser window, where you can authenticate on `npm`.
193
193
 
194
+ * **Publish:**: Type `npm publish` to publish this library on `npm`. Make sure the version is above the one existing on `npm`
194
195
 
195
- ```shell
196
- TO DO
197
- ```
196
+ </br>
198
197
 
199
- 4. NPM
198
+ ## 4. Libray on NPM
200
199
 
201
200
  The library is hosted on NPM @ [https://www.npmjs.com/package/cdsclient-lib](https://www.npmjs.com/package/cdsclient-lib)
@@ -0,0 +1,304 @@
1
+ /**
2
+ * Copyright © 2024 Rajdeep Rath. All Rights Reserved.
3
+ *
4
+ * This codebase is open-source and provided for use exclusively with the Cloudisense platform,
5
+ * as governed by its End-User License Agreement (EULA). Unauthorized use, reproduction,
6
+ * or distribution of this code outside of the Cloudisense ecosystem is strictly prohibited.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * You may not use this file except in compliance with the License.
10
+ * A copy of the License is available at:
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * This code may include third-party open-source libraries subject to their respective licenses.
14
+ * Such licenses are referenced in the source files or accompanying documentation.
15
+ *
16
+ * For questions or permissions beyond the scope of this notice, please contact Rajdeep Rath.
17
+ */
18
+ import 'reflect-metadata';
19
+ import { IServiceClient, IClientConfig } from "./interfaces";
20
+ import { IEventHandler } from "strongly-typed-events";
21
+ import { ClientEventProvider } from "./event/eventprovider";
22
+ import { LogInfo, AuthData, RuleInfo } from "./models";
23
+ export declare class CloudisenseApiClient extends ClientEventProvider implements IServiceClient {
24
+ host: string;
25
+ port: number;
26
+ autoconnect?: boolean;
27
+ reconnectOnFailure?: boolean;
28
+ authdata: AuthData;
29
+ private _socketservice;
30
+ private _restEndPoint;
31
+ private _authtime;
32
+ private _lastCredentials;
33
+ private _errorCount;
34
+ private static MAX_ERROR_TOLERANCE;
35
+ private _topicevents;
36
+ constructor(config: IClientConfig);
37
+ /**
38
+ * Subscribes to a specific DataEvent topic
39
+ *
40
+ * @param topicname topic name to subscribe to
41
+ * @param fn subscriber handler function
42
+ */
43
+ subscribeTopic(topicname: string, fn: IEventHandler<IServiceClient, any>): Function;
44
+ /**
45
+ * Unsubscribes from a specific DataEvent topic. The handler is executed at most once
46
+ *
47
+ * @param topicname topic name to unsubscribe from
48
+ * @param fn subscriber handler function
49
+ */
50
+ unsubscribeTopic(topicname: string, fn: IEventHandler<IServiceClient, any>): void;
51
+ /**
52
+ * Checks to see if a given DataEvent topic has a handler registered against it or not
53
+ *
54
+ * @param topicname
55
+ * @param fn
56
+ */
57
+ hasTopicHandler(topicname: string, fn: IEventHandler<IServiceClient, any>): boolean;
58
+ /**
59
+ * Gets the root path of the filesystem (constrained by sandbox)
60
+ *
61
+ * @returns Promise that resolved to root path data of the filesystem
62
+ */
63
+ get_accessible_file_system_paths(): Promise<any>;
64
+ /**
65
+ * Requests deletion of a file from the file system
66
+ *
67
+ * @param path The path of the file to delete
68
+ * @returns Promise that resolves to nothing if operation is successful and error if unsuccessful
69
+ */
70
+ delete_file(path: string): Promise<any>;
71
+ /**
72
+ * Requests deletion of a directory from the file system
73
+ *
74
+ * @param path The path of the directory to delete
75
+ * @returns Promise that resolves to nothing if operation is successful and error if unsuccessful
76
+ */
77
+ delete_folder(root: string, dirname: string, deleteNonEmpty?: boolean): Promise<any>;
78
+ /**
79
+ * Requests the download file from the file system (within allowed scope)
80
+ *
81
+ * @param path The path of the file to download
82
+ * @returns Promise that resolves to a download link if operation is successful and error if unsuccessful
83
+ */
84
+ download_file(path: string, mode?: string): Promise<any>;
85
+ /**
86
+ * Gets content listing of the file system path specified
87
+ *
88
+ * @returns Promise that resolved to path content (if any)
89
+ */
90
+ list_path_content(root: string, path?: string): Promise<any>;
91
+ /**
92
+ * Fetched the content of a simple text file from server
93
+ *
94
+ * @returns
95
+ */
96
+ read_file(path: string): Promise<string>;
97
+ /**
98
+ * Saves the content of a simple text file on server
99
+ *
100
+ * @returns
101
+ */
102
+ write_file(path: string, content: string): Promise<void>;
103
+ /**
104
+ * Gets list of accessible logs
105
+ *
106
+ * @returns Promise that resolved to List of logs
107
+ */
108
+ get_logs(): Promise<Array<LogInfo>>;
109
+ /**
110
+ * Gets list of reaction engine rules
111
+ *
112
+ * @returns Promise that resolved to List of ReactionRules
113
+ */
114
+ list_rules(head?: boolean): Promise<Array<RuleInfo>>;
115
+ /**
116
+ * Attempts to reloads all reaction rules in the system
117
+ *
118
+ * @returns Promise that resolved to nothing
119
+ */
120
+ reload_rules(): Promise<any>;
121
+ /**
122
+ * Attempts to reloads a reaction rules by specified id
123
+ * in the system
124
+ *
125
+ * @returns Promise that resolved to id of the reaction rule
126
+ */
127
+ reload_rule(id: string): Promise<any>;
128
+ /**
129
+ * Gets rule data of a reaction engine rule by specified id
130
+ *
131
+ * @returns Promise that resolved to Rule data
132
+ */
133
+ get_rule(id: string): Promise<any>;
134
+ /**
135
+ * Requests service to initiate restart via systemctl.
136
+ * Server should have sufficient permissions to execute the command
137
+ *
138
+ * @returns Promise that resolved to nothing (no return value)
139
+ */
140
+ request_restart(id: string): Promise<any>;
141
+ /**
142
+ * Requests to load settings / configuration information from the server
143
+ *
144
+ * @returns Promise that resolved to settings data
145
+ */
146
+ loadSettings(): Promise<any>;
147
+ /**
148
+ * Gets sample reaction rule data from server
149
+ *
150
+ * @returns Promise that resolved to Rule data
151
+ */
152
+ generate_sample_rule(): Promise<any>;
153
+ /**
154
+ * Saves rule data of a reaction engine rule on server
155
+ *
156
+ * @returns Promise that resolved to Rule Id on successful write
157
+ */
158
+ write_rule(data: string, update?: boolean): Promise<any>;
159
+ /**
160
+ * Deletes a rule by specified id
161
+ *
162
+ * @returns Promise that resolves to the id of the deleted rule
163
+ */
164
+ delete_rule(id: string): Promise<string>;
165
+ /**
166
+ * Subscribes to arbitrary data channel (topic path) to get realtime data
167
+ *
168
+ * @returns Promise that resolved to subscribable topic path for the data channel for stats
169
+ */
170
+ subscribe_datachannel(topic: string): Promise<any>;
171
+ /**
172
+ * Subscribes to stats channel (topic path) to get realtime data
173
+ *
174
+ * @returns Promise that resolved to subscribable topic path for the data channel for stats
175
+ */
176
+ subscribe_stats(): Promise<any>;
177
+ /**
178
+ * Subscribes to ui updates channel (topic path) to get data updates for dashboard widgets
179
+ *
180
+ * @returns Promise that resolved to subscribable topic path for the data channel for stats
181
+ */
182
+ subscribe_ui_updates(): Promise<any>;
183
+ /**
184
+ * Unsubscribes from stats channel (topic path) to get realtime data
185
+ *
186
+ * @returns Promise that resolved to boolean true on unsubscribe success
187
+ */
188
+ unsubscribe_stats(): Promise<any>;
189
+ /**
190
+ * Subscribes to log channel (topic path) to get realtime data
191
+ *
192
+ * @param topic
193
+ * @returns Promise that resolved to subscribable topic path for the data channel of thsi log
194
+ */
195
+ subscribe_log(topic: string): Promise<any>;
196
+ /**
197
+ *
198
+ * Unsubscribes from a log channel
199
+ *
200
+ * @param logkey
201
+ * @returns
202
+ */
203
+ unsubscribe_log(topic: string): Promise<void>;
204
+ /**
205
+ * Requests to download a log file from server
206
+ *
207
+ * @param logkey
208
+ * @returns
209
+ */
210
+ download_log(logkey: string, mode?: string): Promise<string>;
211
+ /**
212
+ * Gets list of system services that can be started/stopped through the service
213
+ *
214
+ * @returns
215
+ */
216
+ get_system_services(): Promise<string[]>;
217
+ /**
218
+ * Starts a system service using its name
219
+ *
220
+ * @param name
221
+ * @returns
222
+ */
223
+ start_service(name: string): Promise<void>;
224
+ /**
225
+ * Stops a system service using its name
226
+ *
227
+ * @param name
228
+ * @returns
229
+ */
230
+ stop_service(name: string): Promise<void>;
231
+ /**
232
+ * Restarts a system service using its name
233
+ *
234
+ * @param name
235
+ * @returns
236
+ */
237
+ restart_service(name: string): Promise<void>;
238
+ /**
239
+ *
240
+ * Execute arbitrary intent request
241
+ *
242
+ * @param intent
243
+ * @param params
244
+ * @returns
245
+ */
246
+ execute_arbitrary_action(intent: string, params: any): Promise<void>;
247
+ /**
248
+ * Connects to backend service using auth data from previous authentication
249
+ *
250
+ * @param authData
251
+ * @returns Promise
252
+ */
253
+ connectWithAuthData(authData: AuthData): Promise<any>;
254
+ /**
255
+ * Connects to backend service using a set of valid credentials
256
+ *
257
+ * @param username
258
+ * @param password
259
+ * @returns
260
+ */
261
+ connectWithCredentials(username: string, password: string): Promise<any>;
262
+ private __wsconnect;
263
+ /**
264
+ * Returns a boolean promise to help determine if socket si conencted or not
265
+ * @returns
266
+ */
267
+ connected(): Promise<boolean>;
268
+ /**
269
+ * Disconnects the client if connected to the server, otherwise
270
+ * throws error.
271
+ */
272
+ disconnect(): Promise<any>;
273
+ /**
274
+ * Attempts to reconenct back to service using last successful credentials
275
+ */
276
+ private attemptReconnect;
277
+ /**
278
+ * Process push data from server and dispatch events for client
279
+ *
280
+ * @param data
281
+ */
282
+ private processChannelData;
283
+ /**
284
+ * Dispatches topic specific error event with topic specific data
285
+ * @param event
286
+ */
287
+ private _dispatchTopicOrientedErrorEvent;
288
+ /**
289
+ * Dispatches topic specific event with topic specific data - (generic)
290
+ *
291
+ * @param event
292
+ */
293
+ private _dispatchTopicOrientedDataEvent;
294
+ private getBaseAPIendPoint;
295
+ /**
296
+ * Authenticates a user based on username and password
297
+ *
298
+ * @param username
299
+ * @param password
300
+ * @returns
301
+ */
302
+ private authenticate;
303
+ dispose(): void;
304
+ }