@brandlab-digital/site-core 3.6.0 → 3.7.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 CHANGED
@@ -2,6 +2,54 @@
2
2
 
3
3
  Proprietary software © Brandlab Digital Marketing. All rights reserved. Published for Brandlab client sites.
4
4
 
5
+ ## Google reviews (`./google-business-reviews`, from 3.5.0)
6
+
7
+ `parseBusinessProfileReviews` validates a Brandlab reviews feed answer;
8
+ `selectBusinessProfileReviews(feed, { policy, limit, exclude? })` chooses what a
9
+ placement shows, newest first and word for word (`recent`, or `five-star` for
10
+ rating 5 only). The fetch is `site-next/google-business-reviews/server`.
11
+
12
+ ### Leaving out related-party reviews (`exclude`, from 3.7.0)
13
+
14
+ Romie, 19 October 2026: "ok remove suspected Related-party reviews from
15
+ displaying but only if theres enough other reviews to display instead".
16
+ Featuring a review written by a relative of the owner or of Brandlab is a
17
+ consumer-law risk, so a site can name reviews it would rather not feature:
18
+
19
+ ```ts
20
+ // src/config/reviews.ts
21
+ export const reviews = {
22
+ feedSite: 'harbour-electrical',
23
+ policy: 'recent',
24
+ maxReviews: 3,
25
+ exclude: [
26
+ { authorName: 'Jane Example', reason: "Owner's sister; suspected related party (Romie, 19 Oct 2026)." },
27
+ { reviewId: 'AbC123', reason: 'Written by a Brandlab relative (coordinator sweep, 19 Oct 2026).' },
28
+ ],
29
+ } as const
30
+
31
+ // src/lib/reviews.ts
32
+ selectBusinessProfileReviews(feed, { policy: reviews.policy, limit: reviews.maxReviews, exclude: reviews.exclude })
33
+ ```
34
+
35
+ - Each entry names exactly one of `reviewId` (that review, matched exactly) or
36
+ `authorName` (every review by that name, ignoring case, spacing and accent
37
+ composition), plus a non-empty `reason` saying who decided and why. Anything
38
+ else throws, even without a feed, so a bad list fails tests and builds.
39
+ - **Guard:** excluded reviews are hidden only while enough other reviews remain
40
+ to fill `limit`. Otherwise the fewest excluded reviews needed to fill it stay
41
+ (the newest of them), in the policy's order, so a placement never shows fewer
42
+ reviews than it would without the list. A review kept this way was already
43
+ among those shown without the list; `five-star` still shows five-star reviews
44
+ only.
45
+ - The profile's average rating and total are Google's and never change.
46
+ - `excludedBusinessProfileReviewsShown(shown, exclude)` lists the shown reviews
47
+ that match an exclusion (with the entry each matched), so a site can log or
48
+ test when the guard kept one. It is empty whenever the list did its job.
49
+ - The list lives in the site's `src/config/reviews.ts` (`reviews.exclude`).
50
+ brandlab.config carries only `provider` and `selection`; an `exclude` key there
51
+ is refused.
52
+
5
53
  ## Service-area maps (`./area-map`, from 3.6.0)
6
54
 
7
55
  Shared boundary data and the map engine: behaviour, never appearance. Server
@@ -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
- * only the five-star ones (`five-star`), at most `limit`. No feed gives no reviews.
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;CACd;AA2CD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,sBAAsB,GAAG,IAAI,CAgBzF;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,sBAAsB,GAAG,IAAI,GAAG,SAAS,EAC/C,OAAO,EAAE,mCAAmC,GAC3C,qBAAqB,EAAE,CAczB"}
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;I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
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
- * only the five-star ones (`five-star`), at most `limit`. No feed gives no reviews.
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
- return feed.reviews
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,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,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,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,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AAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI;YAAE,MAAK;QAChC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,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"]}
@@ -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,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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;CAC1C;AA8ED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,CAAC,CAAC,SAAS,qBAAqB,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAsIzF"}
package/dist/project.js CHANGED
@@ -153,6 +153,9 @@ export function defineBrandlabProject(config) {
153
153
  !BUSINESS_PROFILE_REVIEWS_SELECTIONS.has(reviews.selection)) {
154
154
  throw new Error('reviews.selection is unsupported.');
155
155
  }
156
+ if ('exclude' in reviews) {
157
+ throw new Error('reviews.exclude belongs in src/config/reviews.ts (reviews.exclude, passed to selectBusinessProfileReviews), not brandlab.config.');
158
+ }
156
159
  }
157
160
  if (config.sitemap?.mode === 'split') {
158
161
  if (config.sitemap.families.length === 0) {
@@ -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,G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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;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,M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'\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 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 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brandlab-digital/site-core",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "license": "UNLICENSED",
5
5
  "repository": {
6
6
  "type": "git",