@glamboyosa/ore 0.0.1 → 0.0.2
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/package.json +3 -10
- package/readme.md +71 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glamboyosa/ore",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -9,19 +9,12 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"keywords": [
|
|
13
|
-
"@glamboyosa/ore",
|
|
14
|
-
"server-sent events",
|
|
15
|
-
"SSE",
|
|
16
|
-
"api"
|
|
17
|
-
],
|
|
12
|
+
"keywords": ["@glamboyosa/ore", "server-sent events", "SSE", "api"],
|
|
18
13
|
"scripts": {
|
|
19
14
|
"build": "tsup",
|
|
20
15
|
"fmt": "pnpm biome format . --write && pnpm biome check . --apply-unsafe "
|
|
21
16
|
},
|
|
22
|
-
"files": [
|
|
23
|
-
"./dist/**"
|
|
24
|
-
],
|
|
17
|
+
"files": ["./dist/**"],
|
|
25
18
|
"devDependencies": {
|
|
26
19
|
"@biomejs/biome": "^1.6.3",
|
|
27
20
|
"@types/node": "^20.11.30",
|
package/readme.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Ore
|
|
2
|
+
|
|
3
|
+
Ore is a JavaScript / TypeScript package that simplifies the consumption of Server-Sent Events (SSE) in web applications. It provides an easy-to-use interface for establishing SSE connections, handling incoming events, and implementing retry strategies in case of connection failures.
|
|
4
|
+
|
|
5
|
+
## Motivation
|
|
6
|
+
|
|
7
|
+
Consuming Server-Sent Events (SSE) or streaming data in web applications isn't always well-documented and can be complex or just plain unreliable to implement. Ore aims to simplify this process by providing a straightforward and reliable way to consume SSE streams.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Establish SSE connections with ease.
|
|
12
|
+
- Handle incoming SSE events and process them accordingly.
|
|
13
|
+
- Implement retry strategies for reconnecting to the SSE endpoint in case of connection failures.
|
|
14
|
+
- Customizable headers for SSE requests.
|
|
15
|
+
- Set maximum retries for connection attempts.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @glamboyosa/ore
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import Ore from "@glamboyosa/ore";
|
|
27
|
+
|
|
28
|
+
// Initialize Ore with URL and optional headers
|
|
29
|
+
const ore = new Ore({
|
|
30
|
+
url: "http://example.com/sse-endpoint",
|
|
31
|
+
headers: {
|
|
32
|
+
"Cache-Control": "no-cache",
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Start SSE connection
|
|
37
|
+
ore.fetchSSE(
|
|
38
|
+
(buffer, parts) => {
|
|
39
|
+
console.log("Received buffer:", buffer);
|
|
40
|
+
// Process the received buffer
|
|
41
|
+
|
|
42
|
+
const b = parts[parts.length - 1];
|
|
43
|
+
console.log("Received parts i.e. events", parts);
|
|
44
|
+
console.log("Buffer per event", b);
|
|
45
|
+
// process the buffer per event
|
|
46
|
+
},
|
|
47
|
+
() => {
|
|
48
|
+
console.log("Stream ended");
|
|
49
|
+
// Handle stream end
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Class Parameters
|
|
55
|
+
|
|
56
|
+
- `url`: `string` - The URL of the SSE endpoint.
|
|
57
|
+
- `headers`: `HeadersInit` (optional) - Optional headers to include in the SSE request. Must be an object where keys are header names and values are header values.
|
|
58
|
+
|
|
59
|
+
## `fetchSSE` Function Parameters
|
|
60
|
+
|
|
61
|
+
- `onBufferReceived`: `function` - Callback function to handle received SSE buffers. Receives the buffer and the optionally the parts i.e. new events as a parameter.
|
|
62
|
+
- `onStreamEnded`: `function` - Callback function to handle stream end events. Receives the internal state of if the buffer stream is ended.
|
|
63
|
+
- `retries`: `number` (optional) - Optional parameter to specify the maximum number of retry attempts. Default is 3.
|
|
64
|
+
|
|
65
|
+
## Contributing
|
|
66
|
+
|
|
67
|
+
Contributions to @glamboyosa/ore are welcome! If you have suggestions for improvements or encounter any issues, feel free to open an issue or submit a pull request on GitHub.
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
This project is licensed under the MIT License.
|