@camox/api-contract 0.63.0 → 0.66.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/src/drafts.ts CHANGED
@@ -25,6 +25,46 @@ export const PUBLISHING_DRAFT_HEADER = "x-camox-publishing-draft";
25
25
  */
26
26
  export const PUBLISHING_DRAFT_VAR = "CAMOX_PUBLISHING_DRAFT";
27
27
 
28
+ /**
29
+ * Request header carrying a look token (ADR 0032): a short-lived, read-only credential the API
30
+ * signs for the agent's `look` tool, naming one project and one draft. A request carrying a valid
31
+ * one reads that draft's content, named with `DRAFT_HEADER`, as a member would, without a session.
32
+ * It writes nothing, reads no other draft, and reads none of Live's private data.
33
+ */
34
+ export const LOOK_TOKEN_HEADER = "x-camox-look-token";
35
+
36
+ /**
37
+ * The cookie the browser `look` drives carries the look token in, set for the website's host
38
+ * only, so third-party requests never see it. The website forwards it as `LOOK_TOKEN_HEADER`.
39
+ */
40
+ export const LOOK_TOKEN_COOKIE = "camox_look";
41
+
42
+ /**
43
+ * The website's lightweight document the browser `look` drives loads (the SDK runtime's
44
+ * `RUNTIME_ROUTE_PATHS.look`): one page of the draft `DRAFT_SEARCH_PARAM` names, at the path
45
+ * `LOOK_PATH_PARAM` gives in the locale `LOOK_LOCALE_PARAM` names, its Default Locale without.
46
+ */
47
+ export const LOOK_DOCUMENT_PATH = "/_camox/look";
48
+ export const LOOK_PATH_PARAM = "path";
49
+ export const LOOK_LOCALE_PARAM = "locale";
50
+
51
+ /**
52
+ * The look document's Block Definition mode: instead of a page, the block of the Block Definition
53
+ * `LOOK_BLOCK_DEFINITION_PARAM` names, alone in the site's shell, with its default content and
54
+ * Block Settings and the overrides `LOOK_CONTENT_PARAM` and `LOOK_SETTINGS_PARAM` give as JSON, in
55
+ * the shape the content tools take.
56
+ */
57
+ export const LOOK_BLOCK_DEFINITION_PARAM = "blockDefinition";
58
+ export const LOOK_CONTENT_PARAM = "content";
59
+ export const LOOK_SETTINGS_PARAM = "settings";
60
+
61
+ /**
62
+ * The id of a block shown without being placed, as the look document's Block Definition mode
63
+ * shows it: never a stored block's, which are UUIDs. Its element is
64
+ * `[data-camox-viewport-block="unplaced"]`.
65
+ */
66
+ export const UNPLACED_BLOCK_ID = "unplaced";
67
+
28
68
  /**
29
69
  * Request header asking the API to create the draft named by `DRAFT_HEADER` if it doesn't
30
70
  * exist yet. Its value is `"1"`.
@@ -87,19 +127,34 @@ export const PUBLISH_BLOCKED_ERROR = "PUBLISH_BLOCKED";
87
127
 
88
128
  /**
89
129
  * oRPC error code for a publish refused because the draft still has pending translations: every
90
- * locale goes live together, unless the caller publishes anyway (ADR 0017).
130
+ * locale goes live together, and there is no publishing anyway (ADR 0033).
91
131
  */
92
132
  export const TRANSLATIONS_PENDING_ERROR = "TRANSLATIONS_PENDING";
93
133
 
134
+ /**
135
+ * oRPC error code for a publish refused because the draft has open findings, each to fix or for a
136
+ * member to dismiss: there is no publishing past them (ADR 0033).
137
+ */
138
+ export const FINDINGS_OPEN_ERROR = "FINDINGS_OPEN";
139
+
140
+ /**
141
+ * oRPC error code for a publish refused because a patroller's check at publish hasn't read the
142
+ * draft's latest changes yet: publishing waits for it (ADR 0033).
143
+ */
144
+ export const CHECKS_RUNNING_ERROR = "CHECKS_RUNNING";
145
+
94
146
  /**
95
147
  * Why the publish tool published nothing of a draft with changes, and returned a fresh preview to
96
148
  * review again, by the error code of each: Live changed since the preview, the draft has blockers,
97
- * translations are still running, or the draft's code changed since the preview.
149
+ * translations are still running, the draft has open findings, a check at publish is still
150
+ * running, or the draft's code changed since the preview.
98
151
  */
99
152
  export const NOT_PUBLISHED_CODES = {
100
153
  conflictsChanged: CONFLICTS_CHANGED_ERROR,
101
154
  blocked: PUBLISH_BLOCKED_ERROR,
102
155
  translating: TRANSLATIONS_PENDING_ERROR,
156
+ findings: FINDINGS_OPEN_ERROR,
157
+ checking: CHECKS_RUNNING_ERROR,
103
158
  revisionChanged: REVISION_CHANGED_ERROR,
104
159
  } as const;
105
160
 
@@ -133,6 +188,7 @@ const BLOCK_WRITES: Record<keyof Router["blocks"], boolean> = {
133
188
  getUsageCounts: false,
134
189
  getPagesUsing: false,
135
190
  getSyncedContent: false,
191
+ getUnplaced: false,
136
192
  create: true,
137
193
  updateContent: true,
138
194
  updateSettings: true,
@@ -208,6 +264,14 @@ const LOCALE_WRITES: Record<keyof Router["locales"], boolean> = {
208
264
  addBack: true,
209
265
  };
210
266
 
267
+ // Applying a finding's fix edits content as the member would; dismissing one is the project's,
268
+ // never content (ADR 0034).
269
+ const PATROL_WRITES: Record<keyof Router["patrol"], boolean> = {
270
+ get: false,
271
+ applyFix: true,
272
+ dismissFinding: false,
273
+ };
274
+
211
275
  // `definitions` is absent: its sync is a release, never a studio content write.
212
276
  const CONTENT_WRITES: Partial<Record<keyof Router, Record<string, boolean>>> = {
213
277
  blocks: BLOCK_WRITES,
@@ -215,6 +279,7 @@ const CONTENT_WRITES: Partial<Record<keyof Router, Record<string, boolean>>> = {
215
279
  collectionDefinitions: COLLECTION_WRITES,
216
280
  files: FILE_WRITES,
217
281
  pages: PAGE_WRITES,
282
+ patrol: PATROL_WRITES,
218
283
  repeatableItems: ITEM_WRITES,
219
284
  };
220
285
 
@@ -0,0 +1,51 @@
1
+ /** How a layout's pages come about: authored by editors, derived from data, or one fixed page. */
2
+ export type LayoutKind = "curated" | "derived" | "singleton";
3
+
4
+ /** A layout as route matching reads it: its id, which is its file route, and its kind. */
5
+ export type LayoutRoute = { id: string; kind: LayoutKind };
6
+
7
+ /** The segments of a layout's file route, such as `blog.$slug`: `$` segments are params. */
8
+ export function routeSegments(id: string) {
9
+ return id.split(".");
10
+ }
11
+
12
+ /**
13
+ * The singleton or derived layout whose route matches `pathname`, a path in its Locale, with its
14
+ * params, or null. The route with the fewest params wins, so a singleton's fixed route wins over
15
+ * a derived route that would match it too. The SDK renders pages and the API checks them with it.
16
+ */
17
+ export function matchLayoutRoute<L>(
18
+ layouts: readonly L[],
19
+ pathname: string,
20
+ routeOf: (layout: L) => LayoutRoute,
21
+ ): { layout: L; params: Record<string, string> } | null {
22
+ const path = pathname.replace(/^\/|\/$/g, "").split("/");
23
+ const paramCount = (layout: L) =>
24
+ routeSegments(routeOf(layout).id).filter((s) => s.startsWith("$")).length;
25
+ const candidates = layouts
26
+ .filter((layout) => routeOf(layout).kind !== "curated")
27
+ .sort((a, b) => paramCount(a) - paramCount(b));
28
+ for (const layout of candidates) {
29
+ const segments = routeSegments(routeOf(layout).id);
30
+ if (segments.length !== path.length) continue;
31
+ const params: Record<string, string> = {};
32
+ let matches = true;
33
+ for (const [index, segment] of segments.entries()) {
34
+ let value: string;
35
+ try {
36
+ value = decodeURIComponent(path[index]!);
37
+ } catch {
38
+ matches = false;
39
+ break;
40
+ }
41
+ if (segment.startsWith("$") && value && !value.includes("/"))
42
+ params[segment.slice(1)] = value;
43
+ else if (segment !== value) {
44
+ matches = false;
45
+ break;
46
+ }
47
+ }
48
+ if (matches) return { layout, params };
49
+ }
50
+ return null;
51
+ }
package/src/patrol.ts CHANGED
@@ -4,8 +4,11 @@
4
4
  * Live, and names each report's subject, so the studio needs no entity loaded to show it.
5
5
  */
6
6
 
7
- /** A patroller's stable id. The registry in the API lists them all. */
8
- export type PatrollerId = "translator" | "seoManager";
7
+ /** Every patroller's stable id. The registry in the API lists them all. */
8
+ export const PATROLLER_IDS = ["translator", "seoManager", "linkChecker", "proofreader"] as const;
9
+
10
+ /** A patroller's stable id. */
11
+ export type PatrollerId = (typeof PATROLLER_IDS)[number];
9
12
 
10
13
  /**
11
14
  * What a structured report says was done. Each has a failed form, by the report's outcome. A
@@ -16,7 +19,10 @@ export type ReportVerb =
16
19
  | "mergedWithLive"
17
20
  | "wroteSeo"
18
21
  | "describedFile"
19
- | "publishedCatchUp";
22
+ | "publishedCatchUp"
23
+ | "removedLink"
24
+ | "fixedLink"
25
+ | "fixedMistake";
20
26
 
21
27
  /** What a report can be about. */
22
28
  export type ReportEntity =
@@ -51,8 +57,11 @@ export const reportLocale = (
51
57
  /** Whether the work was done, or failed. A failure shows in its report only. */
52
58
  export type ReportOutcome = "done" | "failed";
53
59
 
54
- /** Whether a report needs a human. Nothing raises one yet. */
55
- export type AttentionLevel = "none" | "needed";
60
+ /**
61
+ * Where a patroller is on duty, in drafts or on Live: it works as you go, checks when you
62
+ * publish, or is off there (ADR 0034).
63
+ */
64
+ export type PatrollerDuty = "asYouGo" | "atPublish" | "off";
56
65
 
57
66
  /**
58
67
  * Where the studio shows a report's subject: a page on the Canvas, with the block and repeatable
@@ -68,7 +77,6 @@ export type ReportView = {
68
77
  id: string;
69
78
  summary: ReportSummary;
70
79
  outcome: ReportOutcome;
71
- attention: AttentionLevel;
72
80
  /** When the work last settled, in milliseconds since the epoch. */
73
81
  at: number;
74
82
  /** Whether the report is Live's, seen from a draft or from Live. */
@@ -80,6 +88,98 @@ export type ReportView = {
80
88
  place: ReportPlace | null;
81
89
  };
82
90
 
91
+ /**
92
+ * What a finding is about (ADR 0034), by its kind:
93
+ * - `missingPage`: a link to a page that doesn't exist, the page's name as it was last known.
94
+ * - `brokenLink`: an external link that failed, and how.
95
+ * - `misspelling`, `grammar`: the flagged text, in the sentence it's in.
96
+ * A link's `url` is as content stores it: a page link's is `camox:page:<id>`, and `text` is what
97
+ * the link reads.
98
+ */
99
+ export type FindingAbout =
100
+ | { kind: "missingPage"; url: string; text: string; page: string | null }
101
+ | { kind: "brokenLink"; url: string; text: string; failure: LinkFailure }
102
+ | { kind: "misspelling" | "grammar"; text: string; sentence: string };
103
+
104
+ /** How a link failed: an HTTP error status, no connection (DNS included), or no answer in time. */
105
+ export type LinkFailure =
106
+ | { kind: "status"; status: number }
107
+ | { kind: "unreachable" }
108
+ | { kind: "timeout" };
109
+
110
+ export type FindingKind = FindingAbout["kind"];
111
+
112
+ /**
113
+ * The fix a finding suggests, which applying makes: removing the link, keeping its text, or
114
+ * replacing the flagged text with `replacement` in its sentence, keeping its formatting.
115
+ */
116
+ export type FindingFix = { kind: "removeLink" } | { kind: "replaceText"; replacement: string };
117
+
118
+ /** A finding, open, in the scope viewed. */
119
+ export type FindingView = {
120
+ /** What applying or dismissing it names. */
121
+ id: number;
122
+ about: FindingAbout;
123
+ /** The fix it suggests, if any. */
124
+ fix: FindingFix | null;
125
+ /** The content it's in, named in its locale. */
126
+ subject: ReportSubject;
127
+ /** The locale of the content it's in, by its tag. */
128
+ locale: string;
129
+ /** The content field it's in, by name. */
130
+ field: string;
131
+ /** When it was first raised, in milliseconds since the epoch. */
132
+ raisedAt: number;
133
+ /** Whether it's Live's. Live's are fixed in the Patrol Draft. */
134
+ live: boolean;
135
+ /** Where its content shows, as for reports. */
136
+ place: ReportPlace | null;
137
+ };
138
+
139
+ /** What a finding is about, after where it is: "links to About, a page that no longer exists". */
140
+ function aboutSentence(about: FindingAbout): string {
141
+ switch (about.kind) {
142
+ case "missingPage":
143
+ return about.page === null
144
+ ? "links to a page that no longer exists"
145
+ : `links to ${about.page}, a page that no longer exists`;
146
+ case "brokenLink": {
147
+ const { failure } = about;
148
+ const how =
149
+ failure.kind === "status"
150
+ ? `answers with an error (${failure.status})`
151
+ : failure.kind === "timeout"
152
+ ? "doesn't answer in time"
153
+ : "can't be reached";
154
+ return `links to ${about.url}, which ${how}`;
155
+ }
156
+ case "misspelling":
157
+ return "may be misspelled";
158
+ case "grammar":
159
+ return "may be a grammar mistake";
160
+ }
161
+ }
162
+
163
+ /**
164
+ * A finding as one sentence, as the studio, emails, Briefs and refusals word it: "“About us” in
165
+ * Footer links to About, a page that no longer exists".
166
+ */
167
+ export function findingSentence(finding: Pick<FindingView, "about" | "subject">): string {
168
+ return `“${finding.about.text}” in ${finding.subject.name} ${aboutSentence(finding.about)}`;
169
+ }
170
+
171
+ /** A member's dismissal of what a finding was about: no finding like it is raised again. */
172
+ export type DismissalView = {
173
+ id: number;
174
+ about: FindingAbout;
175
+ by: { id: string; name: string };
176
+ /** When it was dismissed, in milliseconds since the epoch. */
177
+ at: number;
178
+ };
179
+
180
+ /** What applying a finding's fix did: applied it, or found its content changed and rechecked. */
181
+ export type ApplyResult = { applied: boolean };
182
+
83
183
  /** How many subjects a patroller is on in one locale, a locale's tag. */
84
184
  export type LocaleCount = { locale: string; count: number };
85
185
 
@@ -96,18 +196,38 @@ export type PatrollerView = {
96
196
  id: PatrollerId;
97
197
  /** Its role, as editors know it: "Translator", "SEO manager". */
98
198
  role: string;
199
+ /** Its duty in the scope viewed. Off there, it still has its reports. */
200
+ duty: PatrollerDuty;
99
201
  /** Null when it isn't working in the scope. */
100
202
  working: PatrollerWorking | null;
101
- /** Its latest activity in the scope, or null when it never worked there. */
203
+ /**
204
+ * When it last finished a check in the scope, whether it found anything or not, or null when it
205
+ * never checked there.
206
+ */
207
+ lastCheckedAt: number | null;
208
+ /**
209
+ * Its latest activity in the scope: its last check, its newest report or when its pending work
210
+ * started, whichever is later. Null when it never worked there.
211
+ */
102
212
  lastActivityAt: number | null;
103
213
  /** Its newest reports, newest first. */
104
214
  reports: ReportView[];
105
215
  /** How many more reports it has than `reports` shows, per locale, the most first. */
106
216
  more: { locale: string | null; count: number }[];
217
+ /** Its open findings in the scope viewed, the oldest first. Their count is the row's badge. */
218
+ findings: FindingView[];
219
+ /** The project's dismissals of its findings, the newest first. */
220
+ dismissals: DismissalView[];
107
221
  };
108
222
 
109
- /** Every patroller of the registry, the latest activity first; never-worked ones last. */
110
- export type PatrolView = { patrollers: PatrollerView[] };
223
+ /**
224
+ * Every patroller of the registry, the latest activity first; never-worked ones last. With the
225
+ * project's open Patrol Draft, where Live's findings are fixed, if any.
226
+ */
227
+ export type PatrolView = {
228
+ patrollers: PatrollerView[];
229
+ patrolDraft: { id: string; name: string | null } | null;
230
+ };
111
231
 
112
232
  /** How many reports the Patrol shows of each patroller; the rest are counted. */
113
233
  export const REPORTS_SHOWN = 5;