@fast-simon/dashboard-utilities 1.0.168-beta.5 → 1.0.168-beta.7

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.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,YAAY,EAAS,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAgB,eAAe,EAAC,MAAM,wBAAwB,CAAA;AAGrE,OAAO,EAAC,qBAAqB,EAAC,MAAM,+BAA+B,CAAA;AACnE,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAC,kBAAkB,EAAC,MAAM,4BAA4B,CAAA;AAC7D,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAA;AAC/C,OAAO,qBAAqB,MAAM,oCAAoC,CAAA;AACtE,OAAO,kBAAkB,MAAM,iCAAiC,CAAA;AAChE,OAAO,iBAAiB,MAAM,4CAA4C,CAAA;AAC1E,OAAO,SAAS,MAAM,oCAAoC,CAAA;AAC1D,OAAO,YAAY,MAAM,wCAAwC,CAAA;AACjE,OAAO,EAAC,YAAY,EAAC,MAAM,uCAAuC,CAAA;AAClE,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAC/D,OAAO,UAAU,MAAM,oCAAoC,CAAC;AAC5D,OAAO,eAAe,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAC5D,OAA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AAE,WAAW,EAAE,eAAe,EACnH,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,qBAAqB,EAAE,WAAW,EAAE,QAAQ,EAAE,kBAAkB,EAAE,WAAW,EAC3H,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAC,YAAY,EAAE,qBAAqB,EAAC,YAAY,EAAC,SAAS,EAC9H,QAAQ,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,mBAAmB,EAAC,qBAAqB,EACtI,kBAAkB,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,4BAA4B,EAClG,wBAAwB,EAAE,wBAAwB,EAClD,yBAAyB,EAAE,6BAA6B,EAAE,6BAA6B,EACvF,iCAAiC,EAAE,iCAAiC,EAAE,0BAA0B,EAChG,8BAA8B,EAAE,8BAA8B,EAC9D,oBAAoB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,cAAc,EAAE,gBAAgB,EAC9F,sBAAsB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,cAAc,EAAE,uBAAuB,EAAE,UAAU,EAAE,kBAAkB,EACnM,CAAC","sourcesContent":["import {CustomClasses, SideMenuType, SideMenuItem, MenuItemName} from \"./@types/sideMenu\"\nimport {ProductLabelType} from \"./@types/productLabel\"\nimport {videoFormats, Banner} from \"./@types/banner\"\nimport {EditorProduct, isEditorProduct} from \"./@types/editorProduct\"\nimport {IconProps} from \"./@types/iconProps\"\n\nimport {BackOfficeFiltersIcon} from \"./icons/BackOfficeFiltersIcon\"\nimport {BannersIcon} from \"./icons/BannersIcon\"\nimport {HelpIcon} from \"./icons/HelpIcon\"\nimport {InStoreFiltersIcon} from \"./icons/InStoreFiltersIcon\"\nimport {PromoteIcon} from \"./icons/PromoteIcon\"\nimport {RemoveIcon} from \"./icons/RemoveIcon\"\nimport {RestoreIcon} from \"./icons/RestoreIcon\"\nimport {GeneralIcon} from \"./icons/GeneralIcon\"\nimport BackOfficeFiltersMenu from './components/BackOfficeFiltersMenu'\nimport InStoreFiltersMenu from './components/InStoreFiltersMenu'\nimport DndContextWrapper from './components/DragAndDrop/DndContextWrapper'\nimport Droppable from './components/DragAndDrop/Droppable'\nimport ProductLabel from './components/ProductLabel/ProductLabel'\nimport {SortableItem} from './components/DragAndDrop/SortableItem'\nimport ProductGrid from \"./components/productGrid/ProductGrid\";\nimport SelectCard from \"./components/SelectCard/SelectCard\";\nimport RenderIfVisible from \"./components/RenderIfVisible\";\nimport {useDragToSelect} from \"./utils/useDragToSelect\";\nimport {CustomTagsFilters} from \"./utils/customTagsFilters\";\nimport {useProductsPerRow} from \"./utils/useProductsPerRow\";\nimport { LandingPage } from \"./services/landingPage\";\nimport { FullTextSearch } from \"./services/search\";\nimport { getFormatProducts } from \"./services/getFormatProducts\";\nimport {useFastState, useFastStateFunctions, ComparisonData} from \"./components/FastSimonApi\"\nimport { ServerProduct, ProductAnalytics, ProductPersonalizationCoefficients, FilterCoefEntry, Pillar, PillarKind, PersonalizationConfidence, PersonalizationStory } from \"./@types/product\"\nimport { FullTextServerResponseAll, QueryUnderstanding } from \"./@types/results\"\nimport { smartCollectionsResults } from \"./@types/categories\"\nimport FastSimonApi from \"./components/FastSimonApi/FastSimonApi\"\nimport MainTheme from \"./components/FastSimonApi\"\nimport { FeaturedRanking } from \"@fast-simon/utilities/lib/@types/product\"\nimport { Products } from \"./services/products\"\nimport {getLSVectorSearchDict, getLSVectorSearchOn } from \"./utils/getLSVectorSearch\"\nimport { AutocompleteReasoningResponse } from \"./@types/autocomplete\"\nimport {getUseCacheSetting, setUseCacheSetting} from \"./utils/getCacheSettings\"\nimport {getShowSalesAnalyticsSetting, setShowSalesAnalyticsSetting} from \"./utils/getSalesAnalyticsSettings\"\nimport {getShowRequestUrlSetting, setShowRequestUrlSetting} from \"./utils/getRequestUrlSettings\"\nimport {getPersonalizationSegment, getUserSegmentPreviewSettings, setUserSegmentPreviewSettings, UserSegmentPreview, UserSegmentPreviewSettings} from \"./utils/userSegmentPreview\"\nimport {getPersonalizationPreviewSettings, setPersonalizationPreviewSettings, buildPersonalizationParams, PersonalizationPreviewSettings, PersonalizationType} from \"./utils/personalizationPreview\"\nimport {getSessionTokenPreviewSettings, setSessionTokenPreviewSettings, SessionTokenPreviewSettings} from \"./utils/sessionTokenPreview\"\nimport {LiveSessionData, SpvProductMeta, RequestType, SPV_LIMITS, countSendableViews, generateSessionToken, getLiveSessionData, setLiveSessionData, addProductView, addProductToCart, buildLiveSessionParams, resetLiveSession, startLiveSession, stopLiveSession, setSessionSegment, setLiveSessionSiteScope, formatTokenAge, getUserSegmentFromToken} from \"./utils/liveSessionPreview\"\n// export * from './components';\n\nexport type {\n MenuItemName,\n CustomClasses,\n SideMenuType,\n SideMenuItem,\n ProductLabelType,\n Banner,\n EditorProduct,\n IconProps,\n ServerProduct,\n ProductAnalytics,\n ProductPersonalizationCoefficients,\n FilterCoefEntry,\n Pillar,\n PillarKind,\n PersonalizationConfidence,\n PersonalizationStory,\n FullTextServerResponseAll,\n QueryUnderstanding,\n smartCollectionsResults,\n AutocompleteReasoningResponse,\n FeaturedRanking,\n ComparisonData,\n UserSegmentPreview,\n UserSegmentPreviewSettings,\n PersonalizationPreviewSettings,\n PersonalizationType,\n SessionTokenPreviewSettings,\n LiveSessionData,\n SpvProductMeta,\n RequestType\n};\n\nexport {\n BackOfficeFiltersMenu, InStoreFiltersMenu, Droppable, DndContextWrapper, SortableItem, ProductGrid, RenderIfVisible,\n useDragToSelect, LandingPage, FullTextSearch, BackOfficeFiltersIcon, BannersIcon, HelpIcon, InStoreFiltersIcon, PromoteIcon,\n RestoreIcon, RemoveIcon, GeneralIcon, videoFormats, isEditorProduct,useFastState, useFastStateFunctions,FastSimonApi,MainTheme,\n Products, getFormatProducts, useProductsPerRow, ProductLabel, CustomTagsFilters, SelectCard ,getLSVectorSearchOn,getLSVectorSearchDict,\n getUseCacheSetting, setUseCacheSetting, getShowSalesAnalyticsSetting, setShowSalesAnalyticsSetting,\n getShowRequestUrlSetting, setShowRequestUrlSetting,\n getPersonalizationSegment, getUserSegmentPreviewSettings, setUserSegmentPreviewSettings,\n getPersonalizationPreviewSettings, setPersonalizationPreviewSettings, buildPersonalizationParams,\n getSessionTokenPreviewSettings, setSessionTokenPreviewSettings,\n generateSessionToken, getLiveSessionData, setLiveSessionData, addProductView, addProductToCart,\n buildLiveSessionParams, resetLiveSession, startLiveSession, stopLiveSession, setSessionSegment, setLiveSessionSiteScope, formatTokenAge, getUserSegmentFromToken, SPV_LIMITS, countSendableViews\n};"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,YAAY,EAAS,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAgB,eAAe,EAAC,MAAM,wBAAwB,CAAA;AAGrE,OAAO,EAAC,qBAAqB,EAAC,MAAM,+BAA+B,CAAA;AACnE,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAC,kBAAkB,EAAC,MAAM,4BAA4B,CAAA;AAC7D,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAA;AAC/C,OAAO,qBAAqB,MAAM,oCAAoC,CAAA;AACtE,OAAO,kBAAkB,MAAM,iCAAiC,CAAA;AAChE,OAAO,iBAAiB,MAAM,4CAA4C,CAAA;AAC1E,OAAO,SAAS,MAAM,oCAAoC,CAAA;AAC1D,OAAO,YAAY,MAAM,wCAAwC,CAAA;AACjE,OAAO,EAAC,YAAY,EAAC,MAAM,uCAAuC,CAAA;AACl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AE,gBAAgB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,cAAc,EAAE,uBAAuB,EAAC,MAAM,4BAA4B,CAAA;AAoCxY,OAAO,EACH,qBAAqB,EAAE,kBAAkB,EAAE,SAAS,EAAE,iBAAiB,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EACnH,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,qBAAqB,EAAE,WAAW,EAAE,QAAQ,EAAE,kBAAkB,EAAE,WAAW,EAC3H,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAC,YAAY,EAAE,qBAAqB,EAAC,YAAY,EAAC,SAAS,EAC9H,QAAQ,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,mBAAmB,EAAC,qBAAqB,EACtI,kBAAkB,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,4BAA4B,EAClG,wBAAwB,EAAE,wBAAwB,EAClD,yBAAyB,EAAE,6BAA6B,EAAE,6BAA6B,EACvF,iCAAiC,EAAE,iCAAiC,EAAE,0BAA0B,EAChG,8BAA8B,EAAE,8BAA8B,EAC9D,oBAAoB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,cAAc,EAAE,gBAAgB,EAC9F,sBAAsB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,cAAc,EAAE,uBAAuB,EAAE,UAAU,EAAE,kBAAkB,EACnM,CAAC","sourcesContent":["import {CustomClasses, SideMenuType, SideMenuItem, MenuItemName} from \"./@types/sideMenu\"\nimport {ProductLabelType} from \"./@types/productLabel\"\nimport {videoFormats, Banner} from \"./@types/banner\"\nimport {EditorProduct, isEditorProduct} from \"./@types/editorProduct\"\nimport {IconProps} from \"./@types/iconProps\"\n\nimport {BackOfficeFiltersIcon} from \"./icons/BackOfficeFiltersIcon\"\nimport {BannersIcon} from \"./icons/BannersIcon\"\nimport {HelpIcon} from \"./icons/HelpIcon\"\nimport {InStoreFiltersIcon} from \"./icons/InStoreFiltersIcon\"\nimport {PromoteIcon} from \"./icons/PromoteIcon\"\nimport {RemoveIcon} from \"./icons/RemoveIcon\"\nimport {RestoreIcon} from \"./icons/RestoreIcon\"\nimport {GeneralIcon} from \"./icons/GeneralIcon\"\nimport BackOfficeFiltersMenu from './components/BackOfficeFiltersMenu'\nimport InStoreFiltersMenu from './components/InStoreFiltersMenu'\nimport DndContextWrapper from './components/DragAndDrop/DndContextWrapper'\nimport Droppable from './components/DragAndDrop/Droppable'\nimport ProductLabel from './components/ProductLabel/ProductLabel'\nimport {SortableItem} from './components/DragAndDrop/SortableItem'\nimport ProductGrid from \"./components/productGrid/ProductGrid\";\nimport SelectCard from \"./components/SelectCard/SelectCard\";\nimport RenderIfVisible from \"./components/RenderIfVisible\";\nimport {useDragToSelect} from \"./utils/useDragToSelect\";\nimport {CustomTagsFilters} from \"./utils/customTagsFilters\";\nimport {useProductsPerRow} from \"./utils/useProductsPerRow\";\nimport { LandingPage } from \"./services/landingPage\";\nimport { FullTextSearch } from \"./services/search\";\nimport { getFormatProducts } from \"./services/getFormatProducts\";\nimport {useFastState, useFastStateFunctions, ComparisonData} from \"./components/FastSimonApi\"\nimport { ServerProduct, ProductAnalytics, ProductPersonalizationCoefficients, FilterCoefEntry, Pillar, PillarKind, PersonalizationConfidence, PersonalizationStory } from \"./@types/product\"\nimport { FullTextServerResponseAll, QueryUnderstanding } from \"./@types/results\"\nimport { smartCollectionsResults } from \"./@types/categories\"\nimport FastSimonApi from \"./components/FastSimonApi/FastSimonApi\"\nimport MainTheme from \"./components/FastSimonApi\"\nimport { FeaturedRanking } from \"@fast-simon/utilities/lib/@types/product\"\nimport { Products } from \"./services/products\"\nimport {getLSVectorSearchDict, getLSVectorSearchOn } from \"./utils/getLSVectorSearch\"\nimport { AutocompleteReasoningResponse } from \"./@types/autocomplete\"\nimport {getUseCacheSetting, setUseCacheSetting} from \"./utils/getCacheSettings\"\nimport {getShowSalesAnalyticsSetting, setShowSalesAnalyticsSetting} from \"./utils/getSalesAnalyticsSettings\"\nimport {getShowRequestUrlSetting, setShowRequestUrlSetting} from \"./utils/getRequestUrlSettings\"\nimport {getPersonalizationSegment, getUserSegmentPreviewSettings, setUserSegmentPreviewSettings, UserSegmentPreview, UserSegmentPreviewSettings} from \"./utils/userSegmentPreview\"\nimport {getPersonalizationPreviewSettings, setPersonalizationPreviewSettings, buildPersonalizationParams, PersonalizationPreviewSettings, PersonalizationType} from \"./utils/personalizationPreview\"\nimport {getSessionTokenPreviewSettings, setSessionTokenPreviewSettings, SessionTokenPreviewSettings} from \"./utils/sessionTokenPreview\"\nimport {LiveSessionData, SpvProductMeta, RequestType, SPV_LIMITS, sendableViews, countSendableViews, generateSessionToken, getLiveSessionData, setLiveSessionData, addProductView, addProductToCart, buildLiveSessionParams, resetLiveSession, startLiveSession, stopLiveSession, setSessionSegment, setLiveSessionSiteScope, formatTokenAge, getUserSegmentFromToken} from \"./utils/liveSessionPreview\"\n// export * from './components';\n\nexport type {\n MenuItemName,\n CustomClasses,\n SideMenuType,\n SideMenuItem,\n ProductLabelType,\n Banner,\n EditorProduct,\n IconProps,\n ServerProduct,\n ProductAnalytics,\n ProductPersonalizationCoefficients,\n FilterCoefEntry,\n Pillar,\n PillarKind,\n PersonalizationConfidence,\n PersonalizationStory,\n FullTextServerResponseAll,\n QueryUnderstanding,\n smartCollectionsResults,\n AutocompleteReasoningResponse,\n FeaturedRanking,\n ComparisonData,\n UserSegmentPreview,\n UserSegmentPreviewSettings,\n PersonalizationPreviewSettings,\n PersonalizationType,\n SessionTokenPreviewSettings,\n LiveSessionData,\n SpvProductMeta,\n RequestType\n};\n\nexport {\n BackOfficeFiltersMenu, InStoreFiltersMenu, Droppable, DndContextWrapper, SortableItem, ProductGrid, RenderIfVisible,\n useDragToSelect, LandingPage, FullTextSearch, BackOfficeFiltersIcon, BannersIcon, HelpIcon, InStoreFiltersIcon, PromoteIcon,\n RestoreIcon, RemoveIcon, GeneralIcon, videoFormats, isEditorProduct,useFastState, useFastStateFunctions,FastSimonApi,MainTheme,\n Products, getFormatProducts, useProductsPerRow, ProductLabel, CustomTagsFilters, SelectCard ,getLSVectorSearchOn,getLSVectorSearchDict,\n getUseCacheSetting, setUseCacheSetting, getShowSalesAnalyticsSetting, setShowSalesAnalyticsSetting,\n getShowRequestUrlSetting, setShowRequestUrlSetting,\n getPersonalizationSegment, getUserSegmentPreviewSettings, setUserSegmentPreviewSettings,\n getPersonalizationPreviewSettings, setPersonalizationPreviewSettings, buildPersonalizationParams,\n getSessionTokenPreviewSettings, setSessionTokenPreviewSettings,\n generateSessionToken, getLiveSessionData, setLiveSessionData, addProductView, addProductToCart,\n buildLiveSessionParams, resetLiveSession, startLiveSession, stopLiveSession, setSessionSegment, setLiveSessionSiteScope, formatTokenAge, getUserSegmentFromToken, SPV_LIMITS, countSendableViews\n};"]}
@@ -21,8 +21,11 @@ export interface SpvLimits {
21
21
  expiryDays: number;
22
22
  }
23
23
  export declare const SPV_LIMITS: Record<RequestType, SpvLimits>;
24
- /** How many views `buildLiveSessionParams` would actually send. Not `Object.keys(spv).length`:
25
- * `filterAccumulator` drops expired entries BEFORE comparing against `min`. */
24
+ /** The views `buildLiveSessionParams` still counts, most recent first. Not `Object.entries(spv)`:
25
+ * `filterAccumulator` drops expired entries BEFORE comparing against `min`. Not capped at `max`
26
+ * either -- the cap is applied before the `min` check, but `max >= min` on both surfaces, so it
27
+ * cannot change activation, and a capped count would disagree with the list it heads. */
28
+ export declare function sendableViews(spv: Record<string, number>, requestType: RequestType): [string, number][];
26
29
  export declare function countSendableViews(spv: Record<string, number>, requestType: RequestType): number;
27
30
  /**
28
31
  * Set the site scope for live session storage. Must be called when the site changes.
@@ -4,12 +4,16 @@ export const SPV_LIMITS = {
4
4
  collection: { min: 1, max: 10, expiryDays: 365 },
5
5
  search: { min: 3, max: 50, expiryDays: 5 },
6
6
  };
7
- /** How many views `buildLiveSessionParams` would actually send. Not `Object.keys(spv).length`:
8
- * `filterAccumulator` drops expired entries BEFORE comparing against `min`. */
7
+ /** The views `buildLiveSessionParams` still counts, most recent first. Not `Object.entries(spv)`:
8
+ * `filterAccumulator` drops expired entries BEFORE comparing against `min`. Not capped at `max`
9
+ * either -- the cap is applied before the `min` check, but `max >= min` on both surfaces, so it
10
+ * cannot change activation, and a capped count would disagree with the list it heads. */
11
+ export function sendableViews(spv, requestType) {
12
+ const cutoff = Math.floor(Date.now() / 1000) - SPV_LIMITS[requestType].expiryDays * 86400;
13
+ return Object.entries(spv || {}).filter(([, ts]) => ts >= cutoff).sort((a, b) => b[1] - a[1]);
14
+ }
9
15
  export function countSendableViews(spv, requestType) {
10
- const limits = SPV_LIMITS[requestType];
11
- const cutoff = Math.floor(Date.now() / 1000) - limits.expiryDays * 86400;
12
- return Math.min(Object.values(spv || {}).filter(ts => ts >= cutoff).length, limits.max);
16
+ return sendableViews(spv, requestType).length;
13
17
  }
14
18
  const LIVE_SESSION_KEY_PREFIX = 'ai_explainer_live_session';
15
19
  const SESSION_TIMEOUT_MS = 30 * 60 * 1000; // 30 minutes — matches storefront SESSION_TOKEN_LIFE
@@ -1 +1 @@
1
- {"version":3,"file":"liveSessionPreview.js","sourceRoot":"","sources":["../../src/utils/liveSessionPreview.ts"],"names":[],"mappings":"AA0BA,iGAAiG;AACjG,mEAAmE;AACnE,MAAM,CAAC,MAAM,UAAU,GAAmC;IACtD,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE;IAChD,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE;CAC7C,CAAC;AAEF;gFACgF;AAChF,MAAM,UAAU,kBAAkB,CAAC,GAA2B,EAAE,WAAwB;IACpF,MAAM,MAA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IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC;AACjF,CAAC","sourcesContent":["export interface SpvProductMeta {\n title: string;\n image?: string;\n url?: string;\n size?: string; // cart-adds only: the size that was added (a product can be carted in several sizes)\n}\n\nexport interface LiveSessionData {\n enabled: boolean;\n sessionToken: string;\n spv: Record<string, number>; // {product_id: unix_timestamp}\n spvMeta: Record<string, SpvProductMeta>; // {product_id: {title, image}} — display info only\n spc: Record<string, number>; // {\"product_id::variant_id\": unix_timestamp} — cart actions\n spcMeta: Record<string, SpvProductMeta>; // {\"product_id::variant_id\": {title, image, url, size}} — per cart-add, display info only\n createdAt: number; // unix timestamp ms when token was created\n lastActive: number; // unix timestamp ms of last activity (matches storefront 30-min timeout)\n}\n\nexport type RequestType = 'collection' | 'search';\n\nexport interface SpvLimits {\n min: number;\n max: number;\n expiryDays: number;\n}\n\n// Exported so the panel reads the same thresholds `buildLiveSessionParams` trims by, rather than\n// re-deriving them; two components had already drifted to 1 and 3.\nexport const SPV_LIMITS: Record<RequestType, SpvLimits> = {\n collection: { min: 1, max: 10, expiryDays: 365 },\n search: { min: 3, max: 50, expiryDays: 5 },\n};\n\n/** How many views `buildLiveSessionParams` would actually send. Not `Object.keys(spv).length`:\n * `filterAccumulator` drops expired entries BEFORE comparing against `min`. */\nexport function countSendableViews(spv: Record<string, number>, requestType: RequestType): number {\n const limits = SPV_LIMITS[requestType];\n const cutoff = Math.floor(Date.now() / 1000) - limits.expiryDays * 86400;\n return Math.min(Object.values(spv || {}).filter(ts => ts >= cutoff).length, limits.max);\n}\n\nconst LIVE_SESSION_KEY_PREFIX = 'ai_explainer_live_session';\nconst SESSION_TIMEOUT_MS = 30 * 60 * 1000; // 30 minutes — matches storefront SESSION_TOKEN_LIFE\n\n// Current site scope — must be set before any live session operations\nlet _siteScope = '';\n\n/**\n * Set the site scope for live session storage. Must be called when the site changes.\n * This ensures SPV/token are isolated per site.\n */\nexport function setLiveSessionSiteScope(uuid: string): void {\n _siteScope = uuid;\n}\n\nfunction getLiveSessionKey(): string {\n return _siteScope ? `${LIVE_SESSION_KEY_PREFIX}_${_siteScope}` : LIVE_SESSION_KEY_PREFIX;\n}\n\n// Crockford Base32 alphabet for ULID encoding\nconst CROCKFORD = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';\n\n/**\n * Generate a ULID-based session token matching production format: 'g' + 26-char ULID.\n * @param timestampMs - Optional timestamp in ms to encode (defaults to Date.now()).\n * Use a past timestamp to simulate a \"returning\" user (e.g., Date.now() - 2 * 86400000).\n */\nexport function generateSessionToken(timestampMs?: number): string {\n const now = timestampMs ?? Date.now();\n let ts = now;\n const timePart = new Array(10);\n for (let i = 9; i >= 0; i--) {\n timePart[i] = CROCKFORD[ts & 0x1f];\n ts = Math.floor(ts / 32);\n }\n const randPart = new Array(16);\n for (let i = 0; i < 16; i++) {\n randPart[i] = CROCKFORD[Math.floor(Math.random() * 32)];\n }\n return 'g' + timePart.join('') + randPart.join('');\n}\n\nconst defaultData: LiveSessionData = {\n enabled: false,\n sessionToken: '',\n spv: {},\n spvMeta: {},\n spc: {},\n spcMeta: {},\n createdAt: 0,\n lastActive: 0,\n};\n\nexport function getLiveSessionData(): LiveSessionData {\n try {\n const stored = localStorage.getItem(getLiveSessionKey());\n if (stored) {\n const parsed = JSON.parse(stored);\n if (!parsed.spvMeta) parsed.spvMeta = {};\n // spc / spcMeta are keyed by \"product_id::variant_id\". Drop any key without \"::\" —\n // serving silently ignores such keys and they'd corrupt the product-id derivation\n // (cartedProductIds). Also covers data from an earlier bare-variant-id format.\n parsed.spc = Object.fromEntries(Object.entries(parsed.spc || {}).filter(([k]) => k.includes('::')));\n parsed.spcMeta = Object.fromEntries(Object.entries(parsed.spcMeta || {}).filter(([k]) => k.includes('::')));\n if (!parsed.lastActive) parsed.lastActive = parsed.createdAt || 0;\n return parsed;\n }\n } catch (e) {\n // Ignore parsing errors\n }\n return { ...defaultData };\n}\n\nexport function setLiveSessionData(data: LiveSessionData): void {\n localStorage.setItem(getLiveSessionKey(), JSON.stringify(data));\n}\n\n/**\n * Check if the session has timed out (30+ min of inactivity).\n */\nfunction isSessionExpired(data: LiveSessionData): boolean {\n if (!data.lastActive) return false;\n return (Date.now() - data.lastActive) >= SESSION_TIMEOUT_MS;\n}\n\n/**\n * Touch the session (update lastActive). Called on every meaningful action.\n */\nfunction touchSession(data: LiveSessionData): LiveSessionData {\n data.lastActive = Date.now();\n return data;\n}\n\n/**\n * Filter and cap an accumulator (SPV or SPC) for a specific request type.\n */\nfunction filterAccumulator(\n acc: Record<string, number>,\n limits: SpvLimits\n): Record<string, number> | undefined {\n const cutoff = Math.floor(Date.now() / 1000) - limits.expiryDays * 86400;\n const entries = Object.entries(acc);\n // Fast path: skip filtering if empty\n if (entries.length === 0) return undefined;\n\n const recent = entries\n .filter(([_, ts]) => ts >= cutoff)\n .sort((a, b) => b[1] - a[1])\n .slice(0, limits.max);\n\n if (recent.length < limits.min) return undefined;\n return Object.fromEntries(recent);\n}\n\n/**\n * Add a product view to SPV. Touches session. Persists to localStorage.\n * @param meta - Optional product title/image for display in the session panel.\n */\nexport function addProductView(productId: string, meta?: SpvProductMeta): LiveSessionData {\n const data = touchSession(getLiveSessionData());\n data.spv[productId] = Math.floor(Date.now() / 1000);\n if (meta) data.spvMeta[productId] = meta;\n setLiveSessionData(data);\n return data;\n}\n\n/**\n * Add a cart-add to SPC. Touches session. Persists to localStorage.\n * @param productVariantKey - must be \"product_id::variant_id\" to match the serving parser\n * (a key without \"::\" is silently dropped by serving's _init_spc_cart; treated as a no-op here).\n * @param meta - optional product title/image/url/size for display in the session panel, keyed by\n * the full \"product_id::variant_id\" so each size of a product is its own cart-add.\n */\nexport function addProductToCart(productVariantKey: string, meta?: SpvProductMeta): LiveSessionData {\n // Validate before touching the session: serving drops keys without \"::\", so a bad key is a\n // no-op and shouldn't mutate the session at all.\n if (!productVariantKey.includes('::')) {\n return getLiveSessionData();\n }\n const data = touchSession(getLiveSessionData());\n data.spc[productVariantKey] = Math.floor(Date.now() / 1000);\n if (meta) data.spcMeta[productVariantKey] = meta;\n setLiveSessionData(data);\n return data;\n}\n\n/**\n * Convert LiveSessionData into the params format that updateSettingsAndRefetch expects.\n * Also touches the session (updates lastActive).\n */\n/**\n * @param personalizationTypes - Available filter types from the backend (e.g., ['gender', 'size', 'type']).\n * Defaults to all known types if not provided.\n */\nexport function buildLiveSessionParams(data: LiveSessionData, requestType: RequestType = 'collection', personalizationTypes: string[] = ['gender', 'size', 'type']): {\n personalization_preview: { enabled: boolean; spvJson: string; spcJson: string; types: string[] } | null;\n session_token: string | undefined;\n user_segment_preview: 'none' | 'new' | 'returning';\n} {\n if (!data.enabled) {\n return { personalization_preview: null, session_token: undefined, user_segment_preview: 'none' };\n }\n\n const limits = SPV_LIMITS[requestType];\n const filteredSpv = filterAccumulator(data.spv, limits);\n // SPC only sent with collections (not supported in search serving)\n const filteredSpc = requestType === 'collection' ? filterAccumulator(data.spc, limits) : undefined;\n\n // spv OR spc enables the preview — a cart-only session (size personalization) is valid.\n // Active personalization types ALSO enable it with an empty session: sites that run the\n // size-availability correction from n=0 (empty cart -> population-prior baseline) still need\n // the request to carry `personalization`, otherwise serving's use_filter_personalization stays\n // off and the cold-start size down-ranking a real first-time shopper sees can't be previewed.\n const hasTypes = personalizationTypes.length > 0;\n return {\n personalization_preview: (filteredSpv || filteredSpc || hasTypes) ? {\n enabled: true,\n spvJson: filteredSpv ? JSON.stringify(filteredSpv) : '',\n spcJson: filteredSpc ? JSON.stringify(filteredSpc) : '',\n types: personalizationTypes,\n } : null,\n session_token: data.sessionToken || undefined,\n user_segment_preview: getUserSegmentFromToken(data.createdAt),\n };\n}\n\n/**\n * Regenerate session token with a specific age for new/returning segment testing.\n * \"new\" → token created now (age < 1 day). \"returning\" → token created 2 days ago.\n * Preserves SPV/SPC — only the token changes.\n */\nexport function setSessionSegment(segment: 'new' | 'returning'): LiveSessionData {\n const data = touchSession(getLiveSessionData());\n const tokenTimestamp = segment === 'returning'\n ? Date.now() - 2 * 24 * 60 * 60 * 1000 // 2 days ago\n : Date.now();\n data.sessionToken = generateSessionToken(tokenTimestamp);\n data.createdAt = tokenTimestamp;\n setLiveSessionData(data);\n return data;\n}\n\n/**\n * Reset live session: fresh token, clear SPV + SPC.\n */\nexport function resetLiveSession(): LiveSessionData {\n const now = Date.now();\n const data: LiveSessionData = {\n enabled: true,\n sessionToken: generateSessionToken(),\n spv: {},\n spvMeta: {},\n spc: {},\n spcMeta: {},\n createdAt: now,\n lastActive: now,\n };\n setLiveSessionData(data);\n return data;\n}\n\n/**\n * Start a live session. Resumes if existing and not expired.\n * If expired (30+ min inactive), resets to a fresh session (matching storefront behavior).\n */\nexport function startLiveSession(): LiveSessionData {\n const existing = getLiveSessionData();\n if (existing.sessionToken && !isSessionExpired(existing)) {\n existing.enabled = true;\n existing.lastActive = Date.now();\n setLiveSessionData(existing);\n return existing;\n }\n // No session or expired — create fresh\n return resetLiveSession();\n}\n\n/**\n * Stop live session (pause). Token, SPV and SPC remain for potential resume.\n */\nexport function stopLiveSession(): LiveSessionData {\n const data = getLiveSessionData();\n data.enabled = false;\n setLiveSessionData(data);\n return data;\n}\n\n/**\n * Format token age as human-readable string.\n */\nexport function formatTokenAge(createdAt: number): string {\n if (!createdAt) return 'N/A';\n const totalMinutes = Math.floor((Date.now() - createdAt) / 60000);\n const days = Math.floor(totalMinutes / 1440);\n const hours = Math.floor((totalMinutes % 1440) / 60);\n const minutes = totalMinutes % 60;\n if (days > 0) return `${days}d ${hours}h`;\n if (hours > 0) return `${hours}h ${minutes}m`;\n return `${minutes}m`;\n}\n\n/**\n * Get user segment derived from token age.\n */\nexport function getUserSegmentFromToken(createdAt: number): 'new' | 'returning' {\n if (!createdAt) return 'new';\n return (Date.now() - createdAt) >= 24 * 60 * 60 * 1000 ? 'returning' : 'new';\n}\n"]}
1
+ {"version":3,"file":"liveSessionPreview.js","sourceRoot":"","sources":["../../src/utils/liveSessionPreview.ts"],"names":[],"mappings":"AA0BA,iGAAiG;AACjG,mEAAmE;AACnE,MAAM,CAAC,MAAM,UAAU,GAAmC;IACtD,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE;IAChD,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE;CAC7C,CAAC;AAEF;;;0FAG0F;AAC1F,MAAM,UAAU,aAAa,CAAC,GAA2B,EAAE,WAAwB;IAC/E,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,UAAU,GAAG,KAAK,CAAC;IAC1F,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClG,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,GAA2B,EAAE,WAAwB;IACpF,OAAO,aAAa,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,MAAM,CAAC;AAClD,CAAC;AAED,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAC5D,MAAM,kBAAkB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,qDAAqD;AAEhG,sEAAsE;AACtE,IAAI,UAAU,GAAG,EAAE,CAAC;AAEp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AC,SAAiB;IAC5C,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,KAAK,CAAC,CAAC;IAClE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IACrD,MAAM,OAAO,GAAG,YAAY,GAAG,EAAE,CAAC;IAClC,IAAI,IAAI,GAAG,CAAC;QAAE,OAAO,GAAG,IAAI,KAAK,KAAK,GAAG,CAAC;IAC1C,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,GAAG,KAAK,KAAK,OAAO,GAAG,CAAC;IAC9C,OAAO,GAAG,OAAO,GAAG,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,SAAiB;IACrD,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC;AACjF,CAAC","sourcesContent":["export interface SpvProductMeta {\n title: string;\n image?: string;\n url?: string;\n size?: string; // cart-adds only: the size that was added (a product can be carted in several sizes)\n}\n\nexport interface LiveSessionData {\n enabled: boolean;\n sessionToken: string;\n spv: Record<string, number>; // {product_id: unix_timestamp}\n spvMeta: Record<string, SpvProductMeta>; // {product_id: {title, image}} — display info only\n spc: Record<string, number>; // {\"product_id::variant_id\": unix_timestamp} — cart actions\n spcMeta: Record<string, SpvProductMeta>; // {\"product_id::variant_id\": {title, image, url, size}} — per cart-add, display info only\n createdAt: number; // unix timestamp ms when token was created\n lastActive: number; // unix timestamp ms of last activity (matches storefront 30-min timeout)\n}\n\nexport type RequestType = 'collection' | 'search';\n\nexport interface SpvLimits {\n min: number;\n max: number;\n expiryDays: number;\n}\n\n// Exported so the panel reads the same thresholds `buildLiveSessionParams` trims by, rather than\n// re-deriving them; two components had already drifted to 1 and 3.\nexport const SPV_LIMITS: Record<RequestType, SpvLimits> = {\n collection: { min: 1, max: 10, expiryDays: 365 },\n search: { min: 3, max: 50, expiryDays: 5 },\n};\n\n/** The views `buildLiveSessionParams` still counts, most recent first. Not `Object.entries(spv)`:\n * `filterAccumulator` drops expired entries BEFORE comparing against `min`. Not capped at `max`\n * either -- the cap is applied before the `min` check, but `max >= min` on both surfaces, so it\n * cannot change activation, and a capped count would disagree with the list it heads. */\nexport function sendableViews(spv: Record<string, number>, requestType: RequestType): [string, number][] {\n const cutoff = Math.floor(Date.now() / 1000) - SPV_LIMITS[requestType].expiryDays * 86400;\n return Object.entries(spv || {}).filter(([, ts]) => ts >= cutoff).sort((a, b) => b[1] - a[1]);\n}\n\nexport function countSendableViews(spv: Record<string, number>, requestType: RequestType): number {\n return sendableViews(spv, requestType).length;\n}\n\nconst LIVE_SESSION_KEY_PREFIX = 'ai_explainer_live_session';\nconst SESSION_TIMEOUT_MS = 30 * 60 * 1000; // 30 minutes — matches storefront SESSION_TOKEN_LIFE\n\n// Current site scope — must be set before any live session operations\nlet _siteScope = '';\n\n/**\n * Set the site scope for live session storage. Must be called when the site changes.\n * This ensures SPV/token are isolated per site.\n */\nexport function setLiveSessionSiteScope(uuid: string): void {\n _siteScope = uuid;\n}\n\nfunction getLiveSessionKey(): string {\n return _siteScope ? `${LIVE_SESSION_KEY_PREFIX}_${_siteScope}` : LIVE_SESSION_KEY_PREFIX;\n}\n\n// Crockford Base32 alphabet for ULID encoding\nconst CROCKFORD = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';\n\n/**\n * Generate a ULID-based session token matching production format: 'g' + 26-char ULID.\n * @param timestampMs - Optional timestamp in ms to encode (defaults to Date.now()).\n * Use a past timestamp to simulate a \"returning\" user (e.g., Date.now() - 2 * 86400000).\n */\nexport function generateSessionToken(timestampMs?: number): string {\n const now = timestampMs ?? Date.now();\n let ts = now;\n const timePart = new Array(10);\n for (let i = 9; i >= 0; i--) {\n timePart[i] = CROCKFORD[ts & 0x1f];\n ts = Math.floor(ts / 32);\n }\n const randPart = new Array(16);\n for (let i = 0; i < 16; i++) {\n randPart[i] = CROCKFORD[Math.floor(Math.random() * 32)];\n }\n return 'g' + timePart.join('') + randPart.join('');\n}\n\nconst defaultData: LiveSessionData = {\n enabled: false,\n sessionToken: '',\n spv: {},\n spvMeta: {},\n spc: {},\n spcMeta: {},\n createdAt: 0,\n lastActive: 0,\n};\n\nexport function getLiveSessionData(): LiveSessionData {\n try {\n const stored = localStorage.getItem(getLiveSessionKey());\n if (stored) {\n const parsed = JSON.parse(stored);\n if (!parsed.spvMeta) parsed.spvMeta = {};\n // spc / spcMeta are keyed by \"product_id::variant_id\". Drop any key without \"::\" —\n // serving silently ignores such keys and they'd corrupt the product-id derivation\n // (cartedProductIds). Also covers data from an earlier bare-variant-id format.\n parsed.spc = Object.fromEntries(Object.entries(parsed.spc || {}).filter(([k]) => k.includes('::')));\n parsed.spcMeta = Object.fromEntries(Object.entries(parsed.spcMeta || {}).filter(([k]) => k.includes('::')));\n if (!parsed.lastActive) parsed.lastActive = parsed.createdAt || 0;\n return parsed;\n }\n } catch (e) {\n // Ignore parsing errors\n }\n return { ...defaultData };\n}\n\nexport function setLiveSessionData(data: LiveSessionData): void {\n localStorage.setItem(getLiveSessionKey(), JSON.stringify(data));\n}\n\n/**\n * Check if the session has timed out (30+ min of inactivity).\n */\nfunction isSessionExpired(data: LiveSessionData): boolean {\n if (!data.lastActive) return false;\n return (Date.now() - data.lastActive) >= SESSION_TIMEOUT_MS;\n}\n\n/**\n * Touch the session (update lastActive). Called on every meaningful action.\n */\nfunction touchSession(data: LiveSessionData): LiveSessionData {\n data.lastActive = Date.now();\n return data;\n}\n\n/**\n * Filter and cap an accumulator (SPV or SPC) for a specific request type.\n */\nfunction filterAccumulator(\n acc: Record<string, number>,\n limits: SpvLimits\n): Record<string, number> | undefined {\n const cutoff = Math.floor(Date.now() / 1000) - limits.expiryDays * 86400;\n const entries = Object.entries(acc);\n // Fast path: skip filtering if empty\n if (entries.length === 0) return undefined;\n\n const recent = entries\n .filter(([_, ts]) => ts >= cutoff)\n .sort((a, b) => b[1] - a[1])\n .slice(0, limits.max);\n\n if (recent.length < limits.min) return undefined;\n return Object.fromEntries(recent);\n}\n\n/**\n * Add a product view to SPV. Touches session. Persists to localStorage.\n * @param meta - Optional product title/image for display in the session panel.\n */\nexport function addProductView(productId: string, meta?: SpvProductMeta): LiveSessionData {\n const data = touchSession(getLiveSessionData());\n data.spv[productId] = Math.floor(Date.now() / 1000);\n if (meta) data.spvMeta[productId] = meta;\n setLiveSessionData(data);\n return data;\n}\n\n/**\n * Add a cart-add to SPC. Touches session. Persists to localStorage.\n * @param productVariantKey - must be \"product_id::variant_id\" to match the serving parser\n * (a key without \"::\" is silently dropped by serving's _init_spc_cart; treated as a no-op here).\n * @param meta - optional product title/image/url/size for display in the session panel, keyed by\n * the full \"product_id::variant_id\" so each size of a product is its own cart-add.\n */\nexport function addProductToCart(productVariantKey: string, meta?: SpvProductMeta): LiveSessionData {\n // Validate before touching the session: serving drops keys without \"::\", so a bad key is a\n // no-op and shouldn't mutate the session at all.\n if (!productVariantKey.includes('::')) {\n return getLiveSessionData();\n }\n const data = touchSession(getLiveSessionData());\n data.spc[productVariantKey] = Math.floor(Date.now() / 1000);\n if (meta) data.spcMeta[productVariantKey] = meta;\n setLiveSessionData(data);\n return data;\n}\n\n/**\n * Convert LiveSessionData into the params format that updateSettingsAndRefetch expects.\n * Also touches the session (updates lastActive).\n */\n/**\n * @param personalizationTypes - Available filter types from the backend (e.g., ['gender', 'size', 'type']).\n * Defaults to all known types if not provided.\n */\nexport function buildLiveSessionParams(data: LiveSessionData, requestType: RequestType = 'collection', personalizationTypes: string[] = ['gender', 'size', 'type']): {\n personalization_preview: { enabled: boolean; spvJson: string; spcJson: string; types: string[] } | null;\n session_token: string | undefined;\n user_segment_preview: 'none' | 'new' | 'returning';\n} {\n if (!data.enabled) {\n return { personalization_preview: null, session_token: undefined, user_segment_preview: 'none' };\n }\n\n const limits = SPV_LIMITS[requestType];\n const filteredSpv = filterAccumulator(data.spv, limits);\n // SPC only sent with collections (not supported in search serving)\n const filteredSpc = requestType === 'collection' ? filterAccumulator(data.spc, limits) : undefined;\n\n // spv OR spc enables the preview — a cart-only session (size personalization) is valid.\n // Active personalization types ALSO enable it with an empty session: sites that run the\n // size-availability correction from n=0 (empty cart -> population-prior baseline) still need\n // the request to carry `personalization`, otherwise serving's use_filter_personalization stays\n // off and the cold-start size down-ranking a real first-time shopper sees can't be previewed.\n const hasTypes = personalizationTypes.length > 0;\n return {\n personalization_preview: (filteredSpv || filteredSpc || hasTypes) ? {\n enabled: true,\n spvJson: filteredSpv ? JSON.stringify(filteredSpv) : '',\n spcJson: filteredSpc ? JSON.stringify(filteredSpc) : '',\n types: personalizationTypes,\n } : null,\n session_token: data.sessionToken || undefined,\n user_segment_preview: getUserSegmentFromToken(data.createdAt),\n };\n}\n\n/**\n * Regenerate session token with a specific age for new/returning segment testing.\n * \"new\" → token created now (age < 1 day). \"returning\" → token created 2 days ago.\n * Preserves SPV/SPC — only the token changes.\n */\nexport function setSessionSegment(segment: 'new' | 'returning'): LiveSessionData {\n const data = touchSession(getLiveSessionData());\n const tokenTimestamp = segment === 'returning'\n ? Date.now() - 2 * 24 * 60 * 60 * 1000 // 2 days ago\n : Date.now();\n data.sessionToken = generateSessionToken(tokenTimestamp);\n data.createdAt = tokenTimestamp;\n setLiveSessionData(data);\n return data;\n}\n\n/**\n * Reset live session: fresh token, clear SPV + SPC.\n */\nexport function resetLiveSession(): LiveSessionData {\n const now = Date.now();\n const data: LiveSessionData = {\n enabled: true,\n sessionToken: generateSessionToken(),\n spv: {},\n spvMeta: {},\n spc: {},\n spcMeta: {},\n createdAt: now,\n lastActive: now,\n };\n setLiveSessionData(data);\n return data;\n}\n\n/**\n * Start a live session. Resumes if existing and not expired.\n * If expired (30+ min inactive), resets to a fresh session (matching storefront behavior).\n */\nexport function startLiveSession(): LiveSessionData {\n const existing = getLiveSessionData();\n if (existing.sessionToken && !isSessionExpired(existing)) {\n existing.enabled = true;\n existing.lastActive = Date.now();\n setLiveSessionData(existing);\n return existing;\n }\n // No session or expired — create fresh\n return resetLiveSession();\n}\n\n/**\n * Stop live session (pause). Token, SPV and SPC remain for potential resume.\n */\nexport function stopLiveSession(): LiveSessionData {\n const data = getLiveSessionData();\n data.enabled = false;\n setLiveSessionData(data);\n return data;\n}\n\n/**\n * Format token age as human-readable string.\n */\nexport function formatTokenAge(createdAt: number): string {\n if (!createdAt) return 'N/A';\n const totalMinutes = Math.floor((Date.now() - createdAt) / 60000);\n const days = Math.floor(totalMinutes / 1440);\n const hours = Math.floor((totalMinutes % 1440) / 60);\n const minutes = totalMinutes % 60;\n if (days > 0) return `${days}d ${hours}h`;\n if (hours > 0) return `${hours}h ${minutes}m`;\n return `${minutes}m`;\n}\n\n/**\n * Get user segment derived from token age.\n */\nexport function getUserSegmentFromToken(createdAt: number): 'new' | 'returning' {\n if (!createdAt) return 'new';\n return (Date.now() - createdAt) >= 24 * 60 * 60 * 1000 ? 'returning' : 'new';\n}\n"]}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@fast-simon/dashboard-utilities",
3
- "version": "1.0.168-beta.5",
3
+ "version": "1.0.168-beta.7",
4
4
  "scripts": {
5
5
  "dev": "vite",
6
6
  "preview": "vite preview",
7
7
  "build": "tsc -p tsconfig-build.json",
8
+ "test": "vitest run",
8
9
  "postbuild": "copyfiles -u 2 \"src/components/**/*.css\" dist/components && copyfiles -u 2 \"src/icons/**/*.css\" dist/icons && copyfiles -u 2 \"src/assets/**/*.gif\" dist/assets"
9
10
  },
10
11
  "main": "dist/index.js",
@@ -57,6 +58,7 @@
57
58
  "react-modal": "3.14.4",
58
59
  "react-router-dom": "^5.2.0",
59
60
  "rimraf": "^3.0.2",
61
+ "vitest": "^1.6.1",
60
62
  "typescript": "^4.4.4",
61
63
  "vite": "^2.7.2"
62
64
  },