Repository navigation
refactor(builder): move growth, comment automation, media library and workspace data access into business - #1098
Merged
realcodesiman merged 5 commits intoSep 11, 2026
Conversation
realcodesiman
force-pushed
the
refactor/data-access-builder-growth-workspace
branch
from
September 11, 2026 12:25
5be4754 to
a055c80
Compare
… 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 <[email protected]>
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 <[email protected]>
…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 <[email protected]>
realcodesiman
force-pushed
the
refactor/data-access-builder-growth-workspace
branch
from
September 11, 2026 19:26
c5d84e5 to
067da43
Compare
…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 <[email protected]>
realcodesiman
deleted the
refactor/data-access-builder-growth-workspace
branch
September 11, 2026 23:43
sung17
pushed a commit
that referenced
this pull request
Sep 13, 2026
Both snapshots were generated before main dropped AIAssistant/AITrigger and added the ErrorLog columns, so after the rebase they forked the chain at an older tip and still described tables that no longer exist. drizzle-kit reported a non-commutative chain: two branches each adding sentCount. Neither migration.sql changed — the SQL was always correct. What changed is the snapshots' lineage and content: - 20260911081114_add_comment_automation_delivery_stats is renamed to 20260913042025_... so folder order matches prevIds order; it used to sort between two of main's own migrations while claiming to follow the older tip. - Both snapshots are rebuilt as "main's tip + this branch's own entities", dropping the AIAssistant/AITrigger entries they should never have carried. normalizeReplyTexts moves into fbCommentAutomationService, where main's #1098 refactor put every write to this table. It was applied per call site before, which left the template installer out — and a row whose `value` disagrees with its `values` sends the wrong text with no error. Verified with drizzle-kit check ("Everything's fine") and db:check-drift. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
sung17
added a commit
that referenced
this pull request
Sep 13, 2026
…, and multi-text replies (#1171) * feat(comment-automation): track sent/delivered/seen/clicked/failed delivery stats Record delivery lifecycle events for comment automation replies and surface them as Sent/Delivered/Seen/Clicked/Failed columns on the fb-comments and ig-comments tables, reusing the broadcast/sequence stats vocabulary so the contacts dialog and bulk-tag pipeline stay a single implementation. - add lifetime counters on FBCommentAutomation plus the event columns and indexes behind them (migration 20260911081114) - increment counters from the message/flow listeners via the anchor resolver - add the shared stats cell, stat columns, and contacts dialog components - extend the analytics repository/service with the contacts listing query Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * feat(comment-automation): track missed comments, tag counters, and multi-text public replies Builds on the delivery-stat columns with the three things they could not answer on their own: which comments the automation declined, how many tags a commenter has accumulated, and replies made of more than one message. - FBCommentAutomationMiss: every filter decline now records a reason, so the Misses column reports a real denominator instead of silence. Misses go to their own table because FBCommentAutomationEvent purges failed rows nightly. - Comment tag counters behind {{total_tagged}} / {{total_new_tagged}}. - Multi-text public reply (ReplyTextsField), posted as separate comment replies but counted as one reply. - Per-automation analytics: replies chart, error logs, day/month bucketing. Fixes found while verifying the stats end to end, each of which showed up as a silent zero rather than an error: - Delivered/Seen stayed at zero for a text private reply: markDelivered ran before recordReplyEvent inserted the row, so the UPDATE matched nothing. The row is now born delivered. - Clicked could never increment: the private flow reply passed only commentAnchor, while every button encoder reads metadata.commentAutomationId. - A flow/AIAgent reply was enqueued before its analytics row existed, so with no replyAfter the job could settle a row that was not there yet. Dispatch is now deferred until after the row is written. - Messenger image/video steps with buttons dropped metadata entirely, losing comment-automation, broadcast and sequence attribution alike. - markClicked could double-count concurrent clicks; markSeen accepted a read receipt older than the reply; settleEvent never cleared failedAt on the way back to sent; getContacts paged without a tiebreaker and counted contacts the list did not show. The click path was silent end to end, so two warns and three opt-in diagnostics now cover it. logDiagnostic calls isLevelEnabled through an optional call so the repo's hand-rolled logger doubles in tests opt out instead of throwing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix(database): relink comment automation migrations onto main's chain Both snapshots were generated before main dropped AIAssistant/AITrigger and added the ErrorLog columns, so after the rebase they forked the chain at an older tip and still described tables that no longer exist. drizzle-kit reported a non-commutative chain: two branches each adding sentCount. Neither migration.sql changed — the SQL was always correct. What changed is the snapshots' lineage and content: - 20260911081114_add_comment_automation_delivery_stats is renamed to 20260913042025_... so folder order matches prevIds order; it used to sort between two of main's own migrations while claiming to follow the older tip. - Both snapshots are rebuilt as "main's tip + this branch's own entities", dropping the AIAssistant/AITrigger entries they should never have carried. normalizeReplyTexts moves into fbCommentAutomationService, where main's #1098 refactor put every write to this table. It was applied per call site before, which left the template installer out — and a row whose `value` disagrees with its `values` sends the wrong text with no error. Verified with drizzle-kit check ("Everything's fine") and db:check-drift. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Deathgiver <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
hello-jackytruong
referenced
this pull request
in hello-jackytruong/ChatWorkAI
Nov 22, 2026
… workspace data access into business (#1098) * refactor(builder): move growth, comment automation, media library and 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) * refactor(builder,worker): move media-library, broadcasts, error-logs, 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.
hello-jackytruong
referenced
this pull request
in hello-jackytruong/ChatWorkAI
Nov 22, 2026
…, and multi-text replies (#1171) * feat(comment-automation): track sent/delivered/seen/clicked/failed delivery stats Record delivery lifecycle events for comment automation replies and surface them as Sent/Delivered/Seen/Clicked/Failed columns on the fb-comments and ig-comments tables, reusing the broadcast/sequence stats vocabulary so the contacts dialog and bulk-tag pipeline stay a single implementation. - add lifetime counters on FBCommentAutomation plus the event columns and indexes behind them (migration 20260911081114) - increment counters from the message/flow listeners via the anchor resolver - add the shared stats cell, stat columns, and contacts dialog components - extend the analytics repository/service with the contacts listing query Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * feat(comment-automation): track missed comments, tag counters, and multi-text public replies Builds on the delivery-stat columns with the three things they could not answer on their own: which comments the automation declined, how many tags a commenter has accumulated, and replies made of more than one message. - FBCommentAutomationMiss: every filter decline now records a reason, so the Misses column reports a real denominator instead of silence. Misses go to their own table because FBCommentAutomationEvent purges failed rows nightly. - Comment tag counters behind {{total_tagged}} / {{total_new_tagged}}. - Multi-text public reply (ReplyTextsField), posted as separate comment replies but counted as one reply. - Per-automation analytics: replies chart, error logs, day/month bucketing. Fixes found while verifying the stats end to end, each of which showed up as a silent zero rather than an error: - Delivered/Seen stayed at zero for a text private reply: markDelivered ran before recordReplyEvent inserted the row, so the UPDATE matched nothing. The row is now born delivered. - Clicked could never increment: the private flow reply passed only commentAnchor, while every button encoder reads metadata.commentAutomationId. - A flow/AIAgent reply was enqueued before its analytics row existed, so with no replyAfter the job could settle a row that was not there yet. Dispatch is now deferred until after the row is written. - Messenger image/video steps with buttons dropped metadata entirely, losing comment-automation, broadcast and sequence attribution alike. - markClicked could double-count concurrent clicks; markSeen accepted a read receipt older than the reply; settleEvent never cleared failedAt on the way back to sent; getContacts paged without a tiebreaker and counted contacts the list did not show. The click path was silent end to end, so two warns and three opt-in diagnostics now cover it. logDiagnostic calls isLevelEnabled through an optional call so the repo's hand-rolled logger doubles in tests opt out instead of throwing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix(database): relink comment automation migrations onto main's chain Both snapshots were generated before main dropped AIAssistant/AITrigger and added the ErrorLog columns, so after the rebase they forked the chain at an older tip and still described tables that no longer exist. drizzle-kit reported a non-commutative chain: two branches each adding sentCount. Neither migration.sql changed — the SQL was always correct. What changed is the snapshots' lineage and content: - 20260911081114_add_comment_automation_delivery_stats is renamed to 20260913042025_... so folder order matches prevIds order; it used to sort between two of main's own migrations while claiming to follow the older tip. - Both snapshots are rebuilt as "main's tip + this branch's own entities", dropping the AIAssistant/AITrigger entries they should never have carried. normalizeReplyTexts moves into fbCommentAutomationService, where main's #1098 refactor put every write to this table. It was applied per call site before, which left the template installer out — and a row whose `value` disagrees with its `values` sends the wrong text with no error. Verified with drizzle-kit check ("Everything's fine") and db:check-drift. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Deathgiver <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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.mainand only append to the shared barrels.Changes
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;listErrorLogsandlistAuditLogsquery functions; methods appended toreflink,qr-code,spreadsheet,fb-comment-automation,ig-story-automation,workspace-member,userservices and thecontact-inbox/filerepositories.apps/builder/src/lib/auth/utils.ts: the membership read now goes throughworkspaceMemberService.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.validationExceptionadded topackages/business/src/errors.tsin the same plain-factory/400 form as feat(contacts): cover full public API for MCP, move logic into business services #1093.features/users/queriesdeleted (zero callers).Notes for reviewers
getFbComment/getIgComment/getIgStorynow thrownotFoundException(404) instead of a bareError(500); same messages, and the only caller swallows the error.media-library-mutations.test.tsmocks the service inline; the real service is covered bypackages/business/__tests__/media-library.service.test.ts.db): the siblingupdate-*/delete-*actions in these features; listed in the plan as follow-ups.Test plan
pnpm --filter @chatbotx.io/database check-types && testpnpm --filter @chatbotx.io/business check-types && test(only the pre-existingads-conversion-rule.service.test.tsfailures remain, also red onmain)pnpm --filter builder check-types && testpnpm lint/r/<ws>/<name>with and without?code=→ 302; media-library upload/move/favourite/delete folder; change a member role; accept an invitation