pino-sse 1.0.0
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/LEGAL.md +76 -0
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/eslint.config.js +24 -0
- package/package.json +31 -0
- package/psse.h3.ts +46 -0
- package/psse.ts +54 -0
package/LEGAL.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Terms of Service
|
|
2
|
+
|
|
3
|
+
## Usage Agreement
|
|
4
|
+
|
|
5
|
+
By inviting the bot or using its features, you are agreeing to the below mentioned Terms of Service and Privacy Policy.
|
|
6
|
+
|
|
7
|
+
You acknowledge that you have the privilege to use the bot freely on any Discord server you share with it, that you can invite it to any server that you have "Manage Server" rights for and that this privilege might get revoked for you, if you're subject of breaking the terms and/or policy of this bot, or the Terms of Service, Privacy Policy and/or Community Guidelines of Discord Inc.
|
|
8
|
+
|
|
9
|
+
Through inviting or interacting with the bot it may collect specific data as described in its [Privacy Policy](#privacy-policy). The intended usage of this data is for core functionalities of the bot such as command handling, server settings, and user settings.
|
|
10
|
+
|
|
11
|
+
## Intended Age
|
|
12
|
+
|
|
13
|
+
The bot may not be used by individuals under the minimal age described in Discord's Terms of Service.
|
|
14
|
+
|
|
15
|
+
Do not provide any age-restricted content (as defined in Discord's safety policies) to the bot. Age-restricted content includes but is not limited to content and discussion related to:
|
|
16
|
+
|
|
17
|
+
- Sexually explicit material such as pornography or sexually explicit text
|
|
18
|
+
- Violent content
|
|
19
|
+
- Illegal, dangerous, and regulated goods such as firearms, tactical gear, alcohol, or drug use
|
|
20
|
+
- Gambling-adjacent or addictive behavior
|
|
21
|
+
|
|
22
|
+
Content submitted to the bot through the use of commands arguments, text inputs, image inputs, or otherwise must adhere to the above conditions. Violating these conditions may result in your account being reported to Discord Inc for further action.
|
|
23
|
+
|
|
24
|
+
## Affiliation
|
|
25
|
+
|
|
26
|
+
The bot is not affiliated with, supported by, or made by Discord Inc.
|
|
27
|
+
|
|
28
|
+
Any direct connection to Discord or any of its trademark objects is purely coincidental. We do not claim to have the copyright ownership of any of Discord's assets, trademarks or other intellectual property.
|
|
29
|
+
|
|
30
|
+
## Liability
|
|
31
|
+
|
|
32
|
+
The owner(s) of the bot may not be made liable for individuals breaking these Terms at any given time. We have faith in the end users being truthful about their information and not misusing this bot or the services of Discord Inc in a malicious way.
|
|
33
|
+
|
|
34
|
+
We reserve the right to update these terms at our own discretion, giving you a 1-week (7 days) period to opt out of these terms if you're not agreeing with the new changes.
|
|
35
|
+
|
|
36
|
+
You may opt out by removing the bot from any server you have the rights for.
|
|
37
|
+
|
|
38
|
+
## Contact
|
|
39
|
+
|
|
40
|
+
People may get in contact through the official support server of the bot.
|
|
41
|
+
|
|
42
|
+
Other ways of support may be provided but aren't guaranteed.
|
|
43
|
+
|
|
44
|
+
# Privacy Policy
|
|
45
|
+
|
|
46
|
+
## Usage of Data
|
|
47
|
+
|
|
48
|
+
The bot may use stored data, as defined below, for different features including but not limited to:
|
|
49
|
+
|
|
50
|
+
- Command handling
|
|
51
|
+
- Providing server and user preferences
|
|
52
|
+
|
|
53
|
+
The bot may share non-sensitive data with 3rd party sites or services, including but not limited to:
|
|
54
|
+
|
|
55
|
+
- Aggregate/statistical data (ex: total number of server or users)
|
|
56
|
+
- Discord generated IDs needed to tie 3rd party data to Discord or user-provided data
|
|
57
|
+
|
|
58
|
+
Personally identifiable (other than IDs) or sensitive information will not be shared with 3rd party sites or services.
|
|
59
|
+
|
|
60
|
+
## Updating Data
|
|
61
|
+
|
|
62
|
+
The bot's data may be updated when using specific commands.
|
|
63
|
+
|
|
64
|
+
Updating data can require the input of an end user, and data that can be seen as sensitive, such as content of a message, may need to be stored when using certain commands.
|
|
65
|
+
|
|
66
|
+
## Temporarily Stored Data
|
|
67
|
+
|
|
68
|
+
The bot may keep stored data in an internal caching mechanic for a certain amount of time. After this time period, the cached information will be dropped and only be re-added when required.
|
|
69
|
+
|
|
70
|
+
Data may be dropped from cache pre-maturely through actions such as removing the bot from the server.
|
|
71
|
+
|
|
72
|
+
## Removal of Data
|
|
73
|
+
|
|
74
|
+
Manual removal of the data can be requested through the official support server. Discord IDs such as user, guild, role, etc. may be stored even after the removal of other data in order to properly identify bot specific statistics since those IDs are public and non-sensitive.
|
|
75
|
+
|
|
76
|
+
For security reasons we will ask you to provide us with proof of ownership to the data you wish to be removed. Only a server owner may request manual removal of server data.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jimmy Lew
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
File without changes
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/* eslint perfectionist/sort-objects: "error" */
|
|
3
|
+
import antfu from '@antfu/eslint-config'
|
|
4
|
+
|
|
5
|
+
export default antfu(
|
|
6
|
+
{
|
|
7
|
+
formatters: true,
|
|
8
|
+
pnpm: true,
|
|
9
|
+
},
|
|
10
|
+
).removeRules(
|
|
11
|
+
'no-labels',
|
|
12
|
+
'no-lone-blocks',
|
|
13
|
+
'no-restricted-syntax',
|
|
14
|
+
'node/prefer-global/buffer',
|
|
15
|
+
'node/prefer-global/process',
|
|
16
|
+
'prefer-rest-params',
|
|
17
|
+
'symbol-description',
|
|
18
|
+
'ts/ban-types',
|
|
19
|
+
'ts/no-empty-object-type',
|
|
20
|
+
'ts/no-invalid-this',
|
|
21
|
+
'ts/no-unnecessary-type-constraint',
|
|
22
|
+
'vue/no-template-shadow',
|
|
23
|
+
'vue/no-v-text-v-html-on-component',
|
|
24
|
+
)
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pino-sse",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Pino transport for server side events",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Jimmy Lew",
|
|
7
|
+
"main": "psse.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"lint": "eslint"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"pino-sse": "./psse.ts"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"pino",
|
|
16
|
+
"sse"
|
|
17
|
+
],
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@antfu/eslint-config": "^6.7.3",
|
|
20
|
+
"@types/node": "^25.0.3",
|
|
21
|
+
"@types/uuid": "^11.0.0",
|
|
22
|
+
"eslint": "^9.39.2"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"h3": "^2.0.1-rc.6",
|
|
26
|
+
"pino-abstract-transport": "^3.0.0",
|
|
27
|
+
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.56.0",
|
|
28
|
+
"uuid": "^13.0.0",
|
|
29
|
+
"uws-cors": "^1.0.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/psse.h3.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import build from 'pino-abstract-transport'
|
|
2
|
+
import {createEventStream, defineEventHandler, H3, handleCors, serve } from 'h3'
|
|
3
|
+
import { v4 as uuid } from 'uuid'
|
|
4
|
+
|
|
5
|
+
interface SSETransportOptions {
|
|
6
|
+
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default async function (opts: SSETransportOptions) {
|
|
10
|
+
const app = new H3()
|
|
11
|
+
let event_stream: any = null
|
|
12
|
+
|
|
13
|
+
app.get("/", (event) => {
|
|
14
|
+
const cors = handleCors(event, {
|
|
15
|
+
origin: '*',
|
|
16
|
+
preflight: {
|
|
17
|
+
statusCode: 204,
|
|
18
|
+
},
|
|
19
|
+
methods: '*',
|
|
20
|
+
})
|
|
21
|
+
if (cors !== false) return cors
|
|
22
|
+
|
|
23
|
+
event_stream = createEventStream(event);
|
|
24
|
+
return event_stream.send();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const server = serve(app, {port: 3333})
|
|
28
|
+
|
|
29
|
+
return build(async (stream) => {
|
|
30
|
+
for await (const obj of stream) {
|
|
31
|
+
obj["log_id"] = uuid()
|
|
32
|
+
const log = JSON.stringify(obj)
|
|
33
|
+
if (!event_stream)
|
|
34
|
+
continue
|
|
35
|
+
await event_stream.push(log)
|
|
36
|
+
}
|
|
37
|
+
}, {
|
|
38
|
+
async close(_) {
|
|
39
|
+
console.log('Killing sse transport');
|
|
40
|
+
await server.close()
|
|
41
|
+
},
|
|
42
|
+
parseLine(line) {
|
|
43
|
+
return JSON.parse(line)
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
}
|
package/psse.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import build from 'pino-abstract-transport'
|
|
2
|
+
import { v4 as uuid } from 'uuid'
|
|
3
|
+
import { App } from 'uWebSockets.js'
|
|
4
|
+
import type { HttpResponse } from 'uWebSockets.js'
|
|
5
|
+
import {cors} from 'uws-cors'
|
|
6
|
+
|
|
7
|
+
interface SSETransportOptions {
|
|
8
|
+
port: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default async function (opts: SSETransportOptions = {port: 3333}) {
|
|
12
|
+
const app = cors(App())
|
|
13
|
+
const connections: Record<string, HttpResponse> = {}
|
|
14
|
+
|
|
15
|
+
app.get("/", (conn) => {
|
|
16
|
+
const conn_id = uuid()
|
|
17
|
+
conn.cork(() => {
|
|
18
|
+
conn.writeHeader('Content-Type', 'text/event-stream')
|
|
19
|
+
conn.writeHeader('Connection', 'keep-alive')
|
|
20
|
+
conn.writeHeader('Cache-Control', 'no-cache')
|
|
21
|
+
})
|
|
22
|
+
conn.writeStatus('200 OK')
|
|
23
|
+
|
|
24
|
+
connections[conn_id] = conn
|
|
25
|
+
|
|
26
|
+
conn.onAborted(() => {
|
|
27
|
+
delete connections[conn_id]
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
})
|
|
31
|
+
app.listen(opts.port, () => {})
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
return build(async (stream) => {
|
|
35
|
+
for await (const obj of stream) {
|
|
36
|
+
obj["log_id"] = uuid()
|
|
37
|
+
const log = JSON.stringify(obj)
|
|
38
|
+
for (const conn of Object.values(connections)) {
|
|
39
|
+
conn.cork(() => conn.write(`data: ${log}\n\n`))
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
async close(_) {
|
|
44
|
+
for (const conn of Object.values(connections)) {
|
|
45
|
+
conn.cork(() => conn.write('event: close\n'))
|
|
46
|
+
conn.close()
|
|
47
|
+
}
|
|
48
|
+
app.close()
|
|
49
|
+
},
|
|
50
|
+
parseLine(line) {
|
|
51
|
+
return JSON.parse(line)
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
}
|