@shoppexio/storefront 1.0.82 → 1.0.85

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/index.d.cts CHANGED
@@ -1908,7 +1908,24 @@ declare function getMenu(title: string): Promise<SDKResponse<Menu>>;
1908
1908
  declare function getMenuBySlot(slot: NavigationMenuSlot): Promise<SDKResponse<Menu>>;
1909
1909
  declare function getMenuSlotTitles(slot: NavigationMenuSlot): string[];
1910
1910
 
1911
+ /**
1912
+ * Counts a page view. Call it once per page load or client-side navigation.
1913
+ * Passing the cart also records it for the live visitor map.
1914
+ */
1911
1915
  declare function trackPageView(cartValue?: number, itemCount?: number): Promise<void>;
1916
+ /**
1917
+ * Reports a cart change for the live visitor map without counting a page view
1918
+ * (`event_type: 'presence'`). Use it when the cart changes on a page that was
1919
+ * already counted. A cart state the server already acknowledged, or that a tab
1920
+ * of this shop is sending right now, is not sent again, so a cross-tab `storage`
1921
+ * echo of a change is not a second ping. A failed send leaves nothing behind:
1922
+ * the same state goes out again on the next change or page load.
1923
+ *
1924
+ * The check runs when the change's turn comes, after this tab's earlier sends
1925
+ * settled, never at call time: a revert to the confirmed cart while another
1926
+ * state is on the wire must still go out once that send confirms its state.
1927
+ */
1928
+ declare function trackCartActivity(cartValue: number, itemCount: number): Promise<void>;
1912
1929
 
1913
1930
  /**
1914
1931
  * Anonymized recent-sales feed for storefront social proof (product title +
@@ -1917,6 +1934,12 @@ declare function trackPageView(cartValue?: number, itemCount?: number): Promise<
1917
1934
  */
1918
1935
  declare function getStorefrontRecentSales(): Promise<SDKResponse<StorefrontRecentSales>>;
1919
1936
  declare function getStorefrontOnlineUsers(): Promise<SDKResponse<StorefrontOnlineUsers>>;
1937
+ /**
1938
+ * Keeps this visitor's live presence fresh. The ping carries
1939
+ * `event_type: 'presence'`, so the server refreshes the live session without
1940
+ * counting a shop view: an idle tab that touches presence every minute must
1941
+ * not add a view every few minutes. Page views go through `trackPageView()`.
1942
+ */
1920
1943
  declare function touchStorefrontPresence(): Promise<SDKResponse<{
1921
1944
  pong: string;
1922
1945
  }>>;
@@ -2066,6 +2089,7 @@ declare const shoppex: {
2066
2089
  getMenuByTitle: typeof getMenuByTitle;
2067
2090
  getMenuSlotTitles: typeof getMenuSlotTitles;
2068
2091
  trackPageView: typeof trackPageView;
2092
+ trackCartActivity: typeof trackCartActivity;
2069
2093
  getStorefrontOnlineUsers: typeof getStorefrontOnlineUsers;
2070
2094
  getStorefrontRecentSales: typeof getStorefrontRecentSales;
2071
2095
  touchStorefrontPresence: typeof touchStorefrontPresence;
@@ -2080,4 +2104,4 @@ declare const shoppex: {
2080
2104
  mergeSettings: typeof mergeSettings;
2081
2105
  };
2082
2106
 
2083
- export { type AffiliateValidation, ApiError, type ApiResponse, type BlockDefinition, type BlockInstance, type BuyerRewardActivityItem, type BuyerRewards, CURRENCY_UNAVAILABLE_ERROR_CODE, type CartAddOptions, type CartAddon, type CartAppliedDiscount, type CartBasketMergeLine, type CartCodeSource, CartError, type CartItem, type CartItemUpdate, type CartLineIdentityInput, type CartMetadata, type CartPayload, type CartQuote, type CartQuoteLine, type CartStats, type Category, CheckoutCreateError, type CheckoutOptions, type CheckoutResult, type CouponValidation, type CouponValidationOptions, type CursorPagination, type CustomFieldDefinition, type CustomerEmailPreferencesPatch, type CustomerProfilePatch, type CustomerSubscriptionCancelOptions, type CustomerTicketPayload, type EligibleBundleDeal, type EligibleBundleDealProduct, type EligibleCartDeal, type Feedback, type Invoice, type InvoiceProduct, type Menu, type MenuItem, NetworkError, NotInitializedError, type Page, type PageLayout, type PriceVariant, type Product, type ProductAddon, type ProductBundle, type ProductBundleProduct, type ProductCategory, type ProductDescriptionTab, type ProductFaq, type ProductFeedback, type ProductGroup, type ProductImage, type ProductVariant, type PublishedBuilderSettings, type PublishedThemeSettingsPayload, type ResellerCatalogQuery, type ResellerOrderItem, type ResellerOrdersQuery, type ResolvedThemeSettings, type RewardActionType, type RewardGrantStatus, type RewardProgramSummary, type RewardProgramTeaserItem, type RewardReason, type SDKResponse, type SearchOptions, type SectionDefinition, type SettingField, type Shop, type ShopFeedback, type ShopReviewsPage, type ShopReviewsSummary, type ShopTheme, type ShoppexConfig, ShoppexError, type ShoppexInitOptions, type StorefrontAddon, type StorefrontAddonBootstrap, type StorefrontAnnouncementBarAddon, type StorefrontCatalogSearchItem, type StorefrontContactTicketInput, type StorefrontContactTicketResult, type StorefrontCountdownBarAddon, type StorefrontCouponPopupModalAddon, type StorefrontCustomField, type StorefrontData, type StorefrontItem, type StorefrontOnlineUsers, type StorefrontPromoInfoCardAddon, type StorefrontRecentPurchasePopupAddon, type StorefrontRecentSaleEntry, type StorefrontRecentSales, type StorefrontSearchFilterOptions, type StorefrontSocialLinks, type Subscription, type SubscriptionFlags, type SubscriptionInterval, type ThemeBlockManifest, type ThemeConfig, type TrustedChecks, ValidationError, acceptResellerInvite, addFavorite, affiliate, affiliateStats, applyForReseller, buildStorefrontContactMessage, buildStorefrontCustomFieldPayload, buildStorefrontProductLookup, cancelSubscription, claimWarranty, collectProductSearchHaystack, computeCartLineId, createTicket, dashboard, shoppex as default, emailPreferences, enrollAsReseller, ensureCartLineId, favorites, fetchPublishedBuilderSettings, fetchPublishedThemeSettings, filterProductsBySearchQuery, getMenu, getMenuBySlot, getMenuByTitle, getMenuSlotTitles, getMenus, getMergedStorefrontProducts, getShopReviewsPage, getStorefrontGroupProducts, getStorefrontOnlineUsers, getStorefrontRecentSales, groupMatchesSearchQuery, isProductInStock, isProductOutOfStock, isStorefrontCheckboxCustomFieldValueChecked, isVariantOutOfStock, logout, loyalty, me, mergeSettings, normalizeSearchQuery, normalizeStorefrontCustomFields, order, orders, pauseSubscription, productMatchesSearchQuery, quoteResellerOrder, redeemLoyaltyPoints, removeAvatar, removeFavorite, replyToTicket, requestOtp, reseller, resellerApiKeys, resellerCatalog, resellerOrder, resellerOrders, resellerWallet, resetLicenseHwid, resolveDefaults, resolveDisplayStock, resolveStorefrontApiBaseUrl, resolveStorefrontSocialLinks, resolveVariantStockValue, resumeSubscription, revokeAllSessions, revokeSession, searchMergedStorefrontCatalog, searchMergedStorefrontCatalogItems, sessions, shoppex, stripHtmlFromText, submitStorefrontContactTicket, subscriptionBillingHistory, ticket, touchStorefrontPresence, trackPageView, updateAvatar, updateEmailPreferences, updateProfile, validateStorefrontCustomFieldValue, verifyOtp, warranties };
2107
+ export { type AffiliateValidation, ApiError, type ApiResponse, type BlockDefinition, type BlockInstance, type BuyerRewardActivityItem, type BuyerRewards, CURRENCY_UNAVAILABLE_ERROR_CODE, type CartAddOptions, type CartAddon, type CartAppliedDiscount, type CartBasketMergeLine, type CartCodeSource, CartError, type CartItem, type CartItemUpdate, type CartLineIdentityInput, type CartMetadata, type CartPayload, type CartQuote, type CartQuoteLine, type CartStats, type Category, CheckoutCreateError, type CheckoutOptions, type CheckoutResult, type CouponValidation, type CouponValidationOptions, type CursorPagination, type CustomFieldDefinition, type CustomerEmailPreferencesPatch, type CustomerProfilePatch, type CustomerSubscriptionCancelOptions, type CustomerTicketPayload, type EligibleBundleDeal, type EligibleBundleDealProduct, type EligibleCartDeal, type Feedback, type Invoice, type InvoiceProduct, type Menu, type MenuItem, NetworkError, NotInitializedError, type Page, type PageLayout, type PriceVariant, type Product, type ProductAddon, type ProductBundle, type ProductBundleProduct, type ProductCategory, type ProductDescriptionTab, type ProductFaq, type ProductFeedback, type ProductGroup, type ProductImage, type ProductVariant, type PublishedBuilderSettings, type PublishedThemeSettingsPayload, type ResellerCatalogQuery, type ResellerOrderItem, type ResellerOrdersQuery, type ResolvedThemeSettings, type RewardActionType, type RewardGrantStatus, type RewardProgramSummary, type RewardProgramTeaserItem, type RewardReason, type SDKResponse, type SearchOptions, type SectionDefinition, type SettingField, type Shop, type ShopFeedback, type ShopReviewsPage, type ShopReviewsSummary, type ShopTheme, type ShoppexConfig, ShoppexError, type ShoppexInitOptions, type StorefrontAddon, type StorefrontAddonBootstrap, type StorefrontAnnouncementBarAddon, type StorefrontCatalogSearchItem, type StorefrontContactTicketInput, type StorefrontContactTicketResult, type StorefrontCountdownBarAddon, type StorefrontCouponPopupModalAddon, type StorefrontCustomField, type StorefrontData, type StorefrontItem, type StorefrontOnlineUsers, type StorefrontPromoInfoCardAddon, type StorefrontRecentPurchasePopupAddon, type StorefrontRecentSaleEntry, type StorefrontRecentSales, type StorefrontSearchFilterOptions, type StorefrontSocialLinks, type Subscription, type SubscriptionFlags, type SubscriptionInterval, type ThemeBlockManifest, type ThemeConfig, type TrustedChecks, ValidationError, acceptResellerInvite, addFavorite, affiliate, affiliateStats, applyForReseller, buildStorefrontContactMessage, buildStorefrontCustomFieldPayload, buildStorefrontProductLookup, cancelSubscription, claimWarranty, collectProductSearchHaystack, computeCartLineId, createTicket, dashboard, shoppex as default, emailPreferences, enrollAsReseller, ensureCartLineId, favorites, fetchPublishedBuilderSettings, fetchPublishedThemeSettings, filterProductsBySearchQuery, getMenu, getMenuBySlot, getMenuByTitle, getMenuSlotTitles, getMenus, getMergedStorefrontProducts, getShopReviewsPage, getStorefrontGroupProducts, getStorefrontOnlineUsers, getStorefrontRecentSales, groupMatchesSearchQuery, isProductInStock, isProductOutOfStock, isStorefrontCheckboxCustomFieldValueChecked, isVariantOutOfStock, logout, loyalty, me, mergeSettings, normalizeSearchQuery, normalizeStorefrontCustomFields, order, orders, pauseSubscription, productMatchesSearchQuery, quoteResellerOrder, redeemLoyaltyPoints, removeAvatar, removeFavorite, replyToTicket, requestOtp, reseller, resellerApiKeys, resellerCatalog, resellerOrder, resellerOrders, resellerWallet, resetLicenseHwid, resolveDefaults, resolveDisplayStock, resolveStorefrontApiBaseUrl, resolveStorefrontSocialLinks, resolveVariantStockValue, resumeSubscription, revokeAllSessions, revokeSession, searchMergedStorefrontCatalog, searchMergedStorefrontCatalogItems, sessions, shoppex, stripHtmlFromText, submitStorefrontContactTicket, subscriptionBillingHistory, ticket, touchStorefrontPresence, trackCartActivity, trackPageView, updateAvatar, updateEmailPreferences, updateProfile, validateStorefrontCustomFieldValue, verifyOtp, warranties };
package/dist/index.d.ts CHANGED
@@ -1908,7 +1908,24 @@ declare function getMenu(title: string): Promise<SDKResponse<Menu>>;
1908
1908
  declare function getMenuBySlot(slot: NavigationMenuSlot): Promise<SDKResponse<Menu>>;
1909
1909
  declare function getMenuSlotTitles(slot: NavigationMenuSlot): string[];
1910
1910
 
1911
+ /**
1912
+ * Counts a page view. Call it once per page load or client-side navigation.
1913
+ * Passing the cart also records it for the live visitor map.
1914
+ */
1911
1915
  declare function trackPageView(cartValue?: number, itemCount?: number): Promise<void>;
1916
+ /**
1917
+ * Reports a cart change for the live visitor map without counting a page view
1918
+ * (`event_type: 'presence'`). Use it when the cart changes on a page that was
1919
+ * already counted. A cart state the server already acknowledged, or that a tab
1920
+ * of this shop is sending right now, is not sent again, so a cross-tab `storage`
1921
+ * echo of a change is not a second ping. A failed send leaves nothing behind:
1922
+ * the same state goes out again on the next change or page load.
1923
+ *
1924
+ * The check runs when the change's turn comes, after this tab's earlier sends
1925
+ * settled, never at call time: a revert to the confirmed cart while another
1926
+ * state is on the wire must still go out once that send confirms its state.
1927
+ */
1928
+ declare function trackCartActivity(cartValue: number, itemCount: number): Promise<void>;
1912
1929
 
1913
1930
  /**
1914
1931
  * Anonymized recent-sales feed for storefront social proof (product title +
@@ -1917,6 +1934,12 @@ declare function trackPageView(cartValue?: number, itemCount?: number): Promise<
1917
1934
  */
1918
1935
  declare function getStorefrontRecentSales(): Promise<SDKResponse<StorefrontRecentSales>>;
1919
1936
  declare function getStorefrontOnlineUsers(): Promise<SDKResponse<StorefrontOnlineUsers>>;
1937
+ /**
1938
+ * Keeps this visitor's live presence fresh. The ping carries
1939
+ * `event_type: 'presence'`, so the server refreshes the live session without
1940
+ * counting a shop view: an idle tab that touches presence every minute must
1941
+ * not add a view every few minutes. Page views go through `trackPageView()`.
1942
+ */
1920
1943
  declare function touchStorefrontPresence(): Promise<SDKResponse<{
1921
1944
  pong: string;
1922
1945
  }>>;
@@ -2066,6 +2089,7 @@ declare const shoppex: {
2066
2089
  getMenuByTitle: typeof getMenuByTitle;
2067
2090
  getMenuSlotTitles: typeof getMenuSlotTitles;
2068
2091
  trackPageView: typeof trackPageView;
2092
+ trackCartActivity: typeof trackCartActivity;
2069
2093
  getStorefrontOnlineUsers: typeof getStorefrontOnlineUsers;
2070
2094
  getStorefrontRecentSales: typeof getStorefrontRecentSales;
2071
2095
  touchStorefrontPresence: typeof touchStorefrontPresence;
@@ -2080,4 +2104,4 @@ declare const shoppex: {
2080
2104
  mergeSettings: typeof mergeSettings;
2081
2105
  };
2082
2106
 
2083
- export { type AffiliateValidation, ApiError, type ApiResponse, type BlockDefinition, type BlockInstance, type BuyerRewardActivityItem, type BuyerRewards, CURRENCY_UNAVAILABLE_ERROR_CODE, type CartAddOptions, type CartAddon, type CartAppliedDiscount, type CartBasketMergeLine, type CartCodeSource, CartError, type CartItem, type CartItemUpdate, type CartLineIdentityInput, type CartMetadata, type CartPayload, type CartQuote, type CartQuoteLine, type CartStats, type Category, CheckoutCreateError, type CheckoutOptions, type CheckoutResult, type CouponValidation, type CouponValidationOptions, type CursorPagination, type CustomFieldDefinition, type CustomerEmailPreferencesPatch, type CustomerProfilePatch, type CustomerSubscriptionCancelOptions, type CustomerTicketPayload, type EligibleBundleDeal, type EligibleBundleDealProduct, type EligibleCartDeal, type Feedback, type Invoice, type InvoiceProduct, type Menu, type MenuItem, NetworkError, NotInitializedError, type Page, type PageLayout, type PriceVariant, type Product, type ProductAddon, type ProductBundle, type ProductBundleProduct, type ProductCategory, type ProductDescriptionTab, type ProductFaq, type ProductFeedback, type ProductGroup, type ProductImage, type ProductVariant, type PublishedBuilderSettings, type PublishedThemeSettingsPayload, type ResellerCatalogQuery, type ResellerOrderItem, type ResellerOrdersQuery, type ResolvedThemeSettings, type RewardActionType, type RewardGrantStatus, type RewardProgramSummary, type RewardProgramTeaserItem, type RewardReason, type SDKResponse, type SearchOptions, type SectionDefinition, type SettingField, type Shop, type ShopFeedback, type ShopReviewsPage, type ShopReviewsSummary, type ShopTheme, type ShoppexConfig, ShoppexError, type ShoppexInitOptions, type StorefrontAddon, type StorefrontAddonBootstrap, type StorefrontAnnouncementBarAddon, type StorefrontCatalogSearchItem, type StorefrontContactTicketInput, type StorefrontContactTicketResult, type StorefrontCountdownBarAddon, type StorefrontCouponPopupModalAddon, type StorefrontCustomField, type StorefrontData, type StorefrontItem, type StorefrontOnlineUsers, type StorefrontPromoInfoCardAddon, type StorefrontRecentPurchasePopupAddon, type StorefrontRecentSaleEntry, type StorefrontRecentSales, type StorefrontSearchFilterOptions, type StorefrontSocialLinks, type Subscription, type SubscriptionFlags, type SubscriptionInterval, type ThemeBlockManifest, type ThemeConfig, type TrustedChecks, ValidationError, acceptResellerInvite, addFavorite, affiliate, affiliateStats, applyForReseller, buildStorefrontContactMessage, buildStorefrontCustomFieldPayload, buildStorefrontProductLookup, cancelSubscription, claimWarranty, collectProductSearchHaystack, computeCartLineId, createTicket, dashboard, shoppex as default, emailPreferences, enrollAsReseller, ensureCartLineId, favorites, fetchPublishedBuilderSettings, fetchPublishedThemeSettings, filterProductsBySearchQuery, getMenu, getMenuBySlot, getMenuByTitle, getMenuSlotTitles, getMenus, getMergedStorefrontProducts, getShopReviewsPage, getStorefrontGroupProducts, getStorefrontOnlineUsers, getStorefrontRecentSales, groupMatchesSearchQuery, isProductInStock, isProductOutOfStock, isStorefrontCheckboxCustomFieldValueChecked, isVariantOutOfStock, logout, loyalty, me, mergeSettings, normalizeSearchQuery, normalizeStorefrontCustomFields, order, orders, pauseSubscription, productMatchesSearchQuery, quoteResellerOrder, redeemLoyaltyPoints, removeAvatar, removeFavorite, replyToTicket, requestOtp, reseller, resellerApiKeys, resellerCatalog, resellerOrder, resellerOrders, resellerWallet, resetLicenseHwid, resolveDefaults, resolveDisplayStock, resolveStorefrontApiBaseUrl, resolveStorefrontSocialLinks, resolveVariantStockValue, resumeSubscription, revokeAllSessions, revokeSession, searchMergedStorefrontCatalog, searchMergedStorefrontCatalogItems, sessions, shoppex, stripHtmlFromText, submitStorefrontContactTicket, subscriptionBillingHistory, ticket, touchStorefrontPresence, trackPageView, updateAvatar, updateEmailPreferences, updateProfile, validateStorefrontCustomFieldValue, verifyOtp, warranties };
2107
+ export { type AffiliateValidation, ApiError, type ApiResponse, type BlockDefinition, type BlockInstance, type BuyerRewardActivityItem, type BuyerRewards, CURRENCY_UNAVAILABLE_ERROR_CODE, type CartAddOptions, type CartAddon, type CartAppliedDiscount, type CartBasketMergeLine, type CartCodeSource, CartError, type CartItem, type CartItemUpdate, type CartLineIdentityInput, type CartMetadata, type CartPayload, type CartQuote, type CartQuoteLine, type CartStats, type Category, CheckoutCreateError, type CheckoutOptions, type CheckoutResult, type CouponValidation, type CouponValidationOptions, type CursorPagination, type CustomFieldDefinition, type CustomerEmailPreferencesPatch, type CustomerProfilePatch, type CustomerSubscriptionCancelOptions, type CustomerTicketPayload, type EligibleBundleDeal, type EligibleBundleDealProduct, type EligibleCartDeal, type Feedback, type Invoice, type InvoiceProduct, type Menu, type MenuItem, NetworkError, NotInitializedError, type Page, type PageLayout, type PriceVariant, type Product, type ProductAddon, type ProductBundle, type ProductBundleProduct, type ProductCategory, type ProductDescriptionTab, type ProductFaq, type ProductFeedback, type ProductGroup, type ProductImage, type ProductVariant, type PublishedBuilderSettings, type PublishedThemeSettingsPayload, type ResellerCatalogQuery, type ResellerOrderItem, type ResellerOrdersQuery, type ResolvedThemeSettings, type RewardActionType, type RewardGrantStatus, type RewardProgramSummary, type RewardProgramTeaserItem, type RewardReason, type SDKResponse, type SearchOptions, type SectionDefinition, type SettingField, type Shop, type ShopFeedback, type ShopReviewsPage, type ShopReviewsSummary, type ShopTheme, type ShoppexConfig, ShoppexError, type ShoppexInitOptions, type StorefrontAddon, type StorefrontAddonBootstrap, type StorefrontAnnouncementBarAddon, type StorefrontCatalogSearchItem, type StorefrontContactTicketInput, type StorefrontContactTicketResult, type StorefrontCountdownBarAddon, type StorefrontCouponPopupModalAddon, type StorefrontCustomField, type StorefrontData, type StorefrontItem, type StorefrontOnlineUsers, type StorefrontPromoInfoCardAddon, type StorefrontRecentPurchasePopupAddon, type StorefrontRecentSaleEntry, type StorefrontRecentSales, type StorefrontSearchFilterOptions, type StorefrontSocialLinks, type Subscription, type SubscriptionFlags, type SubscriptionInterval, type ThemeBlockManifest, type ThemeConfig, type TrustedChecks, ValidationError, acceptResellerInvite, addFavorite, affiliate, affiliateStats, applyForReseller, buildStorefrontContactMessage, buildStorefrontCustomFieldPayload, buildStorefrontProductLookup, cancelSubscription, claimWarranty, collectProductSearchHaystack, computeCartLineId, createTicket, dashboard, shoppex as default, emailPreferences, enrollAsReseller, ensureCartLineId, favorites, fetchPublishedBuilderSettings, fetchPublishedThemeSettings, filterProductsBySearchQuery, getMenu, getMenuBySlot, getMenuByTitle, getMenuSlotTitles, getMenus, getMergedStorefrontProducts, getShopReviewsPage, getStorefrontGroupProducts, getStorefrontOnlineUsers, getStorefrontRecentSales, groupMatchesSearchQuery, isProductInStock, isProductOutOfStock, isStorefrontCheckboxCustomFieldValueChecked, isVariantOutOfStock, logout, loyalty, me, mergeSettings, normalizeSearchQuery, normalizeStorefrontCustomFields, order, orders, pauseSubscription, productMatchesSearchQuery, quoteResellerOrder, redeemLoyaltyPoints, removeAvatar, removeFavorite, replyToTicket, requestOtp, reseller, resellerApiKeys, resellerCatalog, resellerOrder, resellerOrders, resellerWallet, resetLicenseHwid, resolveDefaults, resolveDisplayStock, resolveStorefrontApiBaseUrl, resolveStorefrontSocialLinks, resolveVariantStockValue, resumeSubscription, revokeAllSessions, revokeSession, searchMergedStorefrontCatalog, searchMergedStorefrontCatalogItems, sessions, shoppex, stripHtmlFromText, submitStorefrontContactTicket, subscriptionBillingHistory, ticket, touchStorefrontPresence, trackCartActivity, trackPageView, updateAvatar, updateEmailPreferences, updateProfile, validateStorefrontCustomFieldValue, verifyOtp, warranties };
package/dist/index.js CHANGED
@@ -3318,6 +3318,8 @@ function removeItem(key) {
3318
3318
  // ../sdk/src/core/telemetry.ts
3319
3319
  var CONNECTION_ID_STORAGE_PREFIX = "presence_connection_";
3320
3320
  var CLIENT_ERROR_DEDUPE_WINDOW_MS = 15e3;
3321
+ var CLIENT_ERROR_TEXT_MAX_LENGTH = 500;
3322
+ var CLIENT_ERROR_URL_MAX_LENGTH = 2e3;
3321
3323
  function createPresenceConnectionId() {
3322
3324
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
3323
3325
  return crypto.randomUUID();
@@ -3368,14 +3370,14 @@ async function reportStorefrontClientError(payload) {
3368
3370
  client_error: {
3369
3371
  source: payload.source ?? "sdk",
3370
3372
  phase: payload.phase ?? "request",
3371
- endpoint: payload.endpoint,
3373
+ endpoint: payload.endpoint.slice(0, CLIENT_ERROR_TEXT_MAX_LENGTH),
3372
3374
  method: payload.method,
3373
- message: payload.message,
3375
+ message: payload.message.slice(0, CLIENT_ERROR_TEXT_MAX_LENGTH),
3374
3376
  status_code: payload.statusCode,
3375
3377
  attempt_count: payload.attemptCount,
3376
3378
  response_received: payload.responseReceived ?? false,
3377
- page_url: payload.pageUrl ?? window.location.href,
3378
- request_url: payload.requestUrl,
3379
+ page_url: (payload.pageUrl ?? window.location.href).slice(0, CLIENT_ERROR_URL_MAX_LENGTH),
3380
+ request_url: payload.requestUrl?.slice(0, CLIENT_ERROR_URL_MAX_LENGTH),
3379
3381
  online: payload.online ?? (typeof navigator !== "undefined" ? navigator.onLine : void 0),
3380
3382
  visibility_state: payload.visibilityState ?? (typeof document !== "undefined" ? document.visibilityState : void 0)
3381
3383
  }
@@ -6083,32 +6085,123 @@ function isPlatformPageTrackerActive() {
6083
6085
  }
6084
6086
 
6085
6087
  // ../sdk/src/modules/analytics.ts
6086
- async function trackPageView(cartValue, itemCount) {
6087
- if (!isInitialized()) return;
6088
- if (typeof document === "undefined") return;
6089
- const carriesCart = cartValue !== void 0 || itemCount !== void 0;
6090
- if (isPlatformPageTrackerActive() && !carriesCart) return;
6088
+ var CONFIRMED_CART_STORAGE_PREFIX = "reported_cart_";
6089
+ var IN_FLIGHT_CART_STORAGE_PREFIX = "reporting_cart_";
6090
+ var CART_CLAIM_TTL_MS = 1e4;
6091
+ function confirmedCartKey(storeSlug) {
6092
+ return `${CONFIRMED_CART_STORAGE_PREFIX}${storeSlug}`;
6093
+ }
6094
+ function inFlightCartKey(storeSlug) {
6095
+ return `${IN_FLIGHT_CART_STORAGE_PREFIX}${storeSlug}`;
6096
+ }
6097
+ function cartSnapshot(cartValue, itemCount) {
6098
+ return `${cartValue ?? ""}|${itemCount ?? ""}`;
6099
+ }
6100
+ function readInFlightCart(storeSlug) {
6101
+ const claim = getItem(inFlightCartKey(storeSlug));
6102
+ if (!claim || typeof claim.snapshot !== "string" || typeof claim.token !== "string" || typeof claim.at !== "number") {
6103
+ return null;
6104
+ }
6105
+ return claim;
6106
+ }
6107
+ function isCartReportedOrInFlight(storeSlug, snapshot) {
6108
+ if (getItem(confirmedCartKey(storeSlug)) === snapshot) return true;
6109
+ const claim = readInFlightCart(storeSlug);
6110
+ return claim !== null && claim.snapshot === snapshot && Date.now() - claim.at < CART_CLAIM_TTL_MS;
6111
+ }
6112
+ function createClaimToken() {
6113
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return crypto.randomUUID();
6114
+ return `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
6115
+ }
6116
+ function claimCartReport(storeSlug, cartValue, itemCount) {
6117
+ const snapshot = cartSnapshot(cartValue, itemCount);
6118
+ const token = createClaimToken();
6119
+ setItem(inFlightCartKey(storeSlug), { snapshot, token, at: Date.now() });
6120
+ return (delivered) => {
6121
+ if (readInFlightCart(storeSlug)?.token !== token) return;
6122
+ if (delivered) setItem(confirmedCartKey(storeSlug), snapshot);
6123
+ removeItem(inFlightCartKey(storeSlug));
6124
+ };
6125
+ }
6126
+ var cartSendTail = Promise.resolve();
6127
+ var latestCartRequest = 0;
6128
+ function enqueueCartSend(send) {
6129
+ const request2 = ++latestCartRequest;
6130
+ const run = () => send(() => request2 === latestCartRequest);
6131
+ cartSendTail = cartSendTail.then(run, run);
6132
+ return cartSendTail;
6133
+ }
6134
+ async function postPing(body) {
6091
6135
  const config = getConfig();
6092
- const connectionId = getStorefrontConnectionId(config.storeSlug);
6136
+ const controller = typeof AbortController === "undefined" ? void 0 : new AbortController();
6137
+ let timer;
6138
+ const timedOut = new Promise((resolve) => {
6139
+ timer = setTimeout(() => {
6140
+ controller?.abort();
6141
+ resolve(false);
6142
+ }, CART_CLAIM_TTL_MS);
6143
+ });
6093
6144
  try {
6094
6145
  const endpoint = buildEndpoint("/v1/storefront/shops/:storeSlug/ping", {
6095
6146
  storeSlug: config.storeSlug
6096
6147
  });
6097
- await fetch(`${config.apiBaseUrl}${endpoint}`, {
6148
+ const delivered = fetch(`${config.apiBaseUrl}${endpoint}`, {
6098
6149
  method: "POST",
6099
6150
  headers: { "Content-Type": "application/json" },
6100
- body: JSON.stringify({
6101
- referer: document.referrer || void 0,
6102
- cart_value: cartValue ?? void 0,
6103
- item_count: itemCount ?? void 0,
6104
- connection_id: connectionId ?? void 0,
6105
- path: resolveStorefrontPagePath(),
6106
- utm: resolveUtmParameters(config.storeSlug)
6107
- })
6108
- });
6151
+ body: JSON.stringify(body),
6152
+ signal: controller?.signal
6153
+ }).then((response) => response.ok);
6154
+ return await Promise.race([delivered, timedOut]);
6109
6155
  } catch {
6156
+ return false;
6157
+ } finally {
6158
+ clearTimeout(timer);
6110
6159
  }
6111
6160
  }
6161
+ async function trackPageView(cartValue, itemCount) {
6162
+ if (!isInitialized()) return;
6163
+ if (typeof document === "undefined") return;
6164
+ const carriesCart = cartValue !== void 0 || itemCount !== void 0;
6165
+ if (isPlatformPageTrackerActive()) {
6166
+ if (carriesCart) await enqueueCartSend(() => sendCartActivity(cartValue, itemCount));
6167
+ return;
6168
+ }
6169
+ const config = getConfig();
6170
+ const sendView = async () => {
6171
+ const settle = carriesCart ? claimCartReport(config.storeSlug, cartValue, itemCount) : void 0;
6172
+ const delivered = await postPing({
6173
+ referer: document.referrer || void 0,
6174
+ cart_value: cartValue,
6175
+ item_count: itemCount,
6176
+ connection_id: getStorefrontConnectionId(config.storeSlug) ?? void 0,
6177
+ path: resolveStorefrontPagePath(),
6178
+ utm: resolveUtmParameters(config.storeSlug)
6179
+ });
6180
+ settle?.(delivered);
6181
+ };
6182
+ await (carriesCart ? enqueueCartSend(sendView) : sendView());
6183
+ }
6184
+ async function trackCartActivity(cartValue, itemCount) {
6185
+ if (!isInitialized()) return;
6186
+ if (typeof document === "undefined") return;
6187
+ const snapshot = cartSnapshot(cartValue, itemCount);
6188
+ await enqueueCartSend(async (isLatest) => {
6189
+ if (!isLatest() || isCartReportedOrInFlight(getConfig().storeSlug, snapshot)) return;
6190
+ await sendCartActivity(cartValue, itemCount);
6191
+ });
6192
+ }
6193
+ async function sendCartActivity(cartValue, itemCount) {
6194
+ const config = getConfig();
6195
+ const settle = claimCartReport(config.storeSlug, cartValue, itemCount);
6196
+ const delivered = await postPing({
6197
+ event_type: "presence",
6198
+ cart_value: cartValue,
6199
+ item_count: itemCount,
6200
+ connection_id: getStorefrontConnectionId(config.storeSlug) ?? void 0,
6201
+ path: resolveStorefrontPagePath()
6202
+ });
6203
+ settle(delivered);
6204
+ }
6112
6205
 
6113
6206
  // ../sdk/src/modules/presence.ts
6114
6207
  async function getStorefrontRecentSales() {
@@ -6159,6 +6252,7 @@ async function touchStorefrontPresence() {
6159
6252
  return post(
6160
6253
  endpoint,
6161
6254
  {
6255
+ event_type: "presence",
6162
6256
  referer: document.referrer || void 0,
6163
6257
  connection_id: getStorefrontConnectionId(config.storeSlug) ?? void 0,
6164
6258
  path: resolveStorefrontPagePath(),
@@ -6378,6 +6472,7 @@ var shoppex = {
6378
6472
  getMenuSlotTitles,
6379
6473
  // Analytics
6380
6474
  trackPageView,
6475
+ trackCartActivity,
6381
6476
  getStorefrontOnlineUsers,
6382
6477
  getStorefrontRecentSales,
6383
6478
  touchStorefrontPresence,
@@ -6491,6 +6586,7 @@ export {
6491
6586
  subscriptionBillingHistory,
6492
6587
  ticket,
6493
6588
  touchStorefrontPresence,
6589
+ trackCartActivity,
6494
6590
  trackPageView,
6495
6591
  updateAvatar,
6496
6592
  updateEmailPreferences,