Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
# OpenSpec Change: enterprise-api-plugin-social
- **Change ID**: enterprise-api-plugin-social
- **Package**: `@suaveplan/api-plugin-social`
- **Category**: api/comms
- **Target path**: `api/comms/api-plugin-social`
- **Status**: PROPOSED
- **Date**: 2026-04-24
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/api-plugin-social.md`
---
## Summary
Deliver `@suaveplan/api-plugin-social` on the genesis branch from scratch at enterprise quality. Social graph plugin: follow/unfollow, follower/following lists, activity feed (fan-out on write with configurable fanout limit), likes, comments, shares, content reporting, and a blocking/muting system. Routes under `/social`. Per-table SurrealQL. Typed bus events: `social:followed`, `social:post:liked`, `social:comment:created`, `social:user:blocked`.
---
## Available workspace deps on genesis
| Package | Role |
|---|---|
| `@suaveplan/api` (`workspace:^`) | `definePlugin` |
| `@suaveplan/api-shared` (`workspace:^`) | Helpers |
| `@suaveplan/api-plugin-auth` (`workspace:^`) | `requireAuth` |
| `@suaveplan/api-plugin-database` (`workspace:^`) | SurrealDB |
| `@suaveplan/api-plugin-notifications` (`workspace:^`) | Notify on follow/like/comment |
| `@suaveplan/events` (`workspace:^`) | Event bus |
| `@suaveplan/error` (`workspace:^`) | `SocialError` hierarchy |
| `@suaveplan/rate-limiter` (`workspace:^`) | Rate limits |
| `hono` + `@hono/zod-openapi` + `zod` | Routes |
| `@opentelemetry/api` | OTel |
---
## Public API surface
```ts
function createSocialPlugin(config?: SocialPluginConfig): PluginDescriptor
// Services: FollowService, FeedService, LikeService, CommentService, ReportService, BlockService
// Routes: /social/follow, /social/followers, /social/following,
// /social/feed, /social/posts/:id/like, /social/posts/:id/comments,
// /social/block, /social/report
```
### Error codes
```ts
type SocialErrorCode =
| "SOCIAL_USER_NOT_FOUND"
| "SOCIAL_ALREADY_FOLLOWING"
| "SOCIAL_NOT_FOLLOWING"
| "SOCIAL_BLOCKED"
| "SOCIAL_POST_NOT_FOUND"
| "SOCIAL_COMMENT_NOT_FOUND"
```
---
## File layout
```text
api/comms/api-plugin-social/
package.json tsconfig.json vitest.config.ts
surql/ (follow, feed_item, like, comment, block, report tables)
src/
index.ts events.ts types/ errors/
services/follow/ services/feed/ services/like/ services/comment/
services/block/ services/report/
routes/social/
tests/integration.test.ts
```
---
## Impact
Prerequisites: `@suaveplan/api`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`, `@suaveplan/api-plugin-notifications`.

View File

@@ -0,0 +1,61 @@
# Tasks: enterprise-api-plugin-social
**Change ID**: enterprise-api-plugin-social
**Package**: `@suaveplan/api-plugin-social`
**Target path**: `api/comms/api-plugin-social`
**Prerequisite packages on Verdaccio**: `@suaveplan/api`, `@suaveplan/api-shared`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`, `@suaveplan/api-plugin-notifications`, `@suaveplan/events`, `@suaveplan/rate-limiter`, `@suaveplan/error`
---
## 0. Pre-flight (non-negotiable)
- [ ] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in each)
- [ ] 0.2 If any worktrees exist under `.claude/worktrees/`, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (`git worktree remove`) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
- [ ] 0.3 Confirm the package set in `MANIFEST.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
## 1. Scaffold + types + errors + events
- [ ] Create `api/comms/api-plugin-social/`; `package.json` v0.0.0; standard tooling.
- [ ] Types: `Follow`, `FeedItem`, `Like`, `Comment`, `Block`, `Report`, `SocialPluginConfig` (Zod).
- [ ] Errors: 6-code union + metadata + registration. Test + doc.
- [ ] Events: `SocialEventMap` (social:followed, social:unfollowed, social:post:liked, social:comment:created, social:user:blocked).
---
## 2. SurrealQL
- [ ] `follow.surql`, `feed_item.surql`, `like.surql`, `comment.surql`, `block.surql`, `report.surql`. tenantId + userId indexes.
---
## 3. Services (each `.test.ts` + `.md`)
- [ ] **FollowService**: `follow`, `unfollow`, `listFollowers`, `listFollowing`, `isFollowing`. Notify via `api-plugin-notifications`.
- [ ] **FeedService**: `getFeed(userId)` — fan-out on write; fanout limit configurable (default 1000 followers); paginated.
- [ ] **LikeService**: `like`, `unlike`, `getLikeCount`, `isLiked`. Idempotent.
- [ ] **CommentService**: `createComment`, `deleteComment`, `listComments` (threaded, paginated).
- [ ] **BlockService**: `block`, `unblock`, `isBlocked` — hide from feed + follow from blocked user.
- [ ] **ReportService**: `reportContent`, `listReports` (admin), `resolveReport`.
---
## 4. Routes
- [ ] `POST/DELETE /social/follow/:userId` — `requireAuth` + rate-limit.
- [ ] `GET /social/followers`, `GET /social/following` — `requireAuth`.
- [ ] `GET /social/feed` — `requireAuth`.
- [ ] `POST/DELETE /social/posts/:id/like` — `requireAuth` + rate-limit.
- [ ] `GET/POST /social/posts/:id/comments`, `DELETE /social/comments/:id` — `requireAuth`.
- [ ] `POST /social/block/:userId`, `DELETE /social/block/:userId` — `requireAuth`.
- [ ] `POST /social/report` — `requireAuth`.
- [ ] Route `.test.ts` + `.md`.
---
## 5. Plugin factory + integration tests + publish
- [ ] `createSocialPlugin`: `definePlugin`, `dependencies: ["database", "auth"]`, `migrationsPath: "./surql"`.
- [ ] Integration: follow → feed item appears → like → unlike → block hides from feed (real SurrealDB).
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-social` — green; 100% coverage.
- [ ] `bun scripts/publish.ts --package @suaveplan/api-plugin-social`.
- [ ] Archive → `openspec/archive/2026-04-24-enterprise-api-plugin-social/`.