Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Submit feedback
    • Contribute to GitLab
  • Sign in
U
upgrade-data-crawler-be
  • Project
    • Project
    • Details
    • Activity
    • Releases
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 0
    • Issues 0
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • ThinhNC
  • upgrade-data-crawler-be
  • Merge Requests
  • !3

Merged
Opened Sep 03, 2026 by ThinhNC@ThinhNC
  • Report abuse
Report abuse

feat(core): implement essential saas and crawler lifecycle features

Implement Core Missing SaaS & Crawler Lifecycle Features

Overview

This pull request implements 5 essential features required for a production-grade Data Crawler / SaaS backend, following the 5-layer architectural pattern (Route -> Controller -> Service -> Repository -> Prisma) defined in AGENTS.md.


Key Features Added

1. User Profile & Quota Usage Monitoring

  • Avatar Support: Added nullable avatarUrl to model User in prisma/schema.prisma (migration: 20260903000000_add_user_avatar_url) and supported profile updates via PUT /api/v1/auth/me.
  • Quota & Usage Endpoint (GET /api/v1/auth/me/usage): Computes real-time daily quota consumption based on business timezone Asia/Ho_Chi_Minh (UTC+7), tracking today's executed jobs, remaining jobs, active concurrent crawls, and total pages extracted.

2. Crawl Job Lifecycle (Delete & Re-run)

  • Job Deletion (DELETE /api/v1/crawl-jobs/:id): Enforces tenant ownership checks to prevent IDOR, guards against deleting active RUNNING jobs, cleans up associated export and diff files from storage (Local / S3), and cascades record deletion atomically in a database transaction.
  • Job Re-run / Retry (POST /api/v1/crawl-jobs/:id/rerun): Clones existing job configuration (startUrl, mode, maxPages, maxDepth, urls), validates quota limits, and enqueues a new job into BullMQ.

3. Job Execution Logging (CrawlJobLog)

  • Worker Step-by-Step Logging: The BullMQ worker processor (crawl.worker.processor.ts) records lifecycle checkpoints (INITIALIZE, FETCH, PROCESS, EXPORT, DIFF, COMPLETED, FAILED) into crawl_job_logs.
  • Logs Inspection (GET /api/v1/crawl-jobs/:id/logs): Paginated endpoint for frontend clients to inspect granular execution logs chronologically.

4. Webhook Management & Testing

  • Ping Test (POST /api/v1/webhooks/configs/:id/test): Sends a mock test.ping payload with an HMAC-SHA256 signature (X-Webhook-Signature) to the user's destination URL and records execution metrics in webhook_deliveries.
  • Config Update (PATCH /api/v1/webhooks/configs/:id): Allows modifying URL, subscribed events, active state, or secrets (automatically re-encrypted with AES-256-GCM) without losing past delivery history.

5. Dashboard Analytics & Export Storage Management

  • Dashboard Stats (GET /api/v1/dashboard/stats): Aggregates platform metrics including job counts by status, pages scraped (success vs. failure), active scheduled crawls, and quota balances.
  • Export Management: Added GET /api/v1/exports (paginated listing of user export archives) and DELETE /api/v1/exports/:id (removes archive file from storage and purges database record).

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch origin
git checkout -b feat/core-saas-crawler-features origin/feat/core-saas-crawler-features

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git fetch origin
git checkout origin/develop
git merge --no-ff feat/core-saas-crawler-features

Step 4. Push the result of the merge to GitLab

git push origin develop

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

  • Discussion 0
  • Commits 1
  • Changes 54
Assignee
No assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
0
Labels
None
Assign labels
  • View project labels
Reference: ThinhNC/upgrade-data-crawler-be!3

Revert this merge request

This will create a new commit in order to revert the existing changes.

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.

Cherry-pick this merge request

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.