Skip to content

refactor(data-access): move tag/saved-reply/custom-field logic onto repository pattern - #1050

Open
realcodesiman wants to merge 2 commits into
mainfrom
refactor/repository-pattern-migration
Open

refactor(data-access): move tag/saved-reply/custom-field logic onto repository pattern#1050
realcodesiman wants to merge 2 commits into
mainfrom
refactor/repository-pattern-migration

Conversation

@realcodesiman

Copy link
Copy Markdown
Contributor

Summary

  • Introduces dedicated tag and saved-reply repositories under packages/database/src/repositories, moving direct query logic out of the business services.
  • Adds a Workspace.tokenHash column + index and hashes workspace tokens instead of comparing raw values.
  • Centralizes the owner quota/trial access gate into apps/builder/src/lib/workspace/authorize-workspace-access.ts, shared by server actions and oRPC session/workspace-token auth.
  • Relocates affected business-logic tests from apps/builder/__tests__ into package-level __tests__ (tag, saved-reply, custom-field, flow, flow-version) per repository test-placement convention, and adds new repository-level tests under packages/database/__tests__.

Changes

  • packages/database/src/repositories/{tag,saved-reply}/ — new repositories
  • packages/database/drizzle/20260828025915_create_workspace_token_hash/ — new migration (additive: tokenHash column + index), not yet applied
  • apps/builder/src/lib/workspace/authorize-workspace-access.ts — new shared owner-access gate
  • apps/builder/src/middlewares/{auth,workspace-token-auth}.ts, apps/builder/src/orpc.ts — wired to the new gate
  • packages/business/src/{tag,saved-reply,custom-field,flow,flow-version,workspace}/service.ts — updated to use repositories
  • Test relocation: apps/builder/__tests__/*packages/business/**/__tests__/*; new packages/database/__tests__/{tag,saved-reply}-repository.test.ts

Test plan

  • pnpm lint (ultracite) — passed via pre-commit hook
  • pnpm --filter builder check-types / workspace-wide typecheck — passed via pre-commit hook (58/58 tasks)
  • pnpm --filter @chatbotx.io/database db:migratenot run; migration SQL is additive-only and awaiting explicit approval per project migration-safety rule
  • Manual verification of workspace-token auth flow and tag/saved-reply CRUD in the builder UI

…epository pattern

Introduces dedicated tag and saved-reply repositories under
packages/database/src/repositories, hashes workspace tokens
(new tokenHash column + index), and centralizes the owner
quota/trial gate into authorize-workspace-access.ts shared by
server actions and oRPC auth. Relocates the affected business-
logic tests from apps/builder/__tests__ into package-level
__tests__ per repository convention.
@github-actions github-actions Bot added the improvement Refactor or performance improvement label Aug 28, 2026
…itory migration

Splits the oRPC router so the public OpenAPI handler only ever serves
publicRouter (workspace-token / channel-token auth) while session-authed
procedures move to a private router on /rpc — a procedure missing from
publicRouter now 404s instead of silently answering to a session cookie.
Renames schemas/ -> schema/ and api/authenticated.ts -> api/private.ts
across features for naming consistency with the new boundary, adds a
custom-field repository and api-contract package, and continues moving
tag/saved-reply/custom-field logic onto the repository pattern.
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