@shop-on/theme-server 0.10.0 → 0.11.1

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 (168) hide show
  1. package/dist/account-state.js +1 -2
  2. package/dist/account.d.ts +1 -3
  3. package/dist/account.js +1 -3
  4. package/dist/activity.d.ts +1 -3
  5. package/dist/activity.js +1 -2
  6. package/dist/analytics-proxy.d.ts +8 -14
  7. package/dist/analytics-proxy.js +111 -28
  8. package/dist/analytics-script-proxy.d.ts +1 -5
  9. package/dist/analytics-script-proxy.js +4 -14
  10. package/dist/api-contract/src/addresses.js +32 -0
  11. package/dist/api-contract/src/areas.js +49 -0
  12. package/dist/api-contract/src/custom-data.d.ts +31 -0
  13. package/dist/api-contract/src/custom-data.js +303 -0
  14. package/dist/api-contract/src/ids.js +110 -0
  15. package/dist/api-contract/src/image.js +65 -0
  16. package/dist/api-contract/src/limits.js +44 -0
  17. package/dist/api-contract/src/media.js +13 -0
  18. package/dist/api-contract/src/pickup.js +11 -0
  19. package/dist/api-contract/src/recommendations.js +4 -0
  20. package/dist/api-contract/src/shops.js +27 -0
  21. package/dist/api-contract/src/storefront/analytics.d.ts +100 -0
  22. package/dist/api-contract/src/storefront/analytics.js +138 -0
  23. package/dist/api-contract/src/storefront/areas.d.ts +2 -0
  24. package/dist/api-contract/src/storefront/cart.d.ts +132 -0
  25. package/dist/api-contract/src/storefront/cart.js +248 -0
  26. package/dist/api-contract/src/storefront/catalog.d.ts +3 -0
  27. package/dist/api-contract/src/storefront/checkout-analytics.d.ts +2 -0
  28. package/dist/api-contract/src/storefront/checkout.d.ts +2 -0
  29. package/dist/api-contract/src/storefront/checkout.js +624 -0
  30. package/dist/api-contract/src/storefront/client.d.ts +3 -0
  31. package/dist/api-contract/src/storefront/client.js +6 -0
  32. package/dist/api-contract/src/storefront/content.d.ts +3 -0
  33. package/dist/api-contract/src/storefront/custom-data.d.ts +2 -0
  34. package/dist/api-contract/src/storefront/custom-data.js +27 -0
  35. package/dist/api-contract/src/storefront/customer.d.ts +2 -0
  36. package/dist/api-contract/src/storefront/customer.js +261 -0
  37. package/dist/api-contract/src/storefront/downloads.d.ts +2 -0
  38. package/dist/api-contract/src/storefront/draft-order-invoice.d.ts +2 -0
  39. package/dist/api-contract/src/storefront/forms.d.ts +2 -0
  40. package/dist/api-contract/src/storefront/forms.js +82 -0
  41. package/dist/api-contract/src/storefront/index.d.ts +20956 -0
  42. package/dist/api-contract/src/storefront/orders.d.ts +2 -0
  43. package/dist/api-contract/src/storefront/policies.d.ts +2 -0
  44. package/dist/api-contract/src/storefront/procedure.d.ts +2 -0
  45. package/dist/api-contract/src/storefront/procedure.js +29 -0
  46. package/dist/api-contract/src/storefront/reviews.d.ts +20 -0
  47. package/dist/api-contract/src/storefront/search.d.ts +3 -0
  48. package/dist/api-contract/src/storefront/seo.d.ts +2 -0
  49. package/dist/api-contract/src/storefront/seo.js +132 -0
  50. package/dist/api-contract/src/storefront/shop.d.ts +2 -0
  51. package/dist/api-contract/src/storefront/shop.js +101 -0
  52. package/dist/api-contract/src/taxonomy.js +5 -0
  53. package/dist/api-contract/src/text.js +15 -0
  54. package/dist/api-contract/src/theme-documents.js +13 -0
  55. package/dist/api-contract/src/theme-translations.d.ts +14 -0
  56. package/dist/api-contract/src/theme-translations.js +30 -0
  57. package/dist/api-contract/src/video.js +19 -0
  58. package/dist/availability.d.ts +6 -3
  59. package/dist/availability.js +11 -5
  60. package/dist/blog.d.ts +53 -59
  61. package/dist/blog.js +197 -497
  62. package/dist/cache.d.ts +5 -6
  63. package/dist/cache.js +1 -2
  64. package/dist/canonical-host.d.ts +4 -6
  65. package/dist/canonical-host.js +5 -6
  66. package/dist/card.js +159 -0
  67. package/dist/cart-customer.d.ts +1 -3
  68. package/dist/cart-customer.js +64 -105
  69. package/dist/cart-mutations.d.ts +43 -77
  70. package/dist/cart-mutations.js +106 -232
  71. package/dist/cart-recommendations.d.ts +1 -3
  72. package/dist/cart-recommendations.js +1 -2
  73. package/dist/cart-session.d.ts +1 -3
  74. package/dist/cart-session.js +1 -2
  75. package/dist/cart.d.ts +63 -224
  76. package/dist/cart.js +70 -197
  77. package/dist/checkout.d.ts +13 -17
  78. package/dist/checkout.js +75 -101
  79. package/dist/coalesce.js +57 -0
  80. package/dist/collection.d.ts +89 -298
  81. package/dist/collection.js +210 -656
  82. package/dist/contact.d.ts +20 -10
  83. package/dist/contact.js +36 -30
  84. package/dist/content-version.d.ts +37 -21
  85. package/dist/content-version.js +64 -42
  86. package/dist/contract-kit/src/client.d.ts +12 -0
  87. package/dist/contract-kit/src/client.js +156 -0
  88. package/dist/contract-kit/src/errors.d.ts +1 -0
  89. package/dist/contract-kit/src/errors.js +81 -0
  90. package/dist/contract-kit/src/ids.d.ts +1 -0
  91. package/dist/contract-kit/src/ids.js +118 -0
  92. package/dist/contract-kit/src/index.d.ts +7 -0
  93. package/dist/contract-kit/src/money.d.ts +1 -0
  94. package/dist/contract-kit/src/money.js +10 -0
  95. package/dist/contract-kit/src/pagination.d.ts +1 -0
  96. package/dist/contract-kit/src/procedure.d.ts +69 -0
  97. package/dist/contract-kit/src/procedure.js +16 -0
  98. package/dist/contract-kit/src/realtime.d.ts +1 -0
  99. package/dist/cookie-secret.js +1 -2
  100. package/dist/csrf.js +1 -2
  101. package/dist/customer-handoff.d.ts +1 -3
  102. package/dist/customer-handoff.js +10 -25
  103. package/dist/customer-session.d.ts +1 -3
  104. package/dist/customer-session.js +1 -2
  105. package/dist/customer.d.ts +2 -3
  106. package/dist/customer.js +27 -44
  107. package/dist/files.d.ts +49 -10
  108. package/dist/files.js +106 -89
  109. package/dist/fonts.d.ts +3 -5
  110. package/dist/fonts.js +16 -35
  111. package/dist/html.d.ts +1 -3
  112. package/dist/html.js +1 -2
  113. package/dist/liquid.d.ts +4 -10
  114. package/dist/liquid.js +25 -32
  115. package/dist/listing.js +79 -0
  116. package/dist/marketing-cookies.d.ts +1 -3
  117. package/dist/marketing-cookies.js +1 -2
  118. package/dist/menu.d.ts +46 -155
  119. package/dist/menu.js +51 -61
  120. package/dist/metafields.d.ts +9 -5
  121. package/dist/metafields.js +10 -38
  122. package/dist/metaobject.d.ts +10 -5
  123. package/dist/metaobject.js +43 -66
  124. package/dist/money.d.ts +7 -0
  125. package/dist/money.js +18 -0
  126. package/dist/newsletter.d.ts +19 -10
  127. package/dist/newsletter.js +31 -25
  128. package/dist/page.d.ts +13 -17
  129. package/dist/page.js +49 -105
  130. package/dist/password-session.d.ts +1 -3
  131. package/dist/password-session.js +1 -2
  132. package/dist/password.d.ts +25 -18
  133. package/dist/password.js +41 -59
  134. package/dist/policy.d.ts +7 -7
  135. package/dist/policy.js +19 -55
  136. package/dist/product.d.ts +42 -67
  137. package/dist/product.js +144 -644
  138. package/dist/read-ahead.d.ts +18 -0
  139. package/dist/read-ahead.js +32 -0
  140. package/dist/recommendations.d.ts +6 -12
  141. package/dist/recommendations.js +36 -60
  142. package/dist/review.d.ts +134 -94
  143. package/dist/review.js +257 -469
  144. package/dist/search.d.ts +59 -64
  145. package/dist/search.js +170 -469
  146. package/dist/seo-context.d.ts +1 -3
  147. package/dist/seo-context.js +4 -5
  148. package/dist/seo-documents.d.ts +50 -0
  149. package/dist/seo-documents.js +149 -0
  150. package/dist/shop-seo.d.ts +3 -5
  151. package/dist/shop-seo.js +7 -26
  152. package/dist/shop.d.ts +38 -42
  153. package/dist/shop.js +37 -51
  154. package/dist/store-availability.d.ts +12 -14
  155. package/dist/store-availability.js +18 -56
  156. package/dist/storefront.js +199 -0
  157. package/dist/structured-data.d.ts +3 -28
  158. package/dist/structured-data.js +19 -49
  159. package/dist/trace.js +1 -2
  160. package/dist/translations.d.ts +26 -31
  161. package/dist/translations.js +55 -28
  162. package/package.json +16 -14
  163. package/dist/graphql-env.d.ts +0 -22778
  164. package/dist/graphql.d.ts +0 -64
  165. package/dist/graphql.js +0 -344
  166. package/dist/schema.storefront.graphql +0 -10483
  167. package/dist/seo-proxy.d.ts +0 -11
  168. package/dist/seo-proxy.js +0 -26
@@ -0,0 +1,18 @@
1
+ /** A read started ahead of the await that uses it. Its failure is that
2
+ * await's to raise; on a path that returns or throws before it, the failure is
3
+ * dropped instead of surfacing as an unhandled rejection. */
4
+ export declare function readAhead<T>(read: Promise<T>): Promise<T>;
5
+ /**
6
+ * Route reads a loader starts while enrichment runs. A read is started with
7
+ * input built from the RAW document (`start`, from `enrich`'s `onFlags`) and
8
+ * taken after enrichment with input built the same way from the enriched one
9
+ * (`take`): the started read when the input is the same, a fresh one when
10
+ * enrichment changed a setting it was built from (a dynamic-source binding),
11
+ * so the page always renders what its final settings ask for. A started read
12
+ * nobody takes has its failure dropped; the read the page uses decides its
13
+ * error posture, as before.
14
+ */
15
+ export declare function earlyReads<I, T>(read: (input: I) => Promise<T>): {
16
+ start(input: I): void;
17
+ take(input: I): Promise<T>;
18
+ };
@@ -0,0 +1,32 @@
1
+ // src/read-ahead.ts
2
+ /** A read started ahead of the await that uses it. Its failure is that
3
+ * await's to raise; on a path that returns or throws before it, the failure is
4
+ * dropped instead of surfacing as an unhandled rejection. */
5
+ function readAhead(read) {
6
+ read.catch(() => {});
7
+ return read;
8
+ }
9
+ /**
10
+ * Route reads a loader starts while enrichment runs. A read is started with
11
+ * input built from the RAW document (`start`, from `enrich`'s `onFlags`) and
12
+ * taken after enrichment with input built the same way from the enriched one
13
+ * (`take`): the started read when the input is the same, a fresh one when
14
+ * enrichment changed a setting it was built from (a dynamic-source binding),
15
+ * so the page always renders what its final settings ask for. A started read
16
+ * nobody takes has its failure dropped; the read the page uses decides its
17
+ * error posture, as before.
18
+ */
19
+ function earlyReads(read) {
20
+ const started = /* @__PURE__ */ new Map();
21
+ return {
22
+ start(input) {
23
+ const key = JSON.stringify(input);
24
+ if (started.has(key)) return;
25
+ started.set(key, readAhead(read(input)));
26
+ },
27
+ take(input) {
28
+ return started.get(JSON.stringify(input)) ?? read(input);
29
+ }
30
+ };
31
+ }
32
+ export { earlyReads, readAhead };
@@ -1,29 +1,23 @@
1
1
  import { CollectionProductData } from "./collection.js";
2
- //#region src/recommendations.d.ts
3
2
  export type RecommendationIntent = "RELATED" | "COMPLEMENTARY";
4
3
  export type RecommendationsData = {
5
4
  intent: RecommendationIntent;
6
5
  reference_handle: string;
7
6
  /** The reference product's id — the join key `recommendation_shown` /
8
- * `recommendation_clicked` carry. `null` when the handle doesn't resolve. */
7
+ * `recommendation_clicked` carry. `null` when a buyer may not see it. */
9
8
  reference_id: string | null;
10
9
  products: CollectionProductData[];
11
10
  };
12
- /** Server fetch for the storefront `productRecommendations` field. Returns an
13
- * empty list on any network/GraphQL error so the PDP keeps rendering — the
14
- * recommendations rail is a non-critical surface. `includeOptions` (default
15
- * true) gates the variant-options payload — pass false when the consuming
16
- * cards render no swatches. */
11
+ /** The cards shown beside a product. An empty list when a buyer may not see
12
+ * the product, and on a failed read so the PDP keeps rendering — the rail is a
13
+ * non-critical surface. `includeOptions` (default true) gates the cards'
14
+ * options — pass false when they render no swatches. */
17
15
  export declare const fetchProductRecommendations: (data: {
18
16
  productHandle: string;
19
17
  intent: RecommendationIntent;
20
18
  includeOptions?: boolean;
21
- /** Each swatch value's variant (`firstSelectableVariant`), for cards whose
22
- * swatches switch the card to it. Needs `includeOptions`. */
23
- includeVariants?: boolean;
24
19
  locale?: string;
25
20
  /** Storefront-visible metafields (`"namespace.key"`) each card carries, for
26
21
  * the `closest_product_metafield` sources bound on it. Omitted ⇒ none. */
27
22
  metafieldKeys?: readonly string[];
28
- }) => Promise<RecommendationsData>;
29
- //#endregion
23
+ }) => Promise<RecommendationsData>;
@@ -1,72 +1,48 @@
1
1
  import { memoTTL } from "./cache.js";
2
- import { graphql, request } from "./graphql.js";
3
2
  import { getContentVersion } from "./content-version.js";
4
- import { metafieldKeysKey, metafieldKeysVariables } from "./product.js";
5
- import { CollectionProductNodeFragment, toCollectionProduct } from "./collection.js";
6
- //#region src/recommendations.ts
7
- const FetchProductRecommendationsQuery = graphql(`
8
- query FetchProductRecommendations(
9
- $productHandle: String!
10
- $intent: ProductRecommendationIntentEnum
11
- $includeOptions: Boolean!
12
- $includeVariants: Boolean!
13
- $mediaFirst: Int!
14
- $withMetafields: Boolean = false
15
- $metafieldFirst: Int = 0
16
- $metafieldKeys: [MetafieldKeyInput!] = []
17
- ) {
18
- reference: product(handle: $productHandle) {
19
- id
20
- }
21
- productRecommendations(productHandle: $productHandle, intent: $intent) {
22
- ...CollectionProductNode
23
- }
24
- }
25
- `, [CollectionProductNodeFragment]);
3
+ import { productRef, shapeKey, toCard } from "./card.js";
4
+ import { listingCard } from "./listing.js";
5
+ import { orFallback, orNotFound, storefront } from "./storefront.js";
6
+ // src/recommendations.ts
26
7
  /** A recommendation card's media: its image and the ones a hover gallery shows. */
27
8
  const MEDIA_FIRST = 5;
28
- const fetchRecommendationsCached = memoTTL(async ({ productHandle, intent, includeOptions, includeVariants, locale, metafieldKeys }) => {
29
- const res = await request(FetchProductRecommendationsQuery, {
30
- productHandle,
31
- intent,
32
- includeOptions,
33
- includeVariants,
34
- mediaFirst: MEDIA_FIRST,
35
- ...metafieldKeysVariables(metafieldKeys)
36
- }, locale ? { acceptLanguage: locale } : void 0);
37
- const products = res.productRecommendations.map(toCollectionProduct);
9
+ const none = (data) => ({
10
+ intent: data.intent,
11
+ reference_handle: data.productHandle,
12
+ reference_id: null,
13
+ products: []
14
+ });
15
+ const cardOf = (data) => listingCard({
16
+ mediaFirst: MEDIA_FIRST,
17
+ includeOptions: data.includeOptions,
18
+ metafieldKeys: data.metafieldKeys
19
+ });
20
+ const fetchRecommendationsCached = memoTTL(async (data) => {
21
+ const answer = await orNotFound(storefront(data.locale).products.recommendations({
22
+ ...productRef(data.productHandle),
23
+ intent: data.intent === "RELATED" ? "related" : "complementary",
24
+ card: cardOf(data)
25
+ }));
26
+ if (!answer) return none(data);
38
27
  return {
39
- intent,
40
- reference_handle: productHandle,
41
- reference_id: res.reference?.id ?? null,
42
- products
28
+ intent: data.intent,
29
+ reference_handle: data.productHandle,
30
+ reference_id: answer.productId,
31
+ products: answer.items.map(toCard)
43
32
  };
44
33
  }, {
45
- key: ({ productHandle, intent, includeOptions, includeVariants, locale, metafieldKeys }) => `${intent}|${productHandle}|${includeOptions}|${includeVariants}|${locale ?? ""}|${metafieldKeysKey(metafieldKeys)}`,
34
+ key: (data) => `${data.intent}|${data.productHandle}|${data.locale ?? ""}|${shapeKey(cardOf(data))}`,
46
35
  version: getContentVersion
47
36
  });
48
- /** Server fetch for the storefront `productRecommendations` field. Returns an
49
- * empty list on any network/GraphQL error so the PDP keeps rendering — the
50
- * recommendations rail is a non-critical surface. `includeOptions` (default
51
- * true) gates the variant-options payload — pass false when the consuming
52
- * cards render no swatches. */
37
+ /** The cards shown beside a product. An empty list when a buyer may not see
38
+ * the product, and on a failed read so the PDP keeps rendering — the rail is a
39
+ * non-critical surface. `includeOptions` (default true) gates the cards'
40
+ * options — pass false when they render no swatches. */
53
41
  const fetchProductRecommendations = async (data) => {
54
- const includeOptions = data.includeOptions ?? true;
55
- try {
56
- return await fetchRecommendationsCached({
57
- ...data,
58
- includeOptions,
59
- includeVariants: includeOptions && (data.includeVariants ?? false)
60
- });
61
- } catch (err) {
62
- console.warn("[fetchProductRecommendations] failed:", err);
63
- return {
64
- intent: data.intent,
65
- reference_handle: data.productHandle,
66
- reference_id: null,
67
- products: []
68
- };
69
- }
42
+ const input = {
43
+ ...data,
44
+ includeOptions: data.includeOptions ?? true
45
+ };
46
+ return orFallback(fetchRecommendationsCached(input), none(input), "fetchProductRecommendations");
70
47
  };
71
- //#endregion
72
48
  export { fetchProductRecommendations };
package/dist/review.d.ts CHANGED
@@ -1,6 +1,22 @@
1
+ import { REVIEW_ANSWER_REFUSALS, REVIEW_PHOTO_REFUSALS } from "./api-contract/src/storefront/reviews.js";
2
+ import "./api-contract/src/storefront/index.js";
1
3
  import { ImageFileInfo } from "./files.js";
2
- //#region src/review.d.ts
3
- export type ReviewVoteDirection = "UP" | "DOWN";
4
+ /** A reviewer's answer to one of the shop's review questions, under the
5
+ * question's current name. `value` is a choice's key or a scale's step `"1"`
6
+ * to `"5"`; `label` is the choice's label, or for a step the scale's nearest
7
+ * end (null where the merchant set none). */
8
+ export type ReviewAnswerData = {
9
+ attributeId: string;
10
+ handle: string;
11
+ name: string;
12
+ type: "choice" | "scale";
13
+ value: string;
14
+ label: string | null;
15
+ };
16
+ export type ReviewVoteDirection = "up" | "down";
17
+ /** A buyer photo on a review: `url` / `srcset` the display tier (a lightbox
18
+ * stage, a testimonial card), `thumbUrl` / `thumbSrcset` the small square in a
19
+ * review row; `width` / `height` the original's (its aspect ratio). */
4
20
  export type ReviewMedia = {
5
21
  id: string;
6
22
  url: string | null;
@@ -11,102 +27,114 @@ export type ReviewMedia = {
11
27
  height: number | null;
12
28
  thumbhash: string | null;
13
29
  };
14
- export type ReviewAttributeData = {
15
- definitionId: string;
16
- name: string;
17
- fieldType: "CHOICE" | "SCALE";
18
- value: string;
19
- valueLabel: string | null;
20
- };
21
- export type ReviewProduct = {
22
- handle: string;
23
- title: string;
24
- active: boolean;
25
- image: ImageFileInfo | null;
26
- };
27
30
  export type ReviewData = {
28
31
  id: string;
29
32
  rating: number;
30
33
  title: string | null;
31
34
  body: string;
32
35
  authorName: string;
33
- verified: boolean;
36
+ verifiedBuyer: boolean;
34
37
  createdAt: string;
35
- upvoteCount: number;
36
- downvoteCount: number;
37
- media: ReviewMedia[];
38
- merchantReply: {
38
+ answers: ReviewAnswerData[];
39
+ /** The merchant's public reply. */
40
+ reply: {
39
41
  body: string;
40
42
  repliedAt: string;
41
43
  } | null;
42
- attributes: ReviewAttributeData[];
43
- product: ReviewProduct | null;
44
+ /** Buyer photos, upload order, at most 3. */
45
+ media: ReviewMedia[];
46
+ upvoteCount: number;
47
+ downvoteCount: number;
48
+ /** The current buyer's helpful vote; null when they have none or are anonymous. */
44
49
  myVote: ReviewVoteDirection | null;
45
50
  };
46
- export declare function fetchReview(id: string, locale?: string): Promise<ReviewData | null>;
47
- export declare function fetchReviews(ids: readonly string[], locale?: string): Promise<ReviewData[]>;
48
- export type ProductReviewSort = "RELEVANCE" | "CREATED_DESC" | "CREATED_ASC" | "RATING_DESC" | "RATING_ASC";
51
+ /** The product a picked review is about: a review card links back to it and
52
+ * shows its thumbnail. */
53
+ export type ReviewProduct = {
54
+ id: string;
55
+ handle: string;
56
+ title: string;
57
+ url: string;
58
+ image: ImageFileInfo | null;
59
+ };
60
+ /** A picked review (`review` / `review_list` settings), which may be about any
61
+ * product in the shop. */
62
+ export type ReviewCardData = ReviewData & {
63
+ product: ReviewProduct;
64
+ };
65
+ /** A picked review (`review` setting). Its questions' names and labels are
66
+ * the merchant's, translated, so the read is in the buyer's language. Null for
67
+ * a review a buyer may not see, an id that is no review's (no call is made),
68
+ * and on a failed read. */
69
+ export declare function fetchReview(id: string, locale?: string): Promise<ReviewCardData | null>;
70
+ /** A `review_list` setting's picks, in the merchant's order: one a buyer may
71
+ * not see is dropped rather than left as a hole, so a section renders the list
72
+ * without guarding each entry. A review picked twice renders twice. */
73
+ export declare function fetchReviews(ids: readonly string[], locale?: string): Promise<ReviewCardData[]>;
74
+ /** The orders a buyer can list a product's reviews in; by rating, newest
75
+ * first among equals. `relevance` is "most helpful", main's default. */
76
+ export type ProductReviewSort = "relevance" | "newest" | "oldest" | "rating_desc" | "rating_asc";
49
77
  export type ProductReviewsPage = {
50
78
  reviews: ReviewData[];
79
+ /** How many reviews the list holds under its `rating` filter. */
80
+ total: number;
81
+ /** The page answered, 1-based. */
82
+ page: number;
51
83
  hasNextPage: boolean;
52
- endCursor: string | null;
53
84
  };
54
- /** One page of a product's PUBLISHED reviews. Status filtering is the ability's
55
- * job (see the module header), so the theme never filters. Returns an empty
56
- * page rather than throwing — a failed review fetch must not take the PDP down.
57
- *
58
- * `ratingEq` narrows to a single star bucket (the summary chart's rows are the
59
- * natural trigger); omit it for all reviews. */
60
- export declare function fetchProductReviews({ handle, first, after, sort, ratingEq, verifiedEq, locale }: {
85
+ /** Page `page` of a product's published reviews, `perPage` a page (at most
86
+ * the api's page size). `rating` narrows the list to that many stars,
87
+ * `verified` to verified buyers' reviews. A signed-in buyer's read carries
88
+ * their own vote on each review (`myVote`). An
89
+ * empty page for a product a buyer may not see and on a failed read: a
90
+ * failed review list must not take the product page down. Read fresh on every
91
+ * call: the page, sort and rating permutations would crowd the TTL cache, and a
92
+ * review just published must show on the next read. */
93
+ export declare function fetchProductReviews(data: {
61
94
  handle: string;
62
- first?: number;
63
- after?: string | null;
95
+ page?: number;
96
+ perPage?: number;
64
97
  sort?: ProductReviewSort;
65
- ratingEq?: number | null;
66
- verifiedEq?: boolean | null;
98
+ rating?: number | null;
99
+ verified?: boolean;
67
100
  locale?: string;
68
101
  }): Promise<ProductReviewsPage>;
69
- export type ReviewAttributeChoice = {
70
- key: string;
71
- label: string;
72
- };
73
- export type ReviewAttributeScaleLabels = {
74
- min: string;
75
- mid: string | null;
76
- max: string;
77
- };
78
- export type ReviewAttributeDefinition = {
102
+ /** One of the shop's review questions as a product's reviews answer it: the
103
+ * submit form draws a field for each (`choices` for a choice question,
104
+ * `scaleLabels` for a scale), and the summary draws a scale question's
105
+ * `average` and a bar per `distribution` value (a choice's key, or a step
106
+ * `"1"` to `"5"` with no label). `count` is how many of the product's
107
+ * published reviews answered it. */
108
+ export type ReviewQuestion = {
79
109
  id: string;
80
110
  handle: string;
81
111
  name: string;
82
- fieldType: "CHOICE" | "SCALE";
112
+ type: "choice" | "scale";
83
113
  required: boolean;
84
- choices: ReviewAttributeChoice[] | null;
85
- scaleLabels: ReviewAttributeScaleLabels | null;
86
- };
87
- export type ReviewAttributeDistributionBucket = {
88
- value: string;
89
- valueLabel: string | null;
90
- count: number;
91
- };
92
- export type ReviewAttributeAggregate = {
93
- definitionId: string;
94
- name: string;
95
- fieldType: "CHOICE" | "SCALE";
96
- scaleLabels: ReviewAttributeScaleLabels | null;
114
+ choices: {
115
+ key: string;
116
+ label: string;
117
+ }[];
118
+ scaleLabels: {
119
+ min: string;
120
+ mid: string | null;
121
+ max: string;
122
+ } | null;
97
123
  count: number;
98
124
  average: number | null;
99
- distribution: ReviewAttributeDistributionBucket[];
100
- };
101
- export type ProductReviewAttributeConfig = {
102
- definitions: ReviewAttributeDefinition[];
103
- aggregates: ReviewAttributeAggregate[];
125
+ distribution: {
126
+ value: string;
127
+ label: string | null;
128
+ count: number;
129
+ }[];
104
130
  };
105
- /** The product's custom review-attribute definitions (for the submit form) and
106
- * aggregates (for the summary bars), in one memoized round trip. Shop config +
107
- * review-derived counters, content-version keyed like the other picker fetches.
108
- * Never throws — a failure yields empty config rather than taking the PDP down. */
109
- export declare function fetchProductReviewAttributeConfig(handle: string, locale?: string): Promise<ProductReviewAttributeConfig>;
131
+ /** The review questions that apply to a product, in the merchant's order, in
132
+ * the buyer's language. Empty for a product a buyer may not see and on a
133
+ * failed read. */
134
+ export declare function fetchReviewQuestions(handle: string, locale?: string): Promise<ReviewQuestion[]>;
135
+ /** The vote tallies a vote answers with, for the list to reconcile its
136
+ * optimistic guess. AUTH_REQUIRED: no buyer is signed in (the theme sends
137
+ * them to sign in); FAILED: refused or failed (the theme reverts). */
110
138
  export type ReviewVoteResult = {
111
139
  ok: true;
112
140
  upvoteCount: number;
@@ -116,13 +144,13 @@ export type ReviewVoteResult = {
116
144
  ok: false;
117
145
  reason: "AUTH_REQUIRED" | "FAILED";
118
146
  };
119
- /** Cast (or switch) the current buyer's helpful-vote on a review. Requires a
120
- * customer session — anonymous callers get AUTH_REQUIRED so the theme can route
121
- * them to sign in. Never throws: a transport failure resolves to FAILED. */
147
+ /** Cast or switch the signed-in buyer's helpful vote on a review. Never throws. */
122
148
  export declare function setReviewVote(reviewId: string, direction: ReviewVoteDirection): Promise<ReviewVoteResult>;
123
- /** Clear the current buyer's helpful-vote on a review (un-vote). Same auth +
124
- * failure contract as {@link setReviewVote}. */
149
+ /** Clear the signed-in buyer's helpful vote on a review. Never throws. */
125
150
  export declare function deleteReviewVote(reviewId: string): Promise<ReviewVoteResult>;
151
+ /** The buyer's review of a product (`productId`, `ProductData.id`). A
152
+ * signed-in buyer's review is theirs: the api takes their email (and their
153
+ * name when they have one) in place of the ones sent. */
126
154
  export type ReviewSubmitInput = {
127
155
  productId: string;
128
156
  authorName: string;
@@ -130,33 +158,45 @@ export type ReviewSubmitInput = {
130
158
  rating: number;
131
159
  title?: string | null;
132
160
  body: string;
133
- attributes?: {
134
- definitionId: string;
161
+ /** Answers to the review questions: `attributeId` is the question's `id`
162
+ * (`ReviewQuestion.id`), `value` a choice's key or a scale's step "1".."5".
163
+ * A question left out is not answered. */
164
+ answers?: {
165
+ attributeId: string;
135
166
  value: string;
136
167
  }[];
168
+ /** The widget's token; empty or absent when the shop has no widget. */
169
+ turnstileToken?: string;
137
170
  };
171
+ /** Why the api refused a review, one entry per reason, for the form to word
172
+ * by `field`: `RATE_LIMITED` (`retryAfterSeconds` until the next is counted),
173
+ * `TURNSTILE_FAILED`, `NOT_FOUND` (the product is not one a buyer may see),
174
+ * `CONFLICT` (this email has reviewed the product already, on
175
+ * `authorEmail`), `VALIDATION_FAILED` (one per issue, `field` the input it
176
+ * names), `ANSWERS_REFUSED` (one per refused answer: its question's
177
+ * `attributeId` and `reason`), `PHOTOS_REFUSED` (one per refused photo, on
178
+ * `media`, with its `reason`; a photo the api would not take for upload is
179
+ * `invalid_type` or `too_large`), `FAILED` (anything else: a generic retry). */
138
180
  export type ReviewSubmitError = {
139
- code: string;
181
+ code: "RATE_LIMITED" | "TURNSTILE_FAILED" | "NOT_FOUND" | "CONFLICT" | "VALIDATION_FAILED" | "ANSWERS_REFUSED" | "PHOTOS_REFUSED" | "FAILED";
140
182
  field: string | null;
141
- message: string;
183
+ attributeId?: string;
184
+ reason?: (typeof REVIEW_ANSWER_REFUSALS)[number] | (typeof REVIEW_PHOTO_REFUSALS)[number] | "invalid_type" | "too_large";
185
+ retryAfterSeconds?: number;
142
186
  };
187
+ /** `published` tells the two moderation outcomes apart: `true` ⇒ visible now,
188
+ * so the list's next read carries it; `false` ⇒ queued for the merchant's
189
+ * approval (show a confirmation). */
143
190
  export type ReviewSubmitResult = {
144
191
  ok: true;
145
192
  published: boolean;
146
- review: ReviewData | null;
147
193
  } | {
148
194
  ok: false;
149
- userErrors: ReviewSubmitError[];
195
+ errors: ReviewSubmitError[];
150
196
  };
151
- /** Submit a new review on a product. Reads the `customer_session` cookie itself
152
- * (threaded as `X-Customer-Session` so the API can force the buyer's identity +
153
- * compute verified-buyer status). Photos ride a multipart transport
154
- * ({@link requestUpload}); a text-only submit goes out as an ordinary JSON
155
- * mutation. Never throws — a transport failure resolves to a single `FAILED`
156
- * userError so the form can show a generic retry message.
157
- *
158
- * On success, `published` distinguishes the two moderation outcomes: `true` ⇒
159
- * publicly visible now (the caller can render `review` in the list); `false` ⇒
160
- * queued for merchant approval (show a confirmation, don't list it). */
161
- export declare function submitReview(input: ReviewSubmitInput, media?: readonly Blob[]): Promise<ReviewSubmitResult>;
162
- //#endregion
197
+ /** Submit a buyer's review (`reviews.submit`), with up to three photos
198
+ * (`media`) uploaded first. The token goes only when the form has one: a shop
199
+ * without a widget asks for none. Never throws: a refusal the form does not
200
+ * word, and a transport failure, resolve to a single `FAILED` error so it can
201
+ * show a generic retry message. */
202
+ export declare function submitReview(input: ReviewSubmitInput, media?: readonly Blob[]): Promise<ReviewSubmitResult>;