@brandlab-digital/site-core 3.6.0 → 3.8.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 +48 -0
- package/dist/business.d.ts +59 -0
- package/dist/business.d.ts.map +1 -1
- package/dist/business.js +120 -4
- package/dist/business.js.map +1 -1
- package/dist/google-business-reviews.d.ts +38 -2
- package/dist/google-business-reviews.d.ts.map +1 -1
- package/dist/google-business-reviews.js +85 -4
- package/dist/google-business-reviews.js.map +1 -1
- package/dist/navigation.d.ts +65 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +10 -0
- package/dist/navigation.js.map +1 -0
- package/dist/project.d.ts +21 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +57 -0
- package/dist/project.js.map +1 -1
- package/dist/strategy.d.ts +74 -0
- package/dist/strategy.d.ts.map +1 -0
- package/dist/strategy.js +100 -0
- package/dist/strategy.js.map +1 -0
- package/package.json +9 -1
|
@@ -26,10 +26,35 @@ export interface BusinessProfileReviews {
|
|
|
26
26
|
}
|
|
27
27
|
/** Which reviews a page shows: the newest of all, or the newest five-star ones. */
|
|
28
28
|
export type BusinessProfileReviewsPolicy = 'recent' | 'five-star';
|
|
29
|
+
/**
|
|
30
|
+
* A review a site would rather not feature (3.7.0), such as one written by a relative of the owner or of Brandlab.
|
|
31
|
+
* Name exactly one of `reviewId` (that one review, matched exactly) or `authorName` (every review by that name,
|
|
32
|
+
* ignoring case and spacing), and always the `reason`, so the next person knows who decided and why. The list lives
|
|
33
|
+
* in the site's `src/config/reviews.ts` (`reviews.exclude`), never in brandlab.config.
|
|
34
|
+
*/
|
|
35
|
+
export type BusinessProfileReviewExclusion = {
|
|
36
|
+
reviewId: string;
|
|
37
|
+
authorName?: never;
|
|
38
|
+
reason: string;
|
|
39
|
+
} | {
|
|
40
|
+
authorName: string;
|
|
41
|
+
reviewId?: never;
|
|
42
|
+
reason: string;
|
|
43
|
+
};
|
|
29
44
|
export interface SelectBusinessProfileReviewsOptions {
|
|
30
45
|
policy: BusinessProfileReviewsPolicy;
|
|
31
46
|
/** How many reviews to show at most: a whole number, 1 or more. */
|
|
32
47
|
limit: number;
|
|
48
|
+
/**
|
|
49
|
+
* Reviews to leave out while enough others remain to fill `limit` (3.7.0). When too few others remain, the fewest
|
|
50
|
+
* excluded reviews needed to fill it stay, newest first, so a page never shows fewer reviews because of the list.
|
|
51
|
+
*/
|
|
52
|
+
exclude?: readonly BusinessProfileReviewExclusion[];
|
|
53
|
+
}
|
|
54
|
+
/** A review that was shown although it matches an exclusion, with the first exclusion it matches. */
|
|
55
|
+
export interface ExcludedBusinessProfileReviewShown {
|
|
56
|
+
review: BusinessProfileReview;
|
|
57
|
+
exclusion: BusinessProfileReviewExclusion;
|
|
33
58
|
}
|
|
34
59
|
/**
|
|
35
60
|
* Validates a reviews feed response. Returns null for anything but an available response
|
|
@@ -40,8 +65,19 @@ export interface SelectBusinessProfileReviewsOptions {
|
|
|
40
65
|
*/
|
|
41
66
|
export declare function parseBusinessProfileReviews(value: unknown): BusinessProfileReviews | null;
|
|
42
67
|
/**
|
|
43
|
-
* The reviews a page shows, newest first and word for word: every review (`recent`) or
|
|
44
|
-
*
|
|
68
|
+
* The reviews a page shows, newest first and word for word: every review (`recent`) or only the five-star ones
|
|
69
|
+
* (`five-star`), at most `limit`. No feed gives no reviews.
|
|
70
|
+
*
|
|
71
|
+
* `exclude` (3.7.0) leaves out the reviews it names only while enough other reviews remain to fill `limit`; otherwise
|
|
72
|
+
* the fewest excluded reviews needed to fill it stay (the newest of them), so the page shows as many reviews as it
|
|
73
|
+
* would without the list, all in the policy's order. A kept review was already among those shown without the list.
|
|
74
|
+
* The profile's own average and total are Google's and never change. `excludedBusinessProfileReviewsShown` names
|
|
75
|
+
* any excluded review that stayed.
|
|
45
76
|
*/
|
|
46
77
|
export declare function selectBusinessProfileReviews(feed: BusinessProfileReviews | null | undefined, options: SelectBusinessProfileReviewsOptions): BusinessProfileReview[];
|
|
78
|
+
/**
|
|
79
|
+
* The shown reviews that match an exclusion, each with the first exclusion it matches: empty unless the guard in
|
|
80
|
+
* `selectBusinessProfileReviews` kept an excluded review because too few others remained. Sites can log it or test it.
|
|
81
|
+
*/
|
|
82
|
+
export declare function excludedBusinessProfileReviewsShown(shown: readonly BusinessProfileReview[], exclude: readonly BusinessProfileReviewExclusion[] | undefined): ExcludedBusinessProfileReviewShown[];
|
|
47
83
|
//# sourceMappingURL=google-business-reviews.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-business-reviews.d.ts","sourceRoot":"","sources":["../src/google-business-reviews.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,+DAA+D;IAC/D,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,MAAM,CAAA;IACrB,+CAA+C;IAC/C,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,qEAAqE;IACrE,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,OAAO,EAAE,qBAAqB,EAAE,CAAA;CACjC;AAED,mFAAmF;AACnF,MAAM,MAAM,4BAA4B,GAAG,QAAQ,GAAG,WAAW,CAAA;AAEjE,MAAM,WAAW,mCAAmC;IAClD,MAAM,EAAE,4BAA4B,CAAA;IACpC,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"google-business-reviews.d.ts","sourceRoot":"","sources":["../src/google-business-reviews.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,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ASG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,sBAAsB,GAAG,IAAI,GAAG,SAAS,EAC/C,OAAO,EAAE,mCAAmC,GAC3C,qBAAqB,EAAE,CA8BzB;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,CACjD,KAAK,EAAE,SAAS,qBAAqB,EAAE,EACvC,OAAO,EAAE,SAAS,8BAA8B,EAAE,GAAG,SAAS,GAC7D,kCAAkC,EAAE,CAMtC"}
|
|
@@ -70,9 +70,61 @@ export function parseBusinessProfileReviews(value) {
|
|
|
70
70
|
.filter((review) => review !== null),
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
+
const EXCLUSION_KEYS = new Set(['reviewId', 'authorName', 'reason']);
|
|
74
|
+
function isNonEmptyString(value) {
|
|
75
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
76
|
+
}
|
|
77
|
+
/** Case, spacing and Unicode composition do not tell two author names apart. */
|
|
78
|
+
function normaliseAuthorName(name) {
|
|
79
|
+
return name.normalize('NFC').replace(/\s+/g, ' ').trim().toLowerCase();
|
|
80
|
+
}
|
|
81
|
+
function assertExclusions(exclude) {
|
|
82
|
+
if (exclude === undefined)
|
|
83
|
+
return [];
|
|
84
|
+
if (!Array.isArray(exclude)) {
|
|
85
|
+
throw new Error('Business Profile reviews exclude must be a list.');
|
|
86
|
+
}
|
|
87
|
+
exclude.forEach((entry, index) => {
|
|
88
|
+
const field = `Business Profile reviews exclude[${index}]`;
|
|
89
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
90
|
+
throw new Error(`${field} must be an object with reviewId or authorName and a reason.`);
|
|
91
|
+
}
|
|
92
|
+
const record = entry;
|
|
93
|
+
const unknown = Object.keys(record).find((key) => !EXCLUSION_KEYS.has(key));
|
|
94
|
+
if (unknown)
|
|
95
|
+
throw new Error(`${field} has an unknown field: ${unknown}.`);
|
|
96
|
+
const hasId = record.reviewId !== undefined;
|
|
97
|
+
const hasName = record.authorName !== undefined;
|
|
98
|
+
if (hasId === hasName) {
|
|
99
|
+
throw new Error(`${field} must name exactly one of reviewId or authorName.`);
|
|
100
|
+
}
|
|
101
|
+
if (hasId && !isNonEmptyString(record.reviewId))
|
|
102
|
+
throw new Error(`${field}.reviewId must be a non-empty string.`);
|
|
103
|
+
if (hasName && !isNonEmptyString(record.authorName))
|
|
104
|
+
throw new Error(`${field}.authorName must be a non-empty string.`);
|
|
105
|
+
if (!isNonEmptyString(record.reason)) {
|
|
106
|
+
throw new Error(`${field}.reason is required: say who decided to exclude it and why.`);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
return exclude;
|
|
110
|
+
}
|
|
111
|
+
function findExclusion(review, exclude) {
|
|
112
|
+
if (exclude.length === 0)
|
|
113
|
+
return undefined;
|
|
114
|
+
const author = normaliseAuthorName(review.authorName);
|
|
115
|
+
return exclude.find((entry) => entry.reviewId !== undefined
|
|
116
|
+
? entry.reviewId === review.id
|
|
117
|
+
: normaliseAuthorName(entry.authorName) === author);
|
|
118
|
+
}
|
|
73
119
|
/**
|
|
74
|
-
* The reviews a page shows, newest first and word for word: every review (`recent`) or
|
|
75
|
-
*
|
|
120
|
+
* The reviews a page shows, newest first and word for word: every review (`recent`) or only the five-star ones
|
|
121
|
+
* (`five-star`), at most `limit`. No feed gives no reviews.
|
|
122
|
+
*
|
|
123
|
+
* `exclude` (3.7.0) leaves out the reviews it names only while enough other reviews remain to fill `limit`; otherwise
|
|
124
|
+
* the fewest excluded reviews needed to fill it stay (the newest of them), so the page shows as many reviews as it
|
|
125
|
+
* would without the list, all in the policy's order. A kept review was already among those shown without the list.
|
|
126
|
+
* The profile's own average and total are Google's and never change. `excludedBusinessProfileReviewsShown` names
|
|
127
|
+
* any excluded review that stayed.
|
|
76
128
|
*/
|
|
77
129
|
export function selectBusinessProfileReviews(feed, options) {
|
|
78
130
|
if (!POLICIES.has(options.policy)) {
|
|
@@ -81,13 +133,42 @@ export function selectBusinessProfileReviews(feed, options) {
|
|
|
81
133
|
if (!Number.isInteger(options.limit) || options.limit < 1) {
|
|
82
134
|
throw new Error('Business Profile reviews limit must be a whole number of 1 or more.');
|
|
83
135
|
}
|
|
136
|
+
const exclude = assertExclusions(options.exclude);
|
|
84
137
|
if (!feed)
|
|
85
138
|
return [];
|
|
86
|
-
|
|
139
|
+
const ordered = feed.reviews
|
|
87
140
|
.filter((review) => options.policy === 'recent' || review.rating === 5)
|
|
88
141
|
.map((review, index) => ({ review, index, time: Date.parse(review.createTime) }))
|
|
89
142
|
.sort((a, b) => b.time - a.time || a.index - b.index)
|
|
90
|
-
.slice(0, options.limit)
|
|
91
143
|
.map(({ review }) => review);
|
|
144
|
+
if (exclude.length === 0)
|
|
145
|
+
return ordered.slice(0, options.limit);
|
|
146
|
+
const fill = Math.min(options.limit, ordered.length);
|
|
147
|
+
const excluded = new Set(ordered.filter((review) => findExclusion(review, exclude) !== undefined));
|
|
148
|
+
let keepExcluded = Math.max(0, fill - (ordered.length - excluded.size));
|
|
149
|
+
const shown = [];
|
|
150
|
+
for (const review of ordered) {
|
|
151
|
+
if (shown.length === fill)
|
|
152
|
+
break;
|
|
153
|
+
if (!excluded.has(review)) {
|
|
154
|
+
shown.push(review);
|
|
155
|
+
}
|
|
156
|
+
else if (keepExcluded > 0) {
|
|
157
|
+
shown.push(review);
|
|
158
|
+
keepExcluded -= 1;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return shown;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The shown reviews that match an exclusion, each with the first exclusion it matches: empty unless the guard in
|
|
165
|
+
* `selectBusinessProfileReviews` kept an excluded review because too few others remained. Sites can log it or test it.
|
|
166
|
+
*/
|
|
167
|
+
export function excludedBusinessProfileReviewsShown(shown, exclude) {
|
|
168
|
+
const entries = assertExclusions(exclude);
|
|
169
|
+
return shown.flatMap((review) => {
|
|
170
|
+
const exclusion = findExclusion(review, entries);
|
|
171
|
+
return exclusion ? [{ review, exclusion }] : [];
|
|
172
|
+
});
|
|
92
173
|
}
|
|
93
174
|
//# sourceMappingURL=google-business-reviews.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-business-reviews.js","sourceRoot":"","sources":["../src/google-business-reviews.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA+BH,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAA+B,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAA;AAEpG,SAAS,UAAU,CAAC,KAAc,EAAE,IAAoC;IACtE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;QAC1B,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACnE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IACpD,MAAM,MAAM,GAAG,KAAgC,CAAA;IAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;IAC5B,IACE,OAAO,MAAM,CAAC,EAAE,KAAK,QAAQ;QAC7B,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ;QACrC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE;QACzB,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;QAC/B,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;QACnB,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ;QACrC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC3C,CAAC,MAAM,KA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C,EAAE,CAAC,CAAC;SAChF,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;SACpD,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC;SACvB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAA;AAChC,CAAC","sourcesContent":["/**\n * Google reviews from the Business Profile API, as the Brandlab reviews feed serves them\n * (`{ status: 'available', source: 'google-business-profile', fetchedAt, googleMapsUri,\n * averageRating?, totalReviewCount?, reviews }`). Anything the feed sends that does not\n * match is treated as unavailable (the whole response) or dropped (one review), so a page\n * never shows a review it cannot vouch for. The fetch itself lives in\n * `site-next/google-business-reviews/server`.\n */\n\nexport interface BusinessProfileReview {\n id: string\n authorName: string\n /** Only an https image on a `*.googleusercontent.com` host. */\n authorPhotoUrl?: string\n rating: 1 | 2 | 3 | 4 | 5\n text: string\n /** The time Google records for the review, as the feed sent it. */\n createTime: string\n}\n\nexport interface BusinessProfileReviews {\n googleMapsUri: string\n /** Between 1 and 5 when Google supplies it. */\n averageRating?: number\n /** A whole number of reviews, 0 or more, when Google supplies it. */\n totalReviewCount?: number\n reviews: BusinessProfileReview[]\n}\n\n/** Which reviews a page shows: the newest of all, or the newest five-star ones. */\nexport type BusinessProfileReviewsPolicy = 'recent' | 'five-star'\n\nexport interface SelectBusinessProfileReviewsOptions {\n policy: BusinessProfileReviewsPolicy\n /** How many reviews to show at most: a whole number, 1 or more. */\n limit: number\n}\n\nconst POLICIES: ReadonlySet<string> = new Set<BusinessProfileReviewsPolicy>(['recent', 'five-star'])\n\nfunction isHttpsUrl(value: unknown, host?: (hostname: string) => boolean): value is string {\n if (typeof value !== 'string') return false\n try {\n const url = new URL(value)\n return url.protocol === 'https:' && (!host || host(url.hostname))\n } catch {\n return false\n }\n}\n\nfunction parseReview(value: unknown): BusinessProfileReview | null {\n if (!value || typeof value !== 'object') return null\n const record = value as Record<string, unknown>\n const rating = record.rating\n if (\n typeof record.id !== 'string' ||\n typeof record.authorName !== 'string' ||\n !record.authorName.trim() ||\n typeof record.text !== 'string' ||\n !record.text.trim() ||\n typeof record.createTime !== 'string' ||\n Number.isNaN(Date.parse(record.createTime)) ||\n (rating !== 1 && rating !== 2 && rating !== 3 && rating !== 4 && rating !== 5)\n ) {\n return null\n }\n const photo = isHttpsUrl(record.authorPhotoUrl, (host) => host.endsWith('.googleusercontent.com'))\n ? record.authorPhotoUrl\n : undefined\n return {\n id: record.id,\n authorName: record.authorName.trim(),\n ...(photo ? { authorPhotoUrl: photo } : {}),\n rating,\n text: record.text.trim(),\n createTime: record.createTime,\n }\n}\n\n/**\n * Validates a reviews feed response. Returns null for anything but an available response\n * with an https Google Maps link and a review list; drops each review that is not complete\n * (id, author, text, a valid time and a whole-star rating from 1 to 5). An author photo\n * outside `*.googleusercontent.com`, an average outside 1 to 5 and a total that is not a\n * whole number of 0 or more are left out.\n */\nexport function parseBusinessProfileReviews(value: unknown): BusinessProfileReviews | null {\n if (!value || typeof value !== 'object') return null\n const record = value as Record<string, unknown>\n if (record.status !== 'available' || !isHttpsUrl(record.googleMapsUri) || !Array.isArray(record.reviews)) {\n return null\n }\n const average = record.averageRating\n const total = record.totalReviewCount\n return {\n googleMapsUri: record.googleMapsUri,\n ...(typeof average === 'number' && average >= 1 && average <= 5 ? { averageRating: average } : {}),\n ...(typeof total === 'number' && Number.isInteger(total) && total >= 0 ? { totalReviewCount: total } : {}),\n reviews: record.reviews\n .map(parseReview)\n .filter((review): review is BusinessProfileReview => review !== null),\n }\n}\n\n/**\n * The reviews a page shows, newest first and word for word: every review (`recent`) or\n * only the five-star ones (`five-star`), at most `limit`. No feed gives no reviews.\n */\nexport function selectBusinessProfileReviews(\n feed: BusinessProfileReviews | null | undefined,\n options: SelectBusinessProfileReviewsOptions,\n): BusinessProfileReview[] {\n if (!POLICIES.has(options.policy)) {\n throw new Error('Business Profile reviews policy must be recent or five-star.')\n }\n if (!Number.isInteger(options.limit) || options.limit < 1) {\n throw new Error('Business Profile reviews limit must be a whole number of 1 or more.')\n }\n if (!feed) return []\n return feed.reviews\n .filter((review) => options.policy === 'recent' || review.rating === 5)\n .map((review, index) => ({ review, index, time: Date.parse(review.createTime) }))\n .sort((a, b) => b.time - a.time || a.index - b.index)\n .slice(0, options.limit)\n .map(({ review }) => review)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"google-business-reviews.js","sourceRoot":"","sources":["../src/google-business-reviews.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAoDH,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAA+B,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAA;AAEpG,SAAS,UAAU,CAAC,KAAc,EAAE,IAAoC;IACtE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;QAC1B,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACnE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IACpD,MAAM,MAAM,GAAG,KAAgC,CAAA;IAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;IAC5B,IACE,OAAO,MAAM,CAAC,EAAE,KAAK,QAAQ;QAC7B,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ;QACrC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE;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AE,CAAC;YAC1B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACpB,CAAC;aAAM,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YAC5B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YAClB,YAAY,IAAI,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mCAAmC,CACjD,KAAuC,EACvC,OAA8D;IAE9D,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAA;IACzC,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QAC9B,MAAM,SAAS,GAAG,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAChD,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACjD,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["/**\n * Google reviews from the Business Profile API, as the Brandlab reviews feed serves them\n * (`{ status: 'available', source: 'google-business-profile', fetchedAt, googleMapsUri,\n * averageRating?, totalReviewCount?, reviews }`). Anything the feed sends that does not\n * match is treated as unavailable (the whole response) or dropped (one review), so a page\n * never shows a review it cannot vouch for. The fetch itself lives in\n * `site-next/google-business-reviews/server`.\n */\n\nexport interface BusinessProfileReview {\n id: string\n authorName: string\n /** Only an https image on a `*.googleusercontent.com` host. */\n authorPhotoUrl?: string\n rating: 1 | 2 | 3 | 4 | 5\n text: string\n /** The time Google records for the review, as the feed sent it. */\n createTime: string\n}\n\nexport interface BusinessProfileReviews {\n googleMapsUri: string\n /** Between 1 and 5 when Google supplies it. */\n averageRating?: number\n /** A whole number of reviews, 0 or more, when Google supplies it. */\n totalReviewCount?: number\n reviews: BusinessProfileReview[]\n}\n\n/** Which reviews a page shows: the newest of all, or the newest five-star ones. */\nexport type BusinessProfileReviewsPolicy = 'recent' | 'five-star'\n\n/**\n * A review a site would rather not feature (3.7.0), such as one written by a relative of the owner or of Brandlab.\n * Name exactly one of `reviewId` (that one review, matched exactly) or `authorName` (every review by that name,\n * ignoring case and spacing), and always the `reason`, so the next person knows who decided and why. The list lives\n * in the site's `src/config/reviews.ts` (`reviews.exclude`), never in brandlab.config.\n */\nexport type BusinessProfileReviewExclusion =\n | { reviewId: string; authorName?: never; reason: string }\n | { authorName: string; reviewId?: never; reason: string }\n\nexport interface SelectBusinessProfileReviewsOptions {\n policy: BusinessProfileReviewsPolicy\n /** How many reviews to show at most: a whole number, 1 or more. */\n limit: number\n /**\n * Reviews to leave out while enough others remain to fill `limit` (3.7.0). When too few others remain, the fewest\n * excluded reviews needed to fill it stay, newest first, so a page never shows fewer reviews because of the list.\n */\n exclude?: readonly BusinessProfileReviewExclusion[]\n}\n\n/** A review that was shown although it matches an exclusion, with the first exclusion it matches. */\nexport interface ExcludedBusinessProfileReviewShown {\n review: BusinessProfileReview\n exclusion: BusinessProfileReviewExclusion\n}\n\nconst POLICIES: ReadonlySet<string> = new Set<BusinessProfileReviewsPolicy>(['recent', 'five-star'])\n\nfunction isHttpsUrl(value: unknown, host?: (hostname: string) => boolean): value is string {\n if (typeof value !== 'string') return false\n try {\n const url = new URL(value)\n return url.protocol === 'https:' && (!host || host(url.hostname))\n } catch {\n return false\n }\n}\n\nfunction parseReview(value: unknown): BusinessProfileReview | null {\n if (!value || typeof value !== 'object') return null\n const record = value as Record<string, unknown>\n const rating = record.rating\n if (\n typeof record.id !== 'string' ||\n typeof record.authorName !== 'string' ||\n !record.authorName.trim() ||\n typeof record.text !== 'string' ||\n !record.text.trim() ||\n typeof record.createTime !== 'string' ||\n Number.isNaN(Date.parse(record.createTime)) ||\n (rating !== 1 && rating !== 2 && rating !== 3 && rating !== 4 && rating !== 5)\n ) {\n return null\n }\n const photo = isHttpsUrl(record.authorPhotoUrl, (host) => host.endsWith('.googleusercontent.com'))\n ? record.authorPhotoUrl\n : undefined\n return {\n id: record.id,\n authorName: record.authorName.trim(),\n ...(photo ? { authorPhotoUrl: photo } : {}),\n rating,\n text: record.text.trim(),\n createTime: record.createTime,\n }\n}\n\n/**\n * Validates a reviews feed response. Returns null for anything but an available response\n * with an https Google Maps link and a review list; drops each review that is not complete\n * (id, author, text, a valid time and a whole-star rating from 1 to 5). An author photo\n * outside `*.googleusercontent.com`, an average outside 1 to 5 and a total that is not a\n * whole number of 0 or more are left out.\n */\nexport function parseBusinessProfileReviews(value: unknown): BusinessProfileReviews | null {\n if (!value || typeof value !== 'object') return null\n const record = value as Record<string, unknown>\n if (record.status !== 'available' || !isHttpsUrl(record.googleMapsUri) || !Array.isArray(record.reviews)) {\n return null\n }\n const average = record.averageRating\n const total = record.totalReviewCount\n return {\n googleMapsUri: record.googleMapsUri,\n ...(typeof average === 'number' && average >= 1 && average <= 5 ? { averageRating: average } : {}),\n ...(typeof total === 'number' && Number.isInteger(total) && total >= 0 ? { totalReviewCount: total } : {}),\n reviews: record.reviews\n .map(parseReview)\n .filter((review): review is BusinessProfileReview => review !== null),\n }\n}\n\nconst EXCLUSION_KEYS: ReadonlySet<string> = new Set(['reviewId', 'authorName', 'reason'])\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value.trim().length > 0\n}\n\n/** Case, spacing and Unicode composition do not tell two author names apart. */\nfunction normaliseAuthorName(name: string): string {\n return name.normalize('NFC').replace(/\\s+/g, ' ').trim().toLowerCase()\n}\n\nfunction assertExclusions(exclude: unknown): readonly BusinessProfileReviewExclusion[] {\n if (exclude === undefined) return []\n if (!Array.isArray(exclude)) {\n throw new Error('Business Profile reviews exclude must be a list.')\n }\n exclude.forEach((entry: unknown, index) => {\n const field = `Business Profile reviews exclude[${index}]`\n if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {\n throw new Error(`${field} must be an object with reviewId or authorName and a reason.`)\n }\n const record = entry as Record<string, unknown>\n const unknown = Object.keys(record).find((key) => !EXCLUSION_KEYS.has(key))\n if (unknown) throw new Error(`${field} has an unknown field: ${unknown}.`)\n const hasId = record.reviewId !== undefined\n const hasName = record.authorName !== undefined\n if (hasId === hasName) {\n throw new Error(`${field} must name exactly one of reviewId or authorName.`)\n }\n if (hasId && !isNonEmptyString(record.reviewId)) throw new Error(`${field}.reviewId must be a non-empty string.`)\n if (hasName && !isNonEmptyString(record.authorName)) throw new Error(`${field}.authorName must be a non-empty string.`)\n if (!isNonEmptyString(record.reason)) {\n throw new Error(`${field}.reason is required: say who decided to exclude it and why.`)\n }\n })\n return exclude as readonly BusinessProfileReviewExclusion[]\n}\n\nfunction findExclusion(\n review: BusinessProfileReview,\n exclude: readonly BusinessProfileReviewExclusion[],\n): BusinessProfileReviewExclusion | undefined {\n if (exclude.length === 0) return undefined\n const author = normaliseAuthorName(review.authorName)\n return exclude.find((entry) =>\n entry.reviewId !== undefined\n ? entry.reviewId === review.id\n : normaliseAuthorName(entry.authorName) === author,\n )\n}\n\n/**\n * The reviews a page shows, newest first and word for word: every review (`recent`) or only the five-star ones\n * (`five-star`), at most `limit`. No feed gives no reviews.\n *\n * `exclude` (3.7.0) leaves out the reviews it names only while enough other reviews remain to fill `limit`; otherwise\n * the fewest excluded reviews needed to fill it stay (the newest of them), so the page shows as many reviews as it\n * would without the list, all in the policy's order. A kept review was already among those shown without the list.\n * The profile's own average and total are Google's and never change. `excludedBusinessProfileReviewsShown` names\n * any excluded review that stayed.\n */\nexport function selectBusinessProfileReviews(\n feed: BusinessProfileReviews | null | undefined,\n options: SelectBusinessProfileReviewsOptions,\n): BusinessProfileReview[] {\n if (!POLICIES.has(options.policy)) {\n throw new Error('Business Profile reviews policy must be recent or five-star.')\n }\n if (!Number.isInteger(options.limit) || options.limit < 1) {\n throw new Error('Business Profile reviews limit must be a whole number of 1 or more.')\n }\n const exclude = assertExclusions(options.exclude)\n if (!feed) return []\n const ordered = feed.reviews\n .filter((review) => options.policy === 'recent' || review.rating === 5)\n .map((review, index) => ({ review, index, time: Date.parse(review.createTime) }))\n .sort((a, b) => b.time - a.time || a.index - b.index)\n .map(({ review }) => review)\n if (exclude.length === 0) return ordered.slice(0, options.limit)\n\n const fill = Math.min(options.limit, ordered.length)\n const excluded = new Set(ordered.filter((review) => findExclusion(review, exclude) !== undefined))\n let keepExcluded = Math.max(0, fill - (ordered.length - excluded.size))\n const shown: BusinessProfileReview[] = []\n for (const review of ordered) {\n if (shown.length === fill) break\n if (!excluded.has(review)) {\n shown.push(review)\n } else if (keepExcluded > 0) {\n shown.push(review)\n keepExcluded -= 1\n }\n }\n return shown\n}\n\n/**\n * The shown reviews that match an exclusion, each with the first exclusion it matches: empty unless the guard in\n * `selectBusinessProfileReviews` kept an excluded review because too few others remained. Sites can log it or test it.\n */\nexport function excludedBusinessProfileReviewsShown(\n shown: readonly BusinessProfileReview[],\n exclude: readonly BusinessProfileReviewExclusion[] | undefined,\n): ExcludedBusinessProfileReviewShown[] {\n const entries = assertExclusions(exclude)\n return shown.flatMap((review) => {\n const exclusion = findExclusion(review, entries)\n return exclusion ? [{ review, exclusion }] : []\n })\n}\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The navigation model (F1). One menu per site, built from data: the header, the drawer and the checks all read it.
|
|
3
|
+
* A `menu` item is a real link to its hub plus a separate disclosure button (the WAI-ARIA disclosure navigation
|
|
4
|
+
* pattern); its panel always repeats the hub link first. Prices never appear in menus.
|
|
5
|
+
*
|
|
6
|
+
* `defineBrandlabNavigation` (3.9.0) builds this model from the route catalogue, places, services and
|
|
7
|
+
* `strategy.navigation`, and enforces the N1 rules. The types below are the contract the ui-kit header renders.
|
|
8
|
+
*/
|
|
9
|
+
export interface BrandlabNavLink {
|
|
10
|
+
readonly label: string;
|
|
11
|
+
readonly href: string;
|
|
12
|
+
/** A short line under the label in wide panels. Never a price. */
|
|
13
|
+
readonly description?: string;
|
|
14
|
+
}
|
|
15
|
+
/** One money-service card with its photo, for the `featured` panel. */
|
|
16
|
+
export interface BrandlabNavFeatured {
|
|
17
|
+
readonly label: string;
|
|
18
|
+
readonly href: string;
|
|
19
|
+
readonly description: string;
|
|
20
|
+
readonly image: {
|
|
21
|
+
readonly src: string;
|
|
22
|
+
readonly alt: string;
|
|
23
|
+
readonly width: number;
|
|
24
|
+
readonly height: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** A titled group of links inside a `columns` panel (from the services catalogue's `serviceGroups`). */
|
|
28
|
+
export interface BrandlabNavGroup {
|
|
29
|
+
readonly heading: string;
|
|
30
|
+
readonly links: readonly BrandlabNavLink[];
|
|
31
|
+
}
|
|
32
|
+
export declare const BRANDLAB_NAV_PANELS: readonly ["list", "columns", "featured"];
|
|
33
|
+
export type BrandlabNavPanel = (typeof BRANDLAB_NAV_PANELS)[number];
|
|
34
|
+
export interface BrandlabNavLinkItem {
|
|
35
|
+
readonly kind: 'link';
|
|
36
|
+
/** Stable slug used for element ids. */
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly label: string;
|
|
39
|
+
readonly href: string;
|
|
40
|
+
/** Other paths that mark this item as the current section. */
|
|
41
|
+
readonly activePaths?: readonly string[];
|
|
42
|
+
}
|
|
43
|
+
export interface BrandlabNavMenuItem {
|
|
44
|
+
readonly kind: 'menu';
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly label: string;
|
|
47
|
+
/** The hub: the top-level label links here, and the panel's first link repeats it. */
|
|
48
|
+
readonly href: string;
|
|
49
|
+
/** The panel's first link, for example "All services". */
|
|
50
|
+
readonly hubLabel: string;
|
|
51
|
+
readonly panel: BrandlabNavPanel;
|
|
52
|
+
/** The panel's links in order (for `columns`, every group's links in order). */
|
|
53
|
+
readonly links: readonly BrandlabNavLink[];
|
|
54
|
+
/** For `columns`: the groups, two or three balanced columns. */
|
|
55
|
+
readonly groups?: readonly BrandlabNavGroup[];
|
|
56
|
+
/** For `featured`: one money-service card with its photo. */
|
|
57
|
+
readonly featured?: BrandlabNavFeatured;
|
|
58
|
+
readonly activePaths?: readonly string[];
|
|
59
|
+
}
|
|
60
|
+
export type BrandlabNavItem = BrandlabNavLinkItem | BrandlabNavMenuItem;
|
|
61
|
+
export interface BrandlabNavigation {
|
|
62
|
+
/** In order, left to right; the phone and the quote button follow the menu and are not items. */
|
|
63
|
+
readonly items: readonly BrandlabNavItem[];
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=navigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../src/navigation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,kEAAkE;IAClE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED,uEAAuE;AACvE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAChH;AAED,wGAAwG;AACxG,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,CAAA;CAC3C;AAED,eAAO,MAAM,mBAAmB,0CAA2C,CAAA;AAC3E,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEnE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,8DAA8D;IAC9D,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACzC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,sFAAsF;IACtF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,0DAA0D;IAC1D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAA;IAChC,gFAAgF;IAChF,QAAQ,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,CAAA;IAC1C,gEAAgE;IAChE,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAA;IAC7C,6DAA6D;IAC7D,QAAQ,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAA;IACvC,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACzC;AAED,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG,mBAAmB,CAAA;AAEvE,MAAM,WAAW,kBAAkB;IACjC,iGAAiG;IACjG,QAAQ,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,CAAA;CAC3C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The navigation model (F1). One menu per site, built from data: the header, the drawer and the checks all read it.
|
|
3
|
+
* A `menu` item is a real link to its hub plus a separate disclosure button (the WAI-ARIA disclosure navigation
|
|
4
|
+
* pattern); its panel always repeats the hub link first. Prices never appear in menus.
|
|
5
|
+
*
|
|
6
|
+
* `defineBrandlabNavigation` (3.9.0) builds this model from the route catalogue, places, services and
|
|
7
|
+
* `strategy.navigation`, and enforces the N1 rules. The types below are the contract the ui-kit header renders.
|
|
8
|
+
*/
|
|
9
|
+
export const BRANDLAB_NAV_PANELS = ['list', 'columns', 'featured'];
|
|
10
|
+
//# sourceMappingURL=navigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../src/navigation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAuBH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAU,CAAA","sourcesContent":["/**\n * The navigation model (F1). One menu per site, built from data: the header, the drawer and the checks all read it.\n * A `menu` item is a real link to its hub plus a separate disclosure button (the WAI-ARIA disclosure navigation\n * pattern); its panel always repeats the hub link first. Prices never appear in menus.\n *\n * `defineBrandlabNavigation` (3.9.0) builds this model from the route catalogue, places, services and\n * `strategy.navigation`, and enforces the N1 rules. The types below are the contract the ui-kit header renders.\n */\n\nexport interface BrandlabNavLink {\n readonly label: string\n readonly href: string\n /** A short line under the label in wide panels. Never a price. */\n readonly description?: string\n}\n\n/** One money-service card with its photo, for the `featured` panel. */\nexport interface BrandlabNavFeatured {\n readonly label: string\n readonly href: string\n readonly description: string\n readonly image: { readonly src: string; readonly alt: string; readonly width: number; readonly height: number }\n}\n\n/** A titled group of links inside a `columns` panel (from the services catalogue's `serviceGroups`). */\nexport interface BrandlabNavGroup {\n readonly heading: string\n readonly links: readonly BrandlabNavLink[]\n}\n\nexport const BRANDLAB_NAV_PANELS = ['list', 'columns', 'featured'] as const\nexport type BrandlabNavPanel = (typeof BRANDLAB_NAV_PANELS)[number]\n\nexport interface BrandlabNavLinkItem {\n readonly kind: 'link'\n /** Stable slug used for element ids. */\n readonly id: string\n readonly label: string\n readonly href: string\n /** Other paths that mark this item as the current section. */\n readonly activePaths?: readonly string[]\n}\n\nexport interface BrandlabNavMenuItem {\n readonly kind: 'menu'\n readonly id: string\n readonly label: string\n /** The hub: the top-level label links here, and the panel's first link repeats it. */\n readonly href: string\n /** The panel's first link, for example \"All services\". */\n readonly hubLabel: string\n readonly panel: BrandlabNavPanel\n /** The panel's links in order (for `columns`, every group's links in order). */\n readonly links: readonly BrandlabNavLink[]\n /** For `columns`: the groups, two or three balanced columns. */\n readonly groups?: readonly BrandlabNavGroup[]\n /** For `featured`: one money-service card with its photo. */\n readonly featured?: BrandlabNavFeatured\n readonly activePaths?: readonly string[]\n}\n\nexport type BrandlabNavItem = BrandlabNavLinkItem | BrandlabNavMenuItem\n\nexport interface BrandlabNavigation {\n /** In order, left to right; the phone and the quote button follow the menu and are not items. */\n readonly items: readonly BrandlabNavItem[]\n}\n"]}
|
package/dist/project.d.ts
CHANGED
|
@@ -29,6 +29,26 @@ export interface BrandlabException {
|
|
|
29
29
|
expiresAt?: string;
|
|
30
30
|
reviewTrigger: string;
|
|
31
31
|
}
|
|
32
|
+
export type BrandlabSiteSystemTier = 'shell' | 'enquiry' | 'full';
|
|
33
|
+
/**
|
|
34
|
+
* Site System v2 adoption. `brandlab-ready` blocks on the declared tier's checks and the tiers below it; higher
|
|
35
|
+
* tiers report without blocking. Absent means the site has not adopted v2 and nothing in the ready gate blocks.
|
|
36
|
+
*/
|
|
37
|
+
export interface BrandlabSiteSystemConfig {
|
|
38
|
+
tier: BrandlabSiteSystemTier;
|
|
39
|
+
/** A new build or redesign: the same-trade distinctness check (D4) blocks whatever the tier. */
|
|
40
|
+
newBuild?: boolean;
|
|
41
|
+
/** Extra pages the ready gate samples, beyond home, the contact page and one page per route. */
|
|
42
|
+
samples?: readonly string[];
|
|
43
|
+
/** Quote and call-to-action labels Romie recorded for this site, beyond the closed list. */
|
|
44
|
+
labels?: readonly string[];
|
|
45
|
+
/** Whether the business offers free quotes ("Get a free quote" rather than "Get a quote"). */
|
|
46
|
+
freeQuotes?: boolean;
|
|
47
|
+
/** Third-party hostnames the site may load, for example www.youtube.com. */
|
|
48
|
+
thirdParties?: readonly string[];
|
|
49
|
+
/** Extra tel: links the site legitimately shows, for example a second line. */
|
|
50
|
+
phones?: readonly string[];
|
|
51
|
+
}
|
|
32
52
|
export type BrandlabSitemapConfig = {
|
|
33
53
|
mode: 'single';
|
|
34
54
|
} | {
|
|
@@ -65,6 +85,7 @@ export interface BrandlabProjectConfig {
|
|
|
65
85
|
};
|
|
66
86
|
};
|
|
67
87
|
exceptions?: readonly BrandlabException[];
|
|
88
|
+
siteSystem?: BrandlabSiteSystemConfig;
|
|
68
89
|
}
|
|
69
90
|
/**
|
|
70
91
|
* Defines project-owned variation only. Runtime versions and global Brandlab
|
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,MAAM,MAAM,wBAAwB,GAChC,MAAM,GACN,uBAAuB,GACvB,mBAAmB,GACnB,gBAAgB,CAAA;AACpB,MAAM,MAAM,uBAAuB,GAAG,eAAe,GAAG,yBAAyB,GAAG,eAAe,CAAA;AACnG,MAAM,MAAM,yBAAyB,GAAG,WAAW,GAAG,SAAS,GAAG,MAAM,CAAA;AAExE,MAAM,MAAM,yBAAyB,GACjC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A;SAAE,CAAA;QACvC,OAAO,CAAC,EAAE;YACR,YAAY,EAAE,MAAM,CAAA;YACpB,WAAW,EAAE,6BAA6B,CAAA;SAC3C,CAAA;QACD,SAAS,CAAC,EAAE;YAAE,QAAQ,EAAE,wBAAwB,CAAA;SAAE,CAAA;QAClD,OAAO,CAAC,EAAE,yBAAyB,CAAA;KACpC,CAAA;IACD,OAAO,CAAC,EAAE,qBAAqB,CAAA;IAC/B,mBAAmB,EAAE;QACnB,oBAAoB,EAAE;YACpB,IAAI,EAAE,MAAM,CAAA;YACZ,OAAO,CAAC,EAAE,MAAM,CAAA;YAChB,OAAO,CAAC,EAAE,MAAM,CAAA;YAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;YACjB,IAAI,CAAC,EAAE,MAAM,CAAA;SACd,CAAA;KACF,CAAA;IACD,UAAU,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAA;IACzC,UAAU,CAAC,EAAE,wBAAwB,CAAA;CACtC;AAkGD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,CAAC,CAAC,SAAS,qBAAqB,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CA6KzF"}
|
package/dist/project.js
CHANGED
|
@@ -7,6 +7,7 @@ const PROJECT_CONFIG_KEYS = [
|
|
|
7
7
|
'sitemap',
|
|
8
8
|
'searchCertification',
|
|
9
9
|
'exceptions',
|
|
10
|
+
'siteSystem',
|
|
10
11
|
];
|
|
11
12
|
const ROUTE_FAMILIES = new Set([
|
|
12
13
|
'services',
|
|
@@ -47,6 +48,10 @@ const BUSINESS_PROFILE_REVIEWS_SELECTIONS = new Set([
|
|
|
47
48
|
'recent',
|
|
48
49
|
'five-star',
|
|
49
50
|
]);
|
|
51
|
+
const SITE_SYSTEM_TIERS = new Set(['shell', 'enquiry', 'full']);
|
|
52
|
+
const SITE_SYSTEM_KEYS = ['tier', 'newBuild', 'samples', 'labels', 'freeQuotes', 'thirdParties', 'phones'];
|
|
53
|
+
const HOSTNAME_PATTERN = /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;
|
|
54
|
+
const TEL_HREF_PATTERN = /^tel:\+?\d{6,15}$/;
|
|
50
55
|
function assertNonEmpty(value, field) {
|
|
51
56
|
if (!value.trim()) {
|
|
52
57
|
throw new Error(`${field} cannot be empty.`);
|
|
@@ -66,6 +71,17 @@ function assertKnownKeys(value, allowed, field, hint = '') {
|
|
|
66
71
|
throw new Error(`${field} contains unsupported keys: ${unsupported.join(', ')}.${hint}`);
|
|
67
72
|
}
|
|
68
73
|
}
|
|
74
|
+
function assertStringList(value, field, check) {
|
|
75
|
+
if (!Array.isArray(value)) {
|
|
76
|
+
throw new Error(`${field} must be a list.`);
|
|
77
|
+
}
|
|
78
|
+
value.forEach((item, index) => {
|
|
79
|
+
if (typeof item !== 'string')
|
|
80
|
+
throw new Error(`${field}[${index}] must be text.`);
|
|
81
|
+
check(item, `${field}[${index}]`);
|
|
82
|
+
});
|
|
83
|
+
assertUnique(value, field);
|
|
84
|
+
}
|
|
69
85
|
function assertUnique(values, field) {
|
|
70
86
|
const duplicate = values.find((value, index) => values.indexOf(value) !== index);
|
|
71
87
|
if (duplicate) {
|
|
@@ -153,6 +169,9 @@ export function defineBrandlabProject(config) {
|
|
|
153
169
|
!BUSINESS_PROFILE_REVIEWS_SELECTIONS.has(reviews.selection)) {
|
|
154
170
|
throw new Error('reviews.selection is unsupported.');
|
|
155
171
|
}
|
|
172
|
+
if ('exclude' in reviews) {
|
|
173
|
+
throw new Error('reviews.exclude belongs in src/config/reviews.ts (reviews.exclude, passed to selectBusinessProfileReviews), not brandlab.config.');
|
|
174
|
+
}
|
|
156
175
|
}
|
|
157
176
|
if (config.sitemap?.mode === 'split') {
|
|
158
177
|
if (config.sitemap.families.length === 0) {
|
|
@@ -162,6 +181,44 @@ export function defineBrandlabProject(config) {
|
|
|
162
181
|
config.sitemap.families.forEach((path, index) => assertRootRelativePath(path, `sitemap.families[${index}]`));
|
|
163
182
|
assertNonEmpty(config.sitemap.reason, 'sitemap.reason');
|
|
164
183
|
}
|
|
184
|
+
if (config.siteSystem !== undefined) {
|
|
185
|
+
const siteSystem = config.siteSystem;
|
|
186
|
+
if (!siteSystem || typeof siteSystem !== 'object' || Array.isArray(siteSystem)) {
|
|
187
|
+
throw new Error('siteSystem must be an object with a tier.');
|
|
188
|
+
}
|
|
189
|
+
assertKnownKeys(siteSystem, SITE_SYSTEM_KEYS, 'siteSystem');
|
|
190
|
+
if (!SITE_SYSTEM_TIERS.has(siteSystem.tier)) {
|
|
191
|
+
throw new Error('siteSystem.tier is unsupported.');
|
|
192
|
+
}
|
|
193
|
+
if (siteSystem.newBuild !== undefined && typeof siteSystem.newBuild !== 'boolean') {
|
|
194
|
+
throw new Error('siteSystem.newBuild must be true or false.');
|
|
195
|
+
}
|
|
196
|
+
if (siteSystem.samples !== undefined) {
|
|
197
|
+
if (!Array.isArray(siteSystem.samples)) {
|
|
198
|
+
throw new Error('siteSystem.samples must be a list of paths.');
|
|
199
|
+
}
|
|
200
|
+
assertUnique(siteSystem.samples, 'siteSystem.samples');
|
|
201
|
+
siteSystem.samples.forEach((path, index) => assertRootRelativePath(path, `siteSystem.samples[${index}]`));
|
|
202
|
+
}
|
|
203
|
+
if (siteSystem.labels !== undefined) {
|
|
204
|
+
assertStringList(siteSystem.labels, 'siteSystem.labels', (label, field) => assertNonEmpty(label, field));
|
|
205
|
+
}
|
|
206
|
+
if (siteSystem.freeQuotes !== undefined && typeof siteSystem.freeQuotes !== 'boolean') {
|
|
207
|
+
throw new Error('siteSystem.freeQuotes must be true or false.');
|
|
208
|
+
}
|
|
209
|
+
if (siteSystem.thirdParties !== undefined) {
|
|
210
|
+
assertStringList(siteSystem.thirdParties, 'siteSystem.thirdParties', (host, field) => {
|
|
211
|
+
if (!HOSTNAME_PATTERN.test(host))
|
|
212
|
+
throw new Error(`${field} must be a hostname such as www.youtube.com.`);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
if (siteSystem.phones !== undefined) {
|
|
216
|
+
assertStringList(siteSystem.phones, 'siteSystem.phones', (href, field) => {
|
|
217
|
+
if (!TEL_HREF_PATTERN.test(href))
|
|
218
|
+
throw new Error(`${field} must be a tel: link such as tel:+61290001234.`);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
165
222
|
assertUnique((config.exceptions ?? []).map((exception) => exception.ruleId), 'exceptions.ruleId');
|
|
166
223
|
(config.exceptions ?? []).forEach((exception, index) => {
|
|
167
224
|
assertNonEmpty(exception.ruleId, `exceptions[${index}].ruleId`);
|
package/dist/project.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAA;AAuFhE,MAAM,mBAAmB,GAAG;IAC1B,WAAW;IACX,QAAQ;IACR,cAAc;IACd,SAAS;IACT,qBAAqB;IACrB,YAAY;CACJ,CAAA;AACV,MAAM,cAAc,GAAG,IAAI,GAAG,CAAsB;IAClD,UAAU;IACV,WAAW;IACX,mBAAmB;IACnB,MAAM;IACN,UAAU;IACV,OAAO;CACR,CAAC,CAAA;AACF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAsB,CAAC,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAA;AACjF,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAgC;IAC9D,MAAM;IACN,iBAAiB;IACjB,iBAAiB;IACjB,0BAA0B;CAC3B,CAAC,CAAA;AACF,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAA2B;IAC5D,MAAM;IACN,uBAAuB;IACvB,mBAAmB;IACnB,gBAAgB;CACjB,CAAC,CAAA;AACF,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAA0B;IACzD,eAA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,YAAY,CACV,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,EAC9D,mBAAmB,CACpB,CAEA;IAAA,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;QACtD,cAAc,CAAC,SAAS,CAAC,MAAM,EAAE,cAAc,KAAK,UAAU,CAAC,CAAA;QAC/D,cAAc,CAAC,SAAS,CAAC,SAAS,EAAE,cAAc,KAAK,aAAa,CAAC,CAAA;QACrE,cAAc,CAAC,SAAS,CAAC,QAAQ,EAAE,cAAc,KAAK,YAAY,CAAC,CAAA;QACnE,cAAc,CAAC,SAAS,CAAC,aAAa,EAAE,cAAc,KAAK,iBAAiB,CAAC,CAAA;QAC7E,IAAI,SAAS,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,cAAc,KAAK,0BAA0B,CAAC,CAAA;QAChE,CAAC;QAED,IAAI,SAAS,CAAC,SAAS,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;YACzE,MAAM,IAAI,KAAK,CAAC,cAAc,KAAK,mCAAmC,CAAC,CAAA;QACzE,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { normalizeBrandlabRoutePath } from './routes.js'\nimport { assertBrandlabCanonicalEntityId } from './entity-id.js'\nimport type { GooglePlaceReviewsSelection } from './google-reviews.js'\nimport type { BusinessProfileReviewsPolicy } from './google-business-reviews.js'\n\nexport type BrandlabRouteFamily =\n | 'services'\n | 'locations'\n | 'service-locations'\n | 'blog'\n | 'projects'\n | 'legal'\n\nexport type BrandlabBlogAdapter = 'none' | 'mdx' | 'structured'\nexport type BrandlabContactAttachmentMode =\n | 'none'\n | 'images-optional'\n | 'images-required'\n | 'images-and-pdfs-optional'\nexport type BrandlabLocationStrategy =\n | 'none'\n | 'approved-service-area'\n | 'physical-location'\n | 'multi-location'\nexport type BrandlabReviewsProvider = 'google-places' | 'google-business-profile' | 'project-owned'\nexport type BrandlabGoogleReviewsMode = 'link-only' | 'summary' | 'full'\n\nexport type BrandlabReviewsCapability =\n | { provider: 'project-owned' }\n | {\n /** 3.5.0: Google reviews read on the server from the Brandlab reviews feed (site-next/google-business-reviews/server). */\n provider: 'google-business-profile'\n /** Optional presentation policy: the newest reviews, or the newest five-star ones. */\n selection?: BusinessProfileReviewsPolicy\n }\n | {\n provider: 'google-places'\n mode: BrandlabGoogleReviewsMode\n /** Optional presentation policy. Five-star selection is valid only in full mode. */\n selection?: GooglePlaceReviewsSelection\n /** Stable route IDs where review proof is intentionally presented. */\n routeIds: readonly string[]\n }\n\nexport interface BrandlabException {\n ruleId: string\n rationale: string\n owner: 'Romie'\n evidence: string\n expiresAt?: string\n reviewTrigger: string\n}\n\nexport type BrandlabSitemapConfig =\n | { mode: 'single' }\n | {\n mode: 'split'\n families: readonly string[]\n reason: string\n }\n\nexport interface BrandlabProjectConfig {\n projectId: string\n routes: {\n families: readonly BrandlabRouteFamily[]\n }\n capabilities?: {\n blog?: { adapter: BrandlabBlogAdapter }\n contact?: {\n fieldProfile: string\n attachments: BrandlabContactAttachmentMode\n }\n locations?: { strategy: BrandlabLocationStrategy }\n reviews?: BrandlabReviewsCapability\n }\n sitemap?: BrandlabSitemapConfig\n searchCertification: {\n representativeRoutes: {\n home: string\n contact?: string\n service?: string\n location?: string\n blog?: string\n }\n }\n exceptions?: readonly BrandlabException[]\n}\n\nconst PROJECT_CONFIG_KEYS = [\n 'projectId',\n 'routes',\n 'capabilities',\n 'sitemap',\n 'searchCertification',\n 'exceptions',\n] as const\nconst ROUTE_FAMILIES = new Set<BrandlabRouteFamily>([\n 'services',\n 'locations',\n 'service-locations',\n 'blog',\n 'projects',\n 'legal',\n])\nconst BLOG_ADAPTERS = new Set<BrandlabBlogAdapter>(['none', 'mdx', 'structured'])\nconst ATTACHMENT_MODES = new Set<BrandlabContactAttachmentMode>([\n 'none',\n 'images-optional',\n 'images-required',\n 'images-and-pdfs-optional',\n])\nconst LOCATION_STRATEGIES = new Set<BrandlabLocationStrategy>([\n 'none',\n 'approved-service-area',\n 'physical-location',\n 'multi-location',\n])\nconst REVIEWS_PROVIDERS = new Set<BrandlabReviewsProvider>([\n 'google-places',\n 'google-business-profile',\n 'project-owned',\n])\nconst GOOGLE_REVIEWS_MODES = new Set<BrandlabGoogleReviewsMode>([\n 'link-only',\n 'summary',\n 'full',\n])\nconst GOOGLE_REVIEWS_SELECTIONS = new Set<GooglePlaceReviewsSelection>([\n 'relevance',\n 'five-star-featured',\n])\nconst BUSINESS_PROFILE_REVIEWS_SELECTIONS = new Set<BusinessProfileReviewsPolicy>([\n 'recent',\n 'five-star',\n])\n\nfunction assertNonEmpty(value: string, field: string) {\n if (!value.trim()) {\n throw new Error(`${field} cannot be empty.`)\n }\n}\n\nfunction assertRootRelativePath(path: string, field: string) {\n try {\n normalizeBrandlabRoutePath(path)\n } catch {\n throw new Error(`${field} must be a root-relative path without a query string or hash.`)\n }\n}\n\nfunction assertKnownKeys(value: object, allowed: readonly string[], field: string, hint = '') {\n const unsupported = Object.keys(value).filter((key) => !allowed.includes(key))\n if (unsupported.length > 0) {\n throw new Error(`${field} contains unsupported keys: ${unsupported.join(', ')}.${hint}`)\n }\n}\n\nfunction assertUnique(values: readonly string[], field: string) {\n const duplicate = values.find((value, index) => values.indexOf(value) !== index)\n if (duplicate) {\n throw new Error(`${field} contains duplicate value \"${duplicate}\".`)\n }\n}\n\n/**\n * Defines project-owned variation only. Runtime versions and global Brandlab\n * policy deliberately do not belong in this object.\n */\nexport function defineBrandlabProject<const T extends BrandlabProjectConfig>(config: T): T {\n if (!config || typeof config !== 'object' || Array.isArray(config)) {\n throw new TypeError('defineBrandlabProject requires a project configuration.')\n }\n assertKnownKeys(config, PROJECT_CONFIG_KEYS, 'Project configuration')\n assertNonEmpty(config.projectId, 'projectId')\n\n assertBrandlabCanonicalEntityId(config.projectId)\n\n if (!config.routes || typeof config.routes !== 'object') {\n throw new Error('routes.families is required.')\n }\n assertKnownKeys(\n config.routes,\n ['families'],\n 'routes',\n ' Redirects belong in the src/data/redirects.ts table.',\n )\n assertUnique(config.routes.families, 'routes.families')\n config.routes.families.forEach((family, index) => {\n if (!ROUTE_FAMILIES.has(family)) {\n throw new Error(`routes.families[${index}] is unsupported.`)\n }\n })\n\n const representativeRoutes = config.searchCertification.representativeRoutes\n Object.entries(representativeRoutes).forEach(([name, path]) => {\n if (path) assertRootRelativePath(path, `searchCertification.representativeRoutes.${name}`)\n })\n if (representativeRoutes.home !== '/') {\n throw new Error('searchCertification.representativeRoutes.home must be \"/\".')\n }\n\n if (config.capabilities?.contact) {\n assertNonEmpty(config.capabilities.contact.fieldProfile, 'contact.fieldProfile')\n if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(config.capabilities.contact.fieldProfile)) {\n throw new Error('contact.fieldProfile must be lowercase kebab-case.')\n }\n if (!ATTACHMENT_MODES.has(config.capabilities.contact.attachments)) {\n throw new Error('contact.attachments is unsupported.')\n }\n }\n if (\n config.capabilities?.blog &&\n !BLOG_ADAPTERS.has(config.capabilities.blog.adapter)\n ) {\n throw new Error('blog.adapter is unsupported.')\n }\n if (\n config.capabilities?.locations &&\n !LOCATION_STRATEGIES.has(config.capabilities.locations.strategy)\n ) {\n throw new Error('locations.strategy is unsupported.')\n }\n if (\n config.capabilities?.reviews &&\n !REVIEWS_PROVIDERS.has(config.capabilities.reviews.provider)\n ) {\n throw new Error('reviews.provider is unsupported.')\n }\n if (\n config.capabilities?.reviews?.provider === 'google-places' &&\n !config.routes.families.includes('legal')\n ) {\n throw new Error('Google Places reviews require the legal route family.')\n }\n if (config.capabilities?.reviews?.provider === 'google-places') {\n const reviews = config.capabilities.reviews\n if (!GOOGLE_REVIEWS_MODES.has(reviews.mode)) {\n throw new Error('reviews.mode is unsupported.')\n }\n if (reviews.selection && !GOOGLE_REVIEWS_SELECTIONS.has(reviews.selection)) {\n throw new Error('reviews.selection is unsupported.')\n }\n if (reviews.selection === 'five-star-featured' && reviews.mode !== 'full') {\n throw new Error('Five-star featured reviews require full mode.')\n }\n if (!Array.isArray(reviews.routeIds) || reviews.routeIds.length === 0) {\n throw new Error('Google Places reviews require at least one approved route ID.')\n }\n assertUnique(reviews.routeIds, 'reviews.routeIds')\n reviews.routeIds.forEach((routeId, index) => {\n if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(routeId)) {\n throw new Error(`reviews.routeIds[${index}] must be lowercase kebab-case.`)\n }\n })\n }\n\n if (config.capabilities?.reviews?.provider === 'google-business-profile') {\n const reviews = config.capabilities.reviews\n if (\n reviews.selection !== undefined &&\n !BUSINESS_PROFILE_REVIEWS_SELECTIONS.has(reviews.selection)\n ) {\n throw new Error('reviews.selection is unsupported.')\n }\n }\n\n if (config.sitemap?.mode === 'split') {\n if (config.sitemap.families.length === 0) {\n throw new Error('Split sitemap configuration requires at least one family.')\n }\n assertUnique(config.sitemap.families, 'sitemap.families')\n config.sitemap.families.forEach((path, index) =>\n assertRootRelativePath(path, `sitemap.families[${index}]`),\n )\n assertNonEmpty(config.sitemap.reason, 'sitemap.reason')\n }\n\n assertUnique(\n (config.exceptions ?? []).map((exception) => exception.ruleId),\n 'exceptions.ruleId',\n )\n\n ;(config.exceptions ?? []).forEach((exception, index) => {\n assertNonEmpty(exception.ruleId, `exceptions[${index}].ruleId`)\n assertNonEmpty(exception.rationale, `exceptions[${index}].rationale`)\n assertNonEmpty(exception.evidence, `exceptions[${index}].evidence`)\n assertNonEmpty(exception.reviewTrigger, `exceptions[${index}].reviewTrigger`)\n if (exception.owner !== 'Romie') {\n throw new Error(`exceptions[${index}].owner must be \"Romie\".`)\n }\n\n if (exception.expiresAt && Number.isNaN(Date.parse(exception.expiresAt))) {\n throw new Error(`exceptions[${index}].expiresAt must be a valid date.`)\n }\n })\n\n return config\n}\n"]}
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAA;AA8GhE,MAAM,mBAAmB,GAAG;IAC1B,WAAW;IACX,QAAQ;IACR,cAAc;IACd,SAAS;IACT,qBAAqB;IACrB,YAAY;IACZ,YAAY;CACJ,CAAA;AACV,MAAM,cAAc,GAAG,IAAI,GAAG,CAAsB;IAClD,UAAU;IACV,WAAW;IACX,mBAAmB;IACnB,MAAM;IACN,UAAU;IACV,OAAO;CACR,CAAC,CAAA;AACF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAsB,CAAC,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAA;AACjF,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAgC;IAC9D,MAAM;IACN,iBAAiB;IACjB,iBAAiB;IACjB,0BAA0B;CAC3B,CAAC,CAAA;AACF,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAA2B;IAC5D,MAAM;IACN,uBAAuB;IACvB,mBAAmB;IACnB,gBAAgB;CACjB,CAAC,CAAA;AACF,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAA0B;IACzD,eAAe;IACf,yBAAyB;IACzB,eAAe;CAChB,CAAC,CAAA;AACF,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAA4B;IAC9D,WAAW;IACX,SAAS;IACT,MAAM;CACP,CAAC,CAAA;AACF,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAA8B;IACrE,WAAW;IACX,oBAAoB;CACrB,CAAC,CAAA;AACF,MAAM,mCAAmC,GAAG,IAAI,GAAG,CAA+B;IAChF,QAAQ;IACR,WAAW;CACZ,CAAC,CAAA;AACF,MAAM,iBAAiB,GAAG,IAAI,G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AK,EAAE,EAAE;gBACvE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;oBAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,gDAAgD,CAAC,CAAA;YAC7G,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,YAAY,CACV,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,EAC9D,mBAAmB,CACpB,CAEA;IAAA,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;QACtD,cAAc,CAAC,SAAS,CAAC,MAAM,EAAE,cAAc,KAAK,UAAU,CAAC,CAAA;QAC/D,cAAc,CAAC,SAAS,CAAC,SAAS,EAAE,cAAc,KAAK,aAAa,CAAC,CAAA;QACrE,cAAc,CAAC,SAAS,CAAC,QAAQ,EAAE,cAAc,KAAK,YAAY,CAAC,CAAA;QACnE,cAAc,CAAC,SAAS,CAAC,aAAa,EAAE,cAAc,KAAK,iBAAiB,CAAC,CAAA;QAC7E,IAAI,SAAS,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,cAAc,KAAK,0BAA0B,CAAC,CAAA;QAChE,CAAC;QAED,IAAI,SAAS,CAAC,SAAS,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;YACzE,MAAM,IAAI,KAAK,CAAC,cAAc,KAAK,mCAAmC,CAAC,CAAA;QACzE,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { normalizeBrandlabRoutePath } from './routes.js'\nimport { assertBrandlabCanonicalEntityId } from './entity-id.js'\nimport type { GooglePlaceReviewsSelection } from './google-reviews.js'\nimport type { BusinessProfileReviewsPolicy } from './google-business-reviews.js'\n\nexport type BrandlabRouteFamily =\n | 'services'\n | 'locations'\n | 'service-locations'\n | 'blog'\n | 'projects'\n | 'legal'\n\nexport type BrandlabBlogAdapter = 'none' | 'mdx' | 'structured'\nexport type BrandlabContactAttachmentMode =\n | 'none'\n | 'images-optional'\n | 'images-required'\n | 'images-and-pdfs-optional'\nexport type BrandlabLocationStrategy =\n | 'none'\n | 'approved-service-area'\n | 'physical-location'\n | 'multi-location'\nexport type BrandlabReviewsProvider = 'google-places' | 'google-business-profile' | 'project-owned'\nexport type BrandlabGoogleReviewsMode = 'link-only' | 'summary' | 'full'\n\nexport type BrandlabReviewsCapability =\n | { provider: 'project-owned' }\n | {\n /** 3.5.0: Google reviews read on the server from the Brandlab reviews feed (site-next/google-business-reviews/server). */\n provider: 'google-business-profile'\n /** Optional presentation policy: the newest reviews, or the newest five-star ones. */\n selection?: BusinessProfileReviewsPolicy\n }\n | {\n provider: 'google-places'\n mode: BrandlabGoogleReviewsMode\n /** Optional presentation policy. Five-star selection is valid only in full mode. */\n selection?: GooglePlaceReviewsSelection\n /** Stable route IDs where review proof is intentionally presented. */\n routeIds: readonly string[]\n }\n\nexport interface BrandlabException {\n ruleId: string\n rationale: string\n owner: 'Romie'\n evidence: string\n expiresAt?: string\n reviewTrigger: string\n}\n\nexport type BrandlabSiteSystemTier = 'shell' | 'enquiry' | 'full'\n\n/**\n * Site System v2 adoption. `brandlab-ready` blocks on the declared tier's checks and the tiers below it; higher\n * tiers report without blocking. Absent means the site has not adopted v2 and nothing in the ready gate blocks.\n */\nexport interface BrandlabSiteSystemConfig {\n tier: BrandlabSiteSystemTier\n /** A new build or redesign: the same-trade distinctness check (D4) blocks whatever the tier. */\n newBuild?: boolean\n /** Extra pages the ready gate samples, beyond home, the contact page and one page per route. */\n samples?: readonly string[]\n /** Quote and call-to-action labels Romie recorded for this site, beyond the closed list. */\n labels?: readonly string[]\n /** Whether the business offers free quotes (\"Get a free quote\" rather than \"Get a quote\"). */\n freeQuotes?: boolean\n /** Third-party hostnames the site may load, for example www.youtube.com. */\n thirdParties?: readonly string[]\n /** Extra tel: links the site legitimately shows, for example a second line. */\n phones?: readonly string[]\n}\n\nexport type BrandlabSitemapConfig =\n | { mode: 'single' }\n | {\n mode: 'split'\n families: readonly string[]\n reason: string\n }\n\nexport interface BrandlabProjectConfig {\n projectId: string\n routes: {\n families: readonly BrandlabRouteFamily[]\n }\n capabilities?: {\n blog?: { adapter: BrandlabBlogAdapter }\n contact?: {\n fieldProfile: string\n attachments: BrandlabContactAttachmentMode\n }\n locations?: { strategy: BrandlabLocationStrategy }\n reviews?: BrandlabReviewsCapability\n }\n sitemap?: BrandlabSitemapConfig\n searchCertification: {\n representativeRoutes: {\n home: string\n contact?: string\n service?: string\n location?: string\n blog?: string\n }\n }\n exceptions?: readonly BrandlabException[]\n siteSystem?: BrandlabSiteSystemConfig\n}\n\nconst PROJECT_CONFIG_KEYS = [\n 'projectId',\n 'routes',\n 'capabilities',\n 'sitemap',\n 'searchCertification',\n 'exceptions',\n 'siteSystem',\n] as const\nconst ROUTE_FAMILIES = new Set<BrandlabRouteFamily>([\n 'services',\n 'locations',\n 'service-locations',\n 'blog',\n 'projects',\n 'legal',\n])\nconst BLOG_ADAPTERS = new Set<BrandlabBlogAdapter>(['none', 'mdx', 'structured'])\nconst ATTACHMENT_MODES = new Set<BrandlabContactAttachmentMode>([\n 'none',\n 'images-optional',\n 'images-required',\n 'images-and-pdfs-optional',\n])\nconst LOCATION_STRATEGIES = new Set<BrandlabLocationStrategy>([\n 'none',\n 'approved-service-area',\n 'physical-location',\n 'multi-location',\n])\nconst REVIEWS_PROVIDERS = new Set<BrandlabReviewsProvider>([\n 'google-places',\n 'google-business-profile',\n 'project-owned',\n])\nconst GOOGLE_REVIEWS_MODES = new Set<BrandlabGoogleReviewsMode>([\n 'link-only',\n 'summary',\n 'full',\n])\nconst GOOGLE_REVIEWS_SELECTIONS = new Set<GooglePlaceReviewsSelection>([\n 'relevance',\n 'five-star-featured',\n])\nconst BUSINESS_PROFILE_REVIEWS_SELECTIONS = new Set<BusinessProfileReviewsPolicy>([\n 'recent',\n 'five-star',\n])\nconst SITE_SYSTEM_TIERS = new Set<BrandlabSiteSystemTier>(['shell', 'enquiry', 'full'])\nconst SITE_SYSTEM_KEYS = ['tier', 'newBuild', 'samples', 'labels', 'freeQuotes', 'thirdParties', 'phones']\nconst HOSTNAME_PATTERN = /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z]{2,63}$/\nconst TEL_HREF_PATTERN = /^tel:\\+?\\d{6,15}$/\n\nfunction assertNonEmpty(value: string, field: string) {\n if (!value.trim()) {\n throw new Error(`${field} cannot be empty.`)\n }\n}\n\nfunction assertRootRelativePath(path: string, field: string) {\n try {\n normalizeBrandlabRoutePath(path)\n } catch {\n throw new Error(`${field} must be a root-relative path without a query string or hash.`)\n }\n}\n\nfunction assertKnownKeys(value: object, allowed: readonly string[], field: string, hint = '') {\n const unsupported = Object.keys(value).filter((key) => !allowed.includes(key))\n if (unsupported.length > 0) {\n throw new Error(`${field} contains unsupported keys: ${unsupported.join(', ')}.${hint}`)\n }\n}\n\nfunction assertStringList(\n value: unknown,\n field: string,\n check: (item: string, itemField: string) => void,\n) {\n if (!Array.isArray(value)) {\n throw new Error(`${field} must be a list.`)\n }\n value.forEach((item, index) => {\n if (typeof item !== 'string') throw new Error(`${field}[${index}] must be text.`)\n check(item, `${field}[${index}]`)\n })\n assertUnique(value as string[], field)\n}\n\nfunction assertUnique(values: readonly string[], field: string) {\n const duplicate = values.find((value, index) => values.indexOf(value) !== index)\n if (duplicate) {\n throw new Error(`${field} contains duplicate value \"${duplicate}\".`)\n }\n}\n\n/**\n * Defines project-owned variation only. Runtime versions and global Brandlab\n * policy deliberately do not belong in this object.\n */\nexport function defineBrandlabProject<const T extends BrandlabProjectConfig>(config: T): T {\n if (!config || typeof config !== 'object' || Array.isArray(config)) {\n throw new TypeError('defineBrandlabProject requires a project configuration.')\n }\n assertKnownKeys(config, PROJECT_CONFIG_KEYS, 'Project configuration')\n assertNonEmpty(config.projectId, 'projectId')\n\n assertBrandlabCanonicalEntityId(config.projectId)\n\n if (!config.routes || typeof config.routes !== 'object') {\n throw new Error('routes.families is required.')\n }\n assertKnownKeys(\n config.routes,\n ['families'],\n 'routes',\n ' Redirects belong in the src/data/redirects.ts table.',\n )\n assertUnique(config.routes.families, 'routes.families')\n config.routes.families.forEach((family, index) => {\n if (!ROUTE_FAMILIES.has(family)) {\n throw new Error(`routes.families[${index}] is unsupported.`)\n }\n })\n\n const representativeRoutes = config.searchCertification.representativeRoutes\n Object.entries(representativeRoutes).forEach(([name, path]) => {\n if (path) assertRootRelativePath(path, `searchCertification.representativeRoutes.${name}`)\n })\n if (representativeRoutes.home !== '/') {\n throw new Error('searchCertification.representativeRoutes.home must be \"/\".')\n }\n\n if (config.capabilities?.contact) {\n assertNonEmpty(config.capabilities.contact.fieldProfile, 'contact.fieldProfile')\n if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(config.capabilities.contact.fieldProfile)) {\n throw new Error('contact.fieldProfile must be lowercase kebab-case.')\n }\n if (!ATTACHMENT_MODES.has(config.capabilities.contact.attachments)) {\n throw new Error('contact.attachments is unsupported.')\n }\n }\n if (\n config.capabilities?.blog &&\n !BLOG_ADAPTERS.has(config.capabilities.blog.adapter)\n ) {\n throw new Error('blog.adapter is unsupported.')\n }\n if (\n config.capabilities?.locations &&\n !LOCATION_STRATEGIES.has(config.capabilities.locations.strategy)\n ) {\n throw new Error('locations.strategy is unsupported.')\n }\n if (\n config.capabilities?.reviews &&\n !REVIEWS_PROVIDERS.has(config.capabilities.reviews.provider)\n ) {\n throw new Error('reviews.provider is unsupported.')\n }\n if (\n config.capabilities?.reviews?.provider === 'google-places' &&\n !config.routes.families.includes('legal')\n ) {\n throw new Error('Google Places reviews require the legal route family.')\n }\n if (config.capabilities?.reviews?.provider === 'google-places') {\n const reviews = config.capabilities.reviews\n if (!GOOGLE_REVIEWS_MODES.has(reviews.mode)) {\n throw new Error('reviews.mode is unsupported.')\n }\n if (reviews.selection && !GOOGLE_REVIEWS_SELECTIONS.has(reviews.selection)) {\n throw new Error('reviews.selection is unsupported.')\n }\n if (reviews.selection === 'five-star-featured' && reviews.mode !== 'full') {\n throw new Error('Five-star featured reviews require full mode.')\n }\n if (!Array.isArray(reviews.routeIds) || reviews.routeIds.length === 0) {\n throw new Error('Google Places reviews require at least one approved route ID.')\n }\n assertUnique(reviews.routeIds, 'reviews.routeIds')\n reviews.routeIds.forEach((routeId, index) => {\n if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(routeId)) {\n throw new Error(`reviews.routeIds[${index}] must be lowercase kebab-case.`)\n }\n })\n }\n\n if (config.capabilities?.reviews?.provider === 'google-business-profile') {\n const reviews = config.capabilities.reviews\n if (\n reviews.selection !== undefined &&\n !BUSINESS_PROFILE_REVIEWS_SELECTIONS.has(reviews.selection)\n ) {\n throw new Error('reviews.selection is unsupported.')\n }\n if ('exclude' in reviews) {\n throw new Error(\n 'reviews.exclude belongs in src/config/reviews.ts (reviews.exclude, passed to selectBusinessProfileReviews), not brandlab.config.',\n )\n }\n }\n\n if (config.sitemap?.mode === 'split') {\n if (config.sitemap.families.length === 0) {\n throw new Error('Split sitemap configuration requires at least one family.')\n }\n assertUnique(config.sitemap.families, 'sitemap.families')\n config.sitemap.families.forEach((path, index) =>\n assertRootRelativePath(path, `sitemap.families[${index}]`),\n )\n assertNonEmpty(config.sitemap.reason, 'sitemap.reason')\n }\n\n if (config.siteSystem !== undefined) {\n const siteSystem = config.siteSystem\n if (!siteSystem || typeof siteSystem !== 'object' || Array.isArray(siteSystem)) {\n throw new Error('siteSystem must be an object with a tier.')\n }\n assertKnownKeys(siteSystem, SITE_SYSTEM_KEYS, 'siteSystem')\n if (!SITE_SYSTEM_TIERS.has(siteSystem.tier)) {\n throw new Error('siteSystem.tier is unsupported.')\n }\n if (siteSystem.newBuild !== undefined && typeof siteSystem.newBuild !== 'boolean') {\n throw new Error('siteSystem.newBuild must be true or false.')\n }\n if (siteSystem.samples !== undefined) {\n if (!Array.isArray(siteSystem.samples)) {\n throw new Error('siteSystem.samples must be a list of paths.')\n }\n assertUnique(siteSystem.samples, 'siteSystem.samples')\n siteSystem.samples.forEach((path, index) =>\n assertRootRelativePath(path, `siteSystem.samples[${index}]`),\n )\n }\n if (siteSystem.labels !== undefined) {\n assertStringList(siteSystem.labels, 'siteSystem.labels', (label, field) => assertNonEmpty(label, field))\n }\n if (siteSystem.freeQuotes !== undefined && typeof siteSystem.freeQuotes !== 'boolean') {\n throw new Error('siteSystem.freeQuotes must be true or false.')\n }\n if (siteSystem.thirdParties !== undefined) {\n assertStringList(siteSystem.thirdParties, 'siteSystem.thirdParties', (host, field) => {\n if (!HOSTNAME_PATTERN.test(host)) throw new Error(`${field} must be a hostname such as www.youtube.com.`)\n })\n }\n if (siteSystem.phones !== undefined) {\n assertStringList(siteSystem.phones, 'siteSystem.phones', (href, field) => {\n if (!TEL_HREF_PATTERN.test(href)) throw new Error(`${field} must be a tel: link such as tel:+61290001234.`)\n })\n }\n }\n\n assertUnique(\n (config.exceptions ?? []).map((exception) => exception.ruleId),\n 'exceptions.ruleId',\n )\n\n ;(config.exceptions ?? []).forEach((exception, index) => {\n assertNonEmpty(exception.ruleId, `exceptions[${index}].ruleId`)\n assertNonEmpty(exception.rationale, `exceptions[${index}].rationale`)\n assertNonEmpty(exception.evidence, `exceptions[${index}].evidence`)\n assertNonEmpty(exception.reviewTrigger, `exceptions[${index}].reviewTrigger`)\n if (exception.owner !== 'Romie') {\n throw new Error(`exceptions[${index}].owner must be \"Romie\".`)\n }\n\n if (exception.expiresAt && Number.isNaN(Date.parse(exception.expiresAt))) {\n throw new Error(`exceptions[${index}].expiresAt must be a valid date.`)\n }\n })\n\n return config\n}\n"]}
|