@oktis-works/api 0.16.10 → 0.17.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +154 -0
  2. package/package.json +7 -7
package/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # @oktis-works/api
2
+
3
+ REST API — Hono-based, JWT auth, multi-tenant, permission-gated.
4
+
5
+ ## Base URL
6
+
7
+ ```
8
+ /api/v1
9
+ ```
10
+
11
+ ## Authentication
12
+
13
+ - **JWT** in `Authorization: Bearer <token>`
14
+ - **Tenant** from JWT claim or `X-Tenant-ID` header
15
+ - **Permissions** via `requirePermission(action, resource)` middleware
16
+
17
+ ## Content Routes (`/content`)
18
+
19
+ | Method | Path | Permission | Description |
20
+ |--------|------|------------|-------------|
21
+ | `GET` | `/content` | `read:content` | List (pagination, filter by type/status/search) |
22
+ | `GET` | `/content/:id` | `read:content` | Get by ID |
23
+ | `GET` | `/content/slug/:slug` | `read:content` | Get by slug (optional `?type=`) |
24
+ | `GET` | `/content/singleton/:type` | `read:content` | Get singleton content |
25
+ | `POST` | `/content` | `create:content` | Create content |
26
+ | `PUT` | `/content/:id` | `update:content` | Update content |
27
+ | `DELETE` | `/content/:id` | `delete:content` | Delete content |
28
+ | `POST` | `/content/:id/publish` | `update:content` | Publish (sync or `?mode=async`) |
29
+ | `POST` | `/content/:id/unpublish` | `update:content` | Unpublish |
30
+
31
+ ### Create Content (`POST /content`)
32
+
33
+ ```json
34
+ {
35
+ "type": "post",
36
+ "title": "Hello World",
37
+ "slug": "hello-world", // optional, auto-generated
38
+ "body": { "html": "<p>...</p>" },
39
+ "excerpt": "Optional excerpt",
40
+ "status": "DRAFT", // DRAFT | PUBLISHED | ARCHIVED | TRASHED
41
+ "featuredImageId": "uuid",
42
+ "seoTitle": "SEO Title",
43
+ "seoDescription": "SEO Description",
44
+ "metadata": { "hub_type": "project" }, // for hub pages
45
+ "layout": "custom-layout", // optional
46
+ "parentId": "uuid" // Phase 1: hierarchical parent
47
+ }
48
+ ```
49
+
50
+ **Response:** `201 Created` with content object.
51
+
52
+ ### Update Content (`PUT /content/:id`)
53
+
54
+ Same fields as create (all optional). `parentId: null` removes parent.
55
+
56
+ **Validation:**
57
+ - `parentId` must be same type, same tenant
58
+ - No cycles (server-side)
59
+ - Max depth 5
60
+
61
+ ### List Content (`GET /content`)
62
+
63
+ Query params:
64
+ - `page=1`, `limit=20`
65
+ - `type=post`
66
+ - `status=PUBLISHED`
67
+ - `search=query` (title/slug)
68
+ - `include=author` — attaches author object
69
+
70
+ ## Content Types (`/content-types`)
71
+
72
+ | Method | Path | Permission |
73
+ |--------|------|------------|
74
+ | `GET` | `/content-types` | `read:content-types` |
75
+ | `POST` | `/content-types` | `create:content-types` |
76
+ | `PUT` | `/content-types/:slug` | `update:content-types` |
77
+ | `DELETE` | `/content-types/:slug` | `delete:content-types` |
78
+
79
+ ## Settings (`/settings`)
80
+
81
+ | Method | Path | Permission |
82
+ |--------|------|------------|
83
+ | `GET` | `/settings/:group` | `read:settings` |
84
+ | `PUT` | `/settings` | `update:settings` |
85
+
86
+ Groups: `reading`, `general`, `writing`, `media`, `permalinks`.
87
+
88
+ ## Media (`/media`)
89
+
90
+ | Method | Path | Permission |
91
+ |--------|------|------------|
92
+ | `GET` | `/media` | `read:media` |
93
+ | `POST` | `/media` | `create:media` (multipart) |
94
+ | `DELETE` | `/media/:id` | `delete:media` |
95
+
96
+ ## Tenants (`/tenants`)
97
+
98
+ | Method | Path | Permission |
99
+ |--------|------|------------|
100
+ | `GET` | `/tenants` | `read:tenants` (superadmin) |
101
+ | `POST` | `/tenants` | `create:tenants` (superadmin) |
102
+
103
+ ## Phase 1 Integration
104
+
105
+ ### Parent ID in Content API
106
+
107
+ ```json
108
+ // POST /content or PUT /content/:id
109
+ {
110
+ "parentId": "uuid-of-parent-item"
111
+ }
112
+ ```
113
+
114
+ Passed directly to `contentService.create/update`.
115
+
116
+ ### Hub Page Metadata
117
+
118
+ ```json
119
+ // PUT /content/:pageId
120
+ {
121
+ "metadata": { "hub_type": "project" }
122
+ }
123
+ ```
124
+
125
+ Sets page as hub for content type `project`. Slug becomes URL base (`/projects/`).
126
+
127
+ ## Error Responses
128
+
129
+ ```json
130
+ // 400 Bad Request
131
+ { "error": "Validation failed: ..." }
132
+
133
+ // 401 Unauthorized
134
+ { "error": "Invalid or expired token" }
135
+
136
+ // 403 Forbidden
137
+ { "error": "Insufficient permissions" }
138
+
139
+ // 404 Not Found
140
+ { "error": "Content not found" }
141
+
142
+ // 409 Conflict
143
+ { "error": "Parent assignment would create a cycle" }
144
+ ```
145
+
146
+ ## Multi-tenant
147
+
148
+ - `tenantId` injected from JWT (never from request body)
149
+ - All queries scoped via `runWithTenantTransaction(tenantId, fn)`
150
+ - RLS enforces isolation at DB level
151
+
152
+ ## Rate Limiting
153
+
154
+ - Not implemented yet (TODO)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oktis-works/api",
3
- "version": "0.16.10",
3
+ "version": "0.17.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -18,14 +18,14 @@
18
18
  "clean": "rm -rf dist tsconfig.tsbuildinfo"
19
19
  },
20
20
  "dependencies": {
21
- "@oktis-works/core": "^0.15.6",
22
- "@oktis-works/auth": "^0.8.4",
23
- "@oktis-works/config": "^0.6.5",
24
- "@oktis-works/database": "^0.14.8",
25
- "@oktis-works/types": "^0.9.4",
21
+ "@oktis-works/core": "^0.16.5",
22
+ "@oktis-works/auth": "^0.8.5",
23
+ "@oktis-works/config": "^0.6.6",
24
+ "@oktis-works/database": "^0.15.5",
25
+ "@oktis-works/types": "^0.10.0",
26
26
  "hono": "4.13.12",
27
27
  "@hono/node-server": "1.8.0",
28
- "@oktis-works/validation": "^0.8.1"
28
+ "@oktis-works/validation": "^0.8.2"
29
29
  },
30
30
  "devDependencies": {
31
31
  "typescript": "5.7.3",