Skip to content

Commit 94fd84a

Browse files
authored
Merge pull request #12 from CDPTechnologies/NPM
NPM setup
2 parents 657c714 + 15621e0 commit 94fd84a

5 files changed

Lines changed: 148 additions & 46 deletions

File tree

.github/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# CDPLogger Client for JavaScript
2+
3+
A simple JavaScript interface for communicating with CDP applications that include a CDPLogger component to retrieve historic data.
4+
- For documentation on the JS logger client see [DOCUMENTATION.md](DOCUMENTATION.md).
5+
- For a quickstart guide on how to set-up the npm project for either Node or Web see [QUICKSTART.md](QUICKSTART.md)
6+
- For more information about CDP Studio see https://cdpstudio.com/.
7+
8+
## Installation
9+
10+
Clone the repository and install dependencies:
11+
12+
```bash
13+
npm install
14+
```
15+
16+
17+
## Running Tests
18+
19+
To run the automatic tests with fake data, execute:
20+
21+
```bash
22+
npm test
23+
```
24+
25+
Note: these jest tests execute on every push and pull of the repo as well.
26+
27+
To test the time sync functionality using simulated response:
28+
29+
```bash
30+
node test/testTimeSync.js
31+
```
32+
33+
34+
## Usage
35+
36+
The value.js file contains a simple logger built for the CDP Studio example case.
37+
38+
1. Set up and run the Logger in CDP Studio.
39+
(Refer to Help → Framework - Data Logging → How to Setup Logging in Automation System)
40+
https://cdpstudio.com/manual/cdp/cdplogger/cdplogger-configuration-example.html
41+
42+
2. Run the value.js file from the command line:
43+
44+
```bash
45+
node examples/value.js
46+
```
47+
48+
For usage related to events run:
49+
50+
```bash
51+
node examples/event.js
52+
```
53+
54+
55+
## Contact
56+
57+
Email: support@cdptech.com

QUICKSTART.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ To enable web support, ensure your `client.js` file includes these modifications
5656
const EventQuery = root.DBMessaging.Protobuf.EventQuery;
5757
```
5858

59-
3. **Expose the Client Globally:**
60-
At the end of your `client.js`, attach the client API to the global window:
61-
```js
62-
cdplogger.Client = Client;
63-
window.cdplogger = cdplogger;
64-
```
65-
This ensures that when `client.js` is loaded in a browser, the `cdplogger` object (and its `Client` class) is available globally.
66-
6759
*Make sure these modifications are only applied for the browser version of your client module.*
6860

6961
## Usage

README.md

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,67 @@
1-
# CDPLogger Client for JavaScript
1+
# CDP Logger Client
22

3-
A simple JavaScript interface for communicating with CDP applications that include a CDPLogger component to retrieve historic data.
4-
- For documentation on the JS logger client see [DOCUMENTATION.md](DOCUMENTATION.md).
5-
- For a quickstart guide on how to set-up the npm project for either Node or Web see [QUICKSTART.md](QUICKSTART.md)
6-
- For more information about CDP Studio see https://cdpstudio.com/.
7-
8-
## Installation
9-
10-
Clone the repository and install dependencies:
11-
12-
```bash
13-
npm install
14-
```
3+
# CDP Logger Client
154

5+
A JavaScript client for reading historic data from systems created with the CDP Studio development platform.
6+
For more information about CDP Studio, see https://cdpstudio.com/.
7+
For more information about CDP Logger, see https://cdpstudio.com/manual/cdp/cdplogger/cdplogger-index.html.
168

17-
## Running Tests
9+
This client allows you to:
10+
- Connect to a CDP Logger or LogServer component
11+
- Request logged nodes and their metadata
12+
- Retrieve data points for specific nodes
13+
- Query events from the logger
14+
- Get log limits and API version information
1815

19-
To run the automatic tests with fake data, execute:
16+
## Installation
2017

2118
```bash
22-
npm test
19+
npm install cdp-logger-client
2320
```
2421

25-
Note: these jest tests execute on every push and pull of the repo as well.
22+
## Quick Start
2623

27-
To test the time sync functionality using simulated response:
24+
For a quick introduction, see the [QUICKSTART.md](QUICKSTART.md) guide.
2825

29-
```bash
30-
node test/testTimeSync.js
31-
```
26+
## Documentation
3227

28+
For detailed documentation, see [DOCUMENTATION.md](DOCUMENTATION.md).
3329

3430
## Usage
3531

36-
The value.js file contains a simple logger built for the CDP Studio example case.
32+
### Node.js
3733

38-
1. Set up and run the Logger in CDP Studio.
39-
(Refer to Help → Framework - Data Logging → How to Setup Logging in Automation System)
40-
https://cdpstudio.com/manual/cdp/cdplogger/cdplogger-configuration-example.html
34+
```javascript
35+
const cdplogger = require('cdp-logger-client');
36+
global.WebSocket = require('ws');
4137

42-
2. Run the value.js file from the command line:
38+
const client = new cdplogger.Client('127.0.0.1:17000');
4339

44-
```bash
45-
node examples/value.js
40+
// List logged nodes
41+
client.requestLoggedNodes().then(nodes => {
42+
console.log("Available nodes:", nodes);
43+
});
4644
```
4745

48-
For usage related to events run:
49-
50-
```bash
51-
node examples/event.js
46+
### Browser
47+
48+
```html
49+
<script src="protobuf.min.js"></script>
50+
<script src="containerPb.js"></script>
51+
<script src="client.js"></script>
52+
<script>
53+
const client = new cdplogger.Client(window.location.hostname + ":17000");
54+
55+
client.requestLoggedNodes().then(nodes => {
56+
console.log("Available nodes:", nodes);
57+
});
58+
</script>
5259
```
5360

54-
5561
## Contact
5662

57-
Email: support@cdptech.com
63+
Email: support@cdptech.com
64+
65+
## License
66+
67+
MIT

client.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,15 @@ class Client {
11171117
}
11181118
}
11191119

1120+
// Export the module
11201121
const cdplogger = {};
11211122
cdplogger.Client = Client;
11221123

1123-
module.exports = cdplogger;
1124+
// For Node.js
1125+
if (typeof module !== 'undefined' && module.exports) {
1126+
module.exports = cdplogger;
1127+
}
1128+
// For Browser
1129+
else if (typeof window !== 'undefined') {
1130+
window.cdplogger = cdplogger;
1131+
}

package.json

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,47 @@
11
{
2-
"devDependencies": {
3-
"jest": "^29.7.0",
4-
"ws": "^8.18.1"
2+
"name": "cdp-logger-client",
3+
"version": "1.0.0",
4+
"description": "A JavaScript client for interacting with CDP Logger or LogServer via WebSocket",
5+
"main": "client.js",
6+
"files": [
7+
"client.js",
8+
"generated/containerPb.js",
9+
"README.md",
10+
"QUICKSTART.md",
11+
"DOCUMENTATION.md",
12+
"LICENSE"
13+
],
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/CDPTechnologies/JavascriptCDPLoggerClient.git"
517
},
618
"scripts": {
719
"test": "jest"
820
},
21+
"keywords": [
22+
"cdp",
23+
"cdp-studio",
24+
"cdplogger",
25+
"cdp-logger",
26+
"cdp-logger-client",
27+
"cdploggerclient",
28+
"cdpjsclientlogger",
29+
"cdp-js-client-logger",
30+
"cdp-studio-logger",
31+
"logger",
32+
"logger-client"
33+
],
34+
"author": "CDP Technologies",
35+
"license": "MIT",
36+
"bugs": {
37+
"url": "https://github.com/CDPTechnologies/JavascriptCDPLoggerClient/issues"
38+
},
39+
"homepage": "https://github.com/CDPTechnologies/JavascriptCDPLoggerClient#readme",
940
"dependencies": {
1041
"protobufjs": "^7.4.0"
42+
},
43+
"devDependencies": {
44+
"ws": "^8.13.0",
45+
"jest": "^29.5.0"
1146
}
1247
}

0 commit comments

Comments
 (0)