@brandlab-digital/site-core 3.4.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/google-business-reviews.d.ts +47 -0
- package/dist/google-business-reviews.d.ts.map +1 -0
- package/dist/google-business-reviews.js +93 -0
- package/dist/google-business-reviews.js.map +1 -0
- package/dist/project.d.ts +7 -1
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +12 -0
- package/dist/project.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google reviews from the Business Profile API, as the Brandlab reviews feed serves them
|
|
3
|
+
* (`{ status: 'available', source: 'google-business-profile', fetchedAt, googleMapsUri,
|
|
4
|
+
* averageRating?, totalReviewCount?, reviews }`). Anything the feed sends that does not
|
|
5
|
+
* match is treated as unavailable (the whole response) or dropped (one review), so a page
|
|
6
|
+
* never shows a review it cannot vouch for. The fetch itself lives in
|
|
7
|
+
* `site-next/google-business-reviews/server`.
|
|
8
|
+
*/
|
|
9
|
+
export interface BusinessProfileReview {
|
|
10
|
+
id: string;
|
|
11
|
+
authorName: string;
|
|
12
|
+
/** Only an https image on a `*.googleusercontent.com` host. */
|
|
13
|
+
authorPhotoUrl?: string;
|
|
14
|
+
rating: 1 | 2 | 3 | 4 | 5;
|
|
15
|
+
text: string;
|
|
16
|
+
/** The time Google records for the review, as the feed sent it. */
|
|
17
|
+
createTime: string;
|
|
18
|
+
}
|
|
19
|
+
export interface BusinessProfileReviews {
|
|
20
|
+
googleMapsUri: string;
|
|
21
|
+
/** Between 1 and 5 when Google supplies it. */
|
|
22
|
+
averageRating?: number;
|
|
23
|
+
/** A whole number of reviews, 0 or more, when Google supplies it. */
|
|
24
|
+
totalReviewCount?: number;
|
|
25
|
+
reviews: BusinessProfileReview[];
|
|
26
|
+
}
|
|
27
|
+
/** Which reviews a page shows: the newest of all, or the newest five-star ones. */
|
|
28
|
+
export type BusinessProfileReviewsPolicy = 'recent' | 'five-star';
|
|
29
|
+
export interface SelectBusinessProfileReviewsOptions {
|
|
30
|
+
policy: BusinessProfileReviewsPolicy;
|
|
31
|
+
/** How many reviews to show at most: a whole number, 1 or more. */
|
|
32
|
+
limit: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validates a reviews feed response. Returns null for anything but an available response
|
|
36
|
+
* with an https Google Maps link and a review list; drops each review that is not complete
|
|
37
|
+
* (id, author, text, a valid time and a whole-star rating from 1 to 5). An author photo
|
|
38
|
+
* outside `*.googleusercontent.com`, an average outside 1 to 5 and a total that is not a
|
|
39
|
+
* whole number of 0 or more are left out.
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseBusinessProfileReviews(value: unknown): BusinessProfileReviews | null;
|
|
42
|
+
/**
|
|
43
|
+
* The reviews a page shows, newest first and word for word: every review (`recent`) or
|
|
44
|
+
* only the five-star ones (`five-star`), at most `limit`. No feed gives no reviews.
|
|
45
|
+
*/
|
|
46
|
+
export declare function selectBusinessProfileReviews(feed: BusinessProfileReviews | null | undefined, options: SelectBusinessProfileReviewsOptions): BusinessProfileReview[];
|
|
47
|
+
//# sourceMappingURL=google-business-reviews.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-business-reviews.d.ts","sourceRoot":"","sources":["../src/google-business-reviews.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,+DAA+D;IAC/D,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,MAAM,CAAA;IACrB,+CAA+C;IAC/C,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,qEAAqE;IACrE,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,OAAO,EAAE,qBAAqB,EAAE,CAAA;CACjC;AAED,mFAAmF;AACnF,MAAM,MAAM,4BAA4B,GAAG,QAAQ,GAAG,WAAW,CAAA;AAEjE,MAAM,WAAW,mCAAmC;IAClD,MAAM,EAAE,4BAA4B,CAAA;IACpC,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAA;CACd;AA2CD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,sBAAsB,GAAG,IAAI,CAgBzF;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,sBAAsB,GAAG,IAAI,GAAG,SAAS,EAC/C,OAAO,EAAE,mCAAmC,GAC3C,qBAAqB,EAAE,CAczB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google reviews from the Business Profile API, as the Brandlab reviews feed serves them
|
|
3
|
+
* (`{ status: 'available', source: 'google-business-profile', fetchedAt, googleMapsUri,
|
|
4
|
+
* averageRating?, totalReviewCount?, reviews }`). Anything the feed sends that does not
|
|
5
|
+
* match is treated as unavailable (the whole response) or dropped (one review), so a page
|
|
6
|
+
* never shows a review it cannot vouch for. The fetch itself lives in
|
|
7
|
+
* `site-next/google-business-reviews/server`.
|
|
8
|
+
*/
|
|
9
|
+
const POLICIES = new Set(['recent', 'five-star']);
|
|
10
|
+
function isHttpsUrl(value, host) {
|
|
11
|
+
if (typeof value !== 'string')
|
|
12
|
+
return false;
|
|
13
|
+
try {
|
|
14
|
+
const url = new URL(value);
|
|
15
|
+
return url.protocol === 'https:' && (!host || host(url.hostname));
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function parseReview(value) {
|
|
22
|
+
if (!value || typeof value !== 'object')
|
|
23
|
+
return null;
|
|
24
|
+
const record = value;
|
|
25
|
+
const rating = record.rating;
|
|
26
|
+
if (typeof record.id !== 'string' ||
|
|
27
|
+
typeof record.authorName !== 'string' ||
|
|
28
|
+
!record.authorName.trim() ||
|
|
29
|
+
typeof record.text !== 'string' ||
|
|
30
|
+
!record.text.trim() ||
|
|
31
|
+
typeof record.createTime !== 'string' ||
|
|
32
|
+
Number.isNaN(Date.parse(record.createTime)) ||
|
|
33
|
+
(rating !== 1 && rating !== 2 && rating !== 3 && rating !== 4 && rating !== 5)) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const photo = isHttpsUrl(record.authorPhotoUrl, (host) => host.endsWith('.googleusercontent.com'))
|
|
37
|
+
? record.authorPhotoUrl
|
|
38
|
+
: undefined;
|
|
39
|
+
return {
|
|
40
|
+
id: record.id,
|
|
41
|
+
authorName: record.authorName.trim(),
|
|
42
|
+
...(photo ? { authorPhotoUrl: photo } : {}),
|
|
43
|
+
rating,
|
|
44
|
+
text: record.text.trim(),
|
|
45
|
+
createTime: record.createTime,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validates a reviews feed response. Returns null for anything but an available response
|
|
50
|
+
* with an https Google Maps link and a review list; drops each review that is not complete
|
|
51
|
+
* (id, author, text, a valid time and a whole-star rating from 1 to 5). An author photo
|
|
52
|
+
* outside `*.googleusercontent.com`, an average outside 1 to 5 and a total that is not a
|
|
53
|
+
* whole number of 0 or more are left out.
|
|
54
|
+
*/
|
|
55
|
+
export function parseBusinessProfileReviews(value) {
|
|
56
|
+
if (!value || typeof value !== 'object')
|
|
57
|
+
return null;
|
|
58
|
+
const record = value;
|
|
59
|
+
if (record.status !== 'available' || !isHttpsUrl(record.googleMapsUri) || !Array.isArray(record.reviews)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const average = record.averageRating;
|
|
63
|
+
const total = record.totalReviewCount;
|
|
64
|
+
return {
|
|
65
|
+
googleMapsUri: record.googleMapsUri,
|
|
66
|
+
...(typeof average === 'number' && average >= 1 && average <= 5 ? { averageRating: average } : {}),
|
|
67
|
+
...(typeof total === 'number' && Number.isInteger(total) && total >= 0 ? { totalReviewCount: total } : {}),
|
|
68
|
+
reviews: record.reviews
|
|
69
|
+
.map(parseReview)
|
|
70
|
+
.filter((review) => review !== null),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The reviews a page shows, newest first and word for word: every review (`recent`) or
|
|
75
|
+
* only the five-star ones (`five-star`), at most `limit`. No feed gives no reviews.
|
|
76
|
+
*/
|
|
77
|
+
export function selectBusinessProfileReviews(feed, options) {
|
|
78
|
+
if (!POLICIES.has(options.policy)) {
|
|
79
|
+
throw new Error('Business Profile reviews policy must be recent or five-star.');
|
|
80
|
+
}
|
|
81
|
+
if (!Number.isInteger(options.limit) || options.limit < 1) {
|
|
82
|
+
throw new Error('Business Profile reviews limit must be a whole number of 1 or more.');
|
|
83
|
+
}
|
|
84
|
+
if (!feed)
|
|
85
|
+
return [];
|
|
86
|
+
return feed.reviews
|
|
87
|
+
.filter((review) => options.policy === 'recent' || review.rating === 5)
|
|
88
|
+
.map((review, index) => ({ review, index, time: Date.parse(review.createTime) }))
|
|
89
|
+
.sort((a, b) => b.time - a.time || a.index - b.index)
|
|
90
|
+
.slice(0, options.limit)
|
|
91
|
+
.map(({ review }) => review);
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=google-business-reviews.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-business-reviews.js","sourceRoot":"","sources":["../src/google-business-reviews.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA+BH,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAA+B,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAA;AAEpG,SAAS,UAAU,CAAC,KAAc,EAAE,IAAoC;IACtE,IAAI,OAAO,KAAK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Google reviews from the Business Profile API, as the Brandlab reviews feed serves them\n * (`{ status: 'available', source: 'google-business-profile', fetchedAt, googleMapsUri,\n * averageRating?, totalReviewCount?, reviews }`). Anything the feed sends that does not\n * match is treated as unavailable (the whole response) or dropped (one review), so a page\n * never shows a review it cannot vouch for. The fetch itself lives in\n * `site-next/google-business-reviews/server`.\n */\n\nexport interface BusinessProfileReview {\n id: string\n authorName: string\n /** Only an https image on a `*.googleusercontent.com` host. */\n authorPhotoUrl?: string\n rating: 1 | 2 | 3 | 4 | 5\n text: string\n /** The time Google records for the review, as the feed sent it. */\n createTime: string\n}\n\nexport interface BusinessProfileReviews {\n googleMapsUri: string\n /** Between 1 and 5 when Google supplies it. */\n averageRating?: number\n /** A whole number of reviews, 0 or more, when Google supplies it. */\n totalReviewCount?: number\n reviews: BusinessProfileReview[]\n}\n\n/** Which reviews a page shows: the newest of all, or the newest five-star ones. */\nexport type BusinessProfileReviewsPolicy = 'recent' | 'five-star'\n\nexport interface SelectBusinessProfileReviewsOptions {\n policy: BusinessProfileReviewsPolicy\n /** How many reviews to show at most: a whole number, 1 or more. */\n limit: number\n}\n\nconst POLICIES: ReadonlySet<string> = new Set<BusinessProfileReviewsPolicy>(['recent', 'five-star'])\n\nfunction isHttpsUrl(value: unknown, host?: (hostname: string) => boolean): value is string {\n if (typeof value !== 'string') return false\n try {\n const url = new URL(value)\n return url.protocol === 'https:' && (!host || host(url.hostname))\n } catch {\n return false\n }\n}\n\nfunction parseReview(value: unknown): BusinessProfileReview | null {\n if (!value || typeof value !== 'object') return null\n const record = value as Record<string, unknown>\n const rating = record.rating\n if (\n typeof record.id !== 'string' ||\n typeof record.authorName !== 'string' ||\n !record.authorName.trim() ||\n typeof record.text !== 'string' ||\n !record.text.trim() ||\n typeof record.createTime !== 'string' ||\n Number.isNaN(Date.parse(record.createTime)) ||\n (rating !== 1 && rating !== 2 && rating !== 3 && rating !== 4 && rating !== 5)\n ) {\n return null\n }\n const photo = isHttpsUrl(record.authorPhotoUrl, (host) => host.endsWith('.googleusercontent.com'))\n ? record.authorPhotoUrl\n : undefined\n return {\n id: record.id,\n authorName: record.authorName.trim(),\n ...(photo ? { authorPhotoUrl: photo } : {}),\n rating,\n text: record.text.trim(),\n createTime: record.createTime,\n }\n}\n\n/**\n * Validates a reviews feed response. Returns null for anything but an available response\n * with an https Google Maps link and a review list; drops each review that is not complete\n * (id, author, text, a valid time and a whole-star rating from 1 to 5). An author photo\n * outside `*.googleusercontent.com`, an average outside 1 to 5 and a total that is not a\n * whole number of 0 or more are left out.\n */\nexport function parseBusinessProfileReviews(value: unknown): BusinessProfileReviews | null {\n if (!value || typeof value !== 'object') return null\n const record = value as Record<string, unknown>\n if (record.status !== 'available' || !isHttpsUrl(record.googleMapsUri) || !Array.isArray(record.reviews)) {\n return null\n }\n const average = record.averageRating\n const total = record.totalReviewCount\n return {\n googleMapsUri: record.googleMapsUri,\n ...(typeof average === 'number' && average >= 1 && average <= 5 ? { averageRating: average } : {}),\n ...(typeof total === 'number' && Number.isInteger(total) && total >= 0 ? { totalReviewCount: total } : {}),\n reviews: record.reviews\n .map(parseReview)\n .filter((review): review is BusinessProfileReview => review !== null),\n }\n}\n\n/**\n * The reviews a page shows, newest first and word for word: every review (`recent`) or\n * only the five-star ones (`five-star`), at most `limit`. No feed gives no reviews.\n */\nexport function selectBusinessProfileReviews(\n feed: BusinessProfileReviews | null | undefined,\n options: SelectBusinessProfileReviewsOptions,\n): BusinessProfileReview[] {\n if (!POLICIES.has(options.policy)) {\n throw new Error('Business Profile reviews policy must be recent or five-star.')\n }\n if (!Number.isInteger(options.limit) || options.limit < 1) {\n throw new Error('Business Profile reviews limit must be a whole number of 1 or more.')\n }\n if (!feed) return []\n return feed.reviews\n .filter((review) => options.policy === 'recent' || review.rating === 5)\n .map((review, index) => ({ review, index, time: Date.parse(review.createTime) }))\n .sort((a, b) => b.time - a.time || a.index - b.index)\n .slice(0, options.limit)\n .map(({ review }) => review)\n}\n"]}
|
package/dist/project.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import type { GooglePlaceReviewsSelection } from './google-reviews.js';
|
|
2
|
+
import type { BusinessProfileReviewsPolicy } from './google-business-reviews.js';
|
|
2
3
|
export type BrandlabRouteFamily = 'services' | 'locations' | 'service-locations' | 'blog' | 'projects' | 'legal';
|
|
3
4
|
export type BrandlabBlogAdapter = 'none' | 'mdx' | 'structured';
|
|
4
5
|
export type BrandlabContactAttachmentMode = 'none' | 'images-optional' | 'images-required' | 'images-and-pdfs-optional';
|
|
5
6
|
export type BrandlabLocationStrategy = 'none' | 'approved-service-area' | 'physical-location' | 'multi-location';
|
|
6
|
-
export type BrandlabReviewsProvider = 'google-places' | 'project-owned';
|
|
7
|
+
export type BrandlabReviewsProvider = 'google-places' | 'google-business-profile' | 'project-owned';
|
|
7
8
|
export type BrandlabGoogleReviewsMode = 'link-only' | 'summary' | 'full';
|
|
8
9
|
export type BrandlabReviewsCapability = {
|
|
9
10
|
provider: 'project-owned';
|
|
11
|
+
} | {
|
|
12
|
+
/** 3.5.0: Google reviews read on the server from the Brandlab reviews feed (site-next/google-business-reviews/server). */
|
|
13
|
+
provider: 'google-business-profile';
|
|
14
|
+
/** Optional presentation policy: the newest reviews, or the newest five-star ones. */
|
|
15
|
+
selection?: BusinessProfileReviewsPolicy;
|
|
10
16
|
} | {
|
|
11
17
|
provider: 'google-places';
|
|
12
18
|
mode: BrandlabGoogleReviewsMode;
|
package/dist/project.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AACtE,OAAO,KAAK,EAAE,4BAA4B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,SAAS,MAAM,EAAE,CAAA;IAC3B,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAEL,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE;QACN,QAAQ,EAAE,SAAS,mBAAmB,EAAE,CAAA;KACzC,CAAA;IACD,YAAY,CAAC,EAAE;QACb,IAAI,CAAC,EAAE;YAAE,OAAO,EAAE,mBAAmB,CAAA;SAAE,CAAA;QACvC,OAAO,CAAC,EAAE;YACR,YAAY,EAAE,MAAM,CAAA;YACpB,WAAW,EAAE,6BAA6B,CAAA;SAC3C,CAAA;QACD,SAAS,CAAC,EAAE;YAAE,QAAQ,EAAE,wBAAwB,CAAA;SAAE,CAAA;QAClD,OAAO,CAAC,EAAE,yBAAyB,CAAA;KACpC,CAAA;IACD,OAAO,CAAC,EAAE,qBAAqB,CAAA;IAC/B,mBAAmB,EAAE;QACnB,oBAAoB,EAAE;YACpB,IAAI,EAAE,MAAM,CAAA;YACZ,OAAO,CAAC,EAAE,MAAM,CAAA;YAChB,OAAO,CAAC,EAAE,MAAM,CAAA;YAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;YACjB,IAAI,CAAC,EAAE,MAAM,CAAA;SACd,CAAA;KACF,CAAA;IACD,UAAU,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAA;CAC1C;AA8ED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,CAAC,CAAC,SAAS,qBAAqB,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAiIzF"}
|
package/dist/project.js
CHANGED
|
@@ -31,6 +31,7 @@ const LOCATION_STRATEGIES = new Set([
|
|
|
31
31
|
]);
|
|
32
32
|
const REVIEWS_PROVIDERS = new Set([
|
|
33
33
|
'google-places',
|
|
34
|
+
'google-business-profile',
|
|
34
35
|
'project-owned',
|
|
35
36
|
]);
|
|
36
37
|
const GOOGLE_REVIEWS_MODES = new Set([
|
|
@@ -42,6 +43,10 @@ const GOOGLE_REVIEWS_SELECTIONS = new Set([
|
|
|
42
43
|
'relevance',
|
|
43
44
|
'five-star-featured',
|
|
44
45
|
]);
|
|
46
|
+
const BUSINESS_PROFILE_REVIEWS_SELECTIONS = new Set([
|
|
47
|
+
'recent',
|
|
48
|
+
'five-star',
|
|
49
|
+
]);
|
|
45
50
|
function assertNonEmpty(value, field) {
|
|
46
51
|
if (!value.trim()) {
|
|
47
52
|
throw new Error(`${field} cannot be empty.`);
|
|
@@ -142,6 +147,13 @@ export function defineBrandlabProject(config) {
|
|
|
142
147
|
}
|
|
143
148
|
});
|
|
144
149
|
}
|
|
150
|
+
if (config.capabilities?.reviews?.provider === 'google-business-profile') {
|
|
151
|
+
const reviews = config.capabilities.reviews;
|
|
152
|
+
if (reviews.selection !== undefined &&
|
|
153
|
+
!BUSINESS_PROFILE_REVIEWS_SELECTIONS.has(reviews.selection)) {
|
|
154
|
+
throw new Error('reviews.selection is unsupported.');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
145
157
|
if (config.sitemap?.mode === 'split') {
|
|
146
158
|
if (config.sitemap.families.length === 0) {
|
|
147
159
|
throw new Error('Split sitemap configuration requires at least one family.');
|
package/dist/project.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAA;AAgFhE,MAAM,mBAAmB,GAAG;IAC1B,WAAW;IACX,QAAQ;IACR,cAAc;IACd,SAAS;IACT,qBAAqB;IACrB,YAAY;CACJ,CAAA;AACV,MAAM,cAAc,GAAG,IAAI,GAAG,CAAsB;IAClD,UAAU;IACV,WAAW;IACX,mBAAmB;IACnB,MAAM;IACN,UAAU;IACV,OAAO;CACR,CAAC,CAAA;AACF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAsB,CAAC,MAAM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AAC,SAAS,CAAC,MAAM,CAAC,EAC9D,mBAAmB,CACpB,CAEA;IAAA,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;QACtD,cAAc,CAAC,SAAS,CAAC,MAAM,EAAE,cAAc,KAAK,UAAU,CAAC,CAAA;QAC/D,cAAc,CAAC,SAAS,CAAC,SAAS,EAAE,cAAc,KAAK,aAAa,CAAC,CAAA;QACrE,cAAc,CAAC,SAAS,CAAC,QAAQ,EAAE,cAAc,KAAK,YAAY,CAAC,CAAA;QACnE,cAAc,CAAC,SAAS,CAAC,aAAa,EAAE,cAAc,KAAK,iBAAiB,CAAC,CAAA;QAC7E,IAAI,SAAS,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,cAAc,KAAK,0BAA0B,CAAC,CAAA;QAChE,CAAC;QAED,IAAI,SAAS,CAAC,SAAS,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;YACzE,MAAM,IAAI,KAAK,CAAC,cAAc,KAAK,mCAAmC,CAAC,CAAA;QACzE,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { normalizeBrandlabRoutePath } from './routes.js'\nimport { assertBrandlabCanonicalEntityId } from './entity-id.js'\nimport type { GooglePlaceReviewsSelection } from './google-reviews.js'\n\nexport type BrandlabRouteFamily =\n | 'services'\n | 'locations'\n | 'service-locations'\n | 'blog'\n | 'projects'\n | 'legal'\n\nexport type BrandlabBlogAdapter = 'none' | 'mdx' | 'structured'\nexport type BrandlabContactAttachmentMode =\n | 'none'\n | 'images-optional'\n | 'images-required'\n | 'images-and-pdfs-optional'\nexport type BrandlabLocationStrategy =\n | 'none'\n | 'approved-service-area'\n | 'physical-location'\n | 'multi-location'\nexport type BrandlabReviewsProvider = 'google-places' | 'project-owned'\nexport type BrandlabGoogleReviewsMode = 'link-only' | 'summary' | 'full'\n\nexport type BrandlabReviewsCapability =\n | { provider: 'project-owned' }\n | {\n provider: 'google-places'\n mode: BrandlabGoogleReviewsMode\n /** Optional presentation policy. Five-star selection is valid only in full mode. */\n selection?: GooglePlaceReviewsSelection\n /** Stable route IDs where review proof is intentionally presented. */\n routeIds: readonly string[]\n }\n\nexport interface BrandlabException {\n ruleId: string\n rationale: string\n owner: 'Romie'\n evidence: string\n expiresAt?: string\n reviewTrigger: string\n}\n\nexport type BrandlabSitemapConfig =\n | { mode: 'single' }\n | {\n mode: 'split'\n families: readonly string[]\n reason: string\n }\n\nexport interface BrandlabProjectConfig {\n projectId: string\n routes: {\n families: readonly BrandlabRouteFamily[]\n }\n capabilities?: {\n blog?: { adapter: BrandlabBlogAdapter }\n contact?: {\n fieldProfile: string\n attachments: BrandlabContactAttachmentMode\n }\n locations?: { strategy: BrandlabLocationStrategy }\n reviews?: BrandlabReviewsCapability\n }\n sitemap?: BrandlabSitemapConfig\n searchCertification: {\n representativeRoutes: {\n home: string\n contact?: string\n service?: string\n location?: string\n blog?: string\n }\n }\n exceptions?: readonly BrandlabException[]\n}\n\nconst PROJECT_CONFIG_KEYS = [\n 'projectId',\n 'routes',\n 'capabilities',\n 'sitemap',\n 'searchCertification',\n 'exceptions',\n] as const\nconst ROUTE_FAMILIES = new Set<BrandlabRouteFamily>([\n 'services',\n 'locations',\n 'service-locations',\n 'blog',\n 'projects',\n 'legal',\n])\nconst BLOG_ADAPTERS = new Set<BrandlabBlogAdapter>(['none', 'mdx', 'structured'])\nconst ATTACHMENT_MODES = new Set<BrandlabContactAttachmentMode>([\n 'none',\n 'images-optional',\n 'images-required',\n 'images-and-pdfs-optional',\n])\nconst LOCATION_STRATEGIES = new Set<BrandlabLocationStrategy>([\n 'none',\n 'approved-service-area',\n 'physical-location',\n 'multi-location',\n])\nconst REVIEWS_PROVIDERS = new Set<BrandlabReviewsProvider>([\n 'google-places',\n 'project-owned',\n])\nconst GOOGLE_REVIEWS_MODES = new Set<BrandlabGoogleReviewsMode>([\n 'link-only',\n 'summary',\n 'full',\n])\nconst GOOGLE_REVIEWS_SELECTIONS = new Set<GooglePlaceReviewsSelection>([\n 'relevance',\n 'five-star-featured',\n])\n\nfunction assertNonEmpty(value: string, field: string) {\n if (!value.trim()) {\n throw new Error(`${field} cannot be empty.`)\n }\n}\n\nfunction assertRootRelativePath(path: string, field: string) {\n try {\n normalizeBrandlabRoutePath(path)\n } catch {\n throw new Error(`${field} must be a root-relative path without a query string or hash.`)\n }\n}\n\nfunction assertKnownKeys(value: object, allowed: readonly string[], field: string, hint = '') {\n const unsupported = Object.keys(value).filter((key) => !allowed.includes(key))\n if (unsupported.length > 0) {\n throw new Error(`${field} contains unsupported keys: ${unsupported.join(', ')}.${hint}`)\n }\n}\n\nfunction assertUnique(values: readonly string[], field: string) {\n const duplicate = values.find((value, index) => values.indexOf(value) !== index)\n if (duplicate) {\n throw new Error(`${field} contains duplicate value \"${duplicate}\".`)\n }\n}\n\n/**\n * Defines project-owned variation only. Runtime versions and global Brandlab\n * policy deliberately do not belong in this object.\n */\nexport function defineBrandlabProject<const T extends BrandlabProjectConfig>(config: T): T {\n if (!config || typeof config !== 'object' || Array.isArray(config)) {\n throw new TypeError('defineBrandlabProject requires a project configuration.')\n }\n assertKnownKeys(config, PROJECT_CONFIG_KEYS, 'Project configuration')\n assertNonEmpty(config.projectId, 'projectId')\n\n assertBrandlabCanonicalEntityId(config.projectId)\n\n if (!config.routes || typeof config.routes !== 'object') {\n throw new Error('routes.families is required.')\n }\n assertKnownKeys(\n config.routes,\n ['families'],\n 'routes',\n ' Redirects belong in the src/data/redirects.ts table.',\n )\n assertUnique(config.routes.families, 'routes.families')\n config.routes.families.forEach((family, index) => {\n if (!ROUTE_FAMILIES.has(family)) {\n throw new Error(`routes.families[${index}] is unsupported.`)\n }\n })\n\n const representativeRoutes = config.searchCertification.representativeRoutes\n Object.entries(representativeRoutes).forEach(([name, path]) => {\n if (path) assertRootRelativePath(path, `searchCertification.representativeRoutes.${name}`)\n })\n if (representativeRoutes.home !== '/') {\n throw new Error('searchCertification.representativeRoutes.home must be \"/\".')\n }\n\n if (config.capabilities?.contact) {\n assertNonEmpty(config.capabilities.contact.fieldProfile, 'contact.fieldProfile')\n if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(config.capabilities.contact.fieldProfile)) {\n throw new Error('contact.fieldProfile must be lowercase kebab-case.')\n }\n if (!ATTACHMENT_MODES.has(config.capabilities.contact.attachments)) {\n throw new Error('contact.attachments is unsupported.')\n }\n }\n if (\n config.capabilities?.blog &&\n !BLOG_ADAPTERS.has(config.capabilities.blog.adapter)\n ) {\n throw new Error('blog.adapter is unsupported.')\n }\n if (\n config.capabilities?.locations &&\n !LOCATION_STRATEGIES.has(config.capabilities.locations.strategy)\n ) {\n throw new Error('locations.strategy is unsupported.')\n }\n if (\n config.capabilities?.reviews &&\n !REVIEWS_PROVIDERS.has(config.capabilities.reviews.provider)\n ) {\n throw new Error('reviews.provider is unsupported.')\n }\n if (\n config.capabilities?.reviews?.provider === 'google-places' &&\n !config.routes.families.includes('legal')\n ) {\n throw new Error('Google Places reviews require the legal route family.')\n }\n if (config.capabilities?.reviews?.provider === 'google-places') {\n const reviews = config.capabilities.reviews\n if (!GOOGLE_REVIEWS_MODES.has(reviews.mode)) {\n throw new Error('reviews.mode is unsupported.')\n }\n if (reviews.selection && !GOOGLE_REVIEWS_SELECTIONS.has(reviews.selection)) {\n throw new Error('reviews.selection is unsupported.')\n }\n if (reviews.selection === 'five-star-featured' && reviews.mode !== 'full') {\n throw new Error('Five-star featured reviews require full mode.')\n }\n if (!Array.isArray(reviews.routeIds) || reviews.routeIds.length === 0) {\n throw new Error('Google Places reviews require at least one approved route ID.')\n }\n assertUnique(reviews.routeIds, 'reviews.routeIds')\n reviews.routeIds.forEach((routeId, index) => {\n if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(routeId)) {\n throw new Error(`reviews.routeIds[${index}] must be lowercase kebab-case.`)\n }\n })\n }\n\n if (config.sitemap?.mode === 'split') {\n if (config.sitemap.families.length === 0) {\n throw new Error('Split sitemap configuration requires at least one family.')\n }\n assertUnique(config.sitemap.families, 'sitemap.families')\n config.sitemap.families.forEach((path, index) =>\n assertRootRelativePath(path, `sitemap.families[${index}]`),\n )\n assertNonEmpty(config.sitemap.reason, 'sitemap.reason')\n }\n\n assertUnique(\n (config.exceptions ?? []).map((exception) => exception.ruleId),\n 'exceptions.ruleId',\n )\n\n ;(config.exceptions ?? []).forEach((exception, index) => {\n assertNonEmpty(exception.ruleId, `exceptions[${index}].ruleId`)\n assertNonEmpty(exception.rationale, `exceptions[${index}].rationale`)\n assertNonEmpty(exception.evidence, `exceptions[${index}].evidence`)\n assertNonEmpty(exception.reviewTrigger, `exceptions[${index}].reviewTrigger`)\n if (exception.owner !== 'Romie') {\n throw new Error(`exceptions[${index}].owner must be \"Romie\".`)\n }\n\n if (exception.expiresAt && Number.isNaN(Date.parse(exception.expiresAt))) {\n throw new Error(`exceptions[${index}].expiresAt must be a valid date.`)\n }\n })\n\n return config\n}\n"]}
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAA;AAuFhE,MAAM,mBAAmB,GAAG;IAC1B,WAAW;IACX,QAAQ;IACR,cAAc;IACd,SAAS;IACT,qBAAqB;IACrB,YAAY;CACJ,CAAA;AACV,MAAM,cAAc,GAAG,IAAI,GAAG,CAAsB;IAClD,UAAU;IACV,WAAW;IACX,mBAAmB;IACnB,MAAM;IACN,UAAU;IACV,OAAO;CACR,CAAC,CAAA;AACF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAsB,CAAC,MAAM,EAAE,KAAK,EAAE,YAAY,CA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A;AACf,CAAC","sourcesContent":["import { normalizeBrandlabRoutePath } from './routes.js'\nimport { assertBrandlabCanonicalEntityId } from './entity-id.js'\nimport type { GooglePlaceReviewsSelection } from './google-reviews.js'\nimport type { BusinessProfileReviewsPolicy } from './google-business-reviews.js'\n\nexport type BrandlabRouteFamily =\n | 'services'\n | 'locations'\n | 'service-locations'\n | 'blog'\n | 'projects'\n | 'legal'\n\nexport type BrandlabBlogAdapter = 'none' | 'mdx' | 'structured'\nexport type BrandlabContactAttachmentMode =\n | 'none'\n | 'images-optional'\n | 'images-required'\n | 'images-and-pdfs-optional'\nexport type BrandlabLocationStrategy =\n | 'none'\n | 'approved-service-area'\n | 'physical-location'\n | 'multi-location'\nexport type BrandlabReviewsProvider = 'google-places' | 'google-business-profile' | 'project-owned'\nexport type BrandlabGoogleReviewsMode = 'link-only' | 'summary' | 'full'\n\nexport type BrandlabReviewsCapability =\n | { provider: 'project-owned' }\n | {\n /** 3.5.0: Google reviews read on the server from the Brandlab reviews feed (site-next/google-business-reviews/server). */\n provider: 'google-business-profile'\n /** Optional presentation policy: the newest reviews, or the newest five-star ones. */\n selection?: BusinessProfileReviewsPolicy\n }\n | {\n provider: 'google-places'\n mode: BrandlabGoogleReviewsMode\n /** Optional presentation policy. Five-star selection is valid only in full mode. */\n selection?: GooglePlaceReviewsSelection\n /** Stable route IDs where review proof is intentionally presented. */\n routeIds: readonly string[]\n }\n\nexport interface BrandlabException {\n ruleId: string\n rationale: string\n owner: 'Romie'\n evidence: string\n expiresAt?: string\n reviewTrigger: string\n}\n\nexport type BrandlabSitemapConfig =\n | { mode: 'single' }\n | {\n mode: 'split'\n families: readonly string[]\n reason: string\n }\n\nexport interface BrandlabProjectConfig {\n projectId: string\n routes: {\n families: readonly BrandlabRouteFamily[]\n }\n capabilities?: {\n blog?: { adapter: BrandlabBlogAdapter }\n contact?: {\n fieldProfile: string\n attachments: BrandlabContactAttachmentMode\n }\n locations?: { strategy: BrandlabLocationStrategy }\n reviews?: BrandlabReviewsCapability\n }\n sitemap?: BrandlabSitemapConfig\n searchCertification: {\n representativeRoutes: {\n home: string\n contact?: string\n service?: string\n location?: string\n blog?: string\n }\n }\n exceptions?: readonly BrandlabException[]\n}\n\nconst PROJECT_CONFIG_KEYS = [\n 'projectId',\n 'routes',\n 'capabilities',\n 'sitemap',\n 'searchCertification',\n 'exceptions',\n] as const\nconst ROUTE_FAMILIES = new Set<BrandlabRouteFamily>([\n 'services',\n 'locations',\n 'service-locations',\n 'blog',\n 'projects',\n 'legal',\n])\nconst BLOG_ADAPTERS = new Set<BrandlabBlogAdapter>(['none', 'mdx', 'structured'])\nconst ATTACHMENT_MODES = new Set<BrandlabContactAttachmentMode>([\n 'none',\n 'images-optional',\n 'images-required',\n 'images-and-pdfs-optional',\n])\nconst LOCATION_STRATEGIES = new Set<BrandlabLocationStrategy>([\n 'none',\n 'approved-service-area',\n 'physical-location',\n 'multi-location',\n])\nconst REVIEWS_PROVIDERS = new Set<BrandlabReviewsProvider>([\n 'google-places',\n 'google-business-profile',\n 'project-owned',\n])\nconst GOOGLE_REVIEWS_MODES = new Set<BrandlabGoogleReviewsMode>([\n 'link-only',\n 'summary',\n 'full',\n])\nconst GOOGLE_REVIEWS_SELECTIONS = new Set<GooglePlaceReviewsSelection>([\n 'relevance',\n 'five-star-featured',\n])\nconst BUSINESS_PROFILE_REVIEWS_SELECTIONS = new Set<BusinessProfileReviewsPolicy>([\n 'recent',\n 'five-star',\n])\n\nfunction assertNonEmpty(value: string, field: string) {\n if (!value.trim()) {\n throw new Error(`${field} cannot be empty.`)\n }\n}\n\nfunction assertRootRelativePath(path: string, field: string) {\n try {\n normalizeBrandlabRoutePath(path)\n } catch {\n throw new Error(`${field} must be a root-relative path without a query string or hash.`)\n }\n}\n\nfunction assertKnownKeys(value: object, allowed: readonly string[], field: string, hint = '') {\n const unsupported = Object.keys(value).filter((key) => !allowed.includes(key))\n if (unsupported.length > 0) {\n throw new Error(`${field} contains unsupported keys: ${unsupported.join(', ')}.${hint}`)\n }\n}\n\nfunction assertUnique(values: readonly string[], field: string) {\n const duplicate = values.find((value, index) => values.indexOf(value) !== index)\n if (duplicate) {\n throw new Error(`${field} contains duplicate value \"${duplicate}\".`)\n }\n}\n\n/**\n * Defines project-owned variation only. Runtime versions and global Brandlab\n * policy deliberately do not belong in this object.\n */\nexport function defineBrandlabProject<const T extends BrandlabProjectConfig>(config: T): T {\n if (!config || typeof config !== 'object' || Array.isArray(config)) {\n throw new TypeError('defineBrandlabProject requires a project configuration.')\n }\n assertKnownKeys(config, PROJECT_CONFIG_KEYS, 'Project configuration')\n assertNonEmpty(config.projectId, 'projectId')\n\n assertBrandlabCanonicalEntityId(config.projectId)\n\n if (!config.routes || typeof config.routes !== 'object') {\n throw new Error('routes.families is required.')\n }\n assertKnownKeys(\n config.routes,\n ['families'],\n 'routes',\n ' Redirects belong in the src/data/redirects.ts table.',\n )\n assertUnique(config.routes.families, 'routes.families')\n config.routes.families.forEach((family, index) => {\n if (!ROUTE_FAMILIES.has(family)) {\n throw new Error(`routes.families[${index}] is unsupported.`)\n }\n })\n\n const representativeRoutes = config.searchCertification.representativeRoutes\n Object.entries(representativeRoutes).forEach(([name, path]) => {\n if (path) assertRootRelativePath(path, `searchCertification.representativeRoutes.${name}`)\n })\n if (representativeRoutes.home !== '/') {\n throw new Error('searchCertification.representativeRoutes.home must be \"/\".')\n }\n\n if (config.capabilities?.contact) {\n assertNonEmpty(config.capabilities.contact.fieldProfile, 'contact.fieldProfile')\n if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(config.capabilities.contact.fieldProfile)) {\n throw new Error('contact.fieldProfile must be lowercase kebab-case.')\n }\n if (!ATTACHMENT_MODES.has(config.capabilities.contact.attachments)) {\n throw new Error('contact.attachments is unsupported.')\n }\n }\n if (\n config.capabilities?.blog &&\n !BLOG_ADAPTERS.has(config.capabilities.blog.adapter)\n ) {\n throw new Error('blog.adapter is unsupported.')\n }\n if (\n config.capabilities?.locations &&\n !LOCATION_STRATEGIES.has(config.capabilities.locations.strategy)\n ) {\n throw new Error('locations.strategy is unsupported.')\n }\n if (\n config.capabilities?.reviews &&\n !REVIEWS_PROVIDERS.has(config.capabilities.reviews.provider)\n ) {\n throw new Error('reviews.provider is unsupported.')\n }\n if (\n config.capabilities?.reviews?.provider === 'google-places' &&\n !config.routes.families.includes('legal')\n ) {\n throw new Error('Google Places reviews require the legal route family.')\n }\n if (config.capabilities?.reviews?.provider === 'google-places') {\n const reviews = config.capabilities.reviews\n if (!GOOGLE_REVIEWS_MODES.has(reviews.mode)) {\n throw new Error('reviews.mode is unsupported.')\n }\n if (reviews.selection && !GOOGLE_REVIEWS_SELECTIONS.has(reviews.selection)) {\n throw new Error('reviews.selection is unsupported.')\n }\n if (reviews.selection === 'five-star-featured' && reviews.mode !== 'full') {\n throw new Error('Five-star featured reviews require full mode.')\n }\n if (!Array.isArray(reviews.routeIds) || reviews.routeIds.length === 0) {\n throw new Error('Google Places reviews require at least one approved route ID.')\n }\n assertUnique(reviews.routeIds, 'reviews.routeIds')\n reviews.routeIds.forEach((routeId, index) => {\n if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(routeId)) {\n throw new Error(`reviews.routeIds[${index}] must be lowercase kebab-case.`)\n }\n })\n }\n\n if (config.capabilities?.reviews?.provider === 'google-business-profile') {\n const reviews = config.capabilities.reviews\n if (\n reviews.selection !== undefined &&\n !BUSINESS_PROFILE_REVIEWS_SELECTIONS.has(reviews.selection)\n ) {\n throw new Error('reviews.selection is unsupported.')\n }\n }\n\n if (config.sitemap?.mode === 'split') {\n if (config.sitemap.families.length === 0) {\n throw new Error('Split sitemap configuration requires at least one family.')\n }\n assertUnique(config.sitemap.families, 'sitemap.families')\n config.sitemap.families.forEach((path, index) =>\n assertRootRelativePath(path, `sitemap.families[${index}]`),\n )\n assertNonEmpty(config.sitemap.reason, 'sitemap.reason')\n }\n\n assertUnique(\n (config.exceptions ?? []).map((exception) => exception.ruleId),\n 'exceptions.ruleId',\n )\n\n ;(config.exceptions ?? []).forEach((exception, index) => {\n assertNonEmpty(exception.ruleId, `exceptions[${index}].ruleId`)\n assertNonEmpty(exception.rationale, `exceptions[${index}].rationale`)\n assertNonEmpty(exception.evidence, `exceptions[${index}].evidence`)\n assertNonEmpty(exception.reviewTrigger, `exceptions[${index}].reviewTrigger`)\n if (exception.owner !== 'Romie') {\n throw new Error(`exceptions[${index}].owner must be \"Romie\".`)\n }\n\n if (exception.expiresAt && Number.isNaN(Date.parse(exception.expiresAt))) {\n throw new Error(`exceptions[${index}].expiresAt must be a valid date.`)\n }\n })\n\n return config\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brandlab-digital/site-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -97,6 +97,10 @@
|
|
|
97
97
|
"types": "./dist/google-reviews.d.ts",
|
|
98
98
|
"import": "./dist/google-reviews.js"
|
|
99
99
|
},
|
|
100
|
+
"./google-business-reviews": {
|
|
101
|
+
"types": "./dist/google-business-reviews.d.ts",
|
|
102
|
+
"import": "./dist/google-business-reviews.js"
|
|
103
|
+
},
|
|
100
104
|
"./reviews": {
|
|
101
105
|
"types": "./dist/reviews.d.ts",
|
|
102
106
|
"import": "./dist/reviews.js"
|