@shop-on/theme-server 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account-state.js +1 -2
- package/dist/account.d.ts +1 -3
- package/dist/account.js +1 -3
- package/dist/activity.d.ts +1 -3
- package/dist/activity.js +1 -2
- package/dist/analytics-proxy.d.ts +8 -14
- package/dist/analytics-proxy.js +111 -28
- package/dist/analytics-script-proxy.d.ts +1 -5
- package/dist/analytics-script-proxy.js +4 -14
- package/dist/api-contract/src/addresses.js +32 -0
- package/dist/api-contract/src/areas.js +49 -0
- package/dist/api-contract/src/custom-data.d.ts +31 -0
- package/dist/api-contract/src/custom-data.js +303 -0
- package/dist/api-contract/src/ids.js +110 -0
- package/dist/api-contract/src/image.js +65 -0
- package/dist/api-contract/src/limits.js +44 -0
- package/dist/api-contract/src/media.js +13 -0
- package/dist/api-contract/src/pickup.js +11 -0
- package/dist/api-contract/src/recommendations.js +4 -0
- package/dist/api-contract/src/shops.js +27 -0
- package/dist/api-contract/src/storefront/analytics.d.ts +100 -0
- package/dist/api-contract/src/storefront/analytics.js +138 -0
- package/dist/api-contract/src/storefront/areas.d.ts +2 -0
- package/dist/api-contract/src/storefront/cart.d.ts +132 -0
- package/dist/api-contract/src/storefront/cart.js +248 -0
- package/dist/api-contract/src/storefront/catalog.d.ts +3 -0
- package/dist/api-contract/src/storefront/checkout-analytics.d.ts +2 -0
- package/dist/api-contract/src/storefront/checkout.d.ts +2 -0
- package/dist/api-contract/src/storefront/checkout.js +624 -0
- package/dist/api-contract/src/storefront/client.d.ts +3 -0
- package/dist/api-contract/src/storefront/client.js +6 -0
- package/dist/api-contract/src/storefront/content.d.ts +3 -0
- package/dist/api-contract/src/storefront/custom-data.d.ts +2 -0
- package/dist/api-contract/src/storefront/custom-data.js +27 -0
- package/dist/api-contract/src/storefront/customer.d.ts +2 -0
- package/dist/api-contract/src/storefront/customer.js +261 -0
- package/dist/api-contract/src/storefront/downloads.d.ts +2 -0
- package/dist/api-contract/src/storefront/draft-order-invoice.d.ts +2 -0
- package/dist/api-contract/src/storefront/forms.d.ts +2 -0
- package/dist/api-contract/src/storefront/forms.js +82 -0
- package/dist/api-contract/src/storefront/index.d.ts +20956 -0
- package/dist/api-contract/src/storefront/orders.d.ts +2 -0
- package/dist/api-contract/src/storefront/policies.d.ts +2 -0
- package/dist/api-contract/src/storefront/procedure.d.ts +2 -0
- package/dist/api-contract/src/storefront/procedure.js +29 -0
- package/dist/api-contract/src/storefront/reviews.d.ts +20 -0
- package/dist/api-contract/src/storefront/search.d.ts +3 -0
- package/dist/api-contract/src/storefront/seo.d.ts +2 -0
- package/dist/api-contract/src/storefront/seo.js +132 -0
- package/dist/api-contract/src/storefront/shop.d.ts +2 -0
- package/dist/api-contract/src/storefront/shop.js +101 -0
- package/dist/api-contract/src/taxonomy.js +5 -0
- package/dist/api-contract/src/text.js +15 -0
- package/dist/api-contract/src/theme-documents.js +13 -0
- package/dist/api-contract/src/theme-translations.d.ts +14 -0
- package/dist/api-contract/src/theme-translations.js +30 -0
- package/dist/api-contract/src/video.js +19 -0
- package/dist/availability.d.ts +6 -3
- package/dist/availability.js +11 -5
- package/dist/blog.d.ts +53 -59
- package/dist/blog.js +197 -497
- package/dist/cache.d.ts +5 -6
- package/dist/cache.js +1 -2
- package/dist/canonical-host.d.ts +4 -6
- package/dist/canonical-host.js +5 -6
- package/dist/card.js +159 -0
- package/dist/cart-customer.d.ts +1 -3
- package/dist/cart-customer.js +64 -105
- package/dist/cart-mutations.d.ts +43 -77
- package/dist/cart-mutations.js +106 -232
- package/dist/cart-recommendations.d.ts +1 -3
- package/dist/cart-recommendations.js +1 -2
- package/dist/cart-session.d.ts +1 -3
- package/dist/cart-session.js +1 -2
- package/dist/cart.d.ts +63 -224
- package/dist/cart.js +70 -197
- package/dist/checkout.d.ts +13 -17
- package/dist/checkout.js +75 -101
- package/dist/coalesce.js +57 -0
- package/dist/collection.d.ts +89 -298
- package/dist/collection.js +210 -656
- package/dist/contact.d.ts +20 -10
- package/dist/contact.js +36 -30
- package/dist/content-version.d.ts +37 -21
- package/dist/content-version.js +64 -42
- package/dist/contract-kit/src/client.d.ts +12 -0
- package/dist/contract-kit/src/client.js +156 -0
- package/dist/contract-kit/src/errors.d.ts +1 -0
- package/dist/contract-kit/src/errors.js +81 -0
- package/dist/contract-kit/src/ids.d.ts +1 -0
- package/dist/contract-kit/src/ids.js +118 -0
- package/dist/contract-kit/src/index.d.ts +7 -0
- package/dist/contract-kit/src/money.d.ts +1 -0
- package/dist/contract-kit/src/money.js +10 -0
- package/dist/contract-kit/src/pagination.d.ts +1 -0
- package/dist/contract-kit/src/procedure.d.ts +69 -0
- package/dist/contract-kit/src/procedure.js +16 -0
- package/dist/contract-kit/src/realtime.d.ts +1 -0
- package/dist/cookie-secret.js +1 -2
- package/dist/csrf.js +1 -2
- package/dist/customer-handoff.d.ts +1 -3
- package/dist/customer-handoff.js +10 -25
- package/dist/customer-session.d.ts +1 -3
- package/dist/customer-session.js +1 -2
- package/dist/customer.d.ts +2 -3
- package/dist/customer.js +27 -44
- package/dist/files.d.ts +49 -10
- package/dist/files.js +106 -89
- package/dist/fonts.d.ts +3 -5
- package/dist/fonts.js +16 -35
- package/dist/html.d.ts +1 -3
- package/dist/html.js +1 -2
- package/dist/liquid.d.ts +4 -10
- package/dist/liquid.js +25 -32
- package/dist/listing.js +79 -0
- package/dist/marketing-cookies.d.ts +1 -3
- package/dist/marketing-cookies.js +1 -2
- package/dist/menu.d.ts +46 -155
- package/dist/menu.js +51 -61
- package/dist/metafields.d.ts +9 -5
- package/dist/metafields.js +10 -38
- package/dist/metaobject.d.ts +10 -5
- package/dist/metaobject.js +43 -66
- package/dist/money.d.ts +7 -0
- package/dist/money.js +18 -0
- package/dist/newsletter.d.ts +19 -10
- package/dist/newsletter.js +31 -25
- package/dist/page.d.ts +13 -17
- package/dist/page.js +49 -105
- package/dist/password-session.d.ts +1 -3
- package/dist/password-session.js +1 -2
- package/dist/password.d.ts +25 -18
- package/dist/password.js +41 -59
- package/dist/policy.d.ts +7 -7
- package/dist/policy.js +19 -55
- package/dist/product.d.ts +42 -67
- package/dist/product.js +144 -644
- package/dist/read-ahead.d.ts +18 -0
- package/dist/read-ahead.js +32 -0
- package/dist/recommendations.d.ts +6 -12
- package/dist/recommendations.js +36 -60
- package/dist/review.d.ts +134 -94
- package/dist/review.js +257 -469
- package/dist/search.d.ts +59 -64
- package/dist/search.js +170 -469
- package/dist/seo-context.d.ts +1 -3
- package/dist/seo-context.js +4 -5
- package/dist/seo-documents.d.ts +50 -0
- package/dist/seo-documents.js +149 -0
- package/dist/shop-seo.d.ts +3 -5
- package/dist/shop-seo.js +7 -26
- package/dist/shop.d.ts +38 -42
- package/dist/shop.js +37 -51
- package/dist/store-availability.d.ts +12 -14
- package/dist/store-availability.js +18 -56
- package/dist/storefront.js +199 -0
- package/dist/structured-data.d.ts +3 -28
- package/dist/structured-data.js +19 -49
- package/dist/trace.js +1 -2
- package/dist/translations.d.ts +26 -31
- package/dist/translations.js +55 -28
- package/package.json +16 -14
- package/dist/graphql-env.d.ts +0 -22778
- package/dist/graphql.d.ts +0 -64
- package/dist/graphql.js +0 -344
- package/dist/schema.storefront.graphql +0 -10483
- package/dist/seo-proxy.d.ts +0 -11
- 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
|
|
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
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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>;
|
package/dist/recommendations.js
CHANGED
|
@@ -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 {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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:
|
|
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: (
|
|
34
|
+
key: (data) => `${data.intent}|${data.productHandle}|${data.locale ?? ""}|${shapeKey(cardOf(data))}`,
|
|
46
35
|
version: getContentVersion
|
|
47
36
|
});
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
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
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
3
|
-
|
|
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
|
-
|
|
36
|
+
verifiedBuyer: boolean;
|
|
34
37
|
createdAt: string;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
export type
|
|
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
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
|
|
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
|
-
|
|
63
|
-
|
|
95
|
+
page?: number;
|
|
96
|
+
perPage?: number;
|
|
64
97
|
sort?: ProductReviewSort;
|
|
65
|
-
|
|
66
|
-
|
|
98
|
+
rating?: number | null;
|
|
99
|
+
verified?: boolean;
|
|
67
100
|
locale?: string;
|
|
68
101
|
}): Promise<ProductReviewsPage>;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
112
|
+
type: "choice" | "scale";
|
|
83
113
|
required: boolean;
|
|
84
|
-
choices:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
125
|
+
distribution: {
|
|
126
|
+
value: string;
|
|
127
|
+
label: string | null;
|
|
128
|
+
count: number;
|
|
129
|
+
}[];
|
|
104
130
|
};
|
|
105
|
-
/** The
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
|
|
109
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
134
|
-
|
|
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:
|
|
181
|
+
code: "RATE_LIMITED" | "TURNSTILE_FAILED" | "NOT_FOUND" | "CONFLICT" | "VALIDATION_FAILED" | "ANSWERS_REFUSED" | "PHOTOS_REFUSED" | "FAILED";
|
|
140
182
|
field: string | null;
|
|
141
|
-
|
|
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
|
-
|
|
195
|
+
errors: ReviewSubmitError[];
|
|
150
196
|
};
|
|
151
|
-
/** Submit a
|
|
152
|
-
* (
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
|
|
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>;
|