curriculum-api 0.1.0 → 0.2.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/dist/{admin-U7LVEF3Y.js → admin-LLA7YFBM.js} +1357 -438
- package/dist/chunk-2BZOKT6H.js +877 -0
- package/dist/{chunk-RL62MWPL.js → chunk-IM5Z67ZH.js} +79 -40
- package/dist/cli.js +19 -5
- package/dist/index.d.ts +20 -2
- package/dist/index.js +1129 -131
- package/drizzle/0003_zippy_frank_castle.sql +1 -0
- package/drizzle/0004_woozy_bloodaxe.sql +2 -0
- package/drizzle/0005_little_kronos.sql +8 -0
- package/drizzle/0006_drop_master_cv.sql +3 -0
- package/drizzle/0007_graceful_karma.sql +5 -0
- package/drizzle/meta/0003_snapshot.json +556 -0
- package/drizzle/meta/0004_snapshot.json +549 -0
- package/drizzle/meta/0005_snapshot.json +595 -0
- package/drizzle/meta/0006_snapshot.json +589 -0
- package/drizzle/meta/0007_snapshot.json +621 -0
- package/drizzle/meta/_journal.json +35 -0
- package/package.json +10 -3
- package/dist/chunk-N6XNQ5R5.js +0 -463
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "curriculum-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Hono backend for a personal curriculum site: public chat, recruiter chat and admin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -36,12 +36,17 @@
|
|
|
36
36
|
],
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "tsup",
|
|
39
|
+
"verify:tailor": "tsx --env-file-if-exists=.env --env-file-if-exists=.env.local scripts/verify-tailor.ts",
|
|
39
40
|
"typecheck": "tsc --noEmit && tsc --noEmit -p src/admin/tsconfig.client.json",
|
|
40
41
|
"lint": "biome check . && tsx scripts/check-architecture.ts && tsx scripts/build-js.ts --check",
|
|
41
42
|
"test": "vitest run",
|
|
42
43
|
"test:unit": "vitest run --project unit",
|
|
43
44
|
"test:int": "vitest run --project integration",
|
|
44
|
-
"dev": "tsx scripts/build-js.ts && tsx --env-file-if-exists=.env --env-file-if-exists=.env.local examples/node/server.ts",
|
|
45
|
+
"dev": "tsx scripts/build-js.ts && tsx watch --env-file-if-exists=.env --env-file-if-exists=.env.local examples/node/server.ts",
|
|
46
|
+
"db:up": "docker compose --env-file .env.local up -d --wait",
|
|
47
|
+
"db:down": "docker compose --env-file .env.local down",
|
|
48
|
+
"db:migrate": "tsx --env-file=.env.local src/cli.ts migrate",
|
|
49
|
+
"db:seed": "tsx --env-file=.env.local src/cli.ts seed",
|
|
45
50
|
"db:generate": "drizzle-kit generate",
|
|
46
51
|
"vendor:htmx": "tsx scripts/vendor-htmx.ts",
|
|
47
52
|
"build:css": "tsx scripts/build-css.ts",
|
|
@@ -51,7 +56,6 @@
|
|
|
51
56
|
},
|
|
52
57
|
"dependencies": {
|
|
53
58
|
"@hono/zod-openapi": "1.6.3",
|
|
54
|
-
"@neondatabase/serverless": "1.2.1",
|
|
55
59
|
"@openrouter/ai-sdk-provider": "3.1.0",
|
|
56
60
|
"ai": "7.0.179",
|
|
57
61
|
"bcryptjs": "3.0.3",
|
|
@@ -59,6 +63,7 @@
|
|
|
59
63
|
"hono": "4.13.19",
|
|
60
64
|
"jose": "6.2.18",
|
|
61
65
|
"marked": "16.4.1",
|
|
66
|
+
"pg": "8.23.1",
|
|
62
67
|
"zod": "4.6.7"
|
|
63
68
|
},
|
|
64
69
|
"devDependencies": {
|
|
@@ -69,9 +74,11 @@
|
|
|
69
74
|
"@hono/node-server": "2.1.11",
|
|
70
75
|
"@tailwindcss/cli": "4.3.5",
|
|
71
76
|
"@types/node": "26.6.6",
|
|
77
|
+
"@types/pg": "8.23.1",
|
|
72
78
|
"drizzle-kit": "0.31.11",
|
|
73
79
|
"esbuild": "0.28.2",
|
|
74
80
|
"htmx.org": "2.0.11",
|
|
81
|
+
"notyf": "3.10.0",
|
|
75
82
|
"tailwindcss": "4.3.5",
|
|
76
83
|
"tsup": "9.0.0",
|
|
77
84
|
"tsx": "4.23.15",
|
package/dist/chunk-N6XNQ5R5.js
DELETED
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
// src/services/errors.ts
|
|
2
|
-
var DomainError = class extends Error {
|
|
3
|
-
};
|
|
4
|
-
var ValidationError = class extends DomainError {
|
|
5
|
-
constructor(message = "Invalid input", fields) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.fields = fields;
|
|
8
|
-
this.name = "ValidationError";
|
|
9
|
-
}
|
|
10
|
-
fields;
|
|
11
|
-
code = "validation_error";
|
|
12
|
-
status = 400;
|
|
13
|
-
};
|
|
14
|
-
var UnauthorizedError = class extends DomainError {
|
|
15
|
-
code = "unauthorized";
|
|
16
|
-
status = 401;
|
|
17
|
-
constructor(message = "Unauthorized") {
|
|
18
|
-
super(message);
|
|
19
|
-
this.name = "UnauthorizedError";
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
var ForbiddenError = class extends DomainError {
|
|
23
|
-
code = "forbidden";
|
|
24
|
-
status = 403;
|
|
25
|
-
constructor(message = "Forbidden") {
|
|
26
|
-
super(message);
|
|
27
|
-
this.name = "ForbiddenError";
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
var CaptchaFailedError = class extends DomainError {
|
|
31
|
-
code = "captcha_failed";
|
|
32
|
-
status = 403;
|
|
33
|
-
constructor(message = "Captcha verification failed") {
|
|
34
|
-
super(message);
|
|
35
|
-
this.name = "CaptchaFailedError";
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var NotFoundError = class extends DomainError {
|
|
39
|
-
code = "not_found";
|
|
40
|
-
status = 404;
|
|
41
|
-
constructor(message = "Not found") {
|
|
42
|
-
super(message);
|
|
43
|
-
this.name = "NotFoundError";
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var ChatRevokedError = class extends DomainError {
|
|
47
|
-
code = "chat_revoked";
|
|
48
|
-
status = 410;
|
|
49
|
-
constructor(message = "This chat was revoked") {
|
|
50
|
-
super(message);
|
|
51
|
-
this.name = "ChatRevokedError";
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var ChatExpiredError = class extends DomainError {
|
|
55
|
-
code = "chat_expired";
|
|
56
|
-
status = 410;
|
|
57
|
-
constructor(message = "This chat expired") {
|
|
58
|
-
super(message);
|
|
59
|
-
this.name = "ChatExpiredError";
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var LimitReachedError = class extends DomainError {
|
|
63
|
-
code = "limit_reached";
|
|
64
|
-
status = 429;
|
|
65
|
-
constructor(message = "Limit reached") {
|
|
66
|
-
super(message);
|
|
67
|
-
this.name = "LimitReachedError";
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
var LlmUnavailableError = class extends DomainError {
|
|
71
|
-
code = "llm_unavailable";
|
|
72
|
-
status = 502;
|
|
73
|
-
constructor(message = "The language model is unavailable") {
|
|
74
|
-
super(message);
|
|
75
|
-
this.name = "LlmUnavailableError";
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
var PiiLeakError = class extends DomainError {
|
|
79
|
-
constructor(fieldKey) {
|
|
80
|
-
super(`Personal info field "${fieldKey}" found in an LLM prompt`);
|
|
81
|
-
this.fieldKey = fieldKey;
|
|
82
|
-
this.name = "PiiLeakError";
|
|
83
|
-
}
|
|
84
|
-
fieldKey;
|
|
85
|
-
code = "internal_error";
|
|
86
|
-
status = 500;
|
|
87
|
-
};
|
|
88
|
-
var ConfigError = class extends DomainError {
|
|
89
|
-
constructor(fields) {
|
|
90
|
-
super(`Invalid configuration: ${fields.join(", ")}`);
|
|
91
|
-
this.fields = fields;
|
|
92
|
-
this.name = "ConfigError";
|
|
93
|
-
}
|
|
94
|
-
fields;
|
|
95
|
-
code = "config_error";
|
|
96
|
-
status = 500;
|
|
97
|
-
};
|
|
98
|
-
var DecryptionError = class extends DomainError {
|
|
99
|
-
code = "internal_error";
|
|
100
|
-
status = 500;
|
|
101
|
-
constructor(message = "Could not decrypt value") {
|
|
102
|
-
super(message);
|
|
103
|
-
this.name = "DecryptionError";
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// src/security/ip.ts
|
|
108
|
-
function clientIp(headers) {
|
|
109
|
-
const forwarded = headers.get("x-forwarded-for")?.split(",")[0]?.trim();
|
|
110
|
-
if (forwarded) return forwarded;
|
|
111
|
-
const real = headers.get("x-real-ip")?.trim();
|
|
112
|
-
return real || null;
|
|
113
|
-
}
|
|
114
|
-
async function hashIp(ip, salt) {
|
|
115
|
-
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(salt + ip));
|
|
116
|
-
return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// src/llm/pii-guard.ts
|
|
120
|
-
var MIN_LENGTH = 3;
|
|
121
|
-
var PHONE_MIN_DIGITS = 7;
|
|
122
|
-
var DIGIT_RUN = /[\d\s+\-().]+/g;
|
|
123
|
-
var digitsOf = (s) => s.replace(/\D/g, "");
|
|
124
|
-
var escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
125
|
-
function kindOf(value) {
|
|
126
|
-
if (digitsOf(value).length >= PHONE_MIN_DIGITS && /^[\d\s+\-().]+$/.test(value)) return "phone";
|
|
127
|
-
if (value.includes("@")) return "email";
|
|
128
|
-
return "text";
|
|
129
|
-
}
|
|
130
|
-
function matcherFor(field) {
|
|
131
|
-
const value = field.value.trim();
|
|
132
|
-
if (value.length < MIN_LENGTH) return null;
|
|
133
|
-
const kind = kindOf(value);
|
|
134
|
-
if (kind === "phone") {
|
|
135
|
-
const digits = digitsOf(value);
|
|
136
|
-
return (text) => (text.match(DIGIT_RUN) ?? []).some((run) => digitsOf(run).includes(digits));
|
|
137
|
-
}
|
|
138
|
-
const needle = value.toLowerCase();
|
|
139
|
-
return (text) => text.toLowerCase().includes(needle);
|
|
140
|
-
}
|
|
141
|
-
function findPii(text, fields) {
|
|
142
|
-
const matches = [];
|
|
143
|
-
for (const field of fields) {
|
|
144
|
-
const matcher = matcherFor(field);
|
|
145
|
-
if (matcher?.(text)) matches.push({ key: field.key, label: field.label });
|
|
146
|
-
}
|
|
147
|
-
return matches;
|
|
148
|
-
}
|
|
149
|
-
function redactPii(text, fields) {
|
|
150
|
-
let out = text;
|
|
151
|
-
for (const field of fields) {
|
|
152
|
-
const value = field.value.trim();
|
|
153
|
-
if (value.length < MIN_LENGTH) continue;
|
|
154
|
-
if (kindOf(value) === "phone") {
|
|
155
|
-
const digits = digitsOf(value);
|
|
156
|
-
out = out.replace(DIGIT_RUN, (run) => {
|
|
157
|
-
if (!digitsOf(run).includes(digits)) return run;
|
|
158
|
-
const lead = run.match(/^\s*/)?.[0] ?? "";
|
|
159
|
-
const trail = run.match(/\s*$/)?.[0] ?? "";
|
|
160
|
-
return `${lead}[redacted]${trail}`;
|
|
161
|
-
});
|
|
162
|
-
} else {
|
|
163
|
-
out = out.replace(new RegExp(escapeRegExp(value), "gi"), "[redacted]");
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return out;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// src/security/crypto.ts
|
|
170
|
-
var IV_BYTES = 12;
|
|
171
|
-
async function importKey(keyB64) {
|
|
172
|
-
return crypto.subtle.importKey("raw", Buffer.from(keyB64, "base64"), "AES-GCM", false, [
|
|
173
|
-
"encrypt",
|
|
174
|
-
"decrypt"
|
|
175
|
-
]);
|
|
176
|
-
}
|
|
177
|
-
async function encrypt(plain, keyB64) {
|
|
178
|
-
const iv = crypto.getRandomValues(new Uint8Array(IV_BYTES));
|
|
179
|
-
const cipher = await crypto.subtle.encrypt(
|
|
180
|
-
{ name: "AES-GCM", iv },
|
|
181
|
-
await importKey(keyB64),
|
|
182
|
-
new TextEncoder().encode(plain)
|
|
183
|
-
);
|
|
184
|
-
return Buffer.concat([iv, new Uint8Array(cipher)]).toString("base64");
|
|
185
|
-
}
|
|
186
|
-
async function decrypt(payloadB64, keyB64) {
|
|
187
|
-
try {
|
|
188
|
-
const bytes = Buffer.from(payloadB64, "base64");
|
|
189
|
-
const iv = bytes.subarray(0, IV_BYTES);
|
|
190
|
-
const data = bytes.subarray(IV_BYTES);
|
|
191
|
-
const plain = await crypto.subtle.decrypt(
|
|
192
|
-
{ name: "AES-GCM", iv },
|
|
193
|
-
await importKey(keyB64),
|
|
194
|
-
data
|
|
195
|
-
);
|
|
196
|
-
return new TextDecoder().decode(plain);
|
|
197
|
-
} catch {
|
|
198
|
-
throw new DecryptionError();
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// src/services/personal-info.service.ts
|
|
203
|
-
var VISIBILITIES = ["public", "recruiter", "print"];
|
|
204
|
-
var KEY_PATTERN = /^[A-Z][A-Z0-9_]{0,31}$/;
|
|
205
|
-
var CHANNEL_VISIBILITIES = {
|
|
206
|
-
public: ["public"],
|
|
207
|
-
recruiter: ["public", "recruiter"],
|
|
208
|
-
print: ["public", "recruiter", "print"]
|
|
209
|
-
};
|
|
210
|
-
function invalid(field, reason) {
|
|
211
|
-
throw new ValidationError(`Invalid ${field}: ${reason}`, { [field]: reason });
|
|
212
|
-
}
|
|
213
|
-
function requireText(field, value) {
|
|
214
|
-
if (typeof value !== "string" || value.trim() === "") invalid(field, "must not be empty");
|
|
215
|
-
return value;
|
|
216
|
-
}
|
|
217
|
-
function requireVisibility(value) {
|
|
218
|
-
if (typeof value !== "string" || !VISIBILITIES.some((v) => v === value)) {
|
|
219
|
-
invalid("visibility", "must be public, recruiter or print");
|
|
220
|
-
}
|
|
221
|
-
return value;
|
|
222
|
-
}
|
|
223
|
-
var meta = (row) => ({
|
|
224
|
-
key: row.key,
|
|
225
|
-
label: row.label,
|
|
226
|
-
sortOrder: row.sortOrder,
|
|
227
|
-
visibility: row.visibility,
|
|
228
|
-
updatedAt: row.updatedAt
|
|
229
|
-
});
|
|
230
|
-
var PersonalInfoService = class {
|
|
231
|
-
constructor(repo, keyB64) {
|
|
232
|
-
this.repo = repo;
|
|
233
|
-
this.keyB64 = keyB64;
|
|
234
|
-
}
|
|
235
|
-
repo;
|
|
236
|
-
keyB64;
|
|
237
|
-
async list() {
|
|
238
|
-
return (await this.repo.list()).map(meta);
|
|
239
|
-
}
|
|
240
|
-
async create(input) {
|
|
241
|
-
if (!KEY_PATTERN.test(input.key ?? "")) invalid("key", "must match ^[A-Z][A-Z0-9_]{0,31}$");
|
|
242
|
-
if (await this.repo.find(input.key)) invalid("key", "already exists");
|
|
243
|
-
const label = requireText("label", input.label);
|
|
244
|
-
const value = requireText("value", input.value);
|
|
245
|
-
const visibility = requireVisibility(input.visibility);
|
|
246
|
-
const row = await this.repo.insert({
|
|
247
|
-
key: input.key,
|
|
248
|
-
label,
|
|
249
|
-
visibility,
|
|
250
|
-
sortOrder: input.sortOrder ?? 0,
|
|
251
|
-
valueEncrypted: await encrypt(value, this.keyB64)
|
|
252
|
-
});
|
|
253
|
-
return meta(row);
|
|
254
|
-
}
|
|
255
|
-
async update(key2, input) {
|
|
256
|
-
const patch = {};
|
|
257
|
-
if (input.label !== void 0) patch.label = requireText("label", input.label);
|
|
258
|
-
if (input.visibility !== void 0) patch.visibility = requireVisibility(input.visibility);
|
|
259
|
-
if (input.sortOrder !== void 0) patch.sortOrder = input.sortOrder;
|
|
260
|
-
if (input.value !== void 0) {
|
|
261
|
-
patch.valueEncrypted = await encrypt(requireText("value", input.value), this.keyB64);
|
|
262
|
-
}
|
|
263
|
-
const row = await this.repo.update(key2, patch);
|
|
264
|
-
if (!row) throw new NotFoundError(`Personal info ${key2} not found`);
|
|
265
|
-
return meta(row);
|
|
266
|
-
}
|
|
267
|
-
async delete(key2) {
|
|
268
|
-
if (!await this.repo.delete(key2)) throw new NotFoundError(`Personal info ${key2} not found`);
|
|
269
|
-
}
|
|
270
|
-
async reveal(key2) {
|
|
271
|
-
const row = await this.repo.find(key2);
|
|
272
|
-
if (!row) throw new NotFoundError(`Personal info ${key2} not found`);
|
|
273
|
-
return decrypt(row.valueEncrypted, this.keyB64);
|
|
274
|
-
}
|
|
275
|
-
async contactFor(channel) {
|
|
276
|
-
const visible = CHANNEL_VISIBILITIES[channel];
|
|
277
|
-
const rows = (await this.repo.list()).filter((r) => visible.includes(r.visibility));
|
|
278
|
-
return Promise.all(
|
|
279
|
-
rows.map(async (r) => ({
|
|
280
|
-
key: r.key,
|
|
281
|
-
label: r.label,
|
|
282
|
-
value: await decrypt(r.valueEncrypted, this.keyB64)
|
|
283
|
-
}))
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
/** Every decrypted value, for the PII Guard only. */
|
|
287
|
-
allValues() {
|
|
288
|
-
return this.contactFor("print");
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
// src/lib/markdown.ts
|
|
293
|
-
import { Marked } from "marked";
|
|
294
|
-
var ALLOWED_TAGS = /* @__PURE__ */ new Set([
|
|
295
|
-
"h1",
|
|
296
|
-
"h2",
|
|
297
|
-
"h3",
|
|
298
|
-
"h4",
|
|
299
|
-
"h5",
|
|
300
|
-
"h6",
|
|
301
|
-
"p",
|
|
302
|
-
"ul",
|
|
303
|
-
"ol",
|
|
304
|
-
"li",
|
|
305
|
-
"strong",
|
|
306
|
-
"em",
|
|
307
|
-
"a",
|
|
308
|
-
"code",
|
|
309
|
-
"pre",
|
|
310
|
-
"blockquote",
|
|
311
|
-
"hr",
|
|
312
|
-
"br"
|
|
313
|
-
]);
|
|
314
|
-
var VOID_TAGS = /* @__PURE__ */ new Set(["hr", "br"]);
|
|
315
|
-
var SAFE_HREF = /^(https?:|mailto:)/i;
|
|
316
|
-
var noRawHtml = {
|
|
317
|
-
html: () => void 0,
|
|
318
|
-
tag: () => void 0
|
|
319
|
-
};
|
|
320
|
-
var marked = new Marked({ gfm: true, async: false });
|
|
321
|
-
marked.use({ tokenizer: noRawHtml });
|
|
322
|
-
var escapeAttr = (s) => s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
323
|
-
var decodeEntities = (s) => s.replace(/"/g, '"').replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
324
|
-
function hrefOf(attrs) {
|
|
325
|
-
const m = /(?:^|\s)href\s*=\s*(?:"([^"]*)"|'([^']*)')/i.exec(attrs);
|
|
326
|
-
const raw = m?.[1] ?? m?.[2];
|
|
327
|
-
if (raw === void 0) return null;
|
|
328
|
-
const href = [...decodeEntities(raw)].filter((ch) => {
|
|
329
|
-
const code = ch.charCodeAt(0);
|
|
330
|
-
return code > 32 && (code < 127 || code > 159);
|
|
331
|
-
}).join("");
|
|
332
|
-
return SAFE_HREF.test(href) ? href : null;
|
|
333
|
-
}
|
|
334
|
-
function sanitize(html) {
|
|
335
|
-
return html.replace(
|
|
336
|
-
/<(\/?)([a-zA-Z][a-zA-Z0-9]*)((?:"[^"]*"|'[^']*'|[^>"'])*)>/g,
|
|
337
|
-
(_, slash, name, attrs) => {
|
|
338
|
-
const tag = String(name).toLowerCase();
|
|
339
|
-
if (!ALLOWED_TAGS.has(tag)) return "";
|
|
340
|
-
if (slash) return VOID_TAGS.has(tag) ? "" : `</${tag}>`;
|
|
341
|
-
if (tag === "a") {
|
|
342
|
-
const href = hrefOf(attrs);
|
|
343
|
-
return href === null ? "<a>" : `<a href="${escapeAttr(href)}">`;
|
|
344
|
-
}
|
|
345
|
-
return `<${tag}>`;
|
|
346
|
-
}
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
|
-
function renderMarkdown(markdown) {
|
|
350
|
-
return sanitize(marked.parse(markdown));
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// src/services/settings-keys.ts
|
|
354
|
-
var MODEL_AREAS = ["public", "tailor", "recruiter"];
|
|
355
|
-
var LIMIT_NAMES = [
|
|
356
|
-
"publicQuestionsPerIpPerDay",
|
|
357
|
-
"recruiterQuestionsDefault",
|
|
358
|
-
"publicMaxOutputTokens",
|
|
359
|
-
"recruiterMaxOutputTokens",
|
|
360
|
-
"maxQuestionChars",
|
|
361
|
-
"maxHistoryMessages",
|
|
362
|
-
"sessionTtlMinutes"
|
|
363
|
-
];
|
|
364
|
-
var PAGE_SIZES = ["A4", "Letter"];
|
|
365
|
-
var PAGE_SIZE_KEY = "print.pageSize";
|
|
366
|
-
var modelKey = (area) => `model.${area}`;
|
|
367
|
-
var limitKey = (name) => `limits.${name}`;
|
|
368
|
-
var SETTINGS_KEYS = [
|
|
369
|
-
...MODEL_AREAS.map(modelKey),
|
|
370
|
-
...LIMIT_NAMES.map(limitKey),
|
|
371
|
-
PAGE_SIZE_KEY
|
|
372
|
-
];
|
|
373
|
-
|
|
374
|
-
// src/security/session.ts
|
|
375
|
-
import { deleteCookie, setCookie } from "hono/cookie";
|
|
376
|
-
import { jwtVerify, SignJWT } from "jose";
|
|
377
|
-
var SESSION_COOKIE = "curr_session";
|
|
378
|
-
var ADMIN_COOKIE = "curr_admin";
|
|
379
|
-
var ADMIN_SESSION_SECONDS = 8 * 60 * 60;
|
|
380
|
-
var key = (secret) => new TextEncoder().encode(secret);
|
|
381
|
-
var SCOPES = ["public", "recruiter", "admin"];
|
|
382
|
-
async function signSession(payload, secret, ttlSeconds) {
|
|
383
|
-
const claims = { scope: payload.scope };
|
|
384
|
-
if (payload.cid !== void 0) claims.cid = payload.cid;
|
|
385
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
386
|
-
return new SignJWT(claims).setProtectedHeader({ alg: "HS256" }).setIssuedAt(now).setExpirationTime(now + ttlSeconds).sign(key(secret));
|
|
387
|
-
}
|
|
388
|
-
async function verifySession(token, secret) {
|
|
389
|
-
try {
|
|
390
|
-
const { payload } = await jwtVerify(token, key(secret), { algorithms: ["HS256"] });
|
|
391
|
-
const scope = payload.scope;
|
|
392
|
-
if (typeof scope !== "string" || !SCOPES.includes(scope)) return null;
|
|
393
|
-
const session = { scope };
|
|
394
|
-
if (typeof payload.cid === "string") session.cid = payload.cid;
|
|
395
|
-
return session;
|
|
396
|
-
} catch {
|
|
397
|
-
return null;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
function setSessionCookie(c, token, cfg) {
|
|
401
|
-
setCookie(c, SESSION_COOKIE, token, {
|
|
402
|
-
httpOnly: true,
|
|
403
|
-
sameSite: "Strict",
|
|
404
|
-
secure: cfg.secureCookies,
|
|
405
|
-
path: `${cfg.basePath}/api`,
|
|
406
|
-
maxAge: cfg.limits.sessionTtlMinutes * 60
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
function setAdminCookie(c, token, cfg) {
|
|
410
|
-
setCookie(c, ADMIN_COOKIE, token, {
|
|
411
|
-
httpOnly: true,
|
|
412
|
-
sameSite: "Strict",
|
|
413
|
-
secure: cfg.secureCookies,
|
|
414
|
-
path: `${cfg.basePath}/admin`,
|
|
415
|
-
maxAge: ADMIN_SESSION_SECONDS
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
function clearAdminCookie(c, cfg) {
|
|
419
|
-
deleteCookie(c, ADMIN_COOKIE, {
|
|
420
|
-
httpOnly: true,
|
|
421
|
-
sameSite: "Strict",
|
|
422
|
-
secure: cfg.secureCookies,
|
|
423
|
-
path: `${cfg.basePath}/admin`
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
export {
|
|
428
|
-
DomainError,
|
|
429
|
-
ValidationError,
|
|
430
|
-
UnauthorizedError,
|
|
431
|
-
ForbiddenError,
|
|
432
|
-
CaptchaFailedError,
|
|
433
|
-
NotFoundError,
|
|
434
|
-
ChatRevokedError,
|
|
435
|
-
ChatExpiredError,
|
|
436
|
-
LimitReachedError,
|
|
437
|
-
LlmUnavailableError,
|
|
438
|
-
PiiLeakError,
|
|
439
|
-
ConfigError,
|
|
440
|
-
DecryptionError,
|
|
441
|
-
clientIp,
|
|
442
|
-
hashIp,
|
|
443
|
-
findPii,
|
|
444
|
-
redactPii,
|
|
445
|
-
VISIBILITIES,
|
|
446
|
-
PersonalInfoService,
|
|
447
|
-
renderMarkdown,
|
|
448
|
-
MODEL_AREAS,
|
|
449
|
-
LIMIT_NAMES,
|
|
450
|
-
PAGE_SIZES,
|
|
451
|
-
PAGE_SIZE_KEY,
|
|
452
|
-
modelKey,
|
|
453
|
-
limitKey,
|
|
454
|
-
SETTINGS_KEYS,
|
|
455
|
-
SESSION_COOKIE,
|
|
456
|
-
ADMIN_COOKIE,
|
|
457
|
-
ADMIN_SESSION_SECONDS,
|
|
458
|
-
signSession,
|
|
459
|
-
verifySession,
|
|
460
|
-
setSessionCookie,
|
|
461
|
-
setAdminCookie,
|
|
462
|
-
clearAdminCookie
|
|
463
|
-
};
|