@brew-cms/api 0.1.0
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.
- package/LICENSE +201 -0
- package/dist/index.js +5 -0
- package/package.json +29 -0
- package/src/__tests__/api.test.ts +416 -0
- package/src/errors.ts +42 -0
- package/src/idempotency.ts +41 -0
- package/src/index.ts +4 -0
- package/src/router.ts +538 -0
- package/src/validators.ts +63 -0
- package/tsconfig.json +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@brew-cms/api",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "REST API router, OpenAPI spec, idempotency, and request validation for BrewCMS",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@brew-cms/content": "0.1.0",
|
|
17
|
+
"@brew-cms/core": "0.1.0",
|
|
18
|
+
"@brew-cms/intelligence": "0.1.0",
|
|
19
|
+
"@brew-cms/policy": "0.1.0",
|
|
20
|
+
"zod": "^3.24.1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@brew-cms/db": "0.1.0"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc -b",
|
|
27
|
+
"clean": "rimraf dist"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { handleApiRequest, type ApiContext } from '../router.js';
|
|
3
|
+
import { InMemoryIdempotencyStore } from '../idempotency.js';
|
|
4
|
+
import {
|
|
5
|
+
DocumentService,
|
|
6
|
+
WorkflowService,
|
|
7
|
+
AgentService,
|
|
8
|
+
AuditService,
|
|
9
|
+
TaxonomyService,
|
|
10
|
+
type Actor,
|
|
11
|
+
type Clock,
|
|
12
|
+
type IdGenerator,
|
|
13
|
+
} from '@brew-cms/core';
|
|
14
|
+
import { PolicyEngine } from '@brew-cms/policy';
|
|
15
|
+
import {
|
|
16
|
+
createDatabaseConnection,
|
|
17
|
+
seedInitialData,
|
|
18
|
+
SQLiteDocumentRepository,
|
|
19
|
+
SQLiteRevisionRepository,
|
|
20
|
+
SQLiteTaxonomyRepository,
|
|
21
|
+
SQLiteAuditEventRepository,
|
|
22
|
+
SQLiteAgentRepository,
|
|
23
|
+
SQLiteMediaAssetRepository,
|
|
24
|
+
} from '@brew-cms/db';
|
|
25
|
+
import {
|
|
26
|
+
DefaultSourceRegistry,
|
|
27
|
+
DeterministicMockEmbeddingProvider,
|
|
28
|
+
MemorySemanticIndexAdapter,
|
|
29
|
+
MockContentSourceAdapter,
|
|
30
|
+
IndexingService,
|
|
31
|
+
HybridRetrievalService,
|
|
32
|
+
CanonicalSourceResolver,
|
|
33
|
+
} from '@brew-cms/intelligence';
|
|
34
|
+
|
|
35
|
+
describe('REST API /api/v1 and Router', () => {
|
|
36
|
+
let ctx: ApiContext;
|
|
37
|
+
const adminActor: Actor = {
|
|
38
|
+
id: 'usr_admin_default',
|
|
39
|
+
type: 'human',
|
|
40
|
+
role: 'Admin',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
const db = createDatabaseConnection({ filePath: ':memory:' });
|
|
45
|
+
seedInitialData(db);
|
|
46
|
+
|
|
47
|
+
const docRepo = new SQLiteDocumentRepository(db);
|
|
48
|
+
const revRepo = new SQLiteRevisionRepository(db);
|
|
49
|
+
const taxRepo = new SQLiteTaxonomyRepository(db);
|
|
50
|
+
const auditRepo = new SQLiteAuditEventRepository(db);
|
|
51
|
+
const agentRepo = new SQLiteAgentRepository(db);
|
|
52
|
+
|
|
53
|
+
const policy = new PolicyEngine();
|
|
54
|
+
const clock: Clock = { now: () => new Date('2026-09-12T12:00:00Z') };
|
|
55
|
+
let idCounter = 1;
|
|
56
|
+
const idGen: IdGenerator = { generate: (p = 'id') => `${p}_${idCounter++}` };
|
|
57
|
+
|
|
58
|
+
const documentService = new DocumentService(docRepo, revRepo, auditRepo, policy, clock, idGen);
|
|
59
|
+
const workflowService = new WorkflowService(docRepo, revRepo, auditRepo, policy, clock, idGen);
|
|
60
|
+
const agentService = new AgentService(agentRepo, auditRepo, policy, clock, idGen);
|
|
61
|
+
const auditService = new AuditService(auditRepo);
|
|
62
|
+
const taxonomyService = new TaxonomyService(taxRepo);
|
|
63
|
+
|
|
64
|
+
const mediaRepo = new SQLiteMediaAssetRepository(db);
|
|
65
|
+
|
|
66
|
+
ctx = {
|
|
67
|
+
documentService,
|
|
68
|
+
workflowService,
|
|
69
|
+
agentService,
|
|
70
|
+
auditService,
|
|
71
|
+
taxonomyService,
|
|
72
|
+
revisionRepo: revRepo,
|
|
73
|
+
mediaRepo,
|
|
74
|
+
agentRepo,
|
|
75
|
+
idempotencyStore: new InMemoryIdempotencyStore(),
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('serves health endpoints', async () => {
|
|
80
|
+
const live = await handleApiRequest(
|
|
81
|
+
{ method: 'GET', path: '/api/health/live', actor: adminActor },
|
|
82
|
+
ctx
|
|
83
|
+
);
|
|
84
|
+
expect(live.status).toBe(200);
|
|
85
|
+
expect((live.body as any).status).toBe('live');
|
|
86
|
+
|
|
87
|
+
const ready = await handleApiRequest(
|
|
88
|
+
{ method: 'GET', path: '/api/health/ready', actor: adminActor },
|
|
89
|
+
ctx
|
|
90
|
+
);
|
|
91
|
+
expect(ready.status).toBe(200);
|
|
92
|
+
expect((ready.body as any).status).toBe('ready');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('creates and publishes a document via REST endpoints', async () => {
|
|
96
|
+
// 1. Create document
|
|
97
|
+
const createRes = await handleApiRequest(
|
|
98
|
+
{
|
|
99
|
+
method: 'POST',
|
|
100
|
+
path: '/api/v1/documents',
|
|
101
|
+
actor: adminActor,
|
|
102
|
+
body: {
|
|
103
|
+
type: 'post',
|
|
104
|
+
slug: 'rest-intro',
|
|
105
|
+
title: 'REST Architecture in BrewCMS',
|
|
106
|
+
sourceMarkdown: '# REST Architecture\n\nContent operating system REST APIs.',
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
ctx
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
expect(createRes.status).toBe(201);
|
|
113
|
+
const doc = (createRes.body as any).document;
|
|
114
|
+
expect(doc.id).toBeDefined();
|
|
115
|
+
expect(doc.status).toBe('DRAFT');
|
|
116
|
+
|
|
117
|
+
// 2. Publish document
|
|
118
|
+
const publishRes = await handleApiRequest(
|
|
119
|
+
{
|
|
120
|
+
method: 'POST',
|
|
121
|
+
path: `/api/v1/documents/${doc.id}/publish`,
|
|
122
|
+
actor: adminActor,
|
|
123
|
+
body: {},
|
|
124
|
+
},
|
|
125
|
+
ctx
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
expect(publishRes.status).toBe(200);
|
|
129
|
+
expect((publishRes.body as any).document.status).toBe('PUBLISHED');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('enforces idempotency using Idempotency-Key header', async () => {
|
|
133
|
+
const key = 'idem_unique_key_123';
|
|
134
|
+
|
|
135
|
+
// First mutation
|
|
136
|
+
const req1 = await handleApiRequest(
|
|
137
|
+
{
|
|
138
|
+
method: 'POST',
|
|
139
|
+
path: '/api/v1/documents',
|
|
140
|
+
headers: { 'idempotency-key': key },
|
|
141
|
+
actor: adminActor,
|
|
142
|
+
body: {
|
|
143
|
+
type: 'post',
|
|
144
|
+
slug: 'idempotent-doc',
|
|
145
|
+
title: 'Idempotency Post',
|
|
146
|
+
sourceMarkdown: '# Test',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
ctx
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
expect(req1.status).toBe(201);
|
|
153
|
+
const initialId = (req1.body as any).document.id;
|
|
154
|
+
|
|
155
|
+
// Second identical request with same key
|
|
156
|
+
const req2 = await handleApiRequest(
|
|
157
|
+
{
|
|
158
|
+
method: 'POST',
|
|
159
|
+
path: '/api/v1/documents',
|
|
160
|
+
headers: { 'idempotency-key': key },
|
|
161
|
+
actor: adminActor,
|
|
162
|
+
body: {
|
|
163
|
+
type: 'post',
|
|
164
|
+
slug: 'idempotent-doc',
|
|
165
|
+
title: 'Idempotency Post',
|
|
166
|
+
sourceMarkdown: '# Test',
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
ctx
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
expect(req2.status).toBe(201);
|
|
173
|
+
expect(req2.headers?.['X-Cache-Lookup']).toBe('HIT');
|
|
174
|
+
expect((req2.body as any).document.id).toBe(initialId);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('returns standard machine-readable error envelope on validation failure', async () => {
|
|
178
|
+
const res = await handleApiRequest(
|
|
179
|
+
{
|
|
180
|
+
method: 'POST',
|
|
181
|
+
path: '/api/v1/documents',
|
|
182
|
+
actor: adminActor,
|
|
183
|
+
headers: { 'x-request-id': 'req_xyz' },
|
|
184
|
+
body: {
|
|
185
|
+
type: 'invalid_type',
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
ctx
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
expect(res.status).toBeGreaterThanOrEqual(400);
|
|
192
|
+
const body = res.body as any;
|
|
193
|
+
expect(body.error).toBeDefined();
|
|
194
|
+
expect(body.error.code).toBeDefined();
|
|
195
|
+
expect(body.error.requestId).toBe('req_xyz');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('handles full editorial lifecycle: submit -> approve -> publish -> unpublish -> restore', async () => {
|
|
199
|
+
// 1. Create draft
|
|
200
|
+
const createRes = await handleApiRequest(
|
|
201
|
+
{
|
|
202
|
+
method: 'POST',
|
|
203
|
+
path: '/api/v1/documents',
|
|
204
|
+
actor: adminActor,
|
|
205
|
+
body: {
|
|
206
|
+
type: 'post',
|
|
207
|
+
slug: 'lifecycle-test',
|
|
208
|
+
title: 'Lifecycle Post',
|
|
209
|
+
sourceMarkdown: '# Lifecycle Test\n\nInitial version.',
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
ctx
|
|
213
|
+
);
|
|
214
|
+
expect(createRes.status).toBe(201);
|
|
215
|
+
const docId = (createRes.body as any).document.id;
|
|
216
|
+
const initialRevId = (createRes.body as any).revision.id;
|
|
217
|
+
|
|
218
|
+
// 2. Submit for review
|
|
219
|
+
const submitRes = await handleApiRequest(
|
|
220
|
+
{
|
|
221
|
+
method: 'POST',
|
|
222
|
+
path: `/api/v1/documents/${docId}/submit`,
|
|
223
|
+
actor: adminActor,
|
|
224
|
+
body: {},
|
|
225
|
+
},
|
|
226
|
+
ctx
|
|
227
|
+
);
|
|
228
|
+
expect(submitRes.status).toBe(200);
|
|
229
|
+
expect((submitRes.body as any).status).toBe('IN_REVIEW');
|
|
230
|
+
|
|
231
|
+
// 3. Approve
|
|
232
|
+
const approveRes = await handleApiRequest(
|
|
233
|
+
{
|
|
234
|
+
method: 'POST',
|
|
235
|
+
path: `/api/v1/documents/${docId}/approve`,
|
|
236
|
+
actor: adminActor,
|
|
237
|
+
body: {},
|
|
238
|
+
},
|
|
239
|
+
ctx
|
|
240
|
+
);
|
|
241
|
+
expect(approveRes.status).toBe(200);
|
|
242
|
+
expect((approveRes.body as any).status).toBe('APPROVED');
|
|
243
|
+
|
|
244
|
+
// 4. Publish
|
|
245
|
+
const publishRes = await handleApiRequest(
|
|
246
|
+
{
|
|
247
|
+
method: 'POST',
|
|
248
|
+
path: `/api/v1/documents/${docId}/publish`,
|
|
249
|
+
actor: adminActor,
|
|
250
|
+
body: {},
|
|
251
|
+
},
|
|
252
|
+
ctx
|
|
253
|
+
);
|
|
254
|
+
expect(publishRes.status).toBe(200);
|
|
255
|
+
expect((publishRes.body as any).document.status).toBe('PUBLISHED');
|
|
256
|
+
|
|
257
|
+
// 5. Unpublish
|
|
258
|
+
const unpublishRes = await handleApiRequest(
|
|
259
|
+
{
|
|
260
|
+
method: 'POST',
|
|
261
|
+
path: `/api/v1/documents/${docId}/unpublish`,
|
|
262
|
+
actor: adminActor,
|
|
263
|
+
body: {},
|
|
264
|
+
},
|
|
265
|
+
ctx
|
|
266
|
+
);
|
|
267
|
+
expect(unpublishRes.status).toBe(200);
|
|
268
|
+
expect((unpublishRes.body as any).status).toBe('DRAFT');
|
|
269
|
+
|
|
270
|
+
// 6. Restore initial revision
|
|
271
|
+
const restoreRes = await handleApiRequest(
|
|
272
|
+
{
|
|
273
|
+
method: 'POST',
|
|
274
|
+
path: `/api/v1/documents/${docId}/restore`,
|
|
275
|
+
actor: adminActor,
|
|
276
|
+
body: { revisionId: initialRevId },
|
|
277
|
+
},
|
|
278
|
+
ctx
|
|
279
|
+
);
|
|
280
|
+
expect(restoreRes.status).toBe(200);
|
|
281
|
+
expect((restoreRes.body as any).restoredRevision).toBeDefined();
|
|
282
|
+
expect((restoreRes.body as any).restoredRevision.sourceMarkdown).toBe('# Lifecycle Test\n\nInitial version.');
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('manages media and agent endpoints', async () => {
|
|
286
|
+
// Media list and create
|
|
287
|
+
const mediaCreate = await handleApiRequest(
|
|
288
|
+
{
|
|
289
|
+
method: 'POST',
|
|
290
|
+
path: '/api/v1/media',
|
|
291
|
+
actor: adminActor,
|
|
292
|
+
body: {
|
|
293
|
+
filename: 'banner.png',
|
|
294
|
+
mimeType: 'image/png',
|
|
295
|
+
sizeBytes: 1024,
|
|
296
|
+
altText: 'Banner Image',
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
ctx
|
|
300
|
+
);
|
|
301
|
+
expect(mediaCreate.status).toBe(201);
|
|
302
|
+
expect((mediaCreate.body as any).id).toBeDefined();
|
|
303
|
+
|
|
304
|
+
const mediaList = await handleApiRequest(
|
|
305
|
+
{
|
|
306
|
+
method: 'GET',
|
|
307
|
+
path: '/api/v1/media',
|
|
308
|
+
actor: adminActor,
|
|
309
|
+
},
|
|
310
|
+
ctx
|
|
311
|
+
);
|
|
312
|
+
expect(mediaList.status).toBe(200);
|
|
313
|
+
expect((mediaList.body as any).items.length).toBeGreaterThan(0);
|
|
314
|
+
|
|
315
|
+
// Agent list
|
|
316
|
+
const agentList = await handleApiRequest(
|
|
317
|
+
{
|
|
318
|
+
method: 'GET',
|
|
319
|
+
path: '/api/v1/agents',
|
|
320
|
+
actor: adminActor,
|
|
321
|
+
},
|
|
322
|
+
ctx
|
|
323
|
+
);
|
|
324
|
+
expect(agentList.status).toBe(200);
|
|
325
|
+
expect(Array.isArray((agentList.body as any).items)).toBe(true);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it('exposes intelligence status, indexing, and hybrid retrieval endpoints', async () => {
|
|
329
|
+
// Set up intelligence services
|
|
330
|
+
const registry = new DefaultSourceRegistry();
|
|
331
|
+
const mockSource = new MockContentSourceAdapter('brew-sqlite', [
|
|
332
|
+
{
|
|
333
|
+
sourceId: 'brew-sqlite',
|
|
334
|
+
contentId: 'doc-ai-1',
|
|
335
|
+
revisionId: 'rev-1',
|
|
336
|
+
title: 'Distributed Enterprise Intelligence',
|
|
337
|
+
canonicalUrl: '/posts/distributed-enterprise-intelligence',
|
|
338
|
+
summary: 'How AI agents work with governed content workflows.',
|
|
339
|
+
body: '# Distributed Enterprise Intelligence\n\nHow AI agents work with governed content workflows and retrieval.',
|
|
340
|
+
publishedAt: '2026-09-12T00:00:00Z',
|
|
341
|
+
},
|
|
342
|
+
]);
|
|
343
|
+
registry.register(mockSource);
|
|
344
|
+
|
|
345
|
+
const embeddingProvider = new DeterministicMockEmbeddingProvider();
|
|
346
|
+
const semanticIndex = new MemorySemanticIndexAdapter();
|
|
347
|
+
const indexingService = new IndexingService(registry, embeddingProvider, semanticIndex);
|
|
348
|
+
const retrievalService = new HybridRetrievalService(embeddingProvider, semanticIndex);
|
|
349
|
+
const canonicalResolver = new CanonicalSourceResolver(registry);
|
|
350
|
+
|
|
351
|
+
const intelligenceCtx: ApiContext = {
|
|
352
|
+
...ctx,
|
|
353
|
+
sourceRegistry: registry,
|
|
354
|
+
indexingService,
|
|
355
|
+
retrievalService,
|
|
356
|
+
canonicalResolver,
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
// 1. Status endpoint
|
|
360
|
+
const statusRes = await handleApiRequest(
|
|
361
|
+
{ method: 'GET', path: '/api/v1/intelligence/status', actor: adminActor },
|
|
362
|
+
intelligenceCtx
|
|
363
|
+
);
|
|
364
|
+
expect(statusRes.status).toBe(200);
|
|
365
|
+
expect((statusRes.body as any).status).toBe('operational');
|
|
366
|
+
expect((statusRes.body as any).sources.length).toBe(1);
|
|
367
|
+
expect((statusRes.body as any).sources[0].id).toBe('brew-sqlite');
|
|
368
|
+
|
|
369
|
+
// 2. Trigger Indexing
|
|
370
|
+
const indexRes = await handleApiRequest(
|
|
371
|
+
{
|
|
372
|
+
method: 'POST',
|
|
373
|
+
path: '/api/v1/intelligence/index',
|
|
374
|
+
actor: adminActor,
|
|
375
|
+
body: { sourceId: 'brew-sqlite' },
|
|
376
|
+
},
|
|
377
|
+
intelligenceCtx
|
|
378
|
+
);
|
|
379
|
+
expect(indexRes.status).toBe(200);
|
|
380
|
+
expect((indexRes.body as any).summary.indexed).toBe(1);
|
|
381
|
+
|
|
382
|
+
// 3. Search endpoint (references only)
|
|
383
|
+
const searchRes = await handleApiRequest(
|
|
384
|
+
{
|
|
385
|
+
method: 'GET',
|
|
386
|
+
path: '/api/v1/intelligence/search',
|
|
387
|
+
actor: adminActor,
|
|
388
|
+
query: { q: 'enterprise intelligence' },
|
|
389
|
+
},
|
|
390
|
+
intelligenceCtx
|
|
391
|
+
);
|
|
392
|
+
expect(searchRes.status).toBe(200);
|
|
393
|
+
expect((searchRes.body as any).total).toBeGreaterThan(0);
|
|
394
|
+
const item = (searchRes.body as any).items[0];
|
|
395
|
+
expect(item.contentId).toBe('doc-ai-1');
|
|
396
|
+
expect(item.sourceId).toBe('brew-sqlite');
|
|
397
|
+
// Content body must NOT be in search reference result
|
|
398
|
+
expect(item.markdown).toBeUndefined();
|
|
399
|
+
|
|
400
|
+
// 4. Search with resolve=true (canonical resolution)
|
|
401
|
+
const resolvedSearchRes = await handleApiRequest(
|
|
402
|
+
{
|
|
403
|
+
method: 'GET',
|
|
404
|
+
path: '/api/v1/intelligence/search',
|
|
405
|
+
actor: adminActor,
|
|
406
|
+
query: { q: 'enterprise intelligence', resolve: 'true' },
|
|
407
|
+
},
|
|
408
|
+
intelligenceCtx
|
|
409
|
+
);
|
|
410
|
+
expect(resolvedSearchRes.status).toBe(200);
|
|
411
|
+
const resolvedItem = (resolvedSearchRes.body as any).items[0];
|
|
412
|
+
expect(resolvedItem.reference.contentId).toBe('doc-ai-1');
|
|
413
|
+
expect(resolvedItem.canonical.title).toBe('Distributed Enterprise Intelligence');
|
|
414
|
+
expect(resolvedItem.canonical.body).toContain('governed content workflows');
|
|
415
|
+
});
|
|
416
|
+
});
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DomainError } from '@brew-cms/core';
|
|
2
|
+
|
|
3
|
+
export interface ApiErrorEnvelope {
|
|
4
|
+
error: {
|
|
5
|
+
code: string;
|
|
6
|
+
message: string;
|
|
7
|
+
requestId?: string;
|
|
8
|
+
details?: unknown;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function formatErrorResponse(
|
|
13
|
+
err: unknown,
|
|
14
|
+
requestId?: string
|
|
15
|
+
): { status: number; body: ApiErrorEnvelope } {
|
|
16
|
+
if (err instanceof DomainError) {
|
|
17
|
+
return {
|
|
18
|
+
status: err.statusCode,
|
|
19
|
+
body: {
|
|
20
|
+
error: {
|
|
21
|
+
code: err.code,
|
|
22
|
+
message: err.message,
|
|
23
|
+
requestId,
|
|
24
|
+
details: err.details,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Fallback for unexpected internal errors: NEVER expose raw stack traces or internal SQL details
|
|
31
|
+
const fallbackMessage = err instanceof Error ? err.message : 'An unexpected internal error occurred.';
|
|
32
|
+
return {
|
|
33
|
+
status: 500,
|
|
34
|
+
body: {
|
|
35
|
+
error: {
|
|
36
|
+
code: 'INTERNAL_ERROR',
|
|
37
|
+
message: fallbackMessage,
|
|
38
|
+
requestId,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface IdempotencyRecord {
|
|
2
|
+
key: string;
|
|
3
|
+
actorId: string;
|
|
4
|
+
responseStatus: number;
|
|
5
|
+
responseBody: unknown;
|
|
6
|
+
expiresAt: Date;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class InMemoryIdempotencyStore {
|
|
10
|
+
private cache = new Map<string, IdempotencyRecord>();
|
|
11
|
+
|
|
12
|
+
get(key: string, actorId: string): IdempotencyRecord | null {
|
|
13
|
+
const compositeKey = `${actorId}:${key}`;
|
|
14
|
+
const record = this.cache.get(compositeKey);
|
|
15
|
+
if (!record) return null;
|
|
16
|
+
|
|
17
|
+
if (record.expiresAt < new Date()) {
|
|
18
|
+
this.cache.delete(compositeKey);
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return record;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
set(
|
|
25
|
+
key: string,
|
|
26
|
+
actorId: string,
|
|
27
|
+
responseStatus: number,
|
|
28
|
+
responseBody: unknown,
|
|
29
|
+
ttlSeconds: number = 3600
|
|
30
|
+
): void {
|
|
31
|
+
const compositeKey = `${actorId}:${key}`;
|
|
32
|
+
const expiresAt = new Date(Date.now() + ttlSeconds * 1000);
|
|
33
|
+
this.cache.set(compositeKey, {
|
|
34
|
+
key,
|
|
35
|
+
actorId,
|
|
36
|
+
responseStatus,
|
|
37
|
+
responseBody,
|
|
38
|
+
expiresAt,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/index.ts
ADDED
package/src/router.ts
ADDED
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Actor,
|
|
3
|
+
DocumentService,
|
|
4
|
+
WorkflowService,
|
|
5
|
+
AgentService,
|
|
6
|
+
AuditService,
|
|
7
|
+
TaxonomyService,
|
|
8
|
+
RevisionRepository,
|
|
9
|
+
MediaProvider,
|
|
10
|
+
MediaAssetRepository,
|
|
11
|
+
AgentRepository,
|
|
12
|
+
} from '@brew-cms/core';
|
|
13
|
+
import type {
|
|
14
|
+
SourceRegistry,
|
|
15
|
+
IndexingService,
|
|
16
|
+
HybridRetrievalService,
|
|
17
|
+
CanonicalSourceResolver,
|
|
18
|
+
} from '@brew-cms/intelligence';
|
|
19
|
+
import { compileContent } from '@brew-cms/content';
|
|
20
|
+
import { formatErrorResponse } from './errors.js';
|
|
21
|
+
import { InMemoryIdempotencyStore } from './idempotency.js';
|
|
22
|
+
import {
|
|
23
|
+
CreateDocumentRequestSchema,
|
|
24
|
+
UpdateDocumentRequestSchema,
|
|
25
|
+
PublishDocumentRequestSchema,
|
|
26
|
+
ScheduleDocumentRequestSchema,
|
|
27
|
+
CreateTopicRequestSchema,
|
|
28
|
+
CreateTagRequestSchema,
|
|
29
|
+
CreateSeriesRequestSchema,
|
|
30
|
+
} from './validators.js';
|
|
31
|
+
|
|
32
|
+
export interface ApiRequest {
|
|
33
|
+
method: string;
|
|
34
|
+
path: string;
|
|
35
|
+
query?: Record<string, string | undefined>;
|
|
36
|
+
headers?: Record<string, string | undefined>;
|
|
37
|
+
body?: unknown;
|
|
38
|
+
actor: Actor;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ApiResponse {
|
|
42
|
+
status: number;
|
|
43
|
+
headers?: Record<string, string>;
|
|
44
|
+
body: unknown;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ApiContext {
|
|
48
|
+
documentService: DocumentService;
|
|
49
|
+
workflowService: WorkflowService;
|
|
50
|
+
agentService: AgentService;
|
|
51
|
+
auditService: AuditService;
|
|
52
|
+
taxonomyService: TaxonomyService;
|
|
53
|
+
revisionRepo: RevisionRepository;
|
|
54
|
+
mediaProvider?: MediaProvider;
|
|
55
|
+
mediaRepo?: MediaAssetRepository;
|
|
56
|
+
agentRepo?: AgentRepository;
|
|
57
|
+
idempotencyStore?: InMemoryIdempotencyStore;
|
|
58
|
+
sourceRegistry?: SourceRegistry;
|
|
59
|
+
indexingService?: IndexingService;
|
|
60
|
+
retrievalService?: HybridRetrievalService;
|
|
61
|
+
canonicalResolver?: CanonicalSourceResolver;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function handleApiRequest(
|
|
65
|
+
req: ApiRequest,
|
|
66
|
+
ctx: ApiContext
|
|
67
|
+
): Promise<ApiResponse> {
|
|
68
|
+
const idempotencyKey = req.headers?.['idempotency-key'];
|
|
69
|
+
const idempotencyStore = ctx.idempotencyStore;
|
|
70
|
+
|
|
71
|
+
// 1. Idempotency Check for mutations
|
|
72
|
+
if (idempotencyKey && req.method !== 'GET' && idempotencyStore) {
|
|
73
|
+
const cached = idempotencyStore.get(idempotencyKey, req.actor.id);
|
|
74
|
+
if (cached) {
|
|
75
|
+
return {
|
|
76
|
+
status: cached.responseStatus,
|
|
77
|
+
headers: { 'X-Cache-Lookup': 'HIT', 'Idempotency-Key': idempotencyKey },
|
|
78
|
+
body: cached.responseBody,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const response = await dispatchRoute(req, ctx);
|
|
85
|
+
|
|
86
|
+
// Save in idempotency store if mutation
|
|
87
|
+
if (idempotencyKey && req.method !== 'GET' && idempotencyStore && response.status < 400) {
|
|
88
|
+
idempotencyStore.set(idempotencyKey, req.actor.id, response.status, response.body);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return response;
|
|
92
|
+
} catch (err: any) {
|
|
93
|
+
const errorFormatted = formatErrorResponse(err, req.headers?.['x-request-id']);
|
|
94
|
+
return {
|
|
95
|
+
status: errorFormatted.status,
|
|
96
|
+
headers: { 'Content-Type': 'application/json' },
|
|
97
|
+
body: errorFormatted.body,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function dispatchRoute(req: ApiRequest, ctx: ApiContext): Promise<ApiResponse> {
|
|
103
|
+
const { path: rawPath, method, actor } = req;
|
|
104
|
+
const urlPath = rawPath.replace(/\/$/, '');
|
|
105
|
+
|
|
106
|
+
// 1. Health Endpoints
|
|
107
|
+
if (urlPath === '/api/health/live' && method === 'GET') {
|
|
108
|
+
return { status: 200, body: { status: 'live', timestamp: new Date().toISOString() } };
|
|
109
|
+
}
|
|
110
|
+
if (urlPath === '/api/health/ready' && method === 'GET') {
|
|
111
|
+
return { status: 200, body: { status: 'ready', database: 'connected', timestamp: new Date().toISOString() } };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 2. Documents
|
|
115
|
+
if (urlPath === '/api/v1/documents') {
|
|
116
|
+
if (method === 'GET') {
|
|
117
|
+
const result = await ctx.documentService.listDocuments({
|
|
118
|
+
type: req.query?.type as any,
|
|
119
|
+
status: req.query?.status as any,
|
|
120
|
+
query: req.query?.q,
|
|
121
|
+
limit: req.query?.limit ? Number(req.query.limit) : undefined,
|
|
122
|
+
});
|
|
123
|
+
return { status: 200, body: result };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (method === 'POST') {
|
|
127
|
+
const validated = CreateDocumentRequestSchema.parse(req.body);
|
|
128
|
+
const compiled = compileContent(validated.sourceMarkdown, {
|
|
129
|
+
frontmatterDefaults: validated.frontmatter,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const res = await ctx.documentService.createDraft(actor, {
|
|
133
|
+
type: validated.type,
|
|
134
|
+
slug: validated.slug,
|
|
135
|
+
title: validated.title,
|
|
136
|
+
excerpt: validated.excerpt,
|
|
137
|
+
sourceMarkdown: compiled.sourceMarkdown,
|
|
138
|
+
frontmatter: compiled.frontmatter,
|
|
139
|
+
contentIr: compiled.contentIr,
|
|
140
|
+
contentHash: compiled.contentHash,
|
|
141
|
+
compilerVersion: compiled.compilerVersion,
|
|
142
|
+
wordCount: compiled.wordCount,
|
|
143
|
+
readingTimeSeconds: compiled.readingTimeSeconds,
|
|
144
|
+
seo: validated.seo,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
return { status: 201, body: res };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Document by ID: /api/v1/documents/:id
|
|
152
|
+
const docIdMatch = urlPath.match(/^\/api\/v1\/documents\/([^/]+)$/);
|
|
153
|
+
if (docIdMatch) {
|
|
154
|
+
const id = docIdMatch[1];
|
|
155
|
+
if (method === 'GET') {
|
|
156
|
+
const doc = await ctx.documentService.getDocument(id);
|
|
157
|
+
return { status: 200, body: doc };
|
|
158
|
+
}
|
|
159
|
+
if (method === 'PUT') {
|
|
160
|
+
const validated = UpdateDocumentRequestSchema.parse(req.body);
|
|
161
|
+
let compiled: ReturnType<typeof compileContent> | undefined;
|
|
162
|
+
if (validated.sourceMarkdown !== undefined) {
|
|
163
|
+
compiled = compileContent(validated.sourceMarkdown, {
|
|
164
|
+
frontmatterDefaults: validated.frontmatter,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const res = await ctx.documentService.updateDraft(actor, id, {
|
|
169
|
+
title: validated.title,
|
|
170
|
+
slug: validated.slug,
|
|
171
|
+
excerpt: validated.excerpt,
|
|
172
|
+
sourceMarkdown: compiled?.sourceMarkdown,
|
|
173
|
+
frontmatter: compiled?.frontmatter,
|
|
174
|
+
contentIr: compiled?.contentIr,
|
|
175
|
+
contentHash: compiled?.contentHash,
|
|
176
|
+
compilerVersion: compiled?.compilerVersion,
|
|
177
|
+
wordCount: compiled?.wordCount,
|
|
178
|
+
readingTimeSeconds: compiled?.readingTimeSeconds,
|
|
179
|
+
seo: validated.seo,
|
|
180
|
+
changeSummary: validated.changeSummary,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
return { status: 200, body: res };
|
|
184
|
+
}
|
|
185
|
+
if (method === 'DELETE') {
|
|
186
|
+
await ctx.documentService.deleteDocument(actor, id);
|
|
187
|
+
return { status: 200, body: { success: true, id } };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Revisions for document: /api/v1/documents/:id/revisions
|
|
192
|
+
const revMatch = urlPath.match(/^\/api\/v1\/documents\/([^/]+)\/revisions$/);
|
|
193
|
+
if (revMatch && method === 'GET') {
|
|
194
|
+
const id = revMatch[1];
|
|
195
|
+
const revisions = await ctx.revisionRepo.listByDocumentId(id);
|
|
196
|
+
return { status: 200, body: { revisions } };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Publish: /api/v1/documents/:id/publish
|
|
200
|
+
const publishMatch = urlPath.match(/^\/api\/v1\/documents\/([^/]+)\/publish$/);
|
|
201
|
+
if (publishMatch && method === 'POST') {
|
|
202
|
+
const id = publishMatch[1];
|
|
203
|
+
const validated = PublishDocumentRequestSchema.parse(req.body || {});
|
|
204
|
+
const res = await ctx.workflowService.publish(actor, id, validated.revisionId);
|
|
205
|
+
return { status: 200, body: res };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Submit for review: /api/v1/documents/:id/submit
|
|
209
|
+
const submitMatch = urlPath.match(/^\/api\/v1\/documents\/([^/]+)\/submit$/);
|
|
210
|
+
if (submitMatch && method === 'POST') {
|
|
211
|
+
const id = submitMatch[1];
|
|
212
|
+
const revisionId = (req.body as any)?.revisionId;
|
|
213
|
+
const res = await ctx.workflowService.submitForReview(actor, id, revisionId);
|
|
214
|
+
return { status: 200, body: res };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Approve: /api/v1/documents/:id/approve
|
|
218
|
+
const approveMatch = urlPath.match(/^\/api\/v1\/documents\/([^/]+)\/approve$/);
|
|
219
|
+
if (approveMatch && method === 'POST') {
|
|
220
|
+
const id = approveMatch[1];
|
|
221
|
+
const revisionId = (req.body as any)?.revisionId;
|
|
222
|
+
const res = await ctx.workflowService.approve(actor, id, revisionId);
|
|
223
|
+
return { status: 200, body: res };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Request Changes: /api/v1/documents/:id/request-changes
|
|
227
|
+
const reqChangesMatch = urlPath.match(/^\/api\/v1\/documents\/([^/]+)\/request-changes$/);
|
|
228
|
+
if (reqChangesMatch && method === 'POST') {
|
|
229
|
+
const id = reqChangesMatch[1];
|
|
230
|
+
const reason = (req.body as any)?.reason;
|
|
231
|
+
const res = await ctx.workflowService.requestChanges(actor, id, reason);
|
|
232
|
+
return { status: 200, body: res };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Unpublish: /api/v1/documents/:id/unpublish
|
|
236
|
+
const unpublishMatch = urlPath.match(/^\/api\/v1\/documents\/([^/]+)\/unpublish$/);
|
|
237
|
+
if (unpublishMatch && method === 'POST') {
|
|
238
|
+
const id = unpublishMatch[1];
|
|
239
|
+
const res = await ctx.workflowService.unpublish(actor, id);
|
|
240
|
+
return { status: 200, body: res };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Archive: /api/v1/documents/:id/archive
|
|
244
|
+
const archiveMatch = urlPath.match(/^\/api\/v1\/documents\/([^/]+)\/archive$/);
|
|
245
|
+
if (archiveMatch && method === 'POST') {
|
|
246
|
+
const id = archiveMatch[1];
|
|
247
|
+
const res = await ctx.workflowService.archive(actor, id);
|
|
248
|
+
return { status: 200, body: res };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Restore Revision: /api/v1/documents/:id/restore
|
|
252
|
+
const restoreMatch = urlPath.match(/^\/api\/v1\/documents\/([^/]+)\/restore$/);
|
|
253
|
+
if (restoreMatch && method === 'POST') {
|
|
254
|
+
const id = restoreMatch[1];
|
|
255
|
+
const targetRevId = (req.body as any)?.revisionId;
|
|
256
|
+
const changeSummary = (req.body as any)?.changeSummary;
|
|
257
|
+
const res = await ctx.workflowService.restoreRevision(actor, id, targetRevId, changeSummary);
|
|
258
|
+
return { status: 200, body: res };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Schedule: /api/v1/documents/:id/schedule
|
|
262
|
+
const scheduleMatch = urlPath.match(/^\/api\/v1\/documents\/([^/]+)\/schedule$/);
|
|
263
|
+
if (scheduleMatch && method === 'POST') {
|
|
264
|
+
const id = scheduleMatch[1];
|
|
265
|
+
const validated = ScheduleDocumentRequestSchema.parse(req.body);
|
|
266
|
+
const res = await ctx.workflowService.schedule(
|
|
267
|
+
actor,
|
|
268
|
+
id,
|
|
269
|
+
new Date(validated.scheduledAt),
|
|
270
|
+
validated.revisionId
|
|
271
|
+
);
|
|
272
|
+
return { status: 200, body: res };
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Taxonomies: Topics
|
|
276
|
+
if (urlPath === '/api/v1/topics') {
|
|
277
|
+
if (method === 'GET') {
|
|
278
|
+
const items = await ctx.taxonomyService.listTopics();
|
|
279
|
+
return { status: 200, body: { items } };
|
|
280
|
+
}
|
|
281
|
+
if (method === 'POST') {
|
|
282
|
+
const validated = CreateTopicRequestSchema.parse(req.body);
|
|
283
|
+
const res = await ctx.taxonomyService.createTopic({
|
|
284
|
+
id: `top_${validated.slug}`,
|
|
285
|
+
...validated,
|
|
286
|
+
});
|
|
287
|
+
return { status: 201, body: res };
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Taxonomies: Tags
|
|
292
|
+
if (urlPath === '/api/v1/tags') {
|
|
293
|
+
if (method === 'GET') {
|
|
294
|
+
const items = await ctx.taxonomyService.listTags();
|
|
295
|
+
return { status: 200, body: { items } };
|
|
296
|
+
}
|
|
297
|
+
if (method === 'POST') {
|
|
298
|
+
const validated = CreateTagRequestSchema.parse(req.body);
|
|
299
|
+
const res = await ctx.taxonomyService.createTag({
|
|
300
|
+
id: `tag_${validated.slug}`,
|
|
301
|
+
...validated,
|
|
302
|
+
});
|
|
303
|
+
return { status: 201, body: res };
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Taxonomies: Series
|
|
308
|
+
if (urlPath === '/api/v1/series') {
|
|
309
|
+
if (method === 'GET') {
|
|
310
|
+
const items = await ctx.taxonomyService.listSeries();
|
|
311
|
+
return { status: 200, body: { items } };
|
|
312
|
+
}
|
|
313
|
+
if (method === 'POST') {
|
|
314
|
+
const validated = CreateSeriesRequestSchema.parse(req.body);
|
|
315
|
+
const res = await ctx.taxonomyService.createSeries({
|
|
316
|
+
id: `ser_${validated.slug}`,
|
|
317
|
+
...validated,
|
|
318
|
+
});
|
|
319
|
+
return { status: 201, body: res };
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Media: /api/v1/media
|
|
324
|
+
if (urlPath === '/api/v1/media') {
|
|
325
|
+
if (method === 'GET') {
|
|
326
|
+
const items = ctx.mediaRepo
|
|
327
|
+
? await ctx.mediaRepo.list({
|
|
328
|
+
mimeType: req.query?.mimeType,
|
|
329
|
+
limit: req.query?.limit ? Number(req.query.limit) : 50,
|
|
330
|
+
})
|
|
331
|
+
: [];
|
|
332
|
+
return { status: 200, body: { items } };
|
|
333
|
+
}
|
|
334
|
+
if (method === 'POST') {
|
|
335
|
+
const body = req.body as any;
|
|
336
|
+
if (!ctx.mediaRepo) {
|
|
337
|
+
return { status: 500, body: { error: { code: 'NO_MEDIA_REPO', message: 'Media repository not configured.' } } };
|
|
338
|
+
}
|
|
339
|
+
let stored: any = null;
|
|
340
|
+
if (ctx.mediaProvider && body.contentBase64) {
|
|
341
|
+
stored = await ctx.mediaProvider.put({
|
|
342
|
+
filename: body.filename,
|
|
343
|
+
mimeType: body.mimeType,
|
|
344
|
+
content: Buffer.from(body.contentBase64, 'base64'),
|
|
345
|
+
prefix: body.prefix,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
const asset = await ctx.mediaRepo.create({
|
|
349
|
+
id: body.id || `med_${Date.now()}`,
|
|
350
|
+
provider: stored?.provider || 'local',
|
|
351
|
+
providerKey: stored?.providerKey || body.providerKey || body.filename,
|
|
352
|
+
mimeType: body.mimeType || 'application/octet-stream',
|
|
353
|
+
sizeBytes: stored?.sizeBytes || body.sizeBytes || 0,
|
|
354
|
+
width: body.width ?? null,
|
|
355
|
+
height: body.height ?? null,
|
|
356
|
+
altText: body.altText ?? null,
|
|
357
|
+
caption: body.caption ?? null,
|
|
358
|
+
metadata: body.metadata ?? null,
|
|
359
|
+
createdBy: actor.id,
|
|
360
|
+
});
|
|
361
|
+
return { status: 201, body: asset };
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Audit Events
|
|
366
|
+
if (urlPath === '/api/v1/audit' && method === 'GET') {
|
|
367
|
+
const events = await ctx.auditService.listEvents({
|
|
368
|
+
resourceType: req.query?.resourceType,
|
|
369
|
+
resourceId: req.query?.resourceId,
|
|
370
|
+
actorId: req.query?.actorId,
|
|
371
|
+
limit: req.query?.limit ? Number(req.query.limit) : 50,
|
|
372
|
+
});
|
|
373
|
+
return { status: 200, body: { items: events } };
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Agents: /api/v1/agents
|
|
377
|
+
if (urlPath === '/api/v1/agents') {
|
|
378
|
+
if (method === 'GET') {
|
|
379
|
+
const agents = await ctx.agentService.listAgents();
|
|
380
|
+
return { status: 200, body: { items: agents } };
|
|
381
|
+
}
|
|
382
|
+
if (method === 'POST') {
|
|
383
|
+
const body = req.body as any;
|
|
384
|
+
const agent = await ctx.agentService.registerAgent(actor, {
|
|
385
|
+
id: body.id,
|
|
386
|
+
name: body.name,
|
|
387
|
+
description: body.description,
|
|
388
|
+
scopes: body.scopes || [],
|
|
389
|
+
});
|
|
390
|
+
return { status: 201, body: agent };
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Agent Action Runs: /api/v1/agent/runs
|
|
395
|
+
if (urlPath === '/api/v1/agent/runs') {
|
|
396
|
+
if (method === 'GET') {
|
|
397
|
+
const runs = ctx.agentRepo
|
|
398
|
+
? await ctx.agentRepo.listActionRuns({ limit: req.query?.limit ? Number(req.query.limit) : 50 })
|
|
399
|
+
: [];
|
|
400
|
+
return { status: 200, body: { items: runs } };
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// Agent Action Run Approval: /api/v1/agent/runs/:id/approve
|
|
405
|
+
const approveRunMatch = urlPath.match(/^\/api\/v1\/agent\/runs\/([^/]+)\/approve$/);
|
|
406
|
+
if (approveRunMatch && method === 'POST') {
|
|
407
|
+
const runId = approveRunMatch[1];
|
|
408
|
+
const res = await ctx.agentService.approveActionRun(actor, runId, (req.body as any)?.reason);
|
|
409
|
+
return { status: 200, body: res };
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// Agent Action Run Rejection: /api/v1/agent/runs/:id/reject
|
|
413
|
+
const rejectRunMatch = urlPath.match(/^\/api\/v1\/agent\/runs\/([^/]+)\/reject$/);
|
|
414
|
+
if (rejectRunMatch && method === 'POST') {
|
|
415
|
+
const runId = rejectRunMatch[1];
|
|
416
|
+
const res = await ctx.agentService.rejectActionRun(actor, runId, (req.body as any)?.reason);
|
|
417
|
+
return { status: 200, body: res };
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Intelligence: Status / Sources
|
|
421
|
+
if (urlPath === '/api/v1/intelligence/status' && method === 'GET') {
|
|
422
|
+
const registry = ctx.sourceRegistry ?? ctx.indexingService?.registry;
|
|
423
|
+
return {
|
|
424
|
+
status: 200,
|
|
425
|
+
body: {
|
|
426
|
+
status: 'operational',
|
|
427
|
+
hasIndexingService: Boolean(ctx.indexingService),
|
|
428
|
+
hasRetrievalService: Boolean(ctx.retrievalService),
|
|
429
|
+
hasCanonicalResolver: Boolean(ctx.canonicalResolver),
|
|
430
|
+
sources: registry
|
|
431
|
+
? registry.list().map((s) => ({
|
|
432
|
+
id: s.sourceId,
|
|
433
|
+
capabilities: s.capabilities,
|
|
434
|
+
}))
|
|
435
|
+
: [],
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// Intelligence: Hybrid Retrieval
|
|
441
|
+
if (urlPath === '/api/v1/intelligence/search' && method === 'GET') {
|
|
442
|
+
if (!ctx.retrievalService) {
|
|
443
|
+
return {
|
|
444
|
+
status: 503,
|
|
445
|
+
body: {
|
|
446
|
+
error: {
|
|
447
|
+
code: 'INTELLIGENCE_UNAVAILABLE',
|
|
448
|
+
message: 'Retrieval service is not configured.',
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
const q = req.query?.q;
|
|
454
|
+
if (!q || typeof q !== 'string') {
|
|
455
|
+
return {
|
|
456
|
+
status: 400,
|
|
457
|
+
body: {
|
|
458
|
+
error: {
|
|
459
|
+
code: 'INVALID_QUERY',
|
|
460
|
+
message: "Query parameter 'q' is required.",
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
const limit = req.query?.limit ? Number(req.query.limit) : 10;
|
|
466
|
+
const minScore = req.query?.minScore ? Number(req.query.minScore) : undefined;
|
|
467
|
+
const sourceId = req.query?.sourceId;
|
|
468
|
+
|
|
469
|
+
const results = await ctx.retrievalService.search({
|
|
470
|
+
query: q,
|
|
471
|
+
limit,
|
|
472
|
+
minScore,
|
|
473
|
+
sourceId,
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
const shouldResolve = req.query?.resolve === 'true' && ctx.canonicalResolver;
|
|
477
|
+
if (shouldResolve && ctx.canonicalResolver) {
|
|
478
|
+
const resolved = await ctx.canonicalResolver.resolveMany(results);
|
|
479
|
+
return {
|
|
480
|
+
status: 200,
|
|
481
|
+
body: {
|
|
482
|
+
query: q,
|
|
483
|
+
total: results.length,
|
|
484
|
+
items: resolved.map((r) => ({
|
|
485
|
+
reference: r.reference,
|
|
486
|
+
canonical: r.content,
|
|
487
|
+
error: r.error,
|
|
488
|
+
})),
|
|
489
|
+
},
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return {
|
|
494
|
+
status: 200,
|
|
495
|
+
body: {
|
|
496
|
+
query: q,
|
|
497
|
+
total: results.length,
|
|
498
|
+
items: results,
|
|
499
|
+
},
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// Intelligence: Indexing
|
|
504
|
+
if (urlPath === '/api/v1/intelligence/index' && method === 'POST') {
|
|
505
|
+
if (!ctx.indexingService) {
|
|
506
|
+
return {
|
|
507
|
+
status: 503,
|
|
508
|
+
body: {
|
|
509
|
+
error: {
|
|
510
|
+
code: 'INTELLIGENCE_UNAVAILABLE',
|
|
511
|
+
message: 'Indexing service is not configured.',
|
|
512
|
+
},
|
|
513
|
+
},
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
const body = (req.body || {}) as { sourceId?: string; contentId?: string; revisionId?: string };
|
|
517
|
+
if (body.sourceId && body.contentId) {
|
|
518
|
+
const result = await ctx.indexingService.indexDocument(body.sourceId, body.contentId, body.revisionId);
|
|
519
|
+
return { status: 200, body: { success: true, result } };
|
|
520
|
+
} else if (body.sourceId) {
|
|
521
|
+
const summary = await ctx.indexingService.syncSource(body.sourceId);
|
|
522
|
+
return { status: 200, body: { success: true, summary } };
|
|
523
|
+
} else {
|
|
524
|
+
const summaries = await ctx.indexingService.syncAll();
|
|
525
|
+
return { status: 200, body: { success: true, summaries } };
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
return {
|
|
530
|
+
status: 404,
|
|
531
|
+
body: {
|
|
532
|
+
error: {
|
|
533
|
+
code: 'ROUTE_NOT_FOUND',
|
|
534
|
+
message: `Endpoint '${method} ${urlPath}' was not found.`,
|
|
535
|
+
},
|
|
536
|
+
},
|
|
537
|
+
};
|
|
538
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const CreateDocumentRequestSchema = z.object({
|
|
4
|
+
type: z.enum(['post', 'page']),
|
|
5
|
+
slug: z.string().min(1),
|
|
6
|
+
title: z.string().min(1),
|
|
7
|
+
excerpt: z.string().optional().nullable(),
|
|
8
|
+
sourceMarkdown: z.string(),
|
|
9
|
+
frontmatter: z.record(z.unknown()).optional(),
|
|
10
|
+
seo: z
|
|
11
|
+
.object({
|
|
12
|
+
metaTitle: z.string().optional(),
|
|
13
|
+
metaDescription: z.string().optional(),
|
|
14
|
+
ogImage: z.string().optional(),
|
|
15
|
+
noIndex: z.boolean().optional(),
|
|
16
|
+
})
|
|
17
|
+
.optional()
|
|
18
|
+
.nullable(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const UpdateDocumentRequestSchema = z.object({
|
|
22
|
+
title: z.string().optional(),
|
|
23
|
+
slug: z.string().optional(),
|
|
24
|
+
excerpt: z.string().optional().nullable(),
|
|
25
|
+
sourceMarkdown: z.string().optional(),
|
|
26
|
+
frontmatter: z.record(z.unknown()).optional(),
|
|
27
|
+
seo: z
|
|
28
|
+
.object({
|
|
29
|
+
metaTitle: z.string().optional(),
|
|
30
|
+
metaDescription: z.string().optional(),
|
|
31
|
+
ogImage: z.string().optional(),
|
|
32
|
+
noIndex: z.boolean().optional(),
|
|
33
|
+
})
|
|
34
|
+
.optional()
|
|
35
|
+
.nullable(),
|
|
36
|
+
changeSummary: z.string().optional().nullable(),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const PublishDocumentRequestSchema = z.object({
|
|
40
|
+
revisionId: z.string().optional(),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const ScheduleDocumentRequestSchema = z.object({
|
|
44
|
+
scheduledAt: z.string().datetime(),
|
|
45
|
+
revisionId: z.string().optional(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export const CreateTopicRequestSchema = z.object({
|
|
49
|
+
slug: z.string().min(1),
|
|
50
|
+
name: z.string().min(1),
|
|
51
|
+
description: z.string().optional().nullable(),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export const CreateTagRequestSchema = z.object({
|
|
55
|
+
slug: z.string().min(1),
|
|
56
|
+
name: z.string().min(1),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const CreateSeriesRequestSchema = z.object({
|
|
60
|
+
slug: z.string().min(1),
|
|
61
|
+
name: z.string().min(1),
|
|
62
|
+
description: z.string().optional().nullable(),
|
|
63
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "src",
|
|
5
|
+
"outDir": "dist"
|
|
6
|
+
},
|
|
7
|
+
"references": [
|
|
8
|
+
{ "path": "../core" },
|
|
9
|
+
{ "path": "../content" },
|
|
10
|
+
{ "path": "../policy" },
|
|
11
|
+
{ "path": "../intelligence" }
|
|
12
|
+
],
|
|
13
|
+
"include": ["src/**/*"]
|
|
14
|
+
}
|