Initial commit: Korrith website, assessment API, PocketBase schema, Docker/Coolify deployment

This commit is contained in:
Korrith
2026-09-17 20:47:51 +00:00
commit c17f11f591
248 changed files with 39721 additions and 0 deletions
@@ -0,0 +1,20 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
let settings = app.settings()
settings.meta.appName = "f7b2aa49-1077-4692-8b37-dae2a255116c.app-preview.com"
settings.meta.appURL = "https://f7b2aa49-1077-4692-8b37-dae2a255116c.app-preview.com/hcgi/platform"
settings.meta.hideControls = true
settings.logs.maxDays = 7
settings.logs.minLevel = 8
settings.logs.logIP = true
settings.trustedProxy.headers = [
"X-Real-IP",
"X-Forwarded-For",
"CF-Connecting-IP",
]
app.save(settings)
})
@@ -0,0 +1,10 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const superusers = app.findCollectionByNameOrId("_superusers")
const record = new Record(superusers)
record.set("email", $os.getenv("PB_SUPERUSER_EMAIL"))
record.set("password", $os.getenv("PB_SUPERUSER_PASSWORD"))
app.save(record)
})
@@ -0,0 +1,10 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const superusers = app.findCollectionByNameOrId("_superusers")
superusers.authAlert = {
enabled: false,
}
app.save(superusers)
})
@@ -0,0 +1,55 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
let settings = app.settings()
settings.rateLimits = {
enabled: true,
rules: [
// General API limit - 200 requests per 5 minutes
{
label: "/api",
audience: "",
duration: 5 * 60, // 5 minutes
maxRequests: 200
},
// Brute force protection for auth attempts - 20 attempts per 5 minutes (guests only)
{
label: "*:auth",
audience: "@guest", // Only for unauthenticated users
duration: 5 * 60, // 15 minutes
maxRequests: 20
},
// Password reset - 5 per hour
{
label: "POST /api/collections/users/request-password-reset",
audience: "",
duration: 60 * 60, // 1 hour
maxRequests: 5
},
// Email verification - 5 per hour
{
label: "POST /api/collections/users/request-verification",
audience: "",
duration: 60 * 60, // 1 hour
maxRequests: 5
},
// Email change - 3 per hour (authenticated only)
{
label: "POST /api/collections/users/request-email-change",
audience: "@auth",
duration: 60 * 60, // 1 hour
maxRequests: 3
},
// OTP - 10 per hour
{
label: "POST /api/collections/users/request-otp",
audience: "",
duration: 60 * 60, // 1 hour
maxRequests: 10
}
]
}
app.save(settings)
})
@@ -0,0 +1,19 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
let usersCollection
try {
usersCollection = app.findCollectionByNameOrId("users")
usersCollection.authAlert = {
enabled: false,
}
} catch (error) {
if (error.message.includes("no rows in result set")) {
return
}
throw error
}
app.save(usersCollection)
})
@@ -0,0 +1,159 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = new Collection({
"createRule": "",
"deleteRule": "@request.auth.collectionName = 'users' && @request.auth.role = 'admin'",
"fields": [
{
"autogeneratePattern": "[a-z0-9]{15}",
"hidden": false,
"id": "text9973129546",
"max": 15,
"min": 15,
"name": "id",
"pattern": "^[a-z0-9]+$",
"presentable": false,
"primaryKey": true,
"required": true,
"system": true,
"type": "text"
},
{
"hidden": false,
"id": "text7224323192",
"name": "firstName",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "text",
"autogeneratePattern": "",
"max": 0,
"min": 0,
"pattern": ""
},
{
"hidden": false,
"id": "text8927180967",
"name": "lastName",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "text",
"autogeneratePattern": "",
"max": 0,
"min": 0,
"pattern": ""
},
{
"hidden": false,
"id": "email3000958229",
"name": "email",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "email",
"exceptDomains": [],
"onlyDomains": []
},
{
"hidden": false,
"id": "json4467574208",
"name": "websites",
"presentable": false,
"primaryKey": false,
"required": false,
"system": false,
"type": "json",
"maxSize": 0
},
{
"hidden": false,
"id": "json7565497650",
"name": "apps",
"presentable": false,
"primaryKey": false,
"required": false,
"system": false,
"type": "json",
"maxSize": 0
},
{
"hidden": false,
"id": "json2686026609",
"name": "systems",
"presentable": false,
"primaryKey": false,
"required": false,
"system": false,
"type": "json",
"maxSize": 0
},
{
"hidden": false,
"id": "text2579574645",
"name": "industry",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "text",
"autogeneratePattern": "",
"max": 0,
"min": 0,
"pattern": ""
},
{
"hidden": false,
"id": "autodate2823430259",
"name": "created",
"onCreate": true,
"onUpdate": false,
"presentable": false,
"system": false,
"type": "autodate"
},
{
"hidden": false,
"id": "autodate7741794431",
"name": "updated",
"onCreate": true,
"onUpdate": true,
"presentable": false,
"system": false,
"type": "autodate"
}
],
"id": "pbc_3506166606",
"indexes": [],
"listRule": "@request.auth.collectionName = 'users' && @request.auth.role = 'admin'",
"name": "assessments",
"system": false,
"type": "base",
"updateRule": "@request.auth.collectionName = 'users' && @request.auth.role = 'admin'",
"viewRule": "@request.auth.collectionName = 'users' && @request.auth.role = 'admin'"
});
try {
return app.save(collection);
} catch (e) {
if (e.message.includes("Collection name must be unique")) {
console.log("Collection already exists, skipping");
return;
}
throw e;
}
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("pbc_3506166606");
return app.delete(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,22 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("websites");
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.add(new JSONField({
name: "websites",
required: false
}));
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,22 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("apps");
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.add(new JSONField({
name: "apps",
required: false
}));
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,22 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("systems");
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.add(new JSONField({
name: "systems",
required: false
}));
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,22 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("websites");
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.add(new JSONField({
name: "websites",
required: false
}));
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,22 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("apps");
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.add(new JSONField({
name: "apps",
required: false
}));
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,22 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("systems");
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.add(new JSONField({
name: "systems",
required: false
}));
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,31 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
const existing = collection.fields.getByName("websites_text");
if (existing) {
if (existing.type === "text") {
return; // field already exists with correct type, skip
}
collection.fields.removeByName("websites_text"); // exists with wrong type, remove first
}
collection.fields.add(new TextField({
name: "websites_text",
required: true
}));
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("websites_text");
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,31 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
const existing = collection.fields.getByName("apps_text");
if (existing) {
if (existing.type === "text") {
return; // field already exists with correct type, skip
}
collection.fields.removeByName("apps_text"); // exists with wrong type, remove first
}
collection.fields.add(new TextField({
name: "apps_text",
required: true
}));
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("apps_text");
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,31 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
const existing = collection.fields.getByName("systems_text");
if (existing) {
if (existing.type === "text") {
return; // field already exists with correct type, skip
}
collection.fields.removeByName("systems_text"); // exists with wrong type, remove first
}
collection.fields.add(new TextField({
name: "systems_text",
required: true
}));
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("systems_text");
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,22 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("websites");
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.add(new JSONField({
name: "websites",
required: false
}));
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,22 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("apps");
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.add(new JSONField({
name: "apps",
required: false
}));
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,22 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("systems");
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.add(new JSONField({
name: "systems",
required: false
}));
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,22 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("websites");
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.add(new JSONField({
name: "websites",
required: false
}));
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,22 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("apps");
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.add(new JSONField({
name: "apps",
required: false
}));
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,22 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.removeByName("systems");
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
collection.fields.add(new JSONField({
name: "systems",
required: false
}));
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,16 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
return app.delete(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping delete");
return;
}
throw e;
}
}, (app) => {
// Note: The down migration cannot restore data, only the collection structure
// You would need to manually recreate the collection structure here if needed
})
@@ -0,0 +1,16 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
return app.delete(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping delete");
return;
}
throw e;
}
}, (app) => {
// Note: The down migration cannot restore data, only the collection structure
// You would need to manually recreate the collection structure here if needed
})
@@ -0,0 +1,170 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = new Collection({
"createRule": "",
"deleteRule": "@request.auth.collectionName = 'users' && @request.auth.role = 'admin'",
"fields": [
{
"autogeneratePattern": "[a-z0-9]{15}",
"hidden": false,
"id": "text3930877004",
"max": 15,
"min": 15,
"name": "id",
"pattern": "^[a-z0-9]+$",
"presentable": false,
"primaryKey": true,
"required": true,
"system": true,
"type": "text"
},
{
"hidden": false,
"id": "text9496940303",
"name": "firstName",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "text",
"autogeneratePattern": "",
"max": 0,
"min": 0,
"pattern": ""
},
{
"hidden": false,
"id": "text6526030650",
"name": "lastName",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "text",
"autogeneratePattern": "",
"max": 0,
"min": 0,
"pattern": ""
},
{
"hidden": false,
"id": "text1504649217",
"name": "email",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "text",
"autogeneratePattern": "",
"max": 0,
"min": 0,
"pattern": ""
},
{
"hidden": false,
"id": "text3766238150",
"name": "industry",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "text",
"autogeneratePattern": "",
"max": 0,
"min": 0,
"pattern": ""
},
{
"hidden": false,
"id": "text0206998537",
"name": "websites",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "text",
"autogeneratePattern": "",
"max": 0,
"min": 0,
"pattern": ""
},
{
"hidden": false,
"id": "text1142803244",
"name": "applications",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "text",
"autogeneratePattern": "",
"max": 0,
"min": 0,
"pattern": ""
},
{
"hidden": false,
"id": "text6766822077",
"name": "systems",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "text",
"autogeneratePattern": "",
"max": 0,
"min": 0,
"pattern": ""
},
{
"hidden": false,
"id": "autodate1878312857",
"name": "created",
"onCreate": true,
"onUpdate": false,
"presentable": false,
"system": false,
"type": "autodate"
},
{
"hidden": false,
"id": "autodate5206414872",
"name": "updated",
"onCreate": true,
"onUpdate": true,
"presentable": false,
"system": false,
"type": "autodate"
}
],
"id": "pbc_6716256996",
"indexes": [],
"listRule": "@request.auth.collectionName = 'users' && @request.auth.role = 'admin'",
"name": "assessments",
"system": false,
"type": "base",
"updateRule": "@request.auth.collectionName = 'users' && @request.auth.role = 'admin'",
"viewRule": "@request.auth.collectionName = 'users' && @request.auth.role = 'admin'"
});
try {
return app.save(collection);
} catch (e) {
if (e.message.includes("Collection name must be unique")) {
console.log("Collection already exists, skipping");
return;
}
throw e;
}
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("pbc_6716256996");
return app.delete(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,21 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
const field = collection.fields.getByName("websites");
field.required = false;
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
const field = collection.fields.getByName("websites");
if (!field) { console.log("Field not found, skipping revert"); return; }
field.required = true;
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection or field not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,21 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
const field = collection.fields.getByName("applications");
field.required = false;
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
const field = collection.fields.getByName("applications");
if (!field) { console.log("Field not found, skipping revert"); return; }
field.required = true;
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection or field not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,21 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
const field = collection.fields.getByName("systems");
field.required = false;
return app.save(collection);
}, (app) => {
try {
const collection = app.findCollectionByNameOrId("assessments");
const field = collection.fields.getByName("systems");
if (!field) { console.log("Field not found, skipping revert"); return; }
field.required = true;
return app.save(collection);
} catch (e) {
if (e.message.includes("no rows in result set")) {
console.log("Collection or field not found, skipping revert");
return;
}
throw e;
}
})
@@ -0,0 +1,32 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("assessments");
const record0 = new Record(collection);
record0.id = "zlolg0zav7yhepz";
record0.set("firstName", "John");
record0.set("lastName", "Doe");
record0.set("email", "john@example.com");
record0.set("industry", "Technology");
try {
app.save(record0);
} catch (e) {
if (e.message.includes("Value must be unique")) {
console.log("Record with unique value already exists, skipping");
} else {
throw e;
}
}
}, (app) => {
const seededRecordIds = ["zlolg0zav7yhepz"];
for (const seededRecordId of seededRecordIds) {
try {
app.delete(app.findRecordById("assessments", seededRecordId));
} catch (error) {
if (error.message.includes("no rows in result set")) {
continue;
}
throw error;
}
}
})