@brandlab-digital/site-core 3.10.0 → 3.11.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.
@@ -75,6 +75,48 @@ export declare function parseBusinessProfileReviews(value: unknown): BusinessPro
75
75
  * any excluded review that stayed.
76
76
  */
77
77
  export declare function selectBusinessProfileReviews(feed: BusinessProfileReviews | null | undefined, options: SelectBusinessProfileReviewsOptions): BusinessProfileReview[];
78
+ /**
79
+ * Whether a review's text names any of the words, such as a suburb, region or service (3.11.0). Case, spacing and
80
+ * Unicode composition are ignored and only whole words match: "Castle Hill" matches "castle hill's deck" but "Hill"
81
+ * does not match "Hills".
82
+ */
83
+ export declare function businessProfileReviewMentions(review: BusinessProfileReview, mention: readonly string[]): boolean;
84
+ /**
85
+ * Mention ordering (3.11.0): the reviews that name any of the words first, then the rest, each group in the order it
86
+ * was given. It only reorders: it never adds, drops or rewrites a review, and no words leave the order unchanged.
87
+ */
88
+ export declare function orderBusinessProfileReviewsByMention<Review extends BusinessProfileReview>(reviews: readonly Review[], mention: readonly string[] | undefined): Review[];
89
+ export interface PrepareBusinessProfileReviewsOptions extends SelectBusinessProfileReviewsOptions {
90
+ /**
91
+ * Suburb, region or service names (3.11.0): the feed's reviews that name one come first, before `limit` applies, so
92
+ * a matching review from anywhere in the feed can be shown. Reorders only; it never adds a review the feed lacks.
93
+ */
94
+ mention?: readonly string[];
95
+ }
96
+ /**
97
+ * What a reviews band shows (3.11.0): the selected reviews with Google's own average, total and profile link. The
98
+ * numbers come only from the feed; the policy is kept so the band can say how the reviews were chosen.
99
+ */
100
+ export interface PreparedBusinessProfileReviews {
101
+ policy: BusinessProfileReviewsPolicy;
102
+ /** Google's average, between 1 and 5, when the feed has it. */
103
+ averageRating?: number;
104
+ /** Google's total, when the feed has it. */
105
+ totalReviewCount?: number;
106
+ /** The Business Profile on Google Maps. */
107
+ profileUrl: string;
108
+ /** The words the reviews were ordered by (empty when none). */
109
+ mention: readonly string[];
110
+ /** Newest first within the policy, reviews naming a `mention` word first; at most `limit`. */
111
+ reviews: BusinessProfileReview[];
112
+ }
113
+ /**
114
+ * The feed's reviews ready for a reviews band: `selectBusinessProfileReviews` with mention ordering applied before
115
+ * the limit and the 3.7.0 `exclude` guard (unchanged) applied to that order. Returns null when there is no feed, or
116
+ * when there are no reviews to show and no Google average and total either, so the band renders nothing at all.
117
+ * With no reviews but an average and total, the band shows the rating alone.
118
+ */
119
+ export declare function prepareBusinessProfileReviews(feed: BusinessProfileReviews | null | undefined, options: PrepareBusinessProfileReviewsOptions): PreparedBusinessProfileReviews | null;
78
120
  /**
79
121
  * The shown reviews that match an exclusion, each with the first exclusion it matches: empty unless the guard in
80
122
  * `selectBusinessProfileReviews` kept an excluded review because too few others remained. Sites can log it or test it.
@@ -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;;;;;GAKG;AACH,MAAM,MAAM,8BAA8B,GACtC;IAAE,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,SAAS,MAAM,EAAE,GAAG,OAAO,CAGhH;AAED;;;GAGG;AACH,wBAAgB,oCAAoC,CAAC,MAAM,SAAS,qBAAqB,EACvF,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GACrC,MAAM,EAAE,CAOV;AAED,MAAM,WAAW,oCAAqC,SAAQ,mCAAmC;IAC/F;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAC5B;AAED;;;GAGG;AACH,MAAM,WAAW,8BAA8B;IAC7C,MAAM,EAAE,4BAA4B,CAAA;IACpC,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,4CAA4C;IAC5C,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAA;IAClB,+DAA+D;IAC/D,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;IAC1B,8FAA8F;IAC9F,OAAO,EAAE,qBAAqB,EAAE,CAAA;CACjC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,sBAAsB,GAAG,IAAI,GAAG,SAAS,EAC/C,OAAO,EAAE,oCAAoC,GAC5C,8BAA8B,GAAG,IAAI,CAgBvC;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,CACjD,KAAK,EAAE,SAAS,qBAAqB,EAAE,EACvC,OAAO,EAAE,SAAS,8BAA8B,EAAE,GAAG,SAAS,GAC7D,kCAAkC,EAAE,CAMtC"}
@@ -127,23 +127,33 @@ function findExclusion(review, exclude) {
127
127
  * any excluded review that stayed.
128
128
  */
129
129
  export function selectBusinessProfileReviews(feed, options) {
130
+ const exclude = assertSelectOptions(options);
131
+ if (!feed)
132
+ return [];
133
+ return fillAvoidingExcluded(policyOrder(feed, options.policy), options.limit, exclude);
134
+ }
135
+ function assertSelectOptions(options) {
130
136
  if (!POLICIES.has(options.policy)) {
131
137
  throw new Error('Business Profile reviews policy must be recent or five-star.');
132
138
  }
133
139
  if (!Number.isInteger(options.limit) || options.limit < 1) {
134
140
  throw new Error('Business Profile reviews limit must be a whole number of 1 or more.');
135
141
  }
136
- const exclude = assertExclusions(options.exclude);
137
- if (!feed)
138
- return [];
139
- const ordered = feed.reviews
140
- .filter((review) => options.policy === 'recent' || review.rating === 5)
142
+ return assertExclusions(options.exclude);
143
+ }
144
+ /** The policy's reviews, newest first, ties in feed order. */
145
+ function policyOrder(feed, policy) {
146
+ return feed.reviews
147
+ .filter((review) => policy === 'recent' || review.rating === 5)
141
148
  .map((review, index) => ({ review, index, time: Date.parse(review.createTime) }))
142
149
  .sort((a, b) => b.time - a.time || a.index - b.index)
143
150
  .map(({ review }) => review);
151
+ }
152
+ /** The 3.7.0 guard: the first `limit` of `ordered`, leaving out excluded reviews only while others remain to fill it. */
153
+ function fillAvoidingExcluded(ordered, limit, exclude) {
144
154
  if (exclude.length === 0)
145
- return ordered.slice(0, options.limit);
146
- const fill = Math.min(options.limit, ordered.length);
155
+ return ordered.slice(0, limit);
156
+ const fill = Math.min(limit, ordered.length);
147
157
  const excluded = new Set(ordered.filter((review) => findExclusion(review, exclude) !== undefined));
148
158
  let keepExcluded = Math.max(0, fill - (ordered.length - excluded.size));
149
159
  const shown = [];
@@ -160,6 +170,74 @@ export function selectBusinessProfileReviews(feed, options) {
160
170
  }
161
171
  return shown;
162
172
  }
173
+ /** Case, spacing and Unicode composition do not tell two spellings of a word apart. */
174
+ function normaliseWords(value) {
175
+ return value.normalize('NFC').replace(/\s+/g, ' ').trim().toLowerCase();
176
+ }
177
+ function assertMention(mention) {
178
+ if (mention === undefined)
179
+ return [];
180
+ if (!Array.isArray(mention) || mention.some((term) => typeof term !== 'string')) {
181
+ throw new Error('Business Profile reviews mention must be a list of words, such as suburb or service names.');
182
+ }
183
+ return mention.map((term) => term.trim()).filter((term) => term.length > 0);
184
+ }
185
+ function mentionPattern(mention) {
186
+ const words = mention.map(normaliseWords).filter((word) => word.length > 0);
187
+ if (words.length === 0)
188
+ return null;
189
+ const alternatives = words.map((word) => word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
190
+ // Whole words: no letter or digit may touch either end of the match.
191
+ return new RegExp(`(?<![\\p{L}\\p{N}])(?:${alternatives})(?![\\p{L}\\p{N}])`, 'u');
192
+ }
193
+ /**
194
+ * Whether a review's text names any of the words, such as a suburb, region or service (3.11.0). Case, spacing and
195
+ * Unicode composition are ignored and only whole words match: "Castle Hill" matches "castle hill's deck" but "Hill"
196
+ * does not match "Hills".
197
+ */
198
+ export function businessProfileReviewMentions(review, mention) {
199
+ const pattern = mentionPattern(assertMention(mention));
200
+ return pattern ? pattern.test(normaliseWords(review.text)) : false;
201
+ }
202
+ /**
203
+ * Mention ordering (3.11.0): the reviews that name any of the words first, then the rest, each group in the order it
204
+ * was given. It only reorders: it never adds, drops or rewrites a review, and no words leave the order unchanged.
205
+ */
206
+ export function orderBusinessProfileReviewsByMention(reviews, mention) {
207
+ const pattern = mentionPattern(assertMention(mention));
208
+ if (!pattern)
209
+ return [...reviews];
210
+ const named = [];
211
+ const others = [];
212
+ for (const review of reviews)
213
+ (pattern.test(normaliseWords(review.text)) ? named : others).push(review);
214
+ return [...named, ...others];
215
+ }
216
+ /**
217
+ * The feed's reviews ready for a reviews band: `selectBusinessProfileReviews` with mention ordering applied before
218
+ * the limit and the 3.7.0 `exclude` guard (unchanged) applied to that order. Returns null when there is no feed, or
219
+ * when there are no reviews to show and no Google average and total either, so the band renders nothing at all.
220
+ * With no reviews but an average and total, the band shows the rating alone.
221
+ */
222
+ export function prepareBusinessProfileReviews(feed, options) {
223
+ const exclude = assertSelectOptions(options);
224
+ const mention = assertMention(options.mention);
225
+ if (!feed)
226
+ return null;
227
+ const ordered = orderBusinessProfileReviewsByMention(policyOrder(feed, options.policy), mention);
228
+ const reviews = fillAvoidingExcluded(ordered, options.limit, exclude);
229
+ const hasRating = feed.averageRating !== undefined && (feed.totalReviewCount ?? 0) > 0;
230
+ if (reviews.length === 0 && !hasRating)
231
+ return null;
232
+ return {
233
+ policy: options.policy,
234
+ ...(feed.averageRating !== undefined ? { averageRating: feed.averageRating } : {}),
235
+ ...(feed.totalReviewCount !== undefined ? { totalReviewCount: feed.totalReviewCount } : {}),
236
+ profileUrl: feed.googleMapsUri,
237
+ mention,
238
+ reviews,
239
+ };
240
+ }
163
241
  /**
164
242
  * The shown reviews that match an exclusion, each with the first exclusion it matches: empty unless the guard in
165
243
  * `selectBusinessProfileReviews` kept an excluded review because too few others remained. Sites can log it or test it.
@@ -1 +1 @@
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,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C,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
+ {"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,MAA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,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClF,GAAG,CAAC,IAAI,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3F,UAAU,EAAE,IAAI,CAAC,aAAa;QAC9B,OAAO;QACP,OAAO;KACR,CAAA;AACH,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 const exclude = assertSelectOptions(options)\n if (!feed) return []\n return fillAvoidingExcluded(policyOrder(feed, options.policy), options.limit, exclude)\n}\n\nfunction assertSelectOptions(options: SelectBusinessProfileReviewsOptions): readonly BusinessProfileReviewExclusion[] {\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 return assertExclusions(options.exclude)\n}\n\n/** The policy's reviews, newest first, ties in feed order. */\nfunction policyOrder(feed: BusinessProfileReviews, policy: BusinessProfileReviewsPolicy): BusinessProfileReview[] {\n return feed.reviews\n .filter((review) => 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}\n\n/** The 3.7.0 guard: the first `limit` of `ordered`, leaving out excluded reviews only while others remain to fill it. */\nfunction fillAvoidingExcluded(\n ordered: readonly BusinessProfileReview[],\n limit: number,\n exclude: readonly BusinessProfileReviewExclusion[],\n): BusinessProfileReview[] {\n if (exclude.length === 0) return ordered.slice(0, limit)\n\n const fill = Math.min(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/** Case, spacing and Unicode composition do not tell two spellings of a word apart. */\nfunction normaliseWords(value: string): string {\n return value.normalize('NFC').replace(/\\s+/g, ' ').trim().toLowerCase()\n}\n\nfunction assertMention(mention: unknown): readonly string[] {\n if (mention === undefined) return []\n if (!Array.isArray(mention) || mention.some((term) => typeof term !== 'string')) {\n throw new Error('Business Profile reviews mention must be a list of words, such as suburb or service names.')\n }\n return (mention as readonly string[]).map((term) => term.trim()).filter((term) => term.length > 0)\n}\n\nfunction mentionPattern(mention: readonly string[]): RegExp | null {\n const words = mention.map(normaliseWords).filter((word) => word.length > 0)\n if (words.length === 0) return null\n const alternatives = words.map((word) => word.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')).join('|')\n // Whole words: no letter or digit may touch either end of the match.\n return new RegExp(`(?<![\\\\p{L}\\\\p{N}])(?:${alternatives})(?![\\\\p{L}\\\\p{N}])`, 'u')\n}\n\n/**\n * Whether a review's text names any of the words, such as a suburb, region or service (3.11.0). Case, spacing and\n * Unicode composition are ignored and only whole words match: \"Castle Hill\" matches \"castle hill's deck\" but \"Hill\"\n * does not match \"Hills\".\n */\nexport function businessProfileReviewMentions(review: BusinessProfileReview, mention: readonly string[]): boolean {\n const pattern = mentionPattern(assertMention(mention))\n return pattern ? pattern.test(normaliseWords(review.text)) : false\n}\n\n/**\n * Mention ordering (3.11.0): the reviews that name any of the words first, then the rest, each group in the order it\n * was given. It only reorders: it never adds, drops or rewrites a review, and no words leave the order unchanged.\n */\nexport function orderBusinessProfileReviewsByMention<Review extends BusinessProfileReview>(\n reviews: readonly Review[],\n mention: readonly string[] | undefined,\n): Review[] {\n const pattern = mentionPattern(assertMention(mention))\n if (!pattern) return [...reviews]\n const named: Review[] = []\n const others: Review[] = []\n for (const review of reviews) (pattern.test(normaliseWords(review.text)) ? named : others).push(review)\n return [...named, ...others]\n}\n\nexport interface PrepareBusinessProfileReviewsOptions extends SelectBusinessProfileReviewsOptions {\n /**\n * Suburb, region or service names (3.11.0): the feed's reviews that name one come first, before `limit` applies, so\n * a matching review from anywhere in the feed can be shown. Reorders only; it never adds a review the feed lacks.\n */\n mention?: readonly string[]\n}\n\n/**\n * What a reviews band shows (3.11.0): the selected reviews with Google's own average, total and profile link. The\n * numbers come only from the feed; the policy is kept so the band can say how the reviews were chosen.\n */\nexport interface PreparedBusinessProfileReviews {\n policy: BusinessProfileReviewsPolicy\n /** Google's average, between 1 and 5, when the feed has it. */\n averageRating?: number\n /** Google's total, when the feed has it. */\n totalReviewCount?: number\n /** The Business Profile on Google Maps. */\n profileUrl: string\n /** The words the reviews were ordered by (empty when none). */\n mention: readonly string[]\n /** Newest first within the policy, reviews naming a `mention` word first; at most `limit`. */\n reviews: BusinessProfileReview[]\n}\n\n/**\n * The feed's reviews ready for a reviews band: `selectBusinessProfileReviews` with mention ordering applied before\n * the limit and the 3.7.0 `exclude` guard (unchanged) applied to that order. Returns null when there is no feed, or\n * when there are no reviews to show and no Google average and total either, so the band renders nothing at all.\n * With no reviews but an average and total, the band shows the rating alone.\n */\nexport function prepareBusinessProfileReviews(\n feed: BusinessProfileReviews | null | undefined,\n options: PrepareBusinessProfileReviewsOptions,\n): PreparedBusinessProfileReviews | null {\n const exclude = assertSelectOptions(options)\n const mention = assertMention(options.mention)\n if (!feed) return null\n const ordered = orderBusinessProfileReviewsByMention(policyOrder(feed, options.policy), mention)\n const reviews = fillAvoidingExcluded(ordered, options.limit, exclude)\n const hasRating = feed.averageRating !== undefined && (feed.totalReviewCount ?? 0) > 0\n if (reviews.length === 0 && !hasRating) return null\n return {\n policy: options.policy,\n ...(feed.averageRating !== undefined ? { averageRating: feed.averageRating } : {}),\n ...(feed.totalReviewCount !== undefined ? { totalReviewCount: feed.totalReviewCount } : {}),\n profileUrl: feed.googleMapsUri,\n mention,\n reviews,\n }\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,47 @@
1
+ /**
2
+ * The media manifest (`src/data/media.ts`): one entry for every image a site renders (T6), keyed by a stable id, with
3
+ * its provenance, the job and suburb it shows, the month, the focal point, its alt text and the rights to use it.
4
+ * Location metadata is stripped from the files themselves (T9). Real job photos come first; stock and AI images are
5
+ * supporting only, and an AI image renders a visible "Illustration" label (F13).
6
+ */
7
+ export declare const BRANDLAB_MEDIA_PROVENANCES: readonly ["genuine", "stock", "illustrative-ai"];
8
+ export type BrandlabMediaProvenance = (typeof BRANDLAB_MEDIA_PROVENANCES)[number];
9
+ /** The frame ratios a component may crop to (F13). */
10
+ export declare const BRANDLAB_MEDIA_RATIOS: readonly ["16:9", "4:5", "4:3", "3:2"];
11
+ export type BrandlabMediaRatio = (typeof BRANDLAB_MEDIA_RATIOS)[number];
12
+ /** The point to keep in view when a frame crops the image, as percentages from the top left. */
13
+ export interface BrandlabFocalPoint {
14
+ readonly x: number;
15
+ readonly y: number;
16
+ }
17
+ /** One image in the manifest. */
18
+ export interface BrandlabMediaEntry {
19
+ /** The file under `/public` (for example `/images/jobs/castle-hill-kitchen.jpg`) or an absolute image URL. */
20
+ readonly src: string;
21
+ /** The file's intrinsic size in pixels. */
22
+ readonly width: number;
23
+ readonly height: number;
24
+ /** What the image shows, in Australian English. Empty only for a decorative image. */
25
+ readonly alt: string;
26
+ /** Pure decoration: renders with empty alt text. */
27
+ readonly decorative?: boolean;
28
+ readonly provenance: BrandlabMediaProvenance;
29
+ /** The job log row (`jobs.ts`) a genuine job photo comes from. */
30
+ readonly job?: string;
31
+ readonly suburb?: string;
32
+ /** When the work was done or the photo taken, YYYY-MM. */
33
+ readonly month?: string;
34
+ readonly focalPoint?: BrandlabFocalPoint;
35
+ /** Who holds the rights and on what basis, for example "Client-supplied via the drop folder, 12 Oct 2026". */
36
+ readonly rights: string;
37
+ }
38
+ /** A site's whole manifest, keyed by media id. */
39
+ export type BrandlabMediaManifest = Readonly<Record<string, BrandlabMediaEntry>>;
40
+ /** The ids of a manifest, for typed lookups: `BrandlabMediaId<typeof media>`. */
41
+ export type BrandlabMediaId<T extends BrandlabMediaManifest> = Extract<keyof T, string>;
42
+ /**
43
+ * Declares the site's media manifest (`src/data/media.ts`). Fails on malformed entries; returns the manifest as given,
44
+ * so its ids stay typed.
45
+ */
46
+ export declare function defineMedia<const T extends BrandlabMediaManifest>(media: T): T;
47
+ //# sourceMappingURL=media.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,0BAA0B,kDAAmD,CAAA;AAC1F,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAA;AAEjF,sDAAsD;AACtD,eAAO,MAAM,qBAAqB,wCAAyC,CAAA;AAC3E,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEvE,gGAAgG;AAChG,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,iCAAiC;AACjC,MAAM,WAAW,kBAAkB;IACjC,8GAA8G;IAC9G,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,sFAAsF;IACtF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,oDAAoD;IACpD,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;IAC7B,QAAQ,CAAC,UAAU,EAAE,uBAAuB,CAAA;IAC5C,kEAAkE;IAClE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,0DAA0D;IAC1D,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,kBAAkB,CAAA;IACxC,8GAA8G;IAC9G,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED,kDAAkD;AAClD,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAA;AAEhF,iFAAiF;AACjF,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAA;AAyCvF;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,CAAC,CAAC,SAAS,qBAAqB,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAS9E"}
package/dist/media.js ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The media manifest (`src/data/media.ts`): one entry for every image a site renders (T6), keyed by a stable id, with
3
+ * its provenance, the job and suburb it shows, the month, the focal point, its alt text and the rights to use it.
4
+ * Location metadata is stripped from the files themselves (T9). Real job photos come first; stock and AI images are
5
+ * supporting only, and an AI image renders a visible "Illustration" label (F13).
6
+ */
7
+ export const BRANDLAB_MEDIA_PROVENANCES = ['genuine', 'stock', 'illustrative-ai'];
8
+ /** The frame ratios a component may crop to (F13). */
9
+ export const BRANDLAB_MEDIA_RATIOS = ['16:9', '4:5', '4:3', '3:2'];
10
+ const MEDIA_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
11
+ const MONTH = /^\d{4}-(?:0[1-9]|1[0-2])$/;
12
+ function entryIssues(id, entry) {
13
+ const issues = [];
14
+ if (!MEDIA_ID.test(id))
15
+ issues.push('the id must be a lower-case slug.');
16
+ if (!entry || typeof entry !== 'object')
17
+ return [...issues, 'an entry is a record.'];
18
+ if (typeof entry.src !== 'string' || !/^(?:\/(?!\/)|https:\/\/)\S+$/.test(entry.src)) {
19
+ issues.push('src must be a /public path or an https URL.');
20
+ }
21
+ if (!Number.isInteger(entry.width) || entry.width <= 0 || !Number.isInteger(entry.height) || entry.height <= 0) {
22
+ issues.push('width and height must be whole pixel sizes.');
23
+ }
24
+ if (entry.decorative === true) {
25
+ if (entry.alt !== '')
26
+ issues.push('a decorative image has empty alt text.');
27
+ }
28
+ else if (typeof entry.alt !== 'string' || entry.alt.trim() === '' || entry.alt.length > 250) {
29
+ issues.push('alt must describe the image (at most 250 characters), or mark the image decorative.');
30
+ }
31
+ if (!BRANDLAB_MEDIA_PROVENANCES.includes(entry.provenance)) {
32
+ issues.push(`provenance must be one of ${BRANDLAB_MEDIA_PROVENANCES.join(', ')}.`);
33
+ }
34
+ if (entry.month !== undefined && (typeof entry.month !== 'string' || !MONTH.test(entry.month))) {
35
+ issues.push('month must be YYYY-MM.');
36
+ }
37
+ if (entry.focalPoint !== undefined) {
38
+ const { x, y } = entry.focalPoint;
39
+ const inRange = (value) => typeof value === 'number' && value >= 0 && value <= 100;
40
+ if (!inRange(x) || !inRange(y))
41
+ issues.push('focalPoint x and y are percentages from 0 to 100.');
42
+ }
43
+ for (const field of ['job', 'suburb']) {
44
+ const value = entry[field];
45
+ if (value !== undefined && (typeof value !== 'string' || value.trim() === ''))
46
+ issues.push(`${field} cannot be empty.`);
47
+ }
48
+ if (typeof entry.rights !== 'string' || entry.rights.trim() === '' || entry.rights.length > 300) {
49
+ issues.push('rights must say who holds them and on what basis (at most 300 characters).');
50
+ }
51
+ return issues;
52
+ }
53
+ /**
54
+ * Declares the site's media manifest (`src/data/media.ts`). Fails on malformed entries; returns the manifest as given,
55
+ * so its ids stay typed.
56
+ */
57
+ export function defineMedia(media) {
58
+ if (!media || typeof media !== 'object' || Array.isArray(media))
59
+ throw new Error('The media manifest is a record keyed by id.');
60
+ const issues = Object.entries(media).flatMap(([id, entry]) => entryIssues(id, entry).map((detail) => `- media.${id}: ${detail}`));
61
+ if (issues.length > 0) {
62
+ const shown = issues.slice(0, 20);
63
+ const more = issues.length > shown.length ? `\n- …and ${issues.length - shown.length} more` : '';
64
+ throw new Error(`Invalid media manifest:\n${shown.join('\n')}${more}`);
65
+ }
66
+ return media;
67
+ }
68
+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CAAC,EAAE,CAAA;QAChG,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,CAAA;IACxE,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["/**\n * The media manifest (`src/data/media.ts`): one entry for every image a site renders (T6), keyed by a stable id, with\n * its provenance, the job and suburb it shows, the month, the focal point, its alt text and the rights to use it.\n * Location metadata is stripped from the files themselves (T9). Real job photos come first; stock and AI images are\n * supporting only, and an AI image renders a visible \"Illustration\" label (F13).\n */\n\nexport const BRANDLAB_MEDIA_PROVENANCES = ['genuine', 'stock', 'illustrative-ai'] as const\nexport type BrandlabMediaProvenance = (typeof BRANDLAB_MEDIA_PROVENANCES)[number]\n\n/** The frame ratios a component may crop to (F13). */\nexport const BRANDLAB_MEDIA_RATIOS = ['16:9', '4:5', '4:3', '3:2'] as const\nexport type BrandlabMediaRatio = (typeof BRANDLAB_MEDIA_RATIOS)[number]\n\n/** The point to keep in view when a frame crops the image, as percentages from the top left. */\nexport interface BrandlabFocalPoint {\n readonly x: number\n readonly y: number\n}\n\n/** One image in the manifest. */\nexport interface BrandlabMediaEntry {\n /** The file under `/public` (for example `/images/jobs/castle-hill-kitchen.jpg`) or an absolute image URL. */\n readonly src: string\n /** The file's intrinsic size in pixels. */\n readonly width: number\n readonly height: number\n /** What the image shows, in Australian English. Empty only for a decorative image. */\n readonly alt: string\n /** Pure decoration: renders with empty alt text. */\n readonly decorative?: boolean\n readonly provenance: BrandlabMediaProvenance\n /** The job log row (`jobs.ts`) a genuine job photo comes from. */\n readonly job?: string\n readonly suburb?: string\n /** When the work was done or the photo taken, YYYY-MM. */\n readonly month?: string\n readonly focalPoint?: BrandlabFocalPoint\n /** Who holds the rights and on what basis, for example \"Client-supplied via the drop folder, 12 Oct 2026\". */\n readonly rights: string\n}\n\n/** A site's whole manifest, keyed by media id. */\nexport type BrandlabMediaManifest = Readonly<Record<string, BrandlabMediaEntry>>\n\n/** The ids of a manifest, for typed lookups: `BrandlabMediaId<typeof media>`. */\nexport type BrandlabMediaId<T extends BrandlabMediaManifest> = Extract<keyof T, string>\n\nconst MEDIA_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/\nconst MONTH = /^\\d{4}-(?:0[1-9]|1[0-2])$/\n\nfunction entryIssues(id: string, entry: BrandlabMediaEntry): string[] {\n const issues: string[] = []\n if (!MEDIA_ID.test(id)) issues.push('the id must be a lower-case slug.')\n if (!entry || typeof entry !== 'object') return [...issues, 'an entry is a record.']\n if (typeof entry.src !== 'string' || !/^(?:\\/(?!\\/)|https:\\/\\/)\\S+$/.test(entry.src)) {\n issues.push('src must be a /public path or an https URL.')\n }\n if (!Number.isInteger(entry.width) || entry.width <= 0 || !Number.isInteger(entry.height) || entry.height <= 0) {\n issues.push('width and height must be whole pixel sizes.')\n }\n if (entry.decorative === true) {\n if (entry.alt !== '') issues.push('a decorative image has empty alt text.')\n } else if (typeof entry.alt !== 'string' || entry.alt.trim() === '' || entry.alt.length > 250) {\n issues.push('alt must describe the image (at most 250 characters), or mark the image decorative.')\n }\n if (!(BRANDLAB_MEDIA_PROVENANCES as readonly string[]).includes(entry.provenance)) {\n issues.push(`provenance must be one of ${BRANDLAB_MEDIA_PROVENANCES.join(', ')}.`)\n }\n if (entry.month !== undefined && (typeof entry.month !== 'string' || !MONTH.test(entry.month))) {\n issues.push('month must be YYYY-MM.')\n }\n if (entry.focalPoint !== undefined) {\n const { x, y } = entry.focalPoint\n const inRange = (value: unknown) => typeof value === 'number' && value >= 0 && value <= 100\n if (!inRange(x) || !inRange(y)) issues.push('focalPoint x and y are percentages from 0 to 100.')\n }\n for (const field of ['job', 'suburb'] as const) {\n const value = entry[field]\n if (value !== undefined && (typeof value !== 'string' || value.trim() === '')) issues.push(`${field} cannot be empty.`)\n }\n if (typeof entry.rights !== 'string' || entry.rights.trim() === '' || entry.rights.length > 300) {\n issues.push('rights must say who holds them and on what basis (at most 300 characters).')\n }\n return issues\n}\n\n/**\n * Declares the site's media manifest (`src/data/media.ts`). Fails on malformed entries; returns the manifest as given,\n * so its ids stay typed.\n */\nexport function defineMedia<const T extends BrandlabMediaManifest>(media: T): T {\n if (!media || typeof media !== 'object' || Array.isArray(media)) throw new Error('The media manifest is a record keyed by id.')\n const issues = Object.entries(media).flatMap(([id, entry]) => entryIssues(id, entry).map((detail) => `- media.${id}: ${detail}`))\n if (issues.length > 0) {\n const shown = issues.slice(0, 20)\n const more = issues.length > shown.length ? `\\n- …and ${issues.length - shown.length} more` : ''\n throw new Error(`Invalid media manifest:\\n${shown.join('\\n')}${more}`)\n }\n return media\n}\n"]}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Typical prices (`src/data/prices.ts`). One band per job, site-wide, each with where its figures came from and when
3
+ * they were checked. A band renders only in a renderable status: confirmed by the owner, the business's own published
4
+ * prices, or researched bands Romie has signed off for that client (`romie-approved`, his accepted risk, dated by
5
+ * `checkedOn`). A `held` band never renders; the page links to the cost guide instead.
6
+ *
7
+ * Prices are labelled "Typical prices", never "{suburb} prices" or "market rates". A part price (a call-out fee, an
8
+ * hourly rate) only ever shows beside the full price of the job: NSW Fair Trading, "you cannot state a price that is
9
+ * only a part of the cost unless the single price is also clearly stated".
10
+ */
11
+ export declare const BRANDLAB_PRICE_STATUSES: readonly ["owner-confirmed", "published", "romie-approved", "held"];
12
+ export type BrandlabPriceStatus = (typeof BRANDLAB_PRICE_STATUSES)[number];
13
+ /** The statuses that may render on a page. */
14
+ export declare const RENDERABLE_PRICE_STATUSES: readonly ["owner-confirmed", "published", "romie-approved"];
15
+ /** The default caption of every price table. */
16
+ export declare const PRICE_CAPTION = "Typical prices";
17
+ /** A part of a job's price, such as a call-out fee. It only ever renders beside the job's full price. */
18
+ export interface BrandlabPricePart {
19
+ /** What the part covers, for example "Call-out fee" or "Each extra hour". */
20
+ readonly label: string;
21
+ readonly low: number;
22
+ /** The top of the part's band; omit for a fixed amount. */
23
+ readonly high?: number;
24
+ }
25
+ /** One row of `prices.ts` as a site writes it. */
26
+ export interface BrandlabPriceInput {
27
+ /** The service slug the band belongs to (its money-service page). */
28
+ readonly service: string;
29
+ /** The job the band prices, for example "Single tree removal up to 10 m". One band per job, site-wide. */
30
+ readonly job: string;
31
+ /** The full price in dollars: the bottom and the top of the typical band. */
32
+ readonly low: number;
33
+ readonly high: number;
34
+ /** What the band is per when it isn't the whole job, for example "per square metre". */
35
+ readonly unit?: string;
36
+ readonly includes?: readonly string[];
37
+ readonly excludes?: readonly string[];
38
+ /** Whether the figures include GST. Defaults to true. */
39
+ readonly gstIncluded?: boolean;
40
+ /** Parts of the price (a call-out fee, an hourly rate), shown only beside the full price. */
41
+ readonly parts?: readonly BrandlabPricePart[];
42
+ readonly status: BrandlabPriceStatus;
43
+ /** Where the figures came from: the owner's answer, the published price list or Romie's sign-off. */
44
+ readonly source: string;
45
+ /** When the band was last checked, YYYY-MM-DD. */
46
+ readonly checkedOn: string;
47
+ }
48
+ /** A validated price row, with its defaults applied. */
49
+ export interface BrandlabPrice extends Readonly<Omit<BrandlabPriceInput, 'gstIncluded' | 'includes' | 'excludes' | 'parts'>> {
50
+ readonly gstIncluded: boolean;
51
+ readonly includes: readonly string[];
52
+ readonly excludes: readonly string[];
53
+ readonly parts: readonly BrandlabPricePart[];
54
+ }
55
+ export interface BrandlabPriceIssue {
56
+ readonly index: number;
57
+ readonly job: string;
58
+ readonly detail: string;
59
+ }
60
+ /**
61
+ * Every problem in a price list: malformed rows, part prices above the full price, "market" wording and any job priced
62
+ * twice (one band per job, site-wide).
63
+ */
64
+ export declare function validatePrices(rows: readonly BrandlabPriceInput[]): BrandlabPriceIssue[];
65
+ /**
66
+ * Declares the site's typical prices (`src/data/prices.ts`). Fails on malformed rows, part prices above the full
67
+ * price, "market" wording and duplicate jobs; fills `gstIncluded` (true), `includes`, `excludes` and `parts`.
68
+ */
69
+ export declare function definePrices(rows: readonly BrandlabPriceInput[]): readonly BrandlabPrice[];
70
+ /** Whether a band may render: owner-confirmed, published or romie-approved. `held` never renders. */
71
+ export declare function isRenderablePrice(price: Pick<BrandlabPrice, 'status'>): boolean;
72
+ /** The bands a page may show, in file order, optionally for one service. */
73
+ export declare function renderablePrices<T extends Pick<BrandlabPrice, 'status' | 'service'>>(prices: readonly T[], service?: string): T[];
74
+ /** Whole dollars as "$1,200"; cents only when the amount has them ("$89.50"). */
75
+ export declare function formatAud(amount: number): string;
76
+ /** A band as "$1,200–$2,500", or one figure when the bottom and top match. Never "from $X". */
77
+ export declare function formatPriceBand(band: {
78
+ readonly low: number;
79
+ readonly high?: number | undefined;
80
+ }): string;
81
+ /**
82
+ * Whether a price table caption keeps to the rule: "Typical prices", or "Typical {service} prices" where {service} is
83
+ * one of the given service slugs with hyphens as spaces ("Typical tree removal prices" for `tree-removal`). A place
84
+ * name ("Typical parramatta prices") or "market rates" never passes.
85
+ */
86
+ export declare function isAllowedPriceCaption(caption: string, services?: readonly string[]): boolean;
87
+ /** Throws when a caption breaks the "Typical prices" rule. */
88
+ export declare function assertPriceCaption(caption: string, services?: readonly string[]): void;
89
+ /** Throws when a GST flag label is missing "GST" or reads as a "+ GST" teaser. */
90
+ export declare function assertGstLabel(label: string, field?: string): void;
91
+ //# sourceMappingURL=prices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prices.d.ts","sourceRoot":"","sources":["../src/prices.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,eAAO,MAAM,uBAAuB,qEAAsE,CAAA;AAC1G,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE1E,8CAA8C;AAC9C,eAAO,MAAM,yBAAyB,6DAAuG,CAAA;AAE7I,gDAAgD;AAChD,eAAO,MAAM,aAAa,mBAAmB,CAAA;AAE7C,yGAAyG;AACzG,MAAM,WAAW,iBAAiB;IAChC,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,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