@echovisionlab/geul-telemetry 0.1.2 → 0.1.3
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/README.md +7 -0
- package/package.json +1 -1
- package/src/audit/content-shared.ts +184 -0
- package/src/audit/content.ts +43 -691
- package/src/audit/page.ts +137 -0
- package/src/audit/post.ts +263 -0
- package/src/audit/work.ts +183 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AuditCollectionOperation,
|
|
3
|
+
AuditItemOperation,
|
|
4
|
+
AuditRecord,
|
|
5
|
+
AuditState,
|
|
6
|
+
} from "../records.ts";
|
|
7
|
+
import { canonicalAuditValues } from "./attributes.ts";
|
|
8
|
+
import {
|
|
9
|
+
isRelationDownloadPolicyAuditRecord,
|
|
10
|
+
validateRelationDownloadPolicyAuditRecord,
|
|
11
|
+
} from "./relation-download-policy.ts";
|
|
12
|
+
import {
|
|
13
|
+
buildContentAuditRecord,
|
|
14
|
+
buildRootAuditRecord,
|
|
15
|
+
buildVersionCreatedAuditRecord,
|
|
16
|
+
requireFeaturedImage,
|
|
17
|
+
requireFields,
|
|
18
|
+
requireOnly,
|
|
19
|
+
requireShareLink,
|
|
20
|
+
requireStateTransition,
|
|
21
|
+
requireVersion,
|
|
22
|
+
requireVersionRestore,
|
|
23
|
+
} from "./content-shared.ts";
|
|
24
|
+
import type { AuditMetadata } from "./types.ts";
|
|
25
|
+
|
|
26
|
+
type PageConfigurationField = "document_layout" | "show_title" | "slug";
|
|
27
|
+
|
|
28
|
+
const pageConfigurationFields = new Set<PageConfigurationField>([
|
|
29
|
+
"document_layout",
|
|
30
|
+
"show_title",
|
|
31
|
+
"slug",
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
export function requirePageUpdate(record: AuditRecord): void {
|
|
35
|
+
if (isRelationDownloadPolicyAuditRecord(record))
|
|
36
|
+
return validateRelationDownloadPolicyAuditRecord(record);
|
|
37
|
+
if (record.changed_fields?.length === 1) {
|
|
38
|
+
switch (record.changed_fields[0]) {
|
|
39
|
+
case "version":
|
|
40
|
+
return requireVersion(record);
|
|
41
|
+
case "featured_image":
|
|
42
|
+
return requireFeaturedImage(record, "asset_id");
|
|
43
|
+
case "share_links":
|
|
44
|
+
return requireShareLink(record);
|
|
45
|
+
case "version_restore":
|
|
46
|
+
return requireVersionRestore(record);
|
|
47
|
+
case "status":
|
|
48
|
+
requireStateTransition(record, ["draft", "published"]);
|
|
49
|
+
return requireOnly(record, [
|
|
50
|
+
"changed_fields",
|
|
51
|
+
"previous_state",
|
|
52
|
+
"new_state",
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
requireFields(record, pageConfigurationFields);
|
|
57
|
+
requireOnly(record, ["changed_fields"]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function buildPageVersionCreatedAuditRecord(
|
|
61
|
+
m: AuditMetadata,
|
|
62
|
+
id: string,
|
|
63
|
+
version: string,
|
|
64
|
+
contributors: readonly string[],
|
|
65
|
+
): AuditRecord {
|
|
66
|
+
return buildVersionCreatedAuditRecord(
|
|
67
|
+
m,
|
|
68
|
+
"page.updated",
|
|
69
|
+
id,
|
|
70
|
+
version,
|
|
71
|
+
contributors,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
export function buildPageConfigurationAuditRecord(
|
|
75
|
+
m: AuditMetadata,
|
|
76
|
+
id: string,
|
|
77
|
+
fields: readonly PageConfigurationField[],
|
|
78
|
+
): AuditRecord {
|
|
79
|
+
return buildContentAuditRecord(m, "page.updated", id, {
|
|
80
|
+
changed_fields: canonicalAuditValues(fields),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
export function buildPageLifecycleAuditRecord(
|
|
84
|
+
m: AuditMetadata,
|
|
85
|
+
id: string,
|
|
86
|
+
previous: Extract<AuditState, "draft" | "published">,
|
|
87
|
+
next: Extract<AuditState, "draft" | "published">,
|
|
88
|
+
): AuditRecord {
|
|
89
|
+
return buildContentAuditRecord(m, "page.updated", id, {
|
|
90
|
+
changed_fields: ["status"],
|
|
91
|
+
previous_state: previous,
|
|
92
|
+
new_state: next,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
export function buildPageFeaturedImageAuditRecord(
|
|
96
|
+
m: AuditMetadata,
|
|
97
|
+
id: string,
|
|
98
|
+
assetId: string,
|
|
99
|
+
operation: AuditCollectionOperation,
|
|
100
|
+
): AuditRecord {
|
|
101
|
+
return buildContentAuditRecord(m, "page.updated", id, {
|
|
102
|
+
changed_fields: ["featured_image"],
|
|
103
|
+
asset_id: assetId,
|
|
104
|
+
collection_operation: operation,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
export function buildPageShareLinkAuditRecord(
|
|
108
|
+
m: AuditMetadata,
|
|
109
|
+
id: string,
|
|
110
|
+
itemId: string,
|
|
111
|
+
operation: Extract<AuditItemOperation, "created" | "deleted">,
|
|
112
|
+
): AuditRecord {
|
|
113
|
+
return buildContentAuditRecord(m, "page.updated", id, {
|
|
114
|
+
changed_fields: ["share_links"],
|
|
115
|
+
item_id: itemId,
|
|
116
|
+
item_operation: operation,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
export function buildPageVersionRestoreAuditRecord(
|
|
120
|
+
m: AuditMetadata,
|
|
121
|
+
id: string,
|
|
122
|
+
versionId: string,
|
|
123
|
+
): AuditRecord {
|
|
124
|
+
return buildContentAuditRecord(m, "page.updated", id, {
|
|
125
|
+
changed_fields: ["version_restore"],
|
|
126
|
+
version_id: versionId,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const buildPageCreatedAuditRecord = (
|
|
131
|
+
m: AuditMetadata,
|
|
132
|
+
id: string,
|
|
133
|
+
): AuditRecord => buildRootAuditRecord(m, "page.created", id);
|
|
134
|
+
export const buildPageDeletedAuditRecord = (
|
|
135
|
+
m: AuditMetadata,
|
|
136
|
+
id: string,
|
|
137
|
+
): AuditRecord => buildRootAuditRecord(m, "page.deleted", id);
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AuditCollectionOperation,
|
|
3
|
+
AuditItemOperation,
|
|
4
|
+
AuditRecord,
|
|
5
|
+
AuditRelationship,
|
|
6
|
+
AuditState,
|
|
7
|
+
} from "../records.ts";
|
|
8
|
+
import { canonicalAuditValues } from "./attributes.ts";
|
|
9
|
+
import {
|
|
10
|
+
isRelationDownloadPolicyAuditRecord,
|
|
11
|
+
validateRelationDownloadPolicyAuditRecord,
|
|
12
|
+
} from "./relation-download-policy.ts";
|
|
13
|
+
import {
|
|
14
|
+
buildContentAuditRecord,
|
|
15
|
+
buildRootAuditRecord,
|
|
16
|
+
buildVersionCreatedAuditRecord,
|
|
17
|
+
requireFeaturedImage,
|
|
18
|
+
requireFields,
|
|
19
|
+
requireIdentifier,
|
|
20
|
+
requireOnly,
|
|
21
|
+
requireShareLink,
|
|
22
|
+
requireStateTransition,
|
|
23
|
+
requireVersion,
|
|
24
|
+
requireVersionRestore,
|
|
25
|
+
} from "./content-shared.ts";
|
|
26
|
+
import type { AuditMetadata } from "./types.ts";
|
|
27
|
+
|
|
28
|
+
type PostConfigurationField =
|
|
29
|
+
"comments_enabled" | "document_layout" | "map_place_id" | "slug";
|
|
30
|
+
|
|
31
|
+
const postConfigurationFields = new Set<PostConfigurationField>([
|
|
32
|
+
"comments_enabled",
|
|
33
|
+
"document_layout",
|
|
34
|
+
"map_place_id",
|
|
35
|
+
"slug",
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
function postParticipantFields(
|
|
39
|
+
previous: AuditRelationship,
|
|
40
|
+
next: AuditRelationship,
|
|
41
|
+
): readonly ("authors" | "collaborators")[] {
|
|
42
|
+
const valid = new Set<AuditRelationship>(["none", "author", "collaborator"]);
|
|
43
|
+
if (!valid.has(previous) || !valid.has(next) || previous === next) {
|
|
44
|
+
throw new TypeError(
|
|
45
|
+
"post participant requires a distinct author/collaborator transition",
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
if (previous === "author" || next === "author") {
|
|
49
|
+
if (previous === "collaborator" || next === "collaborator") {
|
|
50
|
+
return ["authors", "collaborators"];
|
|
51
|
+
}
|
|
52
|
+
return ["authors"];
|
|
53
|
+
}
|
|
54
|
+
return ["collaborators"];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function requirePostParticipant(record: AuditRecord): void {
|
|
58
|
+
const previous = record.previous_relationship;
|
|
59
|
+
const next = record.new_relationship;
|
|
60
|
+
if (previous === undefined || next === undefined) {
|
|
61
|
+
throw new TypeError("post participant requires relationships");
|
|
62
|
+
}
|
|
63
|
+
const fields = postParticipantFields(previous, next);
|
|
64
|
+
if (
|
|
65
|
+
record.changed_fields?.length !== fields.length ||
|
|
66
|
+
record.changed_fields.some((field, i) => field !== fields[i])
|
|
67
|
+
) {
|
|
68
|
+
throw new TypeError(
|
|
69
|
+
"post participant changed_fields must match the relationship transition",
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
requireIdentifier("subject_member_id", record.subject_member_id);
|
|
73
|
+
requireOnly(record, [
|
|
74
|
+
"changed_fields",
|
|
75
|
+
"subject_member_id",
|
|
76
|
+
"previous_relationship",
|
|
77
|
+
"new_relationship",
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function requirePostUpdate(record: AuditRecord): void {
|
|
82
|
+
if (isRelationDownloadPolicyAuditRecord(record))
|
|
83
|
+
return validateRelationDownloadPolicyAuditRecord(record);
|
|
84
|
+
if (record.changed_fields?.length === 1) {
|
|
85
|
+
switch (record.changed_fields[0]) {
|
|
86
|
+
case "version":
|
|
87
|
+
return requireVersion(record);
|
|
88
|
+
case "featured_image":
|
|
89
|
+
return requireFeaturedImage(record, "asset_id");
|
|
90
|
+
case "share_links":
|
|
91
|
+
return requireShareLink(record);
|
|
92
|
+
case "version_restore":
|
|
93
|
+
return requireVersionRestore(record);
|
|
94
|
+
case "comments": {
|
|
95
|
+
if (record.actor_kind !== "member") {
|
|
96
|
+
throw new TypeError("post comment requires a member actor");
|
|
97
|
+
}
|
|
98
|
+
if (
|
|
99
|
+
!record.item_operation ||
|
|
100
|
+
!["created", "updated", "deleted"].includes(record.item_operation)
|
|
101
|
+
) {
|
|
102
|
+
throw new TypeError("post comment requires an item operation");
|
|
103
|
+
}
|
|
104
|
+
requireIdentifier("item_id", record.item_id);
|
|
105
|
+
requireOnly(record, ["changed_fields", "item_operation", "item_id"]);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (
|
|
111
|
+
record.changed_fields?.includes("authors") ||
|
|
112
|
+
record.changed_fields?.includes("collaborators")
|
|
113
|
+
) {
|
|
114
|
+
return requirePostParticipant(record);
|
|
115
|
+
}
|
|
116
|
+
const fields = requireFields(
|
|
117
|
+
record,
|
|
118
|
+
new Set([...postConfigurationFields, "schedule", "status"]),
|
|
119
|
+
);
|
|
120
|
+
const lifecycle = fields.includes("schedule") || fields.includes("status");
|
|
121
|
+
if (!lifecycle) return requireOnly(record, ["changed_fields"]);
|
|
122
|
+
requireStateTransition(record, [
|
|
123
|
+
"draft",
|
|
124
|
+
"scheduled",
|
|
125
|
+
"published",
|
|
126
|
+
"archived",
|
|
127
|
+
]);
|
|
128
|
+
if (fields.includes("schedule")) {
|
|
129
|
+
if (
|
|
130
|
+
!record.scheduled_at ||
|
|
131
|
+
Number.isNaN(Date.parse(record.scheduled_at)) ||
|
|
132
|
+
!record.scheduled_time_zone
|
|
133
|
+
) {
|
|
134
|
+
throw new TypeError(
|
|
135
|
+
"post schedule requires scheduled_at and scheduled_time_zone",
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
} else if (
|
|
139
|
+
record.scheduled_at !== undefined ||
|
|
140
|
+
record.scheduled_time_zone !== undefined
|
|
141
|
+
) {
|
|
142
|
+
throw new TypeError(
|
|
143
|
+
"post schedule attributes require changed_fields schedule",
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
requireOnly(record, [
|
|
147
|
+
"changed_fields",
|
|
148
|
+
"previous_state",
|
|
149
|
+
"new_state",
|
|
150
|
+
"scheduled_at",
|
|
151
|
+
"scheduled_time_zone",
|
|
152
|
+
]);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function buildPostVersionCreatedAuditRecord(
|
|
156
|
+
m: AuditMetadata,
|
|
157
|
+
id: string,
|
|
158
|
+
version: string,
|
|
159
|
+
contributors: readonly string[],
|
|
160
|
+
): AuditRecord {
|
|
161
|
+
return buildVersionCreatedAuditRecord(
|
|
162
|
+
m,
|
|
163
|
+
"post.updated",
|
|
164
|
+
id,
|
|
165
|
+
version,
|
|
166
|
+
contributors,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
export function buildPostConfigurationAuditRecord(
|
|
170
|
+
m: AuditMetadata,
|
|
171
|
+
id: string,
|
|
172
|
+
fields: readonly PostConfigurationField[],
|
|
173
|
+
): AuditRecord {
|
|
174
|
+
return buildContentAuditRecord(m, "post.updated", id, {
|
|
175
|
+
changed_fields: canonicalAuditValues(fields),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
export function buildPostLifecycleAuditRecord(
|
|
179
|
+
m: AuditMetadata,
|
|
180
|
+
id: string,
|
|
181
|
+
fields: readonly ("schedule" | "status")[],
|
|
182
|
+
previous: AuditState,
|
|
183
|
+
next: AuditState,
|
|
184
|
+
scheduledAt?: string,
|
|
185
|
+
scheduledTimeZone?: string,
|
|
186
|
+
): AuditRecord {
|
|
187
|
+
return buildContentAuditRecord(m, "post.updated", id, {
|
|
188
|
+
changed_fields: canonicalAuditValues(fields),
|
|
189
|
+
previous_state: previous,
|
|
190
|
+
new_state: next,
|
|
191
|
+
scheduled_at: scheduledAt,
|
|
192
|
+
scheduled_time_zone: scheduledTimeZone,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
export function buildPostFeaturedImageAuditRecord(
|
|
196
|
+
m: AuditMetadata,
|
|
197
|
+
id: string,
|
|
198
|
+
assetId: string,
|
|
199
|
+
operation: AuditCollectionOperation,
|
|
200
|
+
): AuditRecord {
|
|
201
|
+
return buildContentAuditRecord(m, "post.updated", id, {
|
|
202
|
+
changed_fields: ["featured_image"],
|
|
203
|
+
asset_id: assetId,
|
|
204
|
+
collection_operation: operation,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
export function buildPostParticipantAuditRecord(
|
|
208
|
+
m: AuditMetadata,
|
|
209
|
+
id: string,
|
|
210
|
+
memberId: string,
|
|
211
|
+
previous: AuditRelationship,
|
|
212
|
+
next: AuditRelationship,
|
|
213
|
+
): AuditRecord {
|
|
214
|
+
return buildContentAuditRecord(m, "post.updated", id, {
|
|
215
|
+
changed_fields: postParticipantFields(previous, next),
|
|
216
|
+
subject_member_id: memberId,
|
|
217
|
+
previous_relationship: previous,
|
|
218
|
+
new_relationship: next,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
export function buildPostShareLinkAuditRecord(
|
|
222
|
+
m: AuditMetadata,
|
|
223
|
+
id: string,
|
|
224
|
+
itemId: string,
|
|
225
|
+
operation: Extract<AuditItemOperation, "created" | "deleted">,
|
|
226
|
+
): AuditRecord {
|
|
227
|
+
return buildContentAuditRecord(m, "post.updated", id, {
|
|
228
|
+
changed_fields: ["share_links"],
|
|
229
|
+
item_id: itemId,
|
|
230
|
+
item_operation: operation,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
export function buildPostCommentAuditRecord(
|
|
234
|
+
m: AuditMetadata,
|
|
235
|
+
id: string,
|
|
236
|
+
itemId: string,
|
|
237
|
+
operation: AuditItemOperation,
|
|
238
|
+
): AuditRecord {
|
|
239
|
+
return buildContentAuditRecord(m, "post.updated", id, {
|
|
240
|
+
changed_fields: ["comments"],
|
|
241
|
+
item_id: itemId,
|
|
242
|
+
item_operation: operation,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
export function buildPostVersionRestoreAuditRecord(
|
|
246
|
+
m: AuditMetadata,
|
|
247
|
+
id: string,
|
|
248
|
+
versionId: string,
|
|
249
|
+
): AuditRecord {
|
|
250
|
+
return buildContentAuditRecord(m, "post.updated", id, {
|
|
251
|
+
changed_fields: ["version_restore"],
|
|
252
|
+
version_id: versionId,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export const buildPostCreatedAuditRecord = (
|
|
257
|
+
m: AuditMetadata,
|
|
258
|
+
id: string,
|
|
259
|
+
): AuditRecord => buildRootAuditRecord(m, "post.created", id);
|
|
260
|
+
export const buildPostDeletedAuditRecord = (
|
|
261
|
+
m: AuditMetadata,
|
|
262
|
+
id: string,
|
|
263
|
+
): AuditRecord => buildRootAuditRecord(m, "post.deleted", id);
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AuditCollectionOperation,
|
|
3
|
+
AuditItemOperation,
|
|
4
|
+
AuditRecord,
|
|
5
|
+
AuditState,
|
|
6
|
+
} from "../records.ts";
|
|
7
|
+
import { canonicalAuditValues } from "./attributes.ts";
|
|
8
|
+
import {
|
|
9
|
+
isRelationDownloadPolicyAuditRecord,
|
|
10
|
+
validateRelationDownloadPolicyAuditRecord,
|
|
11
|
+
} from "./relation-download-policy.ts";
|
|
12
|
+
import {
|
|
13
|
+
buildContentAuditRecord,
|
|
14
|
+
buildRootAuditRecord,
|
|
15
|
+
buildVersionCreatedAuditRecord,
|
|
16
|
+
requireFeaturedImage,
|
|
17
|
+
requireFields,
|
|
18
|
+
requireIdentifier,
|
|
19
|
+
requireOnly,
|
|
20
|
+
requireShareLink,
|
|
21
|
+
requireStateTransition,
|
|
22
|
+
requireVersion,
|
|
23
|
+
requireVersionRestore,
|
|
24
|
+
} from "./content-shared.ts";
|
|
25
|
+
import type { AuditMetadata } from "./types.ts";
|
|
26
|
+
|
|
27
|
+
type WorkMetadataField =
|
|
28
|
+
| "clients"
|
|
29
|
+
| "featured"
|
|
30
|
+
| "is_present"
|
|
31
|
+
| "map_place_id"
|
|
32
|
+
| "metadata"
|
|
33
|
+
| "month"
|
|
34
|
+
| "slug"
|
|
35
|
+
| "type"
|
|
36
|
+
| "until_month"
|
|
37
|
+
| "until_year"
|
|
38
|
+
| "year";
|
|
39
|
+
|
|
40
|
+
const workMetadataFields = new Set<WorkMetadataField>([
|
|
41
|
+
"clients",
|
|
42
|
+
"featured",
|
|
43
|
+
"is_present",
|
|
44
|
+
"map_place_id",
|
|
45
|
+
"metadata",
|
|
46
|
+
"month",
|
|
47
|
+
"slug",
|
|
48
|
+
"type",
|
|
49
|
+
"until_month",
|
|
50
|
+
"until_year",
|
|
51
|
+
"year",
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
export function requireWorkUpdate(record: AuditRecord): void {
|
|
55
|
+
if (isRelationDownloadPolicyAuditRecord(record))
|
|
56
|
+
return validateRelationDownloadPolicyAuditRecord(record);
|
|
57
|
+
if (record.changed_fields?.length === 1) {
|
|
58
|
+
switch (record.changed_fields[0]) {
|
|
59
|
+
case "version":
|
|
60
|
+
return requireVersion(record);
|
|
61
|
+
case "featured_image":
|
|
62
|
+
return requireFeaturedImage(record, "asset_id");
|
|
63
|
+
case "share_links":
|
|
64
|
+
return requireShareLink(record);
|
|
65
|
+
case "version_restore":
|
|
66
|
+
return requireVersionRestore(record);
|
|
67
|
+
case "status":
|
|
68
|
+
requireStateTransition(record, ["draft", "published", "archived"]);
|
|
69
|
+
return requireOnly(record, [
|
|
70
|
+
"changed_fields",
|
|
71
|
+
"previous_state",
|
|
72
|
+
"new_state",
|
|
73
|
+
]);
|
|
74
|
+
case "credits":
|
|
75
|
+
if (
|
|
76
|
+
!record.item_operation ||
|
|
77
|
+
!["created", "updated", "deleted"].includes(record.item_operation)
|
|
78
|
+
) {
|
|
79
|
+
throw new TypeError("work credit requires an item operation");
|
|
80
|
+
}
|
|
81
|
+
requireIdentifier("item_id", record.item_id);
|
|
82
|
+
return requireOnly(record, [
|
|
83
|
+
"changed_fields",
|
|
84
|
+
"item_operation",
|
|
85
|
+
"item_id",
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
requireFields(record, workMetadataFields);
|
|
90
|
+
requireOnly(record, ["changed_fields"]);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function buildWorkVersionCreatedAuditRecord(
|
|
94
|
+
m: AuditMetadata,
|
|
95
|
+
id: string,
|
|
96
|
+
version: string,
|
|
97
|
+
contributors: readonly string[],
|
|
98
|
+
): AuditRecord {
|
|
99
|
+
return buildVersionCreatedAuditRecord(
|
|
100
|
+
m,
|
|
101
|
+
"work.updated",
|
|
102
|
+
id,
|
|
103
|
+
version,
|
|
104
|
+
contributors,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function buildWorkMetadataAuditRecord(
|
|
109
|
+
m: AuditMetadata,
|
|
110
|
+
id: string,
|
|
111
|
+
fields: readonly WorkMetadataField[],
|
|
112
|
+
): AuditRecord {
|
|
113
|
+
return buildContentAuditRecord(m, "work.updated", id, {
|
|
114
|
+
changed_fields: canonicalAuditValues(fields),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
export function buildWorkLifecycleAuditRecord(
|
|
118
|
+
m: AuditMetadata,
|
|
119
|
+
id: string,
|
|
120
|
+
previous: Extract<AuditState, "draft" | "published" | "archived">,
|
|
121
|
+
next: Extract<AuditState, "draft" | "published" | "archived">,
|
|
122
|
+
): AuditRecord {
|
|
123
|
+
return buildContentAuditRecord(m, "work.updated", id, {
|
|
124
|
+
changed_fields: ["status"],
|
|
125
|
+
previous_state: previous,
|
|
126
|
+
new_state: next,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
export function buildWorkFeaturedImageAuditRecord(
|
|
130
|
+
m: AuditMetadata,
|
|
131
|
+
id: string,
|
|
132
|
+
assetId: string,
|
|
133
|
+
operation: AuditCollectionOperation,
|
|
134
|
+
): AuditRecord {
|
|
135
|
+
return buildContentAuditRecord(m, "work.updated", id, {
|
|
136
|
+
changed_fields: ["featured_image"],
|
|
137
|
+
asset_id: assetId,
|
|
138
|
+
collection_operation: operation,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
export function buildWorkCreditAuditRecord(
|
|
142
|
+
m: AuditMetadata,
|
|
143
|
+
id: string,
|
|
144
|
+
itemId: string,
|
|
145
|
+
operation: AuditItemOperation,
|
|
146
|
+
): AuditRecord {
|
|
147
|
+
return buildContentAuditRecord(m, "work.updated", id, {
|
|
148
|
+
changed_fields: ["credits"],
|
|
149
|
+
item_id: itemId,
|
|
150
|
+
item_operation: operation,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
export function buildWorkShareLinkAuditRecord(
|
|
154
|
+
m: AuditMetadata,
|
|
155
|
+
id: string,
|
|
156
|
+
itemId: string,
|
|
157
|
+
operation: Extract<AuditItemOperation, "created" | "deleted">,
|
|
158
|
+
): AuditRecord {
|
|
159
|
+
return buildContentAuditRecord(m, "work.updated", id, {
|
|
160
|
+
changed_fields: ["share_links"],
|
|
161
|
+
item_id: itemId,
|
|
162
|
+
item_operation: operation,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
export function buildWorkVersionRestoreAuditRecord(
|
|
166
|
+
m: AuditMetadata,
|
|
167
|
+
id: string,
|
|
168
|
+
versionId: string,
|
|
169
|
+
): AuditRecord {
|
|
170
|
+
return buildContentAuditRecord(m, "work.updated", id, {
|
|
171
|
+
changed_fields: ["version_restore"],
|
|
172
|
+
version_id: versionId,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export const buildWorkCreatedAuditRecord = (
|
|
177
|
+
m: AuditMetadata,
|
|
178
|
+
id: string,
|
|
179
|
+
): AuditRecord => buildRootAuditRecord(m, "work.created", id);
|
|
180
|
+
export const buildWorkDeletedAuditRecord = (
|
|
181
|
+
m: AuditMetadata,
|
|
182
|
+
id: string,
|
|
183
|
+
): AuditRecord => buildRootAuditRecord(m, "work.deleted", id);
|