Compare commits

..
10 Commits
Author SHA1 Message Date
RoyDumblauskas 562ec61802 enforce unique position per article 2026-08-22 18:14:26 -05:00
RoyDumblauskas 6f21248132 render articles 2026-08-22 17:57:54 -05:00
RoyDumblauskas 1073b794d6 adding permissions layer 2026-07-07 01:24:14 -05:00
RoyDumblauskas 1e43be14bd auth cleanup 2026-07-04 00:28:31 -05:00
RoyDumblauskas 4149e13337 logout/signup 2026-07-03 22:30:33 -05:00
RoyDumblauskas af4004040c refresh token 2026-07-03 21:42:37 -05:00
RoyDumblauskas 2ba686debe remove logging 2026-06-29 00:45:36 -05:00
RoyDumblauskas deddb7e113 cleanup and env example 2026-06-29 00:32:41 -05:00
RoyDumblauskas 29f0d38787 complete login endpoint 2026-06-29 00:27:51 -05:00
RoyDumblauskas 5cbaef08d0 move jwt type extension 2026-06-28 20:29:51 -05:00
34 changed files with 1870 additions and 1162 deletions
+6
View File
@@ -0,0 +1,6 @@
PORT=number
JWT_SECRET=string
DATABASE_URL=postgresqlConnectionString
PASSWORD_HASH_SECRET=verySecretHash
PRESALT=prepend
POSTSALT=postpend
+244 -162
View File
@@ -13,6 +13,7 @@
"drizzle-orm": "^1.0.0-rc.4",
"express": "^5.1.0",
"pg": "^8.22.0",
"typescript": "^6.0.3",
"uuid": "^13.0.0"
},
"devDependencies": {
@@ -24,9 +25,9 @@
}
},
"node_modules/@drizzle-team/brocli": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@drizzle-team/brocli/-/brocli-0.11.0.tgz",
"integrity": "sha512-hD3pekGiPg0WPCCGAZmusBBJsDqGUR66Y452YgQsZOnkdQ7ViEPKuyP4huUGEZQefp8g34RRodXYmJ2TbCH+tg==",
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/@drizzle-team/brocli/-/brocli-0.12.0.tgz",
"integrity": "sha512-mlUE+rZ8CatQekLhnaiN91Iemdd+e2gFKooGlnRB3oPTL3VghLfX24dx7HrzMNeC1JrIB/0kpsfyty3f5HNfxQ==",
"dev": true,
"license": "Apache-2.0"
},
@@ -519,9 +520,9 @@
}
},
"node_modules/@types/express-serve-static-core": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-5.1.1.tgz",
"integrity": "sha512-v4zIMr/cX7/d2BpAEX3KNKL/JrT1s43s96lLvvdTmza1oEvDudCqK9aF/djc/SWgy8Yh0h30TZx5VpzqFCxk5A==",
"version": "5.1.3",
"resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-5.1.3.tgz",
"integrity": "sha512-dPfW8NFiOF4wOHc7+N/QSxlY9cfSsenewGbAz8C8U/MULPd/YZ27LvJUIlzaXie7e6Ove9YunJGgC9tbHD2cKw==",
"dev": true,
"license": "MIT",
"dependencies": {
@@ -539,9 +540,9 @@
"license": "MIT"
},
"node_modules/@types/node": {
"version": "24.13.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.13.2.tgz",
"integrity": "sha512-fRa09kZTgu8o71KFcDjUFuc7F+dEbZYZmkI0mg5YBTRs0yMKjYHsq/c0urDKeDb+D5qVgXOdFcuu+DZPKOITwA==",
"version": "24.13.3",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.13.3.tgz",
"integrity": "sha512-Dh8vAsV36ig5wa9OX4pXvMc9D3Veibfw2wix0CUwYODLD8nkj9UsLjASr49nPg+2eKzxhBV+v7L8pXvT4e639Q==",
"devOptional": true,
"license": "MIT",
"dependencies": {
@@ -549,9 +550,9 @@
}
},
"node_modules/@types/pg": {
"version": "8.20.0",
"resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.20.0.tgz",
"integrity": "sha512-bEPFOaMAHTEP1EzpvHTbmwR8UsFyHSKsRisLIHVMXnpNefSbGA1bD6CVy+qKjGSqmZqNqBDV2azOBo8TgkcVow==",
"version": "8.23.1",
"resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.23.1.tgz",
"integrity": "sha512-fKVHpikPdg4GKks3JuLEhvwSyvwzF23hnabPy6DD8ljVbC7+6J5dQzdv4arV6jqq57djnMgs1HKBxX4P8aBI3A==",
"devOptional": true,
"license": "MIT",
"dependencies": {
@@ -633,9 +634,9 @@
}
},
"node_modules/body-parser/node_modules/content-type": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-2.0.0.tgz",
"integrity": "sha512-j/O/d7GcZCyNl7/hwZAb606rzqkyvaDctLmckbxLzHvFBzTJHuGEdodATcP3yIRoDrLHkIATJuvzbFlp/ki2cQ==",
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz",
"integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==",
"license": "MIT",
"engines": {
"node": ">=18"
@@ -762,13 +763,13 @@
}
},
"node_modules/drizzle-kit": {
"version": "1.0.0-rc.4-ca0f029",
"resolved": "https://registry.npmjs.org/drizzle-kit/-/drizzle-kit-1.0.0-rc.4-ca0f029.tgz",
"integrity": "sha512-hM1K72ptIPOpJDScHo7cAF+K8A8Tr3q2yHvBJvOZWvLn2lN+G4RDUvG3rT3ohlSE2O3BN/s7g3e3JiQLStt8iQ==",
"version": "1.0.0-rc.5-ab785fc",
"resolved": "https://registry.npmjs.org/drizzle-kit/-/drizzle-kit-1.0.0-rc.5-ab785fc.tgz",
"integrity": "sha512-TSg7sK1finOxdo48O9mDfyMY3lhi/aHCVIil5TFhthyq/H/89H/3nwX5V9Gdp7HYMUGFHyWJD5iowSn98l0elw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@drizzle-team/brocli": "^0.11.0",
"@drizzle-team/brocli": "^0.12.0",
"@js-temporal/polyfill": "^0.5.1",
"esbuild": "^0.25.10",
"get-tsconfig": "^4.13.6",
@@ -779,27 +780,37 @@
}
},
"node_modules/drizzle-orm": {
"version": "1.0.0-rc.4-5d5b77c",
"resolved": "https://registry.npmjs.org/drizzle-orm/-/drizzle-orm-1.0.0-rc.4-5d5b77c.tgz",
"integrity": "sha512-Oq9W4B11PracWY9cuCLTFT+JA5kXqR6rBmWcM8oh0xwLgCviVl9wh6ZuWX7Zpv1Jir/8W+M37syvjSYtj1f5iA==",
"version": "1.0.0-rc.5-ab785fc",
"resolved": "https://registry.npmjs.org/drizzle-orm/-/drizzle-orm-1.0.0-rc.5-ab785fc.tgz",
"integrity": "sha512-28PVt0PS/+4kPa8eKr4mqP8y/YcbdOgdVcGUa6LGl2Kd2bykNWuf/WUOFoSCoynagblbcRgMO1zChLvRcWD6Tg==",
"license": "Apache-2.0",
"peerDependencies": {
"@aws-sdk/client-rds-data": ">=3",
"@cloudflare/workers-types": ">=4",
"@effect/sql-pg": ">=4.0.0-beta.58 || >=4.0.0",
"@effect/sql-d1": ">=4.0.0-beta.105 || >=4.0.0",
"@effect/sql-libsql": ">=4.0.0-beta.105 || >=4.0.0",
"@effect/sql-mysql2": ">=4.0.0-beta.105 || >=4.0.0",
"@effect/sql-pg": ">=4.0.0-beta.105 || >=4.0.0",
"@effect/sql-pglite": ">=4.0.0-beta.105 || >=4.0.0",
"@effect/sql-sqlite-bun": ">=4.0.0-beta.105 || >=4.0.0",
"@effect/sql-sqlite-do": ">=4.0.0-beta.105 || >=4.0.0",
"@effect/sql-sqlite-node": ">=4.0.0-beta.105 || >=4.0.0",
"@effect/sql-sqlite-wasm": ">=4.0.0-beta.105 || >=4.0.0",
"@electric-sql/pglite": ">=0.2.0",
"@libsql/client": ">=0.10.0",
"@libsql/client-wasm": ">=0.10.0",
"@neondatabase/serverless": ">=0.10.0",
"@op-engineering/op-sqlite": ">=2",
"@op-engineering/op-sqlite": ">=17",
"@opentelemetry/api": "^1.4.1",
"@planetscale/database": ">=1.13",
"@sinclair/typebox": ">=0.34.8",
"@sqlitecloud/drivers": ">=1.0.653",
"@tidbcloud/serverless": "*",
"@tursodatabase/database": ">=0.2.1",
"@tursodatabase/database-common": ">=0.2.1",
"@tursodatabase/database-wasm": ">=0.2.1",
"@tursodatabase/database": ">=0.7.1",
"@tursodatabase/database-common": ">=0.7.1",
"@tursodatabase/database-wasm": ">=0.7.1",
"@tursodatabase/serverless": ">=1.4.0",
"@tursodatabase/sync": ">=0.7.1",
"@types/better-sqlite3": "*",
"@types/mssql": "^9.1.4",
"@types/pg": "*",
@@ -810,15 +821,16 @@
"arktype": ">=2.0.0",
"better-sqlite3": ">=9.3.0",
"bun-types": "*",
"effect": ">=4.0.0-beta.58 || >=4.0.0",
"effect": ">=4.0.0-beta.105 || >=4.0.0",
"expo-sqlite": ">=14.0.0",
"minipg": ">=0.2.0",
"mssql": "^11.0.1",
"mysql2": ">=2",
"pg": ">=8",
"postgres": ">=3",
"sql.js": ">=1",
"sqlite3": ">=5",
"typebox": ">=1.0.0",
"typebox": ">=1.2.0",
"valibot": ">=1.0.0-beta.7",
"zod": "^3.25.0 || ^4.0.0"
},
@@ -829,9 +841,33 @@
"@cloudflare/workers-types": {
"optional": true
},
"@effect/sql-d1": {
"optional": true
},
"@effect/sql-libsql": {
"optional": true
},
"@effect/sql-mysql2": {
"optional": true
},
"@effect/sql-pg": {
"optional": true
},
"@effect/sql-pglite": {
"optional": true
},
"@effect/sql-sqlite-bun": {
"optional": true
},
"@effect/sql-sqlite-do": {
"optional": true
},
"@effect/sql-sqlite-node": {
"optional": true
},
"@effect/sql-sqlite-wasm": {
"optional": true
},
"@electric-sql/pglite": {
"optional": true
},
@@ -871,6 +907,12 @@
"@tursodatabase/database-wasm": {
"optional": true
},
"@tursodatabase/serverless": {
"optional": true
},
"@tursodatabase/sync": {
"optional": true
},
"@types/better-sqlite3": {
"optional": true
},
@@ -907,6 +949,9 @@
"expo-sqlite": {
"optional": true
},
"minipg": {
"optional": true
},
"mssql": {
"optional": true
},
@@ -1196,9 +1241,9 @@
}
},
"node_modules/get-tsconfig": {
"version": "4.14.0",
"resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.14.0.tgz",
"integrity": "sha512-yTb+8DXzDREzgvYmh6s9vHsSVCHeC0G3PI5bEXNBHtmshPnO+S5O7qgLEOn0I5QvMy6kpZN8K1NKGyilLb93wA==",
"version": "4.14.3",
"resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.14.3.tgz",
"integrity": "sha512-++QEw4DIY7WGoukz+/+A/8dGYPT9l9yIadnmSgZ8Rjr3YVSVDipQSO9CdnJo9ePqFqUUqh+wk9uIaoiAwsiPkA==",
"dev": true,
"license": "MIT",
"dependencies": {
@@ -1265,9 +1310,9 @@
}
},
"node_modules/iconv-lite": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz",
"integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==",
"version": "0.7.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.3.tgz",
"integrity": "sha512-IKXpvIzjnC9XTAUbVBcMfGS0EPaIXtW6v+zr+RRp+hqULEpo0owZax6wyRwPOJbWbzjYspQwusTsfVr0ifh4uQ==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
@@ -1328,12 +1373,16 @@
}
},
"node_modules/media-typer": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz",
"integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==",
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.1.tgz",
"integrity": "sha512-yz3xRaG20c6/BOzvYoDaGtPmGscs7YivItZEEqe6GbwNfHuxu9YNmvnEkMzKldAGY4/80pRcQRZSEnhquk9XuQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/merge-descriptors": {
@@ -1380,12 +1429,32 @@
"license": "MIT"
},
"node_modules/negotiator": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz",
"integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==",
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.1.0.tgz",
"integrity": "sha512-NMPBRMJgiQHjbd8phG3Vebdx4kZ1H121rbl5IkMqeOsahptB9BKo/d7oJ3zTXqTgagn2bWlNSXkh0QUGM31RYg==",
"license": "MIT",
"dependencies": {
"content-type": "^2.1.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/negotiator/node_modules/content-type": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz",
"integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/object-inspect": {
@@ -1441,14 +1510,14 @@
}
},
"node_modules/pg": {
"version": "8.22.0",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.22.0.tgz",
"integrity": "sha512-8wih1vVIBMxoUM2oB4soJsD9tDnDpLv4OXBJ+EJzFsvycD+lfyIreC2gGHq78f8jbLLt+bvlPTFdFZfJkOuzAA==",
"version": "8.23.0",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.23.0.tgz",
"integrity": "sha512-Ip2EQCngowJLGOfCwkFhPXU7/ljlhn6Rxlmy4XYfL2Y+vyRM59+8uR2xqRWKdYmbXmxCFOAmKxBuSUCdF34qLg==",
"license": "MIT",
"dependencies": {
"pg-connection-string": "^2.14.0",
"pg-pool": "^3.14.0",
"pg-protocol": "^1.15.0",
"pg-protocol": "^1.16.0",
"pg-types": "2.2.0",
"pgpass": "1.0.5"
},
@@ -1499,9 +1568,9 @@
}
},
"node_modules/pg-protocol": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.15.0.tgz",
"integrity": "sha512-cq9sECI5s0+uPUXjbz8ioyPJni6RzsRib0US67i5IoTZKw8fNeYlVE7u8F4dG7vEJJtc5wdD1K189lCCUwqWTQ==",
"version": "1.16.0",
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.16.0.tgz",
"integrity": "sha512-sILXutLVjCLjcDuOmvhX5e2Z4cS5qG/6Bu3VkpFwdf/633ElGLpEh9bgmuI5I4sqKqkifQiGyiCcx1HdtrK7tg==",
"license": "MIT"
},
"node_modules/pg-types": {
@@ -1808,9 +1877,9 @@
}
},
"node_modules/tsx": {
"version": "4.22.4",
"resolved": "https://registry.npmjs.org/tsx/-/tsx-4.22.4.tgz",
"integrity": "sha512-X8EX+XV4QR5xCsrgxaED954zTDfY8KqlDtskKEL0cHhyS/P8b4IFOvGDQpsC9Q1XnLq915wEfwwY/zzskCtmhg==",
"version": "4.23.12",
"resolved": "https://registry.npmjs.org/tsx/-/tsx-4.23.12.tgz",
"integrity": "sha512-FDf4L4sYzKtzWYhU/Xm0AQFdTjdIxNo9ElTf2mxXM6k8YMHXzYUe4yODVaXP4V9uMFbVg8c0qyBccK2OOxb45Q==",
"dev": true,
"license": "MIT",
"dependencies": {
@@ -1827,9 +1896,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/aix-ppc64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.1.tgz",
"integrity": "sha512-Svl7tq8k/08+p6CXPpRjQ1fKX+1odH/BQbb48fV6fj3CWHhsoIOoY87w1oHXm0qEpkIK3ZfVgp0hed3XBXzXMQ==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.2.tgz",
"integrity": "sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ==",
"cpu": [
"ppc64"
],
@@ -1844,9 +1913,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/android-arm": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.1.tgz",
"integrity": "sha512-0k2F129Xdio1TdJfzJ8sy1Q47vUD2NnwdhiAf7drUN1EBTfPf4hsFCtmMgu/6m8JSzsBrlmVjudMBQqOfG8usQ==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.2.tgz",
"integrity": "sha512-kXXoiPVVGQcnIYGOeaovwOURpniDBpSq4A03qkQ+BMQqtGG6HYap3xne9C1O1yo4TR3qxlCX5IqqmX6fFo2Lqg==",
"cpu": [
"arm"
],
@@ -1861,9 +1930,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/android-arm64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.1.tgz",
"integrity": "sha512-34EGEbCIAgosYz6goLcopX6Mo7NyGv9tfwEM2/7Ce2VcVRk568iSvniGWcUXIy7wEDR1wzolcxcriFVrWYcwBg==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.2.tgz",
"integrity": "sha512-5YfKeeI8qWfBZIX+u2xZC3Zlb3Os/gLS2sbEKM+I4ZOcsWmHS2WLysCcQZDAFRslDUU5Oiq44gf6PYN1vGwG5A==",
"cpu": [
"arm64"
],
@@ -1878,9 +1947,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/android-x64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.1.tgz",
"integrity": "sha512-dbwY7ltSMDWsRatcRpCnES4F+im88OCUgGZjy52shC7GqHRE/cYlxNbB4Z4UpJswpcc4Qxd2oE/ufM0p61IKng==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.2.tgz",
"integrity": "sha512-O387ite7SzUyCcy3JQX4P4bLtEA7bLLkx+esve5JHnyYfNTxcVpXZo9jhdB0lTKN44gztELTdU7nS8Nr16Fs1Q==",
"cpu": [
"x64"
],
@@ -1895,9 +1964,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/darwin-arm64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.1.tgz",
"integrity": "sha512-TZbWkQY7kvTAXbXUT7uVACR5cMHsDiSz9z7ZKAX/RTq/WJEk3QyRr0wZpNhBDX+/0CtdqUIJlOiodQcta6tY3Q==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.2.tgz",
"integrity": "sha512-n4KqkOQrraxHJcgjM1RvwbigfQKIKJVpM7xp+KsxiyUSrRdIXnt73VhrPAx0fV44hgfmIVKjxMN9J1t5jySVkw==",
"cpu": [
"arm64"
],
@@ -1912,9 +1981,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/darwin-x64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.1.tgz",
"integrity": "sha512-zfdzgK9ACBNZLI/CyHTOx81SyNbM6YXn7rxSgX97VjyiPl9W1i4Ka4fgKECEoFCKGpvBj5qArWIGgQjOwkgskQ==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.2.tgz",
"integrity": "sha512-uq6suIWYP37qzGddBKPw5QEQPi6HiLGsO7UmkpfyaYNQ3D+rN6w6WfwH+nuqcGXWvawGwxOEroO4YGnFh95azw==",
"cpu": [
"x64"
],
@@ -1929,9 +1998,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/freebsd-arm64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.1.tgz",
"integrity": "sha512-wG2EA8ENdEI0qhkSZMjfqrdY+ziCYCPMmtZjjIwOmXFjmyzEHn+UUxk5of+SYsjtfs3VpnlC7QLzSI5hY/rOAw==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.2.tgz",
"integrity": "sha512-n+I0BTSRIoy+d6RPKnEVwql5UwBJolytvY4mAOIEJorKlqgPII8ix6slVVrfZ5Tnj7glIZvloylbB/EJPMWEXw==",
"cpu": [
"arm64"
],
@@ -1946,9 +2015,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/freebsd-x64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.1.tgz",
"integrity": "sha512-i7dZ9vQgnvSCzi/rYCXNgtF/U+eKZNJBzu3eTQbRgHnM7tNSizLOkRFAl3qzVc/Op/u5YkHHa4pf/3DOYHthLQ==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.2.tgz",
"integrity": "sha512-78XJTJkvPs0kz2w61301PJjXl4g7q3JqiYMZ/M/yVI73EHBrCRTgkhu9oqG7vPqq+a/yadEW8aD+agKlk5xrmg==",
"cpu": [
"x64"
],
@@ -1963,9 +2032,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/linux-arm": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.1.tgz",
"integrity": "sha512-qVXBOHQS+d5Y722GwJzJUtOLlX7km3CraOaGormF1pDtPd2C/l1SHRPgjLunLGe51Sh5YYWKMFDyV4SxgMQYTQ==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.2.tgz",
"integrity": "sha512-XlDnu2q5yoqems+xay6wSAcg9DDD7K9RLKZEBOMZm3ckNpJBvOX20tSfby8KfrrhINDyv9V2YVZKY/SpoGJI8w==",
"cpu": [
"arm"
],
@@ -1980,9 +2049,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/linux-arm64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.1.tgz",
"integrity": "sha512-yHs+0uc8+nvEAfAfxrWQKK5peSNzBc4PegcMO0EJ2hT71uA7vB8Ihg2e77R2P7SG5uYjPbHlLLmve4LLLRCf0g==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.2.tgz",
"integrity": "sha512-pW4AC0P3it8c7do9MVM4p51FzHzdM/TZrerurgRcHJ2WTa1VQ1CIq18xncfpBJw4ojkiZZrKW2yIBWBP92j6Ug==",
"cpu": [
"arm64"
],
@@ -1997,9 +2066,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/linux-ia32": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.1.tgz",
"integrity": "sha512-d1z4ZuP0ajrfz/FhGT4vv278rX8KnPPJx8i5+AtK7TYbx9Le9F1hyzurZpkEyjkGa9dUGhQow4C1NmeGvqxN2w==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.2.tgz",
"integrity": "sha512-CYbnj78HsIeA+DhgUKgFCfvNsTHFhMMrinUrMZpDXJXKN8T3XViTZ/+wtHeVxEWY8ewSzTFN+nRmSwO2tZaLUQ==",
"cpu": [
"ia32"
],
@@ -2014,9 +2083,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/linux-loong64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.1.tgz",
"integrity": "sha512-M5sRjUVZrkm1OAPR3dlOYzNmN+loZKGVi1VUQGrwuqLcbR6qeAz+famMhjASeH3YVKvZz+zT1jlh/keC3Rj/lg==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.2.tgz",
"integrity": "sha512-buwkd8nsph4R+ajRvw0qM5Hja/TXQow3ptzWO2EbG/cqcIkHloRrdlBtQlshyYGTNFvfkfJ5tpPLVkY4DtsPfQ==",
"cpu": [
"loong64"
],
@@ -2031,9 +2100,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/linux-mips64el": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.1.tgz",
"integrity": "sha512-mRObBZeHh2OxcBFPWE/FjylkRgZdYuiTR3vaTozquCGOH14iP9oN4x4Ge81CoIDYQrXmIxpFumJBu5MtZpnQJQ==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.2.tgz",
"integrity": "sha512-ZVykbDyk7519VwiNb9Lcj9m8XM6v5V9uKPvrEMkkEedVewf+0itkhahp4HDpgERXhwLRpWFypsGbG/J8s0QjJA==",
"cpu": [
"mips64el"
],
@@ -2048,9 +2117,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/linux-ppc64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.1.tgz",
"integrity": "sha512-slScBsMAb3GFDcdrCgLwZtPYRoH2H/youv10QiZyRjmsP48fznoveWytSgCI/R0ZcUgpc0ZhIUEx6LHts8yrfQ==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.2.tgz",
"integrity": "sha512-CAXl+Dtd9UUuJd8pKKdwh6MLm3MUMiqMPmhZ3tTSXPqfyQ3vDl6R5hZdZ/kYojK4ofXtdfSv1tFq8XzWx3heNQ==",
"cpu": [
"ppc64"
],
@@ -2065,9 +2134,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/linux-riscv64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.1.tgz",
"integrity": "sha512-kw0owk1o0GFETUJyW0jc0G4Yzs0BHZn0JDZ8JRT088vjJYX777BAs1fDGxAC+q831qOs2DTC96mNsG2opdfyyQ==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.2.tgz",
"integrity": "sha512-GeXCej4IQtU1B+QlDV8W/RRvbzI3O/Stss+/bCXv4lZls5WGRtu2a+3JkA3i4qIUlMXpcHebWpF8AkJhATowuA==",
"cpu": [
"riscv64"
],
@@ -2082,9 +2151,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/linux-s390x": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.1.tgz",
"integrity": "sha512-/lAIjX8aYFRByhh6L5rYtPEDRqa9de/4V/juOXcta5frjvzXO4/sqEtyytse0g3zZFuWu5cDN0MkLz2qRDD2Ag==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.2.tgz",
"integrity": "sha512-3H1weTYZPxt/WOhByszQZybS9w5lKzUn1FDMsgEChbHWQwHYQQRfBxgCcZvPhjHfKyJjIievvMmEUawJrdY9Dg==",
"cpu": [
"s390x"
],
@@ -2099,9 +2168,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/linux-x64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.1.tgz",
"integrity": "sha512-u/anNYF2mmVOEDwLtnQ1wOr3EZ9sTNGLWrsYGYwHWzGA3Si84IOkHXlbWTD1NB+9/1lcnweYKO54uhxZydNzfA==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.2.tgz",
"integrity": "sha512-4xTZr1FUmSoQW4XIWmit3tzQrUTZM+N3P0XV8xROKYF50XfI7xeO90+1bZvNwxIufQ9hDQVRJH5YhgPVF8A/HQ==",
"cpu": [
"x64"
],
@@ -2116,9 +2185,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/netbsd-arm64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.1.tgz",
"integrity": "sha512-oks0DYbLwWMmaakTsCb+zL4E+aHRVLom9IJZOAthMQEPiQmydXHkziYEsGYRx0uNV/IjEKGAV941JzH02pflqw==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.2.tgz",
"integrity": "sha512-sSATRjPeDBg3pdgHoQfoYBob11Kk1FGa9lui5RIHZCoCkJa9QKlvl3/vKz2usCmYYjs7ymJR/2Nnsqe+Hjt5nw==",
"cpu": [
"arm64"
],
@@ -2133,9 +2202,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/netbsd-x64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.1.tgz",
"integrity": "sha512-aeL6lAnN89Hz43Mlh1G8ARasbuoYvSITDEx0tHh5b7jJnHcssqgjy9Yx430GDpmCa6OyrKoS0aNRjKundRizGg==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.2.tgz",
"integrity": "sha512-lqnzCV+mM0gIADaKihiCg6ifgfU2L3h5E33rNQBN1Y4MaVGnzryzmvvf7UHxprpQdE8hpqLolJ9Rl+SkIRDpyw==",
"cpu": [
"x64"
],
@@ -2150,9 +2219,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/openbsd-arm64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.1.tgz",
"integrity": "sha512-MEFJe5C3R8pwXdZ5Y21oo6m7ePiS0d9pWucn99O/wvyJZChoIQKrQDxKrGeW8F5+T0okTHesAmDeiHDTIq0V/Q==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.2.tgz",
"integrity": "sha512-AL2qJILH7lNjrDmCQDvdxMfAUIv8KMNZOvrwAQ8i8//ntL9FflhOyMJ8OZSMBb8/AWXe3/5v5S20y3zCoZWKoQ==",
"cpu": [
"arm64"
],
@@ -2167,9 +2236,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/openbsd-x64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.1.tgz",
"integrity": "sha512-i/ZLIOafE0Z8cI/XANJAixoJL/uRAoS2xOA3rb0xN+KK0K177cMAsQYkzHtBrtMXAKuAc7HGgcWiZ/sRC1Nxgw==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.2.tgz",
"integrity": "sha512-QtiuPytchRyC4rwUKhexJdQKvDuZ6hWloi3igqPQNUJCS1/v9EiO3UTOXR6A3FoMo4fnAKbWJdqaIwhOzh8qEw==",
"cpu": [
"x64"
],
@@ -2184,9 +2253,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/openharmony-arm64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.1.tgz",
"integrity": "sha512-ge+Z7EXFNt2BO1oAMsVpiQ8EwndV9i1xXerAeTIK7AtPs3bKFXQM7nlRxDSIUIMeueR1CNXxqztLzdNeReKBJg==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.2.tgz",
"integrity": "sha512-WkhYDmpTjLvGlScA1rwjRUmhl4k8oXR3cIbtqWmELgU/dFeHHlEllxDvdWcNJV9rbzCexB5vz8gtNewWLgCT7Q==",
"cpu": [
"arm64"
],
@@ -2201,9 +2270,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/sunos-x64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.1.tgz",
"integrity": "sha512-BEjgtECkL3vY+SaSQ6nzVfiALUeFxpawyp8Jmf5PtYhf1Ug40N1h/hxlhts+f1FvSvarEigdxS3BlSMI2PJLcQ==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.2.tgz",
"integrity": "sha512-GPMSkTOtMnv2U2F8gxe4Io6qmVs+YKyp832Etqqxr0hFngmXQ3rzwytelm3GIn7T4VviRUlf3sOgBOiTdvaf7g==",
"cpu": [
"x64"
],
@@ -2218,9 +2287,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/win32-arm64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.1.tgz",
"integrity": "sha512-lCv9eK/H6ZJWbE7bh2nw54CZ9M2nupBxJcTsdk/QQnWkdSjKGuxmmH8/GWrlT1eMmZfn4dGcCjRte397WqfQXA==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.2.tgz",
"integrity": "sha512-PIhhEkE9uPBleRBrQEJpUn7MBnibZzbGzYWPmY3x+YoVg/95zbjB4CxPPOQ8l5tYYM4mMaCthF8/1DIfBQQyWQ==",
"cpu": [
"arm64"
],
@@ -2235,9 +2304,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/win32-ia32": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.1.tgz",
"integrity": "sha512-zvb/mB2bSCoJOpoCBgYKKpX6YM6mJBlBUVUtVj41DlZJVEB6/0CKlRYxP5wWl1C1ILiCoAU5wZZ4q1P3qeS6Eg==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.2.tgz",
"integrity": "sha512-YmJbfTlvU7Sdn9BB+4PRES4oB6pxgS37MAONj+hBr/cpXS1aBPKXxNnDbu+QCWPj0o9dgyxeq79g6c5P8KeuYA==",
"cpu": [
"ia32"
],
@@ -2252,9 +2321,9 @@
}
},
"node_modules/tsx/node_modules/@esbuild/win32-x64": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.1.tgz",
"integrity": "sha512-bm4Mowrv+GXMlpWX++EcXw/iLyd1o3+bJkC2DkWXYVvgZCqD/bSj9ctZeAMC3cIxgjRVR2Dufaiu4YPxr5gW1A==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.2.tgz",
"integrity": "sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g==",
"cpu": [
"x64"
],
@@ -2269,9 +2338,9 @@
}
},
"node_modules/tsx/node_modules/esbuild": {
"version": "0.28.1",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.1.tgz",
"integrity": "sha512-HrJrvZv5ayxBzPfwphOoNzkzOIIlifzk0KJrGK2c8R4+LKpMtpYLQeUdjnwjWv/LZlkH2laZk+4w78pi99D4Vw==",
"version": "0.28.2",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz",
"integrity": "sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
@@ -2282,32 +2351,32 @@
"node": ">=18"
},
"optionalDependencies": {
"@esbuild/aix-ppc64": "0.28.1",
"@esbuild/android-arm": "0.28.1",
"@esbuild/android-arm64": "0.28.1",
"@esbuild/android-x64": "0.28.1",
"@esbuild/darwin-arm64": "0.28.1",
"@esbuild/darwin-x64": "0.28.1",
"@esbuild/freebsd-arm64": "0.28.1",
"@esbuild/freebsd-x64": "0.28.1",
"@esbuild/linux-arm": "0.28.1",
"@esbuild/linux-arm64": "0.28.1",
"@esbuild/linux-ia32": "0.28.1",
"@esbuild/linux-loong64": "0.28.1",
"@esbuild/linux-mips64el": "0.28.1",
"@esbuild/linux-ppc64": "0.28.1",
"@esbuild/linux-riscv64": "0.28.1",
"@esbuild/linux-s390x": "0.28.1",
"@esbuild/linux-x64": "0.28.1",
"@esbuild/netbsd-arm64": "0.28.1",
"@esbuild/netbsd-x64": "0.28.1",
"@esbuild/openbsd-arm64": "0.28.1",
"@esbuild/openbsd-x64": "0.28.1",
"@esbuild/openharmony-arm64": "0.28.1",
"@esbuild/sunos-x64": "0.28.1",
"@esbuild/win32-arm64": "0.28.1",
"@esbuild/win32-ia32": "0.28.1",
"@esbuild/win32-x64": "0.28.1"
"@esbuild/aix-ppc64": "0.28.2",
"@esbuild/android-arm": "0.28.2",
"@esbuild/android-arm64": "0.28.2",
"@esbuild/android-x64": "0.28.2",
"@esbuild/darwin-arm64": "0.28.2",
"@esbuild/darwin-x64": "0.28.2",
"@esbuild/freebsd-arm64": "0.28.2",
"@esbuild/freebsd-x64": "0.28.2",
"@esbuild/linux-arm": "0.28.2",
"@esbuild/linux-arm64": "0.28.2",
"@esbuild/linux-ia32": "0.28.2",
"@esbuild/linux-loong64": "0.28.2",
"@esbuild/linux-mips64el": "0.28.2",
"@esbuild/linux-ppc64": "0.28.2",
"@esbuild/linux-riscv64": "0.28.2",
"@esbuild/linux-s390x": "0.28.2",
"@esbuild/linux-x64": "0.28.2",
"@esbuild/netbsd-arm64": "0.28.2",
"@esbuild/netbsd-x64": "0.28.2",
"@esbuild/openbsd-arm64": "0.28.2",
"@esbuild/openbsd-x64": "0.28.2",
"@esbuild/openharmony-arm64": "0.28.2",
"@esbuild/sunos-x64": "0.28.2",
"@esbuild/win32-arm64": "0.28.2",
"@esbuild/win32-ia32": "0.28.2",
"@esbuild/win32-x64": "0.28.2"
}
},
"node_modules/type-is": {
@@ -2329,9 +2398,9 @@
}
},
"node_modules/type-is/node_modules/content-type": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-2.0.0.tgz",
"integrity": "sha512-j/O/d7GcZCyNl7/hwZAb606rzqkyvaDctLmckbxLzHvFBzTJHuGEdodATcP3yIRoDrLHkIATJuvzbFlp/ki2cQ==",
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz",
"integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==",
"license": "MIT",
"engines": {
"node": ">=18"
@@ -2341,6 +2410,19 @@
"url": "https://opencollective.com/express"
}
},
"node_modules/typescript": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz",
"integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==",
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
},
"node_modules/undici-types": {
"version": "7.18.2",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz",
+1
View File
@@ -13,6 +13,7 @@
"drizzle-orm": "^1.0.0-rc.4",
"express": "^5.1.0",
"pg": "^8.22.0",
"typescript": "^6.0.3",
"uuid": "^13.0.0"
},
"devDependencies": {
+31 -14
View File
@@ -7,10 +7,11 @@ import {
varchar,
integer,
bigint,
unique,
uniqueIndex,
boolean,
smallint,
check
check,
foreignKey
} from "drizzle-orm/pg-core";
import { sql, defineRelations } from "drizzle-orm";
@@ -27,7 +28,8 @@ export const blockTypeEnum = pgEnum("post_block_type", [
export const articleStatusEnum = pgEnum("post_status", [
"draft",
"published"
"published",
"archived"
]);
export const articles = pgTable("articles", {
@@ -36,17 +38,32 @@ export const articles = pgTable("articles", {
name: varchar({ length: 255 }).notNull(),
article_status: articleStatusEnum().notNull().default("draft"),
author_id: uuid().notNull().references(() => users.id, { onDelete: "cascade" }),
slug: varchar({ length: 511 }).unique().notNull(),
slug: varchar({ length: 511 }).notNull(),
summary: varchar({ length: 255 }).notNull(),
date_created: timestamp({ mode: "date", withTimezone: true }).defaultNow().notNull(),
last_edit: timestamp({ mode: "date", withTimezone: true }).defaultNow().notNull(),
date_published: timestamp({ mode: "date", withTimezone: true }),
previous_article: uuid(),
next_article: uuid()
},
(table) => [{
slugIdx: unique("no_repeat_slugs_per_author")
.on(table.author_id, table.slug)
}]);
(table) => [
uniqueIndex("no_repeat_slugs_per_author")
.on(table.author_id, table.slug),
foreignKey({
name: "next_article_ref_id",
columns: [table.next_article],
foreignColumns: [table.id]
}),
foreignKey({
name: "previous_article_ref_id",
columns: [table.previous_article],
foreignColumns: [table.id]
})
]);
export const articleBlocks = pgTable("article_blocks", {
id: uuid().notNull().primaryKey().defaultRandom(),
@@ -57,10 +74,10 @@ export const articleBlocks = pgTable("article_blocks", {
content: jsonb().$type<Record<string, unknown>>().notNull(),
},
(table) => [{
postPositionIdx: unique("no_repeat_block_position_per_article")
(table) => [
uniqueIndex("no_repeat_block_position_per_article")
.on(table.article_id, table.position)
}]);
]);
export const images = pgTable("images", {
id: uuid().notNull().primaryKey().defaultRandom(), // Linked in 'content' of articleBlock with type 'image'
@@ -74,13 +91,13 @@ export const images = pgTable("images", {
export const users = pgTable("users", {
id: uuid().notNull().primaryKey().defaultRandom(),
display_name: varchar({ length: 63 }).notNull(),
display_name: varchar({ length: 63 }).unique().notNull(),
username: varchar({ length: 63 }).notNull(),
username: varchar({ length: 63 }).unique().notNull(),
hashed_password: varchar({ length: 255 }).notNull(),
logged_in: boolean().notNull().default(false),
token: varchar({ length: 511 }),
refresh_token: varchar({ length: 511 }),
permissions: smallint().notNull().default(44),
},
(_) => [
+21
View File
@@ -0,0 +1,21 @@
import { Request, Response, NextFunction } from "express";
import JsonWebToken from '../types/JsonWebToken.ts';
export enum Permission {
none = 0,
read = 1,
write = 2,
readwrite = 3,
delete = 4,
readdelete = 5,
writedelete = 6,
all = 7,
};
export function requirePermissions(permission: number, isOwner: Boolean, requiredPermissions: number): Boolean {
const mask = isOwner ?
Math.floor(permission / 10) :
permission % 10;
return (mask & requiredPermissions) === requiredPermissions;
};
+74
View File
@@ -0,0 +1,74 @@
import crypto from 'crypto';
import JsonWebToken from '../types/JsonWebToken.ts';
export function verifySignature(header: string, payload: string, signature: string) {
const signingSecret = process.env.JWT_SECRET!;
const encodedMessage = header + "." + payload;
const calculatedSignature = crypto
.createHmac('sha256', signingSecret)
.update(encodedMessage)
.digest("base64url");
const csBuff = Buffer.from(calculatedSignature);
const sBuff = Buffer.from(signature);
return csBuff.length === sBuff.length &&
crypto.timingSafeEqual(csBuff, sBuff);
}
function base64UrlEncode(input: string) {
return Buffer.from(input).toString("base64url");
}
export function base64UrlDecode(str: string) {
return Buffer.from(str, "base64url").toString();
};
export function encodeMessage(header: JsonWebToken["header"], payload: JsonWebToken["payload"]): string {
const encodedHeader = base64UrlEncode(JSON.stringify(header));
const encodedPayload = base64UrlEncode(JSON.stringify(payload));
return `${encodedHeader}.${encodedPayload}`;
}
export function decodeJWT(token: string) {
const parts = token.split('.');
const header = JSON.parse(base64UrlDecode(parts[0]));
const payload = JSON.parse(base64UrlDecode(parts[1]));
const signature = parts[2]; // Signature remains encoded
return { header, payload, signature };
}
export function generateSignedJWT(userId: string, permissions: number, secondsToExpire: number): string {
const signingSecret = process.env.JWT_SECRET!;
const now = Math.floor(Date.now() / 1000);
const expires = now + secondsToExpire;
const header: JsonWebToken["header"] = {
alg: "HS256",
typ: "JWT",
};
const payload: JsonWebToken["payload"] = {
iat: now,
uid: userId,
prm: permissions,
exp: expires
};
const encodedMessage = encodeMessage(header, payload);
const signature = crypto
.createHmac('sha256', signingSecret)
.update(encodedMessage)
.digest("base64url");
return `${encodedMessage}.${signature}`;
}
-1
View File
@@ -5,7 +5,6 @@ import { blocksRouter } from './routes/blocks.ts';
import { imagesRouter } from './routes/images.ts';
import { authRouter } from './routes/auth.ts';
import { usersRouter } from './routes/users.ts';
import { auth } from './middleware/auth.ts';
const app = express();
app.use(express.json());
-120
View File
@@ -1,120 +0,0 @@
import { Request, Response, NextFunction } from "express";
import crypto from 'crypto';
import JsonWebToken from '../types/JsonWebToken.ts';
export async function auth(
req: Request,
res: Response,
next: NextFunction
) {
// read jwt
const authHeader = req.header("Authorization");
// If there is no jwt, proceed to request with default permissions
if (!authHeader) {
req.jwt = defaultJWT;
} else {
// otherwise decode the jwt
const [scheme, token] = authHeader.split(" ");
if (scheme.toLowerCase() != "bearer") {
return res.status(401).json({
error: "Invalid auth scheme (not Bearer)"
});
};
if (token.split(".").length !== 3) {
return res.status(401).json({
error: "Invalid JWT"
});
}
const [header, payload, signature] = token.split(".");
const validJWT: boolean = verifySignature(header, payload, signature);
let decodedToken: JsonWebToken;
try {
decodedToken = decodeJWT(token);
} catch {
return res.status(401).json({
error: "Invalid JWT"
});
}
const validClaims: boolean =
decodedToken.payload.exp < Math.floor(Date.now() / 1000) &&
decodedToken.header.alg === "HS256" &&
decodedToken.header.typ === "JWT";
if (validJWT && validClaims) {
req.jwt = decodedToken;
} else {
// maybe attempt token refresh here
return res.status(401).json({
error: "Invalid JWT"
});
}
}
next();
};
function verifySignature(header: string, payload: string, signature: string) {
const signingSecret = process.env.JWT_SECRET!;
const encodedMessage = header + "." + payload;
const calculatedSignature = crypto
.createHmac('sha256', signingSecret)
.update(encodedMessage)
.digest("base64url");
const csBuff = Buffer.from(calculatedSignature);
const sBuff = Buffer.from(signature);
return csBuff.length === sBuff.length &&
crypto.timingSafeEqual(csBuff, sBuff);
}
function base64UrlEncode(input: string) {
return Buffer.from(input).toString("base64url");
}
function encodeMessage(header: JsonWebToken["header"], payload: JsonWebToken["payload"]) {
const encodedHeader = base64UrlEncode(JSON.stringify(header));
const encodedPayload = base64UrlEncode(JSON.stringify(payload));
return encodedHeader + "." + encodedPayload;
}
function decodeJWT(token: string) {
const parts = token.split('.');
const decodeBase64Url = (str: string) => {
return Buffer.from(str, "base64url").toString();
};
const header = JSON.parse(decodeBase64Url(parts[0]));
const payload = JSON.parse(decodeBase64Url(parts[1]));
const signature = parts[2]; // Signature remains encoded
return { header, payload, signature };
}
// default fallback JWT
// works fine for all calls that only need "guest" auth
// individual routes will fail if prm (permissions)
// are insufficient
const defaultJWT: JsonWebToken =
{
header: {
alg: "none",
typ: "JWT",
},
payload: {
iat: -1,
uid: "",
prm: 44,
exp: -1,
},
signature: ""
};
+72
View File
@@ -0,0 +1,72 @@
import { Request, Response, NextFunction } from "express";
import JsonWebToken from '../types/JsonWebToken.ts';
import { verifySignature, decodeJWT } from '../helpers/jwt.ts';
import { refreshJWT } from "./refreshJWT.ts";
export function loadJWT(
req: Request,
res: Response,
next: NextFunction
) {
const authHeader = req.header("Authorization");
// If there is no jwt, fail
if (!authHeader) {
return res.status(401).json({
error: "Missing JWT"
});
} else {
// otherwise decode the jwt
const [scheme, token] = authHeader.split(" ");
if (scheme.toLowerCase() != "bearer") {
return res.status(401).json({
error: "Invalid Authorization Scheme"
});
};
if (token === "") {
return res.status(401).json({
error: "Missing JWT"
});
};
if (token.split(".").length !== 3) {
return res.status(401).json({
error: "Malformed JWT"
});
}
const [header, payload, signature] = token.split(".");
const validJWT: boolean = verifySignature(header, payload, signature);
let decodedToken: JsonWebToken;
try {
decodedToken = decodeJWT(token);
} catch {
return res.status(401).json({
error: "Malformed JWT"
});
}
const validClaims: boolean =
decodedToken.header.alg === "HS256" &&
decodedToken.header.typ === "JWT";
const expired: boolean = decodedToken.payload.exp < Math.floor(Date.now() / 1000);
if (validJWT && validClaims && !expired) {
req.jwt = decodedToken;
} else if (validJWT && validClaims && expired) {
req.jwt = decodedToken;
return refreshJWT(req, res, next);
} else {
return res.status(401).json({
error: "Invalid JWT"
});
}
}
return next();
};
+69
View File
@@ -0,0 +1,69 @@
import { drizzle } from 'drizzle-orm/node-postgres';
import { Request, Response, NextFunction } from "express";
import { eq } from 'drizzle-orm';
import { users } from '../db/schema.ts';
import { decodeJWT, generateSignedJWT, verifySignature } from "../helpers/jwt.ts";
const db = drizzle(process.env.DATABASE_URL!);
export async function refreshJWT(
req: Request,
res: Response,
next: NextFunction
) {
// get related user from jwt
const potentialUsers = await db
.select()
.from(users)
.where(eq(users.id, req.jwt.payload.uid));
const user = potentialUsers[0];
if (user.refresh_token === null) {
return res.status(403).json({
error: "No Refresh Token"
});
}
const [header, payload, signature] = user.refresh_token.split(".");
const validJWT: boolean = verifySignature(header, payload, signature);
if (!validJWT) {
return res.status(403).json({
error: "How did an invalid token get in my database?"
});
};
let refreshToken;
try {
refreshToken = decodeJWT(user.refresh_token)
} catch {
return res.status(403).json({
error: "How did an invalid token get in my database?"
});
}
const validClaims: boolean =
refreshToken.header.alg === "HS256" &&
refreshToken.header.typ === "JWT";
const expired: boolean = refreshToken.payload.exp < Math.floor(Date.now() / 1000);
if (!validClaims || expired) {
return res.status(403).json({
error: "Expired Refresh Token"
});
}
const toExpire = 60 * 15; // 15 minutes
const jwt = generateSignedJWT(user.id, user.permissions, toExpire)
res.set("X-New-Access-Token", jwt);
// Have to overwrite with new jwt
// Also I ain't try/catching cause I just made it
const parsedJWT = decodeJWT(jwt);
req.jwt = parsedJWT;
return next();
};
+16 -6
View File
@@ -2,6 +2,7 @@ import { drizzle } from 'drizzle-orm/node-postgres';
import { eq } from 'drizzle-orm';
import { articles } from '../db/schema.ts';
import express, { Request, Response } from "express";
import { Permission, requirePermissions } from '../helpers/authenticate.ts';
const db = drizzle(process.env.DATABASE_URL!);
export const articlesRouter = express.Router();
@@ -18,6 +19,17 @@ articlesRouter.get("/getArticle/:articleId", async (req: Request, res: Response)
const resp = await db.select()
.from(articles)
.where(eq(articles.id, parsedId));
if (!requirePermissions(
req.jwt.payload.prm,
req.jwt.payload.uid === resp[0].author_id,
Permission.read)) {
res.status(403).json({
error: "Insufficient Permissions"
});
};
res.json(resp);
});
@@ -28,7 +40,9 @@ articlesRouter.get("/getArticleBySlug/:slug", async (req: Request, res: Response
const resp = await db.select()
.from(articles)
.where(eq(articles.slug, parsedSlug));
res.json(resp);
// Only return the first
res.json(resp[0]);
});
articlesRouter.post("/postArticle", async (req: Request, res: Response) => {
@@ -47,11 +61,7 @@ articlesRouter.put("/updateArticle/:articleId", async (req: Request, res: Respon
const resp = await db.update(articles)
.set({
name: req.body.name,
author_id: req.body.author_id,
slug: req.body.name.trim().toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]/g, ''),
summary: req.body.summary,
article_status: req.body.article_status,
...req.body,
last_edit: new Date(Date.now()),
date_published: req.body.article_status == "published" ? new Date(Date.now()) : null
})
+120 -1
View File
@@ -1,7 +1,126 @@
import { drizzle } from 'drizzle-orm/node-postgres';
import crypto from 'crypto';
import { eq } from 'drizzle-orm';
import { articles } from '../db/schema.ts';
import { users } from '../db/schema.ts';
import express, { Request, Response } from "express";
import { generateSignedJWT, base64UrlDecode } from '../helpers/jwt.ts';
import { loadJWT } from '../middleware/loadJWT.ts';
const db = drizzle(process.env.DATABASE_URL!);
const hashSecret = process.env.PASSWORD_HASH_SECRET!;
const presalt = process.env.PRESALT!;
const postsalt = process.env.POSTSALT!;
export const authRouter = express.Router();
// username and password => signed jwt
authRouter.get("/login", async (req: Request, res: Response) => {
const authHeader = req.header("Authorization");
if (!authHeader) return res.status(401)
.json({ error: "401: Missing Authorization Header" });
const [scheme, value] = authHeader.split(" ");
if (scheme.toLowerCase() != "basic") return res.status(401)
.json({ error: "401: Incorrect Authorization Scheme" });
const decodedHeader = base64UrlDecode(value);
const [username, password] = decodedHeader.split(":");
loginUser(username, password, res);
});
authRouter.put("/logout", loadJWT, async (req: Request, res: Response) => {
// since login is controlled by a jwt, all we can do here is wipe the refresh_token
// frontend will be responsible for clearing temp token from cache/cookies
// This endpoint will require a logged in user (valid jwt)
const resp = await db
.update(users)
.set({ refresh_token: null, logged_in: false })
.where(eq(users.id, req.jwt.payload.uid));
res.json(resp);
});
authRouter.post("/signup", async (req: Request, res: Response) => {
const { username, password, display_name } = req.body
const hashedPassword = crypto
.createHmac('sha256', hashSecret)
.update(`${presalt}${password}${postsalt}`)
.digest("base64url");
try {
await db
.insert(users)
.values({
display_name: display_name,
username: username,
hashed_password: hashedPassword,
permissions: 71
});
} catch (err: any) {
if (err.cause.code === "23505") {
return res.status(409).json({
error: "Username already exists"
});
}
throw err;
}
loginUser(username, password, res);
});
// because it writes to the response, has to be last step
async function loginUser(username: string, password: string, res: Response) {
const hashedPassword = crypto
.createHmac('sha256', hashSecret)
.update(`${presalt}${password}${postsalt}`)
.digest("base64url");
const potentialUsers = await db
.select()
.from(users)
.where(eq(users.username, username))
.limit(1);
const user = potentialUsers[0];
if (!user) {
return res.status(401).json({
error: "401: Invalid Username",
});
}
const calculatedBuff = Buffer.from(hashedPassword);
const storedBuff = Buffer.from(user.hashed_password);
const match = calculatedBuff.length === storedBuff.length &&
crypto.timingSafeEqual(calculatedBuff, storedBuff);
if (!match)
return res.status(401).json({ error: "401: Failed to authenticate username/password" });
// fifteen minutes
const tempToExpire = 60 * 15;
const jwt = generateSignedJWT(user.id, user.permissions, tempToExpire)
// seven days
const refreshToExpire = 60 * 60 * 24 * 7;
const refreshjwt = generateSignedJWT(user.id, user.permissions, refreshToExpire);
const resp = await db
.update(users)
.set({
refresh_token: refreshjwt,
logged_in: true
})
.where(eq(users.id, user.id));
res.json({
signed_jwt: jwt,
refresh_resp: resp
});
}
+33 -2
View File
@@ -2,12 +2,19 @@ import { drizzle } from 'drizzle-orm/node-postgres';
import { eq } from 'drizzle-orm';
import { users } from '../db/schema.ts';
import express, { Request, Response } from "express";
import { auth } from '../middleware/auth.ts';
import { loadJWT } from '../middleware/loadJWT.ts';
const db = drizzle(process.env.DATABASE_URL!);
export const usersRouter = express.Router();
usersRouter.get("/getUsers", async (_: Request, res: Response) => {
usersRouter.get("/getUsers", loadJWT, async (req: Request, res: Response) => {
if (req.jwt.payload.prm != 77)
return res
.status(403)
.json({
error: "403: Forbidden"
});
const resp = await db.select().from(users);
res.json(resp)
});
@@ -23,6 +30,30 @@ usersRouter.get("/getUser/:userId", async (req: Request, res: Response) => {
res.json(resp);
});
usersRouter.get("/getSelf", loadJWT, async (req: Request, res: Response) => {
const userId = req.jwt.payload.uid;
const resp = await db.select()
.from(users)
.where(eq(users.id, userId));
res.json(resp[0]);
});
usersRouter.get("/getUserName/:userId", async (req: Request, res: Response) => {
const { userId } = req.params;
const parsedId = Array.isArray(userId) ? userId[0] : userId;
const resp = await db.select()
.from(users)
.where(eq(users.id, parsedId));
res.json({
id: resp[0].id,
display_name: resp[0].display_name
});
});
usersRouter.post("/createUser", async (req: Request, res: Response) => {
const resp = await db
.insert(users)
+22
View File
@@ -14,4 +14,26 @@ type JsonWebToken = {
signature: string
};
// default fallback JWT
// works fine for all calls that only need "guest" auth
// individual routes will fail if prm (permissions)
// are insufficient
export function defaultJWT() {
return {
header: {
alg: "none",
typ: "JWT",
},
payload: {
iat: -1,
uid: "",
prm: 0,
exp: -1
},
signature: ""
}
}
export default JsonWebToken;
@@ -1,4 +1,4 @@
import JsonWebToken from './src/types/JsonWebToken.ts';
import JsonWebToken from '../JsonWebToken.ts';
export { }
+17
View File
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"esModuleInterop": true,
"allowImportingTsExtensions": true,
"skipLibCheck": true,
"types": [
"node"
]
},
"include": [
"src"
]
}
+669 -846
View File
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,70 @@
import type { ArticleBlock } from "../types/ArticleBlock";
import { TitleBlock, ParagraphBlock, HeadingBlock, ImageBlock, CodeBlock, QuoteBlock, ListBlock } from "./blocks/";
type ArticleContentProps = {
blocks: ArticleBlock[];
};
export function ArticleContent({ blocks }: ArticleContentProps) {
const sortedBlocks = [...blocks].sort(
(a, b) => a.position - b.position
);
return (
<main className="mx-auto max-w-4xl">
<article className="prose prose-lg max-w-none">
{sortedBlocks.map((block) => (
<ArticleBlockRenderer
key={block.id}
block={block}
/>
))}
</article>
</main>
);
}
function ArticleBlockRenderer({
block,
}: {
block: ArticleBlock;
}) {
switch (block.type) {
case "title":
return <TitleBlock content={block.content} />;
case "paragraph":
return <ParagraphBlock content={block.content} />;
case "heading":
return <HeadingBlock content={block.content} />;
case "image":
return <ImageBlock content={block.content} />;
case "code":
return <CodeBlock content={block.content} />;
case "quote":
return <QuoteBlock content={block.content} />;
case "ordered_list":
return (
<ListBlock
content={block.content}
ordered
/>
);
case "unordered_list":
return (
<ListBlock
content={block.content}
ordered={false}
/>
);
default:
return <div>UNHANDLED BLOCK TYPE</div>;
}
};
+76
View File
@@ -0,0 +1,76 @@
import type { Article } from "./../types/Article.ts";
import type { User } from "./../types/User.ts";
type ArticleHeaderProps = {
article: Article;
author: User;
};
export function ArticleHeader({ article, author }: ArticleHeaderProps) {
const publishedDate = article.date_published
? new Date(article.date_published)
: null;
return (
<header className="mx-auto mb-12 max-w-4xl border-b-2 border-bold-2 pb-8">
{/* Status */}
<div className="mb-4 flex items-center gap-3 text-sm uppercase tracking-widest">
<span className="bg-bold-2 px-3 py-1 font-bold text-tb2">
{article.article_status}
</span>
{publishedDate && (
<time
dateTime={article.date_published ?? undefined}
className="text-tn1"
>
{publishedDate.toLocaleDateString(undefined, {
year: "numeric",
month: "long",
day: "numeric",
})}
</time>
)}
</div>
{/* Title */}
<h1 className="mb-6 text-4xl font-bold leading-tight text-tb1 md:text-5xl">
{article.name}
</h1>
{/* Summary */}
{article.summary && (
<p className="mb-6 max-w-3xl text-xl leading-relaxed text-tn1">
{article.summary}
</p>
)}
{/* Author / metadata */}
<div className="flex flex-wrap items-center gap-x-4 gap-y-2 text-sm text-tn1">
<span>
By{" "}
<span className="font-bold text-tb1">
{author.display_name}
</span>
</span>
<span aria-hidden="true">·</span>
<time dateTime={article.date_created}>
Created{" "}
{new Date(article.date_created).toLocaleDateString()}
</time>
{article.last_edit !== article.date_created && (
<>
<span aria-hidden="true">·</span>
<time dateTime={article.last_edit}>
Updated {new Date(article.last_edit).toLocaleDateString()}
</time>
</>
)}
</div>
</header>
);
}
@@ -0,0 +1,22 @@
export function getString(
content: Record<string, unknown>,
key: string
): string {
const value = content[key];
return typeof value === "string" ? value : "";
}
export function getStringArray(
content: Record<string, unknown>,
key: string
): string[] {
const value = content[key];
if (!Array.isArray(value)) {
return [];
}
return value.filter(
(item): item is string => typeof item === "string"
);
}
@@ -0,0 +1,26 @@
import { getString } from "./BlockHelpers";
export default function CodeBlock({
content,
}: {
content: Record<string, unknown>;
}) {
const code = getString(content, "code");
const language = getString(content, "language");
if (!code) return null;
return (
<div className="my-8 overflow-hidden border-2 border-dark bg-dark">
{language && (
<div className="border-b border-neutral-600 px-4 py-2 text-xs uppercase tracking-widest text-neutral-300">
{language}
</div>
)}
<pre className="overflow-x-auto p-5 font-mono text-sm leading-6 text-tb2">
<code>{code}</code>
</pre>
</div>
);
}
@@ -0,0 +1,26 @@
import { getString } from "./BlockHelpers";
export default function HeadingBlock({
content,
}: {
content: Record<string, unknown>;
}) {
const text = getString(content, "text");
const level = getString(content, "level");
if (!text) return null;
if (level === "3") {
return (
<h3 className="mb-4 mt-10 text-2xl font-bold text-tb1">
{text}
</h3>
);
}
return (
<h2 className="mb-4 mt-10 text-3xl font-bold text-tb1">
{text}
</h2>
);
}
@@ -0,0 +1,29 @@
import { getString } from "./BlockHelpers";
export default function ImageBlock({
content,
}: {
content: Record<string, unknown>;
}) {
const src = getString(content, "src");
const alt = getString(content, "alt");
const caption = getString(content, "caption");
if (!src) return null;
return (
<figure className="my-10">
<img
src={src}
alt={alt}
className="h-auto w-full border-2 border-dark object-cover"
/>
{caption && (
<figcaption className="mt-2 text-center text-sm text-tn1">
{caption}
</figcaption>
)}
</figure>
);
}
@@ -0,0 +1,28 @@
import { getStringArray } from "./BlockHelpers";
export default function ListBlock({
content,
ordered,
}: {
content: Record<string, unknown>;
ordered: boolean;
}) {
const items = getStringArray(content, "items");
if (items.length === 0) return null;
const Tag = ordered ? "ol" : "ul";
return (
<Tag
className={[
"mb-6 space-y-2 pl-8 text-lg leading-8 text-td",
ordered ? "list-decimal" : "list-disc",
].join(" ")}
>
{items.map((item, index) => (
<li key={index}>{item}</li>
))}
</Tag>
);
}
@@ -0,0 +1,17 @@
import { getString } from "./BlockHelpers";
export default function ParagraphBlock({
content,
}: {
content: Record<string, unknown>;
}) {
const text = getString(content, "text");
if (!text) return null;
return (
<p className="mb-6 text-lg leading-8 text-td">
{text}
</p>
);
}
@@ -0,0 +1,24 @@
import { getString } from "./BlockHelpers";
export default function QuoteBlock({
content,
}: {
content: Record<string, unknown>;
}) {
const text = getString(content, "text");
const attribution = getString(content, "attribution");
if (!text) return null;
return (
<blockquote className="my-10 border-l-4 border-bold-1 bg-bold-1/20 px-6 py-4 text-xl italic leading-8 text-tb1">
<p className="m-0">{text}</p>
{attribution && (
<footer className="mt-3 text-sm not-italic text-tn1">
{attribution}
</footer>
)}
</blockquote>
);
}
@@ -0,0 +1,17 @@
import { getString } from "./BlockHelpers";
export default function TitleBlock({
content,
}: {
content: Record<string, unknown>;
}) {
const text = getString(content, "text");
if (!text) return null;
return (
<h2 className="mb-6 mt-12 text-3xl font-bold leading-tight text-tb1 md:text-4xl">
{text}
</h2>
);
}
+7
View File
@@ -0,0 +1,7 @@
export { default as TitleBlock } from "./TitleBlock";
export { default as ParagraphBlock } from "./ParagraphBlock";
export { default as HeadingBlock } from "./HeadingBlock";
export { default as ImageBlock } from "./ImageBlock";
export { default as CodeBlock } from "./CodeBlock";
export { default as QuoteBlock } from "./QuoteBlock";
export { default as ListBlock } from "./ListBlock";
+72 -2
View File
@@ -1,12 +1,82 @@
import { useParams } from 'react-router';
// import { useState, useEffect } from 'react';
import { useState, useEffect } from 'react';
import type { Article } from '../types/Article.ts';
import { ArticleSchema } from '../types/Article.ts';
import type { ArticleBlock } from '../types/ArticleBlock';
import { ArticleBlockListSchema } from '../types/ArticleBlock';
import { UserSchema } from '../types/User';
import type { User } from '../types/User';
import { ArticleHeader } from '../components/ArticleHeader.tsx';
import { ArticleContent } from '../components/ArticleContent.tsx';
export default function Article() {
let { slug } = useParams();
const [article, setArticle] = useState<Article>();
const [articleBlocks, setBlocks] = useState<ArticleBlock[]>();
const [author, setAuthor] = useState<User>();
useEffect(() => {
getArticle(slug!, setArticle, setBlocks, setAuthor);
}, []);
return (
article === undefined || author === undefined || articleBlocks === undefined ?
<div id="article" className="page-container">
<h1>Article: {slug}</h1>
<h1>LOADING</h1>
</div> :
<div id="article" className="page-container">
<ArticleHeader article={article} author={author} />
<ArticleContent blocks={articleBlocks} />
</div>
);
};
async function getArticle(
articleSlug: String,
setArticle: React.Dispatch<React.SetStateAction<Article | undefined>>,
setBlocks: React.Dispatch<React.SetStateAction<ArticleBlock[] | undefined>>,
setAuthor: React.Dispatch<React.SetStateAction<User | undefined>>
) {
const result = await fetch(
`/api/articles/getArticleBySlug/${articleSlug}`,
{
method: "GET",
headers: { "Accept": "application/json" }
}
);
const json = await result.json();
const data = ArticleSchema.parse(json);
setArticle(data);
getBlocks(data.id, setBlocks);
getAuthor(data.author_id, setAuthor);
};
async function getBlocks(articleId: String, setBlocks: React.Dispatch<React.SetStateAction<ArticleBlock[] | undefined>>) {
const result = await fetch(
`/api/blocks/getBlocks/${articleId}`,
{
method: "GET",
headers: { "Accept": "application/json" }
}
);
const json = await result.json();
const data = ArticleBlockListSchema.parse(json);
setBlocks(data);
};
async function getAuthor(userId: String, setBlocks: React.Dispatch<React.SetStateAction<User | undefined>>) {
const result = await fetch(
`/api/users/getUserName/${userId}`,
{
method: "GET",
headers: { "Accept": "application/json" }
}
);
const json = await result.json();
const data = UserSchema.parse(json);
setBlocks(data);
};
+3 -3
View File
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
// import { Button } from '@mui/material';
import { Button } from '@mui/material';
import type { Article } from '../types/Article.ts';
import { ArticleListSchema } from '../types/Article.ts';
import ArticleCard from '../components/ArticleCard.tsx';
@@ -27,12 +27,12 @@ export default function ArticleList() {
return (
<div className="page-container p-3 flex flex-col gap-5">
{/*<Button
{<Button
style={{ border: "solid", borderWidth: "1px" }}
onClick={() => getAllArticles()}
>
Refresh
</Button>*/}
</Button>}
<div className="grid [grid-template-columns:repeat(auto-fit,minmax(16rem,1fr))] gap-5">
{articles.map((article) => (<ArticleCard key={article.id} article={article} />))}
</div>
+5 -1
View File
@@ -1,15 +1,19 @@
import { z } from 'zod';
export const ArticleStatusSchema = z.enum(["draft", "published", "archived"]);
export const ArticleSchema = z.object({
id: z.string(),
name: z.string(),
article_status: z.enum(["draft", "published", "archived"]),
article_status: ArticleStatusSchema,
author_id: z.string(),
slug: z.string(),
summary: z.string(),
date_created: z.string(),
last_edit: z.string(),
date_published: z.string().nullable(),
previous_article: z.string().nullable(),
next_article: z.string().nullable(),
});
export const ArticleListSchema = z.array(ArticleSchema);
+23
View File
@@ -0,0 +1,23 @@
import { z } from 'zod';
export const BlockTypeSchema = z.enum([
"title",
"paragraph",
"heading",
"image",
"code",
"quote",
"ordered_list",
"unordered_list",
]);
export const ArticleBlockSchema = z.object({
id: z.string(),
article_id: z.string(),
position: z.number().int(),
type: BlockTypeSchema,
content: z.record(z.string(), z.unknown()),
});
export const ArticleBlockListSchema = z.array(ArticleBlockSchema);
export type ArticleBlock = z.infer<typeof ArticleBlockSchema>;
+14
View File
@@ -0,0 +1,14 @@
import { z } from 'zod';
export const ImageSchema = z.object({
id: z.string(),
bucket: z.string(),
key: z.string(),
mime_type: z.string(),
height: z.number().int(),
width: z.number().int(),
bytes: z.number().int(),
});
export const ImageListSchema = z.array(ImageSchema);
export type Image = z.infer<typeof ImageSchema>;
+12
View File
@@ -0,0 +1,12 @@
import { z } from 'zod';
// we don't want things like refresh token or hashed password to ever
// propogate to the frontend, so we don't include them in the schema.
// enforce in the backend.
export const UserSchema = z.object({
id: z.string(),
display_name: z.string(),
});
export const UserListSchema = z.array(UserSchema);
export type User = z.infer<typeof UserSchema>;