@brandlab-digital/site-core 3.12.1 → 3.14.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/README.md +80 -0
- package/dist/business.d.ts +81 -0
- package/dist/business.d.ts.map +1 -1
- package/dist/business.js +116 -0
- package/dist/business.js.map +1 -1
- package/dist/council-register.d.ts +53 -0
- package/dist/council-register.d.ts.map +1 -0
- package/dist/council-register.js +113 -0
- package/dist/council-register.js.map +1 -0
- package/dist/google-business-reviews-refresh.d.ts +93 -0
- package/dist/google-business-reviews-refresh.d.ts.map +1 -0
- package/dist/google-business-reviews-refresh.js +140 -0
- package/dist/google-business-reviews-refresh.js.map +1 -0
- package/dist/google-business-reviews.d.ts +1 -0
- package/dist/google-business-reviews.d.ts.map +1 -1
- package/dist/google-business-reviews.js +1 -0
- package/dist/google-business-reviews.js.map +1 -1
- package/dist/jobs.d.ts +71 -0
- package/dist/jobs.d.ts.map +1 -0
- package/dist/jobs.js +107 -0
- package/dist/jobs.js.map +1 -0
- package/dist/locations.d.ts +10 -0
- package/dist/locations.d.ts.map +1 -1
- package/dist/locations.js +15 -0
- package/dist/locations.js.map +1 -1
- package/dist/navigation.d.ts +37 -1
- package/dist/navigation.d.ts.map +1 -1
- package/dist/navigation.js +107 -2
- package/dist/navigation.js.map +1 -1
- package/dist/page-titles.d.ts +71 -0
- package/dist/page-titles.d.ts.map +1 -0
- package/dist/page-titles.js +161 -0
- package/dist/page-titles.js.map +1 -0
- package/dist/project.d.ts +76 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +177 -1
- package/dist/project.js.map +1 -1
- package/dist/section-order.d.ts +47 -2
- package/dist/section-order.d.ts.map +1 -1
- package/dist/section-order.js +96 -3
- package/dist/section-order.js.map +1 -1
- package/dist/site.d.ts +9 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +19 -0
- package/dist/site.js.map +1 -1
- package/dist/strategy.d.ts +172 -0
- package/dist/strategy.d.ts.map +1 -1
- package/dist/strategy.js +300 -2
- package/dist/strategy.js.map +1 -1
- package/package.json +13 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Titles and H1s for new pages (Site System v2 §5.2; correction #27). Earning pages keep their recorded titles
|
|
3
|
+
* (`docs/recorded-titles.json`, check E1); every other page takes its family's pattern:
|
|
4
|
+
*
|
|
5
|
+
* | Family | Title | H1 |
|
|
6
|
+
* |---|---|---|
|
|
7
|
+
* | Home | `{Home phrase} \| {Brand}` | `{Home phrase}` |
|
|
8
|
+
* | Service | `{Service phrase} \| {Brand}` | `{Service phrase}` |
|
|
9
|
+
* | Region, suburb | `{Main service} {Place} \| {Brand}` | `{Main service} {Place}` |
|
|
10
|
+
* | Service-region hub, service in suburb | `{Service} {Place} \| {Brand}` | `{Service} {Place}` |
|
|
11
|
+
* | Cost guide | `{Service} Cost {Area} {Year} \| {Brand}` | `{Service} cost {area} ({year})` |
|
|
12
|
+
* | Project | `{Service} {Suburb}: {Job} \| {Brand}` | `{Job}, {Suburb}` |
|
|
13
|
+
*
|
|
14
|
+
* H1s are the short exact phrase with no "in" and no "the". Titles are at most 60 characters: the short brand only
|
|
15
|
+
* when needed, never a cut keyword. A proof tail (`| From $450 |`, "Same-Week Quotes") comes only from data and only
|
|
16
|
+
* on the service page and head-tier pages. One pipe separates the brand; with a tail there are two.
|
|
17
|
+
*/
|
|
18
|
+
export declare const BRANDLAB_TITLE_MAX_LENGTH = 60;
|
|
19
|
+
export declare const BRANDLAB_TITLE_FAMILIES: readonly ["home", "service", "region", "suburb", "service-region", "service-in-suburb", "cost-guide", "project"];
|
|
20
|
+
export type BrandlabTitleFamily = (typeof BRANDLAB_TITLE_FAMILIES)[number];
|
|
21
|
+
export interface BrandlabPageTitleInput {
|
|
22
|
+
readonly family: BrandlabTitleFamily;
|
|
23
|
+
/** The full brand, for example "AA Tree Services Sydney". */
|
|
24
|
+
readonly brand: string;
|
|
25
|
+
/** The short brand used when the full one would push the title past 60 characters. */
|
|
26
|
+
readonly shortBrand?: string;
|
|
27
|
+
/** Home and service pages: the owned phrase, for example "tree removal sydney". */
|
|
28
|
+
readonly phrase?: string;
|
|
29
|
+
/** Location, cost-guide and project pages: the service (the main service on region and suburb pages). */
|
|
30
|
+
readonly service?: string;
|
|
31
|
+
/** The place's display name, for example "Ryde" or "Western Sydney". */
|
|
32
|
+
readonly place?: string;
|
|
33
|
+
/** Location pages: `head` pages may carry a proof tail; `standard` pages never do. */
|
|
34
|
+
readonly tier?: 'head' | 'standard';
|
|
35
|
+
/** "From $450" or "Same-Week Quotes": only when true and only on service and head-tier pages. */
|
|
36
|
+
readonly proofTail?: string;
|
|
37
|
+
/** Cost guides. */
|
|
38
|
+
readonly year?: number;
|
|
39
|
+
/** Projects: the job, for example "Gum tree removal over a pool". */
|
|
40
|
+
readonly job?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface BrandlabPageTitle {
|
|
43
|
+
/** The full `<title>` (pass it with `titleMode: 'absolute'`). */
|
|
44
|
+
readonly title: string;
|
|
45
|
+
readonly h1: string;
|
|
46
|
+
/** The title before its first pipe. */
|
|
47
|
+
readonly heading: string;
|
|
48
|
+
readonly length: number;
|
|
49
|
+
/** True only when the heading alone is over 60 characters: it is kept whole rather than cut. */
|
|
50
|
+
readonly overLength: boolean;
|
|
51
|
+
}
|
|
52
|
+
/** Title case: every word capitalised except short joining words after the first; words in capitals stay so. */
|
|
53
|
+
export declare function titleCase(phrase: string): string;
|
|
54
|
+
/** "{Service} {Place}": the service in title case and the place as named. The service has no "in" and no "the". */
|
|
55
|
+
export declare function locationHeading(service: string, place: string): string;
|
|
56
|
+
/** The title and H1 a new page of `family` takes. */
|
|
57
|
+
export declare function buildPageTitle(input: BrandlabPageTitleInput): BrandlabPageTitle;
|
|
58
|
+
/** What check E1-pattern compares on a location page. */
|
|
59
|
+
export interface BrandlabLocationHeadingSample {
|
|
60
|
+
readonly h1: string;
|
|
61
|
+
readonly title: string;
|
|
62
|
+
/** The place the page is for, as named. */
|
|
63
|
+
readonly place: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Why a location page's H1 and title break "{Service} {Place}", or null when they keep it: the H1 ends with the place
|
|
67
|
+
* and has a service before it, no "in" and no leading "the"; the title starts with the H1 (letter case aside), has at
|
|
68
|
+
* most two pipes and is at most 60 characters.
|
|
69
|
+
*/
|
|
70
|
+
export declare function locationHeadingProblem(sample: BrandlabLocationHeadingSample): string | null;
|
|
71
|
+
//# sourceMappingURL=page-titles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-titles.d.ts","sourceRoot":"","sources":["../src/page-titles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,eAAO,MAAM,yBAAyB,KAAK,CAAA;AAE3C,eAAO,MAAM,uBAAuB,kHAS1B,CAAA;AACV,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE1E,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAA;IACpC,6DAA6D;IAC7D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,sFAAsF;IACtF,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAC5B,mFAAmF;IACnF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,yGAAyG;IACzG,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,wEAAwE;IACxE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,sFAAsF;IACtF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;IACnC,iGAAiG;IACjG,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,mBAAmB;IACnB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,qEAAqE;IACrE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,iEAAiE;IACjE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,gGAAgG;IAChG,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;CAC7B;AAWD,gHAAgH;AAChH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAWhD;AAYD,mHAAmH;AACnH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKtE;AAcD,qDAAqD;AACrD,wBAAgB,cAAc,CAAC,KAAK,EAAE,sBAAsB,GAAG,iBAAiB,CA4C/E;AAED,yDAAyD;AACzD,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,6BAA6B,GAAG,MAAM,GAAG,IAAI,CAsB3F"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Titles and H1s for new pages (Site System v2 §5.2; correction #27). Earning pages keep their recorded titles
|
|
3
|
+
* (`docs/recorded-titles.json`, check E1); every other page takes its family's pattern:
|
|
4
|
+
*
|
|
5
|
+
* | Family | Title | H1 |
|
|
6
|
+
* |---|---|---|
|
|
7
|
+
* | Home | `{Home phrase} \| {Brand}` | `{Home phrase}` |
|
|
8
|
+
* | Service | `{Service phrase} \| {Brand}` | `{Service phrase}` |
|
|
9
|
+
* | Region, suburb | `{Main service} {Place} \| {Brand}` | `{Main service} {Place}` |
|
|
10
|
+
* | Service-region hub, service in suburb | `{Service} {Place} \| {Brand}` | `{Service} {Place}` |
|
|
11
|
+
* | Cost guide | `{Service} Cost {Area} {Year} \| {Brand}` | `{Service} cost {area} ({year})` |
|
|
12
|
+
* | Project | `{Service} {Suburb}: {Job} \| {Brand}` | `{Job}, {Suburb}` |
|
|
13
|
+
*
|
|
14
|
+
* H1s are the short exact phrase with no "in" and no "the". Titles are at most 60 characters: the short brand only
|
|
15
|
+
* when needed, never a cut keyword. A proof tail (`| From $450 |`, "Same-Week Quotes") comes only from data and only
|
|
16
|
+
* on the service page and head-tier pages. One pipe separates the brand; with a tail there are two.
|
|
17
|
+
*/
|
|
18
|
+
export const BRANDLAB_TITLE_MAX_LENGTH = 60;
|
|
19
|
+
export const BRANDLAB_TITLE_FAMILIES = [
|
|
20
|
+
'home',
|
|
21
|
+
'service',
|
|
22
|
+
'region',
|
|
23
|
+
'suburb',
|
|
24
|
+
'service-region',
|
|
25
|
+
'service-in-suburb',
|
|
26
|
+
'cost-guide',
|
|
27
|
+
'project',
|
|
28
|
+
];
|
|
29
|
+
const SMALL_WORDS = new Set(['a', 'an', 'and', 'as', 'at', 'but', 'by', 'for', 'of', 'on', 'or', 'to', 'with']);
|
|
30
|
+
const BANNED_WORDS = ['in', 'the'];
|
|
31
|
+
function clean(value, field) {
|
|
32
|
+
const text = typeof value === 'string' ? value.trim().replace(/\s+/g, ' ') : '';
|
|
33
|
+
if (!text)
|
|
34
|
+
throw new Error(`buildPageTitle needs a ${field} for this family.`);
|
|
35
|
+
return text;
|
|
36
|
+
}
|
|
37
|
+
/** Title case: every word capitalised except short joining words after the first; words in capitals stay so. */
|
|
38
|
+
export function titleCase(phrase) {
|
|
39
|
+
return phrase
|
|
40
|
+
.trim()
|
|
41
|
+
.split(/\s+/)
|
|
42
|
+
.map((word, index) => {
|
|
43
|
+
if (word.length > 1 && word === word.toUpperCase() && /[A-Z]/.test(word))
|
|
44
|
+
return word;
|
|
45
|
+
const lower = word.toLowerCase();
|
|
46
|
+
if (index > 0 && SMALL_WORDS.has(lower))
|
|
47
|
+
return lower;
|
|
48
|
+
return lower.charAt(0).toUpperCase() + lower.slice(1);
|
|
49
|
+
})
|
|
50
|
+
.join(' ');
|
|
51
|
+
}
|
|
52
|
+
function sentenceCase(phrase) {
|
|
53
|
+
const words = phrase.trim().split(/\s+/);
|
|
54
|
+
return words.map((word, index) => (word.length > 1 && word === word.toUpperCase() && /[A-Z]/.test(word) ? word : index === 0 ? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() : word.toLowerCase())).join(' ');
|
|
55
|
+
}
|
|
56
|
+
function bannedWordIn(service) {
|
|
57
|
+
const words = service.toLowerCase().split(/\s+/);
|
|
58
|
+
return BANNED_WORDS.find((banned) => words.includes(banned));
|
|
59
|
+
}
|
|
60
|
+
/** "{Service} {Place}": the service in title case and the place as named. The service has no "in" and no "the". */
|
|
61
|
+
export function locationHeading(service, place) {
|
|
62
|
+
const name = clean(service, 'service');
|
|
63
|
+
const banned = bannedWordIn(name);
|
|
64
|
+
if (banned)
|
|
65
|
+
throw new Error(`A location heading has no "${banned}": "${name}" is not the short exact phrase.`);
|
|
66
|
+
return `${titleCase(name)} ${clean(place, 'place')}`;
|
|
67
|
+
}
|
|
68
|
+
function fit(heading, input, tailAllowed) {
|
|
69
|
+
const brand = clean(input.brand, 'brand');
|
|
70
|
+
const short = input.shortBrand?.trim() || brand;
|
|
71
|
+
const tail = tailAllowed ? input.proofTail?.trim() : undefined;
|
|
72
|
+
const candidates = [
|
|
73
|
+
...(tail ? [`${heading} | ${tail} | ${brand}`, `${heading} | ${tail} | ${short}`] : []),
|
|
74
|
+
`${heading} | ${brand}`,
|
|
75
|
+
`${heading} | ${short}`,
|
|
76
|
+
];
|
|
77
|
+
return candidates.find((candidate) => candidate.length <= BRANDLAB_TITLE_MAX_LENGTH) ?? heading;
|
|
78
|
+
}
|
|
79
|
+
/** The title and H1 a new page of `family` takes. */
|
|
80
|
+
export function buildPageTitle(input) {
|
|
81
|
+
if (!BRANDLAB_TITLE_FAMILIES.includes(input.family)) {
|
|
82
|
+
throw new Error(`buildPageTitle does not know the family "${String(input.family)}".`);
|
|
83
|
+
}
|
|
84
|
+
const locationFamily = input.family !== 'home' && input.family !== 'service' && input.family !== 'cost-guide' && input.family !== 'project';
|
|
85
|
+
if (input.proofTail !== undefined) {
|
|
86
|
+
if (input.family !== 'service' && !(locationFamily && input.tier === 'head')) {
|
|
87
|
+
throw new Error('A proof tail goes only on the service page and head-tier pages; standard-tier pages never carry one.');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
let heading;
|
|
91
|
+
let h1;
|
|
92
|
+
switch (input.family) {
|
|
93
|
+
case 'home':
|
|
94
|
+
case 'service': {
|
|
95
|
+
const phrase = clean(input.phrase, 'phrase');
|
|
96
|
+
const banned = bannedWordIn(phrase);
|
|
97
|
+
if (banned)
|
|
98
|
+
throw new Error(`An H1 has no "${banned}": "${phrase}" is not the short exact phrase.`);
|
|
99
|
+
heading = titleCase(phrase);
|
|
100
|
+
h1 = heading;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case 'cost-guide': {
|
|
104
|
+
const service = clean(input.service, 'service');
|
|
105
|
+
const place = clean(input.place, 'place');
|
|
106
|
+
if (!Number.isInteger(input.year) || input.year < 2000)
|
|
107
|
+
throw new Error('buildPageTitle needs the year a cost guide is for.');
|
|
108
|
+
heading = `${titleCase(service)} Cost ${place} ${input.year}`;
|
|
109
|
+
h1 = `${sentenceCase(service)} cost ${place} (${input.year})`;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
case 'project': {
|
|
113
|
+
const job = clean(input.job, 'job');
|
|
114
|
+
const place = clean(input.place, 'place');
|
|
115
|
+
heading = `${locationHeading(clean(input.service, 'service'), place)}: ${job}`;
|
|
116
|
+
h1 = `${job}, ${place}`;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
default: {
|
|
120
|
+
heading = locationHeading(clean(input.service, 'service'), clean(input.place, 'place'));
|
|
121
|
+
h1 = heading;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const title = fit(heading, input, input.proofTail !== undefined);
|
|
125
|
+
return { title, h1, heading, length: title.length, overLength: heading.length > BRANDLAB_TITLE_MAX_LENGTH };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Why a location page's H1 and title break "{Service} {Place}", or null when they keep it: the H1 ends with the place
|
|
129
|
+
* and has a service before it, no "in" and no leading "the"; the title starts with the H1 (letter case aside), has at
|
|
130
|
+
* most two pipes and is at most 60 characters.
|
|
131
|
+
*/
|
|
132
|
+
export function locationHeadingProblem(sample) {
|
|
133
|
+
const h1 = sample.h1.trim().replace(/\s+/g, ' ');
|
|
134
|
+
const title = sample.title.trim().replace(/\s+/g, ' ');
|
|
135
|
+
const place = sample.place.trim().replace(/\s+/g, ' ');
|
|
136
|
+
const lowerH1 = h1.toLowerCase();
|
|
137
|
+
const lowerPlace = place.toLowerCase();
|
|
138
|
+
if (!lowerH1.endsWith(` ${lowerPlace}`) && lowerH1 !== lowerPlace) {
|
|
139
|
+
return `the H1 "${h1}" is not "{Service} {Place}": it never ends with the place ("${place}").`;
|
|
140
|
+
}
|
|
141
|
+
const service = h1.slice(0, h1.length - place.length).trim();
|
|
142
|
+
if (!service)
|
|
143
|
+
return `the H1 "${h1}" names the place without the service.`;
|
|
144
|
+
const words = service.toLowerCase().split(' ');
|
|
145
|
+
if (words.includes('in'))
|
|
146
|
+
return `the H1 "${h1}" has "in"; it is the short exact phrase "{Service} {Place}".`;
|
|
147
|
+
if (words.includes('the'))
|
|
148
|
+
return `the H1 "${h1}" has "the"; it is the short exact phrase "{Service} {Place}".`;
|
|
149
|
+
if (!title.toLowerCase().startsWith(lowerH1))
|
|
150
|
+
return `the title "${title}" never starts with the H1 "${h1}".`;
|
|
151
|
+
const rest = title.slice(h1.length);
|
|
152
|
+
if (rest && !rest.startsWith(' | '))
|
|
153
|
+
return `the title "${title}" adds words to "${h1}" before its brand.`;
|
|
154
|
+
if ((title.match(/\|/g) ?? []).length > 2)
|
|
155
|
+
return `the title "${title}" chains more than two pipes.`;
|
|
156
|
+
if (title.length > BRANDLAB_TITLE_MAX_LENGTH && title !== h1) {
|
|
157
|
+
return `the title "${title}" is ${title.length} characters; titles are at most 60 characters (drop or shorten the brand, never the keyword).`;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=page-titles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-titles.js","sourceRoot":"","sources":["../src/page-titles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAA;AAE3C,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,MAAM;IACN,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,gBAAgB;IAChB,mBAAmB;IACnB,YAAY;IACZ,SAAS;CACD,CAAA;AAoCV,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAA;AAC/G,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,KAAK,CAAU,CAAA;AAE3C,SAAS,KAAK,CAAC,KAAyB,EAAE,KAAa;IACrD,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC/E,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KA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GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC9C,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,WAAW,EAAE,+DAA+D,CAAA;IAC7G,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,WAAW,EAAE,gEAAgE,CAAA;IAC/G,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,cAAc,KAAK,+BAA+B,EAAE,IAAI,CAAA;IAC7G,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAA;IACnC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,cAAc,KAAK,oBAAoB,EAAE,qBAAqB,CAAA;IAC1G,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,cAAc,KAAK,+BAA+B,CAAA;IACpG,IAAI,KAAK,CAAC,MAAM,GAAG,yBAAyB,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QAC7D,OAAO,cAAc,KAAK,QAAQ,KAAK,CAAC,MAAM,+FAA+F,CAAA;IAC/I,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["/**\n * Titles and H1s for new pages (Site System v2 §5.2; correction #27). Earning pages keep their recorded titles\n * (`docs/recorded-titles.json`, check E1); every other page takes its family's pattern:\n *\n * | Family | Title | H1 |\n * |---|---|---|\n * | Home | `{Home phrase} \\| {Brand}` | `{Home phrase}` |\n * | Service | `{Service phrase} \\| {Brand}` | `{Service phrase}` |\n * | Region, suburb | `{Main service} {Place} \\| {Brand}` | `{Main service} {Place}` |\n * | Service-region hub, service in suburb | `{Service} {Place} \\| {Brand}` | `{Service} {Place}` |\n * | Cost guide | `{Service} Cost {Area} {Year} \\| {Brand}` | `{Service} cost {area} ({year})` |\n * | Project | `{Service} {Suburb}: {Job} \\| {Brand}` | `{Job}, {Suburb}` |\n *\n * H1s are the short exact phrase with no \"in\" and no \"the\". Titles are at most 60 characters: the short brand only\n * when needed, never a cut keyword. A proof tail (`| From $450 |`, \"Same-Week Quotes\") comes only from data and only\n * on the service page and head-tier pages. One pipe separates the brand; with a tail there are two.\n */\n\nexport const BRANDLAB_TITLE_MAX_LENGTH = 60\n\nexport const BRANDLAB_TITLE_FAMILIES = [\n 'home',\n 'service',\n 'region',\n 'suburb',\n 'service-region',\n 'service-in-suburb',\n 'cost-guide',\n 'project',\n] as const\nexport type BrandlabTitleFamily = (typeof BRANDLAB_TITLE_FAMILIES)[number]\n\nexport interface BrandlabPageTitleInput {\n readonly family: BrandlabTitleFamily\n /** The full brand, for example \"AA Tree Services Sydney\". */\n readonly brand: string\n /** The short brand used when the full one would push the title past 60 characters. */\n readonly shortBrand?: string\n /** Home and service pages: the owned phrase, for example \"tree removal sydney\". */\n readonly phrase?: string\n /** Location, cost-guide and project pages: the service (the main service on region and suburb pages). */\n readonly service?: string\n /** The place's display name, for example \"Ryde\" or \"Western Sydney\". */\n readonly place?: string\n /** Location pages: `head` pages may carry a proof tail; `standard` pages never do. */\n readonly tier?: 'head' | 'standard'\n /** \"From $450\" or \"Same-Week Quotes\": only when true and only on service and head-tier pages. */\n readonly proofTail?: string\n /** Cost guides. */\n readonly year?: number\n /** Projects: the job, for example \"Gum tree removal over a pool\". */\n readonly job?: string\n}\n\nexport interface BrandlabPageTitle {\n /** The full `<title>` (pass it with `titleMode: 'absolute'`). */\n readonly title: string\n readonly h1: string\n /** The title before its first pipe. */\n readonly heading: string\n readonly length: number\n /** True only when the heading alone is over 60 characters: it is kept whole rather than cut. */\n readonly overLength: boolean\n}\n\nconst SMALL_WORDS = new Set(['a', 'an', 'and', 'as', 'at', 'but', 'by', 'for', 'of', 'on', 'or', 'to', 'with'])\nconst BANNED_WORDS = ['in', 'the'] as const\n\nfunction clean(value: string | undefined, field: string): string {\n const text = typeof value === 'string' ? value.trim().replace(/\\s+/g, ' ') : ''\n if (!text) throw new Error(`buildPageTitle needs a ${field} for this family.`)\n return text\n}\n\n/** Title case: every word capitalised except short joining words after the first; words in capitals stay so. */\nexport function titleCase(phrase: string): string {\n return phrase\n .trim()\n .split(/\\s+/)\n .map((word, index) => {\n if (word.length > 1 && word === word.toUpperCase() && /[A-Z]/.test(word)) return word\n const lower = word.toLowerCase()\n if (index > 0 && SMALL_WORDS.has(lower)) return lower\n return lower.charAt(0).toUpperCase() + lower.slice(1)\n })\n .join(' ')\n}\n\nfunction sentenceCase(phrase: string): string {\n const words = phrase.trim().split(/\\s+/)\n return words.map((word, index) => (word.length > 1 && word === word.toUpperCase() && /[A-Z]/.test(word) ? word : index === 0 ? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() : word.toLowerCase())).join(' ')\n}\n\nfunction bannedWordIn(service: string): string | undefined {\n const words = service.toLowerCase().split(/\\s+/)\n return BANNED_WORDS.find((banned) => words.includes(banned))\n}\n\n/** \"{Service} {Place}\": the service in title case and the place as named. The service has no \"in\" and no \"the\". */\nexport function locationHeading(service: string, place: string): string {\n const name = clean(service, 'service')\n const banned = bannedWordIn(name)\n if (banned) throw new Error(`A location heading has no \"${banned}\": \"${name}\" is not the short exact phrase.`)\n return `${titleCase(name)} ${clean(place, 'place')}`\n}\n\nfunction fit(heading: string, input: BrandlabPageTitleInput, tailAllowed: boolean): string {\n const brand = clean(input.brand, 'brand')\n const short = input.shortBrand?.trim() || brand\n const tail = tailAllowed ? input.proofTail?.trim() : undefined\n const candidates = [\n ...(tail ? [`${heading} | ${tail} | ${brand}`, `${heading} | ${tail} | ${short}`] : []),\n `${heading} | ${brand}`,\n `${heading} | ${short}`,\n ]\n return candidates.find((candidate) => candidate.length <= BRANDLAB_TITLE_MAX_LENGTH) ?? heading\n}\n\n/** The title and H1 a new page of `family` takes. */\nexport function buildPageTitle(input: BrandlabPageTitleInput): BrandlabPageTitle {\n if (!(BRANDLAB_TITLE_FAMILIES as readonly string[]).includes(input.family)) {\n throw new Error(`buildPageTitle does not know the family \"${String(input.family)}\".`)\n }\n const locationFamily = input.family !== 'home' && input.family !== 'service' && input.family !== 'cost-guide' && input.family !== 'project'\n if (input.proofTail !== undefined) {\n if (input.family !== 'service' && !(locationFamily && input.tier === 'head')) {\n throw new Error('A proof tail goes only on the service page and head-tier pages; standard-tier pages never carry one.')\n }\n }\n let heading: string\n let h1: string\n switch (input.family) {\n case 'home':\n case 'service': {\n const phrase = clean(input.phrase, 'phrase')\n const banned = bannedWordIn(phrase)\n if (banned) throw new Error(`An H1 has no \"${banned}\": \"${phrase}\" is not the short exact phrase.`)\n heading = titleCase(phrase)\n h1 = heading\n break\n }\n case 'cost-guide': {\n const service = clean(input.service, 'service')\n const place = clean(input.place, 'place')\n if (!Number.isInteger(input.year) || (input.year as number) < 2000) throw new Error('buildPageTitle needs the year a cost guide is for.')\n heading = `${titleCase(service)} Cost ${place} ${input.year}`\n h1 = `${sentenceCase(service)} cost ${place} (${input.year})`\n break\n }\n case 'project': {\n const job = clean(input.job, 'job')\n const place = clean(input.place, 'place')\n heading = `${locationHeading(clean(input.service, 'service'), place)}: ${job}`\n h1 = `${job}, ${place}`\n break\n }\n default: {\n heading = locationHeading(clean(input.service, 'service'), clean(input.place, 'place'))\n h1 = heading\n }\n }\n const title = fit(heading, input, input.proofTail !== undefined)\n return { title, h1, heading, length: title.length, overLength: heading.length > BRANDLAB_TITLE_MAX_LENGTH }\n}\n\n/** What check E1-pattern compares on a location page. */\nexport interface BrandlabLocationHeadingSample {\n readonly h1: string\n readonly title: string\n /** The place the page is for, as named. */\n readonly place: string\n}\n\n/**\n * Why a location page's H1 and title break \"{Service} {Place}\", or null when they keep it: the H1 ends with the place\n * and has a service before it, no \"in\" and no leading \"the\"; the title starts with the H1 (letter case aside), has at\n * most two pipes and is at most 60 characters.\n */\nexport function locationHeadingProblem(sample: BrandlabLocationHeadingSample): string | null {\n const h1 = sample.h1.trim().replace(/\\s+/g, ' ')\n const title = sample.title.trim().replace(/\\s+/g, ' ')\n const place = sample.place.trim().replace(/\\s+/g, ' ')\n const lowerH1 = h1.toLowerCase()\n const lowerPlace = place.toLowerCase()\n if (!lowerH1.endsWith(` ${lowerPlace}`) && lowerH1 !== lowerPlace) {\n return `the H1 \"${h1}\" is not \"{Service} {Place}\": it never ends with the place (\"${place}\").`\n }\n const service = h1.slice(0, h1.length - place.length).trim()\n if (!service) return `the H1 \"${h1}\" names the place without the service.`\n const words = service.toLowerCase().split(' ')\n if (words.includes('in')) return `the H1 \"${h1}\" has \"in\"; it is the short exact phrase \"{Service} {Place}\".`\n if (words.includes('the')) return `the H1 \"${h1}\" has \"the\"; it is the short exact phrase \"{Service} {Place}\".`\n if (!title.toLowerCase().startsWith(lowerH1)) return `the title \"${title}\" never starts with the H1 \"${h1}\".`\n const rest = title.slice(h1.length)\n if (rest && !rest.startsWith(' | ')) return `the title \"${title}\" adds words to \"${h1}\" before its brand.`\n if ((title.match(/\\|/g) ?? []).length > 2) return `the title \"${title}\" chains more than two pipes.`\n if (title.length > BRANDLAB_TITLE_MAX_LENGTH && title !== h1) {\n return `the title \"${title}\" is ${title.length} characters; titles are at most 60 characters (drop or shorten the brand, never the keyword).`\n }\n return null\n}\n"]}
|
package/dist/project.d.ts
CHANGED
|
@@ -48,6 +48,70 @@ export interface BrandlabSiteSystemConfig {
|
|
|
48
48
|
thirdParties?: readonly string[];
|
|
49
49
|
/** Extra tel: links the site legitimately shows, for example a second line. */
|
|
50
50
|
phones?: readonly string[];
|
|
51
|
+
/**
|
|
52
|
+
* Estate families allowed to refresh more often than every 7 days (check W3, from 3.13.0), each with the reason
|
|
53
|
+
* and the recorded decision. Without an entry, a full-tier estate family refreshes at most weekly.
|
|
54
|
+
*/
|
|
55
|
+
refreshExceptions?: readonly BrandlabEstateRefreshException[];
|
|
56
|
+
}
|
|
57
|
+
/** The location estate families check W3 covers. */
|
|
58
|
+
export declare const BRANDLAB_ESTATE_REFRESH_FAMILIES: readonly ["suburb", "service-in-suburb", "region", "council"];
|
|
59
|
+
export type BrandlabEstateRefreshFamily = (typeof BRANDLAB_ESTATE_REFRESH_FAMILIES)[number];
|
|
60
|
+
/** The shortest refresh an estate family may use without an exception: 7 days, in seconds. */
|
|
61
|
+
export declare const BRANDLAB_ESTATE_MIN_REFRESH_SECONDS = 604800;
|
|
62
|
+
export interface BrandlabEstateRefreshException {
|
|
63
|
+
family: BrandlabEstateRefreshFamily;
|
|
64
|
+
/** The shortest refresh the family may use, in whole seconds (60 to 604,799). */
|
|
65
|
+
revalidateSeconds: number;
|
|
66
|
+
/** Why the family needs to refresh more often than weekly. */
|
|
67
|
+
reason: string;
|
|
68
|
+
/** The recorded decision that allows it, for example a Notion decision id. */
|
|
69
|
+
decisionId: string;
|
|
70
|
+
}
|
|
71
|
+
/** A Vercel function region a Brandlab site may run in: Sydney, or Washington with a recorded decision. */
|
|
72
|
+
export type BrandlabOriginRegion = 'syd1' | 'iad1';
|
|
73
|
+
/** `hosting.originRegion`: one region, or both (`['syd1', 'iad1']`; the ISR store then always goes to iad1). */
|
|
74
|
+
export type BrandlabOriginRegionSetting = BrandlabOriginRegion | readonly BrandlabOriginRegion[];
|
|
75
|
+
/** The region every site runs in unless a decision records another: Sydney, where the visitors are. */
|
|
76
|
+
export declare const BRANDLAB_DEFAULT_ORIGIN_REGION = "syd1";
|
|
77
|
+
/** The longest a non-Sydney origin decision lasts before it is reviewed: six calendar months. */
|
|
78
|
+
export declare const BRANDLAB_ORIGIN_DECISION_MAX_MONTHS = 6;
|
|
79
|
+
/**
|
|
80
|
+
* A recorded origin-region decision under rule `origin-region-v1` (operations/shared-platform/ORIGIN_REGION.md).
|
|
81
|
+
* Any region other than Sydney needs one; it lapses on `reviewBy`, at most six months after `decidedOn`.
|
|
82
|
+
*/
|
|
83
|
+
export interface BrandlabOriginRegionDecision {
|
|
84
|
+
rule: 'origin-region-v1';
|
|
85
|
+
/** YYYY-MM-DD. */
|
|
86
|
+
decidedOn: string;
|
|
87
|
+
/** Where the benchmark and the decision are recorded (a Notion page, a PR or a report path). */
|
|
88
|
+
evidence: string;
|
|
89
|
+
/** The expected saving per billing cycle in US dollars (at least US$2 under the rule). */
|
|
90
|
+
savingUsdPerCycle: number;
|
|
91
|
+
/** How much slower a cold miss was in the benchmark, in milliseconds (at most 250 under the rule). */
|
|
92
|
+
coldMissDeltaMs: number;
|
|
93
|
+
/** YYYY-MM-DD, after `decidedOn` and no more than six months after it. The ready gate fails once it passes. */
|
|
94
|
+
reviewBy: string;
|
|
95
|
+
}
|
|
96
|
+
/** A firewall rule recorded for the ready gate's crawler guard (W10): what it matches in the user agent and does. */
|
|
97
|
+
export interface BrandlabFirewallRuleRecord {
|
|
98
|
+
/** The rule's name or id in the Vercel or Cloudflare firewall. */
|
|
99
|
+
id: string;
|
|
100
|
+
action: 'deny' | 'challenge' | 'rate-limit' | 'log' | 'bypass';
|
|
101
|
+
/** How the rule matches the User-Agent header, as the firewall writes it. */
|
|
102
|
+
userAgent: {
|
|
103
|
+
match: 'contains' | 'equals' | 'regex';
|
|
104
|
+
value: string;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Where the site's server functions run (3.13.0). `vercel.json` `regions` must equal `originRegion`; the default is
|
|
109
|
+
* Sydney. Firewall rules that match on the user agent are recorded here so the ready gate can check them.
|
|
110
|
+
*/
|
|
111
|
+
export interface BrandlabHostingConfig {
|
|
112
|
+
originRegion: BrandlabOriginRegionSetting;
|
|
113
|
+
decision?: BrandlabOriginRegionDecision;
|
|
114
|
+
firewall?: readonly BrandlabFirewallRuleRecord[];
|
|
51
115
|
}
|
|
52
116
|
export type BrandlabSitemapConfig = {
|
|
53
117
|
mode: 'single';
|
|
@@ -86,7 +150,19 @@ export interface BrandlabProjectConfig {
|
|
|
86
150
|
};
|
|
87
151
|
exceptions?: readonly BrandlabException[];
|
|
88
152
|
siteSystem?: BrandlabSiteSystemConfig;
|
|
153
|
+
/** Where the server functions run; absent means Sydney (`syd1`). */
|
|
154
|
+
hosting?: BrandlabHostingConfig;
|
|
89
155
|
}
|
|
156
|
+
/** The last day a decision taken on `decidedOn` may be reviewed by: the same day six months later (or month end). */
|
|
157
|
+
export declare function brandlabOriginDecisionReviewLimit(decidedOn: string): string;
|
|
158
|
+
/** The regions `hosting.originRegion` names, sorted; Sydney alone when there is no hosting block. */
|
|
159
|
+
export declare function brandlabOriginRegions(hosting?: Pick<BrandlabHostingConfig, 'originRegion'>): BrandlabOriginRegion[];
|
|
160
|
+
/**
|
|
161
|
+
* Problems with a site's hosting record on `today` (YYYY-MM-DD): the ready gate (W5) fails on any. A region other
|
|
162
|
+
* than Sydney needs an `origin-region-v1` decision whose `reviewBy` has not passed and is no more than six months
|
|
163
|
+
* after `decidedOn`. The shape is checked too, because the gate reads the config without running it.
|
|
164
|
+
*/
|
|
165
|
+
export declare function brandlabHostingProblems(hosting: unknown, today: string): string[];
|
|
90
166
|
/**
|
|
91
167
|
* Defines project-owned variation only. Runtime versions and global Brandlab
|
|
92
168
|
* policy deliberately do not belong in this object.
|
package/dist/project.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AACtE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAA;AAEhF,MAAM,MAAM,mBAAmB,GAC3B,UAAU,GACV,WAAW,GACX,mBAAmB,GACnB,MAAM,GACN,UAAU,GACV,OAAO,CAAA;AAEX,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,KAAK,GAAG,YAAY,CAAA;AAC/D,MAAM,MAAM,6BAA6B,GACrC,MAAM,GACN,iBAAiB,GACjB,iBAAiB,GACjB,0BAA0B,CAAA;AAC9B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
import { normalizeBrandlabRoutePath } from './routes.js';
|
|
2
2
|
import { assertBrandlabCanonicalEntityId } from './entity-id.js';
|
|
3
|
+
/** The location estate families check W3 covers. */
|
|
4
|
+
export const BRANDLAB_ESTATE_REFRESH_FAMILIES = ['suburb', 'service-in-suburb', 'region', 'council'];
|
|
5
|
+
/** The shortest refresh an estate family may use without an exception: 7 days, in seconds. */
|
|
6
|
+
export const BRANDLAB_ESTATE_MIN_REFRESH_SECONDS = 604_800;
|
|
7
|
+
/** The region every site runs in unless a decision records another: Sydney, where the visitors are. */
|
|
8
|
+
export const BRANDLAB_DEFAULT_ORIGIN_REGION = 'syd1';
|
|
9
|
+
/** The longest a non-Sydney origin decision lasts before it is reviewed: six calendar months. */
|
|
10
|
+
export const BRANDLAB_ORIGIN_DECISION_MAX_MONTHS = 6;
|
|
3
11
|
const PROJECT_CONFIG_KEYS = [
|
|
4
12
|
'projectId',
|
|
5
13
|
'routes',
|
|
@@ -8,6 +16,7 @@ const PROJECT_CONFIG_KEYS = [
|
|
|
8
16
|
'searchCertification',
|
|
9
17
|
'exceptions',
|
|
10
18
|
'siteSystem',
|
|
19
|
+
'hosting',
|
|
11
20
|
];
|
|
12
21
|
const ROUTE_FAMILIES = new Set([
|
|
13
22
|
'services',
|
|
@@ -49,9 +58,141 @@ const BUSINESS_PROFILE_REVIEWS_SELECTIONS = new Set([
|
|
|
49
58
|
'five-star',
|
|
50
59
|
]);
|
|
51
60
|
const SITE_SYSTEM_TIERS = new Set(['shell', 'enquiry', 'full']);
|
|
52
|
-
const SITE_SYSTEM_KEYS = ['tier', 'newBuild', 'samples', 'labels', 'freeQuotes', 'thirdParties', 'phones'];
|
|
61
|
+
const SITE_SYSTEM_KEYS = ['tier', 'newBuild', 'samples', 'labels', 'freeQuotes', 'thirdParties', 'phones', 'refreshExceptions'];
|
|
62
|
+
const REFRESH_EXCEPTION_KEYS = ['family', 'revalidateSeconds', 'reason', 'decisionId'];
|
|
53
63
|
const HOSTNAME_PATTERN = /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;
|
|
54
64
|
const TEL_HREF_PATTERN = /^tel:\+?\d{6,15}$/;
|
|
65
|
+
const ORIGIN_REGIONS = new Set(['syd1', 'iad1']);
|
|
66
|
+
const HOSTING_KEYS = ['originRegion', 'decision', 'firewall'];
|
|
67
|
+
const DECISION_KEYS = ['rule', 'decidedOn', 'evidence', 'savingUsdPerCycle', 'coldMissDeltaMs', 'reviewBy'];
|
|
68
|
+
const FIREWALL_ACTIONS = new Set(['deny', 'challenge', 'rate-limit', 'log', 'bypass']);
|
|
69
|
+
const FIREWALL_MATCHES = new Set(['contains', 'equals', 'regex']);
|
|
70
|
+
const ISO_DAY = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
71
|
+
/** A YYYY-MM-DD calendar day as a UTC timestamp, or null when it is not a real day. */
|
|
72
|
+
function isoDay(value) {
|
|
73
|
+
if (typeof value !== 'string')
|
|
74
|
+
return null;
|
|
75
|
+
const match = ISO_DAY.exec(value);
|
|
76
|
+
if (!match)
|
|
77
|
+
return null;
|
|
78
|
+
const time = Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]));
|
|
79
|
+
return new Date(time).toISOString().slice(0, 10) === value ? time : null;
|
|
80
|
+
}
|
|
81
|
+
/** The last day a decision taken on `decidedOn` may be reviewed by: the same day six months later (or month end). */
|
|
82
|
+
export function brandlabOriginDecisionReviewLimit(decidedOn) {
|
|
83
|
+
const start = isoDay(decidedOn);
|
|
84
|
+
if (start === null)
|
|
85
|
+
throw new Error('decidedOn must be a YYYY-MM-DD date.');
|
|
86
|
+
const date = new Date(start);
|
|
87
|
+
const day = date.getUTCDate();
|
|
88
|
+
const target = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + BRANDLAB_ORIGIN_DECISION_MAX_MONTHS, 1));
|
|
89
|
+
const lastDay = new Date(Date.UTC(target.getUTCFullYear(), target.getUTCMonth() + 1, 0)).getUTCDate();
|
|
90
|
+
target.setUTCDate(Math.min(day, lastDay));
|
|
91
|
+
return target.toISOString().slice(0, 10);
|
|
92
|
+
}
|
|
93
|
+
/** The regions `hosting.originRegion` names, sorted; Sydney alone when there is no hosting block. */
|
|
94
|
+
export function brandlabOriginRegions(hosting) {
|
|
95
|
+
const setting = hosting?.originRegion ?? BRANDLAB_DEFAULT_ORIGIN_REGION;
|
|
96
|
+
return [...new Set(typeof setting === 'string' ? [setting] : setting)].sort();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Problems with a site's hosting record on `today` (YYYY-MM-DD): the ready gate (W5) fails on any. A region other
|
|
100
|
+
* than Sydney needs an `origin-region-v1` decision whose `reviewBy` has not passed and is no more than six months
|
|
101
|
+
* after `decidedOn`. The shape is checked too, because the gate reads the config without running it.
|
|
102
|
+
*/
|
|
103
|
+
export function brandlabHostingProblems(hosting, today) {
|
|
104
|
+
if (hosting === undefined)
|
|
105
|
+
return [];
|
|
106
|
+
if (!hosting || typeof hosting !== 'object' || Array.isArray(hosting))
|
|
107
|
+
return ['hosting must be an object with an originRegion.'];
|
|
108
|
+
const record = hosting;
|
|
109
|
+
const problems = [];
|
|
110
|
+
const unknown = Object.keys(record).filter((key) => !HOSTING_KEYS.includes(key));
|
|
111
|
+
if (unknown.length > 0)
|
|
112
|
+
problems.push(`hosting contains unsupported keys: ${unknown.join(', ')}.`);
|
|
113
|
+
const setting = record.originRegion;
|
|
114
|
+
const list = typeof setting === 'string' ? [setting] : Array.isArray(setting) ? setting : null;
|
|
115
|
+
if (!list ||
|
|
116
|
+
list.length === 0 ||
|
|
117
|
+
list.some((region) => !ORIGIN_REGIONS.has(region)) ||
|
|
118
|
+
new Set(list).size !== list.length) {
|
|
119
|
+
problems.push(`hosting.originRegion must be 'syd1', 'iad1' or ['syd1', 'iad1'] (found ${JSON.stringify(setting)}).`);
|
|
120
|
+
return problems;
|
|
121
|
+
}
|
|
122
|
+
const sydneyOnly = list.length === 1 && list[0] === BRANDLAB_DEFAULT_ORIGIN_REGION;
|
|
123
|
+
const decision = record.decision;
|
|
124
|
+
if (decision === undefined) {
|
|
125
|
+
if (!sydneyOnly) {
|
|
126
|
+
problems.push(`hosting.originRegion ${JSON.stringify(setting)} needs a recorded origin-region-v1 decision (hosting.decision); only syd1 runs without one.`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (!decision || typeof decision !== 'object' || Array.isArray(decision)) {
|
|
130
|
+
problems.push('hosting.decision must be an object.');
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const entry = decision;
|
|
134
|
+
const extra = Object.keys(entry).filter((key) => !DECISION_KEYS.includes(key));
|
|
135
|
+
if (extra.length > 0)
|
|
136
|
+
problems.push(`hosting.decision contains unsupported keys: ${extra.join(', ')}.`);
|
|
137
|
+
if (entry.rule !== 'origin-region-v1')
|
|
138
|
+
problems.push(`hosting.decision.rule must be 'origin-region-v1' (found ${JSON.stringify(entry.rule)}).`);
|
|
139
|
+
if (typeof entry.evidence !== 'string' || !entry.evidence.trim())
|
|
140
|
+
problems.push('hosting.decision.evidence must name where the benchmark and decision are recorded.');
|
|
141
|
+
for (const key of ['savingUsdPerCycle', 'coldMissDeltaMs']) {
|
|
142
|
+
if (typeof entry[key] !== 'number' || !Number.isFinite(entry[key]))
|
|
143
|
+
problems.push(`hosting.decision.${key} must be a number.`);
|
|
144
|
+
}
|
|
145
|
+
const decided = isoDay(entry.decidedOn);
|
|
146
|
+
const review = isoDay(entry.reviewBy);
|
|
147
|
+
if (decided === null)
|
|
148
|
+
problems.push('hosting.decision.decidedOn must be a YYYY-MM-DD date.');
|
|
149
|
+
if (review === null)
|
|
150
|
+
problems.push('hosting.decision.reviewBy must be a YYYY-MM-DD date.');
|
|
151
|
+
if (decided !== null && review !== null) {
|
|
152
|
+
const limit = brandlabOriginDecisionReviewLimit(entry.decidedOn);
|
|
153
|
+
if (review <= decided)
|
|
154
|
+
problems.push(`hosting.decision.reviewBy (${entry.reviewBy}) must be after decidedOn (${entry.decidedOn}).`);
|
|
155
|
+
else if (entry.reviewBy > limit) {
|
|
156
|
+
problems.push(`hosting.decision.reviewBy (${entry.reviewBy}) is more than ${BRANDLAB_ORIGIN_DECISION_MAX_MONTHS} months after decidedOn (${entry.decidedOn}); review by ${limit} at the latest.`);
|
|
157
|
+
}
|
|
158
|
+
if (!sydneyOnly && isoDay(today) !== null && today > entry.reviewBy) {
|
|
159
|
+
problems.push(`The origin-region decision for ${JSON.stringify(setting)} lapsed on ${entry.reviewBy}: review it under origin-region-v1 and record a new reviewBy, or move back to syd1.`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const firewall = record.firewall;
|
|
164
|
+
if (firewall !== undefined) {
|
|
165
|
+
if (!Array.isArray(firewall))
|
|
166
|
+
problems.push('hosting.firewall must be a list of recorded rules.');
|
|
167
|
+
else {
|
|
168
|
+
firewall.forEach((rule, index) => {
|
|
169
|
+
const field = `hosting.firewall[${index}]`;
|
|
170
|
+
if (!rule || typeof rule !== 'object' || Array.isArray(rule)) {
|
|
171
|
+
problems.push(`${field} must be an object.`);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const entry = rule;
|
|
175
|
+
if (typeof entry.id !== 'string' || !entry.id.trim())
|
|
176
|
+
problems.push(`${field}.id must name the firewall rule.`);
|
|
177
|
+
if (!FIREWALL_ACTIONS.has(entry.action))
|
|
178
|
+
problems.push(`${field}.action must be one of ${[...FIREWALL_ACTIONS].join(', ')}.`);
|
|
179
|
+
const userAgent = entry.userAgent;
|
|
180
|
+
if (!userAgent || typeof userAgent !== 'object' || !FIREWALL_MATCHES.has(userAgent.match) || typeof userAgent.value !== 'string' || !userAgent.value) {
|
|
181
|
+
problems.push(`${field}.userAgent must be { match: 'contains' | 'equals' | 'regex', value }.`);
|
|
182
|
+
}
|
|
183
|
+
else if (userAgent.match === 'regex') {
|
|
184
|
+
try {
|
|
185
|
+
new RegExp(userAgent.value);
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
problems.push(`${field}.userAgent.value is not a valid regular expression.`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return problems;
|
|
195
|
+
}
|
|
55
196
|
function assertNonEmpty(value, field) {
|
|
56
197
|
if (!value.trim()) {
|
|
57
198
|
throw new Error(`${field} cannot be empty.`);
|
|
@@ -71,6 +212,32 @@ function assertKnownKeys(value, allowed, field, hint = '') {
|
|
|
71
212
|
throw new Error(`${field} contains unsupported keys: ${unsupported.join(', ')}.${hint}`);
|
|
72
213
|
}
|
|
73
214
|
}
|
|
215
|
+
function assertRefreshExceptions(value) {
|
|
216
|
+
const field = 'siteSystem.refreshExceptions';
|
|
217
|
+
if (!Array.isArray(value))
|
|
218
|
+
throw new Error(`${field} must be a list.`);
|
|
219
|
+
value.forEach((entry, index) => {
|
|
220
|
+
const itemField = `${field}[${index}]`;
|
|
221
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
222
|
+
throw new Error(`${itemField} must be an object with family, revalidateSeconds, reason and decisionId.`);
|
|
223
|
+
}
|
|
224
|
+
assertKnownKeys(entry, REFRESH_EXCEPTION_KEYS, itemField);
|
|
225
|
+
const exception = entry;
|
|
226
|
+
if (!BRANDLAB_ESTATE_REFRESH_FAMILIES.includes(exception.family)) {
|
|
227
|
+
throw new Error(`${itemField}.family must be one of ${BRANDLAB_ESTATE_REFRESH_FAMILIES.join(', ')}.`);
|
|
228
|
+
}
|
|
229
|
+
const seconds = exception.revalidateSeconds;
|
|
230
|
+
if (!Number.isSafeInteger(seconds) || seconds < 60 || seconds >= BRANDLAB_ESTATE_MIN_REFRESH_SECONDS) {
|
|
231
|
+
throw new Error(`${itemField}.revalidateSeconds must be whole seconds from 60 to 604799; weekly or slower needs no exception.`);
|
|
232
|
+
}
|
|
233
|
+
for (const key of ['reason', 'decisionId']) {
|
|
234
|
+
if (typeof exception[key] !== 'string')
|
|
235
|
+
throw new Error(`${itemField}.${key} must be text.`);
|
|
236
|
+
assertNonEmpty(exception[key], `${itemField}.${key}`);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
assertUnique(value.map((entry) => entry.family), `${field}.family`);
|
|
240
|
+
}
|
|
74
241
|
function assertStringList(value, field, check) {
|
|
75
242
|
if (!Array.isArray(value)) {
|
|
76
243
|
throw new Error(`${field} must be a list.`);
|
|
@@ -218,6 +385,15 @@ export function defineBrandlabProject(config) {
|
|
|
218
385
|
throw new Error(`${field} must be a tel: link such as tel:+61290001234.`);
|
|
219
386
|
});
|
|
220
387
|
}
|
|
388
|
+
if (siteSystem.refreshExceptions !== undefined) {
|
|
389
|
+
assertRefreshExceptions(siteSystem.refreshExceptions);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (config.hosting !== undefined) {
|
|
393
|
+
// The date-bound lapse is the ready gate's (W5): a lapsed decision must not stop a build or a rollback.
|
|
394
|
+
const problems = brandlabHostingProblems(config.hosting, '0000-01-01');
|
|
395
|
+
if (problems.length > 0)
|
|
396
|
+
throw new Error(problems[0]);
|
|
221
397
|
}
|
|
222
398
|
assertUnique((config.exceptions ?? []).map((exception) => exception.ruleId), 'exceptions.ruleId');
|
|
223
399
|
(config.exceptions ?? []).forEach((exception, index) => {
|