@lacecms/application 0.1.0-alpha.7 → 0.1.0-rc1
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/dist/collection-queries.d.ts +47 -0
- package/dist/collection-queries.d.ts.map +1 -0
- package/dist/collection-queries.js +171 -0
- package/dist/collection-queries.js.map +1 -0
- package/dist/configuration-evolution.d.ts +15 -2
- package/dist/configuration-evolution.d.ts.map +1 -1
- package/dist/configuration-evolution.js +87 -5
- package/dist/configuration-evolution.js.map +1 -1
- package/dist/configuration-fields.d.ts +5 -3
- package/dist/configuration-fields.d.ts.map +1 -1
- package/dist/configuration-fields.js +95 -6
- package/dist/configuration-fields.js.map +1 -1
- package/dist/configuration-links.d.ts +15 -0
- package/dist/configuration-links.d.ts.map +1 -0
- package/dist/configuration-links.js +52 -0
- package/dist/configuration-links.js.map +1 -0
- package/dist/configuration-migration.d.ts +2 -0
- package/dist/configuration-migration.d.ts.map +1 -1
- package/dist/configuration-migration.js +29 -1
- package/dist/configuration-migration.js.map +1 -1
- package/dist/configuration-sync.d.ts +7 -0
- package/dist/configuration-sync.d.ts.map +1 -1
- package/dist/configuration-sync.js +53 -10
- package/dist/configuration-sync.js.map +1 -1
- package/dist/content-authority.d.ts +27 -0
- package/dist/content-authority.d.ts.map +1 -0
- package/dist/content-authority.js +45 -0
- package/dist/content-authority.js.map +1 -0
- package/dist/content-use-cases.d.ts +87 -7
- package/dist/content-use-cases.d.ts.map +1 -1
- package/dist/content-use-cases.js +266 -78
- package/dist/content-use-cases.js.map +1 -1
- package/dist/index.d.ts +133 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +65 -1
- package/dist/index.js.map +1 -1
- package/dist/internal-links.d.ts +117 -0
- package/dist/internal-links.d.ts.map +1 -0
- package/dist/internal-links.js +131 -0
- package/dist/internal-links.js.map +1 -0
- package/dist/media-use-cases.d.ts +11 -1
- package/dist/media-use-cases.d.ts.map +1 -1
- package/dist/media-use-cases.js +53 -5
- package/dist/media-use-cases.js.map +1 -1
- package/dist/oauth.d.ts +91 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +21 -0
- package/dist/oauth.js.map +1 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-use-cases.d.ts","sourceRoot":"","sources":["../src/content-use-cases.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"content-use-cases.d.ts","sourceRoot":"","sources":["../src/content-use-cases.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAezB,OAAO,KAAK,EAEV,aAAa,EAEb,UAAU,EACV,eAAe,EACf,UAAU,EAEX,MAAM,kBAAkB,CAAC;AAE1B;;;GAGG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAmB1D,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EAEjB,aAAa,EACb,QAAQ,EACR,OAAO,EACP,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAQzB,OAAO,KAAK,EACV,YAAY,EACZ,KAAK,EAEL,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EAGpB,WAAW,EACX,oBAAoB,EACpB,YAAY,EAEZ,qBAAqB,EAErB,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC;IAC3C,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IAC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mB;IA6C3B,OAAO,CAAC,YAAY;CAWrB"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { authorizeContentOperation } from "./content-authority.js";
|
|
2
|
+
import { resolveCollectionQuery, validateListQueryBudget, NODE_LIST_QUERY_LIMITS, } from "./collection-queries.js";
|
|
3
|
+
import { collectFieldMedia, toBlockMetadata, collectSnapshotInternalLinks, ContentValidationError, declaresFieldVisibility, detachFieldMedia, encodeFieldPath, MAX_TITLE_LENGTH, publishedBlockData, publishedFieldValues, sha256CanonicalJson, validateEntryAggregate, } from "@lacecms/content";
|
|
2
4
|
/**
|
|
3
5
|
* Thrown by the content use cases when a submitted or published aggregate
|
|
4
6
|
* fails content validation; its issues carry stable codes and paths.
|
|
5
7
|
*/
|
|
6
8
|
export { ContentValidationError } from "@lacecms/content";
|
|
7
|
-
import { DomainError, assertCollectionEntryOperation, assertOrderedBlockPositions, blockKey, contentEntryId, contentModelKey, contentSnapshotId, createContentEntry, mediaId, normalizeEntrySeo, requirePermission, requirePublishedSnapshot, contentPublicPath, } from "@lacecms/domain";
|
|
8
|
-
import { CONTENT_ENTRY_SORTS, CONTENT_ENTRY_STATUSES, DEFAULT_CONTENT_ENTRY_SORT,
|
|
9
|
+
import { DomainError, CollectionQueryValidationError, isContentSlug, auditActor, assertCollectionEntryOperation, assertOrderedBlockPositions, blockKey, contentEntryId, contentModelKey, contentSnapshotId, createContentEntry, mediaId, normalizeEntrySeo, requirePermission, requirePublishedSnapshot, contentPublicPath, } from "@lacecms/domain";
|
|
10
|
+
import { CONTENT_ENTRY_SORTS, CONTENT_ENTRY_STATUSES, DEFAULT_CONTENT_ENTRY_SORT, publicationIdempotencyKey, publicationRequestFingerprint, } from "./index.js";
|
|
11
|
+
import { internalLinkIssuePath } from "./internal-links.js";
|
|
9
12
|
const DUPLICATE_TITLE_SUFFIX = " (copy)";
|
|
10
13
|
/**
|
|
11
14
|
* Appends the duplicate suffix, shortening the source title so the result
|
|
@@ -46,23 +49,135 @@ export function contentModelRoute(model) {
|
|
|
46
49
|
function systemTitle(model, title) {
|
|
47
50
|
return model.kind === "global" ? (model.label ?? model.key) : title;
|
|
48
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Validates and normalizes a submitted draft exactly as the content use cases
|
|
54
|
+
* store it. Pure: no persistence, authorization, media or link-target checks,
|
|
55
|
+
* so clients can predict whether a save would change the stored draft.
|
|
56
|
+
*/
|
|
57
|
+
export function normalizeDraftCandidate(input) {
|
|
58
|
+
const { blocks: registry, draft, mode, model } = input;
|
|
59
|
+
assertOrderedBlockPositions(draft.blocks);
|
|
60
|
+
const aggregate = validateEntryAggregate({
|
|
61
|
+
blocks: draft.blocks.map(({ anchor, className, data, hidden, key, schemaVersion, settings, type }) => ({
|
|
62
|
+
...(anchor === undefined ? {} : { anchor }),
|
|
63
|
+
...(className === undefined ? {} : { className }),
|
|
64
|
+
data,
|
|
65
|
+
...(hidden === undefined ? {} : { hidden }),
|
|
66
|
+
key,
|
|
67
|
+
schemaVersion,
|
|
68
|
+
...(settings === undefined ? {} : { settings }),
|
|
69
|
+
type,
|
|
70
|
+
})),
|
|
71
|
+
fields: draft.fields,
|
|
72
|
+
kind: model.kind,
|
|
73
|
+
...(draft.slug === undefined ? {} : { slug: draft.slug }),
|
|
74
|
+
title: systemTitle(model, draft.title),
|
|
75
|
+
}, model, registry, mode);
|
|
76
|
+
const blocks = aggregate.blocks.map((block, index) => ({
|
|
77
|
+
...(block.anchor === undefined ? {} : { anchor: block.anchor }),
|
|
78
|
+
...(block.className === undefined ? {} : { className: block.className }),
|
|
79
|
+
data: block.data,
|
|
80
|
+
hidden: block.hidden,
|
|
81
|
+
key: blockKey(block.key),
|
|
82
|
+
position: draft.blocks[index].position,
|
|
83
|
+
schemaVersion: block.schemaVersion,
|
|
84
|
+
settings: block.settings,
|
|
85
|
+
type: block.type,
|
|
86
|
+
}));
|
|
87
|
+
const seo = normalizeEntrySeo(draft.seo ?? null, { enabled: seoEnabled(model) });
|
|
88
|
+
return {
|
|
89
|
+
blocks,
|
|
90
|
+
fields: aggregate.fields,
|
|
91
|
+
...(seo === undefined ? {} : { seo }),
|
|
92
|
+
...(aggregate.slug === undefined ? {} : { slug: aggregate.slug }),
|
|
93
|
+
title: aggregate.title,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
49
96
|
function commandEntry(result) {
|
|
50
97
|
if (result.entry === undefined) {
|
|
51
98
|
throw new DomainError("CONTENT_INVALID_STATE", "Content command did not return an entry.");
|
|
52
99
|
}
|
|
53
100
|
return detached(result.entry);
|
|
54
101
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Portable orchestration for content lifecycle commands. Transport handlers and
|
|
57
|
-
* persistence adapters remain outside this service.
|
|
58
|
-
*/
|
|
59
102
|
export class ContentUseCases {
|
|
60
103
|
dependencies;
|
|
104
|
+
listQueryLimits;
|
|
105
|
+
/** Memoized `declaresFieldVisibility` per model key and block type; config is fixed. */
|
|
106
|
+
visibilityOwners = new Map();
|
|
61
107
|
constructor(dependencies) {
|
|
62
108
|
this.dependencies = dependencies;
|
|
109
|
+
this.listQueryLimits = Object.freeze({
|
|
110
|
+
...(dependencies.listQueryLimits ?? NODE_LIST_QUERY_LIMITS),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
discoverModels(input) {
|
|
114
|
+
authorizeContentOperation(input.actor, "discoverModels");
|
|
115
|
+
return detached({
|
|
116
|
+
items: this.dependencies.config.content.map((model) => ({
|
|
117
|
+
key: model.key,
|
|
118
|
+
kind: model.kind,
|
|
119
|
+
version: model.version,
|
|
120
|
+
fields: model.fields,
|
|
121
|
+
blocks: model.blocks,
|
|
122
|
+
blockDefinitions: model.blocks.map((type) => {
|
|
123
|
+
const definition = this.dependencies.config.blocks.get(type);
|
|
124
|
+
if (!definition)
|
|
125
|
+
throw new DomainError("CONTENT_INVALID_STATE", "Configured block metadata is unavailable.");
|
|
126
|
+
return toBlockMetadata(definition);
|
|
127
|
+
}),
|
|
128
|
+
...(model.label === undefined ? {} : { label: model.label }),
|
|
129
|
+
...(model.description === undefined ? {} : { description: model.description }),
|
|
130
|
+
...(model.layout === undefined ? {} : { layout: model.layout }),
|
|
131
|
+
...(model.visibility === undefined ? {} : { visibility: model.visibility }),
|
|
132
|
+
...(model.kind === "page" ? { path: model.path } : {}),
|
|
133
|
+
...(model.kind === "collection"
|
|
134
|
+
? {
|
|
135
|
+
route: model.route,
|
|
136
|
+
...(model.listFields === undefined ? {} : { listFields: model.listFields }),
|
|
137
|
+
...(model.listOptions === undefined ? {} : { listOptions: model.listOptions }),
|
|
138
|
+
}
|
|
139
|
+
: {}),
|
|
140
|
+
...(model.kind !== "global" && model.seo !== undefined ? { seo: model.seo } : {}),
|
|
141
|
+
...(model.kind === "global" && model.seoDefaults !== undefined
|
|
142
|
+
? { seoDefaults: model.seoDefaults }
|
|
143
|
+
: {}),
|
|
144
|
+
})),
|
|
145
|
+
listQueryLimits: this.listQueryLimits,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/** Full authorized admin read, including safe attribution and SEO visibility. */
|
|
149
|
+
async loadAdminEntry(input) {
|
|
150
|
+
authorizeContentOperation(input.actor, "load");
|
|
151
|
+
const entry = await this.dependencies.content.load({ entryId: input.entryId });
|
|
152
|
+
return entry === null ? null : this.adminProjection(entry);
|
|
153
|
+
}
|
|
154
|
+
/** Prepares the same read projection after a create/save without adapter lookups. */
|
|
155
|
+
async projectAdminEntry(input) {
|
|
156
|
+
authorizeContentOperation(input.actor, "load");
|
|
157
|
+
return this.adminProjection(input.entry);
|
|
158
|
+
}
|
|
159
|
+
/** Shared publication enrichment for REST and MCP, using safe admin metadata. */
|
|
160
|
+
async projectPublicationResult(input) {
|
|
161
|
+
authorizeContentOperation(input.actor, "publish");
|
|
162
|
+
const projection = await this.adminProjection(input.result.entry);
|
|
163
|
+
return { ...input.result, seo: projection.seo, updatedBy: projection.updatedBy };
|
|
164
|
+
}
|
|
165
|
+
async adminProjection(entry) {
|
|
166
|
+
const model = this.model(entry.model.key);
|
|
167
|
+
return detached({
|
|
168
|
+
entry,
|
|
169
|
+
updatedBy: await this.actorSummary(entry.draft.updatedBy.id),
|
|
170
|
+
seo: seoEnabled(model),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
async actorSummary(id) {
|
|
174
|
+
const [summary] = await this.dependencies.content.describeActors([id]);
|
|
175
|
+
if (!summary || summary.id !== id)
|
|
176
|
+
throw new DomainError("CONTENT_INVALID_STATE", "Actor description is unavailable.");
|
|
177
|
+
return { id: summary.id, displayName: summary.displayName };
|
|
63
178
|
}
|
|
64
179
|
async create(input) {
|
|
65
|
-
|
|
180
|
+
authorizeContentOperation(input.actor, "create");
|
|
66
181
|
const model = this.model(input.modelKey);
|
|
67
182
|
const draft = await this.validateDraft({ ...input, title: systemTitle(model, input.title) }, model, "draft");
|
|
68
183
|
const now = this.dependencies.clock.now();
|
|
@@ -76,89 +191,101 @@ export class ContentUseCases {
|
|
|
76
191
|
revision: 1,
|
|
77
192
|
state: "draft",
|
|
78
193
|
updatedAt: now,
|
|
79
|
-
updatedBy: input.actor,
|
|
194
|
+
updatedBy: auditActor(input.actor),
|
|
80
195
|
},
|
|
81
196
|
id,
|
|
82
197
|
model: contentModelRoute(model),
|
|
83
198
|
});
|
|
84
|
-
return commandEntry(await this.dependencies.content.create({
|
|
199
|
+
return commandEntry(await this.dependencies.content.create({
|
|
200
|
+
entry,
|
|
201
|
+
mediaReferences: draft.mediaReferences,
|
|
202
|
+
internalLinks: draft.internalLinks,
|
|
203
|
+
}));
|
|
85
204
|
}
|
|
86
205
|
async list(input) {
|
|
87
|
-
|
|
206
|
+
authorizeContentOperation(input.actor, "list");
|
|
88
207
|
const model = this.model(input.modelKey);
|
|
89
208
|
const q = input.q?.trim();
|
|
90
|
-
if (q !== undefined && q.length > MAX_CONTENT_ENTRY_SEARCH_LENGTH) {
|
|
91
|
-
throw new DomainError("CONTENT_INVALID_STATE", `Search terms must not exceed ${MAX_CONTENT_ENTRY_SEARCH_LENGTH} characters.`);
|
|
92
|
-
}
|
|
93
209
|
if (input.status !== undefined &&
|
|
94
210
|
!CONTENT_ENTRY_STATUSES.includes(input.status)) {
|
|
95
211
|
throw new DomainError("CONTENT_INVALID_STATE", "Entry status filter is unsupported.");
|
|
96
212
|
}
|
|
97
|
-
if (input.sort !== undefined &&
|
|
213
|
+
if (input.sort !== undefined &&
|
|
214
|
+
!CONTENT_ENTRY_SORTS.includes(input.sort) &&
|
|
215
|
+
!/^-?field:[A-Za-z][A-Za-z0-9]*$/u.test(input.sort)) {
|
|
98
216
|
throw new DomainError("CONTENT_INVALID_STATE", "Entry sort is unsupported.");
|
|
99
217
|
}
|
|
218
|
+
if (input.slug !== undefined && (model.kind !== "collection" || !isContentSlug(input.slug)))
|
|
219
|
+
throw new CollectionQueryValidationError("/slug");
|
|
220
|
+
const query = resolveCollectionQuery(model, input.sort, input.filters, this.listQueryLimits);
|
|
221
|
+
validateListQueryBudget(q, [], this.listQueryLimits);
|
|
100
222
|
return detached(await this.dependencies.content.list({
|
|
223
|
+
...(query === undefined ? {} : { query }),
|
|
101
224
|
...(input.after === undefined ? {} : { after: input.after }),
|
|
102
225
|
limit: input.limit,
|
|
226
|
+
listQueryLimits: this.listQueryLimits,
|
|
103
227
|
listFields: model.kind === "collection" ? [...(model.listFields ?? [])] : [],
|
|
104
228
|
modelKey: contentModelKey(model.key),
|
|
105
229
|
...(q === undefined || q.length === 0 ? {} : { q }),
|
|
230
|
+
...(input.slug === undefined ? {} : { slug: input.slug }),
|
|
106
231
|
sort: input.sort ?? DEFAULT_CONTENT_ENTRY_SORT,
|
|
107
232
|
...(input.status === undefined ? {} : { status: input.status }),
|
|
108
233
|
}));
|
|
109
234
|
}
|
|
110
235
|
/** Resolves an audit actor's display name so clients never need the users API. */
|
|
111
236
|
async describeActor(input) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (summary === undefined || summary.id !== input.actorId) {
|
|
115
|
-
throw new DomainError("CONTENT_INVALID_STATE", "Actor description is unavailable.");
|
|
116
|
-
}
|
|
117
|
-
return detached(summary);
|
|
237
|
+
authorizeContentOperation(input.actor, "describeActor");
|
|
238
|
+
return this.actorSummary(input.actorId);
|
|
118
239
|
}
|
|
119
240
|
async load(input) {
|
|
120
|
-
|
|
241
|
+
authorizeContentOperation(input.actor, "load");
|
|
121
242
|
const entry = await this.dependencies.content.load({ entryId: input.entryId });
|
|
122
243
|
return entry === null ? null : detached(entry);
|
|
123
244
|
}
|
|
124
245
|
async loadDraft(input) {
|
|
125
|
-
|
|
246
|
+
authorizeContentOperation(input.actor, "loadDraft");
|
|
126
247
|
const draft = await this.dependencies.content.loadDraft({ entryId: input.entryId });
|
|
127
248
|
return draft === null ? null : detached(draft);
|
|
128
249
|
}
|
|
129
250
|
async loadPublished(input) {
|
|
130
|
-
|
|
251
|
+
authorizeContentOperation(input.actor, "loadPublished");
|
|
131
252
|
const published = await this.dependencies.content.loadPublished({ entryId: input.entryId });
|
|
132
253
|
return published === null ? null : detached(published);
|
|
133
254
|
}
|
|
134
255
|
async save(input) {
|
|
135
|
-
|
|
256
|
+
authorizeContentOperation(input.actor, "save");
|
|
136
257
|
const entry = await this.entry(input.entryId);
|
|
137
258
|
const model = this.model(entry.model.key);
|
|
138
259
|
const draft = await this.validateDraft({ ...input, title: systemTitle(model, input.title) }, model, "draft");
|
|
139
260
|
return commandEntry(await this.dependencies.content.saveCompleteDraft({
|
|
140
261
|
entryId: entry.id,
|
|
262
|
+
internalLinks: draft.internalLinks,
|
|
141
263
|
mutation: {
|
|
142
264
|
...draft,
|
|
143
265
|
expectedRevision: input.expectedRevision,
|
|
144
266
|
updatedAt: this.dependencies.clock.now(),
|
|
145
|
-
updatedBy: input.actor,
|
|
267
|
+
updatedBy: auditActor(input.actor),
|
|
146
268
|
},
|
|
147
269
|
}));
|
|
148
270
|
}
|
|
149
271
|
async publish(input) {
|
|
150
|
-
|
|
272
|
+
authorizeContentOperation(input.actor, "publish");
|
|
151
273
|
const entry = await this.entry(input.entryId);
|
|
152
|
-
const draft = await this.validateDraft(entry.draft, this.model(entry.model.key), "publish");
|
|
274
|
+
const draft = await this.validateDraft(entry.draft, this.model(entry.model.key), "publish", entry.id);
|
|
153
275
|
contentPublicPath(entry.model, draft.slug);
|
|
276
|
+
const projection = this.publishedProjection(this.model(entry.model.key), draft);
|
|
277
|
+
// A projection belongs to one draft revision; never attach it to another.
|
|
278
|
+
if (projection !== undefined && entry.draft.revision !== input.expectedRevision)
|
|
279
|
+
throw new DomainError("CONTENT_REVISION_CONFLICT", "The draft revision no longer matches the expected revision.");
|
|
154
280
|
const result = await this.dependencies.content.publish({
|
|
155
281
|
entryId: entry.id,
|
|
156
282
|
expectedRevision: input.expectedRevision,
|
|
283
|
+
...(projection === undefined ? {} : { projection }),
|
|
157
284
|
...(input.idempotencyKey === undefined
|
|
158
285
|
? {}
|
|
159
286
|
: { idempotency: await this.idempotency(input, draft) }),
|
|
160
287
|
publishedAt: this.dependencies.clock.now(),
|
|
161
|
-
publishedBy: input.actor,
|
|
288
|
+
publishedBy: auditActor(input.actor),
|
|
162
289
|
publishedSnapshotId: contentSnapshotId(this.dependencies.idGenerator.next()),
|
|
163
290
|
});
|
|
164
291
|
return {
|
|
@@ -170,7 +297,7 @@ export class ContentUseCases {
|
|
|
170
297
|
};
|
|
171
298
|
}
|
|
172
299
|
async unpublish(input) {
|
|
173
|
-
|
|
300
|
+
authorizeContentOperation(input.actor, "unpublish");
|
|
174
301
|
const entry = await this.entry(input.entryId);
|
|
175
302
|
const idempotency = input.idempotencyKey === undefined
|
|
176
303
|
? undefined
|
|
@@ -181,6 +308,7 @@ export class ContentUseCases {
|
|
|
181
308
|
entryId: input.entryId,
|
|
182
309
|
expectedPublishedSnapshotId: input.expectedPublishedSnapshotId,
|
|
183
310
|
operation: "unpublish",
|
|
311
|
+
...(input.linkImpact === undefined ? {} : { linkImpact: { ...input.linkImpact } }),
|
|
184
312
|
})),
|
|
185
313
|
key: publicationIdempotencyKey(input.idempotencyKey),
|
|
186
314
|
};
|
|
@@ -191,9 +319,10 @@ export class ContentUseCases {
|
|
|
191
319
|
const result = await this.dependencies.content.unpublish({
|
|
192
320
|
entryId: entry.id,
|
|
193
321
|
expectedPublishedSnapshotId: input.expectedPublishedSnapshotId,
|
|
322
|
+
...(input.linkImpact === undefined ? {} : { linkImpact: input.linkImpact }),
|
|
194
323
|
...(idempotency === undefined ? {} : { idempotency }),
|
|
195
324
|
unpublishedAt: this.dependencies.clock.now(),
|
|
196
|
-
unpublishedBy: input.actor,
|
|
325
|
+
unpublishedBy: auditActor(input.actor),
|
|
197
326
|
});
|
|
198
327
|
return {
|
|
199
328
|
build: result.outcome === "replayed"
|
|
@@ -204,7 +333,7 @@ export class ContentUseCases {
|
|
|
204
333
|
};
|
|
205
334
|
}
|
|
206
335
|
async revertDraft(input) {
|
|
207
|
-
|
|
336
|
+
authorizeContentOperation(input.actor, "revertDraft");
|
|
208
337
|
const entry = await this.entry(input.entryId);
|
|
209
338
|
const published = requirePublishedSnapshot(entry);
|
|
210
339
|
return commandEntry(await this.dependencies.content.revertDraft({
|
|
@@ -212,11 +341,11 @@ export class ContentUseCases {
|
|
|
212
341
|
expectedPublishedSnapshotId: published.id,
|
|
213
342
|
expectedRevision: input.expectedRevision,
|
|
214
343
|
revertedAt: this.dependencies.clock.now(),
|
|
215
|
-
revertedBy: input.actor,
|
|
344
|
+
revertedBy: auditActor(input.actor),
|
|
216
345
|
}));
|
|
217
346
|
}
|
|
218
347
|
async duplicate(input) {
|
|
219
|
-
|
|
348
|
+
authorizeContentOperation(input.actor, "duplicate");
|
|
220
349
|
const source = await this.entry(input.entryId);
|
|
221
350
|
assertCollectionEntryOperation(source, "duplicate");
|
|
222
351
|
if (input.expectedRevision !== undefined && input.expectedRevision !== source.draft.revision) {
|
|
@@ -243,7 +372,7 @@ export class ContentUseCases {
|
|
|
243
372
|
revision: 1,
|
|
244
373
|
state: "draft",
|
|
245
374
|
updatedAt: now,
|
|
246
|
-
updatedBy: input.actor,
|
|
375
|
+
updatedBy: auditActor(input.actor),
|
|
247
376
|
},
|
|
248
377
|
id,
|
|
249
378
|
model: contentModelRoute(model),
|
|
@@ -252,6 +381,7 @@ export class ContentUseCases {
|
|
|
252
381
|
duplicateOf: { entryId: source.id, expectedRevision: source.draft.revision },
|
|
253
382
|
entry,
|
|
254
383
|
mediaReferences: draft.mediaReferences,
|
|
384
|
+
internalLinks: draft.internalLinks,
|
|
255
385
|
}));
|
|
256
386
|
}
|
|
257
387
|
/**
|
|
@@ -261,7 +391,7 @@ export class ContentUseCases {
|
|
|
261
391
|
* that does not use the item is left unchanged. Returns whether it saved.
|
|
262
392
|
*/
|
|
263
393
|
async detachMedia(input) {
|
|
264
|
-
|
|
394
|
+
authorizeContentOperation(input.actor, "detachMedia");
|
|
265
395
|
const entry = await this.entry(input.entryId);
|
|
266
396
|
const model = this.model(entry.model.key);
|
|
267
397
|
const { draft } = entry;
|
|
@@ -298,14 +428,15 @@ export class ContentUseCases {
|
|
|
298
428
|
return true;
|
|
299
429
|
}
|
|
300
430
|
async delete(input) {
|
|
301
|
-
|
|
431
|
+
authorizeContentOperation(input.actor, "delete");
|
|
302
432
|
const entry = await this.entry(input.entryId);
|
|
303
433
|
assertCollectionEntryOperation(entry, "delete");
|
|
304
434
|
if (entry.published !== undefined)
|
|
305
435
|
requirePermission(input.actor, "content:publish");
|
|
306
436
|
await this.dependencies.content.delete({
|
|
307
437
|
deletedAt: this.dependencies.clock.now(),
|
|
308
|
-
|
|
438
|
+
...(input.linkImpact === undefined ? {} : { linkImpact: input.linkImpact }),
|
|
439
|
+
deletedBy: auditActor(input.actor),
|
|
309
440
|
entryId: entry.id,
|
|
310
441
|
...(entry.published === undefined ? {} : { expectedPublishedSnapshotId: entry.published.id }),
|
|
311
442
|
expectedRevision: input.expectedRevision,
|
|
@@ -337,46 +468,20 @@ export class ContentUseCases {
|
|
|
337
468
|
}
|
|
338
469
|
return model;
|
|
339
470
|
}
|
|
340
|
-
async validateDraft(input, model, mode) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
...(hidden === undefined ? {} : { hidden }),
|
|
348
|
-
key,
|
|
349
|
-
schemaVersion,
|
|
350
|
-
...(settings === undefined ? {} : { settings }),
|
|
351
|
-
type,
|
|
352
|
-
})),
|
|
353
|
-
fields: input.fields,
|
|
354
|
-
kind: model.kind,
|
|
355
|
-
...(input.slug === undefined ? {} : { slug: input.slug }),
|
|
356
|
-
title: input.title,
|
|
357
|
-
}, model, this.dependencies.config.blocks, mode);
|
|
358
|
-
const blocks = aggregate.blocks.map((block, index) => ({
|
|
359
|
-
...(block.anchor === undefined ? {} : { anchor: block.anchor }),
|
|
360
|
-
...(block.className === undefined ? {} : { className: block.className }),
|
|
361
|
-
data: block.data,
|
|
362
|
-
hidden: block.hidden,
|
|
363
|
-
key: blockKey(block.key),
|
|
364
|
-
position: input.blocks[index].position,
|
|
365
|
-
schemaVersion: block.schemaVersion,
|
|
366
|
-
settings: block.settings,
|
|
367
|
-
type: block.type,
|
|
368
|
-
}));
|
|
369
|
-
const seo = normalizeEntrySeo(input.seo ?? null, { enabled: seoEnabled(model) });
|
|
370
|
-
const normalized = {
|
|
371
|
-
blocks,
|
|
372
|
-
fields: aggregate.fields,
|
|
373
|
-
...(seo === undefined ? {} : { seo }),
|
|
374
|
-
...(aggregate.slug === undefined ? {} : { slug: aggregate.slug }),
|
|
375
|
-
title: aggregate.title,
|
|
376
|
-
};
|
|
471
|
+
async validateDraft(input, model, mode, publishingEntryId) {
|
|
472
|
+
const normalized = normalizeDraftCandidate({
|
|
473
|
+
blocks: this.dependencies.config.blocks,
|
|
474
|
+
draft: input,
|
|
475
|
+
mode,
|
|
476
|
+
model,
|
|
477
|
+
});
|
|
377
478
|
const mediaReferences = this.collectMedia(normalized.fields, model.fields, "$fields");
|
|
378
|
-
if (seo?.image !== undefined) {
|
|
379
|
-
mediaReferences.push({
|
|
479
|
+
if (normalized.seo?.image !== undefined) {
|
|
480
|
+
mediaReferences.push({
|
|
481
|
+
fieldPath: "image",
|
|
482
|
+
mediaId: mediaId(normalized.seo.image),
|
|
483
|
+
sourceKey: "$seo",
|
|
484
|
+
});
|
|
380
485
|
}
|
|
381
486
|
for (const block of normalized.blocks) {
|
|
382
487
|
mediaReferences.push(...this.collectMedia(block.data, this.dependencies.config.blocks.get(block.type).fields, block.key));
|
|
@@ -392,7 +497,90 @@ export class ContentUseCases {
|
|
|
392
497
|
if (!active.has(id))
|
|
393
498
|
throw new DomainError("CONTENT_INVALID_STATE", `Media ${id} is unavailable.`);
|
|
394
499
|
}
|
|
395
|
-
|
|
500
|
+
// Links inside hidden targets are not delivered, so publication never checks them.
|
|
501
|
+
const internalLinks = this.internalLinks(model, normalized.fields, normalized.blocks);
|
|
502
|
+
if (internalLinks.length > 0) {
|
|
503
|
+
if (this.dependencies.content.resolveLinkTargets === undefined)
|
|
504
|
+
throw new DomainError("CONTENT_INVALID_STATE", "Internal link validation is unavailable.");
|
|
505
|
+
const statuses = await this.dependencies.content.resolveLinkTargets([
|
|
506
|
+
...new Set(internalLinks.map((reference) => reference.targetId)),
|
|
507
|
+
]);
|
|
508
|
+
const issues = internalLinks.flatMap((reference) => {
|
|
509
|
+
const status = statuses[reference.targetId];
|
|
510
|
+
const self = publishingEntryId === reference.targetId && model.kind !== "global";
|
|
511
|
+
const nonRoutable = status?.state === "non-routable";
|
|
512
|
+
if (!nonRoutable &&
|
|
513
|
+
(mode === "draft" || !reference.delivered || self || status?.state === "published"))
|
|
514
|
+
return [];
|
|
515
|
+
return [
|
|
516
|
+
{
|
|
517
|
+
code: nonRoutable ? "internal_link_non_routable" : "internal_link_unavailable",
|
|
518
|
+
message: nonRoutable
|
|
519
|
+
? "must target a page or collection entry."
|
|
520
|
+
: "must target an entry with a published route.",
|
|
521
|
+
path: internalLinkIssuePath(reference, normalized.blocks.map((block) => block.key)),
|
|
522
|
+
},
|
|
523
|
+
];
|
|
524
|
+
});
|
|
525
|
+
if (issues.length > 0)
|
|
526
|
+
throw new ContentValidationError(issues);
|
|
527
|
+
}
|
|
528
|
+
return { ...normalized, mediaReferences: Object.freeze(mediaReferences), internalLinks };
|
|
529
|
+
}
|
|
530
|
+
internalLinks(model, fields, blocks) {
|
|
531
|
+
return collectSnapshotInternalLinks(model.fields, fields, blocks.map((block) => {
|
|
532
|
+
const definition = this.dependencies.config.blocks.get(block.type);
|
|
533
|
+
return {
|
|
534
|
+
...block,
|
|
535
|
+
fields: definition.fields,
|
|
536
|
+
...(definition.visibility === undefined
|
|
537
|
+
? {}
|
|
538
|
+
: { visibility: definition.visibility }),
|
|
539
|
+
};
|
|
540
|
+
}), model.visibility);
|
|
541
|
+
}
|
|
542
|
+
/** Whether a model or block type declares conditional-field rules anywhere. */
|
|
543
|
+
declaresVisibility(owner, fields, rules) {
|
|
544
|
+
let declared = this.visibilityOwners.get(owner);
|
|
545
|
+
if (declared === undefined) {
|
|
546
|
+
declared = declaresFieldVisibility(fields, rules);
|
|
547
|
+
this.visibilityOwners.set(owner, declared);
|
|
548
|
+
}
|
|
549
|
+
return declared;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* The published projection of a validated draft and its references, or
|
|
553
|
+
* `undefined` when neither its model nor its blocks declare rules, so the
|
|
554
|
+
* repository copies the draft as before.
|
|
555
|
+
*/
|
|
556
|
+
publishedProjection(model, draft) {
|
|
557
|
+
const registry = this.dependencies.config.blocks;
|
|
558
|
+
if (!this.declaresVisibility(`model:${model.key}`, model.fields, model.visibility) &&
|
|
559
|
+
!draft.blocks.some((block) => {
|
|
560
|
+
const definition = registry.get(block.type);
|
|
561
|
+
return this.declaresVisibility(`block:${block.type}`, definition.fields, definition.visibility);
|
|
562
|
+
}))
|
|
563
|
+
return undefined;
|
|
564
|
+
const fields = publishedFieldValues(model.fields, draft.fields, model.visibility);
|
|
565
|
+
const blocks = draft.blocks.map((block) => ({
|
|
566
|
+
...block,
|
|
567
|
+
data: publishedBlockData(registry.get(block.type), block.data),
|
|
568
|
+
}));
|
|
569
|
+
const mediaReferences = this.collectMedia(fields, model.fields, "$fields");
|
|
570
|
+
if (draft.seo?.image !== undefined)
|
|
571
|
+
mediaReferences.push({
|
|
572
|
+
fieldPath: "image",
|
|
573
|
+
mediaId: mediaId(draft.seo.image),
|
|
574
|
+
sourceKey: "$seo",
|
|
575
|
+
});
|
|
576
|
+
for (const block of blocks)
|
|
577
|
+
mediaReferences.push(...this.collectMedia(block.data, registry.get(block.type).fields, block.key));
|
|
578
|
+
return detached({
|
|
579
|
+
blocks: blocks.map(({ data, key }) => ({ data, key })),
|
|
580
|
+
fields,
|
|
581
|
+
internalLinks: this.internalLinks(model, fields, blocks),
|
|
582
|
+
mediaReferences,
|
|
583
|
+
});
|
|
396
584
|
}
|
|
397
585
|
collectMedia(values, definitions, sourceKey) {
|
|
398
586
|
return collectFieldMedia(definitions, values).map(({ mediaId: id, path }) => ({
|