diff --git a/.env.example b/.env.example index 17cf5d39..3f75ae41 100644 --- a/.env.example +++ b/.env.example @@ -21,7 +21,6 @@ REACT_APP_WCA_ORIGIN=https://www.worldcubeassociation.org REACT_APP_WCA_CLIENT_ID=replace-me # Server config -MONGO_URL=mongodb://mongo:27017/letscube REDIS_URL=redis://redis:6379 POSTGRES_ENABLED=true # DATABASE_URL can replace the individual PG* connection fields. @@ -51,9 +50,9 @@ METRICS_HASH_SECRET=replace-with-a-different-long-random-secret LETSENCRYPT_DIR=/etc/letsencrypt CERTBOT_WWW_DIR=/var/www/certbot -# Mongo backups +# PostgreSQL backups BACKUP_DIR=/opt/letscube/backups -MONGO_BACKUP_URI=mongodb://127.0.0.1:27017/letscube +PG_BACKUP_URI=postgresql://letscube:replace-with-a-long-random-secret@127.0.0.1:5432/letscube BACKUP_S3_URI= AWS_ENDPOINT_URL= AWS_ACCESS_KEY_ID= diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dda18174..e5f405c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,18 +18,21 @@ jobs: - name: Validate production metrics configuration run: scripts/test-compose-metrics-config.sh + - name: Validate production deployment + run: | + scripts/test-deploy-classifier.sh + scripts/test-deploy.sh + scripts/test-image-deploy.sh + scripts/test-production-repair.sh + scripts/test-deploy-workflow.sh + scripts/test-backup-postgres.sh + - name: Validate CI branch coverage run: scripts/test-ci-branches.sh - name: Validate CodeQL branch coverage run: scripts/test-codeql-branches.sh - - name: Rehearse MongoDB backup and restore scripts - run: scripts/test-mongo-backup-restore.sh - - - name: Rehearse a live MongoDB backup and restore - run: scripts/test-mongo-backup-restore-live.sh - server: name: Server lint and unit tests runs-on: ubuntu-latest @@ -108,6 +111,26 @@ jobs: cypress: name: Cypress full-stack smoke runs-on: ubuntu-latest + env: + PGHOST: 127.0.0.1 + PGPORT: 5432 + PGDATABASE: letscube + PGUSER: letscube + PGPASSWORD: letscube + services: + postgres: + image: postgres:17-alpine + env: + POSTGRES_DB: letscube + POSTGRES_USER: letscube + POSTGRES_PASSWORD: letscube + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U letscube -d letscube" + --health-interval 10s + --health-timeout 5s + --health-retries 5 steps: - name: Check out repository uses: actions/checkout@v4 @@ -131,13 +154,16 @@ jobs: node-version: 22.17.0 - name: Start backing services - run: docker compose -f compose.yml -f compose.dev.yml up -d mongo redis + run: docker compose -f compose.yml -f compose.dev.yml up -d redis + + - name: Apply PostgreSQL migrations + run: yarn workspace letscube-server postgres:migrate - name: Start server - run: CORS_ORIGINS=http://localhost:3000,http://localhost:8080 LETSCUBE_TEST_AUTH=true SOCIAL_FEATURES_ENABLED=true POSTGRES_ENABLED=false yarn workspace letscube-server node index.js > server.log 2>&1 & + run: CORS_ORIGINS=http://localhost:3000,http://localhost:8080 LETSCUBE_TEST_AUTH=true SOCIAL_FEATURES_ENABLED=true yarn workspace letscube-server node index.js > server.log 2>&1 & - name: Start socket server - run: SOCIAL_FEATURES_ENABLED=true POSTGRES_ENABLED=false yarn workspace letscube-server node socket/ > socket.log 2>&1 & + run: SOCIAL_FEATURES_ENABLED=true yarn workspace letscube-server node socket/ > socket.log 2>&1 & - name: Wait for local stack run: | diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..f502394f --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,207 @@ +name: Production deploy + +on: + workflow_run: + workflows: [CI] + branches: [master] + types: [completed] + workflow_dispatch: + inputs: + ref: + description: Commit, branch, or tag to deploy. Defaults to master. + required: false + type: string + +permissions: + contents: read + packages: write + +concurrency: + group: production-deploy + cancel-in-progress: false + +jobs: + resolve: + name: Resolve release source + if: >- + github.event_name == 'workflow_dispatch' + || ( + github.event.workflow_run.conclusion == 'success' + && github.event.workflow_run.head_branch == 'master' + ) + runs-on: ubuntu-24.04 + outputs: + source_sha: ${{ steps.source.outputs.source_sha }} + steps: + - name: Check out release source + uses: actions/checkout@v4 + with: + ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || inputs.ref || 'master' }} + fetch-depth: 0 + + - name: Resolve exact commit + id: source + run: echo "source_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + + image: + name: Build immutable image + needs: resolve + runs-on: ubuntu-24.04 + outputs: + image_ref: ${{ steps.image.outputs.image_ref }} + steps: + - name: Check out exact release source + uses: actions/checkout@v4 + with: + ref: ${{ needs.resolve.outputs.source_sha }} + + - uses: docker/setup-buildx-action@v3 + + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + + - name: Build and publish release image with retries + id: build + env: + IMAGE_TAG: ghcr.io/${{ github.repository }}:${{ needs.resolve.outputs.source_sha }} + SOURCE_SHA: ${{ needs.resolve.outputs.source_sha }} + run: | + for attempt in 1 2 3; do + if docker buildx build . \ + --build-arg "SOURCE_SHA=$SOURCE_SHA" \ + --cache-from type=gha,scope=production-image \ + --cache-to type=gha,mode=max,scope=production-image \ + --metadata-file /tmp/build-metadata.json \ + --push \ + --tag "$IMAGE_TAG"; then + digest=$(jq -r '."containerimage.digest" // empty' /tmp/build-metadata.json) + [[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]] + echo "digest=$digest" >> "$GITHUB_OUTPUT" + exit 0 + fi + + if [ "$attempt" -lt 3 ]; then + echo "Image build attempt $attempt failed. Retrying in 30 seconds." >&2 + sleep 30 + fi + done + exit 1 + + - name: Record digest-qualified image + id: image + env: + IMAGE_REPOSITORY: ghcr.io/${{ github.repository }} + IMAGE_DIGEST: ${{ steps.build.outputs.digest }} + run: | + [[ "$IMAGE_DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]] + echo "image_ref=$IMAGE_REPOSITORY@$IMAGE_DIGEST" >> "$GITHUB_OUTPUT" + + deploy: + name: Activate production release + needs: [resolve, image] + runs-on: ubuntu-24.04 + timeout-minutes: 30 + environment: production + env: + APP_DIR: /opt/letscube/runtime + ENV_FILE: /home/www/letscube/.env.prod + PRIVACY_EMAIL_CUTOVER_FILE: /home/www/letscube/.privacy-email-cutover + SERVER_IP: ${{ secrets.SERVER_IP }} + SERVER_USER: www + SOURCE_SHA: ${{ needs.resolve.outputs.source_sha }} + IMAGE_REF: ${{ needs.image.outputs.image_ref }} + steps: + - name: Check out exact release source + uses: actions/checkout@v4 + with: + ref: ${{ needs.resolve.outputs.source_sha }} + fetch-depth: 0 + + - name: Configure deployment SSH + env: + DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }} + DEPLOY_KNOWN_HOSTS: ${{ secrets.DEPLOY_KNOWN_HOSTS }} + run: | + install -m 700 -d "$HOME/.ssh" + printf '%s\n' "$DEPLOY_SSH_KEY" > "$HOME/.ssh/id_ed25519" + printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$HOME/.ssh/known_hosts" + chmod 600 "$HOME/.ssh/id_ed25519" "$HOME/.ssh/known_hosts" + + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + + - name: Pull and validate the immutable image + run: | + docker pull "$IMAGE_REF" + test "$(docker image inspect "$IMAGE_REF" --format '{{index .RepoDigests 0}}')" = "$IMAGE_REF" + test "$(docker image inspect "$IMAGE_REF" --format '{{index .Config.Labels "org.opencontainers.image.revision"}}')" = "$SOURCE_SHA" + docker tag "$IMAGE_REF" "letscube-app:$SOURCE_SHA" + + - name: Enforce the production privacy floor + run: | + cutover=$(ssh -q "$SERVER_USER@$SERVER_IP" \ + "test ! -f '$PRIVACY_EMAIL_CUTOVER_FILE' || cat '$PRIVACY_EMAIL_CUTOVER_FILE'") + if [ -n "$cutover" ]; then + [[ "$cutover" =~ ^[0-9a-f]{40}$ ]] + git merge-base --is-ancestor "$cutover" "$SOURCE_SHA" + fi + + - name: Stage release configuration + run: | + remote_release_dir="/tmp/letscube-release-$SOURCE_SHA" + ssh -q "$SERVER_USER@$SERVER_IP" "mkdir -p '$remote_release_dir'" + scp -q compose.yml compose.prod.yml nginx.conf \ + scripts/deploy-image-release.sh scripts/check-production-health.sh \ + scripts/repair-production-services.sh \ + scripts/disable-legacy-deploy-cron.sh \ + "$SERVER_USER@$SERVER_IP:$remote_release_dir/" + + - name: Transfer the release image + run: | + set -o pipefail + for attempt in 1 2 3; do + if docker save "letscube-app:$SOURCE_SHA" | gzip | \ + ssh -q "$SERVER_USER@$SERVER_IP" 'gzip -d | docker load'; then + exit 0 + fi + + if [ "$attempt" -lt 3 ]; then + echo "Image transfer attempt $attempt failed. Retrying in 30 seconds." >&2 + sleep 30 + fi + done + exit 1 + + - name: Deploy with bounded automatic retries + run: | + remote_release_dir="/tmp/letscube-release-$SOURCE_SHA" + for attempt in 1 2 3; do + if ssh -q "$SERVER_USER@$SERVER_IP" \ + "APP_DIR='$APP_DIR' ENV_FILE='$ENV_FILE' bash '$remote_release_dir/deploy-image-release.sh' '$SOURCE_SHA' '$remote_release_dir'"; then + exit 0 + fi + + if [ "$attempt" -lt 3 ]; then + echo "Deployment attempt $attempt failed. Retrying the same image in 30 seconds." >&2 + sleep 30 + fi + done + exit 1 + + - name: Replace the legacy deployment cron with health repair + run: | + remote_release_dir="/tmp/letscube-release-$SOURCE_SHA" + ssh -q "$SERVER_USER@$SERVER_IP" \ + "APP_DIR='$APP_DIR' ENV_FILE='$ENV_FILE' bash '$remote_release_dir/disable-legacy-deploy-cron.sh'" + + - name: Remove staged release files + if: always() + run: | + remote_release_dir="/tmp/letscube-release-$SOURCE_SHA" + ssh -q "$SERVER_USER@$SERVER_IP" "rm -rf -- '$remote_release_dir'" || true diff --git a/Dockerfile b/Dockerfile index e7bdecbf..9f517456 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,10 @@ FROM node:22-bookworm-slim AS client-build WORKDIR /app +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates openssl \ + && rm -rf /var/lib/apt/lists/* + RUN corepack enable COPY package.json yarn.lock ./ @@ -27,7 +31,7 @@ RUN yarn workspace letscube-client build FROM node:22-bookworm-slim AS server-deps RUN apt-get update \ - && apt-get install -y --no-install-recommends python3 make g++ \ + && apt-get install -y --no-install-recommends ca-certificates openssl python3 make g++ \ && rm -rf /var/lib/apt/lists/* WORKDIR /app @@ -42,6 +46,8 @@ RUN yarn install --frozen-lockfile --production=true --network-concurrency 1 --n && mkdir -p server/node_modules FROM node:22-bookworm-slim AS runtime +ARG SOURCE_SHA=local +LABEL org.opencontainers.image.revision=${SOURCE_SHA} ENV NODE_ENV=prod ENV PORT=8080 ENV SOCKETIO_PORT=9000 diff --git a/README.md b/README.md index 39383a07..88973ad0 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,8 @@ The server's owner/admin handoff and reconnect guarantees are documented in ## Metrics -The server stores pseudonymous room and authentication events in both the -`metric_events` MongoDB collection and the PostgreSQL `analytics.events` table. +The server stores pseudonymous room and authentication events in the +PostgreSQL `analytics.events` table. It records room creations, joins, join failures, leaves and visit duration, accepted result counts, and authentication failures. Peak room users and peak room solve counts are the maximum `activeUserCount` and `roomSolveCount` values @@ -100,18 +100,14 @@ ability to correlate pseudonymous users and rooms across the change. Metrics never include names, email addresses, WCA IDs, room names, passwords, access codes, OAuth credentials, chat content, scramble text, or solve times. -## PostgreSQL dual writes +## PostgreSQL storage -New MongoDB writes are mirrored into PostgreSQL without changing application -reads. PostgreSQL receives public identity and preferences, rooms and -participant state, RaceSession projections for normal rooms, attempts, durable -solve results, and sanitized analytics events. OAuth access tokens are deliberately not copied. Writes use -deterministic UUIDs and upserts, -so retries and future backfills are idempotent. Live room saves mirror only the -attempts and results changed by that save; complete room snapshots are reserved -for explicit backfills. Changing a normal room event ends its projected -RaceSession and starts a new one; earlier attempts and solves remain preserved -under their earlier session. +PostgreSQL stores public identity and preferences, rooms and participant state, +RaceSessions, attempts, durable solve results, social data, sessions, and +sanitized analytics events. OAuth access tokens are deliberately not persisted. +Writes use deterministic UUIDs and upserts, so retries remain idempotent. A +one-time MongoDB backfill tool exists only for cutover and is not loaded by the +runtime. Solve penalties use dedicated boolean columns rather than JSON so histories and statistics remain compact and index-friendly. `GET /api/solve-history` reads @@ -119,14 +115,13 @@ PostgreSQL session-linked history for the authenticated participant. It is enabled in development and may be enabled for selected production users with `FEATURE_SOLVE_HISTORY_USER_IDS`. -Set `POSTGRES_ENABLED=false` to disable mirroring. Production should set +Production should set `PGHOST`, `PGDATABASE`, `PGUSER`, and `POSTGRES_PASSWORD`, or provide a `DATABASE_URL`. When runtime traffic uses a pooled connection, set `DIRECT_DATABASE_URL` to the direct connection used by Prisma Migrate. External TLS connections can set `PGSSL=true` and provide a CA with `PGSSL_CA`; -certificate verification is enabled by default. PostgreSQL failures are logged -but do not fail the corresponding MongoDB-backed application operation during -this migration phase. +certificate verification is enabled by default. PostgreSQL is required for both +application processes; startup and health checks fail closed if it is unavailable. Username lookup uses a separately normalized, uniquely indexed key while preserving display casing. See [the normalized username migration](docs/username-migration.md) diff --git a/README_DEPLOYMENT.md b/README_DEPLOYMENT.md index 2e38878e..527152e7 100644 --- a/README_DEPLOYMENT.md +++ b/README_DEPLOYMENT.md @@ -1,13 +1,13 @@ # LetsCube Deployment -This repo supports running LetsCube with Docker Compose on one VPS. The intended production stack is `api`, `socket`, `mongo`, `postgres`, `redis`, and `nginx`. +This repo supports running LetsCube with Docker Compose on one VPS. The intended production stack is `api`, `socket`, `postgres`, `redis`, and `nginx`. ## Current Startup Audit - The app currently has two Node entrypoints, not one: `server/index.js` for Express/API/static frontend on port `8080`, and `server/socket/index.js` for Socket.IO on port `9000`. - The Express server serves `client/build` directly, so the production Docker image builds the React client and copies it next to the server code. - PM2 is no longer needed in Docker. Compose runs `api` and `socket` as separate services with `restart: unless-stopped`. -- MongoDB was previously read from `server/config/*.json` as `mongodb://127.0.0.1/letscube`; containers should use `MONGO_URL=mongodb://mongo:27017/letscube`. +- PostgreSQL is the only durable application datastore. The runtime does not connect to MongoDB. - Redis was previously hardcoded to `localhost:6379` in the socket process; it is now env-driven with `REDIS_URL=redis://redis:6379`. - Required production secrets are `AUTH_SECRET`, `WCA_CLIENT_ID`, and `WCA_CLIENT_SECRET`. The client build also needs `REACT_APP_WCA_CLIENT_ID`. - The target Node runtime is Node `22.17.0`, and the frontend is built with Vite. @@ -26,7 +26,6 @@ Development ports: - Client: `http://localhost:3000` - API/static server: `http://localhost:8080` - Socket.IO: `http://localhost:9000` -- MongoDB: `127.0.0.1:27017` - Redis: `127.0.0.1:6379` The dev override bind mounts the repo and keeps container `node_modules` in named volumes. @@ -51,7 +50,7 @@ immutable. `APP_IMAGE_TAG=local` remains available for direct development and one-off Compose use. The deployment script always overrides `APP_IMAGE_TAG` with the commit it checked out. -The nginx container listens on ports `80` and `443`, proxies `/socket.io/` to `socket:9000`, and proxies everything else to `api:8080`. MongoDB, PostgreSQL, and Redis are internal only. +The nginx container listens on ports `80` and `443`, proxies `/socket.io/` to `socket:9000`, and proxies everything else to `api:8080`. PostgreSQL and Redis are internal only. TLS expects Let’s Encrypt files at: @@ -75,7 +74,6 @@ View logs: ```bash docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod logs -f api docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod logs -f socket -docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod logs -f mongo docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod logs -f postgres docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod logs -f redis docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod logs -f nginx @@ -228,8 +226,8 @@ run the purge. Correct the release and redeploy it first. After step 3, the privacy-safe commit is the minimum supported rollback image. The PostgreSQL `app.users.email` column remains temporarily as an always-empty -compatibility column. Current dual writes never send it a value and clear a -legacy value whenever they update an existing row. Removing the column is phase two: +compatibility column. Runtime writes never send it a value and clear a legacy +value whenever they update an existing row. Removing the column is phase two: first deploy an application release that no longer references the compatibility column, advance every supported rollback image to that release, and only then apply a migration that drops it. Do not combine that drop with this cutover. @@ -247,10 +245,8 @@ their realtime relay; normal room behavior is unaffected. ### Health Checks The API and socket processes expose dependency-aware health endpoints. -Unavailable MongoDB or Redis returns HTTP `503` with the failing check marked -`error`. PostgreSQL dual writes are optional, so a PostgreSQL outage returns -HTTP `200` with overall status `degraded` while the primary MongoDB/Redis path -remains ready. +Unavailable PostgreSQL or Redis returns HTTP `503` with the failing check marked +`error`. PostgreSQL is required for both application processes. ```bash curl -sS https://letscube.net/health/api @@ -264,43 +260,56 @@ connection in addition to the HTTP readiness endpoint. ## Backups And Restore -Run a MongoDB backup: +Run the backup script from the production checkout: ```bash -APP_DIR=/opt/letscube BACKUP_DIR=/opt/letscube/backups scripts/backup-mongo.sh +APP_DIR=/opt/letscube \ +BACKUP_DIR=/opt/letscube/backups \ +BACKUP_RETENTION_DAYS=14 \ + ./scripts/backup-postgres.sh ``` -The backup script creates timestamped gzip archives and keeps 7 daily, 4 weekly, and 3 monthly local backups. To upload off-server, configure `BACKUP_S3_URI` plus AWS or S3-compatible credentials in the environment. +The script writes a temporary file before it publishes the backup. It removes +PostgreSQL backups that are older than the retention period. It does not remove +other files. + +Copy encrypted backups to a different host. Test restores against a separate +database before you rely on the backups. Example cron: +Create the log directory before you install the cron entry: + +```bash +mkdir -p /opt/letscube/logs +``` + ```cron -15 3 * * * cd /opt/letscube && /opt/letscube/scripts/backup-mongo.sh >> /opt/letscube/logs/backup-mongo.log 2>&1 +17 8 * * * flock -n /tmp/letscube-postgres-backup.lock sh -c 'cd /opt/letscube && APP_DIR=/opt/letscube BACKUP_DIR=/opt/letscube/backups BACKUP_RETENTION_DAYS=14 ./scripts/backup-postgres.sh' >> /opt/letscube/logs/backup-postgres.log 2>&1 ``` -Restore from a backup: +Restore into a separate PostgreSQL database for verification: ```bash -APP_DIR=/opt/letscube scripts/restore-mongo.sh /opt/letscube/backups/letscube-mongo-daily-YYYYmmddTHHMMSSZ.archive.gz +docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod \ + exec -T postgres pg_restore -U "$PGUSER" -d "$PGDATABASE" --clean --if-exists < /path/to/letscube-postgres.dump ``` -The restore script requires typing `RESTORE` and uses `mongorestore --drop`. - ## Migration To A New VPS Do not upgrade the old VPS in place for this migration. 1. Snapshot the existing VPS. -2. Take a fresh MongoDB backup on the current server and copy it off-server. +2. Take a fresh backup of the source database and copy it off-server. 3. Create a new VPS. 4. Install Docker Engine and the modern `docker compose` plugin. 5. Clone this repo to `/opt/letscube`. 6. Create `.env.prod` with production secrets and domains. 7. Copy or issue Let’s Encrypt certs for `letscube.net`. -8. Start MongoDB, PostgreSQL, and Redis containers. -9. Restore MongoDB from the production backup. +8. Start PostgreSQL and Redis containers. +9. Run `yarn workspace letscube-server postgres:migrate` and the documented one-time MongoDB backfill during the maintenance window. 10. Start the full production stack. 11. Test frontend loading, login, room create/join, race/session flows, Redis-backed socket behavior, backups, and restore on non-production data. -12. Confirm MongoDB, PostgreSQL, and Redis are not publicly reachable. +12. Confirm PostgreSQL and Redis are not publicly reachable. 13. Point DNS at the new VPS. 14. Keep the old VPS available for rollback until the new stack has been stable. diff --git a/compose.dev.yml b/compose.dev.yml index a1689a4e..4bb5174a 100644 --- a/compose.dev.yml +++ b/compose.dev.yml @@ -31,7 +31,6 @@ services: NODE_ENV: dev PORT: ${PORT:-8080} SOCKETIO_PORT: ${SOCKETIO_PORT:-9000} - MONGO_URL: ${MONGO_URL:-mongodb://mongo:27017/letscube} REDIS_URL: ${REDIS_URL:-redis://redis:6379} AUTH_SECRET: ${AUTH_SECRET:-dev-secret} AUTH_CALLBACK_URL: ${AUTH_CALLBACK_URL:-http://localhost:8080/auth/callback} @@ -53,7 +52,6 @@ services: NODE_ENV: dev PORT: ${PORT:-8080} SOCKETIO_PORT: ${SOCKETIO_PORT:-9000} - MONGO_URL: ${MONGO_URL:-mongodb://mongo:27017/letscube} REDIS_URL: ${REDIS_URL:-redis://redis:6379} AUTH_SECRET: ${AUTH_SECRET:-dev-secret} AUTH_CALLBACK_URL: ${AUTH_CALLBACK_URL:-http://localhost:8080/auth/callback} @@ -67,10 +65,6 @@ services: ports: - "9000:9000" - mongo: - ports: - - "127.0.0.1:27017:27017" - redis: ports: - "127.0.0.1:6379:6379" diff --git a/compose.prod.yml b/compose.prod.yml index f75bc218..65a3cafc 100644 --- a/compose.prod.yml +++ b/compose.prod.yml @@ -6,25 +6,32 @@ x-app-build: &app-build REACT_APP_WCA_ORIGIN: ${REACT_APP_WCA_ORIGIN:-https://www.worldcubeassociation.org} REACT_APP_WCA_CLIENT_ID: ${REACT_APP_WCA_CLIENT_ID:-} +x-production-logging: &production-logging + driver: json-file + options: + max-size: "20m" + max-file: "3" + services: migrate: build: *app-build api: build: *app-build + logging: *production-logging restart: unless-stopped socket: build: *app-build - restart: unless-stopped - - mongo: + logging: *production-logging restart: unless-stopped postgres: + logging: *production-logging restart: unless-stopped redis: + logging: *production-logging restart: unless-stopped nginx: @@ -41,4 +48,12 @@ services: - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro - ${LETSENCRYPT_DIR:-/etc/letsencrypt}:/etc/letsencrypt:ro - ${CERTBOT_WWW_DIR:-/var/www/certbot}:/var/www/certbot:ro + healthcheck: + test: ["CMD-SHELL", "wget --quiet --spider --no-check-certificate https://127.0.0.1/health/api || exit 1"] + interval: 30s + start_interval: 2s + timeout: 5s + retries: 5 + start_period: 10s + logging: *production-logging restart: unless-stopped diff --git a/compose.yml b/compose.yml index 5d48b33c..02dcfb52 100644 --- a/compose.yml +++ b/compose.yml @@ -11,7 +11,6 @@ x-app-environment: &app-environment METRICS_ENABLED: ${METRICS_ENABLED:-true} METRICS_RETENTION_DAYS: ${METRICS_RETENTION_DAYS:-90} METRICS_HASH_SECRET: ${METRICS_HASH_SECRET:-} - MONGO_URL: ${MONGO_URL:-mongodb://mongo:27017/letscube} REDIS_URL: ${REDIS_URL:-redis://redis:6379} POSTGRES_ENABLED: ${POSTGRES_ENABLED:-true} DATABASE_URL: ${DATABASE_URL:-} @@ -49,7 +48,7 @@ services: environment: <<: *app-environment depends_on: - mongo: + postgres: condition: service_healthy redis: condition: service_healthy @@ -69,7 +68,7 @@ services: environment: <<: *app-environment depends_on: - mongo: + postgres: condition: service_healthy redis: condition: service_healthy @@ -83,17 +82,6 @@ services: retries: 5 start_period: 30s - mongo: - image: mongo:7.0 - volumes: - - mongo-data:/data/db - healthcheck: - test: ["CMD-SHELL", "mongosh --quiet --eval \"db.adminCommand('ping').ok\" | grep 1"] - interval: 30s - timeout: 10s - retries: 5 - start_period: 30s - postgres: image: postgres:17-alpine environment: @@ -121,6 +109,5 @@ services: retries: 5 volumes: - mongo-data: postgres-data: redis-data: diff --git a/cypress/e2e/local_stack.cy.js b/cypress/e2e/local_stack.cy.js index a234a4cd..d45ec3b5 100644 --- a/cypress/e2e/local_stack.cy.js +++ b/cypress/e2e/local_stack.cy.js @@ -153,7 +153,7 @@ describe('local app stack', () => { }); cy.get('[role="dialog"]').contains('button', 'Create').click(); - cy.location('pathname', { timeout: 10000 }).should('match', /^\/rooms\/[a-f0-9]+$/); + cy.location('pathname', { timeout: 10000 }).should('match', /^\/rooms\/[0-9a-f-]{36}$/); cy.get('.MuiBottomNavigation-root').should('not.be.visible'); cy.get('thead tr').first().should('have.css', 'display', 'flex'); cy.location('pathname').then((pathname) => { @@ -178,7 +178,7 @@ describe('local app stack', () => { cy.get('#roomName').type(roomName); cy.get('[role="dialog"]').contains('button', 'Create').click(); - cy.location('pathname', { timeout: 10000 }).should('match', /^\/rooms\/[a-f0-9]+$/); + cy.location('pathname', { timeout: 10000 }).should('match', /^\/rooms\/[0-9a-f-]{36}$/); cy.contains('Chat', { timeout: 10000 }).should('be.visible'); cy.get('input[placeholder="Send Message"]').type(`${message}{enter}`); @@ -239,7 +239,7 @@ describe('local app stack', () => { cy.visit('/friends'); cy.contains(`cypress-${guestId}`, { timeout: 10000 }).parents('li') .contains('button', 'Race with me').click(); - cy.location('pathname', { timeout: 10000 }).should('match', /^\/rooms\/[a-f0-9]+$/); + cy.location('pathname', { timeout: 10000 }).should('match', /^\/rooms\/[0-9a-f-]{36}$/); loginAs(guestId); cy.request(`${apiOrigin}/api/notifications`).then((response) => { @@ -250,7 +250,7 @@ describe('local app stack', () => { cy.visit('/notifications'); cy.contains('invited you to race.', { timeout: 10000 }).should('be.visible'); cy.get('button[aria-label="join race notification"]').click(); - cy.location('pathname', { timeout: 10000 }).should('match', /^\/rooms\/[a-f0-9]+$/); + cy.location('pathname', { timeout: 10000 }).should('match', /^\/rooms\/[0-9a-f-]{36}$/); cy.contains('Waiting For:', { timeout: 10000 }).should('be.visible'); }); }); diff --git a/docker-compose.yml b/docker-compose.yml index 541d623d..d510d525 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,14 +16,6 @@ services: retries: 5 restart: unless-stopped - mongo: - image: mongo:7.0 - ports: - - "127.0.0.1:27017:27017" - volumes: - - mongo-data:/data/db - restart: unless-stopped - redis: image: redis:7-alpine command: ["redis-server", "--appendonly", "yes"] @@ -39,6 +31,5 @@ services: restart: unless-stopped volumes: - mongo-data: postgres-data: redis-data: diff --git a/docs/README.md b/docs/README.md index c2a6e511..d8f44b45 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,7 +10,7 @@ This directory contains the durable technical documentation for Let's Cube. development workflows - [Realtime behavior](realtime.md) — Socket.IO namespaces, room lifecycle, reconnects, and result delivery -- [Data and migrations](data.md) — MongoDB, PostgreSQL, Prisma, metrics, and +- [Data and migrations](data.md) — PostgreSQL, Prisma, metrics, and persistence guarantees - [Room-to-RaceSession backfill and reconciliation](race-session-backfill.md) — resumable migration, parity, privacy, and rollback contract diff --git a/docs/architecture.md b/docs/architecture.md index 33c6d85d..8d91e0c6 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -27,27 +27,21 @@ in production. | | | +-------+-------+ | | | - +----v----+ +-----v----+ - | MongoDB | | Redis | - +----+----+ +----------+ - | - non-blocking mirrors - | - +----v------+ - |PostgreSQL | - +-----------+ + +----v------+ +----------+ + |PostgreSQL | | Redis | + | source | |coordination| + +-----------+ +----------+ ``` -PostgreSQL is written independently by both Node processes; it is shown below -MongoDB to emphasize the current migration direction, not a direct -MongoDB-to-PostgreSQL connection. +PostgreSQL owns durable application state. Redis provides ephemeral +coordination; active room aggregates are bounded by a per-process LRU cache. ## Repository Boundaries | Path | Responsibility | | --- | --- | | `client/` | React UI, Redux state, socket middleware, timers, and PWA assets | -| `server/` | Express API, authentication, Socket.IO, MongoDB models, PostgreSQL mirrors, and metrics | +| `server/` | Express API, authentication, Socket.IO, PostgreSQL repositories, cache, and metrics | | `packages/scrambles/` | Browser-safe event catalog and server-side scramble generation | | `cypress/` | Full-stack browser smoke tests | | `scripts/` | Deployment, rollback tests, backup, and restore tooling | @@ -70,8 +64,8 @@ state stay coordinated outside the component lifecycle. `server/index.js` starts Express on port `8080`. It: -- connects to MongoDB and optionally PostgreSQL; -- installs the shared Mongo-backed session middleware and Passport; +- connects to PostgreSQL; +- installs the shared PostgreSQL session middleware and Passport; - serves `/auth`, `/api`, and `/health/api`; - serves the production client build; and - falls back to `index.html` for client-side routes. @@ -93,7 +87,7 @@ during a deployment. ## Authentication And Sessions WCA OAuth is the normal authentication path. The API creates an Express session -stored in MongoDB, and both the HTTP and Socket.IO processes read that session. +stored in PostgreSQL, and both the HTTP and Socket.IO processes read that session. Browser API requests include credentials, and Socket.IO is configured for credentialed cross-origin connections. @@ -103,17 +97,17 @@ production. ## Data Services -- **MongoDB** is the application source of truth and backs sessions, users, - rooms, results, and metric events. +- **PostgreSQL** is the application source of truth and backs sessions, users, + rooms, results, social data, and metric events. - **Redis** supports the Socket.IO adapter and cross-instance presence checks. -- **PostgreSQL** is an optional, non-blocking dual-write target for normalized - application data and analytics. Application reads do not depend on it yet. +- **PostgreSQL** is required by both application processes. MongoDB models are + retained only by the one-time migration tool. See [Data and migrations](data.md) for schemas and consistency guarantees. ## Production Shape -The production Compose stack runs `api`, `socket`, `mongo`, `postgres`, +The production Compose stack runs `api`, `socket`, `postgres`, `redis`, and `nginx`. API and Socket.IO use the same immutable application image tagged with the deployed commit SHA. nginx terminates TLS, routes Socket.IO traffic to `socket`, and sends all other traffic to `api`. diff --git a/docs/data.md b/docs/data.md index 0e8f395d..b09e8e05 100644 --- a/docs/data.md +++ b/docs/data.md @@ -1,160 +1,63 @@ # Data And Migrations -Let's Cube currently uses MongoDB as its source of truth and PostgreSQL as a -non-blocking dual-write target. Redis is runtime coordination, not durable -application storage. - -## MongoDB - -MongoDB owns application reads and primary writes. Mongoose models cover: - -- users and WCA profile/preferences; -- rooms, participants, attempts, scrambles, and results; -- pseudonymous metric events; and -- Express sessions through `connect-mongo`. - -Room attempts and participant state are embedded in room documents. User-keyed -maps use string forms of WCA numeric user IDs. Normal empty rooms use the -`expireAt` TTL index for delayed cleanup. - -MongoDB write success determines application success. PostgreSQL mirror failure -must not reject a Mongo-backed operation during the current migration phase. +PostgreSQL is the source of truth for all durable application data. Redis is +used only for Socket.IO coordination, presence, and rate limiting. The server +does not connect to MongoDB at runtime. ## PostgreSQL -Prisma defines PostgreSQL in `server/prisma/schema.prisma`, using two schemas: +Prisma defines the schema in `server/prisma/schema.prisma`: | Schema | Contents | | --- | --- | -| `app` | users, rooms, room/session participants, RaceSessions, attempts, and solves | +| `app` | users, rooms, room/session participants, race sessions, attempts, solves, social data, and sessions | | `analytics` | pseudonymous metric events | -PostgreSQL receives normalized copies of users/preferences, rooms and -participant state, normal-room RaceSession projections, attempts, durable -solves, and sanitized analytics. OAuth access tokens are deliberately not -mirrored. Existing PostgreSQL attempts and solves that predate the expansion -remain unlinked until the backfill/reconciliation operation assigns them. +Room history is normalized into attempts and solves. Active room aggregates are +shared through a per-process weighted LRU cache capped at 128 MiB with a 60 +second TTL. Rooms with no connected users receive a ten-minute expiry; expiry +hides the room from active listings while preserving SQL history. -Application reads remain MongoDB-backed except for the development-only solve -history experiment. Setting `POSTGRES_ENABLED=false` disables initialization -and mirrors. PostgreSQL failures are logged, while API and Socket.IO health -report the service as `degraded` instead of unavailable. +OAuth access tokens are used only during the WCA authorization request and are +not persisted. Existing login sessions are intentionally invalidated during +the cutover because sessions are now stored in `app.sessions`. -## Dual-Write Guarantees +## Cutover and migration -`server/postgres/dualWrite.js` derives stable UUIDs from Mongo/WCA identifiers -and uses upserts so retries and future backfills remain idempotent. +The one-time MongoDB backfill tool is migration-only and is never imported by +the API or socket entrypoints. Run a dry run, schedule a maintenance window, +take a PostgreSQL backup, then run: -Room saves collect changed attempts/results and mirror only that delta. A -normal-room event change ends the current projected RaceSession and creates a -new one, preserving the earlier session's attempts and solves. Complete -snapshots are reserved for explicit backfill behavior. +```sh +yarn workspace letscube-server postgres:migrate-from-mongo +yarn workspace letscube-server postgres:migrate-from-mongo --apply +``` -`GET /api/solve-history` is a PostgreSQL-only, authenticated self-history -endpoint enabled in development and optionally for selected production users -through `FEATURE_SOLVE_HISTORY_USER_IDS`. It returns only session-linked solves -for a current non-banned room participant; hidden, expired, and soft-deleted -rooms remain readable to that participant. It never falls back to MongoDB or -selects access codes, passwords, membership lists, moderation data, or email -data. +The tool copies users, rooms and race history, social relationships/blocks, +notifications, and metrics. Sessions are not copied; users must authenticate +again after the big-bang cutover. Verify row counts and representative room, +solve, and social records before starting the new application processes. -The mirror intentionally catches database failures and returns control to the -MongoDB-backed request. Monitoring must surface mirror errors because users may -otherwise see success while PostgreSQL lags. +The shared `server/postgres/dualWrite.js` helpers provide stable identifiers +and idempotent upserts for the migration tool and compatibility model code; +they are not a MongoDB runtime dependency. PostgreSQL `solves.time_ms` is an integer. Any ingestion path accepting fractional JavaScript numbers must normalize or reject them explicitly rather than relying on PostgreSQL coercion. -## Prisma Workflow - -Apply committed migrations: +## Prisma workflow ```sh yarn workspace letscube-server postgres:migrate ``` -Create a migration during development: - -```sh -yarn workspace letscube-server postgres:migrate:dev -``` - -Validate the schema and detect drift: - ```sh yarn workspace letscube-server postgres:schema:validate yarn workspace letscube-server postgres:schema:check ``` -CI starts PostgreSQL 17, validates the Prisma schema, applies every committed -migration, and checks the resulting database against `schema.prisma`. - -Production runs `prisma migrate deploy` as a one-shot Compose service before -application replacement. Application rollback does not reverse migrations, so -migrations must remain compatible with both the new image and the immediately -previous image. - -When runtime traffic uses a pooled `DATABASE_URL`, configure -`DIRECT_DATABASE_URL` for Prisma migration operations. External PostgreSQL can -enable TLS with `PGSSL`; certificate verification is enabled by default and a -CA can be supplied with `PGSSL_CA`. - -## Metrics And Privacy - -The metrics recorder stores room and authentication events in MongoDB's -`metric_events` collection and PostgreSQL's `analytics.events` table. It tracks -room creation, join success/failure, leave duration/reason, accepted results, -peak room users/solves, and authentication failures. - -Actors and rooms are pseudonymized with HMAC-SHA256. Production should set a -dedicated `METRICS_HASH_SECRET`; otherwise the auth secret is used. Changing the -hash secret breaks correlation with older metric records. - -Metrics must not contain: - -- names, email addresses, or WCA IDs; -- room names, passwords, or access codes; -- OAuth credentials or session data; -- chat content; -- scramble text; or -- solve times. - -Raw events expire after 90 days by default. The Node runtime recognizes -`METRICS_RETENTION_DAYS`, `METRICS_ENABLED`, and `METRICS_HASH_SECRET` when they -are present in its process environment. The production Compose configuration -forwards those values from `.env.prod` to both application services. Keep the -hash secret only in `.env.prod`; Compose does not print it during normal -startup. - -MongoDB uses a TTL index; PostgreSQL maintenance deletes expired analytics -records periodically. - -## Backups And Restore - -The repository backup scripts currently protect MongoDB, the application source -of truth. PostgreSQL can be rebuilt from future backfills only to the extent the -mirror covers the desired history; do not assume it is a complete MongoDB -backup. - -See [Production operations](operations.md#backups) for retention and restore -procedures. Never use routine Docker cleanup to remove database volumes. - -## Changing Persistence - -Before a data change, identify: - -1. the MongoDB source shape and read path; -2. whether PostgreSQL needs a new backward-compatible migration; -3. mirror idempotency and retry behavior; -4. backfill requirements for existing documents; -5. privacy and retention effects; and -6. health, monitoring, backup, and rollback consequences. - -Moving reads to PostgreSQL or making PostgreSQL required is a separate migration -decision and must not happen incidentally as part of a schema change. - -The planned Room-to-RaceSession cutover has a separate -[backfill and reconciliation contract](race-session-backfill.md). It requires -resumable, privacy-safe verification before PostgreSQL becomes authoritative -for rooms, race sessions, attempts, and solves. +Production runs `prisma migrate deploy` as a one-shot service before replacing +the application containers. Configure `DIRECT_DATABASE_URL` when the runtime +`DATABASE_URL` is a pooled connection, and use `PGSSL`/`PGSSL_CA` for external +PostgreSQL TLS. diff --git a/docs/development.md b/docs/development.md index c9ef81e9..b85c0dc2 100644 --- a/docs/development.md +++ b/docs/development.md @@ -19,7 +19,7 @@ The root `yarn.lock` is authoritative. Do not install separately inside ## Local Services With Host Node -The simplest workflow runs MongoDB, PostgreSQL, and Redis in Docker while the +The simplest workflow runs PostgreSQL and Redis in Docker while the three application processes run on the host: ```sh @@ -34,7 +34,6 @@ Service ports are bound to localhost: | Client | `http://localhost:3000` | | API | `http://localhost:8080` | | Socket.IO | `http://localhost:9000` | -| MongoDB | `127.0.0.1:27017` | | PostgreSQL | `127.0.0.1:55433` | | Redis | `127.0.0.1:6379` | @@ -76,7 +75,7 @@ environment variables. Important groups are documented in `.env.example`: - process ports and feature flags; - public client build origins; -- MongoDB, Redis, and PostgreSQL connections; +- PostgreSQL and Redis connections; - session and WCA OAuth secrets; - CORS origins and metric retention; and - production TLS and backup paths. @@ -194,7 +193,7 @@ failure. ```sh docker compose -f docker-compose.yml ps -docker compose -f docker-compose.yml logs mongo postgres redis + docker compose -f docker-compose.yml logs postgres redis ``` The API and Socket.IO health endpoints are `http://localhost:8080/health/api` diff --git a/docs/friendships.md b/docs/friendships.md index 6f90e56c..6750d861 100644 --- a/docs/friendships.md +++ b/docs/friendships.md @@ -1,8 +1,7 @@ # Friendship and blocking contract -MongoDB is the source of truth for friendship state. PostgreSQL receives -non-blocking, idempotent mirrors and must never be read to authorize a social -action while the dual-write migration is in progress. +PostgreSQL is the source of truth for friendship state. Redis is used for +rate limiting and invalidation; it is not an authorization datastore. ## Rollout gate @@ -59,7 +58,7 @@ Both friendship writes and block writes check blocking after mutation, so a concurrent block wins and tombstones the relationship. After bounded contention, the API returns `409 relationship_conflict` and the caller should reconcile. -`removed` relationships and inactive blocks are durable MongoDB tombstones, +`removed` relationships and inactive blocks are durable PostgreSQL tombstones, not physical deletes. Each update increments that resource's revision. PostgreSQL upserts accept only a strictly newer revision, so a delayed request, friendship, or active-block mirror cannot overwrite a newer remove/unblock. @@ -71,7 +70,7 @@ so failures remain fail-closed. Unblocking repeats relationship cleanup before deactivating the block. If cleanup fails, the active block remains and the hidden relationship cannot reappear. -New request creation is atomically rate-limited in Redis before MongoDB writes: +New request creation is atomically rate-limited in Redis before PostgreSQL writes: each actor may create 30 requests per 10-minute window, and each normalized pair may create 3 requests per 24-hour window. One Lua operation checks both limits before it increments either counter and gives both counters a Redis TTL. diff --git a/docs/notifications.md b/docs/notifications.md index 20cfa12c..207e7f52 100644 --- a/docs/notifications.md +++ b/docs/notifications.md @@ -1,7 +1,8 @@ # In-app social notifications -Social notifications are a MongoDB-backed, recipient-only inbox. PostgreSQL is -a non-blocking mirror only and is never used to authorize reads or actions. +Social notifications are a PostgreSQL-backed, recipient-only inbox. Redis is +used only to fan out invalidation events and is never used as the source of +truth for reads or actions. The social feature gate remains disabled unless `SOCIAL_FEATURES_ENABLED=true`. ## Typed resource contract diff --git a/docs/operations.md b/docs/operations.md index 5f1ba521..909290f0 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -1,243 +1,114 @@ # Production Operations -This guide covers the Docker Compose production stack on a single VPS. Run -state-changing commands only when the deployment or maintenance action has been -explicitly authorized. - -## Production Stack - -The production stack combines `compose.yml` and `compose.prod.yml`: - -| Service | Role | -| --- | --- | -| `api` | Express API and static client on port 8080 inside Compose | -| `socket` | Socket.IO on port 9000 inside Compose | -| `mongo` | Primary application database and session store | -| `postgres` | Optional dual-write and analytics database | -| `redis` | Socket.IO adapter and cross-instance coordination | -| `nginx` | TLS termination and public reverse proxy | - -API and Socket.IO run the same `letscube-app` image with separate commands. -Production images are tagged with the full deployed commit SHA. - -## Environment And Host Prerequisites - -The host needs Docker Engine, Docker Compose, Git, the repository checkout, and -TLS certificates. Copy `.env.example` to an untracked `.env.prod`, replace every -placeholder, and restrict its permissions. - -Required secrets include: - -- `AUTH_SECRET`; -- `WCA_CLIENT_ID` and `WCA_CLIENT_SECRET`; -- `REACT_APP_WCA_CLIENT_ID` for the browser build; and -- `POSTGRES_PASSWORD` when PostgreSQL is enabled. - -Production TLS mounts default to `/etc/letsencrypt`, with nginx expecting the -certificate for `www.letscube.net`. MongoDB, PostgreSQL, and Redis should remain -internal to the Compose network. - -Do not assume a checkout path from an example or an old server. Determine the -active Compose project directory and pass it as `APP_DIR`. - -## Preflight - -Before deploying: - -1. Confirm the intended Docker context and clear stale `DOCKER_HOST` values. -2. Confirm the checkout is owned by the deployment account and has no local - changes. -3. Fetch the target branch and record the current and target commit SHAs. -4. Check free disk space and Docker usage. -5. Record current container status, image IDs, restart counts, and public health. - -Typical read-only checks: - -```sh -git status --short -git rev-parse HEAD -git rev-parse origin/master -df -h / -docker system df -docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod ps -curl -fsS https://letscube.net/health/api -curl -fsS https://letscube.net/health/socket -``` - -## Deploying - -Use `scripts/deploy.sh` for the Docker production stack: - -```sh -APP_DIR=/path/to/active/checkout \ - ENV_FILE=.env.prod \ - scripts/deploy.sh -``` - -The default `DEPLOY_TARGET=auto` classifies the files changed since the previous -commit: - -| Changed paths | Target | -| --- | --- | -| Documentation, CI, or agent metadata only | `none` | -| Browser client only | `api` | -| Server, shared protocol, dependencies, containers, deployment, or unknown | `all` | - -Override only when the runtime impact is known: +The production stack is `api`, `socket`, `postgres`, `redis`, and `nginx`. +PostgreSQL is the durable source of truth and session store; Redis is ephemeral +coordination and rate limiting. MongoDB is used only by the one-time cutover +backfill tool. + +## Deployment + +Production deploys run through the `Production deploy` GitHub Actions workflow. +The workflow starts after a successful `CI` run on `master`. It performs these +steps: + +1. Build one application image from the exact `master` commit. +2. Push the image to GHCR and retain its immutable digest. +3. Transfer that exact image and the production Compose files to the server. +4. Apply migrations, replace Socket.IO before the API, and verify all five + production services. +5. Retry image builds, transfers, and activation up to three times. Each failed + activation restores the previous application images and Compose files before + the next attempt. + +The server does not fetch or merge Git commits during this process. A manual +workflow run can deploy a specific commit, branch, or tag. The workflow uses the +GitHub `production` environment, so configure its approval policy to match the +release policy. + +The repository needs these GitHub Actions secrets: + +- `SERVER_IP`: the production server address. +- `DEPLOY_SSH_KEY`: the private key for the `www` account. +- `DEPLOY_KNOWN_HOSTS`: the pinned SSH host key entry. + +The server needs Docker access for `www`, the production `.env.prod` file at +`/home/www/letscube`, and the existing certificate directories. Actions stores +runtime Compose files in `/opt/letscube/runtime`, outside the old Git checkout. +After the first successful image activation, it removes only the old +`scripts/deploy.sh` cron entry. It saves the prior crontab at +`/opt/letscube/legacy-deploy-crontab.backup`. The PostgreSQL backup cron remains +active. A replacement cron checks all five services every ten minutes. It +recreates only missing or unhealthy services from the last successful image. +It does not fetch source code. + +The checkout-based script remains available as a temporary recovery path: ```sh -DEPLOY_TARGET=api APP_DIR=/path/to/checkout scripts/deploy.sh -DEPLOY_TARGET=socket APP_DIR=/path/to/checkout scripts/deploy.sh -DEPLOY_TARGET=all APP_DIR=/path/to/checkout scripts/deploy.sh -DEPLOY_TARGET=none APP_DIR=/path/to/checkout scripts/deploy.sh +APP_DIR=/home/www/letscube ENV_FILE=.env.prod scripts/deploy.sh ``` -`DEPLOY_FORCE=true` rebuilds both application services at the current commit. -`DEPLOY_WAIT_TIMEOUT_SECONDS` changes the default 60-second readiness deadline. - -The deploy script: - -1. fetches and fast-forwards the configured branch; -2. builds one immutable application image; -3. starts backing services without recreating them; -4. applies committed PostgreSQL migrations; -5. snapshots the current image for every selected application service; -6. replaces and health-checks Socket.IO before API when both are selected; and -7. reloads nginx after each replacement. - -Socket.IO is deployed first so a backward-compatible server is available before -the new browser bundle is served. Shared protocol changes must support this -brief mixed-version window. - -`scripts/update-production.sh` is the older PM2-oriented updater. It is not the -canonical path for the Docker Compose stack. +It records the last successful commit separately from the checkout. A failed +deployment therefore retries on the next run even when Git already moved to the +new commit. It also treats a missing or unhealthy PostgreSQL, Redis, Socket.IO, +API, or nginx container as a full repair deployment. -## Failed Deployments And Rollback - -A build, backing-service, or migration failure occurs before application -containers are replaced. If replacement readiness or nginx reload fails, -`scripts/deploy.sh` restores every attempted application service in reverse -order from its exact pre-deploy image and Compose definition, then reloads -nginx. - -The Git checkout remains at the fetched commit after failure. Correct the cause -and rerun with the explicit target printed by the script. - -Database migrations are not rolled back automatically. Every production -migration must remain compatible with the previous application image. - -The deploy script can be tested without production access: +Before a big-bang cutover, take a PostgreSQL backup and run the MongoDB +backfill tool during a maintenance window: ```sh -scripts/test-deploy-classifier.sh -scripts/test-deploy.sh -scripts/test-mongo-backup-restore.sh -scripts/test-mongo-backup-restore-live.sh -scripts/classify-deploy-target.sh client/src/components/App.jsx +yarn workspace letscube-server postgres:migrate +yarn workspace letscube-server postgres:migrate-from-mongo +MONGO_URL='mongodb://old-source/letscube' \ + yarn workspace letscube-server postgres:migrate-from-mongo --apply ``` -The live MongoDB rehearsal starts two disposable `mongo:7` containers on an -isolated Docker network, writes only a synthetic attempt, restores it with -`--drop`, verifies it, and removes the containers and network on exit. It never -connects to the configured production or development database. - -## Verification And Monitoring - -After deployment, verify: +The backfill is migration-only. It copies durable records and deliberately does +not copy sessions or OAuth tokens; users authenticate again after cutover. -- the checkout exactly matches the intended `origin/master` commit; -- selected containers use that commit's image and have zero unexpected restarts; -- all Compose services are healthy; -- `/health/api` and `/health/socket` succeed publicly; -- a real Socket.IO connection completes; and -- recent API, socket, nginx, and migration logs contain no new errors. - -Useful commands: +## Health and verification ```sh docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod ps -docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod logs --tail=200 api -docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod logs --tail=200 socket -docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod logs --tail=200 nginx +APP_DIR=/opt/letscube/runtime \ + ENV_FILE=/home/www/letscube/.env.prod \ + /opt/letscube/runtime/scripts/check-production-health.sh +docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod logs --tail=200 api socket postgres +curl -fsS https://letscube.net/health/api +curl -fsS https://letscube.net/health/socket ``` -`/health/api` requires MongoDB and treats PostgreSQL as optional. -`/health/socket` requires MongoDB and Redis and treats PostgreSQL as optional. An -optional PostgreSQL failure returns HTTP 200 with status `degraded`; a required -dependency failure returns HTTP 503 with status `error`. +Both health endpoints require PostgreSQL. The socket endpoint also requires +Redis. A failed required dependency returns HTTP 503. -The default Socket.IO namespace also supports `health_check`, returning a health -report through its acknowledgement or a `health_status` event. +nginx also has a container health check. It calls the API health route through +the local TLS listener. This detects a broken proxy configuration and an +unavailable API upstream. -## Backups +## Backups and restore -Create a MongoDB backup with an explicit checkout and destination: +Create a PostgreSQL custom-format backup and test restores against a separate +database: ```sh -APP_DIR=/path/to/checkout \ - BACKUP_DIR=/path/to/backups \ - scripts/backup-mongo.sh +BACKUP_DIR=/opt/letscube/backups +mkdir -p "$BACKUP_DIR" +docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod \ + exec -T postgres pg_dump -U "$PGUSER" -d "$PGDATABASE" -Fc \ + > "$BACKUP_DIR/letscube-postgres-$(date -u +%Y%m%dT%H%M%SZ).dump" ``` -The script creates gzip archives and retains 7 daily, 4 weekly, and 3 monthly -local backups. Set `BACKUP_S3_URI` and the documented AWS-compatible variables -to copy new archives off-server. - -Backups are only useful if restore is tested periodically against non-production -data. Monitor backup age, size, and off-server upload failures. - -## Restore - -Restore is destructive: `mongorestore --drop` replaces matching collections in -the target database. Verify the archive, target URI, and current backup before -continuing. - ```sh -APP_DIR=/path/to/checkout \ - scripts/restore-mongo.sh /path/to/letscube-mongo-backup.archive.gz +docker compose -f compose.yml -f compose.prod.yml --env-file .env.prod \ + exec -T postgres pg_restore -U "$PGUSER" -d "$PGDATABASE" \ + --clean --if-exists < /path/to/letscube-postgres.dump ``` -The script requires typing `RESTORE`. Never test restore against the production -database. - -## Disk And Log Retention - -Keep enough free space for a cold application image build as well as current and -rollback images. On the current small VPS class, 8–10 GB free is a practical -operating target; investigate at roughly 75% filesystem use and treat 85% as -critical. +Keep backups encrypted and off-host according to the hosting policy. Never +restore destructively over production without an explicit maintenance approval. -Inspect before deleting: - -```sh -df -h / -docker system df -v -journalctl --disk-usage -du -sh /path/to/backups -``` +## Recovery -Safe retention principles: - -- keep the current image and at least two known-good rollback revisions; -- prune old unused build cache and dangling images, not in-use images; -- configure bounded Docker and systemd-journal retention; -- keep backup retention explicit; and -- never prune Docker volumes as routine cleanup. - -See the backup scripts before changing retention paths or schedules. Cron and -other host automation are external state; inspect the deployed account's actual -crontab rather than assuming the repository documents its current schedule. - -## Moving To A New VPS - -1. Snapshot the old VPS and take a fresh off-server MongoDB backup. -2. Provision Docker Engine and Compose on the new host. -3. Clone the repository and create a fresh `.env.prod`. -4. Install or copy TLS certificates securely. -5. Start MongoDB, PostgreSQL, and Redis. -6. Restore MongoDB and apply PostgreSQL migrations. -7. Start API, Socket.IO, and nginx. -8. Test login, room creation/join, timing, reconnect, health, backups, and - restore against non-production data. -9. Confirm data services are not publicly reachable. -10. Move DNS and retain the old VPS until the new stack is stable. +Application images may be rolled back, but Prisma migrations are not reversed by +the deploy script. Keep migrations backward-compatible with the immediately +previous image and verify the database backup before rollback. Do not prune +PostgreSQL or Redis volumes as routine cleanup. diff --git a/docs/race-session-backfill.md b/docs/race-session-backfill.md index e3bcd9f8..101d85d0 100644 --- a/docs/race-session-backfill.md +++ b/docs/race-session-backfill.md @@ -1,17 +1,15 @@ # Room-to-RaceSession backfill and reconciliation contract -This document defines the safe migration contract for issue #175. It is a -specification only: it adds no migration, command, MongoDB write, or production -operation. It applies after the additive `RaceSession` schema is available and -before PostgreSQL becomes authoritative for the complete room aggregate. +This document defines the safe one-time migration contract for issue #175. The +implemented command is `postgres:migrate-from-mongo`; it is run only during the +maintenance-window cutover after the `RaceSession` schema is available. -The [data migration guide](data.md) describes the current MongoDB-backed -dual-write phase. The target Room and RaceSession ownership contract is a -prerequisite for implementing this specification. +The [data migration guide](data.md) describes the runtime source-of-truth and +backfill procedure. ## Scope and source boundary -At the start of this work, MongoDB is authoritative. A legacy Mongo room maps +The legacy Mongo source maps to exactly one PostgreSQL Room and exactly one initial RaceSession, including its current attempts, results, and participant state. The backfill must not infer, synthesize, or claim to recover events that a prior legacy event change diff --git a/docs/race-sessions.md b/docs/race-sessions.md index df9da991..7c1a8178 100644 --- a/docs/race-sessions.md +++ b/docs/race-sessions.md @@ -5,8 +5,8 @@ stream of racing activity within that room. This distinction lets a room retain completed attempts when its event changes and lets a competition room host more than one event without making ordinary rooms more complicated. -This is the target contract for the PostgreSQL migration. It does not change -the current MongoDB-backed runtime by itself. +This contract is implemented by the PostgreSQL runtime. MongoDB is used only by +the one-time cutover backfill. ## Ownership @@ -138,9 +138,7 @@ rooms map to one Room and one RaceSession for their current event; historical event sessions that legacy behavior deleted are not invented. Existing attempt and solve identifiers remain deterministic during backfill. -The migration expands PostgreSQL first, dual-writes and reconciles the complete -aggregate, then switches Room, RaceSession, Attempt, Solve, and participant -reads together. MongoDB must not remain authoritative for room metadata while -PostgreSQL is authoritative for results. The temporary rollback path retains -compatible data without reversing migrations; the later cleanup removes MongoDB -room/result persistence only after the observation window succeeds. +The cutover backfill reconciles the complete aggregate before the big-bang +switch. Room, RaceSession, Attempt, Solve, and participant reads then use +PostgreSQL together. The runtime retains Mongo-shaped compatibility IDs in SQL +for stable client references, but does not read or write MongoDB. diff --git a/docs/realtime.md b/docs/realtime.md index 4659d6be..83ddceab 100644 --- a/docs/realtime.md +++ b/docs/realtime.md @@ -26,7 +26,7 @@ independent namespace connections. ## Session Authentication -The Express session is stored in MongoDB and attached to Socket.IO through +The Express session is stored in PostgreSQL and attached to Socket.IO through `express-socket.io-session`. Socket authentication derives the user from that shared session. Socket.IO and API requests therefore depend on credentialed cookie behavior remaining aligned across the browser, CORS, nginx, and both @@ -69,8 +69,8 @@ During the grace window, preserve: - waiting and competing state; and - room administration. -Normal empty rooms receive an expiration timestamp. Explicit moderation and -leave actions do not use reconnect grace. +Rooms with no connected users receive a ten-minute expiration timestamp. +Explicit moderation and leave actions do not use reconnect grace. ## Client Rejoin @@ -119,7 +119,7 @@ not depend on Grand Prix behavior. ## Health -`GET /health/socket` checks MongoDB, Redis, and optional PostgreSQL. The default +`GET /health/socket` checks PostgreSQL and Redis. The default namespace also accepts `health_check`; it returns the same report through the acknowledgement callback or emits `health_status` when no callback is supplied. diff --git a/docs/release-workflow.md b/docs/release-workflow.md index e0cc89a2..687c0118 100644 --- a/docs/release-workflow.md +++ b/docs/release-workflow.md @@ -1,8 +1,8 @@ # Release Workflow `dev` is the integration branch. `master` is the reviewed release branch. -Production deployment remains a separately authorized operation described in -[Production operations](operations.md). +Production deployment runs through the protected GitHub `production` +environment described in [Production operations](operations.md). ## Branch Flow @@ -11,8 +11,8 @@ Production deployment remains a separately authorized operation described in 3. Treat the resulting `dev` merge commit as the release candidate. Its push CI and CodeQL push runs must finish before promotion is considered. 4. Open a reviewed promotion from that exact `dev` commit to `master`. -5. After the promotion is merged and its `master` push CI passes, perform the - separately authorized deployment procedure. +5. After the promotion is merged, the successful `master` CI run starts the + production deployment workflow. Do not bypass `dev` by merging feature work directly to `master`. A new commit on `dev` after release-candidate validation requires a new validation run. @@ -42,10 +42,11 @@ explicit operational authorization required by the operations guide. ## Deployment Handoff -After `master` CI is green, follow the operations guide in order: +After `master` CI is green, GitHub Actions follows the operations guide in +order: 1. complete the [preflight](operations.md#preflight) checks; -2. deploy with the documented procedure; +2. build and deploy the immutable release image; 3. perform the [verification and monitoring](operations.md#verification-and-monitoring) checks; and 4. use the documented rollback procedure if readiness or verification fails. diff --git a/docs/username-migration.md b/docs/username-migration.md index 396c3b32..807b5e0f 100644 --- a/docs/username-migration.md +++ b/docs/username-migration.md @@ -1,6 +1,6 @@ # Normalized username migration -MongoDB remains the user source of truth. Usernames are optional and use two +PostgreSQL is the user source of truth. Usernames are optional and use two fields: `username` stores trimmed display casing, while `usernameNormalized` stores the lowercase lookup key. The normalized value is intentionally not returned by user serialization. @@ -19,11 +19,11 @@ migration never picks a winner or silently renames an account. Issue #191 / PR #192 is a hard prerequisite. Its WCA email scope removal and data purge must remain in the branch and be deployed before username discovery. -1. Back up MongoDB and schedule a short maintenance window for username writes. +1. Back up PostgreSQL and schedule a short maintenance window for username writes. 2. Apply the committed PostgreSQL migrations. The nullable `app.users.username_normalized` column and its unique index are additive, so the previous application version continues to run. -3. From the release checkout, audit MongoDB without changing data: +3. From the release checkout, audit PostgreSQL without changing data: ```bash yarn workspace letscube-server usernames:backfill @@ -35,36 +35,27 @@ data purge must remain in the branch and be deployed before username discovery. available for a third account to claim. Invalid raw values are deliberately omitted from the report, and email-like invalid values are removed rather than copied or logged. -5. After the collision report is empty, apply the idempotent backfill, reconcile - existing PostgreSQL usernames by WCA user ID, and create or verify the sparse - unique MongoDB index: +5. After the collision report is empty, apply the idempotent PostgreSQL backfill: ```bash yarn workspace letscube-server usernames:backfill --apply --create-index ``` - The PostgreSQL reconciliation uses MongoDB's planned target for each WCA user - and verifies exact equality without printing stored values. It clears both - PostgreSQL username fields for email-like legacy values. When PostgreSQL is - intentionally disabled with `POSTGRES_ENABLED=false`, the command records a - disabled status and skips that secondary store; rerun with PostgreSQL enabled - before bringing the mirror back into service. + The command verifies and updates only normalized PostgreSQL fields without + printing stored values. 6. Run the dry-run command again. `pendingChanges`, `privacyRemoved`, and the collision report must all be empty or zero. The apply command must report zero MongoDB private values and zero PostgreSQL mismatches. 7. Deploy the API and verify a casing-only username change, a conflicting change (`409 USERNAME_TAKEN`), and an invalid change - (`400 INVALID_USERNAME`). PostgreSQL receives the normalized field through - the existing non-blocking dual writer whenever MongoDB users are saved. +(`400 INVALID_USERNAME`). PostgreSQL persists the normalized field with the user +update. Do not enable username writes or the discovery endpoint from #82 until this sequence and the #191 purge have completed successfully. ## Rollback -Do not drop the MongoDB index or PostgreSQL column when rolling the application -back. Both additions are backward-compatible and the previous application -ignores them. Disable username discovery and username edits while the old code -is serving because it does not maintain `usernameNormalized`. Before rolling -forward again, rerun the dry-run and apply commands to reconcile any writes made -by the old application. +Do not drop the PostgreSQL index or column when rolling the application back. +Disable username discovery and username edits while an incompatible image is +serving. diff --git a/scripts/backfill-normalized-usernames.js b/scripts/backfill-normalized-usernames.js index 0a2edae3..b9e6f771 100644 --- a/scripts/backfill-normalized-usernames.js +++ b/scripts/backfill-normalized-usernames.js @@ -1,116 +1,45 @@ #!/usr/bin/env node -/* eslint-disable import/no-extraneous-dependencies, no-console */ -const path = require('path'); -const mongoose = require('mongoose'); +/* eslint-disable no-console */ -process.env.GETCONFIG_ROOT = process.env.GETCONFIG_ROOT - || path.join(__dirname, '../server/config'); - -const config = require('../server/runtimeConfig'); -const { - assertUsernameRolloutReady, - planUsernameBackfill, -} = require('../server/usernameBackfill'); -const { reconcilePostgresUsernames } = require('../server/usernamePostgresBackfill'); +const { normalizeUsername } = require('../server/username'); +const { initializePostgres, pool } = require('../server/postgres'); const args = new Set(process.argv.slice(2)); -const supportedArgs = new Set(['--apply', '--create-index']); -const unknownArg = [...args].find((arg) => !supportedArgs.has(arg)); - -const duplicateNormalizedUsernames = (collection) => collection.aggregate([ - { $match: { usernameNormalized: { $exists: true } } }, - { $group: { _id: '$usernameNormalized', count: { $sum: 1 } } }, - { $match: { count: { $gt: 1 } } }, - { $limit: 1 }, -]).toArray(); - -const readUsers = (collection) => collection.find({}, { - projection: { - _id: 1, - id: 1, - username: 1, - usernameNormalized: 1, - }, -}).toArray(); - -let postgresPool; +const apply = args.has('--apply'); +const unknownArg = [...args].find((arg) => !['--apply', '--create-index'].includes(arg)); const run = async () => { - if (unknownArg) { - throw new Error(`Unknown argument: ${unknownArg}`); - } - - const apply = args.has('--apply'); - const createIndex = args.has('--create-index'); - if (createIndex && !apply) { - throw new Error('--create-index must be used with --apply'); - } - - mongoose.set('strictQuery', false); - await mongoose.connect(config.mongodb, { autoIndex: false }); - const users = mongoose.connection.collection('users'); - const documents = await readUsers(users); - const plan = planUsernameBackfill(documents); - - console.log(JSON.stringify({ - mode: apply ? 'apply' : 'dry-run', - ...plan.report, - }, null, 2)); - - if (!apply) { - return; - } - - if (plan.operations.length) { - const result = await users.bulkWrite(plan.operations, { ordered: false }); - console.log(`Updated ${result.modifiedCount} user records.`); - } - - const verifiedPlan = planUsernameBackfill(await readUsers(users)); - if (verifiedPlan.report.pendingChanges || verifiedPlan.report.privacyRemoved) { - throw new Error('MongoDB username backfill verification failed'); - } - - let postgres = { status: 'disabled' }; - if (config.postgres.enabled) { - // Avoid creating a PostgreSQL pool for dry runs or explicitly disabled mirrors. - // eslint-disable-next-line global-require - ({ pool: postgresPool } = require('../server/postgres')); - postgres = { - status: 'reconciled', - ...await reconcilePostgresUsernames({ - client: postgresPool, - users: verifiedPlan.postgresUsers, - }), - }; - } - - console.log(JSON.stringify({ - verification: { - mongoPendingChanges: verifiedPlan.report.pendingChanges, - mongoPrivateValuesRemaining: verifiedPlan.report.privacyRemoved, - postgres, - }, - }, null, 2)); - - if (createIndex) { - assertUsernameRolloutReady(verifiedPlan.report); - const duplicates = await duplicateNormalizedUsernames(users); - if (duplicates.length) { - throw new Error('Duplicate normalized usernames remain; unique index was not created'); + if (unknownArg) throw new Error(`Unknown argument: ${unknownArg}`); + if (!(await initializePostgres())) throw new Error('PostgreSQL is unavailable'); + + const { rows } = await pool.query( + 'SELECT id, username, username_normalized FROM app.users ORDER BY wca_user_id', + ); + const changes = rows.flatMap((row) => { + const normalized = normalizeUsername(row.username); + return normalized.usernameNormalized === row.username_normalized + ? [] : [{ ...row, normalized }]; + }); + console.log(JSON.stringify({ mode: apply ? 'apply' : 'dry-run', pendingChanges: changes.length }, null, 2)); + + if (apply) { + for (const row of changes) { + await pool.query(` + UPDATE app.users + SET username = $2, username_normalized = $3, source_updated_at = now(), ingested_at = now() + WHERE id = $1 + `, [row.id, row.normalized.username || null, row.normalized.usernameNormalized || null]); } - const name = await users.createIndex( - { usernameNormalized: 1 }, - { name: 'users_username_normalized_unique', sparse: true, unique: true }, - ); - console.log(`Verified MongoDB index ${name}.`); + console.log(`Updated ${changes.length} user records.`); } + return changes.length; }; -run().catch((err) => { - console.error(err.message); - process.exitCode = 1; -}).finally(() => Promise.allSettled([ - mongoose.disconnect(), - ...(postgresPool ? [postgresPool.end()] : []), -])); +if (require.main === module) { + run().catch((err) => { + console.error(err.message); + process.exitCode = 1; + }).finally(() => pool.end()); +} + +module.exports = { run }; diff --git a/scripts/backup-mongo.sh b/scripts/backup-mongo.sh deleted file mode 100755 index 6d8e679d..00000000 --- a/scripts/backup-mongo.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -APP_DIR="${APP_DIR:-/opt/letscube}" -ENV_FILE="${ENV_FILE:-.env.prod}" -BACKUP_DIR="${BACKUP_DIR:-/opt/letscube/backups}" -MONGO_BACKUP_URI="${MONGO_BACKUP_URI:-mongodb://127.0.0.1:27017/letscube}" - -COMPOSE=(docker compose -f compose.yml -f compose.prod.yml --env-file "$ENV_FILE") - -timestamp="$(date -u +%Y%m%dT%H%M%SZ)" -weekday="$(date -u +%u)" -monthday="$(date -u +%d)" -daily_backup="$BACKUP_DIR/letscube-mongo-daily-$timestamp.archive.gz" - -mkdir -p "$BACKUP_DIR" -cd "$APP_DIR" - -"${COMPOSE[@]}" exec -T -e MONGO_BACKUP_URI="$MONGO_BACKUP_URI" mongo \ - sh -c 'mongodump --uri="$MONGO_BACKUP_URI" --archive --gzip' > "$daily_backup" - -created=("$daily_backup") - -if [ "$weekday" = "7" ]; then - weekly_backup="$BACKUP_DIR/letscube-mongo-weekly-$timestamp.archive.gz" - cp "$daily_backup" "$weekly_backup" - created+=("$weekly_backup") -fi - -if [ "$monthday" = "01" ]; then - monthly_backup="$BACKUP_DIR/letscube-mongo-monthly-$timestamp.archive.gz" - cp "$daily_backup" "$monthly_backup" - created+=("$monthly_backup") -fi - -prune_backups() { - local pattern="$1" - local keep="$2" - find "$BACKUP_DIR" -maxdepth 1 -type f -name "$pattern" -printf '%T@ %p\n' \ - | sort -rn \ - | awk -v keep="$keep" 'NR > keep { $1=""; sub(/^ /, ""); print }' \ - | xargs -r rm -f -} - -prune_backups 'letscube-mongo-daily-*.archive.gz' 7 -prune_backups 'letscube-mongo-weekly-*.archive.gz' 4 -prune_backups 'letscube-mongo-monthly-*.archive.gz' 3 - -if [ -n "${BACKUP_S3_URI:-}" ]; then - if ! command -v aws >/dev/null 2>&1; then - echo "BACKUP_S3_URI is set, but aws CLI is not installed." >&2 - exit 1 - fi - - aws_args=() - if [ -n "${AWS_ENDPOINT_URL:-}" ]; then - aws_args+=(--endpoint-url "$AWS_ENDPOINT_URL") - fi - - for backup in "${created[@]}"; do - aws "${aws_args[@]}" s3 cp "$backup" "$BACKUP_S3_URI/" - done -fi - -printf 'Created MongoDB backup: %s\n' "$daily_backup" diff --git a/scripts/backup-postgres.sh b/scripts/backup-postgres.sh new file mode 100755 index 00000000..15f5b1e7 --- /dev/null +++ b/scripts/backup-postgres.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -euo pipefail + +APP_DIR="${APP_DIR:-/opt/letscube}" +ENV_FILE="${ENV_FILE:-.env.prod}" +BACKUP_DIR="${BACKUP_DIR:-$APP_DIR/backups}" +BACKUP_RETENTION_DAYS="${BACKUP_RETENTION_DAYS:-14}" + +if ! [[ "$BACKUP_RETENTION_DAYS" =~ ^[1-9][0-9]*$ ]]; then + echo "BACKUP_RETENTION_DAYS must be a positive integer." >&2 + exit 2 +fi + +if [ "$BACKUP_DIR" = "/" ]; then + echo "BACKUP_DIR cannot be the root directory." >&2 + exit 2 +fi + +COMPOSE=(docker compose -f compose.yml -f compose.prod.yml --env-file "$ENV_FILE") + +cd "$APP_DIR" +mkdir -p -- "$BACKUP_DIR" +umask 077 + +timestamp="$(date -u +%Y%m%dT%H%M%SZ)" +backup_file="$BACKUP_DIR/letscube-postgres-$timestamp.dump" +temporary_file="$(mktemp "$BACKUP_DIR/.letscube-postgres-$timestamp.XXXXXX")" + +cleanup() { + rm -f -- "$temporary_file" +} + +trap cleanup EXIT + +"${COMPOSE[@]}" exec -T postgres \ + sh -c 'exec pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Fc' \ + > "$temporary_file" + +mv -- "$temporary_file" "$backup_file" +trap - EXIT + +find "$BACKUP_DIR" -maxdepth 1 -type f \ + -name 'letscube-postgres-*.dump' \ + -mtime "+$BACKUP_RETENTION_DAYS" \ + -print -delete + +echo "Created PostgreSQL backup: $backup_file" diff --git a/scripts/check-production-health.sh b/scripts/check-production-health.sh new file mode 100755 index 00000000..bf5ab689 --- /dev/null +++ b/scripts/check-production-health.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +set -euo pipefail + +APP_DIR="${APP_DIR:-/opt/letscube/runtime}" +ENV_FILE="${ENV_FILE:-/home/www/letscube/.env.prod}" +HEALTH_ATTEMPTS="${HEALTH_ATTEMPTS:-10}" +HEALTH_RETRY_SECONDS="${HEALTH_RETRY_SECONDS:-3}" + +if ! [[ "$HEALTH_ATTEMPTS" =~ ^[1-9][0-9]*$ ]]; then + echo "HEALTH_ATTEMPTS must be a positive integer." >&2 + exit 2 +fi + +if [[ "$ENV_FILE" = /* ]]; then + ENV_PATH="$ENV_FILE" +else + ENV_PATH="$APP_DIR/$ENV_FILE" +fi + +COMPOSE=( + docker compose + --project-directory "$APP_DIR" + -f "$APP_DIR/compose.yml" + -f "$APP_DIR/compose.prod.yml" + --env-file "$ENV_PATH" +) +services=(postgres redis socket api nginx) + +for ((attempt = 1; attempt <= HEALTH_ATTEMPTS; attempt += 1)); do + failed=() + + for service in "${services[@]}"; do + container_id="$("${COMPOSE[@]}" ps --status running -q "$service")" + if [ -z "$container_id" ]; then + failed+=("$service:missing") + continue + fi + + health_status="$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}missing{{end}}' "$container_id")" + if [ "$health_status" != "healthy" ]; then + failed+=("$service:$health_status") + fi + done + + if [ "${#failed[@]}" -eq 0 ]; then + echo "All production services are healthy." + exit 0 + fi + + echo "Health check $attempt/$HEALTH_ATTEMPTS failed: ${failed[*]}" >&2 + if [ "$attempt" -lt "$HEALTH_ATTEMPTS" ]; then + sleep "$HEALTH_RETRY_SECONDS" + fi +done + +"${COMPOSE[@]}" ps >&2 || true +"${COMPOSE[@]}" logs --tail=120 api socket postgres redis nginx >&2 || true +exit 1 diff --git a/scripts/deploy-image-release.sh b/scripts/deploy-image-release.sh new file mode 100755 index 00000000..9764ced1 --- /dev/null +++ b/scripts/deploy-image-release.sh @@ -0,0 +1,171 @@ +#!/usr/bin/env bash +set -euo pipefail + +SOURCE_SHA="${1:-}" +RELEASE_DIR="${2:-}" +APP_DIR="${APP_DIR:-/opt/letscube/runtime}" +ENV_FILE="${ENV_FILE:-/home/www/letscube/.env.prod}" +DEPLOY_WAIT_TIMEOUT_SECONDS="${DEPLOY_WAIT_TIMEOUT_SECONDS:-90}" +LOCK_FILE="${LOCK_FILE:-/tmp/letscube-deploy.lock}" + +if ! [[ "$SOURCE_SHA" =~ ^[0-9a-f]{40}$ ]]; then + echo "A full source commit SHA is required." >&2 + exit 2 +fi +if [ -z "$RELEASE_DIR" ] || [ ! -d "$RELEASE_DIR" ]; then + echo "A release directory is required." >&2 + exit 2 +fi +if [[ "$ENV_FILE" = /* ]]; then + ENV_PATH="$ENV_FILE" +else + ENV_PATH="$APP_DIR/$ENV_FILE" +fi +if [ ! -f "$ENV_PATH" ]; then + echo "Missing production environment file: $ENV_PATH" >&2 + exit 1 +fi + +release_files=(compose.yml compose.prod.yml nginx.conf) +for file in "${release_files[@]}"; do + if [ ! -f "$RELEASE_DIR/$file" ]; then + echo "Missing release file: $RELEASE_DIR/$file" >&2 + exit 1 + fi +done +if [ ! -x "$RELEASE_DIR/check-production-health.sh" ]; then + echo "Missing executable production health check." >&2 + exit 1 +fi +if [ ! -x "$RELEASE_DIR/repair-production-services.sh" ]; then + echo "Missing executable production repair script." >&2 + exit 1 +fi + +image="letscube-app:$SOURCE_SHA" +docker image inspect "$image" > /dev/null +image_source="$(docker image inspect --format '{{index .Config.Labels "org.opencontainers.image.revision"}}' "$image")" +if [ "$image_source" != "$SOURCE_SHA" ]; then + echo "Image source label does not match $SOURCE_SHA." >&2 + exit 1 +fi + +exec 9> "$LOCK_FILE" +if ! flock -w 60 9; then + echo "Another production deployment holds $LOCK_FILE." >&2 + exit 1 +fi + +mkdir -p "$APP_DIR/scripts" +rollback_dir="$(mktemp -d "${TMPDIR:-/tmp}/letscube-release-rollback.XXXXXX")" +config_staged=false +deployment_complete=false +declare -A rollback_tags=() + +COMPOSE=( + docker compose + --project-directory "$APP_DIR" + -f "$APP_DIR/compose.yml" + -f "$APP_DIR/compose.prod.yml" + --env-file "$ENV_PATH" +) +ROLLBACK_COMPOSE=() + +restore_release() { + local service + local rollback_tag + + set +e + echo "Restoring the previous production release." >&2 + + if [ "$config_staged" = "true" ]; then + for file in "${release_files[@]}"; do + if [ -f "$rollback_dir/$file" ]; then + cp -p "$rollback_dir/$file" "$APP_DIR/$file" + fi + done + fi + + if [ -f "$rollback_dir/compose.yml" ] && [ -f "$rollback_dir/compose.prod.yml" ]; then + ROLLBACK_COMPOSE=( + docker compose + --project-directory "$APP_DIR" + -f "$rollback_dir/compose.yml" + -f "$rollback_dir/compose.prod.yml" + --env-file "$ENV_PATH" + ) + + for service in socket api; do + rollback_tag="${rollback_tags[$service]-}" + if [ -n "$rollback_tag" ]; then + APP_IMAGE_TAG="$rollback_tag" "${ROLLBACK_COMPOSE[@]}" up -d --no-deps \ + --force-recreate --wait --wait-timeout "$DEPLOY_WAIT_TIMEOUT_SECONDS" "$service" + fi + done + + "${ROLLBACK_COMPOSE[@]}" up -d --no-deps --force-recreate --wait \ + --wait-timeout "$DEPLOY_WAIT_TIMEOUT_SECONDS" nginx + fi +} + +cleanup() { + local status=$? + + if [ "$status" -ne 0 ] && [ "$deployment_complete" != "true" ]; then + restore_release || true + fi + rm -rf -- "$rollback_dir" + exit "$status" +} +trap cleanup EXIT + +for file in "${release_files[@]}"; do + if [ -f "$APP_DIR/$file" ]; then + cp -p "$APP_DIR/$file" "$rollback_dir/$file" + fi +done + +deploy_id="$(date -u +%Y%m%dT%H%M%SZ)-$$" +for service in socket api; do + container_id="$("${COMPOSE[@]}" ps -q "$service" 2> /dev/null || true)" + if [ -n "$container_id" ]; then + image_id="$(docker inspect --format '{{.Image}}' "$container_id")" + rollback_tag="rollback-$service-${SOURCE_SHA:0:12}-$deploy_id" + docker image tag "$image_id" "letscube-app:$rollback_tag" + rollback_tags["$service"]="$rollback_tag" + fi +done + +for file in "${release_files[@]}"; do + install -m 0644 "$RELEASE_DIR/$file" "$APP_DIR/$file.new" + mv "$APP_DIR/$file.new" "$APP_DIR/$file" +done +install -m 0755 "$RELEASE_DIR/check-production-health.sh" \ + "$APP_DIR/scripts/check-production-health.sh" +install -m 0755 "$RELEASE_DIR/repair-production-services.sh" \ + "$APP_DIR/scripts/repair-production-services.sh" +config_staged=true + +export APP_IMAGE_TAG="$SOURCE_SHA" +"${COMPOSE[@]}" config --quiet +"${COMPOSE[@]}" up -d --wait --wait-timeout "$DEPLOY_WAIT_TIMEOUT_SECONDS" postgres redis +"${COMPOSE[@]}" run --rm --no-deps migrate + +# Socket.IO is replaced first so it accepts the browser client in the new API image. +"${COMPOSE[@]}" up -d --no-deps --force-recreate --wait \ + --wait-timeout "$DEPLOY_WAIT_TIMEOUT_SECONDS" socket +"${COMPOSE[@]}" up -d --no-deps --force-recreate --wait \ + --wait-timeout "$DEPLOY_WAIT_TIMEOUT_SECONDS" api +"${COMPOSE[@]}" up -d --no-deps --force-recreate --wait \ + --wait-timeout "$DEPLOY_WAIT_TIMEOUT_SECONDS" nginx + +APP_DIR="$APP_DIR" ENV_FILE="$ENV_FILE" \ + "$RELEASE_DIR/check-production-health.sh" + +printf '%s\n' "$SOURCE_SHA" > "$APP_DIR/.last-successful-deploy" +deployment_complete=true +echo "Deployment complete: all services use release $SOURCE_SHA." +"${COMPOSE[@]}" ps + +docker image prune -af --filter "until=168h" || \ + echo "Deployment succeeded, but unused image cleanup failed." >&2 diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 62605b5d..e123cee7 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -9,6 +9,7 @@ DEPLOY_STRATEGY="${DEPLOY_STRATEGY:-ff-only}" DEPLOY_FORCE="${DEPLOY_FORCE:-false}" DEPLOY_TARGET="${DEPLOY_TARGET:-auto}" DEPLOY_WAIT_TIMEOUT_SECONDS="${DEPLOY_WAIT_TIMEOUT_SECONDS:-60}" +LAST_SUCCESSFUL_DEPLOY_FILE="${LAST_SUCCESSFUL_DEPLOY_FILE:-$APP_DIR/.last-successful-deploy}" COMPOSE=(docker compose -f compose.yml -f compose.prod.yml --env-file "$ENV_FILE") ROLLBACK_COMPOSE=() @@ -39,7 +40,18 @@ fi cd "$APP_DIR" -previous_commit="$(git rev-parse HEAD)" +checkout_commit="$(git rev-parse HEAD)" +if [ -f "$LAST_SUCCESSFUL_DEPLOY_FILE" ]; then + previous_commit="$(tr -d '[:space:]' < "$LAST_SUCCESSFUL_DEPLOY_FILE")" + if ! [[ "$previous_commit" =~ ^[0-9a-f]{40}$ ]]; then + echo "Invalid commit in $LAST_SUCCESSFUL_DEPLOY_FILE" >&2 + exit 2 + fi +else + previous_commit="$checkout_commit" + printf '%s\n' "$previous_commit" > "$LAST_SUCCESSFUL_DEPLOY_FILE" +fi + git fetch "$REMOTE" "$BRANCH" case "$DEPLOY_STRATEGY" in @@ -57,6 +69,22 @@ case "$DEPLOY_STRATEGY" in esac current_commit="$(git rev-parse HEAD)" +changed_files=() + +if [ "$previous_commit" != "$current_commit" ]; then + mapfile -d '' changed_files < <( + git diff --name-only --no-renames -z "$previous_commit" "$current_commit" + ) +fi + +production_compose_changed="false" +for changed_file in "${changed_files[@]}"; do + case "$changed_file" in + compose.yml|compose.prod.yml) + production_compose_changed="true" + ;; + esac +done privacy_cutover_file="${PRIVACY_EMAIL_CUTOVER_FILE:-$APP_DIR/.privacy-email-cutover}" if [ -f "$privacy_cutover_file" ]; then @@ -71,20 +99,44 @@ if [ -f "$privacy_cutover_file" ]; then fi fi +unhealthy_backing_services=() +unhealthy_runtime_services=() if [ "$DEPLOY_TARGET" = "auto" ]; then missing_services=() - for service in api socket nginx; do + unhealthy_services=() + for service in postgres redis api socket nginx; do if ! container_id="$("${COMPOSE[@]}" ps --status running -q "$service")"; then echo "Failed to inspect the $service container." >&2 exit 1 fi if [ -z "$container_id" ]; then missing_services+=("$service") + if [ "$service" = "postgres" ] || [ "$service" = "redis" ]; then + unhealthy_backing_services+=("$service") + else + unhealthy_runtime_services+=("$service") + fi + continue + fi + + health_status="$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}missing{{end}}' "$container_id")" + if [ "$health_status" != "healthy" ]; then + unhealthy_services+=("$service:$health_status") + if [ "$service" = "postgres" ] || [ "$service" = "redis" ]; then + unhealthy_backing_services+=("$service") + else + unhealthy_runtime_services+=("$service") + fi fi done - if [ "${#missing_services[@]}" -gt 0 ]; then - echo "Missing runtime services: ${missing_services[*]}; deploying all." + if [ "${#missing_services[@]}" -gt 0 ] || [ "${#unhealthy_services[@]}" -gt 0 ]; then + if [ "${#missing_services[@]}" -gt 0 ]; then + echo "Missing production services: ${missing_services[*]}; deploying all." + fi + if [ "${#unhealthy_services[@]}" -gt 0 ]; then + echo "Unhealthy production services: ${unhealthy_services[*]}; deploying all." + fi resolved_target="all" elif [ "$previous_commit" = "$current_commit" ]; then if [ "$DEPLOY_FORCE" != "true" ]; then @@ -97,9 +149,6 @@ if [ "$DEPLOY_TARGET" = "auto" ]; then # behavior of replacing the complete application deployment. resolved_target="all" else - mapfile -d '' changed_files < <( - git diff --name-only --no-renames -z "$previous_commit" "$current_commit" - ) resolved_target="$( bash scripts/classify-deploy-target.sh "${changed_files[@]}" )" @@ -122,6 +171,7 @@ case "$resolved_target" in ;; none) echo "Updated checkout to $current_commit; no application services selected." + printf '%s\n' "$current_commit" > "$LAST_SUCCESSFUL_DEPLOY_FILE" "${COMPOSE[@]}" ps exit 0 ;; @@ -169,14 +219,32 @@ fi # Compose usage compatible with the default `local` tag. export APP_IMAGE_TAG="$current_commit" +backing_recreate_args=() +runtime_recreate_args=() +if [ "$production_compose_changed" = "true" ]; then + backing_recreate_args=(--force-recreate) + runtime_recreate_args=(--force-recreate) +elif [ "${#unhealthy_runtime_services[@]}" -gt 0 ]; then + runtime_recreate_args=(--force-recreate) +fi + if ! "${COMPOSE[@]}" build api; then echo "Application image build failed; no application containers were replaced." >&2 print_retry_hint exit 1 fi -if ! "${COMPOSE[@]}" up -d --no-recreate --wait \ - --wait-timeout "$DEPLOY_WAIT_TIMEOUT_SECONDS" mongo postgres redis; then +for service in "${unhealthy_backing_services[@]}"; do + if ! "${COMPOSE[@]}" up -d --force-recreate --wait \ + --wait-timeout "$DEPLOY_WAIT_TIMEOUT_SECONDS" "$service"; then + echo "Failed to repair unhealthy $service; no application containers were replaced." >&2 + print_retry_hint + exit 1 + fi +done + +if ! "${COMPOSE[@]}" up -d "${backing_recreate_args[@]}" --wait \ + --wait-timeout "$DEPLOY_WAIT_TIMEOUT_SECONDS" postgres redis; then echo "Failed to start backing services; no application containers were replaced." >&2 print_retry_hint exit 1 @@ -221,10 +289,11 @@ reload_nginx() { container_id="$("${compose_command[@]}" ps --status running -q nginx)" if [ -z "$container_id" ]; then echo "nginx is not running; starting it without replacing dependencies." - "${compose_command[@]}" up -d --no-deps --wait \ - --wait-timeout "$DEPLOY_WAIT_TIMEOUT_SECONDS" nginx || return 1 fi + "${compose_command[@]}" up -d --no-deps "${runtime_recreate_args[@]}" --wait \ + --wait-timeout "$DEPLOY_WAIT_TIMEOUT_SECONDS" nginx || return 1 + "${compose_command[@]}" exec -T nginx nginx -s reload } @@ -287,7 +356,7 @@ for service_index in "${!selected_services[@]}"; do service="${selected_services[$service_index]}" attempted_services+=("$service") - if ! "${COMPOSE[@]}" up -d --no-deps --wait \ + if ! "${COMPOSE[@]}" up -d --no-deps "${runtime_recreate_args[@]}" --wait \ --wait-timeout "$DEPLOY_WAIT_TIMEOUT_SECONDS" "$service"; then echo "$service deployment failed. Recent logs:" >&2 "${COMPOSE[@]}" logs --tail=120 "$service" >&2 || true @@ -317,4 +386,13 @@ for service_index in "${!selected_services[@]}"; do done echo "Deployment complete: $resolved_target now uses letscube-app:$current_commit" +printf '%s\n' "$current_commit" > "$LAST_SUCCESSFUL_DEPLOY_FILE" "${COMPOSE[@]}" ps + +if ! docker image prune -af --filter "until=168h"; then + echo "Deployment succeeded, but unused image cleanup failed." >&2 +fi + +if ! docker builder prune -af --max-used-space 2GB; then + echo "Deployment succeeded, but build cache cleanup failed." >&2 +fi diff --git a/scripts/disable-legacy-deploy-cron.sh b/scripts/disable-legacy-deploy-cron.sh new file mode 100755 index 00000000..c423b4d6 --- /dev/null +++ b/scripts/disable-legacy-deploy-cron.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -euo pipefail + +BACKUP_FILE="${BACKUP_FILE:-/opt/letscube/legacy-deploy-crontab.backup}" +APP_DIR="${APP_DIR:-/opt/letscube/runtime}" +ENV_FILE="${ENV_FILE:-/home/www/letscube/.env.prod}" +temporary_dir="$(mktemp -d "${TMPDIR:-/tmp}/letscube-crontab.XXXXXX")" +marker='# letscube production health repair' +repair_entry="*/10 * * * * APP_DIR=$APP_DIR ENV_FILE=$ENV_FILE $APP_DIR/scripts/repair-production-services.sh 2>&1 | logger -t letscube-repair" + +cleanup() { + rm -rf -- "$temporary_dir" +} +trap cleanup EXIT + +current="$temporary_dir/current" +filtered="$temporary_dir/filtered" +crontab -l > "$current" 2> /dev/null || : + +if ! grep -Fq 'scripts/deploy.sh' "$current" \ + && grep -Fqx "$repair_entry" "$current"; then + echo "Production health repair cron is already configured." + exit 0 +fi + +if [ ! -f "$BACKUP_FILE" ]; then + install -m 0600 "$current" "$BACKUP_FILE" +fi + +grep -Fv 'scripts/deploy.sh' "$current" \ + | grep -Fv "$marker" \ + | grep -Fv 'scripts/repair-production-services.sh' > "$filtered" || : +printf '%s\n%s\n' "$marker" "$repair_entry" >> "$filtered" +crontab "$filtered" +echo "Replaced the legacy deploy cron with image-safe health repair. Backup: $BACKUP_FILE" diff --git a/scripts/repair-production-services.sh b/scripts/repair-production-services.sh new file mode 100755 index 00000000..0f44b74e --- /dev/null +++ b/scripts/repair-production-services.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash +set -euo pipefail + +APP_DIR="${APP_DIR:-/opt/letscube/runtime}" +ENV_FILE="${ENV_FILE:-/home/www/letscube/.env.prod}" +DEPLOY_WAIT_TIMEOUT_SECONDS="${DEPLOY_WAIT_TIMEOUT_SECONDS:-90}" +LOCK_FILE="${LOCK_FILE:-/tmp/letscube-deploy.lock}" + +if [[ "$ENV_FILE" = /* ]]; then + ENV_PATH="$ENV_FILE" +else + ENV_PATH="$APP_DIR/$ENV_FILE" +fi + +COMPOSE=( + docker compose + --project-directory "$APP_DIR" + -f "$APP_DIR/compose.yml" + -f "$APP_DIR/compose.prod.yml" + --env-file "$ENV_PATH" +) + +exec 9> "$LOCK_FILE" +if ! flock -n 9; then + exit 0 +fi + +release_file="$APP_DIR/.last-successful-deploy" +if [ ! -f "$release_file" ]; then + echo "Cannot repair production before the first successful image deployment." >&2 + exit 1 +fi + +source_sha="$(tr -d '[:space:]' < "$release_file")" +if ! [[ "$source_sha" =~ ^[0-9a-f]{40}$ ]]; then + echo "Invalid release in $release_file" >&2 + exit 1 +fi + +image="letscube-app:$source_sha" +image_source="$(docker image inspect \ + --format '{{index .Config.Labels "org.opencontainers.image.revision"}}' "$image")" +if [ "$image_source" != "$source_sha" ]; then + echo "Release image $image does not match its source label." >&2 + exit 1 +fi + +service_health() { + local service="$1" + local container_id + + container_id="$("${COMPOSE[@]}" ps --status running -q "$service")" + if [ -z "$container_id" ]; then + printf 'missing\n' + return + fi + + docker inspect \ + --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}missing{{end}}' \ + "$container_id" +} + +services=(postgres redis socket api nginx) +unhealthy=() +for service in "${services[@]}"; do + status="$(service_health "$service")" + if [ "$status" != healthy ]; then + unhealthy+=("$service:$status") + fi +done + +if [ "${#unhealthy[@]}" -eq 0 ]; then + exit 0 +fi + +echo "Repairing unhealthy production services: ${unhealthy[*]}" +export APP_IMAGE_TAG="$source_sha" +"${COMPOSE[@]}" config --quiet + +for service in "${services[@]}"; do + if [ "$(service_health "$service")" = healthy ]; then + continue + fi + + "${COMPOSE[@]}" up -d --no-deps --force-recreate --wait \ + --wait-timeout "$DEPLOY_WAIT_TIMEOUT_SECONDS" "$service" +done + +APP_DIR="$APP_DIR" ENV_FILE="$ENV_FILE" \ + "$APP_DIR/scripts/check-production-health.sh" diff --git a/scripts/restore-mongo.sh b/scripts/restore-mongo.sh deleted file mode 100755 index 561f75c3..00000000 --- a/scripts/restore-mongo.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -APP_DIR="${APP_DIR:-/opt/letscube}" -ENV_FILE="${ENV_FILE:-.env.prod}" -MONGO_BACKUP_URI="${MONGO_BACKUP_URI:-mongodb://127.0.0.1:27017/letscube}" - -if [ "$#" -ne 1 ]; then - echo "Usage: $0 /path/to/letscube-mongo-backup.archive.gz" >&2 - exit 2 -fi - -backup_path="$1" -if [ ! -f "$backup_path" ]; then - echo "Backup archive not found: $backup_path" >&2 - exit 2 -fi - -COMPOSE=(docker compose -f compose.yml -f compose.prod.yml --env-file "$ENV_FILE") - -cat <> "$BACKUP_TEST_LOG" + printf '\n' >> "$BACKUP_TEST_LOG" + printf 'test PostgreSQL backup\n' + exit + ;; +esac + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +BACKUP_SCRIPT="$SCRIPT_DIR/backup-postgres.sh" +TEST_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/letscube-backup-test.XXXXXX")" + +cleanup() { + rm -rf -- "$TEST_ROOT" +} + +trap cleanup EXIT + +APP_DIR="$TEST_ROOT/app" +BACKUP_DIR="$TEST_ROOT/backups" +FAKE_BIN="$TEST_ROOT/bin" +BACKUP_TEST_LOG="$TEST_ROOT/docker.log" + +mkdir -p "$APP_DIR" "$BACKUP_DIR" "$FAKE_BIN" +touch "$APP_DIR/compose.yml" "$APP_DIR/compose.prod.yml" "$APP_DIR/.env.prod" +ln -s "$SCRIPT_DIR/test-backup-postgres.sh" "$FAKE_BIN/docker" + +stale_backup="$BACKUP_DIR/letscube-postgres-20261001T000000Z.dump" +unrelated_file="$BACKUP_DIR/keep.txt" +touch -d '16 days ago' "$stale_backup" +touch -d '16 days ago' "$unrelated_file" + +PATH="$FAKE_BIN:$PATH" \ + APP_DIR="$APP_DIR" \ + BACKUP_DIR="$BACKUP_DIR" \ + BACKUP_RETENTION_DAYS=14 \ + BACKUP_TEST_LOG="$BACKUP_TEST_LOG" \ + "$BACKUP_SCRIPT" > "$TEST_ROOT/output.log" + +mapfile -t backups < <(find "$BACKUP_DIR" -maxdepth 1 -type f -name 'letscube-postgres-*.dump') + +if [ "${#backups[@]}" -ne 1 ]; then + echo "Expected one current PostgreSQL backup." >&2 + exit 1 +fi + +if [ "$(<"${backups[0]}")" != 'test PostgreSQL backup' ]; then + echo "The PostgreSQL backup content is incorrect." >&2 + exit 1 +fi + +if [ -e "$stale_backup" ]; then + echo "The stale PostgreSQL backup remains." >&2 + exit 1 +fi + +if [ ! -e "$unrelated_file" ]; then + echo "The retention rule removed an unrelated file." >&2 + exit 1 +fi + +if ! grep -q 'exec -T postgres' "$BACKUP_TEST_LOG"; then + echo "The backup did not use the PostgreSQL service." >&2 + exit 1 +fi + +if APP_DIR="$APP_DIR" BACKUP_DIR="$BACKUP_DIR" BACKUP_RETENTION_DAYS=invalid \ + "$BACKUP_SCRIPT" > /dev/null 2>&1; then + echo "The backup accepted an invalid retention period." >&2 + exit 1 +fi + +echo "PostgreSQL backup script checks passed." diff --git a/scripts/test-compose-metrics-config.sh b/scripts/test-compose-metrics-config.sh index d0cb9293..db15a16d 100755 --- a/scripts/test-compose-metrics-config.sh +++ b/scripts/test-compose-metrics-config.sh @@ -32,4 +32,13 @@ jq -e \ ) ' "$RENDERED_CONFIG" > /dev/null -echo "Production metrics Compose configuration checks passed." +jq -e ' + [.services.api, .services.socket, .services.postgres, .services.redis, .services.nginx] + | all( + .logging.driver == "json-file" + and .logging.options["max-size"] == "20m" + and .logging.options["max-file"] == "3" + ) +' "$RENDERED_CONFIG" > /dev/null + +echo "Production Compose configuration checks passed." diff --git a/scripts/test-deploy-workflow.sh b/scripts/test-deploy-workflow.sh new file mode 100755 index 00000000..5195651b --- /dev/null +++ b/scripts/test-deploy-workflow.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -euo pipefail + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +ROOT_DIR="$(cd -- "$SCRIPT_DIR/.." && pwd)" +WORKFLOW="$ROOT_DIR/.github/workflows/deploy.yml" +IMAGE_DEPLOY="$SCRIPT_DIR/deploy-image-release.sh" +HEALTH_CHECK="$SCRIPT_DIR/check-production-health.sh" + +assert_contains() { + local file="$1" + local expected="$2" + + if ! grep -Fq -- "$expected" "$file"; then + echo "$file must contain: $expected" >&2 + exit 1 + fi +} + +assert_contains "$WORKFLOW" 'workflows: [CI]' +assert_contains "$WORKFLOW" 'branches: [master]' +assert_contains "$WORKFLOW" "github.event.workflow_run.conclusion == 'success'" +assert_contains "$WORKFLOW" 'image_ref=$IMAGE_REPOSITORY@$IMAGE_DIGEST' +assert_contains "$WORKFLOW" 'for attempt in 1 2 3; do' +assert_contains "$WORKFLOW" '--cache-to type=gha,mode=max,scope=production-image' +assert_contains "$WORKFLOW" 'Image build attempt $attempt failed.' +assert_contains "$WORKFLOW" 'Image transfer attempt $attempt failed.' +assert_contains "$WORKFLOW" 'docker save "letscube-app:$SOURCE_SHA"' +assert_contains "$WORKFLOW" 'scripts/deploy-image-release.sh scripts/check-production-health.sh' +assert_contains "$WORKFLOW" 'scripts/repair-production-services.sh' +assert_contains "$WORKFLOW" 'scripts/disable-legacy-deploy-cron.sh' +assert_contains "$WORKFLOW" 'APP_DIR: /opt/letscube/runtime' +assert_contains "$WORKFLOW" 'ENV_FILE: /home/www/letscube/.env.prod' + +assert_contains "$IMAGE_DEPLOY" 'docker image inspect "$image"' +assert_contains "$IMAGE_DEPLOY" 'org.opencontainers.image.revision' +assert_contains "$IMAGE_DEPLOY" 'run --rm --no-deps migrate' +assert_contains "$IMAGE_DEPLOY" 'printf '\''%s\n'\'' "$SOURCE_SHA" > "$APP_DIR/.last-successful-deploy"' +assert_contains "$HEALTH_CHECK" 'services=(postgres redis socket api nginx)' + +if grep -Eq 'git (pull|fetch|merge)' "$IMAGE_DEPLOY"; then + echo 'Image deployment must not update a production Git checkout.' >&2 + exit 1 +fi + +bash -n "$IMAGE_DEPLOY" "$HEALTH_CHECK" +echo 'GitHub Actions deployment checks passed.' diff --git a/scripts/test-deploy.sh b/scripts/test-deploy.sh index c707956f..97e5754b 100755 --- a/scripts/test-deploy.sh +++ b/scripts/test-deploy.sh @@ -55,10 +55,18 @@ fake_docker() { case "$1" in inspect) - printf 'sha256:old-image\n' + if [[ "$*" == *'.State.Health'* ]]; then + if [ "${FAKE_UNHEALTHY_CONTAINER:-}" = "${*: -1}" ]; then + printf 'unhealthy\n' + else + printf 'healthy\n' + fi + else + printf 'sha256:old-image\n' + fi return 0 ;; - image) + builder|image) return 0 ;; compose) @@ -100,6 +108,12 @@ fake_docker() { nginx) [ -z "${FAKE_RUNNING_NGINX:-}" ] || printf '%s\n' "$FAKE_RUNNING_NGINX" ;; + postgres) + [ -z "${FAKE_RUNNING_POSTGRES:-}" ] || printf '%s\n' "$FAKE_RUNNING_POSTGRES" + ;; + redis) + [ -z "${FAKE_RUNNING_REDIS:-}" ] || printf '%s\n' "$FAKE_RUNNING_REDIS" + ;; esac return 0 fi @@ -207,13 +221,17 @@ run_bootstrap_test() { TMPDIR="$scenario/tmp" \ bash "$app_dir/scripts/deploy.sh" > "$output" 2>&1 - assert_contains "$(<"$output")" 'Missing runtime services: api socket nginx; deploying all.' + assert_contains "$(<"$output")" \ + 'Missing production services: postgres redis api socket nginx; deploying all.' assert_contains "$(<"$output")" '(target: all)' - backing_line="$(command_line "$log" 'up -d --no-recreate --wait --wait-timeout 17 mongo postgres redis')" + backing_line="$(command_line "$log" \ + 'up -d --force-recreate --wait --wait-timeout 17 postgres')" migration_line="$(command_line "$log" 'run --rm --no-deps migrate')" - socket_line="$(command_line "$log" 'up -d --no-deps --wait --wait-timeout 17 socket')" - api_line="$(command_line "$log" 'up -d --no-deps --wait --wait-timeout 17 api')" + socket_line="$(command_line "$log" \ + 'up -d --no-deps --force-recreate --wait --wait-timeout 17 socket')" + api_line="$(command_line "$log" \ + 'up -d --no-deps --force-recreate --wait --wait-timeout 17 api')" if [ "$backing_line" -ge "$migration_line" ]; then echo 'Migrations ran before backing services became ready.' >&2 @@ -223,6 +241,44 @@ run_bootstrap_test() { echo 'Bootstrap did not deploy socket before API.' >&2 exit 1 fi + + assert_contains "$(<"$log")" 'docker image prune -af --filter until=168h' + assert_contains "$(<"$log")" 'docker builder prune -af --max-used-space 2GB' +} + +run_compose_change_test() { + local scenario="$TEST_ROOT/compose-change" + local app_dir="$scenario/app" + local log="$scenario/commands.log" + local output="$scenario/output.log" + local git_state="$scenario/git-state" + local rollback_marker="$scenario/rollback" + local previous_commit="1111111111111111111111111111111111111111" + local current_commit="2222222222222222222222222222222222222222" + + mkdir -p "$scenario/tmp" + prepare_app "$app_dir" + + PATH="$FAKE_BIN:$PATH" \ + APP_DIR="$app_dir" \ + DEPLOY_TEST_LOG="$log" \ + DEPLOY_WAIT_TIMEOUT_SECONDS=17 \ + ENV_FILE=.env.prod \ + FAKE_CHANGED_PATH=compose.prod.yml \ + FAKE_CURRENT_COMMIT="$current_commit" \ + FAKE_GIT_STATE="$git_state" \ + FAKE_PREVIOUS_COMMIT="$previous_commit" \ + FAKE_ROLLBACK_MARKER="$rollback_marker" \ + FAKE_RUNNING_API=api-container \ + FAKE_RUNNING_NGINX=nginx-container \ + FAKE_RUNNING_SOCKET=socket-container \ + TMPDIR="$scenario/tmp" \ + bash "$app_dir/scripts/deploy.sh" > "$output" 2>&1 + + assert_contains "$(<"$log")" \ + 'up -d --force-recreate --wait --wait-timeout 17 postgres redis' + assert_contains "$(<"$log")" \ + 'up -d --no-deps --force-recreate --wait --wait-timeout 17 nginx' } run_rollback_test() { @@ -270,6 +326,78 @@ run_rollback_test() { assert_contains "$rollback_details" 'APP_IMAGE_TAG=rollback-socket-111111111111-' assert_contains "$(<"$log")" "git show $previous_commit:compose.yml" assert_contains "$(<"$log")" "git show $previous_commit:compose.prod.yml" + + if [ "$(<"$app_dir/.last-successful-deploy")" != "$previous_commit" ]; then + echo 'Failed deployment changed the last successful commit.' >&2 + exit 1 + fi + if grep -Eq 'docker (image|builder) prune' "$log"; then + echo 'Failed deployment removed Docker data.' >&2 + exit 1 + fi + + PATH="$FAKE_BIN:$PATH" \ + APP_DIR="$app_dir" \ + DEPLOY_TEST_LOG="$log" \ + DEPLOY_WAIT_TIMEOUT_SECONDS=17 \ + ENV_FILE=.env.prod \ + FAKE_CHANGED_PATH=server/index.js \ + FAKE_CURRENT_COMMIT="$current_commit" \ + FAKE_GIT_STATE="$git_state" \ + FAKE_PREVIOUS_COMMIT="$previous_commit" \ + FAKE_ROLLBACK_MARKER="$rollback_marker" \ + FAKE_RUNNING_API=api-container \ + FAKE_RUNNING_NGINX=nginx-container \ + FAKE_RUNNING_POSTGRES=postgres-container \ + FAKE_RUNNING_REDIS=redis-container \ + FAKE_RUNNING_SOCKET=socket-container \ + TMPDIR="$scenario/tmp" \ + bash "$app_dir/scripts/deploy.sh" >> "$output" 2>&1 + + if [ "$(<"$app_dir/.last-successful-deploy")" != "$current_commit" ]; then + echo 'Successful retry did not record the deployed commit.' >&2 + exit 1 + fi + +} + +run_unhealthy_service_test() { + local scenario="$TEST_ROOT/unhealthy" + local app_dir="$scenario/app" + local log="$scenario/commands.log" + local output="$scenario/output.log" + local git_state="$scenario/git-state" + local rollback_marker="$scenario/rollback" + local commit="3333333333333333333333333333333333333333" + + mkdir -p "$scenario/tmp" + prepare_app "$app_dir" + + PATH="$FAKE_BIN:$PATH" \ + APP_DIR="$app_dir" \ + DEPLOY_TEST_LOG="$log" \ + DEPLOY_WAIT_TIMEOUT_SECONDS=17 \ + ENV_FILE=.env.prod \ + FAKE_CURRENT_COMMIT="$commit" \ + FAKE_GIT_STATE="$git_state" \ + FAKE_PREVIOUS_COMMIT="$commit" \ + FAKE_ROLLBACK_MARKER="$rollback_marker" \ + FAKE_RUNNING_API=api-container \ + FAKE_RUNNING_NGINX=nginx-container \ + FAKE_RUNNING_POSTGRES=postgres-container \ + FAKE_RUNNING_REDIS=redis-container \ + FAKE_RUNNING_SOCKET=socket-container \ + FAKE_UNHEALTHY_CONTAINER=api-container \ + TMPDIR="$scenario/tmp" \ + bash "$app_dir/scripts/deploy.sh" > "$output" 2>&1 + + assert_contains "$(<"$output")" 'Unhealthy production services: api:unhealthy; deploying all.' + assert_contains "$(<"$log")" \ + 'up -d --no-deps --force-recreate --wait --wait-timeout 17 socket' + if grep -Fq 'up -d --force-recreate --wait --wait-timeout 17 postgres redis' "$log"; then + echo 'An unhealthy API caused healthy backing services to be recreated.' >&2 + exit 1 + fi } run_privacy_floor_test() { @@ -309,7 +437,9 @@ run_privacy_floor_test() { } run_bootstrap_test +run_compose_change_test run_rollback_test +run_unhealthy_service_test run_privacy_floor_test echo 'Deploy script checks passed.' diff --git a/scripts/test-image-deploy.sh b/scripts/test-image-deploy.sh new file mode 100755 index 00000000..d42d059c --- /dev/null +++ b/scripts/test-image-deploy.sh @@ -0,0 +1,209 @@ +#!/usr/bin/env bash +set -euo pipefail + +log_command() { + { + printf 'APP_IMAGE_TAG=%s docker' "${APP_IMAGE_TAG:-}" + printf ' %q' "$@" + printf '\n' + } >> "$IMAGE_DEPLOY_TEST_LOG" +} + +fake_docker() { + log_command "$@" + + if [ "$1" = image ]; then + case "$2" in + inspect) + if [[ "$*" == *org.opencontainers.image.revision* ]]; then + printf '%s\n' "$IMAGE_DEPLOY_TEST_SHA" + fi + return 0 + ;; + tag|prune) return 0 ;; + esac + fi + + if [ "$1" = inspect ]; then + if [[ "$*" == *org.opencontainers.image.revision* ]]; then + printf '%s\n' "$IMAGE_DEPLOY_TEST_SHA" + elif [[ "$*" == *'.State.Health'* ]]; then + printf 'healthy\n' + else + printf 'sha256:old-image\n' + fi + return 0 + fi + + if [ "$1" != compose ]; then + echo "Unexpected fake Docker command: $*" >&2 + return 1 + fi + + local subcommand="" + local service="${*: -1}" + local arg + for arg in "$@"; do + case "$arg" in + config|logs|ps|run|up) + if [ -z "$subcommand" ]; then + subcommand="$arg" + fi + ;; + esac + done + + if [ "$subcommand" = ps ] && [[ "$*" == *' -q '* ]]; then + printf '%s-container\n' "$service" + fi + if [ "$subcommand" = up ] && [ "$service" = api ] \ + && [ "${FAKE_FAIL_CANDIDATE_API:-false}" = true ] \ + && [ "${APP_IMAGE_TAG:-}" = "$IMAGE_DEPLOY_TEST_SHA" ]; then + return 1 + fi +} + +fake_crontab() { + if [ "${1:-}" = -l ]; then + cat "$CRONTAB_TEST_STATE" + else + cp "$1" "$CRONTAB_TEST_STATE" + fi +} + +case "$(basename -- "$0")" in + docker) + fake_docker "$@" + exit + ;; + crontab) + fake_crontab "$@" + exit + ;; +esac + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +TEST_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/letscube-image-deploy-test.XXXXXX")" +SOURCE_SHA="4444444444444444444444444444444444444444" + +cleanup() { + rm -rf -- "$TEST_ROOT" +} +trap cleanup EXIT + +FAKE_BIN="$TEST_ROOT/bin" +mkdir -p "$FAKE_BIN" +ln -s "$SCRIPT_DIR/test-image-deploy.sh" "$FAKE_BIN/docker" +ln -s "$SCRIPT_DIR/test-image-deploy.sh" "$FAKE_BIN/crontab" + +prepare_scenario() { + local scenario="$1" + local app_dir="$scenario/app" + local release_dir="$scenario/release" + + mkdir -p "$app_dir/scripts" "$release_dir" + printf 'production secrets\n' > "$app_dir/.env.prod" + printf 'old compose\n' > "$app_dir/compose.yml" + printf 'old production compose\n' > "$app_dir/compose.prod.yml" + printf 'old nginx\n' > "$app_dir/nginx.conf" + printf 'new compose\n' > "$release_dir/compose.yml" + printf 'new production compose\n' > "$release_dir/compose.prod.yml" + printf 'new nginx\n' > "$release_dir/nginx.conf" + cp "$SCRIPT_DIR/check-production-health.sh" "$release_dir/check-production-health.sh" + cp "$SCRIPT_DIR/repair-production-services.sh" "$release_dir/repair-production-services.sh" + chmod +x "$release_dir/check-production-health.sh" \ + "$release_dir/repair-production-services.sh" +} + +assert_order() { + local log="$1" + local first="$2" + local second="$3" + local first_line + local second_line + + first_line="$(grep -n -m1 -F -- "$first" "$log" | cut -d: -f1)" + second_line="$(grep -n -m1 -F -- "$second" "$log" | cut -d: -f1)" + if [ -z "$first_line" ] || [ -z "$second_line" ] || [ "$first_line" -ge "$second_line" ]; then + echo "Expected '$first' before '$second'." >&2 + exit 1 + fi +} + +run_success_test() { + local scenario="$TEST_ROOT/success" + local log="$scenario/docker.log" + prepare_scenario "$scenario" + + PATH="$FAKE_BIN:$PATH" \ + APP_DIR="$scenario/app" \ + ENV_FILE=.env.prod \ + IMAGE_DEPLOY_TEST_LOG="$log" \ + IMAGE_DEPLOY_TEST_SHA="$SOURCE_SHA" \ + HEALTH_ATTEMPTS=1 \ + LOCK_FILE="$scenario/deploy.lock" \ + bash "$SCRIPT_DIR/deploy-image-release.sh" "$SOURCE_SHA" "$scenario/release" + + test "$(<"$scenario/app/.last-successful-deploy")" = "$SOURCE_SHA" + test "$(<"$scenario/app/compose.yml")" = 'new compose' + assert_order "$log" 'run --rm --no-deps migrate' \ + "up -d --no-deps --force-recreate --wait --wait-timeout 90 socket" + assert_order "$log" \ + "up -d --no-deps --force-recreate --wait --wait-timeout 90 socket" \ + "up -d --no-deps --force-recreate --wait --wait-timeout 90 api" +} + +run_rollback_test() { + local scenario="$TEST_ROOT/rollback" + local log="$scenario/docker.log" + prepare_scenario "$scenario" + + if PATH="$FAKE_BIN:$PATH" \ + APP_DIR="$scenario/app" \ + ENV_FILE=.env.prod \ + FAKE_FAIL_CANDIDATE_API=true \ + IMAGE_DEPLOY_TEST_LOG="$log" \ + IMAGE_DEPLOY_TEST_SHA="$SOURCE_SHA" \ + HEALTH_ATTEMPTS=1 \ + LOCK_FILE="$scenario/deploy.lock" \ + bash "$SCRIPT_DIR/deploy-image-release.sh" "$SOURCE_SHA" "$scenario/release"; then + echo 'Expected the candidate API deployment to fail.' >&2 + exit 1 + fi + + test ! -e "$scenario/app/.last-successful-deploy" + test "$(<"$scenario/app/compose.yml")" = 'old compose' + grep -Fq 'APP_IMAGE_TAG=rollback-socket-' "$log" + grep -Fq 'APP_IMAGE_TAG=rollback-api-' "$log" +} + +run_disable_cron_test() { + local scenario="$TEST_ROOT/disable-cron" + local state="$scenario/crontab" + local backup="$scenario/crontab.backup" + + mkdir -p "$scenario" + cat > "$state" <<'CRONTAB' +*/10 7-14 * * * cd /home/www/letscube && ./scripts/deploy.sh +17 8 * * * cd /home/www/letscube && ./scripts/backup-postgres.sh +CRONTAB + + PATH="$FAKE_BIN:$PATH" CRONTAB_TEST_STATE="$state" BACKUP_FILE="$backup" \ + bash "$SCRIPT_DIR/disable-legacy-deploy-cron.sh" + + grep -Fq 'scripts/deploy.sh' "$backup" + grep -Fq 'scripts/backup-postgres.sh' "$state" + grep -Fq 'scripts/repair-production-services.sh' "$state" + if grep -Fq 'scripts/deploy.sh' "$state"; then + echo 'Legacy deployment cron was not removed.' >&2 + exit 1 + fi + + PATH="$FAKE_BIN:$PATH" CRONTAB_TEST_STATE="$state" BACKUP_FILE="$backup" \ + bash "$SCRIPT_DIR/disable-legacy-deploy-cron.sh" +} + +run_success_test +run_rollback_test +run_disable_cron_test +echo 'Image deployment checks passed.' diff --git a/scripts/test-mongo-backup-restore-live.sh b/scripts/test-mongo-backup-restore-live.sh deleted file mode 100755 index c33385e3..00000000 --- a/scripts/test-mongo-backup-restore-live.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -TEST_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/letscube-mongo-live-rehearsal.XXXXXX")" -NETWORK="letscube-mongo-rehearsal-$RANDOM-$$" -SOURCE="${NETWORK}-source" -TARGET="${NETWORK}-target" -ARCHIVE="$TEST_ROOT/backup.archive.gz" - -cleanup() { - docker rm -f "$SOURCE" "$TARGET" >/dev/null 2>&1 || true - docker network rm "$NETWORK" >/dev/null 2>&1 || true - rm -rf -- "$TEST_ROOT" -} - -trap cleanup EXIT - -wait_for_mongo() { - local container="$1" - local attempt - - for attempt in {1..30}; do - if docker exec "$container" mongosh --quiet --eval 'db.runCommand({ ping: 1 }).ok' \ - | grep -qx '1'; then - return - fi - - sleep 1 - done - - echo "MongoDB did not become ready: $container" >&2 - docker logs "$container" >&2 || true - exit 1 -} - -docker network create "$NETWORK" >/dev/null -docker run -d --rm --name "$SOURCE" --network "$NETWORK" mongo:7.0 >/dev/null -docker run -d --rm --name "$TARGET" --network "$NETWORK" mongo:7.0 >/dev/null - -wait_for_mongo "$SOURCE" -wait_for_mongo "$TARGET" - -docker exec "$SOURCE" mongosh rehearsal --quiet --eval \ - 'db.attempts.insertOne({ ordinal: 1, scramble: "synthetic", solveMs: 12345 })' >/dev/null -docker exec "$TARGET" mongosh rehearsal --quiet --eval \ - 'db.attempts.insertOne({ stale: true })' >/dev/null - -docker exec "$SOURCE" mongodump \ - --uri 'mongodb://localhost:27017/rehearsal' \ - --archive --gzip > "$ARCHIVE" -docker exec -i "$TARGET" mongorestore \ - --uri 'mongodb://localhost:27017/rehearsal' \ - --drop --archive --gzip < "$ARCHIVE" - -record_count="$(docker exec "$TARGET" mongosh rehearsal --quiet --eval 'db.attempts.countDocuments({})')" -scramble="$(docker exec "$TARGET" mongosh rehearsal --quiet --eval 'db.attempts.findOne().scramble')" - -if [ "$record_count" != '1' ] || [ "$scramble" != 'synthetic' ]; then - echo 'MongoDB backup/restore rehearsal did not preserve the synthetic attempt.' >&2 - exit 1 -fi - -echo 'Live MongoDB backup and restore rehearsal passed.' diff --git a/scripts/test-mongo-backup-restore.sh b/scripts/test-mongo-backup-restore.sh deleted file mode 100755 index a9243f91..00000000 --- a/scripts/test-mongo-backup-restore.sh +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -log_command() { - local command="$1" - shift - - { - printf '%s' "$command" - printf ' %q' "$@" - printf '\n' - } >> "$MONGO_REHEARSAL_LOG" -} - -fake_docker() { - log_command docker "$@" - - if [ "$1" != "compose" ]; then - echo "Unexpected fake docker command: $*" >&2 - return 1 - fi - - if [[ "$*" == *mongodump* ]]; then - printf 'synthetic-mongo-archive' - return 0 - fi - - if [[ "$*" == *mongorestore* ]]; then - printf 'restore-input-bytes=%s\n' "$(wc -c)" >> "$MONGO_REHEARSAL_LOG" - return 0 - fi - - echo "Unexpected fake Docker Compose command: $*" >&2 - return 1 -} - -case "$(basename -- "$0")" in - docker) - fake_docker "$@" - exit - ;; -esac - -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" -BACKUP_SCRIPT="$SCRIPT_DIR/backup-mongo.sh" -RESTORE_SCRIPT="$SCRIPT_DIR/restore-mongo.sh" -TEST_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/letscube-mongo-rehearsal.XXXXXX")" - -cleanup() { - rm -rf -- "$TEST_ROOT" -} - -trap cleanup EXIT - -FAKE_BIN="$TEST_ROOT/bin" -mkdir -p "$FAKE_BIN" -ln -s "$SCRIPT_DIR/test-mongo-backup-restore.sh" "$FAKE_BIN/docker" - -assert_contains() { - local value="$1" - local expected="$2" - - if [[ "$value" != *"$expected"* ]]; then - echo "Expected output to contain: $expected" >&2 - exit 1 - fi -} - -run_backup_test() { - local scenario="$TEST_ROOT/backup" - local backup_dir="$scenario/backups" - local log="$scenario/commands.log" - local output="$scenario/output.log" - local backup_path - - mkdir -p "$scenario/app" - - PATH="$FAKE_BIN:$PATH" \ - APP_DIR="$scenario/app" \ - BACKUP_DIR="$backup_dir" \ - MONGO_BACKUP_URI="mongodb://mongo:27017/letscube" \ - MONGO_REHEARSAL_LOG="$log" \ - bash "$BACKUP_SCRIPT" > "$output" - - backup_path="$(find "$backup_dir" -type f -name 'letscube-mongo-daily-*.archive.gz' -print -quit)" - if [ ! -f "$backup_path" ]; then - echo 'Backup script did not create a daily archive.' >&2 - exit 1 - fi - - if [ "$(<"$backup_path")" != 'synthetic-mongo-archive' ]; then - echo 'Backup archive did not contain the synthetic Mongo dump.' >&2 - exit 1 - fi - - assert_contains "$(<"$output")" 'Created MongoDB backup:' - assert_contains "$(<"$log")" 'mongodump' - assert_contains "$(<"$log")" 'MONGO_BACKUP_URI=mongodb://mongo:27017/letscube' -} - -run_restore_test() { - local scenario="$TEST_ROOT/restore" - local archive="$scenario/backup.archive.gz" - local log="$scenario/commands.log" - local output="$scenario/output.log" - - mkdir -p "$scenario/app" - printf 'synthetic restore archive' > "$archive" - - if printf 'NO\n' | PATH="$FAKE_BIN:$PATH" \ - APP_DIR="$scenario/app" \ - MONGO_BACKUP_URI="mongodb://mongo:27017/letscube" \ - MONGO_REHEARSAL_LOG="$log" \ - bash "$RESTORE_SCRIPT" "$archive" > "$output"; then - echo 'Restore accepted an invalid confirmation.' >&2 - exit 1 - fi - - if [ -e "$log" ]; then - echo 'Restore invoked Docker before receiving the required confirmation.' >&2 - exit 1 - fi - - printf 'RESTORE\n' | PATH="$FAKE_BIN:$PATH" \ - APP_DIR="$scenario/app" \ - MONGO_BACKUP_URI="mongodb://mongo:27017/letscube" \ - MONGO_REHEARSAL_LOG="$log" \ - bash "$RESTORE_SCRIPT" "$archive" > "$output" - - assert_contains "$(<"$output")" 'MongoDB restore completed.' - assert_contains "$(<"$log")" 'mongorestore' - assert_contains "$(<"$log")" '--drop' - assert_contains "$(<"$log")" '--archive' - assert_contains "$(<"$log")" '--gzip' - assert_contains "$(<"$log")" 'restore-input-bytes=25' -} - -run_backup_test -run_restore_test - -echo 'MongoDB backup and restore rehearsal checks passed.' diff --git a/scripts/test-production-repair.sh b/scripts/test-production-repair.sh new file mode 100755 index 00000000..e75956ef --- /dev/null +++ b/scripts/test-production-repair.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +set -euo pipefail + +log_command() { + { + printf 'APP_IMAGE_TAG=%s docker' "${APP_IMAGE_TAG:-}" + printf ' %q' "$@" + printf '\n' + } >> "$REPAIR_TEST_LOG" +} + +fake_docker() { + log_command "$@" + + if [ "$1" = image ]; then + printf '%s\n' "$REPAIR_TEST_SHA" + return 0 + fi + + if [ "$1" = inspect ]; then + if [[ "$*" == *org.opencontainers.image.revision* ]]; then + printf '%s\n' "$REPAIR_TEST_SHA" + elif grep -Fqx "${*: -1}" "$REPAIR_TEST_REPAIRED" 2> /dev/null; then + printf 'healthy\n' + elif [ "${*: -1}" = "${REPAIR_TEST_UNHEALTHY:-}" ]; then + printf 'unhealthy\n' + else + printf 'healthy\n' + fi + return 0 + fi + + if [ "$1" != compose ]; then + echo "Unexpected fake Docker command: $*" >&2 + return 1 + fi + + local service="${*: -1}" + if [[ "$*" == *' ps '* ]]; then + printf '%s-container\n' "$service" + elif [[ "$*" == *' up '* ]]; then + printf '%s-container\n' "$service" >> "$REPAIR_TEST_REPAIRED" + fi +} + +case "$(basename -- "$0")" in + docker) + fake_docker "$@" + exit + ;; +esac + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +TEST_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/letscube-repair-test.XXXXXX")" +SOURCE_SHA="5555555555555555555555555555555555555555" + +cleanup() { + rm -rf -- "$TEST_ROOT" +} +trap cleanup EXIT + +mkdir -p "$TEST_ROOT/bin" "$TEST_ROOT/app/scripts" +ln -s "$SCRIPT_DIR/test-production-repair.sh" "$TEST_ROOT/bin/docker" +cp "$SCRIPT_DIR/check-production-health.sh" "$TEST_ROOT/app/scripts/" +chmod +x "$TEST_ROOT/app/scripts/check-production-health.sh" +touch "$TEST_ROOT/app/compose.yml" "$TEST_ROOT/app/compose.prod.yml" \ + "$TEST_ROOT/app/.env.prod" "$TEST_ROOT/repaired" +printf '%s\n' "$SOURCE_SHA" > "$TEST_ROOT/app/.last-successful-deploy" + +PATH="$TEST_ROOT/bin:$PATH" \ + APP_DIR="$TEST_ROOT/app" \ + ENV_FILE=.env.prod \ + HEALTH_ATTEMPTS=1 \ + LOCK_FILE="$TEST_ROOT/deploy.lock" \ + REPAIR_TEST_LOG="$TEST_ROOT/docker.log" \ + REPAIR_TEST_REPAIRED="$TEST_ROOT/repaired" \ + REPAIR_TEST_SHA="$SOURCE_SHA" \ + REPAIR_TEST_UNHEALTHY=api-container \ + bash "$SCRIPT_DIR/repair-production-services.sh" + +grep -Fq 'up -d --no-deps --force-recreate --wait --wait-timeout 90 api' \ + "$TEST_ROOT/docker.log" +if grep -Fq 'up -d --no-deps --force-recreate --wait --wait-timeout 90 postgres' \ + "$TEST_ROOT/docker.log"; then + echo 'Repair replaced a healthy PostgreSQL container.' >&2 + exit 1 +fi + +echo 'Production service repair checks passed.' diff --git a/server/auth/index.js b/server/auth/index.js index 900dc52b..04de5db3 100644 --- a/server/auth/index.js +++ b/server/auth/index.js @@ -94,7 +94,7 @@ module.exports = (app, passport, rateLimitOptions = apiRateLimitOptions()) => { const user = await User.findOneAndUpdate({ id: +profile.id, - }, buildWcaUserUpdate(profile, tokenRes.access_token), { + }, buildWcaUserUpdate(profile), { upsert: true, useFindAndModify: false, new: true, diff --git a/server/auth/wcaProfile.js b/server/auth/wcaProfile.js index d41a0237..53835771 100644 --- a/server/auth/wcaProfile.js +++ b/server/auth/wcaProfile.js @@ -1,8 +1,7 @@ -const buildWcaUserUpdate = (profile, accessToken) => ({ +const buildWcaUserUpdate = (profile) => ({ id: Number(profile.id), name: profile.name, wcaId: profile.wca_id, - accessToken, avatar: profile.avatar, }); diff --git a/server/auth/wcaProfile.test.js b/server/auth/wcaProfile.test.js index 0769ee39..109fc37a 100644 --- a/server/auth/wcaProfile.test.js +++ b/server/auth/wcaProfile.test.js @@ -19,7 +19,6 @@ describe('WCA profile ingestion', () => { id: 1234, name: 'Test Solver', wcaId: '2026TEST01', - accessToken: 'oauth-token', avatar: { thumb_url: 'avatar.png' }, }); expect(update).not.toHaveProperty('email'); diff --git a/server/cache/lru.js b/server/cache/lru.js new file mode 100644 index 00000000..78d598b8 --- /dev/null +++ b/server/cache/lru.js @@ -0,0 +1,102 @@ +class LruCache { + constructor({ maxBytes = 128 * 1024 * 1024, ttlMs = 60 * 1000, estimateSize = defaultSize } = {}) { + if (!Number.isFinite(maxBytes) || maxBytes <= 0) { + throw new Error('LRU maxBytes must be positive'); + } + if (!Number.isFinite(ttlMs) || ttlMs <= 0) { + throw new Error('LRU ttlMs must be positive'); + } + + this.maxBytes = maxBytes; + this.ttlMs = ttlMs; + this.estimateSize = estimateSize; + this.entries = new Map(); + this.bytes = 0; + } + + get size() { + return this.entries.size; + } + + get usedBytes() { + return this.bytes; + } + + get(key, now = Date.now()) { + const entry = this.entries.get(key); + if (!entry) { + return undefined; + } + + if (entry.expiresAt <= now) { + this.delete(key); + return undefined; + } + + this.entries.delete(key); + this.entries.set(key, entry); + return entry.value; + } + + set(key, value, now = Date.now()) { + const bytes = Math.max(1, this.estimateSize(value)); + this.delete(key); + + if (bytes > this.maxBytes) { + return false; + } + + this.entries.set(key, { + value, + bytes, + expiresAt: now + this.ttlMs, + }); + this.bytes += bytes; + this.evict(now); + return true; + } + + delete(key) { + const entry = this.entries.get(key); + if (!entry) { + return false; + } + this.entries.delete(key); + this.bytes -= entry.bytes; + return true; + } + + clear() { + this.entries.clear(); + this.bytes = 0; + } + + invalidatePrefix(prefix) { + for (const key of this.entries.keys()) { + if (key.startsWith(prefix)) { + this.delete(key); + } + } + } + + evict(now = Date.now()) { + for (const [key, entry] of this.entries) { + if (entry.expiresAt <= now || this.bytes > this.maxBytes) { + this.delete(key); + } + if (this.bytes <= this.maxBytes) { + break; + } + } + } +} + +const defaultSize = (value) => { + try { + return Buffer.byteLength(JSON.stringify(value)); + } catch { + return 1; + } +}; + +module.exports = { LruCache, defaultSize }; diff --git a/server/cache/lru.test.js b/server/cache/lru.test.js new file mode 100644 index 00000000..4778dab7 --- /dev/null +++ b/server/cache/lru.test.js @@ -0,0 +1,36 @@ +const { LruCache } = require('./lru'); + +describe('LruCache', () => { + it('evicts the least recently used entry at the byte limit', () => { + const cache = new LruCache({ maxBytes: 4, ttlMs: 1000, estimateSize: (value) => value.length }); + + cache.set('one', 'aa'); + cache.set('two', 'bb'); + expect(cache.get('one')).toBe('aa'); + cache.set('three', 'cc'); + + expect(cache.get('one')).toBe('aa'); + expect(cache.get('two')).toBeUndefined(); + expect(cache.get('three')).toBe('cc'); + }); + + it('expires entries without requiring a timer', () => { + const cache = new LruCache({ maxBytes: 100, ttlMs: 10, estimateSize: () => 1 }); + cache.set('room', { id: 1 }, 100); + + expect(cache.get('room', 109)).toEqual({ id: 1 }); + expect(cache.get('room', 110)).toBeUndefined(); + }); + + it('invalidates related keys by prefix', () => { + const cache = new LruCache({ maxBytes: 100, estimateSize: () => 1 }); + cache.set('room:a', 1); + cache.set('room:b', 2); + cache.set('user:a', 3); + + cache.invalidatePrefix('room:'); + + expect(cache.size).toBe(1); + expect(cache.get('user:a')).toBe(3); + }); +}); diff --git a/server/config/default.json b/server/config/default.json index 463f6120..46a8c12c 100644 --- a/server/config/default.json +++ b/server/config/default.json @@ -6,7 +6,6 @@ "port": 9000, "reconnectGraceMs": 60000 }, - "mongodb": "mongodb://127.0.0.1/letscube", "postgres": { "host": "127.0.0.1", "port": 5432, diff --git a/server/config/dev.json b/server/config/dev.json index 8caf1c67..bd3f7dd4 100644 --- a/server/config/dev.json +++ b/server/config/dev.json @@ -6,7 +6,6 @@ "socketio": { "port": 9000 }, - "mongodb": "mongodb://127.0.0.1/letscube", "postgres": { "host": "127.0.0.1", "port": 55433, diff --git a/server/database.js b/server/database.js index 44543be2..50d90cb3 100644 --- a/server/database.js +++ b/server/database.js @@ -1,15 +1,15 @@ const mongoose = require('mongoose'); -const config = require('./runtimeConfig'); const logger = require('./logger'); +const mongoUrl = process.env.MONGO_URL || process.env.MONGODB_URI || 'mongodb://127.0.0.1/letscube'; module.exports.connect = async () => { - logger.debug('[MONGODB] Attempting to connect to database.', { url: config.mongodb }); + logger.debug('[MONGODB] Attempting to connect to migration source.', { url: mongoUrl }); mongoose.set('strictQuery', false); - await mongoose.connect(config.mongodb).then(() => { - logger.debug('[MONGODB] Connected to database.', { url: config.mongodb }); + await mongoose.connect(mongoUrl).then(() => { + logger.debug('[MONGODB] Connected to migration source.', { url: mongoUrl }); }).catch((err) => { logger.error('[MONGODB] Error when connecting to database', err); process.exit(1); diff --git a/server/index.js b/server/index.js index 9976667d..7ead393c 100644 --- a/server/index.js +++ b/server/index.js @@ -8,7 +8,6 @@ const lusca = require('lusca'); const rateLimit = require('express-rate-limit'); const config = require('./runtimeConfig'); -const { connect } = require('./database'); const { createHealthHandler, createHealthReporter } = require('./health'); const { initializePostgres, pool, startPostgresMaintenance } = require('./postgres'); const session = require('./middlewares/session'); @@ -31,22 +30,17 @@ const init = async () => { app.use(express.json()); // for parsing application/json app.use(express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded - const mongoose = await connect(); - await initializePostgres(); + if (!(await initializePostgres())) { + throw new Error('PostgreSQL is required for the API runtime'); + } startPostgresMaintenance(); const reportHealth = createHealthReporter({ service: 'api', checks: { - mongodb: () => mongoose.connection.readyState === 1, - postgres: { - required: false, - check: async () => { - if (config.postgres.enabled) { - await pool.query('SELECT 1'); - } - return true; - }, + postgres: async () => { + await pool.query('SELECT 1'); + return true; }, }, }); diff --git a/server/metrics.js b/server/metrics.js index 2c067cb4..c5d61a31 100644 --- a/server/metrics.js +++ b/server/metrics.js @@ -4,7 +4,6 @@ const { v4: uuidv4 } = require('uuid'); const config = require('./runtimeConfig'); const logger = require('./logger'); const { METRIC_EVENTS, MetricEvent } = require('./models'); -const { mirrorMetricEvent } = require('./postgres/dualWrite'); const MS_PER_DAY = 24 * 60 * 60 * 1000; @@ -19,7 +18,7 @@ const createMetricRecorder = ({ model = MetricEvent, metricsConfig = config.metrics, metricLogger = logger, - metricMirror = mirrorMetricEvent, + metricMirror = async () => null, now = () => new Date(), } = {}) => { const enabled = !!metricsConfig.enabled; diff --git a/server/middlewares/clientAssets.js b/server/middlewares/clientAssets.js index ceb2ab2c..b69e24a4 100644 --- a/server/middlewares/clientAssets.js +++ b/server/middlewares/clientAssets.js @@ -1,12 +1,9 @@ const express = require('express'); const path = require('path'); -const rateLimit = require('express-rate-limit'); -const { apiRateLimitOptions } = require('./apiRateLimit'); -const createClientAssetsRouter = (buildPath, rateLimitOptions = apiRateLimitOptions()) => { +const createClientAssetsRouter = (buildPath) => { const router = express.Router(); - router.use(rateLimit(rateLimitOptions)); router.use(express.static(buildPath)); const indexPath = path.join(buildPath, 'index.html'); diff --git a/server/middlewares/clientAssets.test.js b/server/middlewares/clientAssets.test.js index 4987eb03..9ae0d078 100644 --- a/server/middlewares/clientAssets.test.js +++ b/server/middlewares/clientAssets.test.js @@ -5,7 +5,6 @@ const http = require('http'); const path = require('path'); const express = require('express'); const { createClientAssetsRouter } = require('./clientAssets'); -const { apiRateLimitOptions } = require('./apiRateLimit'); const request = (server) => new Promise((resolve, reject) => { const req = http.request({ @@ -22,15 +21,12 @@ const request = (server) => new Promise((resolve, reject) => { req.end(); }); -describe('client asset rate limiting', () => { +describe('client assets', () => { let server; beforeEach((done) => { const app = express(); - app.use(createClientAssetsRouter( - path.join(__dirname, '../../client'), - apiRateLimitOptions({ limit: 1, windowMs: 60_000 }), - )); + app.use(createClientAssetsRouter(path.join(__dirname, '../../client'))); server = app.listen(0, '127.0.0.1', () => done()); }); @@ -38,14 +34,11 @@ describe('client asset rate limiting', () => { server.close(() => done()); }); - it('serves the client fallback', async () => { + it('serves repeated client fallback requests without API rate limiting', async () => { const response = await request(server); expect(response.status).toBe(200); expect(response.body).toContain(''); - expect(await request(server)).toEqual({ - body: '{"code":"rate_limited","message":"Too many requests. Please try again later."}', - status: 429, - }); + expect((await request(server)).status).toBe(200); }); }); diff --git a/server/middlewares/session.js b/server/middlewares/session.js index 26c901b8..fcf988fb 100644 --- a/server/middlewares/session.js +++ b/server/middlewares/session.js @@ -1,7 +1,7 @@ const session = require('express-session'); -const { default: MongoStore } = require('connect-mongo'); const config = require('../runtimeConfig'); +const PostgresSessionStore = require('../postgres/sessionStore'); module.exports = session({ secret: config.auth.secret, @@ -13,7 +13,5 @@ module.exports = session({ secure: process.env.NODE_ENV === 'prod', sameSite: 'strict', }, - store: MongoStore.create({ - mongoUrl: config.mongodb, - }), + store: new PostgresSessionStore(), }); diff --git a/server/models/index.js b/server/models/index.js index 8c989917..eeb453d8 100644 --- a/server/models/index.js +++ b/server/models/index.js @@ -1,23 +1,27 @@ -const mongoose = require('mongoose'); -const { FriendRelationship, RELATIONSHIP_STATUSES } = require('./friendRelationship'); -const { Attempt, Room } = require('./room'); -const { METRIC_EVENTS, MetricEvent } = require('./metricEvent'); -const SocialNotification = require('./socialNotification'); -const User = require('./user'); -const UserBlock = require('./userBlock'); +if (process.env.NODE_ENV !== 'test') { + module.exports = require('../postgres/sqlModels'); +} else { + const mongoose = require('mongoose'); + const { FriendRelationship, RELATIONSHIP_STATUSES } = require('./friendRelationship'); + const { Attempt, Room } = require('./room'); + const { METRIC_EVENTS, MetricEvent } = require('./metricEvent'); + const SocialNotification = require('./socialNotification'); + const User = require('./user'); + const UserBlock = require('./userBlock'); -module.exports = { - Room: mongoose.model('Room', Room, 'rooms'), - User: mongoose.model('User', User, 'users'), - FriendRelationship: mongoose.model( - 'FriendRelationship', - FriendRelationship, - 'friend_relationships', - ), - UserBlock: mongoose.model('UserBlock', UserBlock, 'user_blocks'), - Attempt: mongoose.model('Attempt', Attempt, 'attempts'), - MetricEvent: mongoose.model('MetricEvent', MetricEvent, 'metric_events'), - SocialNotification: mongoose.model('SocialNotification', SocialNotification, 'social_notifications'), - METRIC_EVENTS, - RELATIONSHIP_STATUSES, -}; + module.exports = { + Room: mongoose.model('Room', Room, 'rooms'), + User: mongoose.model('User', User, 'users'), + FriendRelationship: mongoose.model( + 'FriendRelationship', + FriendRelationship, + 'friend_relationships', + ), + UserBlock: mongoose.model('UserBlock', UserBlock, 'user_blocks'), + Attempt: mongoose.model('Attempt', Attempt, 'attempts'), + MetricEvent: mongoose.model('MetricEvent', MetricEvent, 'metric_events'), + SocialNotification: mongoose.model('SocialNotification', SocialNotification, 'social_notifications'), + METRIC_EVENTS, + RELATIONSHIP_STATUSES, + }; +} diff --git a/server/package.json b/server/package.json index c98d7c27..2c1e3eba 100644 --- a/server/package.json +++ b/server/package.json @@ -5,7 +5,6 @@ "dependencies": { "@socket.io/redis-adapter": "^8.3.0", "bcrypt": "6.0.0", - "connect-mongo": "^6.0.0", "cors": "^2.8.5", "express": "^4.22.2", "express-rate-limit": "^8.2.1", @@ -15,7 +14,6 @@ "letscube-scrambles": "0.1.0", "lodash": "^4.17.21", "lusca": "^1.7.0", - "mongodb": "^6.21.0", "mongoose": "^8.24.1", "morgan": "^1.11.0", "passport": "^0.7.0", @@ -41,6 +39,7 @@ "postgres:migrate:status": "prisma migrate status --config prisma.config.mjs", "postgres:schema:check": "prisma migrate diff --exit-code --from-config-datasource --to-schema prisma/schema.prisma --config prisma.config.mjs", "postgres:schema:validate": "prisma validate --config prisma.config.mjs", + "postgres:migrate-from-mongo": "node postgres/migrateFromMongo.js", "privacy:purge-user-emails": "node privacy/purgeUserEmails.js", "usernames:backfill": "node ../scripts/backfill-normalized-usernames.js", "test": "jest --passWithNoTests", diff --git a/server/postgres/index.js b/server/postgres/index.js index 47242f4a..11f520e9 100644 --- a/server/postgres/index.js +++ b/server/postgres/index.js @@ -4,6 +4,9 @@ const config = require('../runtimeConfig'); const logger = require('../logger'); const RETRY_DELAY_MS = 30 * 1000; +const MAINTENANCE_INTERVAL_MS = 60 * 60 * 1000; +const SESSION_CLEANUP_BATCH_SIZE = 10_000; +const SESSION_CLEANUP_MAX_BATCHES = 100; const poolConfig = config.postgres.connectionString ? { connectionString: config.postgres.connectionString } @@ -36,6 +39,7 @@ pool.on('error', (err) => { let initialized = false; let initializationPromise; let lastFailureAt = 0; +let maintenancePromise; const initializePostgres = async () => { if (!config.postgres.enabled) { @@ -109,17 +113,67 @@ const deleteExpiredMetrics = () => query( 'DELETE FROM analytics.events WHERE expires_at <= now()', ); +const deleteExpiredSessions = async () => { + let deleted = 0; + + for (let batch = 0; batch < SESSION_CLEANUP_MAX_BATCHES; batch += 1) { + // Small transactions keep cleanup from holding one large table lock when + // a server starts with a large expired-session backlog. + const result = await query(` + WITH expired AS ( + SELECT sid + FROM app.sessions + WHERE expire <= now() + ORDER BY expire + LIMIT $1 + FOR UPDATE SKIP LOCKED + ) + DELETE FROM app.sessions AS sessions + USING expired + WHERE sessions.sid = expired.sid + `, [SESSION_CLEANUP_BATCH_SIZE]); + + if (!result) { + return deleted; + } + + deleted += result.rowCount; + if (result.rowCount < SESSION_CLEANUP_BATCH_SIZE) { + return deleted; + } + } + + return deleted; +}; + +const runPostgresMaintenance = () => { + if (maintenancePromise) { + return maintenancePromise; + } + + maintenancePromise = Promise.all([ + deleteExpiredMetrics(), + deleteExpiredSessions(), + ]).finally(() => { + maintenancePromise = undefined; + }); + + return maintenancePromise; +}; + const startPostgresMaintenance = () => { - deleteExpiredMetrics(); - const timer = setInterval(deleteExpiredMetrics, 6 * 60 * 60 * 1000); + runPostgresMaintenance(); + const timer = setInterval(runPostgresMaintenance, MAINTENANCE_INTERVAL_MS); timer.unref(); }; module.exports = { deleteExpiredMetrics, + deleteExpiredSessions, initializePostgres, pool, query, + runPostgresMaintenance, startPostgresMaintenance, withTransaction, }; diff --git a/server/postgres/index.test.js b/server/postgres/index.test.js new file mode 100644 index 00000000..ce3e26da --- /dev/null +++ b/server/postgres/index.test.js @@ -0,0 +1,46 @@ +/** @jest-environment node */ +/* eslint-env jest */ + +const mockQuery = jest.fn(); +const mockOn = jest.fn(); + +jest.mock('pg', () => ({ + Pool: jest.fn(() => ({ + on: mockOn, + query: mockQuery, + })), +})); +jest.mock('../runtimeConfig', () => ({ + postgres: { + enabled: true, + connectionString: 'postgres://test', + ssl: false, + }, +})); +jest.mock('../logger', () => ({ + error: jest.fn(), + info: jest.fn(), +})); + +const { deleteExpiredSessions } = require('./index'); + +describe('PostgreSQL maintenance', () => { + beforeEach(() => { + jest.clearAllMocks(); + mockQuery.mockResolvedValueOnce({ rows: [{ '?column?': 1 }] }); + }); + + it('deletes expired sessions in bounded batches until the backlog is clear', async () => { + mockQuery + .mockResolvedValueOnce({ rowCount: 10_000 }) + .mockResolvedValueOnce({ rowCount: 4 }); + + await expect(deleteExpiredSessions()).resolves.toBe(10_004); + + expect(mockQuery).toHaveBeenCalledTimes(3); + expect(mockQuery.mock.calls[1][0]).toContain('WHERE expire <= now()'); + expect(mockQuery.mock.calls[1][0]).toContain('LIMIT $1'); + expect(mockQuery.mock.calls[1][0]).toContain('FOR UPDATE SKIP LOCKED'); + expect(mockQuery.mock.calls[1][1]).toEqual([10_000]); + }); +}); diff --git a/server/postgres/migrateFromMongo.js b/server/postgres/migrateFromMongo.js new file mode 100644 index 00000000..be5f4609 --- /dev/null +++ b/server/postgres/migrateFromMongo.js @@ -0,0 +1,122 @@ +// One-time cutover tool. It is intentionally kept separate from the runtime: +// production processes never load the MongoDB connection or models. +process.env.NODE_ENV = 'test'; + +const mongoose = require('mongoose'); +const database = require('../database'); +const { initializePostgres, pool } = require('./index'); +const { + mirrorBlock, + mirrorMetricEvent, + mirrorNotification, + mirrorRelationship, + mirrorRoom, + mirrorUser, +} = require('./dualWrite'); +const { + Room, + User, + FriendRelationship, + UserBlock, + MetricEvent, + SocialNotification, +} = require('../models'); + +const apply = process.argv.includes('--apply'); + +const countDocuments = async (model) => model.countDocuments(); + +const copy = async (label, model, writer, transform = (value) => value, sourceQuery = model.find()) => { + const count = await countDocuments(model); + process.stdout.write(`${label}: ${count} source records${apply ? '' : ' (dry run)'}\n`); + if (!apply) return count; + + const cursor = sourceQuery.cursor(); + let copied = 0; + for await (const value of cursor) { + await writer(transform(value)); + copied += 1; + } + process.stdout.write(`${label}: copied ${copied}\n`); + return copied; +}; + +const copyRelationships = async () => { + const count = await countDocuments(FriendRelationship); + process.stdout.write(`friend relationships: ${count} source records${apply ? '' : ' (dry run)'}\n`); + if (!apply) return count; + const cursor = FriendRelationship.find().cursor(); + for await (const relationship of cursor) { + const users = await User.find({ id: { $in: [relationship.lowUserId, relationship.highUserId, relationship.requestedBy].filter(Boolean) } }); + await mirrorRelationship(relationship, users); + } + return count; +}; + +const copyBlocks = async () => { + const count = await countDocuments(UserBlock); + process.stdout.write(`user blocks: ${count} source records${apply ? '' : ' (dry run)'}\n`); + if (!apply) return count; + const cursor = UserBlock.find().cursor(); + for await (const block of cursor) { + const [blocker, blocked] = await Promise.all([ + User.findOne({ id: block.blockerId }), + User.findOne({ id: block.blockedId }), + ]); + await mirrorBlock(block, blocker, blocked); + } + return count; +}; + +const copyMetrics = async () => copy( + 'metrics', + MetricEvent, + mirrorMetricEvent, + (event) => ({ + ...event.toObject(), + event: event.event, + }), +); + +const copyNotifications = async () => copy( + 'notifications', + SocialNotification, + mirrorNotification, + (notification) => notification.toObject(), +); + +const run = async () => { + if (!(await initializePostgres())) throw new Error('PostgreSQL is unavailable'); + await database.connect(); + + try { + const summary = { + users: await copy('users', User, mirrorUser), + rooms: await copy( + 'rooms', + Room, + mirrorRoom, + (room) => room, + Room.find().populate('users').populate('admin').populate('owner'), + ), + relationships: await copyRelationships(), + blocks: await copyBlocks(), + notifications: await copyNotifications(), + metrics: await copyMetrics(), + }; + process.stdout.write(`MongoDB session records are intentionally not copied; all sessions must re-authenticate after cutover.\n`); + return summary; + } finally { + await mongoose.disconnect(); + await pool.end(); + } +}; + +if (require.main === module) { + run().catch((error) => { + process.stderr.write(`${error.stack || error}\n`); + process.exitCode = 1; + }); +} + +module.exports = { run }; diff --git a/server/postgres/sessionStore.js b/server/postgres/sessionStore.js new file mode 100644 index 00000000..9ff6a016 --- /dev/null +++ b/server/postgres/sessionStore.js @@ -0,0 +1,55 @@ +const session = require('express-session'); +const { pool } = require('./index'); + +class PostgresSessionStore extends session.Store { + constructor({ sessionPool = pool } = {}) { + super(); + this.pool = sessionPool; + } + + get(sid, callback) { + this.pool.query( + 'SELECT sess FROM app.sessions WHERE sid = $1 AND expire > now()', + [sid], + ).then(({ rows }) => callback(null, rows[0] ? rows[0].sess : null)).catch(callback); + } + + set(sid, sess, callback = () => {}) { + const expire = sess.cookie && sess.cookie.expires + ? new Date(sess.cookie.expires) + : new Date(Date.now() + 24 * 60 * 60 * 1000); + this.pool.query(` + INSERT INTO app.sessions (sid, sess, expire) + VALUES ($1, $2::jsonb, $3) + ON CONFLICT (sid) DO UPDATE SET sess = EXCLUDED.sess, expire = EXCLUDED.expire + `, [sid, JSON.stringify(sess), expire]).then(() => callback()).catch(callback); + } + + destroy(sid, callback = () => {}) { + this.pool.query('DELETE FROM app.sessions WHERE sid = $1', [sid]) + .then(() => callback()).catch(callback); + } + + touch(sid, sess, callback = () => {}) { + const expire = sess.cookie && sess.cookie.expires + ? new Date(sess.cookie.expires) + : new Date(Date.now() + 24 * 60 * 60 * 1000); + this.pool.query('UPDATE app.sessions SET expire = $2 WHERE sid = $1', [sid, expire]) + .then(() => callback()).catch(callback); + } + + clear(callback = () => {}) { + this.pool.query('DELETE FROM app.sessions').then(() => callback()).catch(callback); + } + + length(callback) { + this.pool.query('SELECT count(*)::integer AS count FROM app.sessions') + .then(({ rows }) => callback(null, rows[0].count)).catch(callback); + } + + clearExpired() { + return this.pool.query('DELETE FROM app.sessions WHERE expire <= now()'); + } +} + +module.exports = PostgresSessionStore; diff --git a/server/postgres/sqlModels.js b/server/postgres/sqlModels.js new file mode 100644 index 00000000..d791c51b --- /dev/null +++ b/server/postgres/sqlModels.js @@ -0,0 +1,110 @@ +const User = require('./sqlUserModel'); +const { Room } = require('./sqlRoomModel'); +const { + FriendRelationship, + RELATIONSHIP_STATUSES, + SocialNotification, + UserBlock, +} = require('./sqlSocialModels'); +const { pool } = require('./index'); + +const metricRow = (row) => row && ({ + _id: row.id, + id: row.id, + ...row.properties, + event: row.event_name, + occurredAt: row.occurred_at, + expiresAt: row.expires_at, +}); + +const metricWhere = (criteria, values) => { + const clauses = []; + const fields = { event: 'event_name', eventName: 'event_name' }; + Object.entries(fields).forEach(([key, column]) => { + if (criteria[key] !== undefined) { + values.push(criteria[key]); + clauses.push(`${column} = $${values.length}`); + } + }); + [['actorId', 'actorId'], ['roomId', 'roomId']].forEach(([key, property]) => { + if (criteria[key] !== undefined) { + values.push(String(criteria[key])); + clauses.push(`properties->>'${property}' = $${values.length}`); + } + }); + if (criteria.active !== undefined) { + values.push(!!criteria.active); + clauses.push(`COALESCE((properties->>'active')::boolean, false) = $${values.length}`); + } + return clauses.length ? clauses.join(' AND ') : 'TRUE'; +}; + +const MetricEvent = { + create: async (event) => { + const { rows } = await pool.query(` + INSERT INTO analytics.events (id, event_name, occurred_at, actor_id, room_id, properties, expires_at) + VALUES ($1, $2, $3, $4, $5, $6::jsonb, $7) + ON CONFLICT (id) DO NOTHING + RETURNING * + `, [event.eventId, event.event, event.occurredAt, event.actorId || null, event.roomId || null, + JSON.stringify({ ...event }), event.expiresAt]); + return rows[0] || null; + }, + findOne: async (criteria) => { + const values = []; + const { rows } = await pool.query(` + SELECT * FROM analytics.events WHERE ${metricWhere(criteria, values)} + ORDER BY occurred_at DESC, id DESC LIMIT 1 + `, values); + return metricRow(rows[0]); + }, + findOneAndUpdate: async (criteria, update) => { + const values = []; + const where = metricWhere(criteria, values); + const patch = JSON.stringify(update.$set || {}); + values.push(patch); + const { rows } = await pool.query(` + WITH target AS ( + SELECT id FROM analytics.events WHERE ${where} + ORDER BY occurred_at DESC, id DESC LIMIT 1 + ) + UPDATE analytics.events e + SET properties = e.properties || $${values.length}::jsonb + FROM target WHERE e.id = target.id + RETURNING e.* + `, values); + return metricRow(rows[0]); + }, + updateMany: async (criteria, update) => { + const values = []; + const where = metricWhere(criteria, values); + values.push(JSON.stringify(update.$set || {})); + const result = await pool.query(` + UPDATE analytics.events SET properties = properties || $${values.length}::jsonb + WHERE ${where} + `, values); + return { modifiedCount: result.rowCount }; + }, +}; + +const METRIC_EVENTS = Object.freeze({ + AUTH_FAILED: 'auth_failed', + ROOM_CREATED: 'room_created', + ROOM_JOINED: 'room_joined', + ROOM_JOIN_FAILED: 'room_join_failed', + ROOM_LEFT: 'room_left', + ROOM_RESULT_SUBMITTED: 'room_result_submitted', + SOLVE_HISTORY_REQUESTED: 'solve_history_requested', + SOCIAL_ACTION: 'social_action', +}); + +module.exports = { + Room, + User, + FriendRelationship, + UserBlock, + SocialNotification, + RELATIONSHIP_STATUSES, + MetricEvent, + METRIC_EVENTS, +}; diff --git a/server/postgres/sqlQuery.js b/server/postgres/sqlQuery.js new file mode 100644 index 00000000..8a8e8033 --- /dev/null +++ b/server/postgres/sqlQuery.js @@ -0,0 +1,46 @@ +class SqlQuery { + constructor(executor) { + this.executor = executor; + this.options = {}; + this.promise = null; + } + + exec() { + if (!this.promise) { + this.promise = this.executor(this.options); + } + return this.promise; + } + + then(resolve, reject) { + return this.exec().then(resolve, reject); + } + + catch(reject) { + return this.exec().catch(reject); + } + + finally(callback) { + return this.exec().finally(callback); + } + + lean() { + return this; + } + + populate() { + return this; + } + + sort(sort) { + this.options.sort = sort; + return this; + } + + limit(limit) { + this.options.limit = limit; + return this; + } +} + +module.exports = SqlQuery; diff --git a/server/postgres/sqlRoomModel.js b/server/postgres/sqlRoomModel.js new file mode 100644 index 00000000..3f04027f --- /dev/null +++ b/server/postgres/sqlRoomModel.js @@ -0,0 +1,479 @@ +const bcrypt = require('bcrypt'); +const { v4: uuidv4 } = require('uuid'); +const { generateScramble } = require('letscube-scrambles'); +const { pool } = require('./index'); +const { stableId } = require('./dualWrite'); +const { toUser } = require('./userRepository'); +const SqlQuery = require('./sqlQuery'); +const { LruCache } = require('../cache/lru'); + +const STALE_ROOM_LIFETIME_MS = 10 * 60 * 1000; +const roomCache = new LruCache({ + maxBytes: 128 * 1024 * 1024, + ttlMs: 60 * 1000, + estimateSize: (room) => Buffer.byteLength(JSON.stringify({ + id: room._id, + users: room.users, + attempts: room.attempts.map((attempt) => ({ + id: attempt._id, + scrambles: attempt.scrambles, + results: [...(attempt.results instanceof Map + ? attempt.results.entries() : Object.entries(attempt.results || {}))], + })), + event: room.event, + })), +}); + +const boolMap = (entries = []) => new Map(entries.map((entry) => [String(entry.userId), !!entry.value])); +const sameUser = (left, right) => left && right && String(left.id) === String(right.id); + +const selectRoomAdmin = ({ usersInRoom, owner, admin }) => { + if (!usersInRoom.length) return null; + return usersInRoom.find((user) => sameUser(user, owner)) + || usersInRoom.find((user) => sameUser(user, admin)) + || usersInRoom[0]; +}; + +const userRow = (row, prefix = '') => ({ + id: row[`${prefix}user_id`], + wca_user_id: row[`${prefix}wca_user_id`], + name: row[`${prefix}name`], + username: row[`${prefix}username`], + username_normalized: row[`${prefix}username_normalized`], + wca_id: row[`${prefix}wca_id`], + preferences: row[`${prefix}preferences`], + avatar: row[`${prefix}avatar`], +}); + +const readUser = (row) => (row && row.wca_user_id !== null ? toUser(row) : null); + +const externalRoomId = (value) => String(value && value._id !== undefined ? value._id : value); +const internalRoomId = (roomId) => stableId('room', externalRoomId(roomId)); + +const roomRowSql = (condition) => ` + SELECT r.*, + ou.wca_user_id AS owner_wca_user_id, ou.name AS owner_name, + ou.username AS owner_username, ou.username_normalized AS owner_username_normalized, + ou.wca_id AS owner_wca_id, ou.preferences AS owner_preferences, ou.avatar AS owner_avatar, + au.wca_user_id AS admin_wca_user_id, au.name AS admin_name, + au.username AS admin_username, au.username_normalized AS admin_username_normalized, + au.wca_id AS admin_wca_id, au.preferences AS admin_preferences, au.avatar AS admin_avatar + FROM app.rooms r + LEFT JOIN app.users ou ON ou.id = r.owner_id + LEFT JOIN app.users au ON au.id = r.admin_id + WHERE ${condition} +`; + +const readRoom = async (id, { includeDeleted = false } = {}) => { + const values = [externalRoomId(id), internalRoomId(id)]; + const deletedCondition = includeDeleted + ? '' + : ' AND r.deleted_at IS NULL AND (r.expires_at IS NULL OR r.expires_at > now())'; + const roomResult = await pool.query(`${roomRowSql(`(r.mongo_id = $1 OR r.id = $2)${deletedCondition}`)} LIMIT 1`, values); + const row = roomResult.rows[0]; + if (!row) return null; + + const [participants, sessionResult] = await Promise.all([ + pool.query(` + SELECT rp.*, u.id AS user_id, u.wca_user_id, u.name, u.username, + u.username_normalized, u.wca_id, u.preferences, u.avatar + FROM app.room_participants rp + JOIN app.users u ON u.id = rp.user_id + WHERE rp.room_id = $1 + ORDER BY u.wca_user_id + `, [row.id]), + pool.query(` + SELECT * FROM app.race_sessions + WHERE room_id = $1 AND status NOT IN ('ended', 'cancelled') + ORDER BY source_updated_at DESC LIMIT 1 + `, [row.id]), + ]); + const session = sessionResult.rows[0] || null; + const attemptResult = session + ? await pool.query(` + SELECT a.*, s.user_id AS solve_user_id, u.wca_user_id AS solve_wca_user_id, + s.time_ms, s.dnf, s.plus_two_penalty, s.inspection_penalty, s.auf_penalty, + s.submission_id, s.source_created_at AS solve_created_at + FROM app.attempts a + LEFT JOIN app.solves s ON s.attempt_id = a.id AND s.room_id = a.room_id + LEFT JOIN app.users u ON u.id = s.user_id + WHERE a.room_id = $1 AND a.race_session_id = $2 + ORDER BY a.ordinal, s.user_id + `, [row.id, session.id]) + : { rows: [] }; + + const users = participants.rows.map((participant) => readUser(userRow(participant))); + const attemptsById = new Map(); + attemptResult.rows.forEach((attemptRow) => { + let attempt = attemptsById.get(attemptRow.id); + if (!attempt) { + attempt = { + _id: attemptRow.mongo_id, + id: attemptRow.ordinal, + scrambles: attemptRow.scrambles, + results: new Map(), + createdAt: attemptRow.source_created_at, + }; + attemptsById.set(attemptRow.id, attempt); + } + if (attemptRow.solve_wca_user_id !== null) { + attempt.results.set(String(attemptRow.solve_wca_user_id), { + time: attemptRow.time_ms, + penalties: { + DNF: !!attemptRow.dnf, + AUF: !!attemptRow.auf_penalty, + inspection: !!attemptRow.inspection_penalty, + ...(attemptRow.plus_two_penalty ? { plusTwo: true } : {}), + }, + ...(attemptRow.submission_id ? { submissionId: attemptRow.submission_id } : {}), + ...(attemptRow.solve_created_at ? { createdAt: attemptRow.solve_created_at } : {}), + }); + } + }); + + const participantValues = participants.rows.map((participant) => ({ + userId: participant.wca_user_id, + value: participant.in_room, + })); + const room = new RoomDocument({ + _id: row.mongo_id, + id: row.id, + name: row.name, + event: session ? session.cube_event : row.cube_event, + accessCode: row.access_code, + password: row.password_hash, + attempts: [...attemptsById.values()], + users, + waitingFor: boolMap(participants.rows.map((p) => ({ userId: p.wca_user_id, value: p.waiting_for }))), + competing: boolMap(participants.rows.map((p) => ({ userId: p.wca_user_id, value: p.competing }))), + banned: boolMap(participants.rows.map((p) => ({ userId: p.wca_user_id, value: p.banned }))), + inRoom: boolMap(participantValues), + registered: boolMap(participants.rows.map((p) => ({ userId: p.wca_user_id, value: p.registered }))), + presenceRevision: new Map(participants.rows.map((p) => [String(p.wca_user_id), p.presence_revision || 0])), + membershipRevision: row.membership_revision || 0, + admin: readUser(userRow({ + user_id: row.admin_id, + wca_user_id: row.admin_wca_user_id, + name: row.admin_name, + username: row.admin_username, + username_normalized: row.admin_username_normalized, + wca_id: row.admin_wca_id, + preferences: row.admin_preferences, + avatar: row.admin_avatar, + })), + owner: readUser(userRow({ + user_id: row.owner_id, + wca_user_id: row.owner_wca_user_id, + name: row.owner_name, + username: row.owner_username, + username_normalized: row.owner_username_normalized, + wca_id: row.owner_wca_id, + preferences: row.owner_preferences, + avatar: row.owner_avatar, + })), + type: row.room_type, + requireRevealedIdentity: row.require_revealed_identity, + startTime: row.start_time, + started: row.started, + nextSolveAt: session ? session.next_solve_at : row.next_solve_at, + expireAt: row.expires_at, + twitchChannel: row.twitch_channel, + _raceSessionId: session && session.id, + _createdAt: row.source_created_at, + _updatedAt: row.source_updated_at, + }); + return room; +}; + +const loadRoom = async (id, options = {}) => { + const key = externalRoomId(id); + if (!options.includeDeleted) { + const cached = roomCache.get(key); + if (cached && (!cached.expireAt || new Date(cached.expireAt) > new Date())) return cached; + } + const room = await readRoom(id, options); + if (room && !options.includeDeleted) roomCache.set(key, room); + return room; +}; + +class RoomDocument { + constructor(values = {}) { + Object.assign(this, values); + this._id = this._id || uuidv4(); + this.id = this.id || this._id; + this.event = this.event || '333'; + this.accessCode = this.accessCode || uuidv4(); + this.type = this.type || 'normal'; + this.users = this.users || []; + this.attempts = this.attempts || []; + this.waitingFor = this.waitingFor || new Map(); + this.competing = this.competing || new Map(); + this.banned = this.banned || new Map(); + this.inRoom = this.inRoom || new Map(); + this.registered = this.registered || new Map(); + this.presenceRevision = this.presenceRevision || new Map(); + this.membershipRevision = this.membershipRevision || 0; + } + + get usersInRoom() { return this.users.filter((user) => this.inRoom.get(String(user.id))); } + get usersLength() { return this.usersInRoom.length; } + get private() { return !!this.password; } + get waitingForCount() { return [...this.waitingFor.values()].filter(Boolean).length; } + get latestAttempt() { return this.attempts[this.attempts.length - 1]; } + + toObject() { return { ...this }; } + + async save() { + await saveRoom(this); + return this; + } + + async authenticate(password) { + return !!this.password && bcrypt.compare(password, this.password); + } + + async genAttempt() { + return { + _id: uuidv4(), + id: this.attempts.length, + scrambles: [await generateScramble(this.event)], + results: new Map(), + }; + } + + async newAttempt() { + const attempt = await this.genAttempt(); + this.attempts.push(attempt); + this.usersInRoom.forEach((user) => this.waitingFor.set(String(user.id), !!this.competing.get(String(user.id)))); + return this.save(); + } + + async addUser(user, spectating) { + const key = String(user.id); + if (this.inRoom.get(key)) return false; + if (!this.users.some((candidate) => String(candidate.id) === key)) { + this.users.push(user); + this.competing.set(key, this.type === 'normal'); + } else if (spectating) { + this.competing.set(key, false); + } + this.inRoom.set(key, true); + this.membershipRevision += 1; + this.presenceRevision.set(key, (this.presenceRevision.get(key) || 0) + 1); + if (!this.waitingForCount) this.waitingFor.set(key, true); + if (this.type !== 'grand_prix' && (!this.attempts.length || this.latestAttempt.results.size > 0)) { + await this.newAttempt(); + } + this.expireAt = null; + return this.save(); + } + + async dropUser(user) { + const key = String(user.id); + this.inRoom.set(key, false); + this.waitingFor.set(key, false); + this.membershipRevision += 1; + this.presenceRevision.set(key, (this.presenceRevision.get(key) || 0) + 1); + this.admin = selectRoomAdmin(this); + if (!this.usersInRoom.length) { + this.expireAt = new Date(Date.now() + STALE_ROOM_LIFETIME_MS); + } + return this.save(); + } + + async dropUserAtomically(user, expectedMembershipRevision, expectedPresenceRevision) { + const key = String(user.id); + if (!this.inRoom.get(key) + || (expectedMembershipRevision !== undefined && expectedMembershipRevision !== this.membershipRevision) + || (expectedPresenceRevision !== undefined && expectedPresenceRevision !== this.presenceRevision.get(key))) { + return null; + } + const previousAdmin = this.admin; + const room = await this.dropUser(user); + return { room, adminChanged: !sameUser(previousAdmin, room.admin) }; + } + + async advancePresenceRevision(userId) { + const key = String(userId); + if (!this.inRoom.get(key)) return null; + this.presenceRevision.set(key, (this.presenceRevision.get(key) || 0) + 1); + return this.save(); + } + + async banUser(userId) { this.banned.set(String(userId), true); return this.dropUser({ id: userId }); } + async unbanUser(userId) { this.banned.set(String(userId), false); return this.save(); } + async updateRegistration(userId, value) { this.registered.set(String(userId), !!value); return this.save(); } + async start() { this.started = true; this.users.forEach((u) => { if (this.registered.get(String(u.id))) this.competing.set(String(u.id), true); }); return this.save(); } + async pause() { this.started = false; this.nextSolveAt = null; return this.save(); } + async updateStale(stale) { this.expireAt = stale ? new Date(Date.now() + STALE_ROOM_LIFETIME_MS) : null; return this.save(); } + doneWithScramble() { + if (this.type === 'grand_prix' || !this.latestAttempt) return false; + if (!this.usersInRoom.some((user) => this.latestAttempt.results.get(String(user.id)))) return false; + return (this.waitingForCount === 0 || !this.attempts.length) && this.usersInRoom.length > 0; + } + async changeEvent(event) { this.event = event; this.attempts = []; this._raceSessionId = null; return this.newAttempt(); } + async edit(options) { + const unchanged = !!this.password && options.password === this.accessCode; + if (options.private && !this.password && !options.password) throw Object.assign(new Error('A password is required to make a room private'), { statusCode: 400 }); + this.name = options.name; + if (options.private && options.password && !unchanged) this.password = await bcrypt.hash(options.password, 10); + if (!options.private) this.password = null; + this.type = options.type; + this.requireRevealedIdentity = options.requireRevealedIdentity; + this.startTime = options.startTime; + return this.save(); + } + async updateAdminIfNeeded(callback) { + const next = selectRoomAdmin(this); + if (sameUser(this.admin, next) || (!this.admin && !next)) return this; + this.admin = next; + const room = await this.save(); + if (callback && room.admin) callback(room); + return room; + } +} + +const saveRoom = async (room) => { + const client = await pool.connect(); + const now = new Date(); + const roomUuid = internalRoomId(room._id); + const ownerId = room.owner ? stableId('user', room.owner.id) : null; + const adminId = room.admin ? stableId('user', room.admin.id) : null; + const sessionId = room._raceSessionId || stableId('race-session', `${room._id}:${room.event}`); + try { + await client.query('BEGIN'); + await client.query(` + INSERT INTO app.rooms ( + id, mongo_id, name, cube_event, access_code, password_hash, room_type, + owner_id, admin_id, require_revealed_identity, start_time, started, + next_solve_at, expires_at, twitch_channel, source_created_at, source_updated_at, + membership_revision + ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18) + ON CONFLICT (id) DO UPDATE SET + name = EXCLUDED.name, cube_event = EXCLUDED.cube_event, access_code = EXCLUDED.access_code, + password_hash = EXCLUDED.password_hash, room_type = EXCLUDED.room_type, + owner_id = EXCLUDED.owner_id, admin_id = EXCLUDED.admin_id, + require_revealed_identity = EXCLUDED.require_revealed_identity, start_time = EXCLUDED.start_time, + started = EXCLUDED.started, next_solve_at = EXCLUDED.next_solve_at, + expires_at = EXCLUDED.expires_at, twitch_channel = EXCLUDED.twitch_channel, + source_updated_at = EXCLUDED.source_updated_at, membership_revision = EXCLUDED.membership_revision, + ingested_at = now() + `, [roomUuid, room._id, room.name, room.event || '333', room.accessCode, room.password || null, + room.type || 'normal', ownerId, adminId, !!room.requireRevealedIdentity, room.startTime || null, + !!room.started, room.nextSolveAt || null, room.expireAt || null, room.twitchChannel || null, + room._createdAt || now, now, room.membershipRevision || 0]); + + await client.query(` + INSERT INTO app.race_sessions ( + id, room_id, cube_event, race_format, scramble_source, status, scheduled_start_at, + started_at, current_attempt_ordinal, next_solve_at, source_key, source_created_at, source_updated_at + ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) + ON CONFLICT (id) DO UPDATE SET cube_event = EXCLUDED.cube_event, + status = EXCLUDED.status, scheduled_start_at = EXCLUDED.scheduled_start_at, + started_at = COALESCE(app.race_sessions.started_at, EXCLUDED.started_at), + current_attempt_ordinal = EXCLUDED.current_attempt_ordinal, + next_solve_at = EXCLUDED.next_solve_at, source_updated_at = EXCLUDED.source_updated_at, + ingested_at = now() + `, [sessionId, roomUuid, room.event || '333', room.type === 'grand_prix' ? 'grand_prix' : 'normal', + 'letscube', room.started ? 'racing' : 'ready', room.startTime || null, room.started ? now : null, + room.latestAttempt ? room.latestAttempt.id : null, room.nextSolveAt || null, + `runtime:${room._id}:${room.event}`, room._createdAt || now, now]); + + for (const user of room.users) { + const key = String(user.id); + await client.query(` + INSERT INTO app.room_participants ( + room_id, user_id, competing, waiting_for, banned, in_room, registered, + presence_revision, source_updated_at + ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) + ON CONFLICT (room_id, user_id) DO UPDATE SET competing = EXCLUDED.competing, + waiting_for = EXCLUDED.waiting_for, banned = EXCLUDED.banned, in_room = EXCLUDED.in_room, + registered = EXCLUDED.registered, presence_revision = EXCLUDED.presence_revision, + source_updated_at = EXCLUDED.source_updated_at, ingested_at = now() + `, [roomUuid, stableId('user', user.id), !!room.competing.get(key), !!room.waitingFor.get(key), + !!room.banned.get(key), !!room.inRoom.get(key), !!room.registered.get(key), + room.presenceRevision.get(key) || 0, now]); + + await client.query(` + INSERT INTO app.session_participants ( + race_session_id, user_id, eligible, competing, waiting_for, registered, source_updated_at + ) VALUES ($1, $2, $3, $4, $5, $6, $7) + ON CONFLICT (race_session_id, user_id) DO UPDATE SET eligible = EXCLUDED.eligible, + competing = EXCLUDED.competing, waiting_for = EXCLUDED.waiting_for, + registered = EXCLUDED.registered, source_updated_at = EXCLUDED.source_updated_at, + ingested_at = now() + `, [sessionId, stableId('user', user.id), !room.banned.get(key), !!room.competing.get(key), + !!room.waitingFor.get(key), !!room.registered.get(key), now]); + } + + for (const attempt of room.attempts) { + const attemptId = stableId('attempt', attempt._id || `${room._id}:${room.event}:${attempt.id}`); + await client.query(` + INSERT INTO app.attempts ( + id, mongo_id, room_id, race_session_id, ordinal, cube_event, scrambles, + source_created_at, source_updated_at + ) VALUES ($1, $2, $3, $4, $5, $6, $7::jsonb, $8, $9) + ON CONFLICT (id) DO UPDATE SET scrambles = EXCLUDED.scrambles, + source_updated_at = EXCLUDED.source_updated_at, ingested_at = now() + `, [attemptId, attempt._id || `${room._id}:${room.event}:${attempt.id}`, roomUuid, sessionId, + attempt.id, room.event || '333', JSON.stringify(attempt.scrambles || []), attempt.createdAt || now, now]); + + for (const [userId, result] of (attempt.results instanceof Map ? attempt.results.entries() : Object.entries(attempt.results || {}))) { + const solveId = stableId('solve', `${attempt._id || attempt.id}:${userId}`); + const penalties = result.penalties || {}; + await client.query(` + INSERT INTO app.solves ( + id, attempt_id, room_id, user_id, time_ms, dnf, plus_two_penalty, + inspection_penalty, auf_penalty, submission_id, source_created_at, source_updated_at + ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) + ON CONFLICT (id) DO UPDATE SET time_ms = EXCLUDED.time_ms, dnf = EXCLUDED.dnf, + plus_two_penalty = EXCLUDED.plus_two_penalty, inspection_penalty = EXCLUDED.inspection_penalty, + auf_penalty = EXCLUDED.auf_penalty, submission_id = EXCLUDED.submission_id, + source_updated_at = EXCLUDED.source_updated_at, ingested_at = now() + `, [solveId, attemptId, roomUuid, stableId('user', userId), Math.round(result.time), + !!penalties.DNF, !!penalties.plusTwo, !!penalties.inspection, !!penalties.AUF, + result.submissionId || null, result.createdAt || now, now]); + } + } + await client.query('COMMIT'); + room.id = roomUuid; + room._raceSessionId = sessionId; + room._updatedAt = now; + roomCache.set(externalRoomId(room._id), room); + return room; + } catch (error) { + await client.query('ROLLBACK').catch(() => {}); + throw error; + } finally { + client.release(); + } +}; + +const find = (criteria = {}) => new SqlQuery(async () => { + const conditions = ['r.deleted_at IS NULL', '(r.expires_at IS NULL OR r.expires_at > now())']; + const values = []; + if (criteria.type) { values.push(criteria.type); conditions.push(`r.room_type = $${values.length}`); } + const result = await pool.query(`${roomRowSql(conditions.join(' AND '))} ORDER BY r.source_updated_at DESC`, values); + return Promise.all(result.rows.map((row) => loadRoom(row.mongo_id))); +}); + +const findById = (id) => new SqlQuery(() => loadRoom(id)); + +const deleteOne = async (criteria) => { + const id = externalRoomId(criteria._id || criteria.id); + const result = await pool.query(` + UPDATE app.rooms SET deleted_at = now(), expires_at = NULL, ingested_at = now() + WHERE mongo_id = $1 AND deleted_at IS NULL + `, [id]); + roomCache.delete(id); + return { deletedCount: result.rowCount }; +}; + +const Room = RoomDocument; +Room.find = find; +Room.findById = findById; +Room.deleteOne = deleteOne; +Room.isSqlRepository = true; +Room.cache = roomCache; + +module.exports = { Room, RoomDocument, find, findById, loadRoom, saveRoom, selectRoomAdmin }; diff --git a/server/postgres/sqlSocialModels.js b/server/postgres/sqlSocialModels.js new file mode 100644 index 00000000..da608ac5 --- /dev/null +++ b/server/postgres/sqlSocialModels.js @@ -0,0 +1,273 @@ +const { v4: uuidv4 } = require('uuid'); +const { pool } = require('./index'); +const { stableId } = require('./dualWrite'); +const SqlQuery = require('./sqlQuery'); + +const RELATIONSHIP_STATUSES = Object.freeze({ + ACCEPTED: 'accepted', CANCELED: 'canceled', DECLINED: 'declined', + PENDING: 'pending', REMOVED: 'removed', +}); + +const userId = (value) => stableId('user', value); +const relationshipRow = (row) => row && ({ + _id: row.id, + pairKey: row.pair_key, + lowUserId: Number(row.low_wca_user_id || row.low_user_id), + highUserId: Number(row.high_wca_user_id || row.high_user_id), + status: row.status, + requestedBy: row.requested_by_wca_user_id === null || row.requested_by_wca_user_id === undefined + ? undefined : Number(row.requested_by_wca_user_id), + cooldownUntil: row.cooldown_until, + revision: row.revision, + stateChangedAt: row.state_changed_at, + createdAt: row.source_created_at, + updatedAt: row.source_updated_at, +}); + +const blockRow = (row) => row && ({ + _id: row.id, + blockerId: Number(row.blocker_wca_user_id || row.blocker_id), + blockedId: Number(row.blocked_wca_user_id || row.blocked_id), + pairKey: row.pair_key, + active: row.active, + revision: row.revision, + stateChangedAt: row.state_changed_at, + createdAt: row.source_created_at, + updatedAt: row.source_updated_at, +}); + +const relationshipSelect = ` + SELECT fr.*, low.wca_user_id AS low_wca_user_id, high.wca_user_id AS high_wca_user_id, + req.wca_user_id AS requested_by_wca_user_id + FROM app.friend_relationships fr + JOIN app.users low ON low.id = fr.low_user_id + JOIN app.users high ON high.id = fr.high_user_id + LEFT JOIN app.users req ON req.id = fr.requested_by_user_id +`; +const blockSelect = ` + SELECT ub.*, blocker.wca_user_id AS blocker_wca_user_id, blocked.wca_user_id AS blocked_wca_user_id + FROM app.user_blocks ub + JOIN app.users blocker ON blocker.id = ub.blocker_id + JOIN app.users blocked ON blocked.id = ub.blocked_id +`; + +const relationshipWhere = (criteria, values, offset = 0, alias = 'fr') => { + const column = (name) => (alias ? `${alias}.${name}` : name); + const clauses = []; + if (criteria.pairKey) { values.push(criteria.pairKey); clauses.push(`${column('pair_key')} = $${values.length + offset}`); } + if (criteria._id) { values.push(String(criteria._id)); clauses.push(`${column('id')} = $${values.length + offset}::uuid`); } + if (criteria.revision !== undefined) { values.push(criteria.revision); clauses.push(`${column('revision')} = $${values.length + offset}`); } + if (criteria.status?.$in) { values.push(criteria.status.$in); clauses.push(`${column('status')} = ANY($${values.length + offset}::text[])`); } + const or = criteria.$or; + if (or && or.length) { + const parts = or.map((item) => { + if (item.lowUserId !== undefined) { values.push(userId(item.lowUserId)); return `${column('low_user_id')} = $${values.length + offset}`; } + if (item.highUserId !== undefined) { values.push(userId(item.highUserId)); return `${column('high_user_id')} = $${values.length + offset}`; } + return 'FALSE'; + }); + clauses.push(`(${parts.join(' OR ')})`); + } + return clauses.length ? clauses.join(' AND ') : 'TRUE'; +}; + +const blockWhere = (criteria, values) => { + const clauses = []; + if (criteria._id) { values.push(String(criteria._id)); clauses.push(`ub.id = $${values.length}::uuid`); } + if (criteria.pairKey) { values.push(criteria.pairKey); clauses.push(`ub.pair_key = $${values.length}`); } + if (criteria.blockerId !== undefined) { values.push(userId(criteria.blockerId)); clauses.push(`ub.blocker_id = $${values.length}`); } + if (criteria.blockedId !== undefined) { values.push(userId(criteria.blockedId)); clauses.push(`ub.blocked_id = $${values.length}`); } + if (criteria.active !== undefined) { values.push(criteria.active); clauses.push(`ub.active = $${values.length}`); } + if (criteria.$or?.length) { + const parts = criteria.$or.map((item) => { + if (item.blockerId !== undefined) { values.push(userId(item.blockerId)); return `ub.blocker_id = $${values.length}`; } + if (item.blockedId !== undefined) { values.push(userId(item.blockedId)); return `ub.blocked_id = $${values.length}`; } + return 'FALSE'; + }); + clauses.push(`(${parts.join(' OR ')})`); + } + return clauses.length ? clauses.join(' AND ') : 'TRUE'; +}; + +const updateFields = (update) => { + const fields = []; + const values = []; + const set = update.$set || {}; + Object.entries(set).forEach(([key, value]) => { + const column = { + cooldownUntil: 'cooldown_until', requestedBy: 'requested_by_user_id', + stateChangedAt: 'state_changed_at', status: 'status', active: 'active', + }[key]; + if (!column) return; + values.push(key === 'requestedBy' && value ? userId(value) : value); + fields.push(`${column} = $${values.length}`); + }); + if (update.$inc?.revision) fields.push(`revision = revision + ${Number(update.$inc.revision)}`); + return { fields, values }; +}; + +const createRelationshipModel = () => ({ + findOne: (criteria) => new SqlQuery(async () => { + const values = []; + const { rows } = await pool.query(`${relationshipSelect} WHERE ${relationshipWhere(criteria, values)} LIMIT 1`, values); + return relationshipRow(rows[0]); + }), + find: (criteria) => new SqlQuery(async () => { + const values = []; + const { rows } = await pool.query(`${relationshipSelect} WHERE ${relationshipWhere(criteria, values)} ORDER BY fr.state_changed_at DESC`, values); + return rows.map(relationshipRow); + }), + create: async (document) => { + const now = document.stateChangedAt || new Date(); + const id = document._id || stableId('friend-relationship', document.pairKey); + await pool.query(` + INSERT INTO app.friend_relationships ( + id, pair_key, low_user_id, high_user_id, status, requested_by_user_id, + cooldown_until, revision, state_changed_at, source_created_at, source_updated_at + ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $9, $9) + RETURNING * + `, [id, document.pairKey, userId(document.lowUserId), userId(document.highUserId), document.status, + document.requestedBy ? userId(document.requestedBy) : null, document.cooldownUntil || null, + document.revision || 0, now]); + return createRelationshipModel().findOne({ _id: id }); + }, + findOneAndUpdate: async (criteria, update, options = {}) => { + const changes = updateFields(update); + if (!changes.fields.length) return createRelationshipModel().findOne(criteria); + const offset = changes.values.length; + const values = []; + const where = relationshipWhere(criteria, values, offset, null); + const updateResult = await pool.query(`UPDATE app.friend_relationships SET ${changes.fields.join(', ')}, source_updated_at = now(), ingested_at = now() WHERE ${where} RETURNING *`, [...changes.values, ...values]); + if (!updateResult.rows[0] && options.upsert) return null; + return createRelationshipModel().findOne({ _id: criteria._id }); + }, +}); + +const createBlockModel = () => ({ + findOne: (criteria) => new SqlQuery(async () => { + const values = []; + const { rows } = await pool.query(`${blockSelect} WHERE ${blockWhere(criteria, values)} ORDER BY ub.revision DESC LIMIT 1`, values); + return blockRow(rows[0]); + }), + find: (criteria) => new SqlQuery(async () => { + const values = []; + const { rows } = await pool.query(`${blockSelect} WHERE ${blockWhere(criteria, values)} ORDER BY ub.revision DESC`, values); + return rows.map(blockRow); + }), + exists: (criteria) => new SqlQuery(async () => { + const values = []; + const { rows } = await pool.query(`SELECT 1 FROM app.user_blocks ub WHERE ${blockWhere(criteria, values)} LIMIT 1`, values); + return !!rows[0]; + }), + findOneAndUpdate: async (criteria, update, options = {}) => { + const existing = await createBlockModel().findOne(criteria); + const patch = update.$set || {}; + if (!existing && options.upsert) { + const blocker = update.$setOnInsert.blockerId; + const blocked = update.$setOnInsert.blockedId; + const pairKey = update.$setOnInsert.pairKey; + const { rows } = await pool.query(` + INSERT INTO app.user_blocks (id, blocker_id, blocked_id, pair_key, active, revision, state_changed_at, source_created_at, source_updated_at) + VALUES ($1, $2, $3, $4, $5, 1, $6, $6, $6) + ON CONFLICT (blocker_id, blocked_id) DO UPDATE SET active = EXCLUDED.active, + revision = app.user_blocks.revision + 1, state_changed_at = EXCLUDED.state_changed_at, + source_updated_at = EXCLUDED.source_updated_at, ingested_at = now() + RETURNING * + `, [stableId('user-block', `${blocker}:${blocked}`), userId(blocker), userId(blocked), pairKey, + !!patch.active, patch.stateChangedAt || new Date()]); + return blockRow(rows[0]); + } + if (!existing) return null; + const changed = updateFields(update); + if (!changed.fields.length) return existing; + const values = [...changed.values, existing._id]; + const { rows } = await pool.query(`UPDATE app.user_blocks SET ${changed.fields.join(', ')}, source_updated_at = now(), ingested_at = now() WHERE id = $${values.length}::uuid RETURNING *`, values); + return blockRow(rows[0]); + }, +}); + +const notificationRow = (row) => row && ({ + _id: row.id, + id: row.id, + actorId: Number(row.actor_wca_user_id), + recipientId: Number(row.recipient_wca_user_id), + type: row.type, + sourceType: row.source_type, + sourceId: row.source_id, + dedupeKey: row.dedupe_key, + readAt: row.read_at, + expiresAt: row.expires_at, + createdAt: row.source_created_at, + updatedAt: row.source_updated_at, +}); + +const notificationWhere = (criteria, values) => { + const clauses = ['sn.expires_at > now()']; + if (criteria.recipientId !== undefined) { values.push(userId(criteria.recipientId)); clauses.push(`sn.recipient_wca_user_id = (SELECT wca_user_id FROM app.users WHERE id = $${values.length})`); } + if (criteria.expiresAt?.$gt) { values.push(criteria.expiresAt.$gt); clauses.push(`sn.expires_at > $${values.length}`); } + if (criteria.readAt === null) clauses.push('sn.read_at IS NULL'); + if (criteria.$or?.length) { + const parts = criteria.$or.map((item) => { + if (item.createdAt?.$lt) { values.push(item.createdAt.$lt); return `sn.source_created_at < $${values.length}`; } + if (item.createdAt && item._id?.$lt) { + values.push(item.createdAt, String(item._id)); + return `(sn.source_created_at = $${values.length - 1} AND sn.id < $${values.length}::uuid)`; + } + return 'FALSE'; + }); + clauses.push(`(${parts.join(' OR ')})`); + } + return clauses.join(' AND '); +}; + +const SocialNotification = { + create: async (document) => { + const id = uuidv4(); + const { rows } = await pool.query(` + INSERT INTO app.social_notifications ( + id, mongo_id, recipient_wca_user_id, actor_wca_user_id, type, source_type, + source_id, dedupe_key, expires_at, source_created_at, source_updated_at + ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, now(), now()) + RETURNING * + `, [id, id, document.recipientId, document.actorId, document.type, document.sourceType, + String(document.sourceId), document.dedupeKey, document.expiresAt]); + return notificationRow(rows[0]); + }, + find: (criteria) => new SqlQuery(async ({ limit } = {}) => { + const values = []; + let sql = `SELECT * FROM app.social_notifications sn WHERE ${notificationWhere(criteria, values)} ORDER BY source_created_at DESC, id DESC`; + if (limit !== undefined) { values.push(limit); sql += ` LIMIT $${values.length}`; } + const { rows } = await pool.query(sql, values); + return rows.map(notificationRow); + }), + countDocuments: async (criteria) => { + const values = []; + const { rows } = await pool.query(`SELECT count(*)::integer AS count FROM app.social_notifications sn WHERE ${notificationWhere(criteria, values)}`, values); + return rows[0].count; + }, + findOneAndUpdate: async (criteria, update) => { + const values = []; + const clauses = [`sn.id = $${values.length + 1}::uuid`]; + values.push(criteria._id); + if (criteria.recipientId !== undefined) { values.push(criteria.recipientId); clauses.push(`sn.recipient_wca_user_id = $${values.length}`); } + const set = update.$set || {}; + const fields = []; + Object.entries(set).forEach(([key, value]) => { if (key === 'readAt') { values.push(value); fields.push(`read_at = $${values.length}`); } }); + if (!fields.length) return null; + const { rows } = await pool.query(`UPDATE app.social_notifications sn SET ${fields.join(', ')}, source_updated_at = now(), ingested_at = now() WHERE ${clauses.join(' AND ')} RETURNING *`, values); + return notificationRow(rows[0]); + }, + updateMany: async (criteria, update) => { + const values = []; + const where = notificationWhere(criteria, values); + values.push(update.$set.readAt); + const result = await pool.query(`UPDATE app.social_notifications sn SET read_at = $${values.length}, source_updated_at = now(), ingested_at = now() WHERE ${where}`, values); + return { modifiedCount: result.rowCount }; + }, +}; + +module.exports = { + FriendRelationship: createRelationshipModel(), + RELATIONSHIP_STATUSES, + SocialNotification, + UserBlock: createBlockModel(), +}; diff --git a/server/postgres/sqlSocialModels.test.js b/server/postgres/sqlSocialModels.test.js new file mode 100644 index 00000000..179dfccd --- /dev/null +++ b/server/postgres/sqlSocialModels.test.js @@ -0,0 +1,62 @@ +/** @jest-environment node */ +/* eslint-env jest */ + +jest.mock('./index', () => ({ + pool: { query: jest.fn() }, +})); + +const { pool } = require('./index'); +const { FriendRelationship, SocialNotification } = require('./sqlSocialModels'); + +describe('PostgreSQL social notification model', () => { + beforeEach(() => { + jest.clearAllMocks(); + pool.query.mockResolvedValue({ rows: [{ id: 'notification-id' }] }); + }); + + it('uses separate UUID and text parameters for notification identifiers', async () => { + const expiresAt = new Date('2026-07-28T00:00:00.000Z'); + + await SocialNotification.create({ + recipientId: 1234, + actorId: 5678, + type: 'friend_request', + sourceType: 'friend_relationship', + sourceId: 'relationship-1', + dedupeKey: 'friend_request:relationship-1', + expiresAt, + }); + + const [sql, values] = pool.query.mock.calls[0]; + expect(sql).toContain(') VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, now(), now())'); + expect(values).toHaveLength(9); + expect(values[0]).toEqual(expect.any(String)); + expect(values[1]).toBe(values[0]); + expect(values.slice(2)).toEqual([ + 1234, + 5678, + 'friend_request', + 'friend_relationship', + 'relationship-1', + 'friend_request:relationship-1', + expiresAt, + ]); + }); + + it('does not use the read-query alias in relationship updates', async () => { + pool.query + .mockResolvedValueOnce({ rows: [{ id: 'relationship-id' }] }) + .mockResolvedValueOnce({ rows: [{ id: 'relationship-id' }] }); + + await FriendRelationship.findOneAndUpdate( + { _id: 'relationship-id', revision: 1 }, + { $set: { status: 'accepted' }, $inc: { revision: 1 } }, + ); + + const [sql] = pool.query.mock.calls[0]; + expect(sql).toContain('UPDATE app.friend_relationships'); + expect(sql).toContain('WHERE id = $2::uuid AND revision = $3'); + expect(sql).not.toContain('fr.id'); + expect(sql).not.toContain('fr.revision'); + }); +}); diff --git a/server/postgres/sqlUserModel.js b/server/postgres/sqlUserModel.js new file mode 100644 index 00000000..7b26aea4 --- /dev/null +++ b/server/postgres/sqlUserModel.js @@ -0,0 +1,14 @@ +const repository = require('./userRepository'); +const SqlQuery = require('./sqlQuery'); + +const User = { + isSqlRepository: true, + findOne: (criteria) => new SqlQuery(() => repository.findOne(criteria)), + find: (criteria, options) => new SqlQuery((queryOptions) => repository.find( + criteria, + { ...options, ...queryOptions }, + )), + findOneAndUpdate: repository.findOneAndUpdate, +}; + +module.exports = User; diff --git a/server/postgres/userRepository.js b/server/postgres/userRepository.js new file mode 100644 index 00000000..c8e79d36 --- /dev/null +++ b/server/postgres/userRepository.js @@ -0,0 +1,159 @@ +const { pool } = require('./index'); +const { stableId } = require('./dualWrite'); +const { normalizeUsername } = require('../username'); + +const numericId = (value) => { + const id = Number(value); + return Number.isSafeInteger(id) && id > 0 ? id : null; +}; + +const preferencesFromRow = (row) => ({ + showWCAID: !!row.preferences?.showWCAID, + preferRealName: !!row.preferences?.preferRealName, + useInspection: !!row.preferences?.useInspection, + timerType: row.preferences?.timerType || 'spacebar', + muteTimer: !!row.preferences?.muteTimer, +}); + +const toUser = (row) => { + if (!row) return null; + const preferences = preferencesFromRow(row); + const user = { + _id: row.id, + id: Number(row.wca_user_id), + name: row.name, + username: row.username || undefined, + usernameNormalized: row.username_normalized || undefined, + wcaId: row.wca_id || undefined, + avatar: row.avatar || {}, + ...preferences, + }; + Object.defineProperties(user, { + displayName: { enumerable: true, get: () => (user.preferRealName ? user.name : user.username) }, + canJoinRoom: { enumerable: true, get: () => user.preferRealName || !!user.username }, + toObject: { value: () => ({ ...user }), enumerable: false }, + save: { value: () => updateUser(user), enumerable: false }, + }); + return user; +}; + +const userParams = (user, fallbackName = 'Unknown User') => { + const id = numericId(user.id); + if (!id) throw new Error('A valid WCA user ID is required'); + const normalized = normalizeUsername(user.username); + return [ + stableId('user', id), + id, + user.name || fallbackName, + normalized.username || null, + normalized.usernameNormalized || null, + user.wcaId || null, + { + showWCAID: !!user.showWCAID, + preferRealName: !!user.preferRealName, + useInspection: !!user.useInspection, + timerType: user.timerType || 'spacebar', + muteTimer: !!user.muteTimer, + }, + user.avatar || {}, + user.createdAt || null, + new Date(), + ]; +}; + +const updateUser = async (user) => { + const params = userParams(user); + const { rows } = await pool.query(` + INSERT INTO app.users ( + id, wca_user_id, name, username, username_normalized, wca_id, + preferences, avatar, source_created_at, source_updated_at + ) VALUES ($1, $2, $3, $4, $5, $6, $7::jsonb, $8::jsonb, $9, $10) + ON CONFLICT (wca_user_id) DO UPDATE SET + name = EXCLUDED.name, + username = EXCLUDED.username, + username_normalized = EXCLUDED.username_normalized, + wca_id = EXCLUDED.wca_id, + preferences = EXCLUDED.preferences, + avatar = EXCLUDED.avatar, + source_updated_at = EXCLUDED.source_updated_at, + ingested_at = now() + RETURNING * + `, params.map((value, index) => (index === 6 || index === 7 ? JSON.stringify(value) : value))); + return toUser(rows[0]); +}; + +const findOne = async (criteria = {}) => { + if (criteria._id !== undefined) { + const { rows } = await pool.query('SELECT * FROM app.users WHERE id = $1::uuid LIMIT 1', [String(criteria._id)]); + return toUser(rows[0]); + } + const users = await find(criteria, { limit: 1 }); + return users[0] || null; +}; + +const find = async (criteria = {}, { limit, offset = 0, order = 'wca_user_id ASC' } = {}) => { + const values = []; + const conditionSql = (entry) => { + if (entry.$and) return entry.$and.map(conditionSql).filter(Boolean).join(' AND ') || 'TRUE'; + if (entry.$or) return `(${entry.$or.map(conditionSql).filter(Boolean).join(' OR ') || 'FALSE'})`; + const parts = []; + if (entry.id && entry.id.$in) { + values.push(entry.id.$in.map(numericId)); + parts.push(`wca_user_id = ANY($${values.length}::bigint[])`); + } else if (entry.id && entry.id.$ne !== undefined) { + values.push(numericId(entry.id.$ne)); + parts.push(`wca_user_id <> $${values.length}`); + } else if (entry.id !== undefined) { + values.push(numericId(entry.id)); + parts.push(`wca_user_id = $${values.length}`); + } + if (entry.usernameNormalized && entry.usernameNormalized.$gte !== undefined) { + values.push(entry.usernameNormalized.$gte, entry.usernameNormalized.$lt); + parts.push(`username_normalized >= $${values.length - 1} AND username_normalized < $${values.length}`); + } else if (entry.usernameNormalized !== undefined) { + values.push(entry.usernameNormalized); + parts.push(`username_normalized = $${values.length}`); + } + if (entry.showWCAID !== undefined) { + values.push(!!entry.showWCAID); + parts.push(`COALESCE((preferences->>'showWCAID')::boolean, false) = $${values.length}`); + } + if (entry.wcaId !== undefined) { + values.push(entry.wcaId); + parts.push(`wca_id = $${values.length}`); + } + return parts.join(' AND '); + }; + const condition = conditionSql(criteria); + const requestedOrder = typeof order === 'string' + ? order + : (order && order.usernameNormalized === 1 ? 'usernameNormalized 1' : ''); + const safeOrder = requestedOrder === 'usernameNormalized 1' + || requestedOrder === 'username_normalized ASC' + ? 'username_normalized ASC' + : 'wca_user_id ASC'; + let sql = `SELECT * FROM app.users WHERE ${condition || 'TRUE'} ORDER BY ${safeOrder}`; + if (limit !== undefined) { + values.push(limit, offset); + sql += ` LIMIT $${values.length - 1} OFFSET $${values.length}`; + } + const { rows } = await pool.query(sql, values); + return rows.map(toUser); +}; + +const findOneAndUpdate = async (criteria, update, options = {}) => { + const existing = await findOne(criteria); + const patch = update.$set || update; + if (!existing && !options.upsert) return null; + const user = existing || { id: criteria.id, name: patch.name || 'Unknown User' }; + Object.assign(user, patch); + return updateUser(user); +}; + +module.exports = { + find, + findOne, + findOneAndUpdate, + toUser, + updateUser, +}; diff --git a/server/prisma/migrations/20260727160000_sql_runtime_contract/migration.sql b/server/prisma/migrations/20260727160000_sql_runtime_contract/migration.sql new file mode 100644 index 00000000..0a1854aa --- /dev/null +++ b/server/prisma/migrations/20260727160000_sql_runtime_contract/migration.sql @@ -0,0 +1,17 @@ +ALTER TABLE app.rooms + ADD COLUMN IF NOT EXISTS membership_revision integer NOT NULL DEFAULT 0; + +ALTER TABLE app.room_participants + ADD COLUMN IF NOT EXISTS presence_revision integer NOT NULL DEFAULT 0; + +CREATE INDEX IF NOT EXISTS rooms_active_expiry_idx + ON app.rooms (expires_at) + WHERE deleted_at IS NULL; + +CREATE TABLE IF NOT EXISTS app.sessions ( + sid text PRIMARY KEY, + sess jsonb NOT NULL, + expire timestamptz NOT NULL +); + +CREATE INDEX IF NOT EXISTS sessions_expire_idx ON app.sessions (expire); diff --git a/server/prisma/schema.prisma b/server/prisma/schema.prisma index 6de225f2..6686c195 100644 --- a/server/prisma/schema.prisma +++ b/server/prisma/schema.prisma @@ -53,6 +53,16 @@ model SocialNotification { @@schema("app") } +model Session { + sid String @id + sess Json @db.JsonB + expire DateTime @db.Timestamptz(6) + + @@index([expire], map: "sessions_expire_idx") + @@map("sessions") + @@schema("app") +} + model FriendRelationship { id String @id @db.Uuid pairKey String @unique(map: "friend_relationships_pair_key_key") @map("pair_key") @@ -126,6 +136,7 @@ model Room { raceSessions RaceSession[] kind String @default("normal") competitionRef String? @map("competition_ref") + membershipRevision Int @default(0) @map("membership_revision") @@map("rooms") @@schema("app") @@ -182,6 +193,7 @@ model RoomParticipant { banned Boolean @default(false) inRoom Boolean @default(false) @map("in_room") registered Boolean @default(false) + presenceRevision Int @default(0) @map("presence_revision") sourceUpdatedAt DateTime @map("source_updated_at") @db.Timestamptz(6) ingestedAt DateTime @default(now()) @map("ingested_at") @db.Timestamptz(6) room Room @relation(fields: [roomId], references: [id], onDelete: Cascade, onUpdate: NoAction) diff --git a/server/privacy/purgeUserEmails.js b/server/privacy/purgeUserEmails.js index 4de0bf79..31f99a79 100644 --- a/server/privacy/purgeUserEmails.js +++ b/server/privacy/purgeUserEmails.js @@ -1,32 +1,14 @@ -const mongoose = require('mongoose'); -const database = require('../database'); const logger = require('../logger'); -const { pool } = require('../postgres'); -const { purgeUserEmails } = require('./userEmailPurge'); - -const report = (summary) => { - logger.info( - '[PRIVACY] User email purge result: ' - + `MongoDB matched=${summary.mongoMatched} modified=${summary.mongoModified} ` - + `remaining=${summary.mongoRemaining}; PostgreSQL cleared=${summary.postgresCleared} ` - + `remaining=${summary.postgresRemaining}`, - ); -}; +const { initializePostgres, pool } = require('../postgres'); const run = async () => { - const connection = await database.connect(); - try { - return await purgeUserEmails({ - mongoUsers: connection.connection.collection('users'), - postgresClient: pool, - report, - }); + if (!(await initializePostgres())) throw new Error('PostgreSQL is unavailable'); + const result = await pool.query('UPDATE app.users SET email = NULL WHERE email IS NOT NULL'); + logger.info(`[PRIVACY] Cleared ${result.rowCount} PostgreSQL user email values`); + return { postgresCleared: result.rowCount }; } finally { - await Promise.allSettled([ - mongoose.disconnect(), - pool.end(), - ]); + await pool.end(); } }; diff --git a/server/runtimeConfig.js b/server/runtimeConfig.js index bcee12a2..47889e88 100644 --- a/server/runtimeConfig.js +++ b/server/runtimeConfig.js @@ -68,7 +68,6 @@ module.exports = { baseConfig.socketio.reconnectGraceMs, ), }, - mongodb: process.env.MONGO_URL || process.env.MONGODB_URI || baseConfig.mongodb, redis, wcaSource: process.env.WCA_SOURCE || process.env.REACT_APP_WCA_ORIGIN || baseConfig.wcaSource, auth: { diff --git a/server/social/notificationService.js b/server/social/notificationService.js index fb833777..789c69b4 100644 --- a/server/social/notificationService.js +++ b/server/social/notificationService.js @@ -1,8 +1,5 @@ -const mongoose = require('mongoose'); - const logger = require('../logger'); const { SocialNotification, User } = require('../models'); -const { mirrorNotification } = require('../postgres/dualWrite'); const { publishNotificationCreated, publishNotificationUpdated, @@ -17,6 +14,7 @@ const { const DEFAULT_RETENTION_DAYS = 30; const DEFAULT_PAGE_SIZE = 20; const MAX_PAGE_SIZE = 50; +const NOTIFICATION_ID_PATTERN = /^(?:[0-9a-f]{24}|[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})$/i; class NotificationError extends Error { constructor(statusCode, code, message) { @@ -52,10 +50,10 @@ const parseCursor = (cursor) => { try { const parsed = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8')); const createdAt = new Date(parsed.createdAt); - if (Number.isNaN(createdAt.getTime()) || !mongoose.Types.ObjectId.isValid(parsed.id)) { + if (Number.isNaN(createdAt.getTime()) || !NOTIFICATION_ID_PATTERN.test(String(parsed.id))) { throw new Error('invalid cursor'); } - return { createdAt, id: new mongoose.Types.ObjectId(parsed.id) }; + return { createdAt, id: String(parsed.id) }; } catch { throw new NotificationError(400, 'invalid_cursor', 'Invalid notification cursor'); } @@ -102,7 +100,7 @@ const createNotificationService = ({ publishCreated: publishNotificationCreated, publishUpdated: publishNotificationUpdated, }, - mirror = mirrorNotification, + mirror = async () => null, notificationModel = SocialNotification, notificationLogger = logger, now = () => new Date(), @@ -124,7 +122,7 @@ const createNotificationService = ({ try { notification = toPlain(await notificationModel.create(document)); } catch (err) { - if (err && err.code === 11000) { + if (err && (err.code === 11000 || err.code === '23505')) { return { created: false, notification: null }; } throw err; @@ -213,7 +211,7 @@ const createNotificationService = ({ const markRead = async (actor, notificationId) => { const recipientId = normalizeUserId(actor && actor.id); - if (!mongoose.Types.ObjectId.isValid(notificationId)) { + if (!NOTIFICATION_ID_PATTERN.test(String(notificationId))) { throw new NotificationError(404, 'notification_not_found', 'Notification not found'); } const notification = toPlain(await notificationModel.findOneAndUpdate({ diff --git a/server/social/relationshipService.js b/server/social/relationshipService.js index 8ff5eba9..dc59e814 100644 --- a/server/social/relationshipService.js +++ b/server/social/relationshipService.js @@ -1,4 +1,3 @@ -/* eslint-disable no-await-in-loop, no-continue */ const logger = require('../logger'); const metrics = require('../metrics'); const { @@ -7,10 +6,6 @@ const { User, UserBlock, } = require('../models'); -const { - mirrorBlock, - mirrorRelationship, -} = require('../postgres/dualWrite'); const { publishSocialInvalidation } = require('../realtime/socialEvents'); const notificationService = require('./notificationService'); const publicUserProjection = require('./publicUser'); @@ -68,8 +63,8 @@ const createRelationshipService = ({ socialLogger = logger, userModel = User, mirrors = { - mirrorBlock, - mirrorRelationship, + mirrorBlock: async () => null, + mirrorRelationship: async () => null, }, notifier = publishSocialInvalidation, notifications = notificationService, @@ -127,7 +122,7 @@ const createRelationshipService = ({ revision: 0, })); } catch (err) { - if (err.code === 11000) { + if (err.code === 11000 || err.code === '23505') { return undefined; } throw err; diff --git a/server/social/relationshipState.js b/server/social/relationshipState.js index a7de1deb..9e05fe69 100644 --- a/server/social/relationshipState.js +++ b/server/social/relationshipState.js @@ -1,4 +1,4 @@ -const { RELATIONSHIP_STATUSES } = require('../models/friendRelationship'); +const { RELATIONSHIP_STATUSES } = require('../postgres/sqlSocialModels'); const ACTIONS = Object.freeze({ ACCEPT: 'accept', diff --git a/server/socket/index.js b/server/socket/index.js index 75b953f2..b063bcc1 100644 --- a/server/socket/index.js +++ b/server/socket/index.js @@ -5,7 +5,6 @@ const Redis = require('ioredis'); const config = require('../runtimeConfig'); const session = require('../middlewares/session'); -const { connect } = require('../database'); const { createHealthHandler, createHealthReporter } = require('../health'); const { initializePostgres, pool } = require('../postgres'); const logger = require('../logger'); @@ -52,8 +51,9 @@ const init = async () => { server.on('error', logSocketError('http server')); io.on('error', logSocketError('server')); - const mongoose = await connect(); - await initializePostgres(); + if (!(await initializePostgres())) { + throw new Error('PostgreSQL is required for the socket runtime'); + } const pubClient = new Redis(config.redis.url || { host: config.redis.host, @@ -79,15 +79,9 @@ const init = async () => { const reportHealth = createHealthReporter({ service: 'socket', checks: { - mongodb: () => mongoose.connection.readyState === 1, - postgres: { - required: false, - check: async () => { - if (config.postgres.enabled) { - await pool.query('SELECT 1'); - } - return true; - }, + postgres: async () => { + await pool.query('SELECT 1'); + return true; }, redis: async () => pubClient.status === 'ready' && subClient.status === 'ready' diff --git a/server/socket/lib/roomSerialization.js b/server/socket/lib/roomSerialization.js new file mode 100644 index 00000000..f0b376ab --- /dev/null +++ b/server/socket/lib/roomSerialization.js @@ -0,0 +1,43 @@ +const mapToObject = (value) => { + if (!(value instanceof Map)) { + return value; + } + + return Object.fromEntries([...value.entries()].map(([key, entry]) => [String(key), entry])); +}; + +const serializeAttempt = (attempt) => { + if (!attempt) { + return attempt; + } + + const serialized = typeof attempt.toObject === 'function' + ? attempt.toObject() + : { ...attempt }; + serialized.results = mapToObject(serialized.results); + return serialized; +}; + +const serializeRoomMask = (room, keys) => { + const masked = Object.fromEntries( + keys + .filter((key) => room[key] !== undefined) + .map((key) => [key, room[key]]), + ); + + ['competing', 'waitingFor', 'banned', 'inRoom', 'registered'].forEach((key) => { + masked[key] = mapToObject(masked[key]); + }); + + if (Array.isArray(masked.attempts)) { + masked.attempts = masked.attempts.map(serializeAttempt); + } + + return masked; +}; + +module.exports = { + mapToObject, + serializeAttempt, + serializeRoomMask, +}; diff --git a/server/socket/lib/roomSerialization.test.js b/server/socket/lib/roomSerialization.test.js new file mode 100644 index 00000000..07d32932 --- /dev/null +++ b/server/socket/lib/roomSerialization.test.js @@ -0,0 +1,33 @@ +const { + mapToObject, + serializeAttempt, + serializeRoomMask, +} = require('./roomSerialization'); + +describe('room socket serialization', () => { + it('serializes maps with string keys', () => { + expect(mapToObject(new Map([[8184, true]]))).toEqual({ 8184: true }); + }); + + it('serializes attempt result maps', () => { + expect(serializeAttempt({ + id: 0, + results: new Map([['8184', { time: 1234 }]]), + })).toEqual({ + id: 0, + results: { 8184: { time: 1234 } }, + }); + }); + + it('serializes room state used by the browser timer', () => { + expect(serializeRoomMask({ + competing: new Map([['8184', true]]), + waitingFor: new Map([['8184', true]]), + attempts: [{ results: new Map([['8184', { time: 1234 }]]) }], + }, ['competing', 'waitingFor', 'attempts'])).toEqual({ + competing: { 8184: true }, + waitingFor: { 8184: true }, + attempts: [{ results: { 8184: { time: 1234 } } }], + }); + }); +}); diff --git a/server/socket/namespaces/rooms.js b/server/socket/namespaces/rooms.js index 85ee20ad..f83ce01b 100644 --- a/server/socket/namespaces/rooms.js +++ b/server/socket/namespaces/rooms.js @@ -6,7 +6,6 @@ const { parseCommand } = require('../lib/commands'); const config = require('../../runtimeConfig'); const logger = require('../../logger'); const metrics = require('../../metrics'); -const { markRoomDeleted } = require('../../postgres/dualWrite'); const { Room, User } = require('../../models'); const publicUserProjection = require('../../social/publicUser'); const raceInvitationService = require('../../social/raceInvitationService'); @@ -29,6 +28,11 @@ const { createSafeSocketHandler, optionalAcknowledgment, } = require('../lib/socketHandler'); +const { + mapToObject, + serializeAttempt, + serializeRoomMask, +} = require('../lib/roomSerialization'); const PASSWORD_SALT_ROUNDS = 10; @@ -48,7 +52,7 @@ const roomMask = (room) => ({ }); // Data for people in room -const joinRoomMask = _.partial(_.pick, _, privateRoomKeys); +const joinRoomMask = (room) => serializeRoomMask(room, privateRoomKeys); const isRoomTypeEnabled = (type) => checkRoomTypeEnabled(type, config.grandPrix.enabled); const fetchRoom = (id) => Room.findById({ _id: id }).populate('users').populate('admin').populate('owner'); @@ -100,8 +104,8 @@ module.exports = (io, middlewares) => { const updatedRoom = await room.newAttempt(); logger.debug('Sending new scramble to room', { roomId: room.id }); ns().in(room.accessCode).emit(Protocol.NEW_ATTEMPT, { - waitingFor: updatedRoom.waitingFor, - attempt: updatedRoom.attempts[updatedRoom.attempts.length - 1], + waitingFor: mapToObject(updatedRoom.waitingFor), + attempt: serializeAttempt(updatedRoom.attempts[updatedRoom.attempts.length - 1]), }); return updatedRoom; } @@ -738,7 +742,6 @@ module.exports = (io, middlewares) => { const res = await Room.deleteOne({ _id: room._id }); if (res.deletedCount > 0) { - await markRoomDeleted(room._id); socket.room = undefined; acknowledgment(null); ns().emit(Protocol.ROOM_DELETED, id); diff --git a/server/username.js b/server/username.js index 5d58835b..8316c7ee 100644 --- a/server/username.js +++ b/server/username.js @@ -57,7 +57,7 @@ const usernameConflict = () => new UsernameError( 409, ); -const isUsernameDuplicateKeyError = (err) => err && err.code === 11000 && ( +const isUsernameDuplicateKeyError = (err) => err && (err.code === 11000 || err.code === '23505') && ( (err.keyPattern && err.keyPattern.usernameNormalized) || (err.message && err.message.includes('users_username_normalized_unique')) ); diff --git a/yarn.lock b/yarn.lock index 0a5f6dd6..a2b74e12 100644 --- a/yarn.lock +++ b/yarn.lock @@ -944,7 +944,7 @@ "@babel/plugin-transform-react-jsx-development" "^7.29.7" "@babel/plugin-transform-react-pure-annotations" "^7.29.7" -"@babel/runtime@^7.1.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.13", "@babel/runtime@^7.12.5", "@babel/runtime@^7.18.3", "@babel/runtime@^7.21.0", "@babel/runtime@^7.26.0", "@babel/runtime@^7.3.1", "@babel/runtime@^7.5.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.3", "@babel/runtime@^7.8.7", "@babel/runtime@^7.9.2": +"@babel/runtime@^7.1.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.13", "@babel/runtime@^7.12.5", "@babel/runtime@^7.18.3", "@babel/runtime@^7.26.0", "@babel/runtime@^7.3.1", "@babel/runtime@^7.5.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.3", "@babel/runtime@^7.8.7", "@babel/runtime@^7.9.2": version "7.29.7" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.29.7.tgz#12022450c45a4da6d8d8287b18a4ff2ddb23f768" integrity sha512-Nq8OhGWiZIZGV6hLHoyAKLLcJihP/xFeBMGJoUrxTX2psI8dCifzLhZISFb+VWS3wFMRDmCGw5R+dOySCqPLhw== @@ -1214,6 +1214,13 @@ resolved "https://registry.yarnpkg.com/@emotion/weak-memoize/-/weak-memoize-0.4.0.tgz#5e13fac887f08c44f76b0ccaf3370eb00fec9bb6" integrity sha512-snKqtPW01tN0ui7yu9rGv69aJXr/a/Ywvl11sUjNtEcRc+ng/mQriFL0wLXMef74iHa/EkftbDzU9F8iFbH+zg== +"@eslint-community/eslint-utils@^4.2.0": + version "4.10.1" + resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.10.1.tgz#8911bd72b2c3640a543609e0400b8c4d2e7e7cb6" + integrity sha512-cuadcxVFE8sDK6iWJbs8Sn0av2Nrh2QSGQhVlBW9AaAHqHwjWsZHT8LJ4hFGPh7ASBV2deFdM7H/DPjulmh8rg== + dependencies: + eslint-visitor-keys "^3.4.3" + "@eslint-community/eslint-utils@^4.8.0": version "4.9.1" resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.9.1.tgz#4e90af67bc51ddee6cdef5284edf572ec376b595" @@ -1221,7 +1228,7 @@ dependencies: eslint-visitor-keys "^3.4.3" -"@eslint-community/regexpp@^4.12.1": +"@eslint-community/regexpp@^4.12.1", "@eslint-community/regexpp@^4.6.1": version "4.12.2" resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.12.2.tgz#bccdf615bcf7b6e8db830ec0b8d21c9a25de597b" integrity sha512-EriSTlt5OC9/7SXkRSCAhfSxxoSUgBm33OH+IkwbdpgoqsSsUg7y3uh+IICI/Qg4BBWr3U2i39RpmycbxMq4ew== @@ -1249,6 +1256,21 @@ dependencies: "@types/json-schema" "^7.0.15" +"@eslint/eslintrc@^2.1.4": + version "2.1.4" + resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.1.4.tgz#388a269f0f25c1b6adc317b5a2c55714894c70ad" + integrity sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ== + dependencies: + ajv "^6.12.4" + debug "^4.3.2" + espree "^9.6.0" + globals "^13.19.0" + ignore "^5.2.0" + import-fresh "^3.2.1" + js-yaml "^4.1.0" + minimatch "^3.1.2" + strip-json-comments "^3.1.1" + "@eslint/eslintrc@^3.3.5": version "3.3.5" resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-3.3.5.tgz#c131793cfc1a7b96f24a83e0a8bbd4b881558c60" @@ -1264,6 +1286,11 @@ minimatch "^3.1.5" strip-json-comments "^3.1.1" +"@eslint/js@8.57.0": + version "8.57.0" + resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f" + integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g== + "@eslint/js@9.39.4", "@eslint/js@^9.39.4": version "9.39.4" resolved "https://registry.yarnpkg.com/@eslint/js/-/js-9.39.4.tgz#a3f83bfc6fd9bf33a853dfacd0b49b398eb596c1" @@ -1308,11 +1335,25 @@ resolved "https://registry.yarnpkg.com/@humanfs/types/-/types-0.15.0.tgz#f2a09f62012390b2bff3fc6fb248ddec8c09a090" integrity sha512-ZZ1w0aoQkwuUuC7Yf+7sdeaNfqQiiLcSRbfI08oAxqLtpXQr9AIVX7Ay7HLDuiLYAaFPu8oBYNq/QIi9URHJ3Q== +"@humanwhocodes/config-array@^0.11.14": + version "0.11.14" + resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.14.tgz#d78e481a039f7566ecc9660b4ea7fe6b1fec442b" + integrity sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg== + dependencies: + "@humanwhocodes/object-schema" "^2.0.2" + debug "^4.3.1" + minimatch "^3.0.5" + "@humanwhocodes/module-importer@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz#af5b2691a22b44be847b0ca81641c5fb6ad0172c" integrity sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA== +"@humanwhocodes/object-schema@^2.0.2": + version "2.0.3" + resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz#4a2868d75d6d6963e423bcf90b7fd1be343409d3" + integrity sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA== + "@humanwhocodes/retry@^0.4.0", "@humanwhocodes/retry@^0.4.2": version "0.4.3" resolved "https://registry.yarnpkg.com/@humanwhocodes/retry/-/retry-0.4.3.tgz#c2b9d2e374ee62c586d3adbea87199b1d7a7a6ba" @@ -1780,6 +1821,27 @@ dependencies: "@tybys/wasm-util" "^0.10.3" +"@nodelib/fs.scandir@2.1.5": + version "2.1.5" + resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" + integrity sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g== + dependencies: + "@nodelib/fs.stat" "2.0.5" + run-parallel "^1.1.9" + +"@nodelib/fs.stat@2.0.5": + version "2.0.5" + resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz#5bd262af94e9d25bd1e71b05deed44876a222e8b" + integrity sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A== + +"@nodelib/fs.walk@^1.2.8": + version "1.2.8" + resolved "https://registry.yarnpkg.com/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz#e95737e8bb6746ddedf69c556953494f196fe69a" + integrity sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg== + dependencies: + "@nodelib/fs.scandir" "2.1.5" + fastq "^1.6.0" + "@optique/core@1.1.1", "@optique/core@>=0.9.1": version "1.1.1" resolved "https://registry.yarnpkg.com/@optique/core/-/core-1.1.1.tgz#dfedf03cee4dbdc11b7a99d83908ccd4ba403c1f" @@ -2621,6 +2683,11 @@ dependencies: "@types/yargs-parser" "*" +"@ungap/structured-clone@^1.2.0": + version "1.3.3" + resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.3.3.tgz#094041e1a4cb1987f038335421281ac8be390bcc" + integrity sha512-60YRaenCQcVjYEKOcG824+DRGGIQ3VKErcBoAEDJZz5bKIs2ZG+X/H9Nk+Q6EVkwJk5QNApxbrc5QtBSwtrXAg== + "@ungap/structured-clone@^1.3.0": version "1.3.2" resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.3.2.tgz#a03ad82cd5676414d068ba86f880c5681194aadf" @@ -2760,17 +2827,12 @@ accepts@~1.3.4, accepts@~1.3.8: mime-types "~2.1.34" negotiator "0.6.3" -acorn-jsx@^5.2.0, acorn-jsx@^5.3.2: +acorn-jsx@^5.3.2: version "5.3.2" resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937" integrity sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ== -acorn@^7.1.1: - version "7.4.1" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" - integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== - -acorn@^8.15.0: +acorn@^8.15.0, acorn@^8.9.0: version "8.17.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.17.0.tgz#1785adb84faf8d8add10369b93826fc2bd08f1fe" integrity sha512-xRQbDb9BnwDafYNn6Vwl839DYVjqXYb1XVGtWAZ1kcDc6iwAL4hg3B1dZlRiuENFeO2H53gFG3in621AdERVAg== @@ -2780,7 +2842,7 @@ agent-base@^7.1.0, agent-base@^7.1.2: resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-7.1.4.tgz#e3cd76d4c548ee895d3c3fd8dc1f6c5b9032e7a8" integrity sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ== -ajv@^6.10.0, ajv@^6.10.2, ajv@^6.14.0: +ajv@^6.12.4, ajv@^6.14.0: version "6.15.0" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.15.0.tgz#07e982c74626167aa7a2495c53817892d7139492" integrity sha512-fgFx7Hfoq60ytK2c7DhnF8jIvzYgOMxfugjLOSMHjLIPgenqa7S7oaagATUq99mV6IYvN2tRmC0wnTYX6iPbMw== @@ -2800,7 +2862,7 @@ ajv@^8.12.0, ajv@^8.6.0: json-schema-traverse "^1.0.0" require-from-string "^2.0.2" -ansi-escapes@^4.2.1, ansi-escapes@^4.3.2: +ansi-escapes@^4.3.2: version "4.3.2" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-4.3.2.tgz#6b2291d1db7d98b6521d5f1efa42d0f3a9feb65e" integrity sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ== @@ -2814,11 +2876,6 @@ ansi-escapes@^7.0.0: dependencies: environment "^1.0.0" -ansi-regex@^4.1.0: - version "4.1.1" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.1.tgz#164daac87ab2d6f6db3a29875e2d1766582dabed" - integrity sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g== - ansi-regex@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" @@ -2829,13 +2886,6 @@ ansi-regex@^6.2.2: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-6.2.2.tgz#60216eea464d864597ce2832000738a0589650c1" integrity sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg== -ansi-styles@^3.2.0, ansi-styles@^3.2.1: - version "3.2.1" - resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" - integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA== - dependencies: - color-convert "^1.9.0" - ansi-styles@^4.0.0, ansi-styles@^4.1.0: version "4.3.0" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" @@ -2986,16 +3036,6 @@ arraybuffer.prototype.slice@^1.0.4: get-intrinsic "^1.2.6" is-array-buffer "^3.0.4" -asn1.js@^5.4.1: - version "5.4.1" - resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-5.4.1.tgz#11a980b84ebb91781ce35b0fdc2ee294e3783f07" - integrity sha512-+I//4cYPccV8LdmBLiX8CYvf9Sp3vQsrqu2QNXRcrbiWvcx/UdlFiqUJJzxRQxgsZmvhXhn4cSKeSmoFjVdupA== - dependencies: - bn.js "^4.0.0" - inherits "^2.0.1" - minimalistic-assert "^1.0.0" - safer-buffer "^2.1.0" - asn1@~0.2.3: version "0.2.6" resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.6.tgz#0d3a7bb6e64e02a90c0303b31f292868ea09a08d" @@ -3013,11 +3053,6 @@ ast-types-flow@^0.0.8: resolved "https://registry.yarnpkg.com/ast-types-flow/-/ast-types-flow-0.0.8.tgz#0a85e1c92695769ac13a428bb653e7538bea27d6" integrity sha512-OH/2E5Fg20h2aPrbe+QL8JZQFko0YZaF+j4mnQ7BGhfavO7OpSLa8a0y9sBwomHdSbkhTS8TQNayBfnW5DwbvQ== -astral-regex@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9" - integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg== - async-function@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/async-function/-/async-function-1.0.0.tgz#509c9fca60eaf85034c6829838188e4e4c8ffb2b" @@ -3247,11 +3282,6 @@ bluebird@^3.7.2: resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f" integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== -bn.js@^4.0.0: - version "4.12.5" - resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.5.tgz#74f119ffecd823168d188eae06d97ea40835c489" - integrity sha512-3aRg6/JxfffFD+OlOjOFR3Vo79l39ooBTFucxx+MT3dhCtzn3EmiUPQo+6/OZuI2jbXi3YKgmiTFBgChQMwIRQ== - body-parser@~1.20.5: version "1.20.6" resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.6.tgz#60c789c78e0992d906da0a29d71ae01d15c1ed76" @@ -3419,15 +3449,6 @@ caseless@~0.12.0: resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw== -chalk@^2.1.0: - version "2.4.2" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" - integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== - dependencies: - ansi-styles "^3.2.1" - escape-string-regexp "^1.0.5" - supports-color "^5.3.0" - chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" @@ -3456,11 +3477,6 @@ character-reference-invalid@^1.0.0: resolved "https://registry.yarnpkg.com/character-reference-invalid/-/character-reference-invalid-1.1.4.tgz#083329cda0eae272ab3dbbf37e9a382c13af1560" integrity sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg== -chardet@^0.7.0: - version "0.7.0" - resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e" - integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== - chart.js@4.5.1: version "4.5.1" resolved "https://registry.yarnpkg.com/chart.js/-/chart.js-4.5.1.tgz#19dd1a9a386a3f6397691672231cb5fc9c052c35" @@ -3530,13 +3546,6 @@ cjs-module-lexer@^2.1.0: resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-2.2.0.tgz#b3ca5101843389259ade7d88c77bd06ce55849ca" integrity sha512-4bHTS2YuzUvtoLjdy+98ykbNB5jS0+07EvFNXerqZQJ89F7DI6ET7OQo/HJuW6K0aVsKA9hj9/RVb2kQVOrPDQ== -cli-cursor@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-3.1.0.tgz#264305a7ae490d1d03bf0c9ba7c925d1753af307" - integrity sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw== - dependencies: - restore-cursor "^3.1.0" - cli-cursor@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-5.0.0.tgz#24a4831ecf5a6b01ddeb32fb71a4b2088b0dce38" @@ -3561,11 +3570,6 @@ cli-truncate@^5.0.0: slice-ansi "^8.0.0" string-width "^8.2.0" -cli-width@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-3.0.0.tgz#a2f48437a2caa9a22436e794bf071ec9e61cedf6" - integrity sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw== - cliui@^8.0.1: version "8.0.1" resolved "https://registry.yarnpkg.com/cliui/-/cliui-8.0.1.tgz#0c04b075db02cbfe60dc8e6cf2f5486b1a3608aa" @@ -3600,7 +3604,7 @@ collect-v8-coverage@^1.0.2: resolved "https://registry.yarnpkg.com/collect-v8-coverage/-/collect-v8-coverage-1.0.3.tgz#cc1f01eb8d02298cbc9a437c74c70ab4e5210b80" integrity sha512-1L5aqIkwPfiodaMgQunkF1zRhNqifHBmtbbbxcr6yVxxBnliw4TDOW6NxpO8DJLgJ16OT+Y4ztZqP6p/FtXnAw== -color-convert@^1.9.0, color-convert@^1.9.3: +color-convert@^1.9.3: version "1.9.3" resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg== @@ -3710,14 +3714,6 @@ confusing-browser-globals@^1.0.10: resolved "https://registry.yarnpkg.com/confusing-browser-globals/-/confusing-browser-globals-1.0.11.tgz#ae40e9b57cdd3915408a2805ebd3a5585608dc81" integrity sha512-JsPKdmh8ZkmnHxDk55FZ1TqVLvEQTvoByJZRN9jzI0UjxK/QgAmsphz7PGtqgPieQZ/CQcHWXCR7ATDNhGe+YA== -connect-mongo@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/connect-mongo/-/connect-mongo-6.0.0.tgz#47f9bd744bd1c205f9dd86402e6938d2a61ed418" - integrity sha512-mHxfnTiWk7ZtxmHdcrFBKlr7fCtgGoFpx/oe9jFW0yb2NinagsxEeuol78nUWMpnWyYK0nnuXMlU9wrgUjTE6g== - dependencies: - debug "^4.4.3" - kruptein "3.0.8" - content-disposition@~0.5.4: version "0.5.4" resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.4.tgz#8b82b4efac82512a02bb0b1dcec9d2c5e8eb5bfe" @@ -3781,18 +3777,7 @@ cosmiconfig@^7.0.0: path-type "^4.0.0" yaml "^1.10.0" -cross-spawn@^6.0.5: - version "6.0.6" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.6.tgz#30d0efa0712ddb7eb5a76e1e8721bffafa6b5d57" - integrity sha512-VqCUuhcd1iB+dsv8gxPttb5iZh/D0iubSP21g36KXdEuf6I5JiioesUVjpCdHV9MZRUfVFlvwtIUyPfxo5trtw== - dependencies: - nice-try "^1.0.4" - path-key "^2.0.1" - semver "^5.5.0" - shebang-command "^1.2.0" - which "^1.2.9" - -cross-spawn@^7.0.0, cross-spawn@^7.0.3, cross-spawn@^7.0.6: +cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3, cross-spawn@^7.0.6: version "7.0.6" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA== @@ -3970,7 +3955,7 @@ debug@2.6.9, debug@~2.6.9: dependencies: ms "2.0.0" -debug@4, debug@4.4.3, debug@4.x, debug@^4, debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4, debug@^4.3.6, debug@^4.4.3, debug@~4.4.1: +debug@4, debug@4.4.3, debug@4.x, debug@^4, debug@^4.0.0, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4, debug@^4.3.6, debug@^4.4.3, debug@~4.4.1: version "4.4.3" resolved "https://registry.yarnpkg.com/debug/-/debug-4.4.3.tgz#c6ae432d9bd9662582fce08709b038c58e9e3d6a" integrity sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA== @@ -4001,7 +3986,7 @@ dedent@^1.6.0: resolved "https://registry.yarnpkg.com/dedent/-/dedent-1.7.2.tgz#34e2264ab538301e27cf7b07bf2369c19baa8dd9" integrity sha512-WzMx3mW98SN+zn3hgemf4OzdmyNhhhKz5Ay0pUfQiMQ3e1g+xmTJWp/pKdwKVXhdSkAEGIIzqeuWrL3mV/AXbA== -deep-is@^0.1.3, deep-is@~0.1.3: +deep-is@^0.1.3: version "0.1.4" resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.4.tgz#a6f2dce612fadd2ef1f519b73551f17e85199831" integrity sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ== @@ -4217,11 +4202,6 @@ emoji-regex@^10.3.0: resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-10.6.0.tgz#bf3d6e8f7f8fd22a65d9703475bc0147357a6b0d" integrity sha512-toUI84YS5YmxW219erniWD0CIVOo46xGKColeNQRgOzDorgBi1v4D71/OFzgD9GO2UGKIv1C3Sp8DAn0+j5w7A== -emoji-regex@^7.0.1: - version "7.0.3" - resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156" - integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA== - emoji-regex@^8.0.0: version "8.0.0" resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" @@ -4468,11 +4448,6 @@ escape-html@~1.0.3: resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" integrity sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow== -escape-string-regexp@^1.0.5: - version "1.0.5" - resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" - integrity sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg== - escape-string-regexp@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz#a30304e99daa32e23b2fd20f51babd07cffca344" @@ -4590,13 +4565,13 @@ eslint-plugin-react@^7.37.5: string.prototype.matchall "^4.0.12" string.prototype.repeat "^1.0.0" -eslint-scope@^5.0.0: - version "5.1.1" - resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" - integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw== +eslint-scope@^7.2.2: + version "7.2.2" + resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-7.2.2.tgz#deb4f92563390f32006894af62a22dba1c46423f" + integrity sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg== dependencies: esrecurse "^4.3.0" - estraverse "^4.1.1" + estraverse "^5.2.0" eslint-scope@^8.4.0: version "8.4.0" @@ -4606,19 +4581,7 @@ eslint-scope@^8.4.0: esrecurse "^4.3.0" estraverse "^5.2.0" -eslint-utils@^1.4.3: - version "1.4.3" - resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-1.4.3.tgz#74fec7c54d0776b6f67e0251040b5806564e981f" - integrity sha512-fbBN5W2xdY45KulGXmLHZ3c3FHfVYmKg0IrAKGOkT/464PQsx2UeIzfz1RmEci+KLm1bBaAzZAh8+/E+XAeZ8Q== - dependencies: - eslint-visitor-keys "^1.1.0" - -eslint-visitor-keys@^1.1.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e" - integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ== - -eslint-visitor-keys@^3.4.3: +eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4.3: version "3.4.3" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz#0cd72fe8550e3c2eae156a96a4dddcd1c8ac5800" integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag== @@ -4628,48 +4591,49 @@ eslint-visitor-keys@^4.2.1: resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz#4cfea60fe7dd0ad8e816e1ed026c1d5251b512c1" integrity sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ== -eslint@6.8.0: - version "6.8.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.8.0.tgz#62262d6729739f9275723824302fb227c8c93ffb" - integrity sha512-K+Iayyo2LtyYhDSYwz5D5QdWw0hCacNzyq1Y821Xna2xSJj7cijoLLYmLxTQgcgZ9mC61nryMy9S7GRbYpI5Ig== +eslint@8.57.0: + version "8.57.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.57.0.tgz#c786a6fd0e0b68941aaf624596fb987089195668" + integrity sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ== dependencies: - "@babel/code-frame" "^7.0.0" - ajv "^6.10.0" - chalk "^2.1.0" - cross-spawn "^6.0.5" - debug "^4.0.1" + "@eslint-community/eslint-utils" "^4.2.0" + "@eslint-community/regexpp" "^4.6.1" + "@eslint/eslintrc" "^2.1.4" + "@eslint/js" "8.57.0" + "@humanwhocodes/config-array" "^0.11.14" + "@humanwhocodes/module-importer" "^1.0.1" + "@nodelib/fs.walk" "^1.2.8" + "@ungap/structured-clone" "^1.2.0" + ajv "^6.12.4" + chalk "^4.0.0" + cross-spawn "^7.0.2" + debug "^4.3.2" doctrine "^3.0.0" - eslint-scope "^5.0.0" - eslint-utils "^1.4.3" - eslint-visitor-keys "^1.1.0" - espree "^6.1.2" - esquery "^1.0.1" + escape-string-regexp "^4.0.0" + eslint-scope "^7.2.2" + eslint-visitor-keys "^3.4.3" + espree "^9.6.1" + esquery "^1.4.2" esutils "^2.0.2" - file-entry-cache "^5.0.1" - functional-red-black-tree "^1.0.1" - glob-parent "^5.0.0" - globals "^12.1.0" - ignore "^4.0.6" - import-fresh "^3.0.0" + fast-deep-equal "^3.1.3" + file-entry-cache "^6.0.1" + find-up "^5.0.0" + glob-parent "^6.0.2" + globals "^13.19.0" + graphemer "^1.4.0" + ignore "^5.2.0" imurmurhash "^0.1.4" - inquirer "^7.0.0" is-glob "^4.0.0" - js-yaml "^3.13.1" + is-path-inside "^3.0.3" + js-yaml "^4.1.0" json-stable-stringify-without-jsonify "^1.0.1" - levn "^0.3.0" - lodash "^4.17.14" - minimatch "^3.0.4" - mkdirp "^0.5.1" + levn "^0.4.1" + lodash.merge "^4.6.2" + minimatch "^3.1.2" natural-compare "^1.4.0" - optionator "^0.8.3" - progress "^2.0.0" - regexpp "^2.0.1" - semver "^6.1.2" - strip-ansi "^5.2.0" - strip-json-comments "^3.0.1" - table "^5.2.3" + optionator "^0.9.3" + strip-ansi "^6.0.1" text-table "^0.2.0" - v8-compile-cache "^2.0.3" eslint@^9.39.4: version "9.39.4" @@ -4720,21 +4684,21 @@ espree@^10.0.1, espree@^10.4.0: acorn-jsx "^5.3.2" eslint-visitor-keys "^4.2.1" -espree@^6.1.2: - version "6.2.1" - resolved "https://registry.yarnpkg.com/espree/-/espree-6.2.1.tgz#77fc72e1fd744a2052c20f38a5b575832e82734a" - integrity sha512-ysCxRQY3WaXJz9tdbWOwuWr5Y/XrPTGX9Kiz3yoUXwW0VZ4w30HTkQLaGx/+ttFjF8i+ACbArnB4ce68a9m5hw== +espree@^9.6.0, espree@^9.6.1: + version "9.6.1" + resolved "https://registry.yarnpkg.com/espree/-/espree-9.6.1.tgz#a2a17b8e434690a5432f2f8018ce71d331a48c6f" + integrity sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ== dependencies: - acorn "^7.1.1" - acorn-jsx "^5.2.0" - eslint-visitor-keys "^1.1.0" + acorn "^8.9.0" + acorn-jsx "^5.3.2" + eslint-visitor-keys "^3.4.1" esprima@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== -esquery@^1.0.1, esquery@^1.5.0: +esquery@^1.4.2, esquery@^1.5.0: version "1.7.0" resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.7.0.tgz#08d048f261f0ddedb5bae95f46809463d9c9496d" integrity sha512-Ap6G0WQwcU/LHsvLwON1fAQX9Zp0A2Y6Y/cJBl9r/JbW90Zyg4/zbG6zzKa2OTALELarYHmKu0GhpM5EO+7T0g== @@ -4748,11 +4712,6 @@ esrecurse@^4.3.0: dependencies: estraverse "^5.2.0" -estraverse@^4.1.1: - version "4.3.0" - resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.3.0.tgz#398ad3f3c5a24948be7725e83d11a7de28cdbd1d" - integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw== - estraverse@^5.1.0, estraverse@^5.2.0, estraverse@^5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.3.0.tgz#2eea5290702f26ab8fe5370370ff86c965d21123" @@ -4921,15 +4880,6 @@ extend@^3.0.0, extend@~3.0.2: resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa" integrity sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g== -external-editor@^3.0.3: - version "3.1.0" - resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495" - integrity sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew== - dependencies: - chardet "^0.7.0" - iconv-lite "^0.4.24" - tmp "^0.0.33" - extsprintf@1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05" @@ -4957,7 +4907,7 @@ fast-json-stable-stringify@^2.0.0, fast-json-stable-stringify@^2.1.0: resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw== -fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6: +fast-levenshtein@^2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" integrity sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw== @@ -4967,6 +4917,13 @@ fast-uri@^3.0.1: resolved "https://registry.yarnpkg.com/fast-uri/-/fast-uri-3.1.3.tgz#f695a40f006aba505631573a0021ddb21194ad11" integrity sha512-i70LwGWUduXqzicKXWshooq+sWL1K3WUU5rKZNG/0i3a1OSoX3HqhH5WbWwTmqWfor4urUakGPiRQcleRZTwOg== +fastq@^1.6.0: + version "1.20.1" + resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.20.1.tgz#ca750a10dc925bc8b18839fd203e3ef4b3ced675" + integrity sha512-GGToxJ/w1x32s/D2EKND7kTil4n8OVk/9mycTc4VDza13lOvpUZTGX3mFSCtV9ksdGBVzvsyAVLM6mHFThxXxw== + dependencies: + reusify "^1.0.4" + fb-watchman@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/fb-watchman/-/fb-watchman-2.0.2.tgz#e9524ee6b5c77e9e5001af0f85f3adbb8623255c" @@ -4989,19 +4946,12 @@ fflate@~0.8.2: resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.8.3.tgz#bc27d8eb30343d4d512abb03480202ce65d825fc" integrity sha512-tbZNuJrLwGUp3zshBtdy4W+ORxZuIh8a5ilyIEQDC5rY1f3U20JMry0Ll3WBzU58EZKsEuJFXhb5gwv8CsPvgA== -figures@^3.0.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/figures/-/figures-3.2.0.tgz#625c18bd293c604dc4a8ddb2febf0c88341746af" - integrity sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg== - dependencies: - escape-string-regexp "^1.0.5" - -file-entry-cache@^5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-5.0.1.tgz#ca0f6efa6dd3d561333fb14515065c2fafdf439c" - integrity sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g== +file-entry-cache@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027" + integrity sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg== dependencies: - flat-cache "^2.0.1" + flat-cache "^3.0.4" file-entry-cache@^8.0.0: version "8.0.0" @@ -5058,14 +5008,14 @@ find-up@^5.0.0: locate-path "^6.0.0" path-exists "^4.0.0" -flat-cache@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-2.0.1.tgz#5d296d6f04bda44a4630a301413bdbc2ec085ec0" - integrity sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA== +flat-cache@^3.0.4: + version "3.2.0" + resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.2.0.tgz#2c0c2d5040c99b1632771a9d105725c0115363ee" + integrity sha512-CYcENa+FtcUKLmhhqyctpclsq7QF38pKjZHsGNiSQF5r4FtoKDWabFDl3hzaEQMvT1LHEysw5twgLvpYYb4vbw== dependencies: - flatted "^2.0.0" - rimraf "2.6.3" - write "1.0.3" + flatted "^3.2.9" + keyv "^4.5.3" + rimraf "^3.0.2" flat-cache@^4.0.0: version "4.0.1" @@ -5075,11 +5025,6 @@ flat-cache@^4.0.0: flatted "^3.2.9" keyv "^4.5.4" -flatted@^2.0.0: - version "2.0.2" - resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138" - integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA== - flatted@^3.2.9: version "3.4.2" resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.4.2.tgz#f5c23c107f0f37de8dbdf24f13722b3b98d52726" @@ -5166,11 +5111,6 @@ function.prototype.name@^1.1.6, function.prototype.name@^1.1.8: is-callable "^1.2.7" is-document.all "^1.0.0" -functional-red-black-tree@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" - integrity sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g== - functions-have-names@^1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834" @@ -5285,13 +5225,6 @@ giget@^3.2.0: resolved "https://registry.yarnpkg.com/giget/-/giget-3.3.0.tgz#b70ee7a3c162c148867a8db918ee14d01b62dab7" integrity sha512-gzi2D96p+AMfDcmJHGDj3KJ9NRiwvlFAU5yfa3ROwWZmFUjX4P43x3BcyRaOMMLto1vUo7C+86+MFhYTl6Ryiw== -glob-parent@^5.0.0, glob-parent@~5.1.2: - version "5.1.2" - resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" - integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow== - dependencies: - is-glob "^4.0.1" - glob-parent@^6.0.2: version "6.0.2" resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-6.0.2.tgz#6d237d99083950c79290f24c7642a3de9a28f9e3" @@ -5299,6 +5232,13 @@ glob-parent@^6.0.2: dependencies: is-glob "^4.0.3" +glob-parent@~5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" + integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow== + dependencies: + is-glob "^4.0.1" + glob@^10.5.0: version "10.5.0" resolved "https://registry.yarnpkg.com/glob/-/glob-10.5.0.tgz#8ec0355919cd3338c28428a23d4f24ecc5fe738c" @@ -5342,12 +5282,12 @@ global-dirs@^3.0.0: dependencies: ini "2.0.0" -globals@^12.1.0: - version "12.4.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-12.4.0.tgz#a18813576a41b00a24a97e7f815918c2e19925f8" - integrity sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg== +globals@^13.19.0: + version "13.24.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-13.24.0.tgz#8432a19d78ce0c1e833949c36adb345400bb1171" + integrity sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ== dependencies: - type-fest "^0.8.1" + type-fest "^0.20.2" globals@^14.0.0: version "14.0.0" @@ -5382,6 +5322,11 @@ grammex@^3.1.11: resolved "https://registry.yarnpkg.com/grammex/-/grammex-3.1.13.tgz#dbcfe00273a282068c2c3dea30722cdb4a26f9ed" integrity sha512-LnPnhOBLEJEVKS8WFDVaA397L9Kq55Q9oSITJiVLHVdhAclfUkWzQv74KhvZHKL2Q09Pb1XdsrOsZ4LfTFFTEg== +graphemer@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/graphemer/-/graphemer-1.4.0.tgz#fb2f1d55e0e3a1849aeffc90c4fa0dd53a0e66c6" + integrity sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag== + graphmatch@^1.1.0: version "1.1.1" resolved "https://registry.yarnpkg.com/graphmatch/-/graphmatch-1.1.1.tgz#dcec68e8cb74de0a372d5252fc06e241daf71c38" @@ -5574,13 +5519,6 @@ iconv-lite@0.6.3: dependencies: safer-buffer ">= 2.1.2 < 3.0.0" -iconv-lite@^0.4.24, iconv-lite@~0.4.24: - version "0.4.24" - resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" - integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== - dependencies: - safer-buffer ">= 2.1.2 < 3" - iconv-lite@^0.7.0: version "0.7.3" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.7.3.tgz#84ee12f963e7de50bc01a13e160a078b3b0f415f" @@ -5588,6 +5526,13 @@ iconv-lite@^0.7.0: dependencies: safer-buffer ">= 2.1.2 < 3.0.0" +iconv-lite@~0.4.24: + version "0.4.24" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" + integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== + dependencies: + safer-buffer ">= 2.1.2 < 3" + idb@^7.0.1: version "7.1.1" resolved "https://registry.yarnpkg.com/idb/-/idb-7.1.1.tgz#d910ded866d32c7ced9befc5bfdf36f572ced72b" @@ -5610,17 +5555,12 @@ ignore-by-default@^1.0.1: resolved "https://registry.yarnpkg.com/ignore-by-default/-/ignore-by-default-1.0.1.tgz#48ca6d72f6c6a3af00a9ad4ae6876be3889e2b09" integrity sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA== -ignore@^4.0.6: - version "4.0.6" - resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" - integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg== - ignore@^5.2.0: version "5.3.2" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.2.tgz#3cd40e729f3643fd87cb04e50bf0eb722bc596f5" integrity sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g== -import-fresh@^3.0.0, import-fresh@^3.2.1: +import-fresh@^3.2.1: version "3.3.1" resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.1.tgz#9cecb56503c0ada1f2741dbbd6546e4b13b57ccf" integrity sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ== @@ -5654,7 +5594,7 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.4: +inherits@2, inherits@^2.0.3, inherits@~2.0.4: version "2.0.4" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== @@ -5669,25 +5609,6 @@ inline-style-parser@0.1.1: resolved "https://registry.yarnpkg.com/inline-style-parser/-/inline-style-parser-0.1.1.tgz#ec8a3b429274e9c0a1f1c4ffa9453a7fef72cea1" integrity sha512-7NXolsK4CAS5+xvdj5OMMbI962hU/wvwoxk+LWR9Ek9bVtyuuYScDN6eS0rUm6TxApFpw7CX1o4uJzcd4AyD3Q== -inquirer@^7.0.0: - version "7.3.3" - resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.3.3.tgz#04d176b2af04afc157a83fd7c100e98ee0aad003" - integrity sha512-JG3eIAj5V9CwcGvuOmoo6LB9kbAYT8HXffUl6memuszlwDC/qvFAJw49XJ5NROSFNPxp3iQg1GqkFhaY/CR0IA== - dependencies: - ansi-escapes "^4.2.1" - chalk "^4.1.0" - cli-cursor "^3.1.0" - cli-width "^3.0.0" - external-editor "^3.0.3" - figures "^3.0.0" - lodash "^4.17.19" - mute-stream "0.0.8" - run-async "^2.4.0" - rxjs "^6.6.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - through "^2.3.6" - internal-slot@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.1.0.tgz#1eac91762947d2f7056bc838d93e13b2e9604961" @@ -5843,11 +5764,6 @@ is-finalizationregistry@^1.1.0: dependencies: call-bound "^1.0.3" -is-fullwidth-code-point@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" - integrity sha512-VHskAKYM8RfSFXwee5t5cbN5PZeq1Wrh6qd5bkyiXIf6UQcN6w/A0eXM9r6t8d+GYOh+o6ZhiEnb88LN/Y8m2w== - is-fullwidth-code-point@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" @@ -5934,7 +5850,7 @@ is-obj@^1.0.1: resolved "https://registry.yarnpkg.com/is-obj/-/is-obj-1.0.1.tgz#3e4729ac1f5fde025cd7d83a896dab9f4f67db0f" integrity sha512-l4RyHgRqGN4Y3+9JHVrNqO+tN0rV5My76uW5/nuO4K1b6vw5G8d/cmFjP9tRfEsdhZNt0IFdZuK/c2Vr4Nb+Qg== -is-path-inside@^3.0.2: +is-path-inside@^3.0.2, is-path-inside@^3.0.3: version "3.0.3" resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-3.0.3.tgz#d231362e53a07ff2b0e0ea7fed049161ffd16283" integrity sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ== @@ -6579,7 +6495,7 @@ js-yaml@^3.13.1: argparse "^1.0.7" esprima "^4.0.0" -js-yaml@^4.1.1: +js-yaml@^4.1.0, js-yaml@^4.1.1: version "4.3.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.3.0.tgz#d1900572a7f7cf0b5f540c83673e60bad3436592" integrity sha512-1td788aAnnZ5qs7V2QIRl1owjtYpbKt749Y3xauqQgwIIGF/xXWz1wMTEBx5O3LK3lXLVuqXPdPxj2BoFHaW9Q== @@ -6778,7 +6694,7 @@ kareem@2.6.3: resolved "https://registry.yarnpkg.com/kareem/-/kareem-2.6.3.tgz#23168ec8ffb6c1abfd31b7169a6fb1dd285992ac" integrity sha512-C3iHfuGUXK2u8/ipq9LfjFfXFxAZMQJJq7vLS45r3D9Y2xQ/m4S8zaR4zMLFWh9AsNPXmcFfUDhTEO8UIC/V6Q== -keyv@^4.5.4: +keyv@^4.5.3, keyv@^4.5.4: version "4.5.4" resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.5.4.tgz#a879a99e29452f942439f2a405e3af8b31d4de93" integrity sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw== @@ -6793,13 +6709,6 @@ kill-port@1.6.0: get-them-args "^1.3.1" shell-exec "^1.0.2" -kruptein@3.0.8: - version "3.0.8" - resolved "https://registry.yarnpkg.com/kruptein/-/kruptein-3.0.8.tgz#e5f392809bfcd36d381ec069ac5c3d155b6e0a09" - integrity sha512-0CyalFA0Cjp3jnziMp0u1uLZW2/ouhQ0mEMfYlroBXNe86na1RwAuwBcdRAegeWZNMfQy/G5fN47g/Axjtqrfw== - dependencies: - asn1.js "^5.4.1" - kuler@1.0.x: version "1.0.1" resolved "https://registry.yarnpkg.com/kuler/-/kuler-1.0.1.tgz#ef7c784f36c9fb6e16dd3150d152677b2b0228a6" @@ -6824,14 +6733,6 @@ leven@^3.1.0: resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2" integrity sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A== -levn@^0.3.0, levn@~0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" - integrity sha512-0OO4y2iOHix2W6ujICbKIaEQXvFQHue65vUG3pb5EUomzPI90z9hsA1VsO/dbIIpC53J8gxM9Q4Oho0jrCM/yA== - dependencies: - prelude-ls "~1.1.2" - type-check "~0.3.2" - levn@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/levn/-/levn-0.4.1.tgz#ae4562c007473b932a6200d403268dd2fffc6ade" @@ -6965,7 +6866,7 @@ lodash.sortby@^4.7.0: resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" integrity sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA== -lodash@^4.17.14, lodash@^4.17.19, lodash@^4.17.21, lodash@^4.17.23: +lodash@^4.17.14, lodash@^4.17.21, lodash@^4.17.23: version "4.18.1" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.18.1.tgz#ff2b66c1f6326d59513de2407bf881439812771c" integrity sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q== @@ -7198,11 +7099,6 @@ min-indent@^1.0.0: resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.1.tgz#a63f681673b30571fbe8bc25686ae746eefa9869" integrity sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg== -minimalistic-assert@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7" - integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A== - minimatch@^10.1.1, minimatch@^10.2.1: version "10.2.5" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-10.2.5.tgz#bd48687a0be38ed2961399105600f832095861d1" @@ -7210,7 +7106,7 @@ minimatch@^10.1.1, minimatch@^10.2.1: dependencies: brace-expansion "^5.0.5" -minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2, minimatch@^3.1.5: +minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2, minimatch@^3.1.5: version "3.1.5" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.5.tgz#580c88f8d5445f2bd6aa8f3cadefa0de79fbd69e" integrity sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w== @@ -7241,13 +7137,6 @@ minimist@^1.2.0, minimist@^1.2.6, minimist@^1.2.8: resolved "https://registry.yarnpkg.com/minipass/-/minipass-7.1.3.tgz#79389b4eb1bb2d003a9bba87d492f2bd37bdc65b" integrity sha512-tEBHqDnIoM/1rXME1zgka9g6Q2lcoCkxHLuc7ODJ5BxbP5d4c2Z5cGgtXAku59200Cx7diuHTOYfSBD8n6mm8A== -mkdirp@^0.5.1: - version "0.5.6" - resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.6.tgz#7def03d2432dcae4ba1d611445c48396062255f6" - integrity sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw== - dependencies: - minimist "^1.2.6" - mongodb-connection-string-url@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.2.tgz#e223089dfa0a5fa9bf505f8aedcbc67b077b33e7" @@ -7256,15 +7145,6 @@ mongodb-connection-string-url@^3.0.2: "@types/whatwg-url" "^11.0.2" whatwg-url "^14.1.0 || ^13.0.0" -mongodb@^6.21.0: - version "6.21.0" - resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-6.21.0.tgz#f83355905900f2e7a912593f0315d5e2e0bda576" - integrity sha512-URyb/VXMjJ4da46OeSXg+puO39XH9DeQpWCslifrRn9JWugy0D+DvvBvkm2WxmHe61O/H19JM66p1z7RHVkZ6A== - dependencies: - "@mongodb-js/saslprep" "^1.3.0" - bson "^6.10.4" - mongodb-connection-string-url "^3.0.2" - mongodb@~6.20.0: version "6.20.0" resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-6.20.0.tgz#5212dcf512719385287aa4574265352eefb01d8e" @@ -7320,11 +7200,6 @@ ms@2.1.3, ms@^2.1.1, ms@^2.1.3: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== -mute-stream@0.0.8: - version "0.0.8" - resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" - integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA== - mysql2@3.15.3: version "3.15.3" resolved "https://registry.yarnpkg.com/mysql2/-/mysql2-3.15.3.tgz#f0348d9c7401bb98cb1f45ffc5a773b109f70808" @@ -7367,11 +7242,6 @@ negotiator@0.6.3: resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.3.tgz#58e323a72fedc0d6f9cd4d31fe49f51479590ccd" integrity sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg== -nice-try@^1.0.4: - version "1.0.5" - resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" - integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== - node-addon-api@^8.3.0: version "8.9.0" resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-8.9.0.tgz#d2467090e6195c428ccd510dfd604f01c027f0a0" @@ -7561,18 +7431,6 @@ onetime@^7.0.0: dependencies: mimic-function "^5.0.0" -optionator@^0.8.3: - version "0.8.3" - resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495" - integrity sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA== - dependencies: - deep-is "~0.1.3" - fast-levenshtein "~2.0.6" - levn "~0.3.0" - prelude-ls "~1.1.2" - type-check "~0.3.2" - word-wrap "~1.2.3" - optionator@^0.9.3: version "0.9.4" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.4.tgz#7ea1c1a5d91d764fb282139c88fe11e182a3a734" @@ -7585,11 +7443,6 @@ optionator@^0.9.3: type-check "^0.4.0" word-wrap "^1.2.5" -os-tmpdir@~1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" - integrity sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g== - ospath@^1.2.2: version "1.2.2" resolved "https://registry.yarnpkg.com/ospath/-/ospath-1.2.2.tgz#1276639774a3f8ef2572f7fe4280e0ea4550c07b" @@ -7747,11 +7600,6 @@ path-is-absolute@^1.0.0: resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" integrity sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg== -path-key@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" - integrity sha512-fEHGKCSmUSDPv4uoj8AlD+joPlq3peND+HRYyxFz4KPw4z926S/b8rIuFs2FYJg3BwsxJf6A9/3eIdLaYC+9Dw== - path-key@^3.0.0, path-key@^3.1.0: version "3.1.1" resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" @@ -7963,11 +7811,6 @@ prelude-ls@^1.2.1: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== -prelude-ls@~1.1.2: - version "1.1.2" - resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" - integrity sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w== - pretty-bytes@^5.3.0, pretty-bytes@^5.6.0: version "5.6.0" resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz#356256f643804773c82f64723fe78c92c62beaeb" @@ -8023,11 +7866,6 @@ process@^0.11.10: resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A== -progress@^2.0.0: - version "2.0.3" - resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" - integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== - prop-types@15.8.1, prop-types@^15.6.2, prop-types@^15.7.2, prop-types@^15.8.1: version "15.8.1" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5" @@ -8102,6 +7940,11 @@ qs@^6.15.2, qs@^6.9.6, qs@~6.15.1: es-define-property "^1.0.1" side-channel "^1.1.1" +queue-microtask@^1.2.2: + version "1.2.3" + resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243" + integrity sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A== + random-bytes@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/random-bytes/-/random-bytes-1.0.0.tgz#4f68a1dc0ae58bd3fb95848c30324db75d64360b" @@ -8374,11 +8217,6 @@ regexp.prototype.flags@^1.5.3, regexp.prototype.flags@^1.5.4: gopd "^1.2.0" set-function-name "^2.0.2" -regexpp@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f" - integrity sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw== - regexpu-core@^6.3.1: version "6.4.0" resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-6.4.0.tgz#3580ce0c4faedef599eccb146612436b62a176e5" @@ -8493,14 +8331,6 @@ rest-api-errors@^1.2.1: resolved "https://registry.yarnpkg.com/rest-api-errors/-/rest-api-errors-1.3.1.tgz#a206da021bcc908b716e2208063f09e052c49b40" integrity sha512-BLUjvPne9dREGjnF9oNdmoyjGUNd3G+I14Z0ulMyGppKnLSQw58fXk5I8X0QLZZcBV89M/D+ndHVdto9QuF8sQ== -restore-cursor@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-3.1.0.tgz#39f67c54b3a7a58cea5236d95cf0034239631f7e" - integrity sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA== - dependencies: - onetime "^5.1.0" - signal-exit "^3.0.2" - restore-cursor@^5.0.0: version "5.1.0" resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-5.1.0.tgz#0766d95699efacb14150993f55baf0953ea1ebe7" @@ -8514,15 +8344,20 @@ retry@^0.12.0: resolved "https://registry.yarnpkg.com/retry/-/retry-0.12.0.tgz#1b42a6266a21f07421d1b0b54b7dc167b01c013b" integrity sha512-9LkiTwjUh6rT555DtE9rTX+BKByPfrMzEAtnlEtdEwr3Nkffwiihqe2bWADg+OQRjt9gl6ICdmB/ZFDCGAtSow== +reusify@^1.0.4: + version "1.1.0" + resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.1.0.tgz#0fe13b9522e1473f51b558ee796e08f11f9b489f" + integrity sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw== + rfdc@^1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/rfdc/-/rfdc-1.4.1.tgz#778f76c4fb731d93414e8f925fbecf64cce7f6ca" integrity sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA== -rimraf@2.6.3: - version "2.6.3" - resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab" - integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA== +rimraf@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a" + integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA== dependencies: glob "^7.1.3" @@ -8589,17 +8424,12 @@ rrweb-cssom@^0.8.0: resolved "https://registry.yarnpkg.com/rrweb-cssom/-/rrweb-cssom-0.8.0.tgz#3021d1b4352fbf3b614aaeed0bc0d5739abe0bc2" integrity sha512-guoltQEx+9aMf2gDZ0s62EcV8lsXR+0w8915TC3ITdn2YueuNjdAYh/levpU9nFaoChh9RUS5ZdQMrKfVEN9tw== -run-async@^2.4.0: - version "2.4.1" - resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455" - integrity sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ== - -rxjs@^6.6.0: - version "6.6.7" - resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.7.tgz#90ac018acabf491bf65044235d5863c4dab804c9" - integrity sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ== +run-parallel@^1.1.9: + version "1.2.0" + resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee" + integrity sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA== dependencies: - tslib "^1.9.0" + queue-microtask "^1.2.2" safe-array-concat@^1.1.3: version "1.1.4" @@ -8670,12 +8500,7 @@ scrambow@^1.8.1: dependencies: commander "^8.2.0" -semver@^5.5.0: - version "5.7.2" - resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8" - integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g== - -semver@^6.1.2, semver@^6.3.0, semver@^6.3.1: +semver@^6.3.0, semver@^6.3.1: version "6.3.1" resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== @@ -8760,13 +8585,6 @@ setprototypeof@1.2.0, setprototypeof@~1.2.0: resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424" integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw== -shebang-command@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" - integrity sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg== - dependencies: - shebang-regex "^1.0.0" - shebang-command@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" @@ -8774,11 +8592,6 @@ shebang-command@^2.0.0: dependencies: shebang-regex "^3.0.0" -shebang-regex@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" - integrity sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ== - shebang-regex@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" @@ -8863,15 +8676,6 @@ slash@^3.0.0: resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q== -slice-ansi@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-2.1.0.tgz#cacd7693461a637a5788d92a7dd4fba068e81636" - integrity sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ== - dependencies: - ansi-styles "^3.2.0" - astral-regex "^1.0.0" - is-fullwidth-code-point "^2.0.0" - slice-ansi@^7.1.0: version "7.1.2" resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-7.1.2.tgz#adf7be70aa6d72162d907cd0e6d5c11f507b5403" @@ -9069,15 +8873,6 @@ string-length@^4.0.2: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.1" -string-width@^3.0.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961" - integrity sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w== - dependencies: - emoji-regex "^7.0.1" - is-fullwidth-code-point "^2.0.0" - strip-ansi "^5.1.0" - string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" @@ -9205,13 +9000,6 @@ stringify-object@^3.3.0: dependencies: ansi-regex "^5.0.1" -strip-ansi@^5.1.0, strip-ansi@^5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae" - integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA== - dependencies: - ansi-regex "^4.1.0" - strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" @@ -9253,7 +9041,7 @@ strip-indent@^3.0.0: dependencies: min-indent "^1.0.0" -strip-json-comments@^3.0.1, strip-json-comments@^3.1.1: +strip-json-comments@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== @@ -9270,7 +9058,7 @@ stylis@4.2.0: resolved "https://registry.yarnpkg.com/stylis/-/stylis-4.2.0.tgz#79daee0208964c8fe695a42fcffcac633a211a51" integrity sha512-Orov6g6BB1sDfYgzWfTHDOxamtX1bE/zo104Dh9e6fqJ3PooipYyfJ0pUmrZO2wAvO8YbEyeFrkV91XTsGMSrw== -supports-color@^5.3.0, supports-color@^5.5.0: +supports-color@^5.5.0: version "5.5.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow== @@ -9313,16 +9101,6 @@ systeminformation@^5.31.1: resolved "https://registry.yarnpkg.com/systeminformation/-/systeminformation-5.31.15.tgz#1b5542b478d13a660cc65ba9881c8f9a132a125a" integrity sha512-7mqCtD28TK5dVdLAQONVa/Do/NBgMH2dxqf49nh6DIKoEWuDg6tkgGBP+dN22VEJVPZa/QqiHomhWNRn4WUNTQ== -table@^5.2.3: - version "5.4.6" - resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e" - integrity sha512-wmEc8m4fjnob4gt5riFRtTu/6+4rSe12TpAELNSqHMfF3IqnA+CH37USM6/YR3qRZv7e56kAEAtd6nKZaxe0Ug== - dependencies: - ajv "^6.10.2" - lodash "^4.17.14" - slice-ansi "^2.1.0" - string-width "^3.0.0" - tagged-tag@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/tagged-tag/-/tagged-tag-1.0.0.tgz#a0b5917c2864cba54841495abfa3f6b13edcf4d6" @@ -9382,11 +9160,6 @@ throttleit@^1.0.0: resolved "https://registry.yarnpkg.com/throttleit/-/throttleit-1.0.1.tgz#304ec51631c3b770c65c6c6f76938b384000f4d5" integrity sha512-vDZpf9Chs9mAdfY046mcPt8fg5QSZr37hEH4TXYBnDF+izxgrbRGUAAaBvIk/fJm9aOFCGFd1EsNg5AZCbnQCQ== -through@^2.3.6: - version "2.3.8" - resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" - integrity sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg== - tiny-invariant@^1.0.2: version "1.3.3" resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.3.3.tgz#46680b7a873a0d5d10005995eb90a70d74d60127" @@ -9417,13 +9190,6 @@ tldts@^6.1.32: dependencies: tldts-core "^6.1.86" -tmp@^0.0.33: - version "0.0.33" - resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" - integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw== - dependencies: - os-tmpdir "~1.0.2" - tmp@~0.2.4: version "0.2.7" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.7.tgz#26f4db11d1601ce8012dcb8a798ece1c06a99059" @@ -9497,7 +9263,7 @@ tsconfig-paths@^3.15.0: minimist "^1.2.6" strip-bom "^3.0.0" -tslib@1.14.1, tslib@^1.9.0: +tslib@1.14.1: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== @@ -9543,13 +9309,6 @@ type-check@^0.4.0, type-check@~0.4.0: dependencies: prelude-ls "^1.2.1" -type-check@~0.3.2: - version "0.3.2" - resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72" - integrity sha512-ZCmOJdvOWDBYJlzAoFkC+Q0+bUyEOS1ltgp1MGU03fqHG+dbi9tBFU2Rd9QKiDZFAYrhPh2JUf7rZRIuHRKtOg== - dependencies: - prelude-ls "~1.1.2" - type-detect@4.0.8: version "4.0.8" resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" @@ -9560,12 +9319,17 @@ type-fest@^0.16.0: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.16.0.tgz#3240b891a78b0deae910dbeb86553e552a148860" integrity sha512-eaBzG6MxNzEn9kiwvtre90cXaNLkmadMWa1zQMs3XORCXNbsH/OewwbxC5ia9dCxIxnTAsSxXJaa/p5y8DlvJg== +type-fest@^0.20.2: + version "0.20.2" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4" + integrity sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ== + type-fest@^0.21.3: version "0.21.3" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37" integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== -type-fest@^0.8.0, type-fest@^0.8.1: +type-fest@^0.8.0: version "0.8.1" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== @@ -9853,11 +9617,6 @@ uuid@^11.1.1: resolved "https://registry.yarnpkg.com/uuid/-/uuid-11.1.1.tgz#f6d81d2e1c65d00762e5e29b16c5d2d995e208ad" integrity sha512-vIYxrBCC/N/K+Js3qSN88go7kIfNPssr/hHCesKCQNAjmgvYS2oqr69kIufEG+O4+PfezOH4EbIeHCfFov8ZgQ== -v8-compile-cache@^2.0.3: - version "2.4.0" - resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.4.0.tgz#cdada8bec61e15865f05d097c5f4fd30e94dc128" - integrity sha512-ocyWc3bAHBB/guyqJQVI5o4BZkPhznPYUG2ea80Gond/BgNWpap8TOmLSeeQG7bnh2KMISxskdADG59j7zruhw== - v8-to-istanbul@^9.0.1: version "9.3.0" resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz#b9572abfa62bd556c16d75fdebc1a411d5ff3175" @@ -10039,13 +9798,6 @@ which-typed-array@^1.1.16, which-typed-array@^1.1.19: gopd "^1.2.0" has-tostringtag "^1.0.2" -which@^1.2.9: - version "1.3.1" - resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" - integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ== - dependencies: - isexe "^2.0.0" - which@^2.0.1: version "2.0.2" resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" @@ -10077,7 +9829,7 @@ winston@3.2.1: triple-beam "^1.3.0" winston-transport "^4.3.0" -word-wrap@^1.2.5, word-wrap@~1.2.3: +word-wrap@^1.2.5: version "1.2.5" resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34" integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA== @@ -10289,13 +10041,6 @@ write-file-atomic@^5.0.1: imurmurhash "^0.1.4" signal-exit "^4.0.1" -write@1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/write/-/write-1.0.3.tgz#0800e14523b923a387e415123c865616aae0f5c3" - integrity sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig== - dependencies: - mkdirp "^0.5.1" - ws@^8.18.0, ws@~8.21.0: version "8.21.0" resolved "https://registry.yarnpkg.com/ws/-/ws-8.21.0.tgz#012e413fc07429945121b0c153158c4343086951"