gathergate 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +212 -2
- package/client/dist/assets/geist-mono-cyrillic-400-normal-C51Di1Mf.woff2 +0 -0
- package/client/dist/assets/geist-mono-cyrillic-400-normal-CPJFfJgk.woff +0 -0
- package/client/dist/assets/geist-mono-cyrillic-500-normal-D2cXvDHF.woff2 +0 -0
- package/client/dist/assets/geist-mono-cyrillic-500-normal-DfuvdVgn.woff +0 -0
- package/client/dist/assets/geist-mono-cyrillic-600-normal-Dfv53e6N.woff2 +0 -0
- package/client/dist/assets/geist-mono-cyrillic-600-normal-DzvMIgFZ.woff +0 -0
- package/client/dist/assets/geist-mono-latin-400-normal-B2yvC1Cq.woff +0 -0
- package/client/dist/assets/geist-mono-latin-400-normal-DTRLJnHl.woff2 +0 -0
- package/client/dist/assets/geist-mono-latin-500-normal-D-GG86Jb.woff +0 -0
- package/client/dist/assets/geist-mono-latin-500-normal-YINYabwD.woff2 +0 -0
- package/client/dist/assets/geist-mono-latin-600-normal-V-KvD_pi.woff2 +0 -0
- package/client/dist/assets/geist-mono-latin-600-normal-bZn07FKM.woff +0 -0
- package/client/dist/assets/geist-mono-latin-ext-400-normal-CfzLURNc.woff +0 -0
- package/client/dist/assets/geist-mono-latin-ext-400-normal-DI-rJ0UV.woff2 +0 -0
- package/client/dist/assets/geist-mono-latin-ext-500-normal-Buglb9-a.woff2 +0 -0
- package/client/dist/assets/geist-mono-latin-ext-500-normal-CrWEgvU_.woff +0 -0
- package/client/dist/assets/geist-mono-latin-ext-600-normal-B7ybHiTt.woff +0 -0
- package/client/dist/assets/geist-mono-latin-ext-600-normal-TphwrhF8.woff2 +0 -0
- package/client/dist/assets/geist-mono-symbols2-400-normal-DjbiTEEA.woff +0 -0
- package/client/dist/assets/geist-mono-symbols2-500-normal-CmnCPGa0.woff +0 -0
- package/client/dist/assets/geist-mono-symbols2-600-normal-D7I4D0GJ.woff +0 -0
- package/client/dist/assets/geist-mono-vietnamese-400-normal-CZEPLOgu.woff +0 -0
- package/client/dist/assets/geist-mono-vietnamese-500-normal-Dx9-epDo.woff +0 -0
- package/client/dist/assets/geist-mono-vietnamese-600-normal-BLL01lwa.woff +0 -0
- package/client/dist/assets/index-BWbZAfMJ.js +80 -0
- package/client/dist/assets/index-ZnG2njjK.css +2 -0
- package/client/dist/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
- package/client/dist/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
- package/client/dist/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
- package/client/dist/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
- package/client/dist/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
- package/client/dist/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
- package/client/dist/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
- package/client/dist/favicon.svg +12 -0
- package/client/dist/index.html +16 -0
- package/client/dist/site.webmanifest +16 -0
- package/dist/adapters/email.js +125 -0
- package/dist/adapters/storage.js +106 -0
- package/dist/app.js +2126 -0
- package/dist/config.js +106 -0
- package/dist/db/client.js +294 -0
- package/dist/db/queries.js +898 -0
- package/dist/emails/templates.js +221 -0
- package/dist/index.js +77 -0
- package/dist/jobs/chaser.js +81 -0
- package/dist/jobs/demo.js +329 -0
- package/dist/jobs/purge.js +22 -0
- package/dist/jobs/webhook.js +153 -0
- package/dist/security/auth.js +69 -0
- package/dist/security/crypto.js +91 -0
- package/dist/security/magic-bytes.js +131 -0
- package/dist/security/rate-limit.js +72 -0
- package/dist/security/ssrf.js +181 -0
- package/dist/templates/presets.js +341 -0
- package/dist/validators/index.js +52 -0
- package/dist/validators/packs/au.js +108 -0
- package/dist/validators/packs/eu.js +85 -0
- package/dist/validators/packs/generic.js +57 -0
- package/dist/validators/packs/types.js +1 -0
- package/dist/validators/packs/uk.js +58 -0
- package/dist/validators/packs/us.js +82 -0
- package/package.json +55 -4
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import nodemailer from "nodemailer";
|
|
2
|
+
import { decryptField } from "../security/crypto.js";
|
|
3
|
+
export class MemoryEmailAdapter {
|
|
4
|
+
sent = [];
|
|
5
|
+
async send(msg) {
|
|
6
|
+
this.sent.push(msg);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
class ConsoleEmailAdapter {
|
|
10
|
+
async send(msg) {
|
|
11
|
+
console.log(`[GatherGate Email Console]\nTo: ${msg.to}\nSubject: ${msg.subject}\n${msg.text}\n---`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
class ResendEmailAdapter {
|
|
15
|
+
apiKey;
|
|
16
|
+
from;
|
|
17
|
+
fetchImpl;
|
|
18
|
+
constructor(apiKey, from, fetchImpl = fetch) {
|
|
19
|
+
this.apiKey = apiKey;
|
|
20
|
+
this.from = from;
|
|
21
|
+
this.fetchImpl = fetchImpl;
|
|
22
|
+
}
|
|
23
|
+
async send(msg) {
|
|
24
|
+
const res = await this.fetchImpl("https://api.resend.com/emails", {
|
|
25
|
+
method: "POST",
|
|
26
|
+
headers: {
|
|
27
|
+
authorization: `Bearer ${this.apiKey}`,
|
|
28
|
+
"content-type": "application/json",
|
|
29
|
+
"user-agent": "GatherGate/1.0 (TensorForge; contact@tensorforge.dev)",
|
|
30
|
+
},
|
|
31
|
+
signal: AbortSignal.timeout(10_000),
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
from: this.from,
|
|
34
|
+
to: [msg.to],
|
|
35
|
+
subject: msg.subject,
|
|
36
|
+
text: msg.text,
|
|
37
|
+
...(msg.html ? { html: msg.html } : {}),
|
|
38
|
+
...(msg.replyTo ? { reply_to: msg.replyTo } : {}),
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
if (!res.ok) {
|
|
42
|
+
throw new Error(`Resend API error (${res.status}): ${await res.text()}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class SmtpEmailAdapter {
|
|
47
|
+
from;
|
|
48
|
+
transporter;
|
|
49
|
+
constructor(smtp, from) {
|
|
50
|
+
this.from = from;
|
|
51
|
+
this.transporter = nodemailer.createTransport({
|
|
52
|
+
host: smtp.host,
|
|
53
|
+
port: smtp.port,
|
|
54
|
+
secure: smtp.secure,
|
|
55
|
+
auth: smtp.user ? { user: smtp.user, pass: smtp.pass } : undefined,
|
|
56
|
+
connectionTimeout: 8_000,
|
|
57
|
+
greetingTimeout: 8_000,
|
|
58
|
+
socketTimeout: 10_000,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async send(msg) {
|
|
62
|
+
await this.transporter.sendMail({
|
|
63
|
+
from: this.from,
|
|
64
|
+
to: msg.to,
|
|
65
|
+
subject: msg.subject,
|
|
66
|
+
text: msg.text,
|
|
67
|
+
html: msg.html,
|
|
68
|
+
...(msg.replyTo ? { replyTo: msg.replyTo } : {}),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function createEmailAdapterFromOptions(opts) {
|
|
73
|
+
if (opts.backend === "resend" && opts.resendApiKey) {
|
|
74
|
+
return new ResendEmailAdapter(opts.resendApiKey, opts.from, opts.fetchImpl);
|
|
75
|
+
}
|
|
76
|
+
if (opts.backend === "smtp" && opts.smtp?.host) {
|
|
77
|
+
return new SmtpEmailAdapter(opts.smtp, opts.from);
|
|
78
|
+
}
|
|
79
|
+
return new ConsoleEmailAdapter();
|
|
80
|
+
}
|
|
81
|
+
export function createEmailAdapter(config) {
|
|
82
|
+
return createEmailAdapterFromOptions({
|
|
83
|
+
backend: config.emailBackend,
|
|
84
|
+
from: config.emailFrom,
|
|
85
|
+
resendApiKey: config.resendApiKey,
|
|
86
|
+
smtp: config.smtp,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
export function resolveWorkspaceEmail(ws, config, masterKey) {
|
|
90
|
+
if (ws.email_backend === "console" || ws.email_backend === "smtp" || ws.email_backend === "resend") {
|
|
91
|
+
let secrets = {};
|
|
92
|
+
if (ws.email_config_encrypted) {
|
|
93
|
+
try {
|
|
94
|
+
secrets = JSON.parse(decryptField(masterKey, ws.email_config_encrypted, `${ws.id}:email`));
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
secrets = {};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
source: "workspace",
|
|
102
|
+
backend: ws.email_backend,
|
|
103
|
+
from: ws.email_from || config.emailFrom,
|
|
104
|
+
replyTo: ws.email_reply_to || "",
|
|
105
|
+
smtp: secrets.smtpHost
|
|
106
|
+
? {
|
|
107
|
+
host: secrets.smtpHost,
|
|
108
|
+
port: secrets.smtpPort ?? 587,
|
|
109
|
+
secure: Boolean(secrets.smtpSecure),
|
|
110
|
+
user: secrets.smtpUser || "",
|
|
111
|
+
pass: secrets.smtpPass || "",
|
|
112
|
+
}
|
|
113
|
+
: undefined,
|
|
114
|
+
resendApiKey: secrets.resendApiKey,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
source: "env",
|
|
119
|
+
backend: config.emailBackend,
|
|
120
|
+
from: config.emailFrom,
|
|
121
|
+
replyTo: "",
|
|
122
|
+
smtp: config.smtp,
|
|
123
|
+
resendApiKey: config.resendApiKey,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
|
+
import { AwsClient } from "aws4fetch";
|
|
5
|
+
class LocalStorageAdapter {
|
|
6
|
+
root;
|
|
7
|
+
constructor(dataDir) {
|
|
8
|
+
this.root = path.resolve(dataDir, "blobs");
|
|
9
|
+
fs.mkdirSync(this.root, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
resolveSafePath(key) {
|
|
12
|
+
const clean = key.replace(/^\/+/, "");
|
|
13
|
+
const target = path.resolve(this.root, clean);
|
|
14
|
+
if (!target.startsWith(this.root + path.sep)) {
|
|
15
|
+
throw new Error("Invalid storage key path");
|
|
16
|
+
}
|
|
17
|
+
return target;
|
|
18
|
+
}
|
|
19
|
+
async put(key, data) {
|
|
20
|
+
const target = this.resolveSafePath(key);
|
|
21
|
+
await fs.promises.mkdir(path.dirname(target), { recursive: true });
|
|
22
|
+
await fs.promises.writeFile(target, data, { mode: 0o600 });
|
|
23
|
+
}
|
|
24
|
+
async getStream(key) {
|
|
25
|
+
const target = this.resolveSafePath(key);
|
|
26
|
+
await fs.promises.access(target, fs.constants.R_OK);
|
|
27
|
+
return fs.createReadStream(target);
|
|
28
|
+
}
|
|
29
|
+
async delete(key) {
|
|
30
|
+
const target = this.resolveSafePath(key);
|
|
31
|
+
try {
|
|
32
|
+
await fs.promises.unlink(target);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
if (err.code !== "ENOENT")
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class S3StorageAdapter {
|
|
41
|
+
aws;
|
|
42
|
+
endpoint;
|
|
43
|
+
bucket;
|
|
44
|
+
constructor(cfg) {
|
|
45
|
+
this.aws = new AwsClient({
|
|
46
|
+
accessKeyId: cfg.accessKeyId,
|
|
47
|
+
secretAccessKey: cfg.secretAccessKey,
|
|
48
|
+
region: cfg.region,
|
|
49
|
+
service: "s3",
|
|
50
|
+
retries: 3,
|
|
51
|
+
initRetryMs: 100,
|
|
52
|
+
});
|
|
53
|
+
this.endpoint = cfg.endpoint;
|
|
54
|
+
this.bucket = cfg.bucket;
|
|
55
|
+
}
|
|
56
|
+
objectUrl(key) {
|
|
57
|
+
const encodedKey = key
|
|
58
|
+
.replace(/^\/+/, "")
|
|
59
|
+
.split("/")
|
|
60
|
+
.map(encodeURIComponent)
|
|
61
|
+
.join("/");
|
|
62
|
+
return `${this.endpoint}/${encodeURIComponent(this.bucket)}/${encodedKey}`;
|
|
63
|
+
}
|
|
64
|
+
async put(key, data) {
|
|
65
|
+
const res = await this.aws.fetch(this.objectUrl(key), {
|
|
66
|
+
method: "PUT",
|
|
67
|
+
headers: {
|
|
68
|
+
"content-type": "application/octet-stream",
|
|
69
|
+
"content-length": String(data.byteLength),
|
|
70
|
+
},
|
|
71
|
+
body: new Uint8Array(data),
|
|
72
|
+
signal: AbortSignal.timeout(60_000),
|
|
73
|
+
});
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
throw new Error(`S3 PUT failed (${res.status}): ${await res.text()}`);
|
|
76
|
+
}
|
|
77
|
+
await res.body?.cancel();
|
|
78
|
+
}
|
|
79
|
+
async getStream(key) {
|
|
80
|
+
const res = await this.aws.fetch(this.objectUrl(key), {
|
|
81
|
+
method: "GET",
|
|
82
|
+
signal: AbortSignal.timeout(60_000),
|
|
83
|
+
});
|
|
84
|
+
if (!res.ok || !res.body) {
|
|
85
|
+
await res.body?.cancel();
|
|
86
|
+
throw new Error(`S3 GET failed (${res.status})`);
|
|
87
|
+
}
|
|
88
|
+
return Readable.fromWeb(res.body);
|
|
89
|
+
}
|
|
90
|
+
async delete(key) {
|
|
91
|
+
const res = await this.aws.fetch(this.objectUrl(key), {
|
|
92
|
+
method: "DELETE",
|
|
93
|
+
signal: AbortSignal.timeout(15_000),
|
|
94
|
+
});
|
|
95
|
+
await res.body?.cancel();
|
|
96
|
+
if (!res.ok && res.status !== 404) {
|
|
97
|
+
throw new Error(`S3 DELETE failed (${res.status})`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export function createStorageAdapter(config) {
|
|
102
|
+
if (config.storageBackend === "s3" && config.s3) {
|
|
103
|
+
return new S3StorageAdapter(config.s3);
|
|
104
|
+
}
|
|
105
|
+
return new LocalStorageAdapter(config.dataDir);
|
|
106
|
+
}
|