Skip to content

refactor(builder): move growth, comment automation, media library and workspace data access into business - #1098

Merged
realcodesiman merged 5 commits into
mainfrom
refactor/data-access-builder-growth-workspace
Sep 11, 2026
Merged

refactor(builder): move growth, comment automation, media library and workspace data access into business#1098
realcodesiman merged 5 commits into
mainfrom
refactor/data-access-builder-growth-workspace

Conversation

@realcodesiman

Copy link
Copy Markdown
Contributor

Summary

  • Removes every direct db.* call from reflinks, QR codes, magic links, spreadsheets, fb/ig comment and ig story automations, the media library, the presigned-upload route, workspace members, invitations, error logs, audit logs and the session auth helper, per .agents/rules/data-access.md.
  • One of seven parallel scope PRs following feat(contacts): cover full public API for MCP, move logic into business services #1093 (contacts); all are based on main and only append to the shared barrels.

Changes

  • New repositories: reflink, media-library-folder, media-library-file (the last also exists on feat(contacts): cover full public API for MCP, move logic into business services #1093; keep one copy when merging). New services: magic-link, media-library, invitation; listErrorLogs and listAuditLogs query functions; methods appended to reflink, qr-code, spreadsheet, fb-comment-automation, ig-story-automation, workspace-member, user services and the contact-inbox/file repositories.
  • apps/builder/src/lib/auth/utils.ts: the membership read now goes through workspaceMemberService.listByUserIdUncached (the uncached variant, so the workspace auth gate keeps its immediate-revocation behavior). Nothing else in that file changes.
  • app/r/[workspaceId]/[name]/route.ts (public): only the two lookups are swapped; every response branch and the unattributed-click warn log are unchanged.
  • validationException added to packages/business/src/errors.ts in the same plain-factory/400 form as feat(contacts): cover full public API for MCP, move logic into business services #1093.
  • Dead features/users/queries deleted (zero callers).

Notes for reviewers

  • Behavior change: getFbComment/getIgComment/getIgStory now throw notFoundException (404) instead of a bare Error (500); same messages, and the only caller swallows the error.
  • The builder-level media-library-mutations.test.ts mocks the service inline; the real service is covered by packages/business/__tests__/media-library.service.test.ts.
  • Out of scope (still use db): the sibling update-*/delete-* actions in these features; listed in the plan as follow-ups.

Test plan

  • pnpm --filter @chatbotx.io/database check-types && test
  • pnpm --filter @chatbotx.io/business check-types && test (only the pre-existing ads-conversion-rule.service.test.ts failures remain, also red on main)
  • pnpm --filter builder check-types && test
  • pnpm lint
  • Manual: duplicate-name create → inline field error; /r/<ws>/<name> with and without ?code= → 302; media-library upload/move/favourite/delete folder; change a member role; accept an invitation

@github-actions github-actions Bot added the improvement Refactor or performance improvement label Sep 6, 2026
@realcodesiman
realcodesiman force-pushed the refactor/data-access-builder-growth-workspace branch from 5be4754 to a055c80 Compare September 11, 2026 12:25
realcodesiman and others added 4 commits September 12, 2026 02:16
… workspace data access into business

Removes direct db usage from reflinks, QR codes, magic links,
spreadsheets, fb/ig comment and ig story automations, the media
library, presigned upload, workspace members, invitations, error logs,
audit logs and the session auth helper per .agents/rules/data-access.md.

- new reflink and media-library-folder repositories; new magic-link,
  media-library and invitation services; listErrorLogs and
  listAuditLogs query functions
- lib/auth/utils.ts uses workspaceMemberService.listByUserIdUncached so
  the workspace auth gate stays uncached
- the public /r/[workspaceId]/[name] route only swaps its two lookups;
  every response branch is unchanged
- validationException added to errors.ts in the same form as #1093
- fb/ig comment and ig story detail lookups now throw notFoundException
  (404) instead of a bare Error (500)
- delete dead features/users/queries (zero callers)
… and file/user data access into business

Continues the data-access layering pass: media-library mutations and folder
listing move from app-layer queries into mediaLibraryService, file creation
moves into a new fileService, broadcast/sequence public APIs call their
service directly instead of app-layer query wrappers, error-logs queries are
replaced by the business layer's listErrorLogs, and worker quota sync uses
userService instead of a raw db query. Deduplicates broadcast-contact
resolution (private and public routes had already drifted) into a shared
list-broadcast-contacts helper.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
logger.warn(error, msg) drops the stack trace since pino's serializer
keys on `err`, not a bare error argument.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…kspace

Add workspace_id filters to media-library file delete/favourite and
workspace-member update queries, closing cross-workspace write paths.
Also relocates QR code item caching to the builder-only findQrCode query
(the public QR landing page reads uncached to avoid stale redirects),
splits safe-action error logging by status code, and adds a snapshot
guard plus scoping tests for comment-automation and QR code listings.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@realcodesiman
realcodesiman force-pushed the refactor/data-access-builder-growth-workspace branch from c5d84e5 to 067da43 Compare September 11, 2026 19:26
…dling into service layer

SmtpService.update/connect/disconnect now merge auth, diff for changes,
and record audit entries internally instead of duplicating that logic
in builder actions — keeping public/private callers of the same method
in sync. ZaloIntegrationService no longer throws on a same-workspace
re-connect; it returns without an integration id and lets the builder
action decide the redirect, since a service must not call redirect().

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@realcodesiman
realcodesiman merged commit 9603201 into main Sep 11, 2026
4 checks passed
@realcodesiman
realcodesiman deleted the refactor/data-access-builder-growth-workspace branch September 11, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Refactor or performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant