From 1a02dcfcc3c20145ba108cac2c04e483afc94a8c Mon Sep 17 00:00:00 2001 From: Andy Burke Date: Thu, 24 Jul 2025 12:09:24 -0700 Subject: [PATCH] refactor: use sync bcrypt to avoid issues with worker perms refactor: fix up includes --- deno.json | 15 +- deno.lock | 144 ++++-------------- models/event.ts | 6 +- models/password_entry.ts | 2 +- models/room.ts | 6 +- models/session.ts | 6 +- models/totp_entry.ts | 2 +- models/user.ts | 6 +- public/api/auth/index.ts | 10 +- public/api/rooms/:room_id/events/index.ts | 12 +- public/api/rooms/index.ts | 4 +- public/api/users/index.ts | 8 +- tests/api/rooms/create_room.test.ts | 4 +- tests/api/rooms/delete_room.test.ts | 4 +- tests/api/rooms/events/create_events.test.ts | 4 +- tests/api/rooms/events/get_events.test.ts | 13 +- tests/api/rooms/events/update_events.test.ts | 4 +- .../update_events_when_append_only.test.ts | 4 +- tests/api/rooms/update_room.test.ts | 4 +- tests/api/users/create_user.test.ts | 4 +- tests/api/users/delete_user.test.ts | 2 +- tests/api/users/login.test.ts | 2 +- tests/api/users/update_user.test.ts | 2 +- tests/helpers.ts | 6 +- utils/api.ts | 2 +- utils/prechecks.ts | 4 +- utils/totp.ts | 2 +- 27 files changed, 104 insertions(+), 178 deletions(-) diff --git a/deno.json b/deno.json index ba22be8..e17b4c7 100644 --- a/deno.json +++ b/deno.json @@ -1,14 +1,14 @@ { "name": "@andyburke/autonomous.contact", "description": "An experiment.", - "version": "0.3.0", + "version": "0.4.0", "license": "MIT", "exports": {}, "tasks": { "lint": "deno lint", "fmt": "deno fmt", - "serve": "FSDB_ROOT=$PWD/.fsdb TRACE_ERROR_RESPONSES=true SERVERUS_TYPESCRIPT_IMPORT_LOGGING=true deno --allow-env --allow-read --allow-write --allow-net jsr:@andyburke/serverus --root ./public --hostname 0.0.0.0", - "test": "DENO_ENV=test FSDB_ROOT=$PWD/tests/data/$(date --iso-8601=seconds) SERVERUS_ROOT=$PWD/public deno test --allow-env --allow-read --allow-write --allow-net --trace-leaks --fail-fast tests/" + "serve": "FSDB_ROOT=$PWD/.fsdb TRACE_ERROR_RESPONSES=true SERVERUS_TYPESCRIPT_IMPORT_LOGGING=true deno --allow-env --allow-read --allow-write --allow-net @andyburke/serverus --root ./public --hostname 0.0.0.0", + "test": "DENO_ENV=test FSDB_ROOT=$PWD/tests/data/$(date --iso-8601=seconds) SERVERUS_ROOT=$PWD/public deno test --allow-env --allow-read --allow-write --allow-net --allow-import --trace-leaks --fail-fast tests/" }, "test": { "exclude": ["tests/data/"] @@ -32,14 +32,13 @@ } }, "imports": { - "@andyburke/fsdb": "jsr:@andyburke/fsdb@^1.0.0", + "@andyburke/fsdb": "jsr:@andyburke/fsdb@^1.0.2", "@andyburke/lurid": "jsr:@andyburke/lurid@^0.2.0", - "@andyburke/serverus": "jsr:@andyburke/serverus@^0.9.3", + "@andyburke/serverus": "jsr:@andyburke/serverus@^0.9.8", "@da/bcrypt": "jsr:@da/bcrypt@^1.0.1", "@std/assert": "jsr:@std/assert@^1.0.13", "@std/encoding": "jsr:@std/encoding@^1.0.10", - "@std/http": "jsr:@std/http@^1.0.19", - "@std/path": "jsr:@std/path@^1.1.1", - "@stdext/crypto": "jsr:@stdext/crypto@^0.1.0" + "@std/http": "jsr:@std/http@^1.0.20", + "@std/path": "jsr:@std/path@^1.1.1" } } diff --git a/deno.lock b/deno.lock index 9ea7877..b95dc9c 100644 --- a/deno.lock +++ b/deno.lock @@ -1,44 +1,34 @@ { "version": "5", "specifiers": { - "jsr:@andyburke/fsdb@1": "1.0.0", - "jsr:@andyburke/lurid@*": "0.2.0", + "jsr:@andyburke/fsdb@^1.0.2": "1.0.2", "jsr:@andyburke/lurid@0.2": "0.2.0", - "jsr:@andyburke/serverus@~0.9.3": "0.9.3", + "jsr:@andyburke/serverus@~0.9.8": "0.9.8", + "jsr:@da/bcrypt@*": "1.0.1", "jsr:@da/bcrypt@^1.0.1": "1.0.1", - "jsr:@std/assert@*": "1.0.13", "jsr:@std/assert@^1.0.13": "1.0.13", "jsr:@std/async@^1.0.13": "1.0.13", - "jsr:@std/cli@^1.0.19": "1.0.20", - "jsr:@std/cli@^1.0.20": "1.0.20", - "jsr:@std/encoding@*": "1.0.10", - "jsr:@std/encoding@1": "1.0.10", + "jsr:@std/cli@^1.0.19": "1.0.21", + "jsr:@std/cli@^1.0.20": "1.0.21", + "jsr:@std/cli@^1.0.21": "1.0.21", "jsr:@std/encoding@^1.0.10": "1.0.10", "jsr:@std/fmt@^1.0.6": "1.0.8", "jsr:@std/fmt@^1.0.8": "1.0.8", - "jsr:@std/fs@^1.0.14": "1.0.19", "jsr:@std/fs@^1.0.18": "1.0.19", "jsr:@std/fs@^1.0.19": "1.0.19", "jsr:@std/html@^1.0.4": "1.0.4", - "jsr:@std/http@*": "1.0.18", - "jsr:@std/http@^1.0.13": "1.0.19", - "jsr:@std/http@^1.0.18": "1.0.18", - "jsr:@std/http@^1.0.19": "1.0.19", - "jsr:@std/internal@^1.0.6": "1.0.9", - "jsr:@std/internal@^1.0.9": "1.0.9", + "jsr:@std/http@^1.0.20": "1.0.20", + "jsr:@std/internal@^1.0.6": "1.0.10", + "jsr:@std/internal@^1.0.9": "1.0.10", "jsr:@std/media-types@^1.1.0": "1.1.0", "jsr:@std/net@^1.0.4": "1.0.4", - "jsr:@std/path@*": "1.1.1", - "jsr:@std/path@^1.0.8": "1.1.1", "jsr:@std/path@^1.1.0": "1.1.1", "jsr:@std/path@^1.1.1": "1.1.1", - "jsr:@std/streams@^1.0.10": "1.0.10", - "jsr:@stdext/crypto@*": "0.1.0", - "jsr:@stdext/crypto@0.1": "0.1.0" + "jsr:@std/streams@^1.0.10": "1.0.10" }, "jsr": { - "@andyburke/fsdb@1.0.0": { - "integrity": "5178eca5813e4f00cf9c00b7a9da9156b54b0c6e98a6fdba54743ccfa6a465d4", + "@andyburke/fsdb@1.0.2": { + "integrity": "f12315b63f534df0f1638828f3b7551ced9b507618f98c6c5dfbd8adf5b96d6f", "dependencies": [ "jsr:@std/cli@^1.0.20", "jsr:@std/fs@^1.0.18", @@ -51,14 +41,15 @@ "jsr:@std/cli@^1.0.19" ] }, - "@andyburke/serverus@0.9.3": { - "integrity": "fb72135b96e9700f6b4959d9fcbcbf8dfeef9ed97cd510709c59304d7fef59d5", + "@andyburke/serverus@0.9.8": { + "integrity": "6d806a5fd50b67edfaeee12f1a59bfc3a0cb22d9bcffba0910bf5b56d0473059", "dependencies": [ + "jsr:@andyburke/serverus", "jsr:@std/async", - "jsr:@std/cli@^1.0.20", + "jsr:@std/cli@^1.0.21", "jsr:@std/fmt@^1.0.6", "jsr:@std/fs@^1.0.19", - "jsr:@std/http@^1.0.19", + "jsr:@std/http", "jsr:@std/media-types", "jsr:@std/path@^1.1.1" ] @@ -75,8 +66,8 @@ "@std/async@1.0.13": { "integrity": "1d76ca5d324aef249908f7f7fe0d39aaf53198e5420604a59ab5c035adc97c96" }, - "@std/cli@1.0.20": { - "integrity": "a8c384a2c98cec6ec6a2055c273a916e2772485eb784af0db004c5ab8ba52333" + "@std/cli@1.0.21": { + "integrity": "cd25b050bdf6282e321854e3822bee624f07aca7636a3a76d95f77a3a919ca2a" }, "@std/encoding@1.0.10": { "integrity": "8783c6384a2d13abd5e9e87a7ae0520a30e9f56aeeaa3bdf910a3eaaf5c811a1" @@ -84,12 +75,6 @@ "@std/fmt@1.0.8": { "integrity": "71e1fc498787e4434d213647a6e43e794af4fd393ef8f52062246e06f7e372b7" }, - "@std/fs@1.0.18": { - "integrity": "24bcad99eab1af4fde75e05da6e9ed0e0dce5edb71b7e34baacf86ffe3969f3a", - "dependencies": [ - "jsr:@std/path@^1.1.0" - ] - }, "@std/fs@1.0.19": { "integrity": "051968c2b1eae4d2ea9f79a08a3845740ef6af10356aff43d3e2ef11ed09fb06", "dependencies": [ @@ -100,28 +85,11 @@ "@std/html@1.0.4": { "integrity": "eff3497c08164e6ada49b7f81a28b5108087033823153d065e3f89467dd3d50e" }, - "@std/http@1.0.17": { - "integrity": "98aec8ab4080d95c21f731e3008f69c29c5012d12f1b4e553f85935db601569f" - }, - "@std/http@1.0.18": { - "integrity": "8d9546aa532c52a0cf318c74616db0638b4c1073405355d1b14f9e1591dccf20", + "@std/http@1.0.20": { + "integrity": "b5cc33fc001bccce65ed4c51815668c9891c69ccd908295997e983d8f56070a1", "dependencies": [ - "jsr:@std/cli@^1.0.20", - "jsr:@std/encoding@^1.0.10", - "jsr:@std/fmt@^1.0.8", - "jsr:@std/fs@^1.0.18", - "jsr:@std/html", - "jsr:@std/media-types", - "jsr:@std/net", - "jsr:@std/path@^1.1.0", - "jsr:@std/streams" - ] - }, - "@std/http@1.0.19": { - "integrity": "52128c8d00a1f0b20019f8b72376e7ef5f3133375b6f805b5bc89b9de2ad4686", - "dependencies": [ - "jsr:@std/cli@^1.0.20", - "jsr:@std/encoding@^1.0.10", + "jsr:@std/cli@^1.0.21", + "jsr:@std/encoding", "jsr:@std/fmt@^1.0.8", "jsr:@std/fs@^1.0.19", "jsr:@std/html", @@ -131,11 +99,8 @@ "jsr:@std/streams" ] }, - "@std/internal@1.0.8": { - "integrity": "fc66e846d8d38a47cffd274d80d2ca3f0de71040f855783724bb6b87f60891f5" - }, - "@std/internal@1.0.9": { - "integrity": "bdfb97f83e4db7a13e8faab26fb1958d1b80cc64366501af78a0aee151696eb8" + "@std/internal@1.0.10": { + "integrity": "e3be62ce42cab0e177c27698e5d9800122f67b766a0bea6ca4867886cbde8cf7" }, "@std/media-types@1.1.0": { "integrity": "c9d093f0c05c3512932b330e3cc1fe1d627b301db33a4c2c2185c02471d6eaa4" @@ -143,9 +108,6 @@ "@std/net@1.0.4": { "integrity": "2f403b455ebbccf83d8a027d29c5a9e3a2452fea39bb2da7f2c04af09c8bc852" }, - "@std/path@1.1.0": { - "integrity": "ddc94f8e3c275627281cbc23341df6b8bcc874d70374f75fec2533521e3d6886" - }, "@std/path@1.1.1": { "integrity": "fe00026bd3a7e6a27f73709b83c607798be40e20c81dde655ce34052fd82ec76", "dependencies": [ @@ -154,65 +116,21 @@ }, "@std/streams@1.0.10": { "integrity": "75c0b1431873cd0d8b3d679015220204d36d3c7420d93b60acfc379eb0dc30af" - }, - "@stdext/crypto@0.1.0": { - "integrity": "05dc9e754c2529574d8bf98bd40c7dc468a02dcb2fa5e8644fff6813ceab66a4", - "dependencies": [ - "jsr:@std/encoding@1" - ] } }, - "remote": { - "https://deno.land/std@0.167.0/_util/asserts.ts": "d0844e9b62510f89ce1f9878b046f6a57bf88f208a10304aab50efcb48365272", - "https://deno.land/std@0.167.0/_util/os.ts": "8a33345f74990e627b9dfe2de9b040004b08ea5146c7c9e8fe9a29070d193934", - "https://deno.land/std@0.167.0/path/_constants.ts": "df1db3ffa6dd6d1252cc9617e5d72165cd2483df90e93833e13580687b6083c3", - "https://deno.land/std@0.167.0/path/_interface.ts": "ee3b431a336b80cf445441109d089b70d87d5e248f4f90ff906820889ecf8d09", - "https://deno.land/std@0.167.0/path/_util.ts": "d16be2a16e1204b65f9d0dfc54a9bc472cafe5f4a190b3c8471ec2016ccd1677", - "https://deno.land/std@0.167.0/path/common.ts": "bee563630abd2d97f99d83c96c2fa0cca7cee103e8cb4e7699ec4d5db7bd2633", - "https://deno.land/std@0.167.0/path/glob.ts": "81cc6c72be002cd546c7a22d1f263f82f63f37fe0035d9726aa96fc8f6e4afa1", - "https://deno.land/std@0.167.0/path/mod.ts": "cf7cec7ac11b7048bb66af8ae03513e66595c279c65cfa12bfc07d9599608b78", - "https://deno.land/std@0.167.0/path/posix.ts": "b859684bc4d80edfd4cad0a82371b50c716330bed51143d6dcdbe59e6278b30c", - "https://deno.land/std@0.167.0/path/separator.ts": "fe1816cb765a8068afb3e8f13ad272351c85cbc739af56dacfc7d93d710fe0f9", - "https://deno.land/std@0.167.0/path/win32.ts": "7cebd2bda6657371adc00061a1d23fdd87bcdf64b4843bb148b0b24c11b40f69", - "https://deno.land/std@0.184.0/_util/asserts.ts": "178dfc49a464aee693a7e285567b3d0b555dc805ff490505a8aae34f9cfb1462", - "https://deno.land/std@0.184.0/_util/os.ts": "d932f56d41e4f6a6093d56044e29ce637f8dcc43c5a90af43504a889cf1775e3", - "https://deno.land/std@0.184.0/async/abortable.ts": "fd682fa46f3b7b16b4606a5ab52a7ce309434b76f820d3221bdfb862719a15d7", - "https://deno.land/std@0.184.0/async/deadline.ts": "c5facb0b404eede83e38bd2717ea8ab34faa2ffb20ef87fd261fcba32ba307aa", - "https://deno.land/std@0.184.0/async/debounce.ts": "adab11d04ca38d699444ac8a9d9856b4155e8dda2afd07ce78276c01ea5a4332", - "https://deno.land/std@0.184.0/async/deferred.ts": "42790112f36a75a57db4a96d33974a936deb7b04d25c6084a9fa8a49f135def8", - "https://deno.land/std@0.184.0/async/delay.ts": "73aa04cec034c84fc748c7be49bb15cac3dd43a57174bfdb7a4aec22c248f0dd", - "https://deno.land/std@0.184.0/async/mod.ts": "f04344fa21738e5ad6bea37a6bfffd57c617c2d372bb9f9dcfd118a1b622e576", - "https://deno.land/std@0.184.0/async/mux_async_iterator.ts": "70c7f2ee4e9466161350473ad61cac0b9f115cff4c552eaa7ef9d50c4cbb4cc9", - "https://deno.land/std@0.184.0/async/pool.ts": "fd082bd4aaf26445909889435a5c74334c017847842ec035739b4ae637ae8260", - "https://deno.land/std@0.184.0/async/retry.ts": "dd19d93033d8eaddbfcb7654c0366e9d3b0a21448bdb06eba4a7d8a8cf936a92", - "https://deno.land/std@0.184.0/async/tee.ts": "47e42d35f622650b02234d43803d0383a89eb4387e1b83b5a40106d18ae36757", - "https://deno.land/std@0.184.0/fmt/colors.ts": "d67e3cd9f472535241a8e410d33423980bec45047e343577554d3356e1f0ef4e", - "https://deno.land/std@0.184.0/fs/_util.ts": "579038bebc3bd35c43a6a7766f7d91fbacdf44bc03468e9d3134297bb99ed4f9", - "https://deno.land/std@0.184.0/fs/ensure_dir.ts": "dc64c4c75c64721d4e3fb681f1382f803ff3d2868f08563ff923fdd20d071c40", - "https://deno.land/std@0.184.0/fs/walk.ts": "920be35a7376db6c0b5b1caf1486fb962925e38c9825f90367f8f26b5e5d0897", - "https://deno.land/std@0.184.0/http/server.ts": "cbb17b594651215ba95c01a395700684e569c165a567e4e04bba327f41197433", - "https://deno.land/std@0.184.0/path/_constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0", - "https://deno.land/std@0.184.0/path/_interface.ts": "6471159dfbbc357e03882c2266d21ef9afdb1e4aa771b0545e90db58a0ba314b", - "https://deno.land/std@0.184.0/path/_util.ts": "d7abb1e0dea065f427b89156e28cdeb32b045870acdf865833ba808a73b576d0", - "https://deno.land/std@0.184.0/path/common.ts": "ee7505ab01fd22de3963b64e46cff31f40de34f9f8de1fff6a1bd2fe79380000", - "https://deno.land/std@0.184.0/path/glob.ts": "d479e0a695621c94d3fd7fe7abd4f9499caf32a8de13f25073451c6ef420a4e1", - "https://deno.land/std@0.184.0/path/mod.ts": "bf718f19a4fdd545aee1b06409ca0805bd1b68ecf876605ce632e932fe54510c", - "https://deno.land/std@0.184.0/path/posix.ts": "8b7c67ac338714b30c816079303d0285dd24af6b284f7ad63da5b27372a2c94d", - "https://deno.land/std@0.184.0/path/separator.ts": "0fb679739d0d1d7bf45b68dacfb4ec7563597a902edbaf3c59b50d5bcadd93b1", - "https://deno.land/std@0.184.0/path/win32.ts": "d186344e5583bcbf8b18af416d13d82b35a317116e6460a5a3953508c3de5bba", - "https://deno.land/x/ulid@v0.3.0/mod.ts": "f7ff065b66abd485051fc68af23becef6ccc7e81f7774d7fcfd894a4b2da1984" + "redirects": { + "https://jsr.io/@da/bcrypt/1.0.1/src/worker.ts": "https://jsr.io/@da/bcrypt/1.0.1/" }, "workspace": { "dependencies": [ - "jsr:@andyburke/fsdb@1", + "jsr:@andyburke/fsdb@^1.0.2", "jsr:@andyburke/lurid@0.2", - "jsr:@andyburke/serverus@~0.9.3", + "jsr:@andyburke/serverus@~0.9.8", "jsr:@da/bcrypt@^1.0.1", "jsr:@std/assert@^1.0.13", "jsr:@std/encoding@^1.0.10", - "jsr:@std/http@^1.0.19", - "jsr:@std/path@^1.1.1", - "jsr:@stdext/crypto@0.1" + "jsr:@std/http@^1.0.20", + "jsr:@std/path@^1.1.1" ] } } diff --git a/models/event.ts b/models/event.ts index 87f06e6..c7f8165 100644 --- a/models/event.ts +++ b/models/event.ts @@ -1,6 +1,6 @@ -import { by_character, by_lurid } from 'jsr:@andyburke/fsdb/organizers'; -import { FSDB_COLLECTION } from 'jsr:@andyburke/fsdb'; -import { FSDB_INDEXER_SYMLINKS } from 'jsr:@andyburke/fsdb/indexers'; +import { by_character, by_lurid } from '@andyburke/fsdb/organizers'; +import { FSDB_COLLECTION } from '@andyburke/fsdb'; +import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers'; /** * @typedef {object} TIMESTAMPS diff --git a/models/password_entry.ts b/models/password_entry.ts index 2e3040c..566992b 100644 --- a/models/password_entry.ts +++ b/models/password_entry.ts @@ -1,4 +1,4 @@ -import { FSDB_COLLECTION } from 'jsr:@andyburke/fsdb'; +import { FSDB_COLLECTION } from '@andyburke/fsdb'; export type PASSWORD_ENTRY = { user_id: string; diff --git a/models/room.ts b/models/room.ts index 09b6e03..2d1db71 100644 --- a/models/room.ts +++ b/models/room.ts @@ -1,6 +1,6 @@ -import { by_character, by_lurid } from 'jsr:@andyburke/fsdb/organizers'; -import { FSDB_COLLECTION } from 'jsr:@andyburke/fsdb'; -import { FSDB_INDEXER_SYMLINKS } from 'jsr:@andyburke/fsdb/indexers'; +import { by_character, by_lurid } from '@andyburke/fsdb/organizers'; +import { FSDB_COLLECTION } from '@andyburke/fsdb'; +import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers'; /** * @typedef {object} ROOM_PERMISSIONS diff --git a/models/session.ts b/models/session.ts index 75903de..6e7e838 100644 --- a/models/session.ts +++ b/models/session.ts @@ -1,6 +1,6 @@ -import { FSDB_COLLECTION } from 'jsr:@andyburke/fsdb'; -import { FSDB_INDEXER_SYMLINKS } from 'jsr:@andyburke/fsdb/indexers'; -import { by_lurid } from 'jsr:@andyburke/fsdb/organizers'; +import { FSDB_COLLECTION } from '@andyburke/fsdb'; +import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers'; +import { by_lurid } from '@andyburke/fsdb/organizers'; export type SESSION = { id: string; diff --git a/models/totp_entry.ts b/models/totp_entry.ts index 63a94b6..5150003 100644 --- a/models/totp_entry.ts +++ b/models/totp_entry.ts @@ -1,4 +1,4 @@ -import { FSDB_COLLECTION } from 'jsr:@andyburke/fsdb'; +import { FSDB_COLLECTION } from '@andyburke/fsdb'; export type TOTP_ENTRY = { user_id: string; diff --git a/models/user.ts b/models/user.ts index 92fd335..a304eab 100644 --- a/models/user.ts +++ b/models/user.ts @@ -1,6 +1,6 @@ -import { FSDB_COLLECTION } from 'jsr:@andyburke/fsdb'; -import { FSDB_INDEXER_SYMLINKS } from 'jsr:@andyburke/fsdb/indexers'; -import { by_character } from 'jsr:@andyburke/fsdb/organizers'; +import { FSDB_COLLECTION } from '@andyburke/fsdb'; +import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers'; +import { by_character } from '@andyburke/fsdb/organizers'; export type USER = { id: string; diff --git a/public/api/auth/index.ts b/public/api/auth/index.ts index 05a97ae..759ea86 100644 --- a/public/api/auth/index.ts +++ b/public/api/auth/index.ts @@ -1,13 +1,13 @@ import { PASSWORD_ENTRIES } from '../../../models/password_entry.ts'; import { USER, USERS } from '../../../models/user.ts'; -import { encodeBase32 } from 'jsr:@std/encoding'; -import lurid from 'jsr:@andyburke/lurid'; +import { encodeBase32 } from '@std/encoding'; +import lurid from '@andyburke/lurid'; import { SESSION, SESSIONS } from '../../../models/session.ts'; import { TOTP_ENTRIES } from '../../../models/totp_entry.ts'; -import { encodeBase64 } from 'jsr:@std/encoding/base64'; +import { encodeBase64 } from '@std/encoding/base64'; import parse_body from '../../../utils/bodyparser.ts'; import { get_session, get_user, PRECHECK_TABLE, require_user, SESSION_ID_TOKEN, SESSION_SECRET_TOKEN } from '../../../utils/prechecks.ts'; -import * as bcrypt from 'jsr:@da/bcrypt'; +import * as bcrypt from '@da/bcrypt'; import { verifyTotp } from '../../../utils/totp.ts'; const DEFAULT_SESSION_TIME: number = 28 * (24 * (60 * (60 * 1_000))); // 28 days @@ -79,7 +79,7 @@ export async function POST(req: Request, meta: Record): Promise): Promise< }; const results = (await events.all(options)) - .map((entry) => entry.load()) - .sort((lhs_item, rhs_item) => rhs_item.timestamps.created.localeCompare(lhs_item.timestamps.created)); + .map((entry: WALK_ENTRY) => entry.load()) + .sort((lhs_item: EVENT, rhs_item: EVENT) => rhs_item.timestamps.created.localeCompare(lhs_item.timestamps.created)); // long-polling support if (results.length === 0 && meta.query.wait) { @@ -106,10 +106,12 @@ export async function GET(request: Request, meta: Record): Promise< events.on('create', on_create); request.signal.addEventListener('abort', () => { events.off('create', on_create); + clearTimeout(timeout); reject(new Error('request aborted')); }); Deno.addSignalListener('SIGINT', () => { events.off('create', on_create); + clearTimeout(timeout); return resolve(Response.json(results, { status: 200, headers diff --git a/public/api/rooms/index.ts b/public/api/rooms/index.ts index 020592a..2366ab0 100644 --- a/public/api/rooms/index.ts +++ b/public/api/rooms/index.ts @@ -1,10 +1,10 @@ -import lurid from 'jsr:@andyburke/lurid'; +import lurid from '@andyburke/lurid'; import parse_body from '../../../utils/bodyparser.ts'; import { get_session, get_user, require_user } from '../../../utils/prechecks.ts'; import * as CANNED_RESPONSES from '../../../utils/canned_responses.ts'; import { PRECHECK_TABLE } from '../../../utils/prechecks.ts'; import { ROOM, ROOMS } from '../../../models/room.ts'; -import { WALK_ENTRY } from 'jsr:@andyburke/fsdb'; +import { WALK_ENTRY } from '@andyburke/fsdb'; export const PRECHECKS: PRECHECK_TABLE = {}; diff --git a/public/api/users/index.ts b/public/api/users/index.ts index 988803f..a367162 100644 --- a/public/api/users/index.ts +++ b/public/api/users/index.ts @@ -1,12 +1,12 @@ import { PASSWORD_ENTRIES, PASSWORD_ENTRY } from '../../../models/password_entry.ts'; import { USER, USERS } from '../../../models/user.ts'; -import lurid from 'jsr:@andyburke/lurid'; -import { encodeBase64 } from 'jsr:@std/encoding'; +import lurid from '@andyburke/lurid'; +import { encodeBase64 } from '@std/encoding'; import parse_body from '../../../utils/bodyparser.ts'; import { create_new_session, SESSION_RESULT } from '../auth/index.ts'; import { get_session, get_user, PRECHECK_TABLE, require_user } from '../../../utils/prechecks.ts'; import * as CANNED_RESPONSES from '../../../utils/canned_responses.ts'; -import * as bcrypt from 'jsr:@da/bcrypt'; +import * as bcrypt from '@da/bcrypt'; // TODO: figure out a better solution for doling out permissions const DEFAULT_USER_PERMISSIONS: string[] = [ @@ -107,7 +107,7 @@ export async function POST(req: Request, meta: Record): Promise { let test_server_info: EPHEMERAL_SERVER | null = null; try { @@ -110,11 +115,13 @@ Deno.test({ asserts.assert(Array.isArray(long_polled_events)); asserts.assertEquals(long_polled_events.length, 1); asserts.assertEquals(long_polled_events[0].data?.i, 12345); + console.log('done'); }); } finally { + console.log('finally'); clear_room_events_cache(); if (test_server_info) { - await test_server_info?.server?.stop(); + await test_server_info.server.stop(); } } } diff --git a/tests/api/rooms/events/update_events.test.ts b/tests/api/rooms/events/update_events.test.ts index 282a6c2..0e6d7f1 100644 --- a/tests/api/rooms/events/update_events.test.ts +++ b/tests/api/rooms/events/update_events.test.ts @@ -1,7 +1,7 @@ -import * as asserts from 'jsr:@std/assert'; +import * as asserts from '@std/assert'; import { EPHEMERAL_SERVER, get_ephemeral_listen_server, get_new_user, set_user_permissions } from '../../../helpers.ts'; import { api, API_CLIENT } from '../../../../utils/api.ts'; -import { generateTotp } from '@stdext/crypto/totp'; +import { generateTotp } from '../../../../utils/totp.ts'; import { clear_room_events_cache } from '../../../../models/event.ts'; Deno.test({ diff --git a/tests/api/rooms/events/update_events_when_append_only.test.ts b/tests/api/rooms/events/update_events_when_append_only.test.ts index 8cf4725..de69253 100644 --- a/tests/api/rooms/events/update_events_when_append_only.test.ts +++ b/tests/api/rooms/events/update_events_when_append_only.test.ts @@ -1,7 +1,7 @@ -import * as asserts from 'jsr:@std/assert'; +import * as asserts from '@std/assert'; import { EPHEMERAL_SERVER, get_ephemeral_listen_server, get_new_user, set_user_permissions } from '../../../helpers.ts'; import { api, API_CLIENT } from '../../../../utils/api.ts'; -import { generateTotp } from '@stdext/crypto/totp'; +import { generateTotp } from '../../../../utils/totp.ts'; import { clear_room_events_cache } from '../../../../models/event.ts'; Deno.test({ diff --git a/tests/api/rooms/update_room.test.ts b/tests/api/rooms/update_room.test.ts index cfe4194..0a152cb 100644 --- a/tests/api/rooms/update_room.test.ts +++ b/tests/api/rooms/update_room.test.ts @@ -1,7 +1,7 @@ import { api, API_CLIENT } from '../../../utils/api.ts'; -import * as asserts from 'jsr:@std/assert'; +import * as asserts from '@std/assert'; import { EPHEMERAL_SERVER, get_ephemeral_listen_server, get_new_user, set_user_permissions } from '../../helpers.ts'; -import { generateTotp } from '@stdext/crypto/totp'; +import { generateTotp } from '../../../utils/totp.ts'; import { clear_room_events_cache } from '../../../models/event.ts'; Deno.test({ diff --git a/tests/api/users/create_user.test.ts b/tests/api/users/create_user.test.ts index a14f050..6eb3585 100644 --- a/tests/api/users/create_user.test.ts +++ b/tests/api/users/create_user.test.ts @@ -1,10 +1,10 @@ import { api, API_CLIENT } from '../../../utils/api.ts'; -import * as asserts from 'jsr:@std/assert'; +import * as asserts from '@std/assert'; import { USER } from '../../../models/user.ts'; import { EPHEMERAL_SERVER, get_ephemeral_listen_server, random_username } from '../../helpers.ts'; import { Cookie, getSetCookies } from '@std/http/cookie'; import { encodeBase64 } from '@std/encoding'; -import { generateTotp } from '@stdext/crypto/totp'; +import { generateTotp } from '../../../utils/totp.ts'; Deno.test({ name: 'API - USERS - Create', diff --git a/tests/api/users/delete_user.test.ts b/tests/api/users/delete_user.test.ts index 2066137..7e60446 100644 --- a/tests/api/users/delete_user.test.ts +++ b/tests/api/users/delete_user.test.ts @@ -4,7 +4,7 @@ import { USER } from '../../../models/user.ts'; import { EPHEMERAL_SERVER, get_ephemeral_listen_server, random_username } from '../../helpers.ts'; import { Cookie, getSetCookies } from '@std/http/cookie'; import { encodeBase64 } from '@std/encoding'; -import { generateTotp } from '@stdext/crypto/totp'; +import { generateTotp } from '../../../utils/totp.ts'; Deno.test({ name: 'API - USERS - Delete', diff --git a/tests/api/users/login.test.ts b/tests/api/users/login.test.ts index 72993a8..8bd92bb 100644 --- a/tests/api/users/login.test.ts +++ b/tests/api/users/login.test.ts @@ -4,7 +4,7 @@ import { USER } from '../../../models/user.ts'; import { EPHEMERAL_SERVER, get_ephemeral_listen_server, random_username } from '../../helpers.ts'; import { Cookie, getSetCookies } from '@std/http/cookie'; import { encodeBase64 } from '@std/encoding'; -import { generateTotp } from '@stdext/crypto/totp'; +import { generateTotp } from '../../../utils/totp.ts'; Deno.test({ name: 'API - USERS - Login (password)', diff --git a/tests/api/users/update_user.test.ts b/tests/api/users/update_user.test.ts index 59dc3ba..478bfed 100644 --- a/tests/api/users/update_user.test.ts +++ b/tests/api/users/update_user.test.ts @@ -4,7 +4,7 @@ import { USER } from '../../../models/user.ts'; import { EPHEMERAL_SERVER, get_ephemeral_listen_server, random_username } from '../../helpers.ts'; import { Cookie, getSetCookies } from '@std/http/cookie'; import { encodeBase64 } from '@std/encoding'; -import { generateTotp } from '@stdext/crypto/totp'; +import { generateTotp } from '../../../utils/totp.ts'; Deno.test({ name: 'API - USERS - Update', diff --git a/tests/helpers.ts b/tests/helpers.ts index 776fd7e..d7e7cdb 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -1,8 +1,8 @@ -import { SERVER, SERVER_OPTIONS } from 'jsr:@andyburke/serverus/server'; -import { convert_to_words } from 'jsr:@andyburke/lurid/word_bytes'; +import { SERVER, SERVER_OPTIONS } from '@andyburke/serverus/server'; +import { convert_to_words } from '@andyburke/lurid/word_bytes'; import { API_CLIENT } from '../utils/api.ts'; import { Cookie, getSetCookies } from '@std/http/cookie'; -import { generateTotp } from '@stdext/crypto/totp'; +import { generateTotp } from '../utils/totp.ts'; const TLDs: string[] = [ 'com', diff --git a/utils/api.ts b/utils/api.ts index 116ade6..60cdc75 100644 --- a/utils/api.ts +++ b/utils/api.ts @@ -1,5 +1,5 @@ import { getSetCookies } from '@std/http/cookie'; -import { generateTotp } from '@stdext/crypto/totp'; +import { generateTotp } from './totp.ts'; export interface API_CLIENT { fetch: (url: string, options?: FETCH_OPTIONS, transform?: (obj: any) => any) => Promise; diff --git a/utils/prechecks.ts b/utils/prechecks.ts index f3d0333..53d162c 100644 --- a/utils/prechecks.ts +++ b/utils/prechecks.ts @@ -1,6 +1,6 @@ -import { getCookies } from 'jsr:@std/http/cookie'; +import { getCookies } from '@std/http/cookie'; import { SESSIONS } from '../models/session.ts'; -import { verifyTotp } from 'jsr:@stdext/crypto/totp'; +import { verifyTotp } from './totp.ts'; import { USERS } from '../models/user.ts'; import * as CANNED_RESPONSES from './canned_responses.ts'; diff --git a/utils/totp.ts b/utils/totp.ts index d2bd404..0954824 100644 --- a/utils/totp.ts +++ b/utils/totp.ts @@ -1,7 +1,7 @@ // https://jsr.io/@stdext/crypto/0.1.0/hotp.ts // https://jsr.io/@stdext/crypto/0.1.0/totp.ts -import { decodeBase32 } from 'jsr:@std/encoding@^1'; +import { decodeBase32 } from '@std/encoding'; /** Converts a counter value to a DataView. *