@brandlab-digital/site-core 3.12.1 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +80 -0
  2. package/dist/business.d.ts +81 -0
  3. package/dist/business.d.ts.map +1 -1
  4. package/dist/business.js +116 -0
  5. package/dist/business.js.map +1 -1
  6. package/dist/council-register.d.ts +53 -0
  7. package/dist/council-register.d.ts.map +1 -0
  8. package/dist/council-register.js +113 -0
  9. package/dist/council-register.js.map +1 -0
  10. package/dist/google-business-reviews-refresh.d.ts +93 -0
  11. package/dist/google-business-reviews-refresh.d.ts.map +1 -0
  12. package/dist/google-business-reviews-refresh.js +140 -0
  13. package/dist/google-business-reviews-refresh.js.map +1 -0
  14. package/dist/google-business-reviews.d.ts +1 -0
  15. package/dist/google-business-reviews.d.ts.map +1 -1
  16. package/dist/google-business-reviews.js +1 -0
  17. package/dist/google-business-reviews.js.map +1 -1
  18. package/dist/jobs.d.ts +71 -0
  19. package/dist/jobs.d.ts.map +1 -0
  20. package/dist/jobs.js +107 -0
  21. package/dist/jobs.js.map +1 -0
  22. package/dist/locations.d.ts +10 -0
  23. package/dist/locations.d.ts.map +1 -1
  24. package/dist/locations.js +15 -0
  25. package/dist/locations.js.map +1 -1
  26. package/dist/navigation.d.ts +37 -1
  27. package/dist/navigation.d.ts.map +1 -1
  28. package/dist/navigation.js +107 -2
  29. package/dist/navigation.js.map +1 -1
  30. package/dist/page-titles.d.ts +71 -0
  31. package/dist/page-titles.d.ts.map +1 -0
  32. package/dist/page-titles.js +161 -0
  33. package/dist/page-titles.js.map +1 -0
  34. package/dist/project.d.ts +76 -0
  35. package/dist/project.d.ts.map +1 -1
  36. package/dist/project.js +177 -1
  37. package/dist/project.js.map +1 -1
  38. package/dist/section-order.d.ts +47 -2
  39. package/dist/section-order.d.ts.map +1 -1
  40. package/dist/section-order.js +96 -3
  41. package/dist/section-order.js.map +1 -1
  42. package/dist/site.d.ts +9 -0
  43. package/dist/site.d.ts.map +1 -1
  44. package/dist/site.js +19 -0
  45. package/dist/site.js.map +1 -1
  46. package/dist/strategy.d.ts +172 -0
  47. package/dist/strategy.d.ts.map +1 -1
  48. package/dist/strategy.js +300 -2
  49. package/dist/strategy.js.map +1 -1
  50. package/package.json +13 -1
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Refreshing pages when a site's Google reviews change, not on a timer (Brandlab 3.13.0). The daily reviews checker
3
+ * hashes each site's feed with `hashBusinessProfileReviews` and, only when the hash differs from the last one it
4
+ * delivered, signs a request with `signBusinessProfileReviewsRevalidate` and posts it to the site's revalidate route
5
+ * (`createBrandlabReviewsRevalidateRoute` in `site-next/google-business-reviews/server`). The route then invalidates
6
+ * the `brandlab-reviews:<site>` fetch tag, so only pages that show the reviews are rewritten, once per real change.
7
+ *
8
+ * Both helpers are pure apart from Web Crypto, so the feed side and the site share one definition.
9
+ */
10
+ /** Bumped when the normalised form changes, so an old hash never matches a new one by accident. */
11
+ export declare const BUSINESS_PROFILE_REVIEWS_HASH_VERSION = 1;
12
+ /** Every reviews fetch carries this tag, so one call can refresh every site's reviews in a deployment. */
13
+ export declare const BUSINESS_PROFILE_REVIEWS_TAG = "brandlab-reviews";
14
+ /** The request headers the revalidate route reads: Unix seconds, and `v1=<hex HMAC-SHA256>`. */
15
+ export declare const BUSINESS_PROFILE_REVIEWS_REVALIDATE_HEADERS: {
16
+ readonly timestamp: "x-brandlab-timestamp";
17
+ readonly signature: "x-brandlab-signature";
18
+ };
19
+ /** The route's environment variable holding the shared signing secret. Never in git. */
20
+ export declare const BUSINESS_PROFILE_REVIEWS_REVALIDATE_SECRET_NAME = "BRANDLAB_REVALIDATE_SECRET";
21
+ /** The route path a site serves the revalidate route at. */
22
+ export declare const BUSINESS_PROFILE_REVIEWS_REVALIDATE_PATH = "/api/brandlab/reviews-revalidate";
23
+ /** The site's own fetch tag, `brandlab-reviews:<site>`. */
24
+ export declare function businessProfileReviewsSiteTag(site: string): string;
25
+ /** The tags the shared reviews fetch carries for a site. */
26
+ export declare function businessProfileReviewsTags(site: string): [string, string];
27
+ /**
28
+ * The parts of a reviews feed answer that change what a page shows. Extra fields are ignored. `reply` and
29
+ * `updateTime` are read when the feed sends them (the 23 Oct 2026 feed sends neither yet).
30
+ */
31
+ export interface BusinessProfileReviewsHashInput {
32
+ averageRating?: number | null;
33
+ totalReviewCount?: number | null;
34
+ reviews: readonly {
35
+ id: string;
36
+ rating?: number | null;
37
+ text?: string | null;
38
+ authorName?: string | null;
39
+ createTime?: string | null;
40
+ updateTime?: string | null;
41
+ reply?: string | {
42
+ comment?: string | null;
43
+ updateTime?: string | null;
44
+ } | null;
45
+ }[];
46
+ }
47
+ /**
48
+ * The normalised review list as one canonical string: the aggregate rating and count, then each review's id, rating,
49
+ * text, author, create and update times and reply, sorted by id. Whitespace runs and Unicode composition do not
50
+ * change it; the order the feed lists reviews in does not either.
51
+ */
52
+ export declare function normaliseBusinessProfileReviews(feed: BusinessProfileReviewsHashInput): string;
53
+ /** SHA-256 of the normalised review list, as 64 lowercase hex characters. */
54
+ export declare function hashBusinessProfileReviews(feed: BusinessProfileReviewsHashInput): Promise<string>;
55
+ /** The body the revalidate route accepts. */
56
+ export interface BusinessProfileReviewsRevalidateBody {
57
+ site: string;
58
+ /** `hashBusinessProfileReviews` of the feed the site should now show. */
59
+ hash: string;
60
+ }
61
+ export declare const BUSINESS_PROFILE_REVIEWS_HASH_PATTERN: RegExp;
62
+ /**
63
+ * The signing secret as both sides use it: surrounding whitespace (a trailing newline pasted into an environment
64
+ * variable, say) is dropped, so the checker and the route sign with the same key.
65
+ */
66
+ export declare function normaliseBusinessProfileReviewsRevalidateSecret(secret: string): string;
67
+ /**
68
+ * The HMAC-SHA256 of `<timestamp>.<body>` under the shared secret (normalised with
69
+ * `normaliseBusinessProfileReviewsRevalidateSecret`), as the signature header value `v1=<hex>`. The secret never
70
+ * travels with the request.
71
+ */
72
+ export declare function signBusinessProfileReviewsRevalidate(input: {
73
+ secret: string;
74
+ /** The exact request body that will be sent. */
75
+ body: string;
76
+ /** Unix seconds; the route refuses a request more than 5 minutes either side of its clock. */
77
+ timestamp: number;
78
+ }): Promise<string>;
79
+ /**
80
+ * A ready-to-send revalidate request for the daily checker: the JSON body, and the headers with a fresh timestamp
81
+ * and signature. POST it to `https://<site>${BUSINESS_PROFILE_REVIEWS_REVALIDATE_PATH}`.
82
+ */
83
+ export declare function createBusinessProfileReviewsRevalidateRequest(input: {
84
+ site: string;
85
+ hash: string;
86
+ secret: string;
87
+ /** Unix seconds; defaults to now. */
88
+ timestamp?: number;
89
+ }): Promise<{
90
+ body: string;
91
+ headers: Record<string, string>;
92
+ }>;
93
+ //# sourceMappingURL=google-business-reviews-refresh.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-business-reviews-refresh.d.ts","sourceRoot":"","sources":["../src/google-business-reviews-refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,mGAAmG;AACnG,eAAO,MAAM,qCAAqC,IAAI,CAAA;AAEtD,0GAA0G;AAC1G,eAAO,MAAM,4BAA4B,qBAAqB,CAAA;AAE9D,gGAAgG;AAChG,eAAO,MAAM,2CAA2C;;;CAG9C,CAAA;AAEV,wFAAwF;AACxF,eAAO,MAAM,+CAA+C,+BAA+B,CAAA;AAE3F,4DAA4D;AAC5D,eAAO,MAAM,wCAAwC,qCAAqC,CAAA;AAI1F,2DAA2D;AAC3D,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKlE;AAED,4DAA4D;AAC5D,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAEzE;AAED;;;GAGG;AACH,MAAM,WAAW,+BAA+B;IAC9C,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,OAAO,EAAE,SAAS;Q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CAAA;IACd,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAC,CAmB7D"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Refreshing pages when a site's Google reviews change, not on a timer (Brandlab 3.13.0). The daily reviews checker
3
+ * hashes each site's feed with `hashBusinessProfileReviews` and, only when the hash differs from the last one it
4
+ * delivered, signs a request with `signBusinessProfileReviewsRevalidate` and posts it to the site's revalidate route
5
+ * (`createBrandlabReviewsRevalidateRoute` in `site-next/google-business-reviews/server`). The route then invalidates
6
+ * the `brandlab-reviews:<site>` fetch tag, so only pages that show the reviews are rewritten, once per real change.
7
+ *
8
+ * Both helpers are pure apart from Web Crypto, so the feed side and the site share one definition.
9
+ */
10
+ /** Bumped when the normalised form changes, so an old hash never matches a new one by accident. */
11
+ export const BUSINESS_PROFILE_REVIEWS_HASH_VERSION = 1;
12
+ /** Every reviews fetch carries this tag, so one call can refresh every site's reviews in a deployment. */
13
+ export const BUSINESS_PROFILE_REVIEWS_TAG = 'brandlab-reviews';
14
+ /** The request headers the revalidate route reads: Unix seconds, and `v1=<hex HMAC-SHA256>`. */
15
+ export const BUSINESS_PROFILE_REVIEWS_REVALIDATE_HEADERS = {
16
+ timestamp: 'x-brandlab-timestamp',
17
+ signature: 'x-brandlab-signature',
18
+ };
19
+ /** The route's environment variable holding the shared signing secret. Never in git. */
20
+ export const BUSINESS_PROFILE_REVIEWS_REVALIDATE_SECRET_NAME = 'BRANDLAB_REVALIDATE_SECRET';
21
+ /** The route path a site serves the revalidate route at. */
22
+ export const BUSINESS_PROFILE_REVIEWS_REVALIDATE_PATH = '/api/brandlab/reviews-revalidate';
23
+ const SITE_SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
24
+ /** The site's own fetch tag, `brandlab-reviews:<site>`. */
25
+ export function businessProfileReviewsSiteTag(site) {
26
+ if (typeof site !== 'string' || !SITE_SLUG.test(site)) {
27
+ throw new Error('Business Profile reviews site must be a lowercase kebab-case slug.');
28
+ }
29
+ return `${BUSINESS_PROFILE_REVIEWS_TAG}:${site}`;
30
+ }
31
+ /** The tags the shared reviews fetch carries for a site. */
32
+ export function businessProfileReviewsTags(site) {
33
+ return [BUSINESS_PROFILE_REVIEWS_TAG, businessProfileReviewsSiteTag(site)];
34
+ }
35
+ function clean(value) {
36
+ return typeof value === 'string' ? value.normalize('NFC').replace(/\s+/g, ' ').trim() || null : null;
37
+ }
38
+ function numberOrNull(value) {
39
+ return typeof value === 'number' && Number.isFinite(value) ? value : null;
40
+ }
41
+ function toHex(buffer) {
42
+ return Array.from(new Uint8Array(buffer), (byte) => byte.toString(16).padStart(2, '0')).join('');
43
+ }
44
+ function subtle() {
45
+ const value = globalThis.crypto?.subtle;
46
+ if (!value)
47
+ throw new Error('A Web Crypto implementation is required.');
48
+ return value;
49
+ }
50
+ /**
51
+ * The normalised review list as one canonical string: the aggregate rating and count, then each review's id, rating,
52
+ * text, author, create and update times and reply, sorted by id. Whitespace runs and Unicode composition do not
53
+ * change it; the order the feed lists reviews in does not either.
54
+ */
55
+ export function normaliseBusinessProfileReviews(feed) {
56
+ if (!feed || typeof feed !== 'object' || !Array.isArray(feed.reviews)) {
57
+ throw new Error('Business Profile reviews to hash must have a review list.');
58
+ }
59
+ const reviews = feed.reviews.map((review) => {
60
+ if (!review || typeof review.id !== 'string' || !review.id.trim()) {
61
+ throw new Error('Every Business Profile review to hash needs an id.');
62
+ }
63
+ const reply = review.reply;
64
+ const replyText = typeof reply === 'string' ? clean(reply) : clean(reply?.comment);
65
+ const replyTime = typeof reply === 'object' && reply !== null ? clean(reply.updateTime) : null;
66
+ return [
67
+ review.id.trim(),
68
+ numberOrNull(review.rating),
69
+ clean(review.text),
70
+ clean(review.authorName),
71
+ clean(review.createTime),
72
+ clean(review.updateTime),
73
+ replyText,
74
+ replyTime,
75
+ ];
76
+ });
77
+ reviews.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
78
+ return JSON.stringify([
79
+ BUSINESS_PROFILE_REVIEWS_HASH_VERSION,
80
+ numberOrNull(feed.averageRating),
81
+ numberOrNull(feed.totalReviewCount),
82
+ reviews,
83
+ ]);
84
+ }
85
+ /** SHA-256 of the normalised review list, as 64 lowercase hex characters. */
86
+ export async function hashBusinessProfileReviews(feed) {
87
+ const digest = await subtle().digest('SHA-256', new TextEncoder().encode(normaliseBusinessProfileReviews(feed)));
88
+ return toHex(digest);
89
+ }
90
+ export const BUSINESS_PROFILE_REVIEWS_HASH_PATTERN = /^[0-9a-f]{64}$/;
91
+ /**
92
+ * The signing secret as both sides use it: surrounding whitespace (a trailing newline pasted into an environment
93
+ * variable, say) is dropped, so the checker and the route sign with the same key.
94
+ */
95
+ export function normaliseBusinessProfileReviewsRevalidateSecret(secret) {
96
+ return typeof secret === 'string' ? secret.trim() : '';
97
+ }
98
+ /**
99
+ * The HMAC-SHA256 of `<timestamp>.<body>` under the shared secret (normalised with
100
+ * `normaliseBusinessProfileReviewsRevalidateSecret`), as the signature header value `v1=<hex>`. The secret never
101
+ * travels with the request.
102
+ */
103
+ export async function signBusinessProfileReviewsRevalidate(input) {
104
+ const secret = normaliseBusinessProfileReviewsRevalidateSecret(input.secret);
105
+ if (secret.length < 32) {
106
+ throw new Error('The revalidate secret must be at least 32 characters.');
107
+ }
108
+ if (!Number.isSafeInteger(input.timestamp) || input.timestamp < 0) {
109
+ throw new Error('The revalidate timestamp must be whole Unix seconds.');
110
+ }
111
+ const crypto = subtle();
112
+ const key = await crypto.importKey('raw', new TextEncoder().encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
113
+ const signature = await crypto.sign('HMAC', key, new TextEncoder().encode(`${input.timestamp}.${input.body}`));
114
+ return `v1=${toHex(signature)}`;
115
+ }
116
+ /**
117
+ * A ready-to-send revalidate request for the daily checker: the JSON body, and the headers with a fresh timestamp
118
+ * and signature. POST it to `https://<site>${BUSINESS_PROFILE_REVIEWS_REVALIDATE_PATH}`.
119
+ */
120
+ export async function createBusinessProfileReviewsRevalidateRequest(input) {
121
+ businessProfileReviewsSiteTag(input.site);
122
+ if (typeof input.hash !== 'string' || !BUSINESS_PROFILE_REVIEWS_HASH_PATTERN.test(input.hash)) {
123
+ throw new Error('The reviews hash must be 64 lowercase hex characters from hashBusinessProfileReviews.');
124
+ }
125
+ const timestamp = input.timestamp ?? Math.floor(Date.now() / 1_000);
126
+ const body = JSON.stringify({ site: input.site, hash: input.hash });
127
+ return {
128
+ body,
129
+ headers: {
130
+ 'content-type': 'application/json',
131
+ [BUSINESS_PROFILE_REVIEWS_REVALIDATE_HEADERS.timestamp]: String(timestamp),
132
+ [BUSINESS_PROFILE_REVIEWS_REVALIDATE_HEADERS.signature]: await signBusinessProfileReviewsRevalidate({
133
+ secret: input.secret,
134
+ body,
135
+ timestamp,
136
+ }),
137
+ },
138
+ };
139
+ }
140
+ //# sourceMappingURL=google-business-reviews-refresh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-business-reviews-refresh.js","sourceRoot":"","sources":["../src/google-business-reviews-refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,mGAAmG;AACnG,MAAM,CAAC,MAAM,qCAAqC,GAAG,CAAC,CAAA;AAEtD,0GAA0G;AAC1G,MAAM,CAAC,MAAM,4BAA4B,GAAG,kBAAkB,CAAA;AAE9D,gGAAgG;AAChG,MAAM,CAAC,MAAM,2CAA2C,GAAG;IACzD,SAAS,EAAE,sBAAsB;IACjC,SAAS,EAAE,sBAAsB;CACzB,CAAA;AAEV,wFAAwF;AACxF,MAAM,CAAC,MAAM,+CAA+C,GAAG,4BAA4B,CAAA;AAE3F,4DAA4D;AAC5D,MAAM,CAAC,MAAM,wCAAwC,GAAG,kCAAkC,CAAA;AAE1F,MAAM,SAAS,GAAG,4BAA4B,CAAA;AAE9C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AAI,EAAiD,CAAC,CAAA;IAClH,OAAO;QACL,IAAI;QACJ,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,CAAC,2CAA2C,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC;YAC1E,CAAC,2CAA2C,CAAC,SAAS,CAAC,EAAE,MAAM,oCAAoC,CAAC;gBAClG,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,IAAI;gBACJ,SAAS;aACV,CAAC;SACH;KACF,CAAA;AACH,CAAC","sourcesContent":["/**\n * Refreshing pages when a site's Google reviews change, not on a timer (Brandlab 3.13.0). The daily reviews checker\n * hashes each site's feed with `hashBusinessProfileReviews` and, only when the hash differs from the last one it\n * delivered, signs a request with `signBusinessProfileReviewsRevalidate` and posts it to the site's revalidate route\n * (`createBrandlabReviewsRevalidateRoute` in `site-next/google-business-reviews/server`). The route then invalidates\n * the `brandlab-reviews:<site>` fetch tag, so only pages that show the reviews are rewritten, once per real change.\n *\n * Both helpers are pure apart from Web Crypto, so the feed side and the site share one definition.\n */\n\n/** Bumped when the normalised form changes, so an old hash never matches a new one by accident. */\nexport const BUSINESS_PROFILE_REVIEWS_HASH_VERSION = 1\n\n/** Every reviews fetch carries this tag, so one call can refresh every site's reviews in a deployment. */\nexport const BUSINESS_PROFILE_REVIEWS_TAG = 'brandlab-reviews'\n\n/** The request headers the revalidate route reads: Unix seconds, and `v1=<hex HMAC-SHA256>`. */\nexport const BUSINESS_PROFILE_REVIEWS_REVALIDATE_HEADERS = {\n timestamp: 'x-brandlab-timestamp',\n signature: 'x-brandlab-signature',\n} as const\n\n/** The route's environment variable holding the shared signing secret. Never in git. */\nexport const BUSINESS_PROFILE_REVIEWS_REVALIDATE_SECRET_NAME = 'BRANDLAB_REVALIDATE_SECRET'\n\n/** The route path a site serves the revalidate route at. */\nexport const BUSINESS_PROFILE_REVIEWS_REVALIDATE_PATH = '/api/brandlab/reviews-revalidate'\n\nconst SITE_SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/\n\n/** The site's own fetch tag, `brandlab-reviews:<site>`. */\nexport function businessProfileReviewsSiteTag(site: string): string {\n if (typeof site !== 'string' || !SITE_SLUG.test(site)) {\n throw new Error('Business Profile reviews site must be a lowercase kebab-case slug.')\n }\n return `${BUSINESS_PROFILE_REVIEWS_TAG}:${site}`\n}\n\n/** The tags the shared reviews fetch carries for a site. */\nexport function businessProfileReviewsTags(site: string): [string, string] {\n return [BUSINESS_PROFILE_REVIEWS_TAG, businessProfileReviewsSiteTag(site)]\n}\n\n/**\n * The parts of a reviews feed answer that change what a page shows. Extra fields are ignored. `reply` and\n * `updateTime` are read when the feed sends them (the 23 Oct 2026 feed sends neither yet).\n */\nexport interface BusinessProfileReviewsHashInput {\n averageRating?: number | null\n totalReviewCount?: number | null\n reviews: readonly {\n id: string\n rating?: number | null\n text?: string | null\n authorName?: string | null\n createTime?: string | null\n updateTime?: string | null\n reply?: string | { comment?: string | null; updateTime?: string | null } | null\n }[]\n}\n\nfunction clean(value: unknown): string | null {\n return typeof value === 'string' ? value.normalize('NFC').replace(/\\s+/g, ' ').trim() || null : null\n}\n\nfunction numberOrNull(value: unknown): number | null {\n return typeof value === 'number' && Number.isFinite(value) ? value : null\n}\n\nfunction toHex(buffer: ArrayBuffer): string {\n return Array.from(new Uint8Array(buffer), (byte) => byte.toString(16).padStart(2, '0')).join('')\n}\n\nfunction subtle(): SubtleCrypto {\n const value = globalThis.crypto?.subtle\n if (!value) throw new Error('A Web Crypto implementation is required.')\n return value\n}\n\n/**\n * The normalised review list as one canonical string: the aggregate rating and count, then each review's id, rating,\n * text, author, create and update times and reply, sorted by id. Whitespace runs and Unicode composition do not\n * change it; the order the feed lists reviews in does not either.\n */\nexport function normaliseBusinessProfileReviews(feed: BusinessProfileReviewsHashInput): string {\n if (!feed || typeof feed !== 'object' || !Array.isArray(feed.reviews)) {\n throw new Error('Business Profile reviews to hash must have a review list.')\n }\n const reviews = feed.reviews.map((review) => {\n if (!review || typeof review.id !== 'string' || !review.id.trim()) {\n throw new Error('Every Business Profile review to hash needs an id.')\n }\n const reply = review.reply\n const replyText = typeof reply === 'string' ? clean(reply) : clean(reply?.comment)\n const replyTime = typeof reply === 'object' && reply !== null ? clean(reply.updateTime) : null\n return [\n review.id.trim(),\n numberOrNull(review.rating),\n clean(review.text),\n clean(review.authorName),\n clean(review.createTime),\n clean(review.updateTime),\n replyText,\n replyTime,\n ] as const\n })\n reviews.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0))\n return JSON.stringify([\n BUSINESS_PROFILE_REVIEWS_HASH_VERSION,\n numberOrNull(feed.averageRating),\n numberOrNull(feed.totalReviewCount),\n reviews,\n ])\n}\n\n/** SHA-256 of the normalised review list, as 64 lowercase hex characters. */\nexport async function hashBusinessProfileReviews(feed: BusinessProfileReviewsHashInput): Promise<string> {\n const digest = await subtle().digest('SHA-256', new TextEncoder().encode(normaliseBusinessProfileReviews(feed)))\n return toHex(digest)\n}\n\n/** The body the revalidate route accepts. */\nexport interface BusinessProfileReviewsRevalidateBody {\n site: string\n /** `hashBusinessProfileReviews` of the feed the site should now show. */\n hash: string\n}\n\nexport const BUSINESS_PROFILE_REVIEWS_HASH_PATTERN = /^[0-9a-f]{64}$/\n\n/**\n * The signing secret as both sides use it: surrounding whitespace (a trailing newline pasted into an environment\n * variable, say) is dropped, so the checker and the route sign with the same key.\n */\nexport function normaliseBusinessProfileReviewsRevalidateSecret(secret: string): string {\n return typeof secret === 'string' ? secret.trim() : ''\n}\n\n/**\n * The HMAC-SHA256 of `<timestamp>.<body>` under the shared secret (normalised with\n * `normaliseBusinessProfileReviewsRevalidateSecret`), as the signature header value `v1=<hex>`. The secret never\n * travels with the request.\n */\nexport async function signBusinessProfileReviewsRevalidate(input: {\n secret: string\n /** The exact request body that will be sent. */\n body: string\n /** Unix seconds; the route refuses a request more than 5 minutes either side of its clock. */\n timestamp: number\n}): Promise<string> {\n const secret = normaliseBusinessProfileReviewsRevalidateSecret(input.secret)\n if (secret.length < 32) {\n throw new Error('The revalidate secret must be at least 32 characters.')\n }\n if (!Number.isSafeInteger(input.timestamp) || input.timestamp < 0) {\n throw new Error('The revalidate timestamp must be whole Unix seconds.')\n }\n const crypto = subtle()\n const key = await crypto.importKey(\n 'raw',\n new TextEncoder().encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['sign'],\n )\n const signature = await crypto.sign('HMAC', key, new TextEncoder().encode(`${input.timestamp}.${input.body}`))\n return `v1=${toHex(signature)}`\n}\n\n/**\n * A ready-to-send revalidate request for the daily checker: the JSON body, and the headers with a fresh timestamp\n * and signature. POST it to `https://<site>${BUSINESS_PROFILE_REVIEWS_REVALIDATE_PATH}`.\n */\nexport async function createBusinessProfileReviewsRevalidateRequest(input: {\n site: string\n hash: string\n secret: string\n /** Unix seconds; defaults to now. */\n timestamp?: number\n}): Promise<{ body: string; headers: Record<string, string> }> {\n businessProfileReviewsSiteTag(input.site)\n if (typeof input.hash !== 'string' || !BUSINESS_PROFILE_REVIEWS_HASH_PATTERN.test(input.hash)) {\n throw new Error('The reviews hash must be 64 lowercase hex characters from hashBusinessProfileReviews.')\n }\n const timestamp = input.timestamp ?? Math.floor(Date.now() / 1_000)\n const body = JSON.stringify({ site: input.site, hash: input.hash } satisfies BusinessProfileReviewsRevalidateBody)\n return {\n body,\n headers: {\n 'content-type': 'application/json',\n [BUSINESS_PROFILE_REVIEWS_REVALIDATE_HEADERS.timestamp]: String(timestamp),\n [BUSINESS_PROFILE_REVIEWS_REVALIDATE_HEADERS.signature]: await signBusinessProfileReviewsRevalidate({\n secret: input.secret,\n body,\n timestamp,\n }),\n },\n }\n}\n"]}
@@ -122,4 +122,5 @@ export declare function prepareBusinessProfileReviews(feed: BusinessProfileRevie
122
122
  * `selectBusinessProfileReviews` kept an excluded review because too few others remained. Sites can log it or test it.
123
123
  */
124
124
  export declare function excludedBusinessProfileReviewsShown(shown: readonly BusinessProfileReview[], exclude: readonly BusinessProfileReviewExclusion[] | undefined): ExcludedBusinessProfileReviewShown[];
125
+ export * from './google-business-reviews-refresh.js';
125
126
  //# 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;;;;;GAKG;AACH,MAAM,MAAM,8BAA8B,GACtC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAE5D,MAAM,WAAW,mCAAmC;IAClD,MAAM,EAAE,4BAA4B,CAAA;IACpC,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,8BAA8B,EAAE,CAAA;CACpD;AAED,qGAA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,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;AAED,cAAc,sCAAsC,CAAA"}
@@ -249,4 +249,5 @@ export function excludedBusinessProfileReviewsShown(shown, exclude) {
249
249
  return exclusion ? [{ review, exclusion }] : [];
250
250
  });
251
251
  }
252
+ export * from './google-business-reviews-refresh.js';
252
253
  //# 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;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,CAA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AE,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"]}
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,IA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AAI,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAA;IACnD,OAAO;QACL,MAAM,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;AAED,cAAc,sCAAsC,CAAA","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\nexport * from './google-business-reviews-refresh.js'\n"]}
package/dist/jobs.d.ts ADDED
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The job log (`src/data/jobs.ts`, 3.14.0): one row per completed job the owner has confirmed, shared by `NearbyJobs`,
3
+ * project cards, the area map's job places and head-tier decisions. A job names its suburb (registry slug), service
4
+ * and what was done; its month is optional, because owners often remember the job but not when (a card then shows the
5
+ * suburb without a date: "Recent tree removal nearby: Ryde"). Photos are media-manifest ids, so each carries its
6
+ * provenance; only genuine photos of that job may illustrate it.
7
+ *
8
+ * Distances rank job cards and are never printed: location copy carries no kilometre figures (L10).
9
+ */
10
+ import type { SuburbCentreLookup } from './locations.js';
11
+ import type { BrandlabMediaEntry, BrandlabMediaManifest } from './media.js';
12
+ export interface BrandlabJob {
13
+ /** A stable kebab-case id; genuine photos of the job name it in their media entry's `job`. */
14
+ readonly id: string;
15
+ /** The registry suburb slug, for example "ryde". */
16
+ readonly suburb: string;
17
+ /** The service slug, as the site's service catalogue names it. */
18
+ readonly service: string;
19
+ /** What was done, in one line of Australian English. */
20
+ readonly outcome: string;
21
+ /** YYYY-MM, when the owner knows it. */
22
+ readonly month?: string;
23
+ /** Media-manifest ids of genuine photos of this job. */
24
+ readonly photos?: readonly string[];
25
+ /** Who confirmed the job and when, for example "Owner, WhatsApp 3 Oct 2026". */
26
+ readonly source: string;
27
+ }
28
+ /** Job cards show jobs within this distance of the page's suburb (v2: the 10 km cap on job cards). */
29
+ export declare const JOB_CARD_MAX_KM = 10;
30
+ /** Cards per page (playbook: 1 to 3). */
31
+ export declare const JOB_CARD_LIMIT = 3;
32
+ /**
33
+ * Validates the job log. With the media manifest, every photo must exist, be `genuine` (stock and AI images never
34
+ * stand for the client's work) and, when its entry names a job, name this one.
35
+ */
36
+ export declare function defineJobs<const T extends readonly BrandlabJob[]>(jobs: T, options?: {
37
+ readonly media?: BrandlabMediaManifest;
38
+ }): T;
39
+ /** A job's photos from the media manifest, in order, with their ids and provenance. */
40
+ export declare function jobPhotos(job: BrandlabJob, media: BrandlabMediaManifest): (BrandlabMediaEntry & {
41
+ readonly id: string;
42
+ })[];
43
+ /**
44
+ * A job card's label: "Recent {service} in {Suburb}" for the page's own suburb, "Recent {service} nearby: {Suburb}"
45
+ * for any other (L4 needs the "nearby" label), with ", {Month Year}" only when the month is known.
46
+ */
47
+ export declare function jobCardLabel(job: BrandlabJob, options: {
48
+ readonly service: string;
49
+ readonly suburbName: string;
50
+ readonly pageSuburb?: string;
51
+ }): string;
52
+ export interface BrandlabNearbyJob<T extends BrandlabJob = BrandlabJob> {
53
+ readonly job: T;
54
+ /** For ranking only; never printed. */
55
+ readonly distanceKm: number;
56
+ readonly sameSuburb: boolean;
57
+ }
58
+ /**
59
+ * The job cards for a page about `origin`: its own suburb's jobs first, then other jobs by real distance between
60
+ * registry centres, within `maxKm` (10) and at most `limit` (3); newest first among equals, undated last. Jobs whose
61
+ * suburb has no centre are left out. Filter by `service` for a service-in-suburb page.
62
+ */
63
+ export declare function nearbyJobs<T extends BrandlabJob>(origin: string, jobs: readonly T[], options: {
64
+ readonly centreOf: SuburbCentreLookup;
65
+ readonly service?: string;
66
+ readonly maxKm?: number;
67
+ readonly limit?: number;
68
+ }): BrandlabNearbyJob<T>[];
69
+ /** One place per job, for the area map's job markers (`overviewMap`, `regionMap`, `suburbLocator` take `jobs`). */
70
+ export declare function jobPlaces(jobs: readonly BrandlabJob[]): string[];
71
+ //# sourceMappingURL=jobs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jobs.d.ts","sourceRoot":"","sources":["../src/jobs.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAExD,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAE3E,MAAM,WAAW,WAAW;IAC1B,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,oDAAoD;IACpD,QAAQ,C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C3B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,WAAW,EAC9C,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,CAAC,EAAE,EAClB,OAAO,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9H,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAiBxB;AAED,mHAAmH;AACnH,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,EAAE,CAEhE"}
package/dist/jobs.js ADDED
@@ -0,0 +1,107 @@
1
+ import { distanceBetweenCentresKm } from './locations.js';
2
+ /** Job cards show jobs within this distance of the page's suburb (v2: the 10 km cap on job cards). */
3
+ export const JOB_CARD_MAX_KM = 10;
4
+ /** Cards per page (playbook: 1 to 3). */
5
+ export const JOB_CARD_LIMIT = 3;
6
+ const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
7
+ const MONTH = /^\d{4}-(?:0[1-9]|1[0-2])$/;
8
+ const JOB_KEYS = ['id', 'suburb', 'service', 'outcome', 'month', 'photos', 'source'];
9
+ function assertText(value, field, maximum) {
10
+ if (typeof value !== 'string' || !value.trim() || value.trim() !== value || value.length > maximum || /[\u0000-\u001f\u007f]/.test(value)) {
11
+ throw new Error(`${field} must be bounded, trimmed text.`);
12
+ }
13
+ }
14
+ /**
15
+ * Validates the job log. With the media manifest, every photo must exist, be `genuine` (stock and AI images never
16
+ * stand for the client's work) and, when its entry names a job, name this one.
17
+ */
18
+ export function defineJobs(jobs, options = {}) {
19
+ if (!Array.isArray(jobs))
20
+ throw new Error('The job log must be a list.');
21
+ const ids = new Set();
22
+ jobs.forEach((job, index) => {
23
+ const field = `jobs[${index}]`;
24
+ if (!job || typeof job !== 'object' || Array.isArray(job))
25
+ throw new Error(`${field} must be a record.`);
26
+ const unknown = Object.keys(job).find((key) => !JOB_KEYS.includes(key));
27
+ if (unknown)
28
+ throw new Error(`${field}.${unknown} is not a job field.`);
29
+ if (typeof job.id !== 'string' || !SLUG.test(job.id))
30
+ throw new Error(`${field}.id must be a kebab-case id.`);
31
+ if (ids.has(job.id))
32
+ throw new Error(`The job log lists "${job.id}" more than once.`);
33
+ ids.add(job.id);
34
+ if (typeof job.suburb !== 'string' || !SLUG.test(job.suburb))
35
+ throw new Error(`${field}.suburb must be the registry suburb slug.`);
36
+ if (typeof job.service !== 'string' || !SLUG.test(job.service))
37
+ throw new Error(`${field}.service must be the service slug.`);
38
+ assertText(job.outcome, `${field}.outcome`, 300);
39
+ assertText(job.source, `${field}.source`, 200);
40
+ if (job.month !== undefined && (typeof job.month !== 'string' || !MONTH.test(job.month)))
41
+ throw new Error(`${field}.month must be YYYY-MM, or left out.`);
42
+ if (job.photos !== undefined) {
43
+ if (!Array.isArray(job.photos))
44
+ throw new Error(`${field}.photos must be a list of media ids.`);
45
+ for (const id of job.photos) {
46
+ if (!options.media)
47
+ continue;
48
+ const entry = Object.hasOwn(options.media, id) ? options.media[id] : undefined;
49
+ if (!entry)
50
+ throw new Error(`${field}.photos: "${id}" is not in the media manifest.`);
51
+ if (entry.provenance !== 'genuine')
52
+ throw new Error(`${field}.photos: "${id}" is ${entry.provenance}; only genuine photos show a job.`);
53
+ if (entry.job !== undefined && entry.job !== job.id)
54
+ throw new Error(`${field}.photos: "${id}" is a photo of ${entry.job}, not ${job.id}.`);
55
+ }
56
+ }
57
+ });
58
+ return jobs;
59
+ }
60
+ /** A job's photos from the media manifest, in order, with their ids and provenance. */
61
+ export function jobPhotos(job, media) {
62
+ return (job.photos ?? []).flatMap((id) => (Object.hasOwn(media, id) ? [{ id, ...media[id] }] : []));
63
+ }
64
+ function formatMonth(month) {
65
+ return new Intl.DateTimeFormat('en-AU', { month: 'long', year: 'numeric', timeZone: 'UTC' }).format(new Date(`${month}-01T00:00:00Z`));
66
+ }
67
+ /**
68
+ * A job card's label: "Recent {service} in {Suburb}" for the page's own suburb, "Recent {service} nearby: {Suburb}"
69
+ * for any other (L4 needs the "nearby" label), with ", {Month Year}" only when the month is known.
70
+ */
71
+ export function jobCardLabel(job, options) {
72
+ const service = options.service.trim().toLowerCase();
73
+ const where = job.suburb === options.pageSuburb ? `in ${options.suburbName}` : `nearby: ${options.suburbName}`;
74
+ return `Recent ${service} ${where}${job.month ? `, ${formatMonth(job.month)}` : ''}`;
75
+ }
76
+ /**
77
+ * The job cards for a page about `origin`: its own suburb's jobs first, then other jobs by real distance between
78
+ * registry centres, within `maxKm` (10) and at most `limit` (3); newest first among equals, undated last. Jobs whose
79
+ * suburb has no centre are left out. Filter by `service` for a service-in-suburb page.
80
+ */
81
+ export function nearbyJobs(origin, jobs, options) {
82
+ const from = options.centreOf(origin);
83
+ if (!from)
84
+ return [];
85
+ const maxKm = options.maxKm ?? JOB_CARD_MAX_KM;
86
+ const limit = options.limit ?? JOB_CARD_LIMIT;
87
+ const found = [];
88
+ for (const job of jobs) {
89
+ if (options.service !== undefined && job.service !== options.service)
90
+ continue;
91
+ const sameSuburb = job.suburb === origin;
92
+ const to = sameSuburb ? from : options.centreOf(job.suburb);
93
+ if (!to)
94
+ continue;
95
+ const distanceKm = sameSuburb ? 0 : distanceBetweenCentresKm(from, to);
96
+ if (distanceKm <= maxKm)
97
+ found.push({ job, distanceKm, sameSuburb });
98
+ }
99
+ return found
100
+ .sort((left, right) => left.distanceKm - right.distanceKm || (right.job.month ?? '').localeCompare(left.job.month ?? ''))
101
+ .slice(0, limit);
102
+ }
103
+ /** One place per job, for the area map's job markers (`overviewMap`, `regionMap`, `suburbLocator` take `jobs`). */
104
+ export function jobPlaces(jobs) {
105
+ return jobs.map((job) => job.suburb);
106
+ }
107
+ //# sourceMappingURL=jobs.js.map