@shoppexio/storefront-react 0.1.1 → 0.1.2
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/CHANGELOG.md +10 -0
- package/dist/index.d.ts +23 -1
- package/dist/index.js +24 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
- Contact form: a message that is longer than the 2,000-character ticket
|
|
6
|
+
limit once the name line is added is refused with an error naming the
|
|
7
|
+
limit, instead of being cut off and reported as sent.
|
|
8
|
+
- Contact form: a subject over 30 characters is refused, not cut.
|
|
9
|
+
- `loadLatestWrittenReviews(limit, labels)`: the newest written reviews for a
|
|
10
|
+
sample, paging the feed only until it has enough. `getShopReviewsPage` is
|
|
11
|
+
typed on the SDK global.
|
|
12
|
+
|
|
3
13
|
## 0.1.1
|
|
4
14
|
|
|
5
15
|
- README rewritten for theme developers: install, quick start, theming,
|
package/dist/index.d.ts
CHANGED
|
@@ -892,6 +892,20 @@ interface ShoppexSdk {
|
|
|
892
892
|
success: boolean;
|
|
893
893
|
data?: SdkShopReview[];
|
|
894
894
|
}>;
|
|
895
|
+
/**
|
|
896
|
+
* One page of the same feed, newest first. `cursor` is the previous page's
|
|
897
|
+
* `pagination.next_cursor`; omit it for the first page.
|
|
898
|
+
*/
|
|
899
|
+
getShopReviewsPage(cursor?: string | null): Promise<{
|
|
900
|
+
success: boolean;
|
|
901
|
+
data?: {
|
|
902
|
+
feedback: SdkShopReview[];
|
|
903
|
+
pagination: {
|
|
904
|
+
next_cursor: string | null;
|
|
905
|
+
has_more: boolean;
|
|
906
|
+
};
|
|
907
|
+
};
|
|
908
|
+
}>;
|
|
895
909
|
/** Starts an in-page sign-in. Sends the email and nothing else. */
|
|
896
910
|
requestOtp(email: string): Promise<SdkResponse<unknown>>;
|
|
897
911
|
/**
|
|
@@ -2894,6 +2908,14 @@ declare function toShopReviews(rows: readonly SdkShopReview[], labels: ShopRevie
|
|
|
2894
2908
|
* derive a number from them.
|
|
2895
2909
|
*/
|
|
2896
2910
|
declare function reviewsForProduct(reviews: readonly ShopReview[], productTitle: string): ShopReview[];
|
|
2911
|
+
/**
|
|
2912
|
+
* The newest WRITTEN reviews, at most `limit`, for a sample such as a home
|
|
2913
|
+
* section. Pages through the feed only until it has enough: a shop with a
|
|
2914
|
+
* thousand reviews costs one request, not ten. Automated entries and ratings
|
|
2915
|
+
* without words are skipped, since a sample of quotes needs quotes.
|
|
2916
|
+
* Resolves null when a page request fails.
|
|
2917
|
+
*/
|
|
2918
|
+
declare function loadLatestWrittenReviews(limit: number, labels: ShopReviewLabels): Promise<ShopReview[] | null>;
|
|
2897
2919
|
declare function averageRating(reviews: readonly ShopReview[]): number | null;
|
|
2898
2920
|
declare function useShopReviews(labels: ShopReviewLabels): ShopReviewsState;
|
|
2899
2921
|
|
|
@@ -3084,4 +3106,4 @@ declare function useOnlineUserCount(): number | null;
|
|
|
3084
3106
|
*/
|
|
3085
3107
|
declare function resolveProductVideoEmbedSrc(value: unknown): string | null;
|
|
3086
3108
|
|
|
3087
|
-
export { ACCOUNT_ARTIFACT_CAPABILITIES, ACCOUNT_PATH, ACCOUNT_PATH_ALIAS, ACCOUNT_ROUTE_MESSAGE_KEYS, ACCOUNT_STOREFRONT_ROUTES, ACCOUNT_TABS, type AccountRouteMessageKey, type AccountRouteParts, type AccountTab, type AccountView, type BuyBoxVariantModel, CATALOG_PAGE_SIZE, CATALOG_SORTS, CATALOG_SORT_LABELS, type CartBoundsHeal, CartProvider, type CartQuoteLineBounds, type CartTotals, type CartView, type CartViewLine, type CatalogCardModel, type CatalogPage, type CatalogSort, type CheckoutFieldGroup, type CheckoutFieldValues, type CheckoutFields, type ContactFormValues, type ContactSubmissionContext, DEFAULT_ACCOUNT_TAB, DEFAULT_LOW_STOCK_THRESHOLD, DELIVERY_TIME_UNITS, type DeliveryPromise, type DeliveryTimeUnit, type GroupCardModel, IMPLEMENTED_ACCOUNT_TABS, type ImplementedAccountTab, type LicenseStatement, type LicenseTerm, type LinePricing, MAX_PAY_WHAT_YOU_WANT_PRICE, type MenuNavLink, type MenuSlot, type NavLink, type NavigationLinks, PRODUCT_BADGE_ICON_NAMES, type ProductAddon, type ProductAutomaticDeal, type ProductBadge, type ProductBadgeIconName, type ProductBundle, type ProductBundleItem, type ProductCardModel, type ProductCategoryRef, type ProductContentTab, type ProductCustomField, type ProductDetailModel, type ProductFaq, type ProductRatingModel, type ProductSubscription, type ProductType, QUOTE_UNAVAILABLE_CHECKOUT_ERROR, type RatingStars, type ResellerProgramSummary, type RewardProgramItem, type RewardProgramSummary, SERVING_CONTEXT_HINT, SHOP_REVIEW_PAGE_SIZE, STOREFRONT_SORT_KEYS, type SdkCartAddOptions, type SdkCartAddon, type SdkCartAppliedDiscount, type SdkCartCodeSource, type SdkCartItem, type SdkCartQuote, type SdkCartQuoteLine, type SdkCheckoutResult, type SdkCustomerAffiliateLink, type SdkCustomerAffiliateSummary, type SdkCustomerDashboard, type SdkCustomerDashboardOrder, type SdkCustomerDeliverable, type SdkCustomerDeliveryStatus, type SdkCustomerDeliverySummary, type SdkCustomerLicense, type SdkCustomerLoyalty, type SdkCustomerLoyaltyRedeem, type SdkCustomerLoyaltyTransactionType, type SdkCustomerOrderDetail, type SdkCustomerOrderPage, type SdkCustomerOrderSummary, type SdkCustomerRewardActivity, type SdkCustomerRewards, type SdkCustomerSubscription, type SdkCustomerTicketSummary, type SdkCustomerWarranty, type SdkCustomerWarrantyClaim, type SdkCustomerWarrantyClaimStatus, type SdkCustomerWarrantyList, type SdkCustomerWarrantyStatus, type SdkEligibleCartDeal, type SdkInitOptions, type SdkMenu, type SdkMenuItem, type SdkPage, type SdkRecentSaleEntry, type SdkResponse, type SdkShopReview, type ShopPageFaqItem, type ShopPageModel, type ShopPageState, type ShopReview, type ShopReviewLabels, type ShopReviewsState, type ShoppexSdk, type SocialLink, type SocialNetwork, type StockChip, type StockTone, type StorefrontAddon, type StorefrontCatalog, type StorefrontCategory, type StorefrontData, type StorefrontGroup, type StorefrontListingItem, type StorefrontPriceVariant, type StorefrontProduct, StorefrontProvider, type StorefrontSettings, type StorefrontShop, type StorefrontShopStats, type StorefrontSortKey, type SubscriptionIntervalUnit, type SupportChannel, type VolumeDiscountRule, accountOrderHref, accountRouteMessage, accountTabHref, accountTabLabelKey, averageRating, badgesForCard, badgesForProductPage, buildCartTotals, buildCartView, buildCustomFieldPayload, buildInitialCheckoutFieldValues, buildProductDetail, buildStorefrontCatalog, calculateDisplayLineTotal, calculateLinePricing, canonicalAccountPath, checkoutFieldKey, checkoutFieldWriteRepriced, checkoutNeedsDetails, clampQuantity, clearRecoveredQuoteCheckoutError, filterCatalogCards, findStorefrontProduct, firstOptionalString, flattenMerchantHtmlToText, formatCompactCount, formatDeliveryTime, formatLicenseTerm, formatMoney, formatSubscriptionCadence, formatSubscriptionTrial, getAuthoredContent, getBuyerCurrency, getProductGroups, getProducts, getShoppex, getStorefrontAddons, getStorefrontCategories, getStorefrontListing, getStorefrontSettings, getStorefrontShop, hasInjectedStorefrontData, isAccountTab, isBlankMerchantHtml, isCheckboxValueChecked, isImplementedAccountTab, isProductSoldOut, isRecord, isSelectionSoldOut, loadShopPage, missingRequiredCheckoutValues, optionalBoolean, optionalString, optionalStringWithDefault, paginateCatalogCards, parseAccountPath, parseCartQuoteLines, parseEnum, parseFiniteNumber, parseProductBadges, parseStorefrontSortKey, readCheckoutNeedsDetails, readStorefrontData, requireArray, requireBoolean, requireNumber, requireRecord, requireString, requireStringFromKeys, requireUnknownRecord, resolveAccountView, resolveBadgeForeground, resolveCartBoundsHeals, resolveCategorySelection, resolveCheckoutFields, resolveDeliveryPromise, resolveDisplayStock, resolveHideStockCounter, resolveLicenseTerm, resolveMenuLinksForSlot, resolvePayWhatYouWantMinimum, resolveProductVideoEmbedSrc, resolveQuantityBounds, resolveSupportChannels, resolveUnsellableLineIds, resolveVariantStock, reviewsForProduct, roundCurrency, sanitizeMerchantHtml, sortCatalogCards, startCartMutation, stripMerchantHtmlImages, submitContactTicket, toShopReviews, toStarCount, useCart, useNavigationLinks, useOnlineUserCount, useShopReviews, useStorefront, validateCheckoutFieldValue, validateCheckoutFields, validateContactSubmission };
|
|
3109
|
+
export { ACCOUNT_ARTIFACT_CAPABILITIES, ACCOUNT_PATH, ACCOUNT_PATH_ALIAS, ACCOUNT_ROUTE_MESSAGE_KEYS, ACCOUNT_STOREFRONT_ROUTES, ACCOUNT_TABS, type AccountRouteMessageKey, type AccountRouteParts, type AccountTab, type AccountView, type BuyBoxVariantModel, CATALOG_PAGE_SIZE, CATALOG_SORTS, CATALOG_SORT_LABELS, type CartBoundsHeal, CartProvider, type CartQuoteLineBounds, type CartTotals, type CartView, type CartViewLine, type CatalogCardModel, type CatalogPage, type CatalogSort, type CheckoutFieldGroup, type CheckoutFieldValues, type CheckoutFields, type ContactFormValues, type ContactSubmissionContext, DEFAULT_ACCOUNT_TAB, DEFAULT_LOW_STOCK_THRESHOLD, DELIVERY_TIME_UNITS, type DeliveryPromise, type DeliveryTimeUnit, type GroupCardModel, IMPLEMENTED_ACCOUNT_TABS, type ImplementedAccountTab, type LicenseStatement, type LicenseTerm, type LinePricing, MAX_PAY_WHAT_YOU_WANT_PRICE, type MenuNavLink, type MenuSlot, type NavLink, type NavigationLinks, PRODUCT_BADGE_ICON_NAMES, type ProductAddon, type ProductAutomaticDeal, type ProductBadge, type ProductBadgeIconName, type ProductBundle, type ProductBundleItem, type ProductCardModel, type ProductCategoryRef, type ProductContentTab, type ProductCustomField, type ProductDetailModel, type ProductFaq, type ProductRatingModel, type ProductSubscription, type ProductType, QUOTE_UNAVAILABLE_CHECKOUT_ERROR, type RatingStars, type ResellerProgramSummary, type RewardProgramItem, type RewardProgramSummary, SERVING_CONTEXT_HINT, SHOP_REVIEW_PAGE_SIZE, STOREFRONT_SORT_KEYS, type SdkCartAddOptions, type SdkCartAddon, type SdkCartAppliedDiscount, type SdkCartCodeSource, type SdkCartItem, type SdkCartQuote, type SdkCartQuoteLine, type SdkCheckoutResult, type SdkCustomerAffiliateLink, type SdkCustomerAffiliateSummary, type SdkCustomerDashboard, type SdkCustomerDashboardOrder, type SdkCustomerDeliverable, type SdkCustomerDeliveryStatus, type SdkCustomerDeliverySummary, type SdkCustomerLicense, type SdkCustomerLoyalty, type SdkCustomerLoyaltyRedeem, type SdkCustomerLoyaltyTransactionType, type SdkCustomerOrderDetail, type SdkCustomerOrderPage, type SdkCustomerOrderSummary, type SdkCustomerRewardActivity, type SdkCustomerRewards, type SdkCustomerSubscription, type SdkCustomerTicketSummary, type SdkCustomerWarranty, type SdkCustomerWarrantyClaim, type SdkCustomerWarrantyClaimStatus, type SdkCustomerWarrantyList, type SdkCustomerWarrantyStatus, type SdkEligibleCartDeal, type SdkInitOptions, type SdkMenu, type SdkMenuItem, type SdkPage, type SdkRecentSaleEntry, type SdkResponse, type SdkShopReview, type ShopPageFaqItem, type ShopPageModel, type ShopPageState, type ShopReview, type ShopReviewLabels, type ShopReviewsState, type ShoppexSdk, type SocialLink, type SocialNetwork, type StockChip, type StockTone, type StorefrontAddon, type StorefrontCatalog, type StorefrontCategory, type StorefrontData, type StorefrontGroup, type StorefrontListingItem, type StorefrontPriceVariant, type StorefrontProduct, StorefrontProvider, type StorefrontSettings, type StorefrontShop, type StorefrontShopStats, type StorefrontSortKey, type SubscriptionIntervalUnit, type SupportChannel, type VolumeDiscountRule, accountOrderHref, accountRouteMessage, accountTabHref, accountTabLabelKey, averageRating, badgesForCard, badgesForProductPage, buildCartTotals, buildCartView, buildCustomFieldPayload, buildInitialCheckoutFieldValues, buildProductDetail, buildStorefrontCatalog, calculateDisplayLineTotal, calculateLinePricing, canonicalAccountPath, checkoutFieldKey, checkoutFieldWriteRepriced, checkoutNeedsDetails, clampQuantity, clearRecoveredQuoteCheckoutError, filterCatalogCards, findStorefrontProduct, firstOptionalString, flattenMerchantHtmlToText, formatCompactCount, formatDeliveryTime, formatLicenseTerm, formatMoney, formatSubscriptionCadence, formatSubscriptionTrial, getAuthoredContent, getBuyerCurrency, getProductGroups, getProducts, getShoppex, getStorefrontAddons, getStorefrontCategories, getStorefrontListing, getStorefrontSettings, getStorefrontShop, hasInjectedStorefrontData, isAccountTab, isBlankMerchantHtml, isCheckboxValueChecked, isImplementedAccountTab, isProductSoldOut, isRecord, isSelectionSoldOut, loadLatestWrittenReviews, loadShopPage, missingRequiredCheckoutValues, optionalBoolean, optionalString, optionalStringWithDefault, paginateCatalogCards, parseAccountPath, parseCartQuoteLines, parseEnum, parseFiniteNumber, parseProductBadges, parseStorefrontSortKey, readCheckoutNeedsDetails, readStorefrontData, requireArray, requireBoolean, requireNumber, requireRecord, requireString, requireStringFromKeys, requireUnknownRecord, resolveAccountView, resolveBadgeForeground, resolveCartBoundsHeals, resolveCategorySelection, resolveCheckoutFields, resolveDeliveryPromise, resolveDisplayStock, resolveHideStockCounter, resolveLicenseTerm, resolveMenuLinksForSlot, resolvePayWhatYouWantMinimum, resolveProductVideoEmbedSrc, resolveQuantityBounds, resolveSupportChannels, resolveUnsellableLineIds, resolveVariantStock, reviewsForProduct, roundCurrency, sanitizeMerchantHtml, sortCatalogCards, startCartMutation, stripMerchantHtmlImages, submitContactTicket, toShopReviews, toStarCount, useCart, useNavigationLinks, useOnlineUserCount, useShopReviews, useStorefront, validateCheckoutFieldValue, validateCheckoutFields, validateContactSubmission };
|
package/dist/index.js
CHANGED
|
@@ -2416,6 +2416,12 @@ function validateContactSubmission(values, context) {
|
|
|
2416
2416
|
if (context.requireInvoice && !values.invoiceId.trim()) {
|
|
2417
2417
|
return "An order or invoice ID is required.";
|
|
2418
2418
|
}
|
|
2419
|
+
if (values.subject.trim().length > MAX_TITLE_LENGTH) {
|
|
2420
|
+
return `Keep the subject under ${MAX_TITLE_LENGTH} characters.`;
|
|
2421
|
+
}
|
|
2422
|
+
if (buildTicketMessage(values).length > MESSAGE_MAX_LENGTH) {
|
|
2423
|
+
return `Your message is too long. Keep it under ${MESSAGE_MAX_LENGTH.toLocaleString("en-US")} characters.`;
|
|
2424
|
+
}
|
|
2419
2425
|
return null;
|
|
2420
2426
|
}
|
|
2421
2427
|
function requiredGlobal(name) {
|
|
@@ -2432,7 +2438,7 @@ function buildTicketMessage(values) {
|
|
|
2432
2438
|
const body = values.message.trim();
|
|
2433
2439
|
return `${name ? `Name: ${name}
|
|
2434
2440
|
|
|
2435
|
-
` : ""}${body}
|
|
2441
|
+
` : ""}${body}`;
|
|
2436
2442
|
}
|
|
2437
2443
|
async function submitContactTicket(values, context) {
|
|
2438
2444
|
const error = validateContactSubmission(values, context);
|
|
@@ -2448,7 +2454,7 @@ async function submitContactTicket(values, context) {
|
|
|
2448
2454
|
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
2449
2455
|
body: JSON.stringify({
|
|
2450
2456
|
email: values.email.trim().toLowerCase(),
|
|
2451
|
-
title: subject.length >= MIN_SUBJECT_LENGTH ? subject
|
|
2457
|
+
title: subject.length >= MIN_SUBJECT_LENGTH ? subject : DEFAULT_TICKET_TITLE,
|
|
2452
2458
|
message: buildTicketMessage(values),
|
|
2453
2459
|
...invoiceId ? { invoice_id: invoiceId } : {}
|
|
2454
2460
|
})
|
|
@@ -2571,6 +2577,21 @@ function reviewsForProduct(reviews, productTitle) {
|
|
|
2571
2577
|
if (!title) return [];
|
|
2572
2578
|
return reviews.filter((review) => review.productTitle === title);
|
|
2573
2579
|
}
|
|
2580
|
+
async function loadLatestWrittenReviews(limit, labels) {
|
|
2581
|
+
const written = [];
|
|
2582
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2583
|
+
let cursor = null;
|
|
2584
|
+
while (written.length < limit) {
|
|
2585
|
+
const result = await getShoppex().getShopReviewsPage(cursor);
|
|
2586
|
+
if (!result.success || !result.data) return null;
|
|
2587
|
+
written.push(...result.data.feedback.filter((row) => !row.is_automated && (row.comment ?? row.message ?? "").trim() !== ""));
|
|
2588
|
+
const next = result.data.pagination.has_more ? result.data.pagination.next_cursor : null;
|
|
2589
|
+
if (!next || seen.has(next)) break;
|
|
2590
|
+
seen.add(next);
|
|
2591
|
+
cursor = next;
|
|
2592
|
+
}
|
|
2593
|
+
return toShopReviews(written, labels).slice(0, limit);
|
|
2594
|
+
}
|
|
2574
2595
|
function averageRating(reviews) {
|
|
2575
2596
|
if (reviews.length === 0) return null;
|
|
2576
2597
|
return reviews.reduce((total, review) => total + review.rating, 0) / reviews.length;
|
|
@@ -2743,6 +2764,7 @@ export {
|
|
|
2743
2764
|
isProductSoldOut,
|
|
2744
2765
|
isRecord,
|
|
2745
2766
|
isSelectionSoldOut,
|
|
2767
|
+
loadLatestWrittenReviews,
|
|
2746
2768
|
loadShopPage,
|
|
2747
2769
|
missingRequiredCheckoutValues,
|
|
2748
2770
|
optionalBoolean,
|