@brandlab-digital/site-core 3.3.2 → 3.4.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/dist/geography.d.ts +14 -2
- package/dist/geography.d.ts.map +1 -1
- package/dist/geography.js +978 -0
- package/dist/geography.js.map +1 -1
- package/dist/location-policy.d.ts +89 -0
- package/dist/location-policy.d.ts.map +1 -0
- package/dist/location-policy.js +119 -0
- package/dist/location-policy.js.map +1 -0
- package/dist/locations.d.ts +63 -0
- package/dist/locations.d.ts.map +1 -1
- package/dist/locations.js +111 -0
- package/dist/locations.js.map +1 -1
- package/dist/schema.d.ts +5 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +8 -0
- package/dist/schema.js.map +1 -1
- package/dist/sitemaps.d.ts +19 -1
- package/dist/sitemaps.d.ts.map +1 -1
- package/dist/sitemaps.js +30 -0
- package/dist/sitemaps.js.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The location index policy (3.4.0): how many indexable location pages a site
|
|
3
|
+
* can carry, and which indexable pages go on its review list.
|
|
4
|
+
*
|
|
5
|
+
* - Capacity is a judgement-based starting limit: the larger of 30 and the
|
|
6
|
+
* Australian, non-brand organic clicks the site's home, service and guide pages
|
|
7
|
+
* earned in the last 90 days. The check fails only when a change takes the
|
|
8
|
+
* indexable location pages above both the limit and the number the site had
|
|
9
|
+
* when the capacity was recorded, so a release that adds none is never blocked.
|
|
10
|
+
* - The review list names indexable location pages that record no qualifying
|
|
11
|
+
* evidence, or carry an open review flag. Pages on it stay indexed; adding
|
|
12
|
+
* evidence, merging or hiding a page is Romie's decision.
|
|
13
|
+
*
|
|
14
|
+
* Project pages are not location pages and never count towards capacity.
|
|
15
|
+
*/
|
|
16
|
+
import type { BrandlabLocationEvidence, BrandlabLocationRouteDecision } from './locations.js';
|
|
17
|
+
/** The capacity floor: a site may carry this many indexable location pages before its own clicks are counted. */
|
|
18
|
+
export declare const BRANDLAB_LOCATION_CAPACITY_FLOOR = 30;
|
|
19
|
+
export interface BrandlabLocationCapacityApproval {
|
|
20
|
+
/** Who approved holding more pages than the limit (Romie). */
|
|
21
|
+
approvedBy: string;
|
|
22
|
+
/** YYYY-MM-DD. */
|
|
23
|
+
approvedAt: string;
|
|
24
|
+
reason: string;
|
|
25
|
+
/** YYYY-MM-DD: when the approval is reviewed. */
|
|
26
|
+
reviewBy: string;
|
|
27
|
+
/** The most indexable location pages the approval allows; omitted means the estate as approved, with no ceiling. */
|
|
28
|
+
maxIndexable?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface BrandlabLocationCapacityDefinition {
|
|
31
|
+
/** The capacity: at least 30 (see locationCapacityFromClicks). */
|
|
32
|
+
limit: number;
|
|
33
|
+
/** Where the number comes from, for example the Search Console window and what it counted. */
|
|
34
|
+
basis: string;
|
|
35
|
+
/** YYYY-MM-DD; recalculate each quarter. */
|
|
36
|
+
recordedAt: string;
|
|
37
|
+
/** Indexable location pages when the capacity was recorded. A site above capacity keeps them, but adds none. */
|
|
38
|
+
indexableAtRecord: number;
|
|
39
|
+
/** Romie's approval to hold more pages than the limit. */
|
|
40
|
+
approval?: BrandlabLocationCapacityApproval;
|
|
41
|
+
}
|
|
42
|
+
export type BrandlabLocationCapacity = Readonly<BrandlabLocationCapacityDefinition>;
|
|
43
|
+
/** The capacity for a quarter's clicks: the larger of 30 and the clicks. */
|
|
44
|
+
export declare function locationCapacityFromClicks(nonLocationClicks: number): number;
|
|
45
|
+
/** Declares a site's recorded location capacity (`src/data/locations/indexing.ts`). */
|
|
46
|
+
export declare function defineLocationCapacity<const T extends BrandlabLocationCapacityDefinition>(definition: T): Readonly<T>;
|
|
47
|
+
/** The parts of a route the policy reads; a route catalogue entry has them all. */
|
|
48
|
+
export interface BrandlabLocationPolicyRoute {
|
|
49
|
+
id?: string;
|
|
50
|
+
path: string;
|
|
51
|
+
kind?: string;
|
|
52
|
+
indexing: string;
|
|
53
|
+
locationDecision?: BrandlabLocationRouteDecision;
|
|
54
|
+
}
|
|
55
|
+
/** Whether a route is an indexable location page (suburb, region, council or service-in-suburb). */
|
|
56
|
+
export declare function isIndexableLocationRoute(route: BrandlabLocationPolicyRoute): boolean;
|
|
57
|
+
export interface BrandlabLocationCapacityResult {
|
|
58
|
+
/** Indexable location pages in the catalogue. */
|
|
59
|
+
indexable: number;
|
|
60
|
+
/** The recorded capacity, or null when the site has not recorded one. */
|
|
61
|
+
limit: number | null;
|
|
62
|
+
/** The most pages the site may index without failing: the limit, the pages at record or the approval. */
|
|
63
|
+
allowed: number | null;
|
|
64
|
+
overCapacity: boolean;
|
|
65
|
+
/** The catalogue adds indexable location pages beyond what the site may carry. */
|
|
66
|
+
blocked: boolean;
|
|
67
|
+
detail: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Compares the catalogue's indexable location pages with the recorded capacity.
|
|
71
|
+
* `blocked` only when the catalogue holds more than both the limit and the pages
|
|
72
|
+
* the site had at record (or an approval's ceiling).
|
|
73
|
+
*/
|
|
74
|
+
export declare function checkLocationCapacity(routes: readonly BrandlabLocationPolicyRoute[], capacity: BrandlabLocationCapacity | null | undefined): BrandlabLocationCapacityResult;
|
|
75
|
+
/** Throws when the catalogue adds indexable location pages beyond the recorded capacity (for a build-time guard). */
|
|
76
|
+
export declare function assertLocationCapacity(routes: readonly BrandlabLocationPolicyRoute[], capacity: BrandlabLocationCapacity | null | undefined): BrandlabLocationCapacityResult;
|
|
77
|
+
export interface BrandlabLocationReviewItem {
|
|
78
|
+
id?: string;
|
|
79
|
+
path: string;
|
|
80
|
+
evidence: readonly BrandlabLocationEvidence[];
|
|
81
|
+
/** What the page is missing; it stays indexed until the review decides. */
|
|
82
|
+
reasons: readonly string[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The site's location review list: indexable location pages with no qualifying
|
|
86
|
+
* evidence recorded, or with an open review flag. Sorted by path.
|
|
87
|
+
*/
|
|
88
|
+
export declare function buildLocationReviewList(routes: readonly BrandlabLocationPolicyRoute[]): BrandlabLocationReviewItem[];
|
|
89
|
+
//# sourceMappingURL=location-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location-policy.d.ts","sourceRoot":"","sources":["../src/location-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,wBAAwB,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AAE7F,iHAAiH;AACjH,eAAO,MAAM,gCAAgC,KAAK,CAAA;AAElD,MAAM,WAAW,gCAAgC;IAC/C,8DAA8D;IAC9D,UAAU,EAAE,MAAM,CAAA;IAClB,kBAAkB;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAA;IAChB,oHAAoH;IACpH,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,kCAAkC;IACjD,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAA;IACb,8FAA8F;IAC9F,KAAK,EAAE,MAAM,CAAA;IACb,4CAA4C;IAC5C,UAAU,EAAE,MAAM,CAAA;IAClB,gHAAgH;IAChH,iBAAiB,EAAE,MAAM,CAAA;IACzB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,gCAAgC,CAAA;CAC5C;AAED,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC,kCAAkC,CAAC,CAAA;AAoBnF,4EAA4E;AAC5E,wBAAgB,0BAA0B,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAK5E;AAED,uFAAuF;AACvF,wBAAgB,sBAAsB,CAAC,KAAK,CAAC,CAAC,SAAS,kCAAkC,EAAE,UAAU,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAkBrH;AAED,mFAAmF;AACnF,MAAM,WAAW,2BAA2B;IAC1C,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,CAAC,EAAE,6BAA6B,CAAA;CACjD;AAID,oGAAoG;AACpG,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO,CAEpF;AAED,MAAM,WAAW,8BAA8B;IAC7C,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAA;IACjB,yEAAyE;IACzE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,yGAAyG;IACzG,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,YAAY,EAAE,OAAO,CAAA;IACrB,kFAAkF;IAClF,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,2BAA2B,EAAE,EAC9C,QAAQ,EAAE,wBAAwB,GAAG,IAAI,GAAG,SAAS,GACpD,8BAA8B,CAgChC;AAED,qHAAqH;AACrH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,2BAA2B,EAAE,EAC9C,QAAQ,EAAE,wBAAwB,GAAG,IAAI,GAAG,SAAS,kCAKtD;AAED,MAAM,WAAW,0BAA0B;IACzC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,SAAS,wBAAwB,EAAE,CAAA;IAC7C,2EAA2E;IAC3E,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;CAC3B;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,SAAS,2BAA2B,EAAE,GAC7C,0BAA0B,EAAE,CAc9B"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/** The capacity floor: a site may carry this many indexable location pages before its own clicks are counted. */
|
|
2
|
+
export const BRANDLAB_LOCATION_CAPACITY_FLOOR = 30;
|
|
3
|
+
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
4
|
+
function assertIsoDate(value, field) {
|
|
5
|
+
if (typeof value !== 'string' || !ISO_DATE.test(value) || Number.isNaN(Date.parse(value))) {
|
|
6
|
+
throw new Error(`${field} must be a YYYY-MM-DD date.`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function assertText(value, field) {
|
|
10
|
+
if (typeof value !== 'string' || !value.trim() || value.length > 500) {
|
|
11
|
+
throw new Error(`${field} needs a concise explanation (at most 500 characters).`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function assertCount(value, field) {
|
|
15
|
+
if (!Number.isInteger(value) || value < 0)
|
|
16
|
+
throw new Error(`${field} must be a whole number of pages.`);
|
|
17
|
+
}
|
|
18
|
+
/** The capacity for a quarter's clicks: the larger of 30 and the clicks. */
|
|
19
|
+
export function locationCapacityFromClicks(nonLocationClicks) {
|
|
20
|
+
if (!Number.isFinite(nonLocationClicks) || nonLocationClicks < 0) {
|
|
21
|
+
throw new Error('Clicks must be a number of clicks, zero or more.');
|
|
22
|
+
}
|
|
23
|
+
return Math.max(BRANDLAB_LOCATION_CAPACITY_FLOOR, Math.floor(nonLocationClicks));
|
|
24
|
+
}
|
|
25
|
+
/** Declares a site's recorded location capacity (`src/data/locations/indexing.ts`). */
|
|
26
|
+
export function defineLocationCapacity(definition) {
|
|
27
|
+
if (!definition || typeof definition !== 'object')
|
|
28
|
+
throw new Error('A location capacity is a record.');
|
|
29
|
+
assertCount(definition.limit, 'Location capacity limit');
|
|
30
|
+
if (definition.limit < BRANDLAB_LOCATION_CAPACITY_FLOOR) {
|
|
31
|
+
throw new Error(`Location capacity limit is at least ${BRANDLAB_LOCATION_CAPACITY_FLOOR}.`);
|
|
32
|
+
}
|
|
33
|
+
assertText(definition.basis, 'Location capacity basis');
|
|
34
|
+
assertIsoDate(definition.recordedAt, 'Location capacity recordedAt');
|
|
35
|
+
assertCount(definition.indexableAtRecord, 'Location capacity indexableAtRecord');
|
|
36
|
+
const approval = definition.approval;
|
|
37
|
+
if (approval !== undefined) {
|
|
38
|
+
assertText(approval.approvedBy, 'Location capacity approval approvedBy');
|
|
39
|
+
assertIsoDate(approval.approvedAt, 'Location capacity approval approvedAt');
|
|
40
|
+
assertText(approval.reason, 'Location capacity approval reason');
|
|
41
|
+
assertIsoDate(approval.reviewBy, 'Location capacity approval reviewBy');
|
|
42
|
+
if (approval.maxIndexable !== undefined)
|
|
43
|
+
assertCount(approval.maxIndexable, 'Location capacity approval maxIndexable');
|
|
44
|
+
}
|
|
45
|
+
return Object.freeze({ ...definition, ...(approval ? { approval: Object.freeze({ ...approval }) } : {}) });
|
|
46
|
+
}
|
|
47
|
+
const LOCATION_KINDS = new Set(['location', 'service-location']);
|
|
48
|
+
/** Whether a route is an indexable location page (suburb, region, council or service-in-suburb). */
|
|
49
|
+
export function isIndexableLocationRoute(route) {
|
|
50
|
+
return LOCATION_KINDS.has(route.kind ?? '') && route.indexing === 'index';
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Compares the catalogue's indexable location pages with the recorded capacity.
|
|
54
|
+
* `blocked` only when the catalogue holds more than both the limit and the pages
|
|
55
|
+
* the site had at record (or an approval's ceiling).
|
|
56
|
+
*/
|
|
57
|
+
export function checkLocationCapacity(routes, capacity) {
|
|
58
|
+
const indexable = routes.filter(isIndexableLocationRoute).length;
|
|
59
|
+
if (!capacity) {
|
|
60
|
+
return {
|
|
61
|
+
indexable,
|
|
62
|
+
limit: null,
|
|
63
|
+
allowed: null,
|
|
64
|
+
overCapacity: false,
|
|
65
|
+
blocked: false,
|
|
66
|
+
detail: `${indexable} indexable location page(s); no location capacity is recorded yet.`,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const approval = capacity.approval;
|
|
70
|
+
const allowed = approval
|
|
71
|
+
? approval.maxIndexable ?? Number.POSITIVE_INFINITY
|
|
72
|
+
: Math.max(capacity.limit, capacity.indexableAtRecord);
|
|
73
|
+
const overCapacity = indexable > capacity.limit;
|
|
74
|
+
const blocked = indexable > allowed;
|
|
75
|
+
const approved = approval ? ` under ${approval.approvedBy}'s approval of ${approval.approvedAt} (review by ${approval.reviewBy})` : '';
|
|
76
|
+
const detail = blocked
|
|
77
|
+
? `${indexable} indexable location page(s) exceed what the site may carry (${allowed}: capacity ${capacity.limit} recorded ${capacity.recordedAt} with ${capacity.indexableAtRecord} at record${approved}). Add pages only within capacity, or record Romie's approval.`
|
|
78
|
+
: overCapacity
|
|
79
|
+
? `${indexable} indexable location page(s) against a capacity of ${capacity.limit} (recorded ${capacity.recordedAt})${approved}; no pages may be added.`
|
|
80
|
+
: `${indexable} indexable location page(s) within a capacity of ${capacity.limit} (recorded ${capacity.recordedAt}).`;
|
|
81
|
+
return {
|
|
82
|
+
indexable,
|
|
83
|
+
limit: capacity.limit,
|
|
84
|
+
allowed: Number.isFinite(allowed) ? allowed : null,
|
|
85
|
+
overCapacity,
|
|
86
|
+
blocked,
|
|
87
|
+
detail,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** Throws when the catalogue adds indexable location pages beyond the recorded capacity (for a build-time guard). */
|
|
91
|
+
export function assertLocationCapacity(routes, capacity) {
|
|
92
|
+
const result = checkLocationCapacity(routes, capacity);
|
|
93
|
+
if (result.blocked)
|
|
94
|
+
throw new Error(result.detail);
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The site's location review list: indexable location pages with no qualifying
|
|
99
|
+
* evidence recorded, or with an open review flag. Sorted by path.
|
|
100
|
+
*/
|
|
101
|
+
export function buildLocationReviewList(routes) {
|
|
102
|
+
const items = [];
|
|
103
|
+
for (const route of routes) {
|
|
104
|
+
if (!isIndexableLocationRoute(route))
|
|
105
|
+
continue;
|
|
106
|
+
const evidence = route.locationDecision?.evidence ?? [];
|
|
107
|
+
const reasons = [];
|
|
108
|
+
if (evidence.length === 0) {
|
|
109
|
+
reasons.push('no qualifying evidence recorded (job, base suburb, facts and demand, existing clicks or enquiries, or an approved exception)');
|
|
110
|
+
}
|
|
111
|
+
const review = route.locationDecision?.review?.trim();
|
|
112
|
+
if (review)
|
|
113
|
+
reasons.push(review);
|
|
114
|
+
if (reasons.length > 0)
|
|
115
|
+
items.push({ ...(route.id ? { id: route.id } : {}), path: route.path, evidence, reasons });
|
|
116
|
+
}
|
|
117
|
+
return items.sort((a, b) => a.path.localeCompare(b.path));
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=location-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location-policy.js","sourceRoot":"","sources":["../src/location-policy.ts"],"names":[],"mappings":"AAiBA,iHAAiH;AACjH,MAAM,CAAC,MAAM,gCAAgC,GAAG,EAAE,CAAA;AA6BlD,MAAM,QAAQ,GAAG,qBAAqB,CAAA;AAEtC,SAAS,aAAa,CAAC,KAAc,EAAE,KAAa;IAClD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAC1F,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,6BAA6B,CAAC,CAAA;IACxD,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,KAAc,EAAE,KAAa;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QACrE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,wDAAwD,CAAC,CAAA;IACnF,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAc,EAAE,KAAa;IAChD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAK,KAAgB,GAAG,CAAC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UD;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAA8C;IAE9C,MAAM,KAAK,GAAiC,EAAE,CAAA;IAC9C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC;YAAE,SAAQ;QAC9C,MAAM,QAAQ,GAAG,KAAK,CAAC,gBAAgB,EAAE,QAAQ,IAAI,EAAE,CAAA;QACvD,MAAM,OAAO,GAAa,EAAE,CAAA;QAC5B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,8HAA8H,CAAC,CAAA;QAC9I,CAAC;QACD,MAAM,MAAM,GAAG,KAAK,CAAC,gBAAgB,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;QACrD,IAAI,MAAM;YAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAChC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAA;IACpH,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;AAC3D,CAAC","sourcesContent":["/**\n * The location index policy (3.4.0): how many indexable location pages a site\n * can carry, and which indexable pages go on its review list.\n *\n * - Capacity is a judgement-based starting limit: the larger of 30 and the\n * Australian, non-brand organic clicks the site's home, service and guide pages\n * earned in the last 90 days. The check fails only when a change takes the\n * indexable location pages above both the limit and the number the site had\n * when the capacity was recorded, so a release that adds none is never blocked.\n * - The review list names indexable location pages that record no qualifying\n * evidence, or carry an open review flag. Pages on it stay indexed; adding\n * evidence, merging or hiding a page is Romie's decision.\n *\n * Project pages are not location pages and never count towards capacity.\n */\nimport type { BrandlabLocationEvidence, BrandlabLocationRouteDecision } from './locations.js'\n\n/** The capacity floor: a site may carry this many indexable location pages before its own clicks are counted. */\nexport const BRANDLAB_LOCATION_CAPACITY_FLOOR = 30\n\nexport interface BrandlabLocationCapacityApproval {\n /** Who approved holding more pages than the limit (Romie). */\n approvedBy: string\n /** YYYY-MM-DD. */\n approvedAt: string\n reason: string\n /** YYYY-MM-DD: when the approval is reviewed. */\n reviewBy: string\n /** The most indexable location pages the approval allows; omitted means the estate as approved, with no ceiling. */\n maxIndexable?: number\n}\n\nexport interface BrandlabLocationCapacityDefinition {\n /** The capacity: at least 30 (see locationCapacityFromClicks). */\n limit: number\n /** Where the number comes from, for example the Search Console window and what it counted. */\n basis: string\n /** YYYY-MM-DD; recalculate each quarter. */\n recordedAt: string\n /** Indexable location pages when the capacity was recorded. A site above capacity keeps them, but adds none. */\n indexableAtRecord: number\n /** Romie's approval to hold more pages than the limit. */\n approval?: BrandlabLocationCapacityApproval\n}\n\nexport type BrandlabLocationCapacity = Readonly<BrandlabLocationCapacityDefinition>\n\nconst ISO_DATE = /^\\d{4}-\\d{2}-\\d{2}$/\n\nfunction assertIsoDate(value: unknown, field: string) {\n if (typeof value !== 'string' || !ISO_DATE.test(value) || Number.isNaN(Date.parse(value))) {\n throw new Error(`${field} must be a YYYY-MM-DD date.`)\n }\n}\n\nfunction assertText(value: unknown, field: string) {\n if (typeof value !== 'string' || !value.trim() || value.length > 500) {\n throw new Error(`${field} needs a concise explanation (at most 500 characters).`)\n }\n}\n\nfunction assertCount(value: unknown, field: string) {\n if (!Number.isInteger(value) || (value as number) < 0) throw new Error(`${field} must be a whole number of pages.`)\n}\n\n/** The capacity for a quarter's clicks: the larger of 30 and the clicks. */\nexport function locationCapacityFromClicks(nonLocationClicks: number): number {\n if (!Number.isFinite(nonLocationClicks) || nonLocationClicks < 0) {\n throw new Error('Clicks must be a number of clicks, zero or more.')\n }\n return Math.max(BRANDLAB_LOCATION_CAPACITY_FLOOR, Math.floor(nonLocationClicks))\n}\n\n/** Declares a site's recorded location capacity (`src/data/locations/indexing.ts`). */\nexport function defineLocationCapacity<const T extends BrandlabLocationCapacityDefinition>(definition: T): Readonly<T> {\n if (!definition || typeof definition !== 'object') throw new Error('A location capacity is a record.')\n assertCount(definition.limit, 'Location capacity limit')\n if (definition.limit < BRANDLAB_LOCATION_CAPACITY_FLOOR) {\n throw new Error(`Location capacity limit is at least ${BRANDLAB_LOCATION_CAPACITY_FLOOR}.`)\n }\n assertText(definition.basis, 'Location capacity basis')\n assertIsoDate(definition.recordedAt, 'Location capacity recordedAt')\n assertCount(definition.indexableAtRecord, 'Location capacity indexableAtRecord')\n const approval = definition.approval\n if (approval !== undefined) {\n assertText(approval.approvedBy, 'Location capacity approval approvedBy')\n assertIsoDate(approval.approvedAt, 'Location capacity approval approvedAt')\n assertText(approval.reason, 'Location capacity approval reason')\n assertIsoDate(approval.reviewBy, 'Location capacity approval reviewBy')\n if (approval.maxIndexable !== undefined) assertCount(approval.maxIndexable, 'Location capacity approval maxIndexable')\n }\n return Object.freeze({ ...definition, ...(approval ? { approval: Object.freeze({ ...approval }) } : {}) })\n}\n\n/** The parts of a route the policy reads; a route catalogue entry has them all. */\nexport interface BrandlabLocationPolicyRoute {\n id?: string\n path: string\n kind?: string\n indexing: string\n locationDecision?: BrandlabLocationRouteDecision\n}\n\nconst LOCATION_KINDS = new Set(['location', 'service-location'])\n\n/** Whether a route is an indexable location page (suburb, region, council or service-in-suburb). */\nexport function isIndexableLocationRoute(route: BrandlabLocationPolicyRoute): boolean {\n return LOCATION_KINDS.has(route.kind ?? '') && route.indexing === 'index'\n}\n\nexport interface BrandlabLocationCapacityResult {\n /** Indexable location pages in the catalogue. */\n indexable: number\n /** The recorded capacity, or null when the site has not recorded one. */\n limit: number | null\n /** The most pages the site may index without failing: the limit, the pages at record or the approval. */\n allowed: number | null\n overCapacity: boolean\n /** The catalogue adds indexable location pages beyond what the site may carry. */\n blocked: boolean\n detail: string\n}\n\n/**\n * Compares the catalogue's indexable location pages with the recorded capacity.\n * `blocked` only when the catalogue holds more than both the limit and the pages\n * the site had at record (or an approval's ceiling).\n */\nexport function checkLocationCapacity(\n routes: readonly BrandlabLocationPolicyRoute[],\n capacity: BrandlabLocationCapacity | null | undefined,\n): BrandlabLocationCapacityResult {\n const indexable = routes.filter(isIndexableLocationRoute).length\n if (!capacity) {\n return {\n indexable,\n limit: null,\n allowed: null,\n overCapacity: false,\n blocked: false,\n detail: `${indexable} indexable location page(s); no location capacity is recorded yet.`,\n }\n }\n const approval = capacity.approval\n const allowed = approval\n ? approval.maxIndexable ?? Number.POSITIVE_INFINITY\n : Math.max(capacity.limit, capacity.indexableAtRecord)\n const overCapacity = indexable > capacity.limit\n const blocked = indexable > allowed\n const approved = approval ? ` under ${approval.approvedBy}'s approval of ${approval.approvedAt} (review by ${approval.reviewBy})` : ''\n const detail = blocked\n ? `${indexable} indexable location page(s) exceed what the site may carry (${allowed}: capacity ${capacity.limit} recorded ${capacity.recordedAt} with ${capacity.indexableAtRecord} at record${approved}). Add pages only within capacity, or record Romie's approval.`\n : overCapacity\n ? `${indexable} indexable location page(s) against a capacity of ${capacity.limit} (recorded ${capacity.recordedAt})${approved}; no pages may be added.`\n : `${indexable} indexable location page(s) within a capacity of ${capacity.limit} (recorded ${capacity.recordedAt}).`\n return {\n indexable,\n limit: capacity.limit,\n allowed: Number.isFinite(allowed) ? allowed : null,\n overCapacity,\n blocked,\n detail,\n }\n}\n\n/** Throws when the catalogue adds indexable location pages beyond the recorded capacity (for a build-time guard). */\nexport function assertLocationCapacity(\n routes: readonly BrandlabLocationPolicyRoute[],\n capacity: BrandlabLocationCapacity | null | undefined,\n) {\n const result = checkLocationCapacity(routes, capacity)\n if (result.blocked) throw new Error(result.detail)\n return result\n}\n\nexport interface BrandlabLocationReviewItem {\n id?: string\n path: string\n evidence: readonly BrandlabLocationEvidence[]\n /** What the page is missing; it stays indexed until the review decides. */\n reasons: readonly string[]\n}\n\n/**\n * The site's location review list: indexable location pages with no qualifying\n * evidence recorded, or with an open review flag. Sorted by path.\n */\nexport function buildLocationReviewList(\n routes: readonly BrandlabLocationPolicyRoute[],\n): BrandlabLocationReviewItem[] {\n const items: BrandlabLocationReviewItem[] = []\n for (const route of routes) {\n if (!isIndexableLocationRoute(route)) continue\n const evidence = route.locationDecision?.evidence ?? []\n const reasons: string[] = []\n if (evidence.length === 0) {\n reasons.push('no qualifying evidence recorded (job, base suburb, facts and demand, existing clicks or enquiries, or an approved exception)')\n }\n const review = route.locationDecision?.review?.trim()\n if (review) reasons.push(review)\n if (reasons.length > 0) items.push({ ...(route.id ? { id: route.id } : {}), path: route.path, evidence, reasons })\n }\n return items.sort((a, b) => a.path.localeCompare(b.path))\n}\n"]}
|
package/dist/locations.d.ts
CHANGED
|
@@ -4,6 +4,19 @@
|
|
|
4
4
|
* Brandlab owns route correctness and shared geography. Projects own their
|
|
5
5
|
* content, evidence and publication decisions.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* What qualifies a location page under the Brandlab evidence standard (3.4.0):
|
|
9
|
+
*
|
|
10
|
+
* - `job`: a verified job in the place from the last three years, with a photo, date and the work done;
|
|
11
|
+
* - `base`: the business's base suburb;
|
|
12
|
+
* - `facts-and-demand`: two or more sourced decision facts that differ from its nearest siblings, plus demand evidence;
|
|
13
|
+
* - `existing-performance`: an existing page with 2 or more organic clicks in the last 12 months, or an organic enquiry;
|
|
14
|
+
* - `approved-exception`: an estate Romie keeps indexed outside the standard, named with a review date.
|
|
15
|
+
*
|
|
16
|
+
* A page without evidence stays indexed and goes on the site's review list; evidence never hides a page.
|
|
17
|
+
*/
|
|
18
|
+
export type BrandlabLocationEvidence = 'job' | 'base' | 'facts-and-demand' | 'existing-performance' | 'approved-exception';
|
|
19
|
+
export declare const BRANDLAB_LOCATION_EVIDENCE: readonly BrandlabLocationEvidence[];
|
|
7
20
|
/**
|
|
8
21
|
* The preferred location publication contract. A project owner explicitly
|
|
9
22
|
* decides whether a route is indexable after checking customer usefulness,
|
|
@@ -13,8 +26,58 @@ export interface BrandlabLocationRouteDecision {
|
|
|
13
26
|
indexing: 'index' | 'noindex-follow';
|
|
14
27
|
rationale: string;
|
|
15
28
|
reviewedAt?: string;
|
|
29
|
+
/** The evidence that qualifies the page (3.4.0); an indexable page without any is on the review list. */
|
|
30
|
+
evidence?: readonly BrandlabLocationEvidence[];
|
|
31
|
+
/** An open review flag (3.4.0): what the page is missing. The page keeps its indexing while it is reviewed. */
|
|
32
|
+
review?: string;
|
|
16
33
|
}
|
|
17
34
|
export declare function defineLocationRouteDecision<const T extends BrandlabLocationRouteDecision>(input: T): T;
|
|
35
|
+
/** A suburb's centre: a point inside it, in GDA2020 degrees (site-core/geography's nswSuburbCentres). */
|
|
36
|
+
export interface SuburbCentre {
|
|
37
|
+
latitude: number;
|
|
38
|
+
longitude: number;
|
|
39
|
+
}
|
|
40
|
+
/** Looks up a place's centre; undefined when the place has none (for example a region or a site-owned location). */
|
|
41
|
+
export type SuburbCentreLookup = (slug: string) => SuburbCentre | undefined;
|
|
42
|
+
/** Great-circle distance between two centres in kilometres. */
|
|
43
|
+
export declare function distanceBetweenCentresKm(from: SuburbCentre, to: SuburbCentre): number;
|
|
44
|
+
export interface RankedSuburb {
|
|
45
|
+
slug: string;
|
|
46
|
+
distanceKm: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Places ranked by distance from `origin`, nearest first (ties by slug), without
|
|
50
|
+
* the origin itself, repeats or places that have no centre. Empty when the
|
|
51
|
+
* origin has no centre.
|
|
52
|
+
*/
|
|
53
|
+
export declare function rankSuburbsByDistance(origin: string, candidates: readonly string[], centreOf: SuburbCentreLookup): RankedSuburb[];
|
|
54
|
+
/**
|
|
55
|
+
* The nearest served places to `origin` by distance between centres, for a
|
|
56
|
+
* suburb page's nearby block (4–6 is the standard). Pass only places with an
|
|
57
|
+
* indexable page, so the block never links a noindex page.
|
|
58
|
+
*/
|
|
59
|
+
export declare function nearestServedSuburbs(origin: string, served: readonly string[], options: {
|
|
60
|
+
centreOf: SuburbCentreLookup;
|
|
61
|
+
limit?: number;
|
|
62
|
+
}): string[];
|
|
63
|
+
/**
|
|
64
|
+
* An existing neighbour list ordered by distance from `origin`, keeping every
|
|
65
|
+
* member: places with a centre first, nearest first; places without one after
|
|
66
|
+
* them in their original order. Unchanged when the origin has no centre.
|
|
67
|
+
*/
|
|
68
|
+
export declare function sortSuburbsByDistance<T extends string>(origin: string, slugs: readonly T[], centreOf: SuburbCentreLookup): T[];
|
|
69
|
+
export interface NeighbourOrderProblem {
|
|
70
|
+
/** Position in the list of the first place that is nearer than the one before it. */
|
|
71
|
+
index: number;
|
|
72
|
+
slug: string;
|
|
73
|
+
previous: string;
|
|
74
|
+
detail: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Why a neighbour list is not ranked by distance from `origin`, or null when it
|
|
78
|
+
* is. Places without a centre are ignored; `toleranceKm` absorbs rounding.
|
|
79
|
+
*/
|
|
80
|
+
export declare function findNeighbourOrderProblem(origin: string, slugs: readonly string[], centreOf: SuburbCentreLookup, toleranceKm?: number): NeighbourOrderProblem | null;
|
|
18
81
|
export declare function resolveLocationRouteIndexing(decision: BrandlabLocationRouteDecision | null | undefined): 'index' | 'noindex-follow';
|
|
19
82
|
export interface RegistryRegion {
|
|
20
83
|
slug: string;
|
package/dist/locations.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locations.d.ts","sourceRoot":"","sources":["../src/locations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,EAAE,OAAO,GAAG,gBAAgB,CAAA;IACpC,SAAS,EAAE,MAAM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E,gCAAgC,GAC3C,2BAA2B,EAAE,CAoH/B;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,gCAAgC,GAC3C,sBAAsB,CAuCxB"}
|
package/dist/locations.js
CHANGED
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
* Brandlab owns route correctness and shared geography. Projects own their
|
|
5
5
|
* content, evidence and publication decisions.
|
|
6
6
|
*/
|
|
7
|
+
export const BRANDLAB_LOCATION_EVIDENCE = Object.freeze([
|
|
8
|
+
'job',
|
|
9
|
+
'base',
|
|
10
|
+
'facts-and-demand',
|
|
11
|
+
'existing-performance',
|
|
12
|
+
'approved-exception',
|
|
13
|
+
]);
|
|
7
14
|
export function defineLocationRouteDecision(input) {
|
|
8
15
|
if (input.indexing !== 'index' && input.indexing !== 'noindex-follow') {
|
|
9
16
|
throw new Error('Location route indexing must be "index" or "noindex-follow".');
|
|
@@ -14,8 +21,112 @@ export function defineLocationRouteDecision(input) {
|
|
|
14
21
|
if (input.reviewedAt && Number.isNaN(Date.parse(input.reviewedAt))) {
|
|
15
22
|
throw new Error('Location route decision reviewedAt must be a valid date.');
|
|
16
23
|
}
|
|
24
|
+
if (input.evidence !== undefined) {
|
|
25
|
+
if (!Array.isArray(input.evidence)) {
|
|
26
|
+
throw new Error('Location route decision evidence must be a list.');
|
|
27
|
+
}
|
|
28
|
+
const unknown = input.evidence.find((kind) => !BRANDLAB_LOCATION_EVIDENCE.includes(kind));
|
|
29
|
+
if (unknown !== undefined) {
|
|
30
|
+
throw new Error(`Location route decision evidence "${String(unknown)}" is not one of ${BRANDLAB_LOCATION_EVIDENCE.join(', ')}.`);
|
|
31
|
+
}
|
|
32
|
+
if (new Set(input.evidence).size !== input.evidence.length) {
|
|
33
|
+
throw new Error('Location route decision evidence lists a kind more than once.');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (input.review !== undefined && (typeof input.review !== 'string' || !input.review.trim())) {
|
|
37
|
+
throw new Error('Location route decision review must say what the page is missing.');
|
|
38
|
+
}
|
|
17
39
|
return input;
|
|
18
40
|
}
|
|
41
|
+
const EARTH_RADIUS_KM = 6371.0088;
|
|
42
|
+
/** Great-circle distance between two centres in kilometres. */
|
|
43
|
+
export function distanceBetweenCentresKm(from, to) {
|
|
44
|
+
const radians = (degrees) => (degrees * Math.PI) / 180;
|
|
45
|
+
const latitudeDelta = radians(to.latitude - from.latitude);
|
|
46
|
+
const longitudeDelta = radians(to.longitude - from.longitude);
|
|
47
|
+
const haversine = Math.sin(latitudeDelta / 2) ** 2 +
|
|
48
|
+
Math.cos(radians(from.latitude)) * Math.cos(radians(to.latitude)) * Math.sin(longitudeDelta / 2) ** 2;
|
|
49
|
+
return 2 * EARTH_RADIUS_KM * Math.asin(Math.min(1, Math.sqrt(haversine)));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Places ranked by distance from `origin`, nearest first (ties by slug), without
|
|
53
|
+
* the origin itself, repeats or places that have no centre. Empty when the
|
|
54
|
+
* origin has no centre.
|
|
55
|
+
*/
|
|
56
|
+
export function rankSuburbsByDistance(origin, candidates, centreOf) {
|
|
57
|
+
const from = centreOf(origin);
|
|
58
|
+
if (!from)
|
|
59
|
+
return [];
|
|
60
|
+
const seen = new Set([origin]);
|
|
61
|
+
const ranked = [];
|
|
62
|
+
for (const slug of candidates) {
|
|
63
|
+
if (seen.has(slug))
|
|
64
|
+
continue;
|
|
65
|
+
seen.add(slug);
|
|
66
|
+
const to = centreOf(slug);
|
|
67
|
+
if (to)
|
|
68
|
+
ranked.push({ slug, distanceKm: distanceBetweenCentresKm(from, to) });
|
|
69
|
+
}
|
|
70
|
+
return ranked.sort((a, b) => a.distanceKm - b.distanceKm || a.slug.localeCompare(b.slug));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The nearest served places to `origin` by distance between centres, for a
|
|
74
|
+
* suburb page's nearby block (4–6 is the standard). Pass only places with an
|
|
75
|
+
* indexable page, so the block never links a noindex page.
|
|
76
|
+
*/
|
|
77
|
+
export function nearestServedSuburbs(origin, served, options) {
|
|
78
|
+
const limit = options.limit ?? 6;
|
|
79
|
+
if (!Number.isInteger(limit) || limit < 1)
|
|
80
|
+
throw new Error('nearestServedSuburbs limit must be a positive integer.');
|
|
81
|
+
return rankSuburbsByDistance(origin, served, options.centreOf).slice(0, limit).map((entry) => entry.slug);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* An existing neighbour list ordered by distance from `origin`, keeping every
|
|
85
|
+
* member: places with a centre first, nearest first; places without one after
|
|
86
|
+
* them in their original order. Unchanged when the origin has no centre.
|
|
87
|
+
*/
|
|
88
|
+
export function sortSuburbsByDistance(origin, slugs, centreOf) {
|
|
89
|
+
const from = centreOf(origin);
|
|
90
|
+
if (!from)
|
|
91
|
+
return [...slugs];
|
|
92
|
+
const located = [];
|
|
93
|
+
const unlocated = [];
|
|
94
|
+
slugs.forEach((slug, index) => {
|
|
95
|
+
const to = centreOf(slug);
|
|
96
|
+
if (to)
|
|
97
|
+
located.push({ slug, distanceKm: distanceBetweenCentresKm(from, to), index });
|
|
98
|
+
else
|
|
99
|
+
unlocated.push(slug);
|
|
100
|
+
});
|
|
101
|
+
located.sort((a, b) => a.distanceKm - b.distanceKm || a.index - b.index);
|
|
102
|
+
return [...located.map((entry) => entry.slug), ...unlocated];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Why a neighbour list is not ranked by distance from `origin`, or null when it
|
|
106
|
+
* is. Places without a centre are ignored; `toleranceKm` absorbs rounding.
|
|
107
|
+
*/
|
|
108
|
+
export function findNeighbourOrderProblem(origin, slugs, centreOf, toleranceKm = 0.05) {
|
|
109
|
+
const from = centreOf(origin);
|
|
110
|
+
if (!from)
|
|
111
|
+
return null;
|
|
112
|
+
let previous;
|
|
113
|
+
for (const [index, slug] of slugs.entries()) {
|
|
114
|
+
const to = centreOf(slug);
|
|
115
|
+
if (!to)
|
|
116
|
+
continue;
|
|
117
|
+
const current = { slug, distanceKm: distanceBetweenCentresKm(from, to) };
|
|
118
|
+
if (previous && current.distanceKm + toleranceKm < previous.distanceKm) {
|
|
119
|
+
return {
|
|
120
|
+
index,
|
|
121
|
+
slug,
|
|
122
|
+
previous: previous.slug,
|
|
123
|
+
detail: `${slug} (${current.distanceKm.toFixed(1)} km) is listed after ${previous.slug} (${previous.distanceKm.toFixed(1)} km); nearby places are ranked nearest first`,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
previous = current;
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
19
130
|
export function resolveLocationRouteIndexing(decision) {
|
|
20
131
|
if (!decision) {
|
|
21
132
|
throw new Error('Location route decision is required.');
|