@taprootio/site-authoring 0.37.1 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1259,6 +1259,25 @@ tracked-Markdown conflict, and a stale push is refused. There is no reverse
1259
1259
  Markdown exporter. See `taproot-site help page free-form` for the closed attrs
1260
1260
  reference and examples.
1261
1261
 
1262
+ ### Testimonial Google reviews in 0.38.0
1263
+
1264
+ A Testimonial block can show the site's selected Google reviews instead of
1265
+ hand-written quotes. In its component data set `"source": "google-reviews"` and
1266
+ optionally `"maxItems"`, a whole number from 1 to 12 (the default is 6). The
1267
+ newest selected reviews are shown, each with the reviewer's name and the month
1268
+ of the review, followed by a note that they are selected reviews from Google
1269
+ with a link to read them all on Google. Omit `source`, or use `"manual"`, for the
1270
+ hand-written `items`. The `items` are kept in the data whichever source is set.
1271
+ `source` and `maxItems` are refused at their field path when the value is
1272
+ unknown or out of range.
1273
+
1274
+ Which reviews are selected, and the minimum star rating, are set by someone who
1275
+ can manage the site's settings in the app under **Marketing → Google reviews**;
1276
+ they are not in the pulled workspace. The site needs a connected Google profile.
1277
+ Until it has reviews to show, a Google Testimonial publishes as empty. A release
1278
+ takes the reviews as they are when it is published. Help reference version 59
1279
+ covers the fields in `taproot-site help component testimonial`.
1280
+
1262
1281
  ### What changed between releases
1263
1282
 
1264
1283
  Taproot accepts only the latest CLI, so an upgrade can be forced at any time.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taprootio/site-authoring",
3
- "version": "0.37.1",
3
+ "version": "0.38.0",
4
4
  "description": "Taproot site authoring CLI: sign in once in the browser, then pull, validate, push, preview, approve, and deploy a site from the terminal",
5
5
  "type": "module",
6
6
  "license": "ISC",
@@ -1,5 +1,18 @@
1
1
  {
2
2
  "entries": [
3
+ {
4
+ "version": "0.38.0",
5
+ "note": "The Testimonial component can show the site's selected Google reviews: set source and maxItems in its component data.",
6
+ "behavior": [
7
+ "Testimonial component data accepts source (manual or google-reviews) and maxItems (a whole number from 1 to 12, shown newest first). Omitted source is manual, so every existing page is unchanged. Other values are refused at the field path before saving.",
8
+ "With source google-reviews the published page shows the site's selected Google reviews instead of the items, which stay in the data untouched. It adds Selected reviews from Google and a link to read all reviews on Google, and shows nothing until a connected Google profile has reviews it can show.",
9
+ "Which reviews are selected, and the minimum star rating, are chosen in the app under Marketing, Google reviews. They are not part of the pulled workspace. A new release picks up the reviews at publish; reviews are not live.",
10
+ "The help reference version is 59."
11
+ ],
12
+ "help": [
13
+ "component"
14
+ ]
15
+ },
3
16
  {
4
17
  "version": "0.37.1",
5
18
  "note": "Uses Espalier 6.15.0, whose footers keep every paragraph and link in the footer colors.",
@@ -22,6 +22,7 @@ import {
22
22
  } from "./vocabulary.js";
23
23
  import { normalizeCssLengthOverride } from "./media-presentation.js";
24
24
  import { isVideoEmbedId, parseVideoEmbedUrl, VIDEO_EMBED_REFUSAL } from "./video-embed-url.js";
25
+ import { TESTIMONIAL_MAX_ITEMS, TESTIMONIAL_SOURCES } from "./testimonial-google-reviews.js";
25
26
 
26
27
  /**
27
28
  * The eight canonical `componentBlock` data shapes. Seven remain mirrored
@@ -207,6 +208,16 @@ const FEATURE_GRID = Object.freeze({
207
208
 
208
209
  /** `TestimonialData` and its `TestimonialItem`. */
209
210
  const TESTIMONIAL = Object.freeze({
211
+ source: described(
212
+ enumOf(...TESTIMONIAL_SOURCES),
213
+ "manual shows the items below. google-reviews shows the site's selected Google reviews instead and keeps the items unchanged; the reviews come from the connected Google profile and are chosen in Marketing, Google reviews.",
214
+ ),
215
+ maxItems: num({
216
+ integer: true,
217
+ minimum: TESTIMONIAL_MAX_ITEMS.minimum,
218
+ maximum: TESTIMONIAL_MAX_ITEMS.maximum,
219
+ description: "How many Google reviews to show, newest first. Used only when source is google-reviews.",
220
+ }),
210
221
  items: withOmission(
211
222
  list(shape({
212
223
  quote: str(),
@@ -653,6 +664,8 @@ const COMPONENT_DEFINITIONS = Object.freeze({
653
664
  "Testimonials",
654
665
  "Attributed quotations displayed in a grid or timed carousel.",
655
666
  {
667
+ source: "manual",
668
+ maxItems: TESTIMONIAL_MAX_ITEMS.default,
656
669
  items: [{ quote: "", authorName: "", authorTitle: "", authorImage: null }],
657
670
  columns: 1,
658
671
  carousel: false,
@@ -665,6 +678,7 @@ const COMPONENT_DEFINITIONS = Object.freeze({
665
678
  "Keep carousel intervals long enough for the full quotation to be read.",
666
679
  "Set carousel:true for directional previous/next arrows, dot navigation and a play/pause control. Navigation or keyboard focus pauses rotation; reduced-motion users get manual navigation without sliding or automatic rotation.",
667
680
  "Use real attributed reviews, or clearly label fictional demo reviews. Never imply invented testimonials are genuine customer endorsements.",
681
+ "Set source:\"google-reviews\" only for a site with a connected Google profile; the published page shows the selected reviews with their reviewer names and a link to read all reviews on Google, and shows nothing until the profile has reviews it can show.",
668
682
  ],
669
683
  {
670
684
  items: [{
@@ -0,0 +1,87 @@
1
+ // Generated from shared/testimonial-google-reviews.ts by scripts/sync-field-validation.mjs. Do not edit.
2
+ /**
3
+ * The one owner of the Testimonial component's Google reviews fields (TR01339): the
4
+ * names, the allowed values and bounds, the function that normalizes stored data, and
5
+ * the one function that chooses which frozen reviews a component shows. The renderer
6
+ * (`generator/src/component-renderer.ts`), the editor and its preview, and the
7
+ * site-authoring CLI all read this file, so a later story adds its fields here and
8
+ * decides nothing again elsewhere. `shared/testimonial-google-reviews-corpus.json` is
9
+ * read by this module's tests and by the C# extractor's tests, so the two never
10
+ * disagree about what uses the Google source.
11
+ *
12
+ * It is pure and dependency-free. The generator, the editor and the CLI cannot import
13
+ * this file across project roots, so `node scripts/sync-field-validation.mjs` writes
14
+ * their copies; edit only this file and run it again.
15
+ */
16
+ /** `manual` is the hand-written quotations; `google-reviews` is the site's selected Google reviews. */
17
+ export const TESTIMONIAL_SOURCES = ["manual", "google-reviews"];
18
+ export const MANUAL_SOURCE = "manual";
19
+ export const GOOGLE_REVIEWS_SOURCE = "google-reviews";
20
+ /** How many reviews a Google-source component shows, as stored: a whole number from 1 to 12. */
21
+ export const TESTIMONIAL_MAX_ITEMS = Object.freeze({ minimum: 1, maximum: 12, default: 6 });
22
+ /** What a creator reads on a published page. Each is one sentence, so a change is made here only. */
23
+ export const GOOGLE_REVIEWS_ATTRIBUTION = "Selected reviews from Google";
24
+ export const GOOGLE_REVIEWS_LINK_TEXT = "Read all reviews on Google";
25
+ export const GOOGLE_REVIEW_LABEL = "Google review";
26
+ /** The reviewer shown when Google sent no name (the freeze stores an empty name, never these words). */
27
+ export const GOOGLE_USER_NAME = "Google user";
28
+ /** An unknown or mistyped source is the hand-written one, so older and foreign data renders as it always did. */
29
+ export function normalizeTestimonialSource(value) {
30
+ return value === GOOGLE_REVIEWS_SOURCE ? GOOGLE_REVIEWS_SOURCE : MANUAL_SOURCE;
31
+ }
32
+ /** A whole number clamped to 1 to 12; anything else is the default. */
33
+ export function normalizeTestimonialMaxItems(value) {
34
+ if (typeof value !== "number" || !Number.isFinite(value))
35
+ return TESTIMONIAL_MAX_ITEMS.default;
36
+ return Math.min(TESTIMONIAL_MAX_ITEMS.maximum, Math.max(TESTIMONIAL_MAX_ITEMS.minimum, Math.trunc(value)));
37
+ }
38
+ /** The two fields of component data that is not an object (or has neither) are the defaults. */
39
+ export function normalizeTestimonialGoogleFields(data) {
40
+ const record = data !== null && typeof data === "object" && !Array.isArray(data)
41
+ ? data
42
+ : {};
43
+ return {
44
+ source: normalizeTestimonialSource(record.source),
45
+ maxItems: normalizeTestimonialMaxItems(record.maxItems),
46
+ };
47
+ }
48
+ /**
49
+ * The month and year of a review in US English, in the given IANA time zone and in UTC when none is given or
50
+ * the zone is not one the runtime knows. Empty when the date is not a date.
51
+ */
52
+ export function formatReviewMonthYear(value, timeZone) {
53
+ const date = value instanceof Date ? value : new Date(value);
54
+ if (Number.isNaN(date.getTime()))
55
+ return "";
56
+ const options = { month: "long", year: "numeric" };
57
+ try {
58
+ return new Intl.DateTimeFormat("en-US", { ...options, timeZone: timeZone || "UTC" }).format(date);
59
+ }
60
+ catch {
61
+ return new Intl.DateTimeFormat("en-US", { ...options, timeZone: "UTC" }).format(date);
62
+ }
63
+ }
64
+ /**
65
+ * Which reviews a Testimonial component shows. With the Google source it is the first `maxItems` of the reviews
66
+ * in the order given (a release freezes them newest first), each with its reviewer and its second line; with the
67
+ * manual source, with no reviews, or without an https profile address it is null, and the component renders as an
68
+ * empty or hand-written one does. The renderer and the editor preview both call this, and later stories extend it.
69
+ */
70
+ export function chooseGoogleReviews(data, input, timeZone) {
71
+ const fields = normalizeTestimonialGoogleFields(data);
72
+ if (fields.source !== GOOGLE_REVIEWS_SOURCE || !input || input.reviews.length === 0)
73
+ return null;
74
+ // The profile link is the attribution every review needs, so an address that cannot be one shows no review.
75
+ if (!/^https:\/\//iu.test(input.mapsUri))
76
+ return null;
77
+ const items = input.reviews.slice(0, fields.maxItems).map((review) => {
78
+ const month = formatReviewMonthYear(review.createTime, timeZone);
79
+ return {
80
+ reviewId: review.reviewId,
81
+ text: review.text,
82
+ name: review.reviewerName.trim() === "" ? GOOGLE_USER_NAME : review.reviewerName,
83
+ byline: month ? `${GOOGLE_REVIEW_LABEL}, ${month}` : GOOGLE_REVIEW_LABEL,
84
+ };
85
+ });
86
+ return { mapsUri: input.mapsUri, items };
87
+ }
@@ -95,7 +95,7 @@ import {
95
95
 
96
96
  export { getAppearanceReference, getFooterReference, getSettingsReference, getThemeReference };
97
97
 
98
- export const REFERENCE_VERSION = 58;
98
+ export const REFERENCE_VERSION = 59;
99
99
 
100
100
  // The date-limit examples `help forms` prints; tests run them through the form validator.
101
101
  export const FORM_DATE_WINDOW_FIELD = Object.freeze({