@wix/web5-core 1.63.6 → 1.63.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/cjs/component/types.js.map +1 -1
- package/dist/cjs/hooks/useResolveSearchSpringEntityData.js +17 -1
- package/dist/cjs/hooks/useResolveSearchSpringEntityData.js.map +1 -1
- package/dist/cjs/hooks/useResolveShopifyEntityData.js +30 -9
- package/dist/cjs/hooks/useResolveShopifyEntityData.js.map +1 -1
- package/dist/cjs/services/shopify/transformShopifyEntity.js +27 -6
- package/dist/cjs/services/shopify/transformShopifyEntity.js.map +1 -1
- package/dist/esm/component/types.js.map +1 -1
- package/dist/esm/hooks/useResolveSearchSpringEntityData.js +17 -1
- package/dist/esm/hooks/useResolveSearchSpringEntityData.js.map +1 -1
- package/dist/esm/hooks/useResolveShopifyEntityData.js +30 -9
- package/dist/esm/hooks/useResolveShopifyEntityData.js.map +1 -1
- package/dist/esm/services/shopify/transformShopifyEntity.js +27 -6
- package/dist/esm/services/shopify/transformShopifyEntity.js.map +1 -1
- package/dist/types/component/types.d.ts +8 -0
- package/dist/types/component/types.d.ts.map +1 -1
- package/dist/types/hooks/useResolveSearchSpringEntityData.d.ts +11 -0
- package/dist/types/hooks/useResolveSearchSpringEntityData.d.ts.map +1 -1
- package/dist/types/hooks/useResolveShopifyEntityData.d.ts +11 -0
- package/dist/types/hooks/useResolveShopifyEntityData.d.ts.map +1 -1
- package/dist/types/services/shopify/transformShopifyEntity.d.ts +2 -2
- package/dist/types/services/shopify/transformShopifyEntity.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../../src/component/types.ts"],"sourcesContent":["import type { FC } from 'react';\nimport type { Callout } from '../types/callout';\n\n/** Props extracted from markdown (base layer). */\nexport interface BaseCompProps {}\nexport interface SlotCompProps extends BaseCompProps {\n callout?: Callout;\n}\n\nexport interface SectionCompProps extends BaseCompProps {\n callout?: Callout;\n}\n\n/** Section props with a slot. TSlot enforces which slot component this section accepts. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface SectionCompPropsWithSlot<TSlot extends FC<any> = FC<any>>\n extends SectionCompProps {\n slot?: TSlot;\n}\n\n// ----------------------\n// Base Components\n// ----------------------\n\nexport interface TextCompProps extends BaseCompProps {\n content: string;\n variant?: 'h1' | 'h2' | 'body' | 'caption';\n}\n\nexport interface ButtonCompProps extends BaseCompProps {\n label: string;\n variant?: 'primary' | 'secondary' | 'ghost';\n onClick?: string;\n}\n\nexport interface ImageCompProps extends BaseCompProps {\n src: string;\n alt: string;\n ratio?: '16:9' | '4:3' | '1:1' | '9:16' | '3:4';\n}\n\nexport interface BadgeCompProps extends BaseCompProps {\n label: string;\n color?: 'primary' | 'secondary' | 'success' | 'warning' | 'error';\n}\n\n// ----------------------\n// Hero Button (aligned to HeroSection1Button)\n// ----------------------\n\nexport interface HeroButton {\n id: string;\n text: string;\n variant?: 'primary' | 'secondary';\n onClick?: string;\n}\n\n// ----------------------\n// Slot Components\n// ----------------------\n\nexport interface KpiItemCompProps extends SlotCompProps {\n title: string;\n description: string;\n icon?: string;\n}\n\n/** Feature item — aligned to web50-server-ui Feature interface */\nexport interface FeatureItemCompProps extends SlotCompProps {\n title?: string;\n description?: string;\n icon?: string;\n}\n\n/** Feature card — aligned to web50-server-ui FeatureCard */\nexport interface FeatureCardCompProps extends SlotCompProps {\n title: string;\n description: string;\n imageUrl?: string;\n imageFromText?: boolean;\n linkText?: string;\n linkHref?: string;\n callout?: Callout;\n}\n\n/** Resolved entity data (populated at runtime via useResolveGenericEntityData) */\nexport interface EntityItemData {\n url: string;\n title: string;\n type: string;\n description?: string;\n excerpt?: string;\n imageUrl?: string;\n date?: string;\n publishDate?: string;\n author?: string;\n cmsItemId?: string;\n usage?: number;\n tags?: string[];\n /** Product vendor / brand name (e.g. \"HOKA\") */\n vendor?: string;\n /**\n * The `{ name, value }` pairs of the one variant a search matched, in the\n * store's own order. Present only when retrieval resolved the product down\n * to a single variant. The names are the store's own, so read this by\n * iterating it — never by looking a name up.\n */\n matchedOptions?: { name: string; value: string }[];\n /** Formatted lowest price across the product's variants (e.g. \"$107.95\") */\n priceMin?: string;\n /** Formatted highest price across the product's variants */\n priceMax?: string;\n /** Formatted price string (e.g. \"542.00 NIS\") */\n price?: string;\n /** Secondary product image URL — shown on hover */\n secondaryImageUrl?: string;\n /** Available sizes for the product */\n sizes?: string[];\n /** Original price before discount (formatted, e.g. \"494.00 NIS\") — shown with strikethrough */\n compareAtPrice?: string;\n /** Discount percentage (e.g. \"30% OFF\") */\n discountPercent?: string;\n /** Product variants with IDs and availability — used for add-to-cart and size display */\n variants?: {\n label: string;\n variantId: string;\n available: boolean;\n selectedOptions?: { name: string; value: string }[];\n price?: string;\n compareAtPrice?: string;\n }[];\n /** All product image URLs (not just featured + secondary) */\n allImages?: string[];\n /** Product option groups (e.g. Size, Color) with their available values */\n options?: { name: string; values: string[] }[];\n}\n\n/** Single entity item within an entity section */\nexport interface EntityItem {\n entityId: string;\n linkText?: string;\n entityType: string;\n entityUrl: string;\n description?: string;\n imageUrl?: string;\n /** Per-item callout from a blockquote inside the list item */\n callout?: Callout;\n /** Resolved at runtime via useResolveGenericEntityData hook; not produced by parse() */\n data?: EntityItemData;\n}\n\n// ---------------------------------------------------------------------------\n// Deprecated aliases — kept for seed-components compilation\n// ---------------------------------------------------------------------------\n/** @deprecated Use EntityItemData */\nexport type GenericEntityData = EntityItemData;\n/** @deprecated Use EntityItemData */\nexport type SolutionEntityData = EntityItemData;\n/** @deprecated Use EntityItemData */\nexport type BlogEntityData = EntityItemData;\n/** @deprecated Use EntityItem */\nexport type GenericEntityCompProps = EntityItem;\n\n/** Comparison row — aligned to web50-server-ui ComparisonRow */\nexport interface ComparisonRow {\n feature: string;\n iconHint?: string;\n values: (boolean | string)[];\n}\n\nexport interface ComparisonColumn {\n label: string;\n href?: string;\n entityId?: string;\n entityType?: string;\n}\n\n/** @deprecated Use Callout from types/callout instead */\nexport interface AiNarrativeCompProps extends SlotCompProps {\n content: string;\n}\n\n// ----------------------\n// Section Components\n// ----------------------\n\n/** Hero — aligned to HeroSection1Props */\nexport interface HeroCompProps extends SectionCompProps {\n headline: string;\n badge?: string | { text: string; showIndicator?: boolean };\n content?: string;\n buttons?: HeroButton[];\n image?: string;\n trailingList?: string;\n leadingQuote?: string;\n}\n\n/**\n * Entity hero — a hero section whose body carries one or more web5 entity\n * links (`web5://entity/...`). Shares the hero framing fields with\n * {@link HeroCompProps} but, instead of CTA buttons, surfaces the entities as\n * resolvable {@link EntityItem}s for rich rendering.\n */\nexport interface HeroEntityCompProps extends SectionCompProps {\n headline: string;\n badge?: string | { text: string; showIndicator?: boolean };\n content?: string;\n image?: string;\n leadingQuote?: string;\n items: EntityItem[];\n}\n\n/** KPI — aligned to KpiSectionProps */\nexport interface KpiCompProps\n extends SectionCompPropsWithSlot<KpiItemComponent> {\n title: string;\n items: KpiItemCompProps[];\n}\n\n/** Feature cards — aligned to FeatureCardsSectionProps */\nexport interface FeatureCardsCompProps extends SectionCompProps {\n cards: FeatureCardCompProps[];\n}\n\n/** Unified entity section — replaces EntityCompProps, SolutionEntityCompProps, BlogEntityCompProps */\nexport interface EntityCompProps extends SectionCompProps {\n title: string;\n description?: string;\n items: EntityItem[];\n}\n\n/** Comparison — aligned to ComparisonSection1Props */\nexport interface ComparisonCompProps extends SectionCompProps {\n title: string;\n description?: string;\n columnLabels: string[];\n columns?: ComparisonColumn[];\n rows: ComparisonRow[];\n featureColumnLabel?: string;\n ctaText?: string;\n ctaHref?: string;\n}\n\n/** General text — aligned to GeneralTextSectionProps (used by Fallback) */\nexport interface GeneralTextCompProps extends SectionCompProps {\n markdown: string;\n}\n\n/** Callout — aligned to CalloutSectionProps */\nexport interface CalloutCompProps extends SectionCompProps {\n callouts: Callout[];\n title?: string;\n relatedLinks?: { text: string; url: string }[];\n}\n\n/** Next steps — aligned to NextStepsSectionProps */\nexport interface NextStepsCompProps extends SectionCompProps {\n title: string;\n body?: string;\n /**\n * True when the chips are already rendered inline inside `body`. Renderers\n * must show `body` alone in that case — listing `steps` as well repeats every\n * chip. `steps` stays populated either way; it is the machine-readable chip\n * list (the scroll chips under the answer are built from it).\n */\n chipsInlineInBody?: boolean;\n backgroundImage?: string;\n steps: { content: string; iconHint?: string }[];\n}\n\n/** Feature section 9+ — aligned to FeatureSection9PlusProps */\nexport interface FeatureSection9PlusCompProps extends SectionCompProps {\n title: string;\n description?: string;\n features: { title?: string; description: string; iconHint?: string }[];\n}\n\n/** List items section — title + a list of feature items. */\nexport interface ListItemsSectionCompProps extends SectionCompProps {\n title: string;\n features: { title?: string; description: string }[];\n}\n\nexport type ListItemsSectionComponent = FC<ListItemsSectionCompProps>;\n\n/** Error — aligned to ErrorSection */\nexport interface ErrorCompProps extends SectionCompProps {\n type: import('../errors/conversationErrorTypes').ConversationErrorType;\n}\n\n/** Skip/HTML/Search — null-component parsers */\nexport interface NullCompProps extends SectionCompProps {}\n\n/** @deprecated Use EntityCompProps */\nexport type SolutionEntityCompProps = EntityCompProps;\n/** @deprecated Use EntityCompProps */\nexport type BlogEntityCompProps = EntityCompProps;\n\n/** CTA Banner — dark purple gradient card with headline, description, and pill link buttons */\nexport interface CtaBannerCompProps extends SectionCompProps {\n headline: string;\n description?: string;\n links: { text: string; href: string }[];\n /** Contextual background image — resolved from allowed keywords during parse() */\n imageUrl?: string;\n imageFromText?: boolean;\n}\n\nexport type CtaBannerSectionComponent = FC<CtaBannerCompProps>;\n\n/** Text block — heading + body with an optional pullquote callout on the side */\nexport interface TextBlockCompProps extends SectionCompProps {\n title: string;\n description: string;\n}\n\n/** Personalized narrative — standalone section with no parse() definition */\nexport interface PersonalizedNarrativeCompProps extends SectionCompProps {\n title: string;\n content?: string;\n}\n\n// --------------------------------\n// Types of component - all components\n// --------------------------------\n\nexport type Component = BaseComponent | SlotComponent | SectionComponent;\n\nexport type BaseComponent = FC<BaseCompProps>;\nexport type SlotComponent = FC<SlotCompProps>;\nexport type SectionComponent = FC<SectionCompProps>;\n\n// Base Components\nexport type TextComponent = FC<TextCompProps>;\nexport type ButtonComponent = FC<ButtonCompProps>;\nexport type ImageComponent = FC<ImageCompProps>;\nexport type BadgeComponent = FC<BadgeCompProps>;\n\n// Slot Components\nexport type KpiItemComponent = FC<KpiItemCompProps>;\nexport type FeatureItemComponent = FC<FeatureItemCompProps>;\nexport type FeatureCardComponent = FC<FeatureCardCompProps>;\n/** @deprecated Use FC<EntityItem> */\nexport type GenericEntityComponent = FC<EntityItem>;\nexport type AiNarrativeComponent = FC<AiNarrativeCompProps>;\n\n// Section Components\nexport type ComparisonSectionComponent = FC<ComparisonCompProps>;\nexport type GeneralTextSectionComponent = FC<GeneralTextCompProps>;\nexport type TextBlockSectionComponent = FC<TextBlockCompProps>;\nexport type HeroSectionComponent = FC<HeroCompProps>;\nexport type HeroEntitySectionComponent = FC<HeroEntityCompProps>;\n\n// section components with slots\nexport type KpiSectionComponent = FC<KpiCompProps>;\nexport type FeatureCardsSectionComponent = FC<FeatureCardsCompProps>;\nexport type EntitySectionComponent = FC<EntityCompProps>;\n\n// New section component types for Phase 4\nexport type CalloutSectionComponent = FC<CalloutCompProps>;\nexport type NextStepsSectionComponent = FC<NextStepsCompProps>;\nexport type FeatureSection9PlusSectionComponent =\n FC<FeatureSection9PlusCompProps>;\nexport type NullSectionComponent = FC<NullCompProps>;\nexport type ErrorSectionComponent = FC<ErrorCompProps>;\nexport type SolutionEntitySectionComponent = FC<SolutionEntityCompProps>;\nexport type BlogEntitySectionComponent = FC<BlogEntityCompProps>;\nexport type PersonalizedNarrativeSectionComponent =\n FC<PersonalizedNarrativeCompProps>;\n\nexport type PropsOf<T> = T extends (props: infer P) => unknown ? P : never;\n\nexport interface SectionFixture<TProps> {\n markdown: string;\n expected: Partial<TProps>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../src/component/types.ts"],"sourcesContent":["import type { FC } from 'react';\nimport type { Callout } from '../types/callout';\n\n/** Props extracted from markdown (base layer). */\nexport interface BaseCompProps {}\nexport interface SlotCompProps extends BaseCompProps {\n callout?: Callout;\n}\n\nexport interface SectionCompProps extends BaseCompProps {\n callout?: Callout;\n}\n\n/** Section props with a slot. TSlot enforces which slot component this section accepts. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface SectionCompPropsWithSlot<TSlot extends FC<any> = FC<any>>\n extends SectionCompProps {\n slot?: TSlot;\n}\n\n// ----------------------\n// Base Components\n// ----------------------\n\nexport interface TextCompProps extends BaseCompProps {\n content: string;\n variant?: 'h1' | 'h2' | 'body' | 'caption';\n}\n\nexport interface ButtonCompProps extends BaseCompProps {\n label: string;\n variant?: 'primary' | 'secondary' | 'ghost';\n onClick?: string;\n}\n\nexport interface ImageCompProps extends BaseCompProps {\n src: string;\n alt: string;\n ratio?: '16:9' | '4:3' | '1:1' | '9:16' | '3:4';\n}\n\nexport interface BadgeCompProps extends BaseCompProps {\n label: string;\n color?: 'primary' | 'secondary' | 'success' | 'warning' | 'error';\n}\n\n// ----------------------\n// Hero Button (aligned to HeroSection1Button)\n// ----------------------\n\nexport interface HeroButton {\n id: string;\n text: string;\n variant?: 'primary' | 'secondary';\n onClick?: string;\n}\n\n// ----------------------\n// Slot Components\n// ----------------------\n\nexport interface KpiItemCompProps extends SlotCompProps {\n title: string;\n description: string;\n icon?: string;\n}\n\n/** Feature item — aligned to web50-server-ui Feature interface */\nexport interface FeatureItemCompProps extends SlotCompProps {\n title?: string;\n description?: string;\n icon?: string;\n}\n\n/** Feature card — aligned to web50-server-ui FeatureCard */\nexport interface FeatureCardCompProps extends SlotCompProps {\n title: string;\n description: string;\n imageUrl?: string;\n imageFromText?: boolean;\n linkText?: string;\n linkHref?: string;\n callout?: Callout;\n}\n\n/** Resolved entity data (populated at runtime via useResolveGenericEntityData) */\nexport interface EntityItemData {\n url: string;\n title: string;\n type: string;\n description?: string;\n excerpt?: string;\n imageUrl?: string;\n date?: string;\n publishDate?: string;\n author?: string;\n cmsItemId?: string;\n usage?: number;\n tags?: string[];\n /** Product vendor / brand name (e.g. \"HOKA\") */\n vendor?: string;\n /**\n * The `{ name, value }` pairs of the one variant a search matched, in the\n * store's own order. Present only when retrieval resolved the product down\n * to a single variant. The names are the store's own, so read this by\n * iterating it — never by looking a name up.\n */\n matchedOptions?: { name: string; value: string }[];\n /**\n * Id of the one variant a search matched — the same variant `imageUrl`,\n * `url` and `matchedOptions` describe. Bare store id, no `gid://` prefix.\n * A live enricher reads this to price that variant rather than the product.\n */\n variantId?: string;\n /** Whether the matched variant is in stock, as of the last live fetch */\n available?: boolean;\n /** Formatted lowest price across the product's variants (e.g. \"$107.95\") */\n priceMin?: string;\n /** Formatted highest price across the product's variants */\n priceMax?: string;\n /** Formatted price string (e.g. \"542.00 NIS\") */\n price?: string;\n /** Secondary product image URL — shown on hover */\n secondaryImageUrl?: string;\n /** Available sizes for the product */\n sizes?: string[];\n /** Original price before discount (formatted, e.g. \"494.00 NIS\") — shown with strikethrough */\n compareAtPrice?: string;\n /** Discount percentage (e.g. \"30% OFF\") */\n discountPercent?: string;\n /** Product variants with IDs and availability — used for add-to-cart and size display */\n variants?: {\n label: string;\n variantId: string;\n available: boolean;\n selectedOptions?: { name: string; value: string }[];\n price?: string;\n compareAtPrice?: string;\n }[];\n /** All product image URLs (not just featured + secondary) */\n allImages?: string[];\n /** Product option groups (e.g. Size, Color) with their available values */\n options?: { name: string; values: string[] }[];\n}\n\n/** Single entity item within an entity section */\nexport interface EntityItem {\n entityId: string;\n linkText?: string;\n entityType: string;\n entityUrl: string;\n description?: string;\n imageUrl?: string;\n /** Per-item callout from a blockquote inside the list item */\n callout?: Callout;\n /** Resolved at runtime via useResolveGenericEntityData hook; not produced by parse() */\n data?: EntityItemData;\n}\n\n// ---------------------------------------------------------------------------\n// Deprecated aliases — kept for seed-components compilation\n// ---------------------------------------------------------------------------\n/** @deprecated Use EntityItemData */\nexport type GenericEntityData = EntityItemData;\n/** @deprecated Use EntityItemData */\nexport type SolutionEntityData = EntityItemData;\n/** @deprecated Use EntityItemData */\nexport type BlogEntityData = EntityItemData;\n/** @deprecated Use EntityItem */\nexport type GenericEntityCompProps = EntityItem;\n\n/** Comparison row — aligned to web50-server-ui ComparisonRow */\nexport interface ComparisonRow {\n feature: string;\n iconHint?: string;\n values: (boolean | string)[];\n}\n\nexport interface ComparisonColumn {\n label: string;\n href?: string;\n entityId?: string;\n entityType?: string;\n}\n\n/** @deprecated Use Callout from types/callout instead */\nexport interface AiNarrativeCompProps extends SlotCompProps {\n content: string;\n}\n\n// ----------------------\n// Section Components\n// ----------------------\n\n/** Hero — aligned to HeroSection1Props */\nexport interface HeroCompProps extends SectionCompProps {\n headline: string;\n badge?: string | { text: string; showIndicator?: boolean };\n content?: string;\n buttons?: HeroButton[];\n image?: string;\n trailingList?: string;\n leadingQuote?: string;\n}\n\n/**\n * Entity hero — a hero section whose body carries one or more web5 entity\n * links (`web5://entity/...`). Shares the hero framing fields with\n * {@link HeroCompProps} but, instead of CTA buttons, surfaces the entities as\n * resolvable {@link EntityItem}s for rich rendering.\n */\nexport interface HeroEntityCompProps extends SectionCompProps {\n headline: string;\n badge?: string | { text: string; showIndicator?: boolean };\n content?: string;\n image?: string;\n leadingQuote?: string;\n items: EntityItem[];\n}\n\n/** KPI — aligned to KpiSectionProps */\nexport interface KpiCompProps\n extends SectionCompPropsWithSlot<KpiItemComponent> {\n title: string;\n items: KpiItemCompProps[];\n}\n\n/** Feature cards — aligned to FeatureCardsSectionProps */\nexport interface FeatureCardsCompProps extends SectionCompProps {\n cards: FeatureCardCompProps[];\n}\n\n/** Unified entity section — replaces EntityCompProps, SolutionEntityCompProps, BlogEntityCompProps */\nexport interface EntityCompProps extends SectionCompProps {\n title: string;\n description?: string;\n items: EntityItem[];\n}\n\n/** Comparison — aligned to ComparisonSection1Props */\nexport interface ComparisonCompProps extends SectionCompProps {\n title: string;\n description?: string;\n columnLabels: string[];\n columns?: ComparisonColumn[];\n rows: ComparisonRow[];\n featureColumnLabel?: string;\n ctaText?: string;\n ctaHref?: string;\n}\n\n/** General text — aligned to GeneralTextSectionProps (used by Fallback) */\nexport interface GeneralTextCompProps extends SectionCompProps {\n markdown: string;\n}\n\n/** Callout — aligned to CalloutSectionProps */\nexport interface CalloutCompProps extends SectionCompProps {\n callouts: Callout[];\n title?: string;\n relatedLinks?: { text: string; url: string }[];\n}\n\n/** Next steps — aligned to NextStepsSectionProps */\nexport interface NextStepsCompProps extends SectionCompProps {\n title: string;\n body?: string;\n /**\n * True when the chips are already rendered inline inside `body`. Renderers\n * must show `body` alone in that case — listing `steps` as well repeats every\n * chip. `steps` stays populated either way; it is the machine-readable chip\n * list (the scroll chips under the answer are built from it).\n */\n chipsInlineInBody?: boolean;\n backgroundImage?: string;\n steps: { content: string; iconHint?: string }[];\n}\n\n/** Feature section 9+ — aligned to FeatureSection9PlusProps */\nexport interface FeatureSection9PlusCompProps extends SectionCompProps {\n title: string;\n description?: string;\n features: { title?: string; description: string; iconHint?: string }[];\n}\n\n/** List items section — title + a list of feature items. */\nexport interface ListItemsSectionCompProps extends SectionCompProps {\n title: string;\n features: { title?: string; description: string }[];\n}\n\nexport type ListItemsSectionComponent = FC<ListItemsSectionCompProps>;\n\n/** Error — aligned to ErrorSection */\nexport interface ErrorCompProps extends SectionCompProps {\n type: import('../errors/conversationErrorTypes').ConversationErrorType;\n}\n\n/** Skip/HTML/Search — null-component parsers */\nexport interface NullCompProps extends SectionCompProps {}\n\n/** @deprecated Use EntityCompProps */\nexport type SolutionEntityCompProps = EntityCompProps;\n/** @deprecated Use EntityCompProps */\nexport type BlogEntityCompProps = EntityCompProps;\n\n/** CTA Banner — dark purple gradient card with headline, description, and pill link buttons */\nexport interface CtaBannerCompProps extends SectionCompProps {\n headline: string;\n description?: string;\n links: { text: string; href: string }[];\n /** Contextual background image — resolved from allowed keywords during parse() */\n imageUrl?: string;\n imageFromText?: boolean;\n}\n\nexport type CtaBannerSectionComponent = FC<CtaBannerCompProps>;\n\n/** Text block — heading + body with an optional pullquote callout on the side */\nexport interface TextBlockCompProps extends SectionCompProps {\n title: string;\n description: string;\n}\n\n/** Personalized narrative — standalone section with no parse() definition */\nexport interface PersonalizedNarrativeCompProps extends SectionCompProps {\n title: string;\n content?: string;\n}\n\n// --------------------------------\n// Types of component - all components\n// --------------------------------\n\nexport type Component = BaseComponent | SlotComponent | SectionComponent;\n\nexport type BaseComponent = FC<BaseCompProps>;\nexport type SlotComponent = FC<SlotCompProps>;\nexport type SectionComponent = FC<SectionCompProps>;\n\n// Base Components\nexport type TextComponent = FC<TextCompProps>;\nexport type ButtonComponent = FC<ButtonCompProps>;\nexport type ImageComponent = FC<ImageCompProps>;\nexport type BadgeComponent = FC<BadgeCompProps>;\n\n// Slot Components\nexport type KpiItemComponent = FC<KpiItemCompProps>;\nexport type FeatureItemComponent = FC<FeatureItemCompProps>;\nexport type FeatureCardComponent = FC<FeatureCardCompProps>;\n/** @deprecated Use FC<EntityItem> */\nexport type GenericEntityComponent = FC<EntityItem>;\nexport type AiNarrativeComponent = FC<AiNarrativeCompProps>;\n\n// Section Components\nexport type ComparisonSectionComponent = FC<ComparisonCompProps>;\nexport type GeneralTextSectionComponent = FC<GeneralTextCompProps>;\nexport type TextBlockSectionComponent = FC<TextBlockCompProps>;\nexport type HeroSectionComponent = FC<HeroCompProps>;\nexport type HeroEntitySectionComponent = FC<HeroEntityCompProps>;\n\n// section components with slots\nexport type KpiSectionComponent = FC<KpiCompProps>;\nexport type FeatureCardsSectionComponent = FC<FeatureCardsCompProps>;\nexport type EntitySectionComponent = FC<EntityCompProps>;\n\n// New section component types for Phase 4\nexport type CalloutSectionComponent = FC<CalloutCompProps>;\nexport type NextStepsSectionComponent = FC<NextStepsCompProps>;\nexport type FeatureSection9PlusSectionComponent =\n FC<FeatureSection9PlusCompProps>;\nexport type NullSectionComponent = FC<NullCompProps>;\nexport type ErrorSectionComponent = FC<ErrorCompProps>;\nexport type SolutionEntitySectionComponent = FC<SolutionEntityCompProps>;\nexport type BlogEntitySectionComponent = FC<BlogEntityCompProps>;\nexport type PersonalizedNarrativeSectionComponent =\n FC<PersonalizedNarrativeCompProps>;\n\nexport type PropsOf<T> = T extends (props: infer P) => unknown ? P : never;\n\nexport interface SectionFixture<TProps> {\n markdown: string;\n expected: Partial<TProps>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -31,8 +31,20 @@ function getSearchSpringHandle(entity) {
|
|
|
31
31
|
var _entity$data;
|
|
32
32
|
return extractProductHandle((_entity$data = entity.data) == null ? void 0 : _entity$data.url) || entity.entityId;
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The turn owns WHICH thing to show; the live fetch owns VOLATILE FACTS about
|
|
37
|
+
* it.
|
|
38
|
+
*
|
|
39
|
+
* Only the turn saw the shopper's question, so only it knows that the brown
|
|
40
|
+
* variant was the one asked for — its `title`, `imageUrl`, `url`,
|
|
41
|
+
* `matchedOptions` and `variantId` all describe that one variant and must
|
|
42
|
+
* survive enrichment. Everything SearchSpring answers with that can go stale
|
|
43
|
+
* between the turn and the render — `price`, `compareAtPrice`, `available`,
|
|
44
|
+
* `priceMin`, `priceMax` — comes from `resolved`.
|
|
45
|
+
*/
|
|
34
46
|
function mergeSearchSpringEntityData(existing, resolved) {
|
|
35
|
-
var _existing$sizes, _existing$variants, _existing$options, _existing$allImages;
|
|
47
|
+
var _existing$matchedOpti, _existing$sizes, _existing$variants, _existing$options, _existing$allImages;
|
|
36
48
|
if (!existing) {
|
|
37
49
|
return resolved;
|
|
38
50
|
}
|
|
@@ -40,6 +52,10 @@ function mergeSearchSpringEntityData(existing, resolved) {
|
|
|
40
52
|
...existing,
|
|
41
53
|
...resolved,
|
|
42
54
|
url: existing.url || resolved.url,
|
|
55
|
+
title: existing.title || resolved.title,
|
|
56
|
+
imageUrl: existing.imageUrl || resolved.imageUrl,
|
|
57
|
+
variantId: existing.variantId || resolved.variantId,
|
|
58
|
+
matchedOptions: (_existing$matchedOpti = existing.matchedOptions) != null && _existing$matchedOpti.length ? existing.matchedOptions : resolved.matchedOptions,
|
|
43
59
|
sizes: (_existing$sizes = existing.sizes) != null && _existing$sizes.length ? existing.sizes : resolved.sizes,
|
|
44
60
|
variants: (_existing$variants = existing.variants) != null && _existing$variants.length ? existing.variants : resolved.variants,
|
|
45
61
|
options: (_existing$options = existing.options) != null && _existing$options.length ? existing.options : resolved.options,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_searchSpringClient","_transformSSProduct","ssEntityCache","Map","extractProductHandle","url","trimmed","trim","undefined","pathname","test","URL","withoutQuery","split","withoutLeadingSlash","replace","productsIndex","indexOf","handle","slice","length","getSearchSpringHandle","entity","_entity$data","data","entityId","mergeSearchSpringEntityData","existing","resolved","_existing$sizes","_existing$variants","_existing$options","_existing$allImages","sizes","variants","options","allImages","useResolveSearchSpringEntityData","entities","config","resolvedMap","setResolvedMap","useState","settled","setSettled","entityKey","useMemo","map","e","entityType","join","useEffect","ignore","siteId","productEntityHandles","filter","toLowerCase","includes","handlesToFetch","Set","has","cached","forEach","item","get","set","fetchAll","productMap","fetchProductsByHandlesMap","product","itemData","transformSSProductToEntityItemData","finalMap","enrichedEntities","loading"],"sources":["../../../src/hooks/useResolveSearchSpringEntityData.ts"],"sourcesContent":["import { useState, useEffect, useMemo } from 'react';\nimport { fetchProductsByHandlesMap } from '../services/searchspring/searchSpringClient';\nimport { transformSSProductToEntityItemData } from '../services/searchspring/transformSSProduct';\nimport type { SearchSpringConfig } from '../services/searchspring/types';\nimport type { EntityItemData } from '../component/types';\n\n// Session-level cache: handle → resolved EntityItemData\nconst ssEntityCache = new Map<string, EntityItemData>();\n\nfunction extractProductHandle(url: string | undefined): string | undefined {\n const trimmed = url?.trim();\n if (!trimmed) {\n return undefined;\n }\n\n let pathname = trimmed;\n try {\n if (/^https?:\\/\\//i.test(trimmed)) {\n pathname = new URL(trimmed).pathname;\n }\n } catch {\n pathname = trimmed;\n }\n\n const withoutQuery = pathname.split(/[?#]/)[0];\n const withoutLeadingSlash = withoutQuery.replace(/^\\/+/, '');\n const productsIndex = withoutLeadingSlash.indexOf('products/');\n const handle =\n productsIndex >= 0\n ? withoutLeadingSlash.slice(productsIndex + 'products/'.length)\n : withoutLeadingSlash;\n\n return handle || undefined;\n}\n\nfunction getSearchSpringHandle(entity: {\n entityId: string;\n data?: EntityItemData;\n}): string {\n return extractProductHandle(entity.data?.url) || entity.entityId;\n}\n\nexport function mergeSearchSpringEntityData(\n existing: EntityItemData | undefined,\n resolved: EntityItemData,\n): EntityItemData {\n if (!existing) {\n return resolved;\n }\n\n return {\n ...existing,\n ...resolved,\n url: existing.url || resolved.url,\n sizes: existing.sizes?.length ? existing.sizes : resolved.sizes,\n variants: existing.variants?.length ? existing.variants : resolved.variants,\n options: existing.options?.length ? existing.options : resolved.options,\n allImages: existing.allImages?.length\n ? existing.allImages\n : resolved.allImages,\n };\n}\n\n/**\n * SearchSpring-backed entity resolution hook.\n *\n * Fetches product data from the SearchSpring Search API by handle\n * and transforms it to EntityItemData. Uses a single batched API call\n * for all products (bgfilter.handle supports OR).\n */\nexport function useResolveSearchSpringEntityData<\n TEntity extends {\n entityId: string;\n entityUrl: string;\n entityType: string;\n data?: EntityItemData;\n },\n>(\n entities: TEntity[],\n config: SearchSpringConfig,\n): { enrichedEntities: TEntity[]; loading: boolean } {\n const [resolvedMap, setResolvedMap] = useState<Map<string, EntityItemData>>(\n new Map(),\n );\n const [settled, setSettled] = useState(false);\n\n // Stable key for dependency tracking\n const entityKey = useMemo(\n () =>\n entities\n .map((e) => `${e.entityType}:${e.entityId}:${getSearchSpringHandle(e)}`)\n .join(','),\n [entities],\n );\n\n useEffect(() => {\n let ignore = false;\n\n if (!entities.length || !config.siteId) {\n setSettled(true);\n return;\n }\n\n const productEntityHandles = entities\n .filter((e) => e.entityType.toLowerCase().includes('product'))\n .map((entity) => ({\n entity,\n handle: getSearchSpringHandle(entity),\n }));\n\n // Collect handles that need fetching. CMS payload IDs use payload url as the handle.\n const handlesToFetch = [\n ...new Set(\n productEntityHandles\n .map(({ handle }) => handle)\n .filter((handle) => !ssEntityCache.has(handle)),\n ),\n ];\n\n // If everything is cached, resolve immediately\n if (handlesToFetch.length === 0) {\n const cached = new Map<string, EntityItemData>();\n productEntityHandles.forEach(({ entity, handle }) => {\n const item = ssEntityCache.get(handle);\n if (item) {\n cached.set(entity.entityId, item);\n }\n });\n setResolvedMap(cached);\n setSettled(true);\n return;\n }\n\n setSettled(false);\n\n const fetchAll = async () => {\n const productMap = await fetchProductsByHandlesMap(\n config.siteId,\n handlesToFetch,\n );\n\n // Transform and cache\n for (const [handle, product] of productMap) {\n const itemData = transformSSProductToEntityItemData(product);\n ssEntityCache.set(handle, itemData);\n }\n\n if (ignore) {\n return;\n }\n\n // Build the final map\n const finalMap = new Map<string, EntityItemData>();\n productEntityHandles.forEach(({ entity, handle }) => {\n const item = ssEntityCache.get(handle);\n if (item) {\n finalMap.set(entity.entityId, item);\n }\n });\n\n setResolvedMap(finalMap);\n setSettled(true);\n };\n\n fetchAll();\n return () => {\n ignore = true;\n };\n }, [entityKey, config.siteId]);\n\n // Merge resolved data into entities\n const enrichedEntities = useMemo(() => {\n return entities.map((entity) => {\n const resolved = resolvedMap.get(entity.entityId);\n if (resolved) {\n return {\n ...entity,\n data: mergeSearchSpringEntityData(entity.data, resolved),\n };\n }\n return entity;\n });\n }, [entities, resolvedMap]);\n\n return { enrichedEntities, loading: !settled };\n}\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAIA;AACA,MAAMG,aAAa,GAAG,IAAIC,GAAG,CAAyB,CAAC;AAEvD,SAASC,oBAAoBA,CAACC,GAAuB,EAAsB;EACzE,MAAMC,OAAO,GAAGD,GAAG,oBAAHA,GAAG,CAAEE,IAAI,CAAC,CAAC;EAC3B,I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]}
|
|
1
|
+
{"version":3,"names":["_react","require","_searchSpringClient","_transformSSProduct","ssEntityCache","Map","extractProductHandle","url","trimmed","trim","undefined","pathname","test","URL","withoutQuery","split","withoutLeadingSlash","replace","productsIndex","indexOf","handle","slice","length","getSearchSpringHandle","entity","_entity$data","data","entityId","mergeSearchSpringEntityData","existing","resolved","_existing$matchedOpti","_existing$sizes","_existing$variants","_existing$options","_existing$allImages","title","imageUrl","variantId","matchedOptions","sizes","variants","options","allImages","useResolveSearchSpringEntityData","entities","config","resolvedMap","setResolvedMap","useState","settled","setSettled","entityKey","useMemo","map","e","entityType","join","useEffect","ignore","siteId","productEntityHandles","filter","toLowerCase","includes","handlesToFetch","Set","has","cached","forEach","item","get","set","fetchAll","productMap","fetchProductsByHandlesMap","product","itemData","transformSSProductToEntityItemData","finalMap","enrichedEntities","loading"],"sources":["../../../src/hooks/useResolveSearchSpringEntityData.ts"],"sourcesContent":["import { useState, useEffect, useMemo } from 'react';\nimport { fetchProductsByHandlesMap } from '../services/searchspring/searchSpringClient';\nimport { transformSSProductToEntityItemData } from '../services/searchspring/transformSSProduct';\nimport type { SearchSpringConfig } from '../services/searchspring/types';\nimport type { EntityItemData } from '../component/types';\n\n// Session-level cache: handle → resolved EntityItemData\nconst ssEntityCache = new Map<string, EntityItemData>();\n\nfunction extractProductHandle(url: string | undefined): string | undefined {\n const trimmed = url?.trim();\n if (!trimmed) {\n return undefined;\n }\n\n let pathname = trimmed;\n try {\n if (/^https?:\\/\\//i.test(trimmed)) {\n pathname = new URL(trimmed).pathname;\n }\n } catch {\n pathname = trimmed;\n }\n\n const withoutQuery = pathname.split(/[?#]/)[0];\n const withoutLeadingSlash = withoutQuery.replace(/^\\/+/, '');\n const productsIndex = withoutLeadingSlash.indexOf('products/');\n const handle =\n productsIndex >= 0\n ? withoutLeadingSlash.slice(productsIndex + 'products/'.length)\n : withoutLeadingSlash;\n\n return handle || undefined;\n}\n\nfunction getSearchSpringHandle(entity: {\n entityId: string;\n data?: EntityItemData;\n}): string {\n return extractProductHandle(entity.data?.url) || entity.entityId;\n}\n\n/**\n * The turn owns WHICH thing to show; the live fetch owns VOLATILE FACTS about\n * it.\n *\n * Only the turn saw the shopper's question, so only it knows that the brown\n * variant was the one asked for — its `title`, `imageUrl`, `url`,\n * `matchedOptions` and `variantId` all describe that one variant and must\n * survive enrichment. Everything SearchSpring answers with that can go stale\n * between the turn and the render — `price`, `compareAtPrice`, `available`,\n * `priceMin`, `priceMax` — comes from `resolved`.\n */\nexport function mergeSearchSpringEntityData(\n existing: EntityItemData | undefined,\n resolved: EntityItemData,\n): EntityItemData {\n if (!existing) {\n return resolved;\n }\n\n return {\n ...existing,\n ...resolved,\n url: existing.url || resolved.url,\n title: existing.title || resolved.title,\n imageUrl: existing.imageUrl || resolved.imageUrl,\n variantId: existing.variantId || resolved.variantId,\n matchedOptions: existing.matchedOptions?.length\n ? existing.matchedOptions\n : resolved.matchedOptions,\n sizes: existing.sizes?.length ? existing.sizes : resolved.sizes,\n variants: existing.variants?.length ? existing.variants : resolved.variants,\n options: existing.options?.length ? existing.options : resolved.options,\n allImages: existing.allImages?.length\n ? existing.allImages\n : resolved.allImages,\n };\n}\n\n/**\n * SearchSpring-backed entity resolution hook.\n *\n * Fetches product data from the SearchSpring Search API by handle\n * and transforms it to EntityItemData. Uses a single batched API call\n * for all products (bgfilter.handle supports OR).\n */\nexport function useResolveSearchSpringEntityData<\n TEntity extends {\n entityId: string;\n entityUrl: string;\n entityType: string;\n data?: EntityItemData;\n },\n>(\n entities: TEntity[],\n config: SearchSpringConfig,\n): { enrichedEntities: TEntity[]; loading: boolean } {\n const [resolvedMap, setResolvedMap] = useState<Map<string, EntityItemData>>(\n new Map(),\n );\n const [settled, setSettled] = useState(false);\n\n // Stable key for dependency tracking\n const entityKey = useMemo(\n () =>\n entities\n .map((e) => `${e.entityType}:${e.entityId}:${getSearchSpringHandle(e)}`)\n .join(','),\n [entities],\n );\n\n useEffect(() => {\n let ignore = false;\n\n if (!entities.length || !config.siteId) {\n setSettled(true);\n return;\n }\n\n const productEntityHandles = entities\n .filter((e) => e.entityType.toLowerCase().includes('product'))\n .map((entity) => ({\n entity,\n handle: getSearchSpringHandle(entity),\n }));\n\n // Collect handles that need fetching. CMS payload IDs use payload url as the handle.\n const handlesToFetch = [\n ...new Set(\n productEntityHandles\n .map(({ handle }) => handle)\n .filter((handle) => !ssEntityCache.has(handle)),\n ),\n ];\n\n // If everything is cached, resolve immediately\n if (handlesToFetch.length === 0) {\n const cached = new Map<string, EntityItemData>();\n productEntityHandles.forEach(({ entity, handle }) => {\n const item = ssEntityCache.get(handle);\n if (item) {\n cached.set(entity.entityId, item);\n }\n });\n setResolvedMap(cached);\n setSettled(true);\n return;\n }\n\n setSettled(false);\n\n const fetchAll = async () => {\n const productMap = await fetchProductsByHandlesMap(\n config.siteId,\n handlesToFetch,\n );\n\n // Transform and cache\n for (const [handle, product] of productMap) {\n const itemData = transformSSProductToEntityItemData(product);\n ssEntityCache.set(handle, itemData);\n }\n\n if (ignore) {\n return;\n }\n\n // Build the final map\n const finalMap = new Map<string, EntityItemData>();\n productEntityHandles.forEach(({ entity, handle }) => {\n const item = ssEntityCache.get(handle);\n if (item) {\n finalMap.set(entity.entityId, item);\n }\n });\n\n setResolvedMap(finalMap);\n setSettled(true);\n };\n\n fetchAll();\n return () => {\n ignore = true;\n };\n }, [entityKey, config.siteId]);\n\n // Merge resolved data into entities\n const enrichedEntities = useMemo(() => {\n return entities.map((entity) => {\n const resolved = resolvedMap.get(entity.entityId);\n if (resolved) {\n return {\n ...entity,\n data: mergeSearchSpringEntityData(entity.data, resolved),\n };\n }\n return entity;\n });\n }, [entities, resolvedMap]);\n\n return { enrichedEntities, loading: !settled };\n}\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAIA;AACA,MAAMG,aAAa,GAAG,IAAIC,GAAG,CAAyB,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AM,CAAC,CAAC;;EAE9B;EACA,MAAMoB,gBAAgB,GAAG,IAAA3B,cAAO,EAAC,MAAM;IACrC,OAAOR,QAAQ,CAACS,GAAG,CAAE9B,MAAM,IAAK;MAC9B,MAAMM,QAAQ,GAAGiB,WAAW,CAACwB,GAAG,CAAC/C,MAAM,CAACG,QAAQ,CAAC;MACjD,IAAIG,QAAQ,EAAE;QACZ,OAAO;UACL,GAAGN,MAAM;UACTE,IAAI,EAAEE,2BAA2B,CAACJ,MAAM,CAACE,IAAI,EAAEI,QAAQ;QACzD,CAAC;MACH;MACA,OAAON,MAAM;IACf,CAAC,CAAC;EACJ,CAAC,EAAE,CAACqB,QAAQ,EAAEE,WAAW,CAAC,CAAC;EAE3B,OAAO;IAAEiC,gBAAgB;IAAEC,OAAO,EAAE,CAAC/B;EAAQ,CAAC;AAChD","ignoreList":[]}
|
|
@@ -7,10 +7,10 @@ var _react = require("react");
|
|
|
7
7
|
var _shopifyStorefrontClient = require("../services/shopify/shopifyStorefrontClient");
|
|
8
8
|
var _shopifyEntityResolver = require("../services/shopify/shopifyEntityResolver");
|
|
9
9
|
var _transformShopifyEntity = require("../services/shopify/transformShopifyEntity");
|
|
10
|
-
// Session-level cache: entityType:entityId → resolved EntityItemData
|
|
10
|
+
// Session-level cache: entityType:entityId:variantId → resolved EntityItemData
|
|
11
11
|
const shopifyEntityCache = new Map();
|
|
12
|
-
function cacheKey(entityType, entityId) {
|
|
13
|
-
return `${entityType}:${entityId}`;
|
|
12
|
+
function cacheKey(entityType, entityId, variantId) {
|
|
13
|
+
return `${entityType}:${entityId}:${variantId || ''}`;
|
|
14
14
|
}
|
|
15
15
|
function normalizeShopifyEntityType(entityType) {
|
|
16
16
|
const lower = entityType.toLowerCase();
|
|
@@ -51,23 +51,41 @@ function extractHandleFromUrl(url) {
|
|
|
51
51
|
return withoutLeadingSlash || undefined;
|
|
52
52
|
}
|
|
53
53
|
function getShopifyLookup(entity) {
|
|
54
|
-
var _entity$data;
|
|
54
|
+
var _entity$data, _entity$data2;
|
|
55
55
|
const entityType = normalizeShopifyEntityType(entity.entityType);
|
|
56
56
|
const urlHandle = extractHandleFromUrl((_entity$data = entity.data) == null ? void 0 : _entity$data.url);
|
|
57
57
|
const entityId = (entityType === 'product' || entityType === 'collection') && urlHandle ? urlHandle : entity.entityId;
|
|
58
58
|
return {
|
|
59
59
|
entityType,
|
|
60
|
-
entityId
|
|
60
|
+
entityId,
|
|
61
|
+
variantId: (_entity$data2 = entity.data) == null ? void 0 : _entity$data2.variantId
|
|
61
62
|
};
|
|
62
63
|
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The turn owns WHICH thing to show; the live fetch owns VOLATILE FACTS about
|
|
67
|
+
* it.
|
|
68
|
+
*
|
|
69
|
+
* Only the turn saw the shopper's question, so only it knows that the brown
|
|
70
|
+
* variant was the one asked for — its `title`, `imageUrl`, `url`,
|
|
71
|
+
* `matchedOptions` and `variantId` all describe that one variant and must
|
|
72
|
+
* survive enrichment. Everything the Storefront answers with that can go stale
|
|
73
|
+
* between the turn and the render — `price`, `compareAtPrice`, `available`,
|
|
74
|
+
* `priceMin`, `priceMax` — comes from `resolved`.
|
|
75
|
+
*/
|
|
63
76
|
function mergeShopifyEntityData(existing, resolved) {
|
|
77
|
+
var _existing$matchedOpti;
|
|
64
78
|
if (!existing) {
|
|
65
79
|
return resolved;
|
|
66
80
|
}
|
|
67
81
|
return {
|
|
68
82
|
...existing,
|
|
69
83
|
...resolved,
|
|
70
|
-
url: existing.url || resolved.url
|
|
84
|
+
url: existing.url || resolved.url,
|
|
85
|
+
title: existing.title || resolved.title,
|
|
86
|
+
imageUrl: existing.imageUrl || resolved.imageUrl,
|
|
87
|
+
variantId: existing.variantId || resolved.variantId,
|
|
88
|
+
matchedOptions: (_existing$matchedOpti = existing.matchedOptions) != null && _existing$matchedOpti.length ? existing.matchedOptions : resolved.matchedOptions
|
|
71
89
|
};
|
|
72
90
|
}
|
|
73
91
|
|
|
@@ -93,7 +111,7 @@ function useResolveShopifyEntityData(entities, shopifyConfig) {
|
|
|
93
111
|
}
|
|
94
112
|
const entityIds = (0, _react.useMemo)(() => entities.map(e => {
|
|
95
113
|
const lookup = getShopifyLookup(e);
|
|
96
|
-
return `${e.entityType}:${e.entityId}:${lookup.entityType
|
|
114
|
+
return `${e.entityType}:${e.entityId}:${cacheKey(lookup.entityType, lookup.entityId, lookup.variantId)}`;
|
|
97
115
|
}).join(','), [entities]);
|
|
98
116
|
(0, _react.useEffect)(() => {
|
|
99
117
|
let ignore = false;
|
|
@@ -107,7 +125,10 @@ function useResolveShopifyEntityData(entities, shopifyConfig) {
|
|
|
107
125
|
return {
|
|
108
126
|
entity,
|
|
109
127
|
lookup,
|
|
110
|
-
key:
|
|
128
|
+
// The variant is part of the key: the cached entry carries that
|
|
129
|
+
// variant's live price, so two entities on the same product but
|
|
130
|
+
// different variants must not share it.
|
|
131
|
+
key: cacheKey(lookup.entityType, lookup.entityId, lookup.variantId)
|
|
111
132
|
};
|
|
112
133
|
});
|
|
113
134
|
|
|
@@ -141,7 +162,7 @@ function useResolveShopifyEntityData(entities, shopifyConfig) {
|
|
|
141
162
|
}) => {
|
|
142
163
|
const resolved = await (0, _shopifyEntityResolver.resolveShopifyEntity)(client, lookup.entityType, lookup.entityId, shopifyConfig);
|
|
143
164
|
if (resolved) {
|
|
144
|
-
const itemData = (0, _transformShopifyEntity.transformShopifyEntityToItemData)(resolved, lookup.entityType);
|
|
165
|
+
const itemData = (0, _transformShopifyEntity.transformShopifyEntityToItemData)(resolved, lookup.entityType, lookup.variantId);
|
|
145
166
|
shopifyEntityCache.set(key, mergeShopifyEntityData(entity.data, itemData));
|
|
146
167
|
}
|
|
147
168
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_shopifyStorefrontClient","_shopifyEntityResolver","_transformShopifyEntity","shopifyEntityCache","Map","cacheKey","entityType","entityId","normalizeShopifyEntityType","lower","toLowerCase","includes","extractHandleFromUrl","url","trimmed","trim","undefined","pathname","test","URL","withoutQuery","split","withoutLeadingSlash","replace","productsIndex","indexOf","slice","length","collectionsIndex","getShopifyLookup","entity","_entity$data","urlHandle","data","mergeShopifyEntityData","existing","resolved","useResolveShopifyEntityData","entities","shopifyConfig","resolvedMap","setResolvedMap","useState","settled","setSettled","clientRef","useRef","configKeyRef","configKey","storeDomain","apiVersion","current","ShopifyStorefrontClient","entityIds","useMemo","map","e","lookup","join","useEffect","ignore","client","entityLookups","key","toFetch","filter","has","cached","forEach","item","get","set","fetchAll","Promise","allSettled","resolveShopifyEntity","itemData","transformShopifyEntityToItemData","finalMap","enrichedEntities","loading"],"sources":["../../../src/hooks/useResolveShopifyEntityData.ts"],"sourcesContent":["import { useState, useEffect, useMemo, useRef } from 'react';\nimport { ShopifyStorefrontClient } from '../services/shopify/shopifyStorefrontClient';\nimport { resolveShopifyEntity } from '../services/shopify/shopifyEntityResolver';\nimport { transformShopifyEntityToItemData } from '../services/shopify/transformShopifyEntity';\nimport type { ShopifyStorefrontConfig } from '../services/shopify/types';\nimport type { EntityItemData } from '../component/types';\n\n// Session-level cache: entityType:entityId → resolved EntityItemData\nconst shopifyEntityCache = new Map<string, EntityItemData>();\n\nfunction cacheKey(entityType: string, entityId: string): string {\n return `${entityType}:${entityId}`;\n}\n\nfunction normalizeShopifyEntityType(entityType: string): string {\n const lower = entityType.toLowerCase();\n if (lower.includes('product')) {\n return 'product';\n }\n if (lower.includes('collection')) {\n return 'collection';\n }\n if (lower.includes('article') || lower.includes('blog')) {\n return 'article';\n }\n return entityType;\n}\n\nfunction extractHandleFromUrl(url: string | undefined): string | undefined {\n const trimmed = url?.trim();\n if (!trimmed) {\n return undefined;\n }\n\n let pathname = trimmed;\n try {\n if (/^https?:\\/\\//i.test(trimmed)) {\n pathname = new URL(trimmed).pathname;\n }\n } catch {\n pathname = trimmed;\n }\n\n const withoutQuery = pathname.split(/[?#]/)[0];\n const withoutLeadingSlash = withoutQuery.replace(/^\\/+/, '');\n const productsIndex = withoutLeadingSlash.indexOf('products/');\n if (productsIndex >= 0) {\n return withoutLeadingSlash.slice(productsIndex + 'products/'.length);\n }\n\n const collectionsIndex = withoutLeadingSlash.indexOf('collections/');\n if (collectionsIndex >= 0) {\n return withoutLeadingSlash.slice(\n collectionsIndex + 'collections/'.length,\n );\n }\n\n return withoutLeadingSlash || undefined;\n}\n\nfunction getShopifyLookup(entity: {\n entityId: string;\n entityType: string;\n data?: EntityItemData;\n}) {\n const entityType = normalizeShopifyEntityType(entity.entityType);\n const urlHandle = extractHandleFromUrl(entity.data?.url);\n const entityId =\n (entityType === 'product' || entityType === 'collection') && urlHandle\n ? urlHandle\n : entity.entityId;\n return { entityType, entityId };\n}\n\nexport function mergeShopifyEntityData(\n existing: EntityItemData | undefined,\n resolved: EntityItemData,\n): EntityItemData {\n if (!existing) {\n return resolved;\n }\n\n return {\n ...existing,\n ...resolved,\n url: existing.url || resolved.url,\n };\n}\n\n/**\n * Shopify-specific implementation of the entity resolution pattern.\n *\n * Fetches entity data from the Shopify Storefront API (tokenless) and\n * transforms it to the standard EntityItemData shape.\n *\n * Designed to be plugged into ComponentDependencies.useResolveGenericEntityData.\n */\nexport function useResolveShopifyEntityData<\n TEntity extends {\n entityId: string;\n entityUrl: string;\n entityType: string;\n data?: EntityItemData;\n },\n>(\n entities: TEntity[],\n shopifyConfig: ShopifyStorefrontConfig,\n): { enrichedEntities: TEntity[]; loading: boolean } {\n const [resolvedMap, setResolvedMap] = useState<Map<string, EntityItemData>>(\n new Map(),\n );\n const [settled, setSettled] = useState(false);\n\n // Stable client reference — recreated only when config changes\n const clientRef = useRef<ShopifyStorefrontClient | null>(null);\n const configKeyRef = useRef('');\n const configKey = `${shopifyConfig.storeDomain}|${\n shopifyConfig.apiVersion || ''\n }`;\n\n if (!clientRef.current || configKeyRef.current !== configKey) {\n clientRef.current = new ShopifyStorefrontClient(shopifyConfig);\n configKeyRef.current = configKey;\n }\n\n const entityIds = useMemo(\n () =>\n entities\n .map((e) => {\n const lookup = getShopifyLookup(e);\n return `${e.entityType}:${e.entityId}:${lookup.entityType}:${lookup.entityId}`;\n })\n .join(','),\n [entities],\n );\n\n useEffect(() => {\n let ignore = false;\n const client = clientRef.current;\n\n if (!entities.length || !client || !shopifyConfig.storeDomain) {\n setSettled(true);\n return;\n }\n\n const entityLookups = entities.map((entity) => {\n const lookup = getShopifyLookup(entity);\n return {\n entity,\n lookup,\n key: cacheKey(lookup.entityType, lookup.entityId),\n };\n });\n\n // Identify entities that need fetching. Payload data can provide the handle.\n const toFetch = entityLookups.filter(\n ({ key }) => !shopifyEntityCache.has(key),\n );\n\n // If everything is cached, resolve immediately\n if (toFetch.length === 0) {\n const cached = new Map<string, EntityItemData>();\n entityLookups.forEach(({ entity, key }) => {\n const item = shopifyEntityCache.get(key);\n if (item) {\n cached.set(entity.entityId, mergeShopifyEntityData(entity.data, item));\n }\n });\n setResolvedMap(cached);\n setSettled(true);\n return;\n }\n\n setSettled(false);\n\n const fetchAll = async () => {\n await Promise.allSettled(\n toFetch.map(async ({ entity, lookup, key }) => {\n const resolved = await resolveShopifyEntity(\n client,\n lookup.entityType,\n lookup.entityId,\n shopifyConfig,\n );\n if (resolved) {\n const itemData = transformShopifyEntityToItemData(\n resolved,\n lookup.entityType,\n );\n shopifyEntityCache.set(\n key,\n mergeShopifyEntityData(entity.data, itemData),\n );\n }\n }),\n );\n\n if (ignore) {\n return;\n }\n\n // Build the resolved map from cache\n const finalMap = new Map<string, EntityItemData>();\n entityLookups.forEach(({ entity, key }) => {\n const item = shopifyEntityCache.get(key);\n if (item) {\n finalMap.set(\n entity.entityId,\n mergeShopifyEntityData(entity.data, item),\n );\n }\n });\n\n setResolvedMap(finalMap);\n setSettled(true);\n };\n\n fetchAll();\n return () => {\n ignore = true;\n };\n }, [entityIds, shopifyConfig.storeDomain]);\n\n // Merge resolved data into entities\n const enrichedEntities = useMemo(() => {\n return entities.map((entity) => {\n const resolved = resolvedMap.get(entity.entityId);\n if (resolved) {\n return { ...entity, data: resolved };\n }\n return entity;\n });\n }, [entities, resolvedMap]);\n\n return { enrichedEntities, loading: !settled };\n}\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,wBAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAF,OAAA;AACA,IAAAG,uBAAA,GAAAH,OAAA;AAIA;AACA,MAAMI,kBAAkB,GAAG,IAAIC,GAAG,CAAyB,CAAC;AAE5D,SAASC,QAAQA,CAACC,UAAkB,EAAEC,QAAgB,EAAU;EAC9D,OAAO,GAAGD,UAAU,IAAIC,QAAQ,EAAE;AACpC;AAEA,SAASC,0BAA0BA,CAACF,UAAkB,EAAU;EAC9D,MAAMG,KAAK,GAAGH,UAAU,CAACI,WAAW,CAAC,CAAC;EACtC,IAAID,KAAK,CAACE,QAAQ,CAAC,SAAS,CAAC,EAAE;IAC7B,OAAO,SAAS;EAClB;EACA,IAAIF,KAAK,CAACE,QAAQ,CAAC,YAAY,CAAC,EAAE;IAChC,OAAO,YAAY;EACrB;EACA,IAAIF,KAAK,CAACE,QAAQ,CAAC,SAAS,CAAC,IAAIF,KAAK,CAACE,QAAQ,CAAC,MAAM,CAAC,EAAE;IACvD,OAAO,SAAS;EAClB;EACA,OAAOL,UAAU;AACnB;AAEA,SAASM,oBAAoBA,CAACC,GAAuB,EAAsB;EACzE,MAAMC,OAAO,GAAGD,GAAG,oBAAHA,GAAG,CAAEE,IAAI,CAAC,CAAC;EAC3B,IAAI,CAACD,OAAO,EAAE;IACZ,OAAOE,SAAS;EAClB;EAEA,IAAIC,QAAQ,GAAGH,OAAO;EACtB,IAAI;IACF,IAAI,eAAe,CAACI,IAAI,CAACJ,OAAO,CAAC,EAAE;MACjCG,QAAQ,GAAG,IAAIE,GAAG,CAACL,OAAO,CAAC,CAACG,QAAQ;IACtC;EACF,CAAC,CAAC,MAAM;IACNA,QAAQ,GAAGH,OAAO;EACpB;EAEA,MAAMM,YAAY,GAAGH,QAAQ,CAAC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AAEG;QAAS,CAAC;MACtC;MACA,OAAON,MAAM;IACf,CAAC,CAAC;EACJ,CAAC,EAAE,CAACQ,QAAQ,EAAEE,WAAW,CAAC,CAAC;EAE3B,OAAO;IAAEuC,gBAAgB;IAAEC,OAAO,EAAE,CAACrC;EAAQ,CAAC;AAChD","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_react","require","_shopifyStorefrontClient","_shopifyEntityResolver","_transformShopifyEntity","shopifyEntityCache","Map","cacheKey","entityType","entityId","variantId","normalizeShopifyEntityType","lower","toLowerCase","includes","extractHandleFromUrl","url","trimmed","trim","undefined","pathname","test","URL","withoutQuery","split","withoutLeadingSlash","replace","productsIndex","indexOf","slice","length","collectionsIndex","getShopifyLookup","entity","_entity$data","_entity$data2","urlHandle","data","mergeShopifyEntityData","existing","resolved","_existing$matchedOpti","title","imageUrl","matchedOptions","useResolveShopifyEntityData","entities","shopifyConfig","resolvedMap","setResolvedMap","useState","settled","setSettled","clientRef","useRef","configKeyRef","configKey","storeDomain","apiVersion","current","ShopifyStorefrontClient","entityIds","useMemo","map","e","lookup","join","useEffect","ignore","client","entityLookups","key","toFetch","filter","has","cached","forEach","item","get","set","fetchAll","Promise","allSettled","resolveShopifyEntity","itemData","transformShopifyEntityToItemData","finalMap","enrichedEntities","loading"],"sources":["../../../src/hooks/useResolveShopifyEntityData.ts"],"sourcesContent":["import { useState, useEffect, useMemo, useRef } from 'react';\nimport { ShopifyStorefrontClient } from '../services/shopify/shopifyStorefrontClient';\nimport { resolveShopifyEntity } from '../services/shopify/shopifyEntityResolver';\nimport { transformShopifyEntityToItemData } from '../services/shopify/transformShopifyEntity';\nimport type { ShopifyStorefrontConfig } from '../services/shopify/types';\nimport type { EntityItemData } from '../component/types';\n\n// Session-level cache: entityType:entityId:variantId → resolved EntityItemData\nconst shopifyEntityCache = new Map<string, EntityItemData>();\n\nfunction cacheKey(\n entityType: string,\n entityId: string,\n variantId?: string,\n): string {\n return `${entityType}:${entityId}:${variantId || ''}`;\n}\n\nfunction normalizeShopifyEntityType(entityType: string): string {\n const lower = entityType.toLowerCase();\n if (lower.includes('product')) {\n return 'product';\n }\n if (lower.includes('collection')) {\n return 'collection';\n }\n if (lower.includes('article') || lower.includes('blog')) {\n return 'article';\n }\n return entityType;\n}\n\nfunction extractHandleFromUrl(url: string | undefined): string | undefined {\n const trimmed = url?.trim();\n if (!trimmed) {\n return undefined;\n }\n\n let pathname = trimmed;\n try {\n if (/^https?:\\/\\//i.test(trimmed)) {\n pathname = new URL(trimmed).pathname;\n }\n } catch {\n pathname = trimmed;\n }\n\n const withoutQuery = pathname.split(/[?#]/)[0];\n const withoutLeadingSlash = withoutQuery.replace(/^\\/+/, '');\n const productsIndex = withoutLeadingSlash.indexOf('products/');\n if (productsIndex >= 0) {\n return withoutLeadingSlash.slice(productsIndex + 'products/'.length);\n }\n\n const collectionsIndex = withoutLeadingSlash.indexOf('collections/');\n if (collectionsIndex >= 0) {\n return withoutLeadingSlash.slice(\n collectionsIndex + 'collections/'.length,\n );\n }\n\n return withoutLeadingSlash || undefined;\n}\n\nfunction getShopifyLookup(entity: {\n entityId: string;\n entityType: string;\n data?: EntityItemData;\n}) {\n const entityType = normalizeShopifyEntityType(entity.entityType);\n const urlHandle = extractHandleFromUrl(entity.data?.url);\n const entityId =\n (entityType === 'product' || entityType === 'collection') && urlHandle\n ? urlHandle\n : entity.entityId;\n return { entityType, entityId, variantId: entity.data?.variantId };\n}\n\n/**\n * The turn owns WHICH thing to show; the live fetch owns VOLATILE FACTS about\n * it.\n *\n * Only the turn saw the shopper's question, so only it knows that the brown\n * variant was the one asked for — its `title`, `imageUrl`, `url`,\n * `matchedOptions` and `variantId` all describe that one variant and must\n * survive enrichment. Everything the Storefront answers with that can go stale\n * between the turn and the render — `price`, `compareAtPrice`, `available`,\n * `priceMin`, `priceMax` — comes from `resolved`.\n */\nexport function mergeShopifyEntityData(\n existing: EntityItemData | undefined,\n resolved: EntityItemData,\n): EntityItemData {\n if (!existing) {\n return resolved;\n }\n\n return {\n ...existing,\n ...resolved,\n url: existing.url || resolved.url,\n title: existing.title || resolved.title,\n imageUrl: existing.imageUrl || resolved.imageUrl,\n variantId: existing.variantId || resolved.variantId,\n matchedOptions: existing.matchedOptions?.length\n ? existing.matchedOptions\n : resolved.matchedOptions,\n };\n}\n\n/**\n * Shopify-specific implementation of the entity resolution pattern.\n *\n * Fetches entity data from the Shopify Storefront API (tokenless) and\n * transforms it to the standard EntityItemData shape.\n *\n * Designed to be plugged into ComponentDependencies.useResolveGenericEntityData.\n */\nexport function useResolveShopifyEntityData<\n TEntity extends {\n entityId: string;\n entityUrl: string;\n entityType: string;\n data?: EntityItemData;\n },\n>(\n entities: TEntity[],\n shopifyConfig: ShopifyStorefrontConfig,\n): { enrichedEntities: TEntity[]; loading: boolean } {\n const [resolvedMap, setResolvedMap] = useState<Map<string, EntityItemData>>(\n new Map(),\n );\n const [settled, setSettled] = useState(false);\n\n // Stable client reference — recreated only when config changes\n const clientRef = useRef<ShopifyStorefrontClient | null>(null);\n const configKeyRef = useRef('');\n const configKey = `${shopifyConfig.storeDomain}|${\n shopifyConfig.apiVersion || ''\n }`;\n\n if (!clientRef.current || configKeyRef.current !== configKey) {\n clientRef.current = new ShopifyStorefrontClient(shopifyConfig);\n configKeyRef.current = configKey;\n }\n\n const entityIds = useMemo(\n () =>\n entities\n .map((e) => {\n const lookup = getShopifyLookup(e);\n return `${e.entityType}:${e.entityId}:${cacheKey(\n lookup.entityType,\n lookup.entityId,\n lookup.variantId,\n )}`;\n })\n .join(','),\n [entities],\n );\n\n useEffect(() => {\n let ignore = false;\n const client = clientRef.current;\n\n if (!entities.length || !client || !shopifyConfig.storeDomain) {\n setSettled(true);\n return;\n }\n\n const entityLookups = entities.map((entity) => {\n const lookup = getShopifyLookup(entity);\n return {\n entity,\n lookup,\n // The variant is part of the key: the cached entry carries that\n // variant's live price, so two entities on the same product but\n // different variants must not share it.\n key: cacheKey(lookup.entityType, lookup.entityId, lookup.variantId),\n };\n });\n\n // Identify entities that need fetching. Payload data can provide the handle.\n const toFetch = entityLookups.filter(\n ({ key }) => !shopifyEntityCache.has(key),\n );\n\n // If everything is cached, resolve immediately\n if (toFetch.length === 0) {\n const cached = new Map<string, EntityItemData>();\n entityLookups.forEach(({ entity, key }) => {\n const item = shopifyEntityCache.get(key);\n if (item) {\n cached.set(entity.entityId, mergeShopifyEntityData(entity.data, item));\n }\n });\n setResolvedMap(cached);\n setSettled(true);\n return;\n }\n\n setSettled(false);\n\n const fetchAll = async () => {\n await Promise.allSettled(\n toFetch.map(async ({ entity, lookup, key }) => {\n const resolved = await resolveShopifyEntity(\n client,\n lookup.entityType,\n lookup.entityId,\n shopifyConfig,\n );\n if (resolved) {\n const itemData = transformShopifyEntityToItemData(\n resolved,\n lookup.entityType,\n lookup.variantId,\n );\n shopifyEntityCache.set(\n key,\n mergeShopifyEntityData(entity.data, itemData),\n );\n }\n }),\n );\n\n if (ignore) {\n return;\n }\n\n // Build the resolved map from cache\n const finalMap = new Map<string, EntityItemData>();\n entityLookups.forEach(({ entity, key }) => {\n const item = shopifyEntityCache.get(key);\n if (item) {\n finalMap.set(\n entity.entityId,\n mergeShopifyEntityData(entity.data, item),\n );\n }\n });\n\n setResolvedMap(finalMap);\n setSettled(true);\n };\n\n fetchAll();\n return () => {\n ignore = true;\n };\n }, [entityIds, shopifyConfig.storeDomain]);\n\n // Merge resolved data into entities\n const enrichedEntities = useMemo(() => {\n return entities.map((entity) => {\n const resolved = resolvedMap.get(entity.entityId);\n if (resolved) {\n return { ...entity, data: resolved };\n }\n return entity;\n });\n }, [entities, resolvedMap]);\n\n return { enrichedEntities, loading: !settled };\n}\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,wBAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAF,OAAA;AACA,IAAAG,uBAAA,GAAAH,OAAA;AAIA;AACA,MAAMI,kBAAkB,GAAG,IAAIC,GAAG,CAAyB,CAAC;AAE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,OAAO,MAAM;MACXZ,MAAM,GAAG,IAAI;IACf,CAAC;EACH,CAAC,EAAE,CAACP,SAAS,EAAEd,aAAa,CAACU,WAAW,CAAC,CAAC;;EAE1C;EACA,MAAM8B,gBAAgB,GAAG,IAAAzB,cAAO,EAAC,MAAM;IACrC,OAAOhB,QAAQ,CAACiB,GAAG,CAAE9B,MAAM,IAAK;MAC9B,MAAMO,QAAQ,GAAGQ,WAAW,CAAC8B,GAAG,CAAC7C,MAAM,CAACxB,QAAQ,CAAC;MACjD,IAAI+B,QAAQ,EAAE;QACZ,OAAO;UAAE,GAAGP,MAAM;UAAEI,IAAI,EAAEG;QAAS,CAAC;MACtC;MACA,OAAOP,MAAM;IACf,CAAC,CAAC;EACJ,CAAC,EAAE,CAACa,QAAQ,EAAEE,WAAW,CAAC,CAAC;EAE3B,OAAO;IAAEuC,gBAAgB;IAAEC,OAAO,EAAE,CAACrC;EAAQ,CAAC;AAChD","ignoreList":[]}
|
|
@@ -71,8 +71,25 @@ function getCompareAtPrice(product) {
|
|
|
71
71
|
}
|
|
72
72
|
return formatPrice(compare);
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The live entry for the variant the turn resolved, if the store still has it.
|
|
77
|
+
* Both sides carry the bare numeric id — `extractVariants` strips the
|
|
78
|
+
* `gid://shopify/ProductVariant/` prefix, and the turn never adds one.
|
|
79
|
+
*/
|
|
80
|
+
function findLiveVariant(variants, variantId) {
|
|
81
|
+
if (!variantId) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
return variants == null ? void 0 : variants.find(variant => variant.variantId === variantId);
|
|
85
|
+
}
|
|
86
|
+
function transformShopifyProduct(product, variantId) {
|
|
75
87
|
var _product$featuredImag, _product$options;
|
|
88
|
+
const variants = extractVariants(product);
|
|
89
|
+
// The turn decided WHICH variant to show; the live fetch is here for what is
|
|
90
|
+
// true about it right now. With no matched variant — or one the store has
|
|
91
|
+
// since dropped — the product-level range is still the only answer we have.
|
|
92
|
+
const matchedVariant = findLiveVariant(variants, variantId);
|
|
76
93
|
return {
|
|
77
94
|
url: product.onlineStoreUrl || '',
|
|
78
95
|
title: product.title,
|
|
@@ -81,10 +98,14 @@ function transformShopifyProduct(product) {
|
|
|
81
98
|
imageUrl: (_product$featuredImag = product.featuredImage) == null ? void 0 : _product$featuredImag.url,
|
|
82
99
|
secondaryImageUrl: getSecondaryImage(product),
|
|
83
100
|
vendor: product.vendor,
|
|
84
|
-
price: formatPrice(product.priceRange.minVariantPrice),
|
|
85
|
-
|
|
101
|
+
price: (matchedVariant == null ? void 0 : matchedVariant.price) || formatPrice(product.priceRange.minVariantPrice),
|
|
102
|
+
// Keyed on the variant, not on its value: an unmatched product falls back
|
|
103
|
+
// to the product-level compare-at, but a matched variant that is simply
|
|
104
|
+
// not on sale must not inherit one and print a false strikethrough.
|
|
105
|
+
compareAtPrice: matchedVariant ? matchedVariant.compareAtPrice : getCompareAtPrice(product),
|
|
106
|
+
available: matchedVariant == null ? void 0 : matchedVariant.available,
|
|
86
107
|
sizes: extractSizes(product),
|
|
87
|
-
variants
|
|
108
|
+
variants,
|
|
88
109
|
allImages: getAllImages(product),
|
|
89
110
|
options: (_product$options = product.options) != null && _product$options.length ? product.options : undefined,
|
|
90
111
|
tags: product.tags.length ? product.tags : undefined
|
|
@@ -118,10 +139,10 @@ function transformShopifyArticle(article) {
|
|
|
118
139
|
* Transform any resolved Shopify entity to the standard EntityItemData shape.
|
|
119
140
|
* Detects the entity type by checking for type-specific fields.
|
|
120
141
|
*/
|
|
121
|
-
function transformShopifyEntityToItemData(entity, entityType) {
|
|
142
|
+
function transformShopifyEntityToItemData(entity, entityType, variantId) {
|
|
122
143
|
switch (entityType.toLowerCase()) {
|
|
123
144
|
case 'product':
|
|
124
|
-
return transformShopifyProduct(entity);
|
|
145
|
+
return transformShopifyProduct(entity, variantId);
|
|
125
146
|
case 'collection':
|
|
126
147
|
return transformShopifyCollection(entity);
|
|
127
148
|
case 'article':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["formatShopifyDate","isoDate","date","Date","isNaN","getTime","undefined","day","getDate","month","toLocaleString","year","getFullYear","formatPrice","money","amount","parseFloat","formatted","toFixed","currencyCode","extractSizes","product","sizes","variants","edges","flatMap","e","node","selectedOptions","filter","o","name","toLowerCase","map","value","unique","Set","length","extractVariants","sizeOption","find","numericId","id","replace","label","title","variantId","available","availableForSale","price","compareAtPrice","getSecondaryImage","images","url","getAllImages","getCompareAtPrice","_product$compareAtPri","compare","compareAtPriceRange","minVariantPrice","min","priceRange","transformShopifyProduct","_product$featuredImag","_product$options","onlineStoreUrl","type","description","imageUrl","featuredImage","secondaryImageUrl","vendor","allImages","options","tags","transformShopifyCollection","collection","_collection$image","image","transformShopifyArticle","article","_article$image","_article$authorV","excerpt","publishDate","publishedAt","author","authorV2","transformShopifyEntityToItemData","entity","entityType"],"sources":["../../../../src/services/shopify/transformShopifyEntity.ts"],"sourcesContent":["import type { EntityItemData } from '../../component/types';\nimport type {\n ShopifyProduct,\n ShopifyCollection,\n ShopifyArticle,\n} from './types';\n\nfunction formatShopifyDate(isoDate: string): string | undefined {\n const date = new Date(isoDate);\n if (isNaN(date.getTime())) {\n return undefined;\n }\n const day = date.getDate();\n const month = date.toLocaleString('en-US', { month: 'short' });\n const year = date.getFullYear();\n return `${day} ${month} ${year}`;\n}\n\nfunction formatPrice(\n money: ShopifyProduct['priceRange']['minVariantPrice'],\n): string {\n const amount = parseFloat(money.amount);\n const formatted = amount.toFixed(2);\n return `${formatted} ${money.currencyCode}`;\n}\n\nfunction extractSizes(product: ShopifyProduct): string[] | undefined {\n const sizes = product.variants.edges.flatMap((e) =>\n e.node.selectedOptions\n .filter((o) => o.name.toLowerCase() === 'size')\n .map((o) => o.value),\n );\n const unique = [...new Set(sizes)];\n return unique.length > 0 ? unique : undefined;\n}\n\n/**\n * Extract variant ID → size label mapping for add-to-cart.\n * Shopify global IDs look like \"gid://shopify/ProductVariant/12345\" —\n * we extract just the numeric part for the Ajax API.\n */\nfunction extractVariants(product: ShopifyProduct): EntityItemData['variants'] {\n const variants = product.variants.edges.map((e) => {\n const sizeOption = e.node.selectedOptions.find(\n (o) => o.name.toLowerCase() === 'size',\n );\n const numericId = e.node.id.replace(\n /^gid:\\/\\/shopify\\/ProductVariant\\//,\n '',\n );\n return {\n label: sizeOption?.value || e.node.title,\n variantId: numericId,\n available: e.node.availableForSale,\n selectedOptions: e.node.selectedOptions.map((o) => ({\n name: o.name,\n value: o.value,\n })),\n price: formatPrice(e.node.price),\n compareAtPrice: e.node.compareAtPrice\n ? formatPrice(e.node.compareAtPrice)\n : undefined,\n };\n });\n return variants.length > 0 ? variants : undefined;\n}\n\nfunction getSecondaryImage(product: ShopifyProduct): string | undefined {\n const images = product.images.edges.map((e) => e.node.url);\n return images.length > 1 ? images[1] : undefined;\n}\n\nfunction getAllImages(product: ShopifyProduct): string[] | undefined {\n const images = product.images.edges.map((e) => e.node.url);\n return images.length > 0 ? images : undefined;\n}\n\nfunction getCompareAtPrice(product: ShopifyProduct): string | undefined {\n const compare = product.compareAtPriceRange?.minVariantPrice;\n if (!compare) {\n return undefined;\n }\n const min = product.priceRange.minVariantPrice;\n if (parseFloat(compare.amount) <= parseFloat(min.amount)) {\n return undefined;\n }\n return formatPrice(compare);\n}\n\nexport function transformShopifyProduct(\n product: ShopifyProduct,\n): EntityItemData {\n return {\n url: product.onlineStoreUrl || '',\n title: product.title,\n type: 'product',\n description: product.description,\n imageUrl: product.featuredImage?.url,\n secondaryImageUrl: getSecondaryImage(product),\n vendor: product.vendor,\n price: formatPrice(product.priceRange.minVariantPrice),\n compareAtPrice: getCompareAtPrice(product),\n sizes: extractSizes(product),\n variants: extractVariants(product),\n allImages: getAllImages(product),\n options: product.options?.length ? product.options : undefined,\n tags: product.tags.length ? product.tags : undefined,\n };\n}\n\nexport function transformShopifyCollection(\n collection: ShopifyCollection,\n): EntityItemData {\n return {\n url: collection.onlineStoreUrl || '',\n title: collection.title,\n type: 'collection',\n description: collection.description,\n imageUrl: collection.image?.url,\n };\n}\n\nexport function transformShopifyArticle(\n article: ShopifyArticle,\n): EntityItemData {\n return {\n url: article.onlineStoreUrl || '',\n title: article.title,\n type: 'article',\n description: article.excerpt || undefined,\n imageUrl: article.image?.url,\n publishDate: formatShopifyDate(article.publishedAt),\n author: article.authorV2?.name || undefined,\n tags: article.tags.length ? article.tags : undefined,\n };\n}\n\n/**\n * Transform any resolved Shopify entity to the standard EntityItemData shape.\n * Detects the entity type by checking for type-specific fields.\n */\nexport function transformShopifyEntityToItemData(\n entity: ShopifyProduct | ShopifyCollection | ShopifyArticle,\n entityType: string,\n): EntityItemData {\n switch (entityType.toLowerCase()) {\n case 'product':\n return transformShopifyProduct(entity as ShopifyProduct);\n case 'collection':\n return transformShopifyCollection(entity as ShopifyCollection);\n case 'article':\n return transformShopifyArticle(entity as ShopifyArticle);\n default:\n return {\n url: '',\n title: (entity as { title?: string }).title || '',\n type: entityType,\n };\n }\n}\n"],"mappings":";;;;;;;AAOA,SAASA,iBAAiBA,CAACC,OAAe,EAAsB;EAC9D,MAAMC,IAAI,GAAG,IAAIC,IAAI,CAACF,OAAO,CAAC;EAC9B,IAAIG,KAAK,CAACF,IAAI,CAACG,OAAO,CAAC,CAAC,CAAC,EAAE;IACzB,OAAOC,SAAS;EAClB;EACA,MAAMC,GAAG,GAAGL,IAAI,CAACM,OAAO,CAAC,CAAC;EAC1B,MAAMC,KAAK,GAAGP,IAAI,CAACQ,cAAc,CAAC,OAAO,EAAE;IAAED,KAAK,EAAE;EAAQ,CAAC,CAAC;EAC9D,MAAME,IAAI,GAAGT,IAAI,CAACU,WAAW,CAAC,CAAC;EAC/B,OAAO,GAAGL,GAAG,IAAIE,KAAK,IAAIE,IAAI,EAAE;AAClC;AAEA,SAASE,WAAWA,CAClBC,KAAsD,EAC9C;EACR,MAAMC,MAAM,GAAGC,UAAU,CAACF,KAAK,CAACC,MAAM,CAAC;EACvC,MAA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AK,IAAI,EAAE;QACjDqB,IAAI,EAAEwB;MACR,CAAC;EACL;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["formatShopifyDate","isoDate","date","Date","isNaN","getTime","undefined","day","getDate","month","toLocaleString","year","getFullYear","formatPrice","money","amount","parseFloat","formatted","toFixed","currencyCode","extractSizes","product","sizes","variants","edges","flatMap","e","node","selectedOptions","filter","o","name","toLowerCase","map","value","unique","Set","length","extractVariants","sizeOption","find","numericId","id","replace","label","title","variantId","available","availableForSale","price","compareAtPrice","getSecondaryImage","images","url","getAllImages","getCompareAtPrice","_product$compareAtPri","compare","compareAtPriceRange","minVariantPrice","min","priceRange","findLiveVariant","variant","transformShopifyProduct","_product$featuredImag","_product$options","matchedVariant","onlineStoreUrl","type","description","imageUrl","featuredImage","secondaryImageUrl","vendor","allImages","options","tags","transformShopifyCollection","collection","_collection$image","image","transformShopifyArticle","article","_article$image","_article$authorV","excerpt","publishDate","publishedAt","author","authorV2","transformShopifyEntityToItemData","entity","entityType"],"sources":["../../../../src/services/shopify/transformShopifyEntity.ts"],"sourcesContent":["import type { EntityItemData } from '../../component/types';\nimport type {\n ShopifyProduct,\n ShopifyCollection,\n ShopifyArticle,\n} from './types';\n\nfunction formatShopifyDate(isoDate: string): string | undefined {\n const date = new Date(isoDate);\n if (isNaN(date.getTime())) {\n return undefined;\n }\n const day = date.getDate();\n const month = date.toLocaleString('en-US', { month: 'short' });\n const year = date.getFullYear();\n return `${day} ${month} ${year}`;\n}\n\nfunction formatPrice(\n money: ShopifyProduct['priceRange']['minVariantPrice'],\n): string {\n const amount = parseFloat(money.amount);\n const formatted = amount.toFixed(2);\n return `${formatted} ${money.currencyCode}`;\n}\n\nfunction extractSizes(product: ShopifyProduct): string[] | undefined {\n const sizes = product.variants.edges.flatMap((e) =>\n e.node.selectedOptions\n .filter((o) => o.name.toLowerCase() === 'size')\n .map((o) => o.value),\n );\n const unique = [...new Set(sizes)];\n return unique.length > 0 ? unique : undefined;\n}\n\n/**\n * Extract variant ID → size label mapping for add-to-cart.\n * Shopify global IDs look like \"gid://shopify/ProductVariant/12345\" —\n * we extract just the numeric part for the Ajax API.\n */\nfunction extractVariants(product: ShopifyProduct): EntityItemData['variants'] {\n const variants = product.variants.edges.map((e) => {\n const sizeOption = e.node.selectedOptions.find(\n (o) => o.name.toLowerCase() === 'size',\n );\n const numericId = e.node.id.replace(\n /^gid:\\/\\/shopify\\/ProductVariant\\//,\n '',\n );\n return {\n label: sizeOption?.value || e.node.title,\n variantId: numericId,\n available: e.node.availableForSale,\n selectedOptions: e.node.selectedOptions.map((o) => ({\n name: o.name,\n value: o.value,\n })),\n price: formatPrice(e.node.price),\n compareAtPrice: e.node.compareAtPrice\n ? formatPrice(e.node.compareAtPrice)\n : undefined,\n };\n });\n return variants.length > 0 ? variants : undefined;\n}\n\nfunction getSecondaryImage(product: ShopifyProduct): string | undefined {\n const images = product.images.edges.map((e) => e.node.url);\n return images.length > 1 ? images[1] : undefined;\n}\n\nfunction getAllImages(product: ShopifyProduct): string[] | undefined {\n const images = product.images.edges.map((e) => e.node.url);\n return images.length > 0 ? images : undefined;\n}\n\nfunction getCompareAtPrice(product: ShopifyProduct): string | undefined {\n const compare = product.compareAtPriceRange?.minVariantPrice;\n if (!compare) {\n return undefined;\n }\n const min = product.priceRange.minVariantPrice;\n if (parseFloat(compare.amount) <= parseFloat(min.amount)) {\n return undefined;\n }\n return formatPrice(compare);\n}\n\n/**\n * The live entry for the variant the turn resolved, if the store still has it.\n * Both sides carry the bare numeric id — `extractVariants` strips the\n * `gid://shopify/ProductVariant/` prefix, and the turn never adds one.\n */\nfunction findLiveVariant(\n variants: EntityItemData['variants'],\n variantId: string | undefined,\n): NonNullable<EntityItemData['variants']>[number] | undefined {\n if (!variantId) {\n return undefined;\n }\n return variants?.find((variant) => variant.variantId === variantId);\n}\n\nexport function transformShopifyProduct(\n product: ShopifyProduct,\n variantId?: string,\n): EntityItemData {\n const variants = extractVariants(product);\n // The turn decided WHICH variant to show; the live fetch is here for what is\n // true about it right now. With no matched variant — or one the store has\n // since dropped — the product-level range is still the only answer we have.\n const matchedVariant = findLiveVariant(variants, variantId);\n\n return {\n url: product.onlineStoreUrl || '',\n title: product.title,\n type: 'product',\n description: product.description,\n imageUrl: product.featuredImage?.url,\n secondaryImageUrl: getSecondaryImage(product),\n vendor: product.vendor,\n price:\n matchedVariant?.price || formatPrice(product.priceRange.minVariantPrice),\n // Keyed on the variant, not on its value: an unmatched product falls back\n // to the product-level compare-at, but a matched variant that is simply\n // not on sale must not inherit one and print a false strikethrough.\n compareAtPrice: matchedVariant\n ? matchedVariant.compareAtPrice\n : getCompareAtPrice(product),\n available: matchedVariant?.available,\n sizes: extractSizes(product),\n variants,\n allImages: getAllImages(product),\n options: product.options?.length ? product.options : undefined,\n tags: product.tags.length ? product.tags : undefined,\n };\n}\n\nexport function transformShopifyCollection(\n collection: ShopifyCollection,\n): EntityItemData {\n return {\n url: collection.onlineStoreUrl || '',\n title: collection.title,\n type: 'collection',\n description: collection.description,\n imageUrl: collection.image?.url,\n };\n}\n\nexport function transformShopifyArticle(\n article: ShopifyArticle,\n): EntityItemData {\n return {\n url: article.onlineStoreUrl || '',\n title: article.title,\n type: 'article',\n description: article.excerpt || undefined,\n imageUrl: article.image?.url,\n publishDate: formatShopifyDate(article.publishedAt),\n author: article.authorV2?.name || undefined,\n tags: article.tags.length ? article.tags : undefined,\n };\n}\n\n/**\n * Transform any resolved Shopify entity to the standard EntityItemData shape.\n * Detects the entity type by checking for type-specific fields.\n */\nexport function transformShopifyEntityToItemData(\n entity: ShopifyProduct | ShopifyCollection | ShopifyArticle,\n entityType: string,\n variantId?: string,\n): EntityItemData {\n switch (entityType.toLowerCase()) {\n case 'product':\n return transformShopifyProduct(entity as ShopifyProduct, variantId);\n case 'collection':\n return transformShopifyCollection(entity as ShopifyCollection);\n case 'article':\n return transformShopifyArticle(entity as ShopifyArticle);\n default:\n return {\n url: '',\n title: (entity as { title?: string }).title || '',\n type: entityType,\n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ACL;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../../src/component/types.ts"],"sourcesContent":["import type { FC } from 'react';\nimport type { Callout } from '../types/callout';\n\n/** Props extracted from markdown (base layer). */\nexport interface BaseCompProps {}\nexport interface SlotCompProps extends BaseCompProps {\n callout?: Callout;\n}\n\nexport interface SectionCompProps extends BaseCompProps {\n callout?: Callout;\n}\n\n/** Section props with a slot. TSlot enforces which slot component this section accepts. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface SectionCompPropsWithSlot<TSlot extends FC<any> = FC<any>>\n extends SectionCompProps {\n slot?: TSlot;\n}\n\n// ----------------------\n// Base Components\n// ----------------------\n\nexport interface TextCompProps extends BaseCompProps {\n content: string;\n variant?: 'h1' | 'h2' | 'body' | 'caption';\n}\n\nexport interface ButtonCompProps extends BaseCompProps {\n label: string;\n variant?: 'primary' | 'secondary' | 'ghost';\n onClick?: string;\n}\n\nexport interface ImageCompProps extends BaseCompProps {\n src: string;\n alt: string;\n ratio?: '16:9' | '4:3' | '1:1' | '9:16' | '3:4';\n}\n\nexport interface BadgeCompProps extends BaseCompProps {\n label: string;\n color?: 'primary' | 'secondary' | 'success' | 'warning' | 'error';\n}\n\n// ----------------------\n// Hero Button (aligned to HeroSection1Button)\n// ----------------------\n\nexport interface HeroButton {\n id: string;\n text: string;\n variant?: 'primary' | 'secondary';\n onClick?: string;\n}\n\n// ----------------------\n// Slot Components\n// ----------------------\n\nexport interface KpiItemCompProps extends SlotCompProps {\n title: string;\n description: string;\n icon?: string;\n}\n\n/** Feature item — aligned to web50-server-ui Feature interface */\nexport interface FeatureItemCompProps extends SlotCompProps {\n title?: string;\n description?: string;\n icon?: string;\n}\n\n/** Feature card — aligned to web50-server-ui FeatureCard */\nexport interface FeatureCardCompProps extends SlotCompProps {\n title: string;\n description: string;\n imageUrl?: string;\n imageFromText?: boolean;\n linkText?: string;\n linkHref?: string;\n callout?: Callout;\n}\n\n/** Resolved entity data (populated at runtime via useResolveGenericEntityData) */\nexport interface EntityItemData {\n url: string;\n title: string;\n type: string;\n description?: string;\n excerpt?: string;\n imageUrl?: string;\n date?: string;\n publishDate?: string;\n author?: string;\n cmsItemId?: string;\n usage?: number;\n tags?: string[];\n /** Product vendor / brand name (e.g. \"HOKA\") */\n vendor?: string;\n /**\n * The `{ name, value }` pairs of the one variant a search matched, in the\n * store's own order. Present only when retrieval resolved the product down\n * to a single variant. The names are the store's own, so read this by\n * iterating it — never by looking a name up.\n */\n matchedOptions?: { name: string; value: string }[];\n /** Formatted lowest price across the product's variants (e.g. \"$107.95\") */\n priceMin?: string;\n /** Formatted highest price across the product's variants */\n priceMax?: string;\n /** Formatted price string (e.g. \"542.00 NIS\") */\n price?: string;\n /** Secondary product image URL — shown on hover */\n secondaryImageUrl?: string;\n /** Available sizes for the product */\n sizes?: string[];\n /** Original price before discount (formatted, e.g. \"494.00 NIS\") — shown with strikethrough */\n compareAtPrice?: string;\n /** Discount percentage (e.g. \"30% OFF\") */\n discountPercent?: string;\n /** Product variants with IDs and availability — used for add-to-cart and size display */\n variants?: {\n label: string;\n variantId: string;\n available: boolean;\n selectedOptions?: { name: string; value: string }[];\n price?: string;\n compareAtPrice?: string;\n }[];\n /** All product image URLs (not just featured + secondary) */\n allImages?: string[];\n /** Product option groups (e.g. Size, Color) with their available values */\n options?: { name: string; values: string[] }[];\n}\n\n/** Single entity item within an entity section */\nexport interface EntityItem {\n entityId: string;\n linkText?: string;\n entityType: string;\n entityUrl: string;\n description?: string;\n imageUrl?: string;\n /** Per-item callout from a blockquote inside the list item */\n callout?: Callout;\n /** Resolved at runtime via useResolveGenericEntityData hook; not produced by parse() */\n data?: EntityItemData;\n}\n\n// ---------------------------------------------------------------------------\n// Deprecated aliases — kept for seed-components compilation\n// ---------------------------------------------------------------------------\n/** @deprecated Use EntityItemData */\nexport type GenericEntityData = EntityItemData;\n/** @deprecated Use EntityItemData */\nexport type SolutionEntityData = EntityItemData;\n/** @deprecated Use EntityItemData */\nexport type BlogEntityData = EntityItemData;\n/** @deprecated Use EntityItem */\nexport type GenericEntityCompProps = EntityItem;\n\n/** Comparison row — aligned to web50-server-ui ComparisonRow */\nexport interface ComparisonRow {\n feature: string;\n iconHint?: string;\n values: (boolean | string)[];\n}\n\nexport interface ComparisonColumn {\n label: string;\n href?: string;\n entityId?: string;\n entityType?: string;\n}\n\n/** @deprecated Use Callout from types/callout instead */\nexport interface AiNarrativeCompProps extends SlotCompProps {\n content: string;\n}\n\n// ----------------------\n// Section Components\n// ----------------------\n\n/** Hero — aligned to HeroSection1Props */\nexport interface HeroCompProps extends SectionCompProps {\n headline: string;\n badge?: string | { text: string; showIndicator?: boolean };\n content?: string;\n buttons?: HeroButton[];\n image?: string;\n trailingList?: string;\n leadingQuote?: string;\n}\n\n/**\n * Entity hero — a hero section whose body carries one or more web5 entity\n * links (`web5://entity/...`). Shares the hero framing fields with\n * {@link HeroCompProps} but, instead of CTA buttons, surfaces the entities as\n * resolvable {@link EntityItem}s for rich rendering.\n */\nexport interface HeroEntityCompProps extends SectionCompProps {\n headline: string;\n badge?: string | { text: string; showIndicator?: boolean };\n content?: string;\n image?: string;\n leadingQuote?: string;\n items: EntityItem[];\n}\n\n/** KPI — aligned to KpiSectionProps */\nexport interface KpiCompProps\n extends SectionCompPropsWithSlot<KpiItemComponent> {\n title: string;\n items: KpiItemCompProps[];\n}\n\n/** Feature cards — aligned to FeatureCardsSectionProps */\nexport interface FeatureCardsCompProps extends SectionCompProps {\n cards: FeatureCardCompProps[];\n}\n\n/** Unified entity section — replaces EntityCompProps, SolutionEntityCompProps, BlogEntityCompProps */\nexport interface EntityCompProps extends SectionCompProps {\n title: string;\n description?: string;\n items: EntityItem[];\n}\n\n/** Comparison — aligned to ComparisonSection1Props */\nexport interface ComparisonCompProps extends SectionCompProps {\n title: string;\n description?: string;\n columnLabels: string[];\n columns?: ComparisonColumn[];\n rows: ComparisonRow[];\n featureColumnLabel?: string;\n ctaText?: string;\n ctaHref?: string;\n}\n\n/** General text — aligned to GeneralTextSectionProps (used by Fallback) */\nexport interface GeneralTextCompProps extends SectionCompProps {\n markdown: string;\n}\n\n/** Callout — aligned to CalloutSectionProps */\nexport interface CalloutCompProps extends SectionCompProps {\n callouts: Callout[];\n title?: string;\n relatedLinks?: { text: string; url: string }[];\n}\n\n/** Next steps — aligned to NextStepsSectionProps */\nexport interface NextStepsCompProps extends SectionCompProps {\n title: string;\n body?: string;\n /**\n * True when the chips are already rendered inline inside `body`. Renderers\n * must show `body` alone in that case — listing `steps` as well repeats every\n * chip. `steps` stays populated either way; it is the machine-readable chip\n * list (the scroll chips under the answer are built from it).\n */\n chipsInlineInBody?: boolean;\n backgroundImage?: string;\n steps: { content: string; iconHint?: string }[];\n}\n\n/** Feature section 9+ — aligned to FeatureSection9PlusProps */\nexport interface FeatureSection9PlusCompProps extends SectionCompProps {\n title: string;\n description?: string;\n features: { title?: string; description: string; iconHint?: string }[];\n}\n\n/** List items section — title + a list of feature items. */\nexport interface ListItemsSectionCompProps extends SectionCompProps {\n title: string;\n features: { title?: string; description: string }[];\n}\n\nexport type ListItemsSectionComponent = FC<ListItemsSectionCompProps>;\n\n/** Error — aligned to ErrorSection */\nexport interface ErrorCompProps extends SectionCompProps {\n type: import('../errors/conversationErrorTypes').ConversationErrorType;\n}\n\n/** Skip/HTML/Search — null-component parsers */\nexport interface NullCompProps extends SectionCompProps {}\n\n/** @deprecated Use EntityCompProps */\nexport type SolutionEntityCompProps = EntityCompProps;\n/** @deprecated Use EntityCompProps */\nexport type BlogEntityCompProps = EntityCompProps;\n\n/** CTA Banner — dark purple gradient card with headline, description, and pill link buttons */\nexport interface CtaBannerCompProps extends SectionCompProps {\n headline: string;\n description?: string;\n links: { text: string; href: string }[];\n /** Contextual background image — resolved from allowed keywords during parse() */\n imageUrl?: string;\n imageFromText?: boolean;\n}\n\nexport type CtaBannerSectionComponent = FC<CtaBannerCompProps>;\n\n/** Text block — heading + body with an optional pullquote callout on the side */\nexport interface TextBlockCompProps extends SectionCompProps {\n title: string;\n description: string;\n}\n\n/** Personalized narrative — standalone section with no parse() definition */\nexport interface PersonalizedNarrativeCompProps extends SectionCompProps {\n title: string;\n content?: string;\n}\n\n// --------------------------------\n// Types of component - all components\n// --------------------------------\n\nexport type Component = BaseComponent | SlotComponent | SectionComponent;\n\nexport type BaseComponent = FC<BaseCompProps>;\nexport type SlotComponent = FC<SlotCompProps>;\nexport type SectionComponent = FC<SectionCompProps>;\n\n// Base Components\nexport type TextComponent = FC<TextCompProps>;\nexport type ButtonComponent = FC<ButtonCompProps>;\nexport type ImageComponent = FC<ImageCompProps>;\nexport type BadgeComponent = FC<BadgeCompProps>;\n\n// Slot Components\nexport type KpiItemComponent = FC<KpiItemCompProps>;\nexport type FeatureItemComponent = FC<FeatureItemCompProps>;\nexport type FeatureCardComponent = FC<FeatureCardCompProps>;\n/** @deprecated Use FC<EntityItem> */\nexport type GenericEntityComponent = FC<EntityItem>;\nexport type AiNarrativeComponent = FC<AiNarrativeCompProps>;\n\n// Section Components\nexport type ComparisonSectionComponent = FC<ComparisonCompProps>;\nexport type GeneralTextSectionComponent = FC<GeneralTextCompProps>;\nexport type TextBlockSectionComponent = FC<TextBlockCompProps>;\nexport type HeroSectionComponent = FC<HeroCompProps>;\nexport type HeroEntitySectionComponent = FC<HeroEntityCompProps>;\n\n// section components with slots\nexport type KpiSectionComponent = FC<KpiCompProps>;\nexport type FeatureCardsSectionComponent = FC<FeatureCardsCompProps>;\nexport type EntitySectionComponent = FC<EntityCompProps>;\n\n// New section component types for Phase 4\nexport type CalloutSectionComponent = FC<CalloutCompProps>;\nexport type NextStepsSectionComponent = FC<NextStepsCompProps>;\nexport type FeatureSection9PlusSectionComponent =\n FC<FeatureSection9PlusCompProps>;\nexport type NullSectionComponent = FC<NullCompProps>;\nexport type ErrorSectionComponent = FC<ErrorCompProps>;\nexport type SolutionEntitySectionComponent = FC<SolutionEntityCompProps>;\nexport type BlogEntitySectionComponent = FC<BlogEntityCompProps>;\nexport type PersonalizedNarrativeSectionComponent =\n FC<PersonalizedNarrativeCompProps>;\n\nexport type PropsOf<T> = T extends (props: infer P) => unknown ? P : never;\n\nexport interface SectionFixture<TProps> {\n markdown: string;\n expected: Partial<TProps>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../src/component/types.ts"],"sourcesContent":["import type { FC } from 'react';\nimport type { Callout } from '../types/callout';\n\n/** Props extracted from markdown (base layer). */\nexport interface BaseCompProps {}\nexport interface SlotCompProps extends BaseCompProps {\n callout?: Callout;\n}\n\nexport interface SectionCompProps extends BaseCompProps {\n callout?: Callout;\n}\n\n/** Section props with a slot. TSlot enforces which slot component this section accepts. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface SectionCompPropsWithSlot<TSlot extends FC<any> = FC<any>>\n extends SectionCompProps {\n slot?: TSlot;\n}\n\n// ----------------------\n// Base Components\n// ----------------------\n\nexport interface TextCompProps extends BaseCompProps {\n content: string;\n variant?: 'h1' | 'h2' | 'body' | 'caption';\n}\n\nexport interface ButtonCompProps extends BaseCompProps {\n label: string;\n variant?: 'primary' | 'secondary' | 'ghost';\n onClick?: string;\n}\n\nexport interface ImageCompProps extends BaseCompProps {\n src: string;\n alt: string;\n ratio?: '16:9' | '4:3' | '1:1' | '9:16' | '3:4';\n}\n\nexport interface BadgeCompProps extends BaseCompProps {\n label: string;\n color?: 'primary' | 'secondary' | 'success' | 'warning' | 'error';\n}\n\n// ----------------------\n// Hero Button (aligned to HeroSection1Button)\n// ----------------------\n\nexport interface HeroButton {\n id: string;\n text: string;\n variant?: 'primary' | 'secondary';\n onClick?: string;\n}\n\n// ----------------------\n// Slot Components\n// ----------------------\n\nexport interface KpiItemCompProps extends SlotCompProps {\n title: string;\n description: string;\n icon?: string;\n}\n\n/** Feature item — aligned to web50-server-ui Feature interface */\nexport interface FeatureItemCompProps extends SlotCompProps {\n title?: string;\n description?: string;\n icon?: string;\n}\n\n/** Feature card — aligned to web50-server-ui FeatureCard */\nexport interface FeatureCardCompProps extends SlotCompProps {\n title: string;\n description: string;\n imageUrl?: string;\n imageFromText?: boolean;\n linkText?: string;\n linkHref?: string;\n callout?: Callout;\n}\n\n/** Resolved entity data (populated at runtime via useResolveGenericEntityData) */\nexport interface EntityItemData {\n url: string;\n title: string;\n type: string;\n description?: string;\n excerpt?: string;\n imageUrl?: string;\n date?: string;\n publishDate?: string;\n author?: string;\n cmsItemId?: string;\n usage?: number;\n tags?: string[];\n /** Product vendor / brand name (e.g. \"HOKA\") */\n vendor?: string;\n /**\n * The `{ name, value }` pairs of the one variant a search matched, in the\n * store's own order. Present only when retrieval resolved the product down\n * to a single variant. The names are the store's own, so read this by\n * iterating it — never by looking a name up.\n */\n matchedOptions?: { name: string; value: string }[];\n /**\n * Id of the one variant a search matched — the same variant `imageUrl`,\n * `url` and `matchedOptions` describe. Bare store id, no `gid://` prefix.\n * A live enricher reads this to price that variant rather than the product.\n */\n variantId?: string;\n /** Whether the matched variant is in stock, as of the last live fetch */\n available?: boolean;\n /** Formatted lowest price across the product's variants (e.g. \"$107.95\") */\n priceMin?: string;\n /** Formatted highest price across the product's variants */\n priceMax?: string;\n /** Formatted price string (e.g. \"542.00 NIS\") */\n price?: string;\n /** Secondary product image URL — shown on hover */\n secondaryImageUrl?: string;\n /** Available sizes for the product */\n sizes?: string[];\n /** Original price before discount (formatted, e.g. \"494.00 NIS\") — shown with strikethrough */\n compareAtPrice?: string;\n /** Discount percentage (e.g. \"30% OFF\") */\n discountPercent?: string;\n /** Product variants with IDs and availability — used for add-to-cart and size display */\n variants?: {\n label: string;\n variantId: string;\n available: boolean;\n selectedOptions?: { name: string; value: string }[];\n price?: string;\n compareAtPrice?: string;\n }[];\n /** All product image URLs (not just featured + secondary) */\n allImages?: string[];\n /** Product option groups (e.g. Size, Color) with their available values */\n options?: { name: string; values: string[] }[];\n}\n\n/** Single entity item within an entity section */\nexport interface EntityItem {\n entityId: string;\n linkText?: string;\n entityType: string;\n entityUrl: string;\n description?: string;\n imageUrl?: string;\n /** Per-item callout from a blockquote inside the list item */\n callout?: Callout;\n /** Resolved at runtime via useResolveGenericEntityData hook; not produced by parse() */\n data?: EntityItemData;\n}\n\n// ---------------------------------------------------------------------------\n// Deprecated aliases — kept for seed-components compilation\n// ---------------------------------------------------------------------------\n/** @deprecated Use EntityItemData */\nexport type GenericEntityData = EntityItemData;\n/** @deprecated Use EntityItemData */\nexport type SolutionEntityData = EntityItemData;\n/** @deprecated Use EntityItemData */\nexport type BlogEntityData = EntityItemData;\n/** @deprecated Use EntityItem */\nexport type GenericEntityCompProps = EntityItem;\n\n/** Comparison row — aligned to web50-server-ui ComparisonRow */\nexport interface ComparisonRow {\n feature: string;\n iconHint?: string;\n values: (boolean | string)[];\n}\n\nexport interface ComparisonColumn {\n label: string;\n href?: string;\n entityId?: string;\n entityType?: string;\n}\n\n/** @deprecated Use Callout from types/callout instead */\nexport interface AiNarrativeCompProps extends SlotCompProps {\n content: string;\n}\n\n// ----------------------\n// Section Components\n// ----------------------\n\n/** Hero — aligned to HeroSection1Props */\nexport interface HeroCompProps extends SectionCompProps {\n headline: string;\n badge?: string | { text: string; showIndicator?: boolean };\n content?: string;\n buttons?: HeroButton[];\n image?: string;\n trailingList?: string;\n leadingQuote?: string;\n}\n\n/**\n * Entity hero — a hero section whose body carries one or more web5 entity\n * links (`web5://entity/...`). Shares the hero framing fields with\n * {@link HeroCompProps} but, instead of CTA buttons, surfaces the entities as\n * resolvable {@link EntityItem}s for rich rendering.\n */\nexport interface HeroEntityCompProps extends SectionCompProps {\n headline: string;\n badge?: string | { text: string; showIndicator?: boolean };\n content?: string;\n image?: string;\n leadingQuote?: string;\n items: EntityItem[];\n}\n\n/** KPI — aligned to KpiSectionProps */\nexport interface KpiCompProps\n extends SectionCompPropsWithSlot<KpiItemComponent> {\n title: string;\n items: KpiItemCompProps[];\n}\n\n/** Feature cards — aligned to FeatureCardsSectionProps */\nexport interface FeatureCardsCompProps extends SectionCompProps {\n cards: FeatureCardCompProps[];\n}\n\n/** Unified entity section — replaces EntityCompProps, SolutionEntityCompProps, BlogEntityCompProps */\nexport interface EntityCompProps extends SectionCompProps {\n title: string;\n description?: string;\n items: EntityItem[];\n}\n\n/** Comparison — aligned to ComparisonSection1Props */\nexport interface ComparisonCompProps extends SectionCompProps {\n title: string;\n description?: string;\n columnLabels: string[];\n columns?: ComparisonColumn[];\n rows: ComparisonRow[];\n featureColumnLabel?: string;\n ctaText?: string;\n ctaHref?: string;\n}\n\n/** General text — aligned to GeneralTextSectionProps (used by Fallback) */\nexport interface GeneralTextCompProps extends SectionCompProps {\n markdown: string;\n}\n\n/** Callout — aligned to CalloutSectionProps */\nexport interface CalloutCompProps extends SectionCompProps {\n callouts: Callout[];\n title?: string;\n relatedLinks?: { text: string; url: string }[];\n}\n\n/** Next steps — aligned to NextStepsSectionProps */\nexport interface NextStepsCompProps extends SectionCompProps {\n title: string;\n body?: string;\n /**\n * True when the chips are already rendered inline inside `body`. Renderers\n * must show `body` alone in that case — listing `steps` as well repeats every\n * chip. `steps` stays populated either way; it is the machine-readable chip\n * list (the scroll chips under the answer are built from it).\n */\n chipsInlineInBody?: boolean;\n backgroundImage?: string;\n steps: { content: string; iconHint?: string }[];\n}\n\n/** Feature section 9+ — aligned to FeatureSection9PlusProps */\nexport interface FeatureSection9PlusCompProps extends SectionCompProps {\n title: string;\n description?: string;\n features: { title?: string; description: string; iconHint?: string }[];\n}\n\n/** List items section — title + a list of feature items. */\nexport interface ListItemsSectionCompProps extends SectionCompProps {\n title: string;\n features: { title?: string; description: string }[];\n}\n\nexport type ListItemsSectionComponent = FC<ListItemsSectionCompProps>;\n\n/** Error — aligned to ErrorSection */\nexport interface ErrorCompProps extends SectionCompProps {\n type: import('../errors/conversationErrorTypes').ConversationErrorType;\n}\n\n/** Skip/HTML/Search — null-component parsers */\nexport interface NullCompProps extends SectionCompProps {}\n\n/** @deprecated Use EntityCompProps */\nexport type SolutionEntityCompProps = EntityCompProps;\n/** @deprecated Use EntityCompProps */\nexport type BlogEntityCompProps = EntityCompProps;\n\n/** CTA Banner — dark purple gradient card with headline, description, and pill link buttons */\nexport interface CtaBannerCompProps extends SectionCompProps {\n headline: string;\n description?: string;\n links: { text: string; href: string }[];\n /** Contextual background image — resolved from allowed keywords during parse() */\n imageUrl?: string;\n imageFromText?: boolean;\n}\n\nexport type CtaBannerSectionComponent = FC<CtaBannerCompProps>;\n\n/** Text block — heading + body with an optional pullquote callout on the side */\nexport interface TextBlockCompProps extends SectionCompProps {\n title: string;\n description: string;\n}\n\n/** Personalized narrative — standalone section with no parse() definition */\nexport interface PersonalizedNarrativeCompProps extends SectionCompProps {\n title: string;\n content?: string;\n}\n\n// --------------------------------\n// Types of component - all components\n// --------------------------------\n\nexport type Component = BaseComponent | SlotComponent | SectionComponent;\n\nexport type BaseComponent = FC<BaseCompProps>;\nexport type SlotComponent = FC<SlotCompProps>;\nexport type SectionComponent = FC<SectionCompProps>;\n\n// Base Components\nexport type TextComponent = FC<TextCompProps>;\nexport type ButtonComponent = FC<ButtonCompProps>;\nexport type ImageComponent = FC<ImageCompProps>;\nexport type BadgeComponent = FC<BadgeCompProps>;\n\n// Slot Components\nexport type KpiItemComponent = FC<KpiItemCompProps>;\nexport type FeatureItemComponent = FC<FeatureItemCompProps>;\nexport type FeatureCardComponent = FC<FeatureCardCompProps>;\n/** @deprecated Use FC<EntityItem> */\nexport type GenericEntityComponent = FC<EntityItem>;\nexport type AiNarrativeComponent = FC<AiNarrativeCompProps>;\n\n// Section Components\nexport type ComparisonSectionComponent = FC<ComparisonCompProps>;\nexport type GeneralTextSectionComponent = FC<GeneralTextCompProps>;\nexport type TextBlockSectionComponent = FC<TextBlockCompProps>;\nexport type HeroSectionComponent = FC<HeroCompProps>;\nexport type HeroEntitySectionComponent = FC<HeroEntityCompProps>;\n\n// section components with slots\nexport type KpiSectionComponent = FC<KpiCompProps>;\nexport type FeatureCardsSectionComponent = FC<FeatureCardsCompProps>;\nexport type EntitySectionComponent = FC<EntityCompProps>;\n\n// New section component types for Phase 4\nexport type CalloutSectionComponent = FC<CalloutCompProps>;\nexport type NextStepsSectionComponent = FC<NextStepsCompProps>;\nexport type FeatureSection9PlusSectionComponent =\n FC<FeatureSection9PlusCompProps>;\nexport type NullSectionComponent = FC<NullCompProps>;\nexport type ErrorSectionComponent = FC<ErrorCompProps>;\nexport type SolutionEntitySectionComponent = FC<SolutionEntityCompProps>;\nexport type BlogEntitySectionComponent = FC<BlogEntityCompProps>;\nexport type PersonalizedNarrativeSectionComponent =\n FC<PersonalizedNarrativeCompProps>;\n\nexport type PropsOf<T> = T extends (props: infer P) => unknown ? P : never;\n\nexport interface SectionFixture<TProps> {\n markdown: string;\n expected: Partial<TProps>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -26,8 +26,20 @@ function getSearchSpringHandle(entity) {
|
|
|
26
26
|
var _entity$data;
|
|
27
27
|
return extractProductHandle((_entity$data = entity.data) == null ? void 0 : _entity$data.url) || entity.entityId;
|
|
28
28
|
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The turn owns WHICH thing to show; the live fetch owns VOLATILE FACTS about
|
|
32
|
+
* it.
|
|
33
|
+
*
|
|
34
|
+
* Only the turn saw the shopper's question, so only it knows that the brown
|
|
35
|
+
* variant was the one asked for — its `title`, `imageUrl`, `url`,
|
|
36
|
+
* `matchedOptions` and `variantId` all describe that one variant and must
|
|
37
|
+
* survive enrichment. Everything SearchSpring answers with that can go stale
|
|
38
|
+
* between the turn and the render — `price`, `compareAtPrice`, `available`,
|
|
39
|
+
* `priceMin`, `priceMax` — comes from `resolved`.
|
|
40
|
+
*/
|
|
29
41
|
export function mergeSearchSpringEntityData(existing, resolved) {
|
|
30
|
-
var _existing$sizes, _existing$variants, _existing$options, _existing$allImages;
|
|
42
|
+
var _existing$matchedOpti, _existing$sizes, _existing$variants, _existing$options, _existing$allImages;
|
|
31
43
|
if (!existing) {
|
|
32
44
|
return resolved;
|
|
33
45
|
}
|
|
@@ -35,6 +47,10 @@ export function mergeSearchSpringEntityData(existing, resolved) {
|
|
|
35
47
|
...existing,
|
|
36
48
|
...resolved,
|
|
37
49
|
url: existing.url || resolved.url,
|
|
50
|
+
title: existing.title || resolved.title,
|
|
51
|
+
imageUrl: existing.imageUrl || resolved.imageUrl,
|
|
52
|
+
variantId: existing.variantId || resolved.variantId,
|
|
53
|
+
matchedOptions: (_existing$matchedOpti = existing.matchedOptions) != null && _existing$matchedOpti.length ? existing.matchedOptions : resolved.matchedOptions,
|
|
38
54
|
sizes: (_existing$sizes = existing.sizes) != null && _existing$sizes.length ? existing.sizes : resolved.sizes,
|
|
39
55
|
variants: (_existing$variants = existing.variants) != null && _existing$variants.length ? existing.variants : resolved.variants,
|
|
40
56
|
options: (_existing$options = existing.options) != null && _existing$options.length ? existing.options : resolved.options,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useState","useEffect","useMemo","fetchProductsByHandlesMap","transformSSProductToEntityItemData","ssEntityCache","Map","extractProductHandle","url","trimmed","trim","undefined","pathname","test","URL","withoutQuery","split","withoutLeadingSlash","replace","productsIndex","indexOf","handle","slice","length","getSearchSpringHandle","entity","_entity$data","data","entityId","mergeSearchSpringEntityData","existing","resolved","_existing$sizes","_existing$variants","_existing$options","_existing$allImages","sizes","variants","options","allImages","useResolveSearchSpringEntityData","entities","config","resolvedMap","setResolvedMap","settled","setSettled","entityKey","map","e","entityType","join","ignore","siteId","productEntityHandles","filter","toLowerCase","includes","handlesToFetch","Set","_ref","has","cached","forEach","_ref2","item","get","set","fetchAll","productMap","product","itemData","finalMap","_ref3","enrichedEntities","loading"],"sources":["../../../src/hooks/useResolveSearchSpringEntityData.ts"],"sourcesContent":["import { useState, useEffect, useMemo } from 'react';\nimport { fetchProductsByHandlesMap } from '../services/searchspring/searchSpringClient';\nimport { transformSSProductToEntityItemData } from '../services/searchspring/transformSSProduct';\nimport type { SearchSpringConfig } from '../services/searchspring/types';\nimport type { EntityItemData } from '../component/types';\n\n// Session-level cache: handle → resolved EntityItemData\nconst ssEntityCache = new Map<string, EntityItemData>();\n\nfunction extractProductHandle(url: string | undefined): string | undefined {\n const trimmed = url?.trim();\n if (!trimmed) {\n return undefined;\n }\n\n let pathname = trimmed;\n try {\n if (/^https?:\\/\\//i.test(trimmed)) {\n pathname = new URL(trimmed).pathname;\n }\n } catch {\n pathname = trimmed;\n }\n\n const withoutQuery = pathname.split(/[?#]/)[0];\n const withoutLeadingSlash = withoutQuery.replace(/^\\/+/, '');\n const productsIndex = withoutLeadingSlash.indexOf('products/');\n const handle =\n productsIndex >= 0\n ? withoutLeadingSlash.slice(productsIndex + 'products/'.length)\n : withoutLeadingSlash;\n\n return handle || undefined;\n}\n\nfunction getSearchSpringHandle(entity: {\n entityId: string;\n data?: EntityItemData;\n}): string {\n return extractProductHandle(entity.data?.url) || entity.entityId;\n}\n\nexport function mergeSearchSpringEntityData(\n existing: EntityItemData | undefined,\n resolved: EntityItemData,\n): EntityItemData {\n if (!existing) {\n return resolved;\n }\n\n return {\n ...existing,\n ...resolved,\n url: existing.url || resolved.url,\n sizes: existing.sizes?.length ? existing.sizes : resolved.sizes,\n variants: existing.variants?.length ? existing.variants : resolved.variants,\n options: existing.options?.length ? existing.options : resolved.options,\n allImages: existing.allImages?.length\n ? existing.allImages\n : resolved.allImages,\n };\n}\n\n/**\n * SearchSpring-backed entity resolution hook.\n *\n * Fetches product data from the SearchSpring Search API by handle\n * and transforms it to EntityItemData. Uses a single batched API call\n * for all products (bgfilter.handle supports OR).\n */\nexport function useResolveSearchSpringEntityData<\n TEntity extends {\n entityId: string;\n entityUrl: string;\n entityType: string;\n data?: EntityItemData;\n },\n>(\n entities: TEntity[],\n config: SearchSpringConfig,\n): { enrichedEntities: TEntity[]; loading: boolean } {\n const [resolvedMap, setResolvedMap] = useState<Map<string, EntityItemData>>(\n new Map(),\n );\n const [settled, setSettled] = useState(false);\n\n // Stable key for dependency tracking\n const entityKey = useMemo(\n () =>\n entities\n .map((e) => `${e.entityType}:${e.entityId}:${getSearchSpringHandle(e)}`)\n .join(','),\n [entities],\n );\n\n useEffect(() => {\n let ignore = false;\n\n if (!entities.length || !config.siteId) {\n setSettled(true);\n return;\n }\n\n const productEntityHandles = entities\n .filter((e) => e.entityType.toLowerCase().includes('product'))\n .map((entity) => ({\n entity,\n handle: getSearchSpringHandle(entity),\n }));\n\n // Collect handles that need fetching. CMS payload IDs use payload url as the handle.\n const handlesToFetch = [\n ...new Set(\n productEntityHandles\n .map(({ handle }) => handle)\n .filter((handle) => !ssEntityCache.has(handle)),\n ),\n ];\n\n // If everything is cached, resolve immediately\n if (handlesToFetch.length === 0) {\n const cached = new Map<string, EntityItemData>();\n productEntityHandles.forEach(({ entity, handle }) => {\n const item = ssEntityCache.get(handle);\n if (item) {\n cached.set(entity.entityId, item);\n }\n });\n setResolvedMap(cached);\n setSettled(true);\n return;\n }\n\n setSettled(false);\n\n const fetchAll = async () => {\n const productMap = await fetchProductsByHandlesMap(\n config.siteId,\n handlesToFetch,\n );\n\n // Transform and cache\n for (const [handle, product] of productMap) {\n const itemData = transformSSProductToEntityItemData(product);\n ssEntityCache.set(handle, itemData);\n }\n\n if (ignore) {\n return;\n }\n\n // Build the final map\n const finalMap = new Map<string, EntityItemData>();\n productEntityHandles.forEach(({ entity, handle }) => {\n const item = ssEntityCache.get(handle);\n if (item) {\n finalMap.set(entity.entityId, item);\n }\n });\n\n setResolvedMap(finalMap);\n setSettled(true);\n };\n\n fetchAll();\n return () => {\n ignore = true;\n };\n }, [entityKey, config.siteId]);\n\n // Merge resolved data into entities\n const enrichedEntities = useMemo(() => {\n return entities.map((entity) => {\n const resolved = resolvedMap.get(entity.entityId);\n if (resolved) {\n return {\n ...entity,\n data: mergeSearchSpringEntityData(entity.data, resolved),\n };\n }\n return entity;\n });\n }, [entities, resolvedMap]);\n\n return { enrichedEntities, loading: !settled };\n}\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,SAAS,EAA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zC,MAAM,CAACG,QAAQ,CAAC;MACjD,IAAIG,QAAQ,EAAE;QACZ,OAAO;UACL,GAAGN,MAAM;UACTE,IAAI,EAAEE,2BAA2B,CAACJ,MAAM,CAACE,IAAI,EAAEI,QAAQ;QACzD,CAAC;MACH;MACA,OAAON,MAAM;IACf,CAAC,CAAC;EACJ,CAAC,EAAE,CAACgB,QAAQ,EAAEE,WAAW,CAAC,CAAC;EAE3B,OAAO;IAAE+B,gBAAgB;IAAEC,OAAO,EAAE,CAAC9B;EAAQ,CAAC;AAChD","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useState","useEffect","useMemo","fetchProductsByHandlesMap","transformSSProductToEntityItemData","ssEntityCache","Map","extractProductHandle","url","trimmed","trim","undefined","pathname","test","URL","withoutQuery","split","withoutLeadingSlash","replace","productsIndex","indexOf","handle","slice","length","getSearchSpringHandle","entity","_entity$data","data","entityId","mergeSearchSpringEntityData","existing","resolved","_existing$matchedOpti","_existing$sizes","_existing$variants","_existing$options","_existing$allImages","title","imageUrl","variantId","matchedOptions","sizes","variants","options","allImages","useResolveSearchSpringEntityData","entities","config","resolvedMap","setResolvedMap","settled","setSettled","entityKey","map","e","entityType","join","ignore","siteId","productEntityHandles","filter","toLowerCase","includes","handlesToFetch","Set","_ref","has","cached","forEach","_ref2","item","get","set","fetchAll","productMap","product","itemData","finalMap","_ref3","enrichedEntities","loading"],"sources":["../../../src/hooks/useResolveSearchSpringEntityData.ts"],"sourcesContent":["import { useState, useEffect, useMemo } from 'react';\nimport { fetchProductsByHandlesMap } from '../services/searchspring/searchSpringClient';\nimport { transformSSProductToEntityItemData } from '../services/searchspring/transformSSProduct';\nimport type { SearchSpringConfig } from '../services/searchspring/types';\nimport type { EntityItemData } from '../component/types';\n\n// Session-level cache: handle → resolved EntityItemData\nconst ssEntityCache = new Map<string, EntityItemData>();\n\nfunction extractProductHandle(url: string | undefined): string | undefined {\n const trimmed = url?.trim();\n if (!trimmed) {\n return undefined;\n }\n\n let pathname = trimmed;\n try {\n if (/^https?:\\/\\//i.test(trimmed)) {\n pathname = new URL(trimmed).pathname;\n }\n } catch {\n pathname = trimmed;\n }\n\n const withoutQuery = pathname.split(/[?#]/)[0];\n const withoutLeadingSlash = withoutQuery.replace(/^\\/+/, '');\n const productsIndex = withoutLeadingSlash.indexOf('products/');\n const handle =\n productsIndex >= 0\n ? withoutLeadingSlash.slice(productsIndex + 'products/'.length)\n : withoutLeadingSlash;\n\n return handle || undefined;\n}\n\nfunction getSearchSpringHandle(entity: {\n entityId: string;\n data?: EntityItemData;\n}): string {\n return extractProductHandle(entity.data?.url) || entity.entityId;\n}\n\n/**\n * The turn owns WHICH thing to show; the live fetch owns VOLATILE FACTS about\n * it.\n *\n * Only the turn saw the shopper's question, so only it knows that the brown\n * variant was the one asked for — its `title`, `imageUrl`, `url`,\n * `matchedOptions` and `variantId` all describe that one variant and must\n * survive enrichment. Everything SearchSpring answers with that can go stale\n * between the turn and the render — `price`, `compareAtPrice`, `available`,\n * `priceMin`, `priceMax` — comes from `resolved`.\n */\nexport function mergeSearchSpringEntityData(\n existing: EntityItemData | undefined,\n resolved: EntityItemData,\n): EntityItemData {\n if (!existing) {\n return resolved;\n }\n\n return {\n ...existing,\n ...resolved,\n url: existing.url || resolved.url,\n title: existing.title || resolved.title,\n imageUrl: existing.imageUrl || resolved.imageUrl,\n variantId: existing.variantId || resolved.variantId,\n matchedOptions: existing.matchedOptions?.length\n ? existing.matchedOptions\n : resolved.matchedOptions,\n sizes: existing.sizes?.length ? existing.sizes : resolved.sizes,\n variants: existing.variants?.length ? existing.variants : resolved.variants,\n options: existing.options?.length ? existing.options : resolved.options,\n allImages: existing.allImages?.length\n ? existing.allImages\n : resolved.allImages,\n };\n}\n\n/**\n * SearchSpring-backed entity resolution hook.\n *\n * Fetches product data from the SearchSpring Search API by handle\n * and transforms it to EntityItemData. Uses a single batched API call\n * for all products (bgfilter.handle supports OR).\n */\nexport function useResolveSearchSpringEntityData<\n TEntity extends {\n entityId: string;\n entityUrl: string;\n entityType: string;\n data?: EntityItemData;\n },\n>(\n entities: TEntity[],\n config: SearchSpringConfig,\n): { enrichedEntities: TEntity[]; loading: boolean } {\n const [resolvedMap, setResolvedMap] = useState<Map<string, EntityItemData>>(\n new Map(),\n );\n const [settled, setSettled] = useState(false);\n\n // Stable key for dependency tracking\n const entityKey = useMemo(\n () =>\n entities\n .map((e) => `${e.entityType}:${e.entityId}:${getSearchSpringHandle(e)}`)\n .join(','),\n [entities],\n );\n\n useEffect(() => {\n let ignore = false;\n\n if (!entities.length || !config.siteId) {\n setSettled(true);\n return;\n }\n\n const productEntityHandles = entities\n .filter((e) => e.entityType.toLowerCase().includes('product'))\n .map((entity) => ({\n entity,\n handle: getSearchSpringHandle(entity),\n }));\n\n // Collect handles that need fetching. CMS payload IDs use payload url as the handle.\n const handlesToFetch = [\n ...new Set(\n productEntityHandles\n .map(({ handle }) => handle)\n .filter((handle) => !ssEntityCache.has(handle)),\n ),\n ];\n\n // If everything is cached, resolve immediately\n if (handlesToFetch.length === 0) {\n const cached = new Map<string, EntityItemData>();\n productEntityHandles.forEach(({ entity, handle }) => {\n const item = ssEntityCache.get(handle);\n if (item) {\n cached.set(entity.entityId, item);\n }\n });\n setResolvedMap(cached);\n setSettled(true);\n return;\n }\n\n setSettled(false);\n\n const fetchAll = async () => {\n const productMap = await fetchProductsByHandlesMap(\n config.siteId,\n handlesToFetch,\n );\n\n // Transform and cache\n for (const [handle, product] of productMap) {\n const itemData = transformSSProductToEntityItemData(product);\n ssEntityCache.set(handle, itemData);\n }\n\n if (ignore) {\n return;\n }\n\n // Build the final map\n const finalMap = new Map<string, EntityItemData>();\n productEntityHandles.forEach(({ entity, handle }) => {\n const item = ssEntityCache.get(handle);\n if (item) {\n finalMap.set(entity.entityId, item);\n }\n });\n\n setResolvedMap(finalMap);\n setSettled(true);\n };\n\n fetchAll();\n return () => {\n ignore = true;\n };\n }, [entityKey, config.siteId]);\n\n // Merge resolved data into entities\n const enrichedEntities = useMemo(() => {\n return entities.map((entity) => {\n const resolved = resolvedMap.get(entity.entityId);\n if (resolved) {\n return {\n ...entity,\n data: mergeSearchSpringEntityData(entity.data, resolved),\n };\n }\n return entity;\n });\n }, [entities, resolvedMap]);\n\n return { enrichedEntities, loading: !settled };\n}\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AACpD,SAASC,yBAAyB,QAAQ,6CAA6C;AACvF,SAASC,kCAAkC,QAAQ,6CAA6C;AAIhG;AACA,MAAMC,aAAa,GAAG,IAAIC,GAAG,CAAyB,CAAC;AAEvD,SAASC,oBAAoBA,CAACC,GAAuB,EAAsB;EACzE,MAAMC,OAAO,GAAGD,GAAG,oBAAHA,GAAG,CAAEE,IAAI,CAAC,CAAC;EAC3B,IAAI,CAACD,OAAO,EAAE;IACZ,OAAOE,SAAS;EAClB;EAEA,IAAIC,QAAQ,GAAGH,OAAO;EACtB,IAAI;IACF,IAAI,eAAe,CAACI,IAAI,CAACJ,OAAO,CAAC,EAAE;MACjCG,QAAQ,GAAG,IAAIE,GAAG,CAACL,OAAO,CAAC,CAACG,QAAQ;IACtC;EACF,CAAC,CAAC,MAAM;IACNA,QAAQ,GAAGH,OAAO;EACpB;EAEA,MAAMM,YAAY,GAAGH,QAAQ,CAACI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;EAC9C,MAAMC,mBAAmB,GAAGF,YAAY,CAACG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;EAC5D,MAAMC,aAAa,GAAGF,mBAAmB,CAACG,OAAO,CAAC,WAAW,CAAC;EAC9D,MAAMC,MAAM,GACVF,aAAa,IAAI,CAAC,GACdF,mBAAmB,CAACK,KAAK,CAACH,aAAa,GAAG,WAAW,CAACI,MAAM,CAAC,GAC7DN,mBAAmB;EAEzB,OAAOI,MAAM,IAAIV,SAAS;AAC5B;AAEA,SAASa,qBAAqBA,CAACC,MAG9B,EAAU;EAAA,IAAAC,YAAA;EACT,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D,MAAM;UAAEJ;QAAO,CAAC,GAAAyD,KAAA;QAC9C,MAAMR,IAAI,GAAGjE,aAAa,CAACkE,GAAG,CAAClD,MAAM,CAAC;QACtC,IAAIiD,IAAI,EAAE;UACRO,QAAQ,CAACL,GAAG,CAAC/C,MAAM,CAACG,QAAQ,EAAE0C,IAAI,CAAC;QACrC;MACF,CAAC,CAAC;MAEFrB,cAAc,CAAC4B,QAAQ,CAAC;MACxB1B,UAAU,CAAC,IAAI,CAAC;IAClB,CAAC;IAEDsB,QAAQ,CAAC,CAAC;IACV,OAAO,MAAM;MACXhB,MAAM,GAAG,IAAI;IACf,CAAC;EACH,CAAC,EAAE,CAACL,SAAS,EAAEL,MAAM,CAACW,MAAM,CAAC,CAAC;;EAE9B;EACA,MAAMqB,gBAAgB,GAAG7E,OAAO,CAAC,MAAM;IACrC,OAAO4C,QAAQ,CAACO,GAAG,CAAE5B,MAAM,IAAK;MAC9B,MAAMM,QAAQ,GAAGiB,WAAW,CAACuB,GAAG,CAAC9C,MAAM,CAACG,QAAQ,CAAC;MACjD,IAAIG,QAAQ,EAAE;QACZ,OAAO;UACL,GAAGN,MAAM;UACTE,IAAI,EAAEE,2BAA2B,CAACJ,MAAM,CAACE,IAAI,EAAEI,QAAQ;QACzD,CAAC;MACH;MACA,OAAON,MAAM;IACf,CAAC,CAAC;EACJ,CAAC,EAAE,CAACqB,QAAQ,EAAEE,WAAW,CAAC,CAAC;EAE3B,OAAO;IAAE+B,gBAAgB;IAAEC,OAAO,EAAE,CAAC9B;EAAQ,CAAC;AAChD","ignoreList":[]}
|
|
@@ -2,10 +2,10 @@ import { useState, useEffect, useMemo, useRef } from 'react';
|
|
|
2
2
|
import { ShopifyStorefrontClient } from '../services/shopify/shopifyStorefrontClient.js';
|
|
3
3
|
import { resolveShopifyEntity } from '../services/shopify/shopifyEntityResolver.js';
|
|
4
4
|
import { transformShopifyEntityToItemData } from '../services/shopify/transformShopifyEntity.js';
|
|
5
|
-
// Session-level cache: entityType:entityId → resolved EntityItemData
|
|
5
|
+
// Session-level cache: entityType:entityId:variantId → resolved EntityItemData
|
|
6
6
|
const shopifyEntityCache = new Map();
|
|
7
|
-
function cacheKey(entityType, entityId) {
|
|
8
|
-
return `${entityType}:${entityId}`;
|
|
7
|
+
function cacheKey(entityType, entityId, variantId) {
|
|
8
|
+
return `${entityType}:${entityId}:${variantId || ''}`;
|
|
9
9
|
}
|
|
10
10
|
function normalizeShopifyEntityType(entityType) {
|
|
11
11
|
const lower = entityType.toLowerCase();
|
|
@@ -46,23 +46,41 @@ function extractHandleFromUrl(url) {
|
|
|
46
46
|
return withoutLeadingSlash || undefined;
|
|
47
47
|
}
|
|
48
48
|
function getShopifyLookup(entity) {
|
|
49
|
-
var _entity$data;
|
|
49
|
+
var _entity$data, _entity$data2;
|
|
50
50
|
const entityType = normalizeShopifyEntityType(entity.entityType);
|
|
51
51
|
const urlHandle = extractHandleFromUrl((_entity$data = entity.data) == null ? void 0 : _entity$data.url);
|
|
52
52
|
const entityId = (entityType === 'product' || entityType === 'collection') && urlHandle ? urlHandle : entity.entityId;
|
|
53
53
|
return {
|
|
54
54
|
entityType,
|
|
55
|
-
entityId
|
|
55
|
+
entityId,
|
|
56
|
+
variantId: (_entity$data2 = entity.data) == null ? void 0 : _entity$data2.variantId
|
|
56
57
|
};
|
|
57
58
|
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The turn owns WHICH thing to show; the live fetch owns VOLATILE FACTS about
|
|
62
|
+
* it.
|
|
63
|
+
*
|
|
64
|
+
* Only the turn saw the shopper's question, so only it knows that the brown
|
|
65
|
+
* variant was the one asked for — its `title`, `imageUrl`, `url`,
|
|
66
|
+
* `matchedOptions` and `variantId` all describe that one variant and must
|
|
67
|
+
* survive enrichment. Everything the Storefront answers with that can go stale
|
|
68
|
+
* between the turn and the render — `price`, `compareAtPrice`, `available`,
|
|
69
|
+
* `priceMin`, `priceMax` — comes from `resolved`.
|
|
70
|
+
*/
|
|
58
71
|
export function mergeShopifyEntityData(existing, resolved) {
|
|
72
|
+
var _existing$matchedOpti;
|
|
59
73
|
if (!existing) {
|
|
60
74
|
return resolved;
|
|
61
75
|
}
|
|
62
76
|
return {
|
|
63
77
|
...existing,
|
|
64
78
|
...resolved,
|
|
65
|
-
url: existing.url || resolved.url
|
|
79
|
+
url: existing.url || resolved.url,
|
|
80
|
+
title: existing.title || resolved.title,
|
|
81
|
+
imageUrl: existing.imageUrl || resolved.imageUrl,
|
|
82
|
+
variantId: existing.variantId || resolved.variantId,
|
|
83
|
+
matchedOptions: (_existing$matchedOpti = existing.matchedOptions) != null && _existing$matchedOpti.length ? existing.matchedOptions : resolved.matchedOptions
|
|
66
84
|
};
|
|
67
85
|
}
|
|
68
86
|
|
|
@@ -88,7 +106,7 @@ export function useResolveShopifyEntityData(entities, shopifyConfig) {
|
|
|
88
106
|
}
|
|
89
107
|
const entityIds = useMemo(() => entities.map(e => {
|
|
90
108
|
const lookup = getShopifyLookup(e);
|
|
91
|
-
return `${e.entityType}:${e.entityId}:${lookup.entityType
|
|
109
|
+
return `${e.entityType}:${e.entityId}:${cacheKey(lookup.entityType, lookup.entityId, lookup.variantId)}`;
|
|
92
110
|
}).join(','), [entities]);
|
|
93
111
|
useEffect(() => {
|
|
94
112
|
let ignore = false;
|
|
@@ -102,7 +120,10 @@ export function useResolveShopifyEntityData(entities, shopifyConfig) {
|
|
|
102
120
|
return {
|
|
103
121
|
entity,
|
|
104
122
|
lookup,
|
|
105
|
-
key:
|
|
123
|
+
// The variant is part of the key: the cached entry carries that
|
|
124
|
+
// variant's live price, so two entities on the same product but
|
|
125
|
+
// different variants must not share it.
|
|
126
|
+
key: cacheKey(lookup.entityType, lookup.entityId, lookup.variantId)
|
|
106
127
|
};
|
|
107
128
|
});
|
|
108
129
|
|
|
@@ -141,7 +162,7 @@ export function useResolveShopifyEntityData(entities, shopifyConfig) {
|
|
|
141
162
|
} = _ref3;
|
|
142
163
|
const resolved = await resolveShopifyEntity(client, lookup.entityType, lookup.entityId, shopifyConfig);
|
|
143
164
|
if (resolved) {
|
|
144
|
-
const itemData = transformShopifyEntityToItemData(resolved, lookup.entityType);
|
|
165
|
+
const itemData = transformShopifyEntityToItemData(resolved, lookup.entityType, lookup.variantId);
|
|
145
166
|
shopifyEntityCache.set(key, mergeShopifyEntityData(entity.data, itemData));
|
|
146
167
|
}
|
|
147
168
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useState","useEffect","useMemo","useRef","ShopifyStorefrontClient","resolveShopifyEntity","transformShopifyEntityToItemData","shopifyEntityCache","Map","cacheKey","entityType","entityId","normalizeShopifyEntityType","lower","toLowerCase","includes","extractHandleFromUrl","url","trimmed","trim","undefined","pathname","test","URL","withoutQuery","split","withoutLeadingSlash","replace","productsIndex","indexOf","slice","length","collectionsIndex","getShopifyLookup","entity","_entity$data","urlHandle","data","mergeShopifyEntityData","existing","resolved","useResolveShopifyEntityData","entities","shopifyConfig","resolvedMap","setResolvedMap","settled","setSettled","clientRef","configKeyRef","configKey","storeDomain","apiVersion","current","entityIds","map","e","lookup","join","ignore","client","entityLookups","key","toFetch","filter","_ref","has","cached","forEach","_ref2","item","get","set","fetchAll","Promise","allSettled","_ref3","itemData","finalMap","_ref4","enrichedEntities","loading"],"sources":["../../../src/hooks/useResolveShopifyEntityData.ts"],"sourcesContent":["import { useState, useEffect, useMemo, useRef } from 'react';\nimport { ShopifyStorefrontClient } from '../services/shopify/shopifyStorefrontClient';\nimport { resolveShopifyEntity } from '../services/shopify/shopifyEntityResolver';\nimport { transformShopifyEntityToItemData } from '../services/shopify/transformShopifyEntity';\nimport type { ShopifyStorefrontConfig } from '../services/shopify/types';\nimport type { EntityItemData } from '../component/types';\n\n// Session-level cache: entityType:entityId → resolved EntityItemData\nconst shopifyEntityCache = new Map<string, EntityItemData>();\n\nfunction cacheKey(entityType: string, entityId: string): string {\n return `${entityType}:${entityId}`;\n}\n\nfunction normalizeShopifyEntityType(entityType: string): string {\n const lower = entityType.toLowerCase();\n if (lower.includes('product')) {\n return 'product';\n }\n if (lower.includes('collection')) {\n return 'collection';\n }\n if (lower.includes('article') || lower.includes('blog')) {\n return 'article';\n }\n return entityType;\n}\n\nfunction extractHandleFromUrl(url: string | undefined): string | undefined {\n const trimmed = url?.trim();\n if (!trimmed) {\n return undefined;\n }\n\n let pathname = trimmed;\n try {\n if (/^https?:\\/\\//i.test(trimmed)) {\n pathname = new URL(trimmed).pathname;\n }\n } catch {\n pathname = trimmed;\n }\n\n const withoutQuery = pathname.split(/[?#]/)[0];\n const withoutLeadingSlash = withoutQuery.replace(/^\\/+/, '');\n const productsIndex = withoutLeadingSlash.indexOf('products/');\n if (productsIndex >= 0) {\n return withoutLeadingSlash.slice(productsIndex + 'products/'.length);\n }\n\n const collectionsIndex = withoutLeadingSlash.indexOf('collections/');\n if (collectionsIndex >= 0) {\n return withoutLeadingSlash.slice(\n collectionsIndex + 'collections/'.length,\n );\n }\n\n return withoutLeadingSlash || undefined;\n}\n\nfunction getShopifyLookup(entity: {\n entityId: string;\n entityType: string;\n data?: EntityItemData;\n}) {\n const entityType = normalizeShopifyEntityType(entity.entityType);\n const urlHandle = extractHandleFromUrl(entity.data?.url);\n const entityId =\n (entityType === 'product' || entityType === 'collection') && urlHandle\n ? urlHandle\n : entity.entityId;\n return { entityType, entityId };\n}\n\nexport function mergeShopifyEntityData(\n existing: EntityItemData | undefined,\n resolved: EntityItemData,\n): EntityItemData {\n if (!existing) {\n return resolved;\n }\n\n return {\n ...existing,\n ...resolved,\n url: existing.url || resolved.url,\n };\n}\n\n/**\n * Shopify-specific implementation of the entity resolution pattern.\n *\n * Fetches entity data from the Shopify Storefront API (tokenless) and\n * transforms it to the standard EntityItemData shape.\n *\n * Designed to be plugged into ComponentDependencies.useResolveGenericEntityData.\n */\nexport function useResolveShopifyEntityData<\n TEntity extends {\n entityId: string;\n entityUrl: string;\n entityType: string;\n data?: EntityItemData;\n },\n>(\n entities: TEntity[],\n shopifyConfig: ShopifyStorefrontConfig,\n): { enrichedEntities: TEntity[]; loading: boolean } {\n const [resolvedMap, setResolvedMap] = useState<Map<string, EntityItemData>>(\n new Map(),\n );\n const [settled, setSettled] = useState(false);\n\n // Stable client reference — recreated only when config changes\n const clientRef = useRef<ShopifyStorefrontClient | null>(null);\n const configKeyRef = useRef('');\n const configKey = `${shopifyConfig.storeDomain}|${\n shopifyConfig.apiVersion || ''\n }`;\n\n if (!clientRef.current || configKeyRef.current !== configKey) {\n clientRef.current = new ShopifyStorefrontClient(shopifyConfig);\n configKeyRef.current = configKey;\n }\n\n const entityIds = useMemo(\n () =>\n entities\n .map((e) => {\n const lookup = getShopifyLookup(e);\n return `${e.entityType}:${e.entityId}:${lookup.entityType}:${lookup.entityId}`;\n })\n .join(','),\n [entities],\n );\n\n useEffect(() => {\n let ignore = false;\n const client = clientRef.current;\n\n if (!entities.length || !client || !shopifyConfig.storeDomain) {\n setSettled(true);\n return;\n }\n\n const entityLookups = entities.map((entity) => {\n const lookup = getShopifyLookup(entity);\n return {\n entity,\n lookup,\n key: cacheKey(lookup.entityType, lookup.entityId),\n };\n });\n\n // Identify entities that need fetching. Payload data can provide the handle.\n const toFetch = entityLookups.filter(\n ({ key }) => !shopifyEntityCache.has(key),\n );\n\n // If everything is cached, resolve immediately\n if (toFetch.length === 0) {\n const cached = new Map<string, EntityItemData>();\n entityLookups.forEach(({ entity, key }) => {\n const item = shopifyEntityCache.get(key);\n if (item) {\n cached.set(entity.entityId, mergeShopifyEntityData(entity.data, item));\n }\n });\n setResolvedMap(cached);\n setSettled(true);\n return;\n }\n\n setSettled(false);\n\n const fetchAll = async () => {\n await Promise.allSettled(\n toFetch.map(async ({ entity, lookup, key }) => {\n const resolved = await resolveShopifyEntity(\n client,\n lookup.entityType,\n lookup.entityId,\n shopifyConfig,\n );\n if (resolved) {\n const itemData = transformShopifyEntityToItemData(\n resolved,\n lookup.entityType,\n );\n shopifyEntityCache.set(\n key,\n mergeShopifyEntityData(entity.data, itemData),\n );\n }\n }),\n );\n\n if (ignore) {\n return;\n }\n\n // Build the resolved map from cache\n const finalMap = new Map<string, EntityItemData>();\n entityLookups.forEach(({ entity, key }) => {\n const item = shopifyEntityCache.get(key);\n if (item) {\n finalMap.set(\n entity.entityId,\n mergeShopifyEntityData(entity.data, item),\n );\n }\n });\n\n setResolvedMap(finalMap);\n setSettled(true);\n };\n\n fetchAll();\n return () => {\n ignore = true;\n };\n }, [entityIds, shopifyConfig.storeDomain]);\n\n // Merge resolved data into entities\n const enrichedEntities = useMemo(() => {\n return entities.map((entity) => {\n const resolved = resolvedMap.get(entity.entityId);\n if (resolved) {\n return { ...entity, data: resolved };\n }\n return entity;\n });\n }, [entities, resolvedMap]);\n\n return { enrichedEntities, loading: !settled };\n}\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAC5D,SAASC,uBAAuB,QAAQ,6CAA6C;AACrF,SAASC,oBAAoB,QAAQ,2CAA2C;AAChF,SAASC,gCAAgC,QAAQ,4CAA4C;AAI7F;AACA,MAAMC,kBAAkB,GAAG,IAAIC,GAAG,CAAyB,CAAC;AAE5D,SAASC,QAAQA,CAACC,UAAkB,EAAEC,QAAgB,EAAU;EAC9D,OAAO,GAAGD,UAAU,IAAIC,QAAQ,EAAE;AACpC;AAEA,SAASC,0BAA0BA,CAACF,UAAkB,EAAU;EAC9D,MAAMG,KAAK,GAAGH,UAAU,CAACI,WAAW,CAAC,CAAC;EACtC,IAAID,KAAK,CAACE,QAAQ,CAAC,SAAS,CAAC,EAAE;IAC7B,OAAO,SAAS;EAClB;EACA,IAAIF,KAAK,CAACE,QAAQ,CAAC,YAAY,CAAC,EAAE;IAChC,OAAO,YAAY;EACrB;EACA,IAAIF,KAAK,CAACE,QAAQ,CAAC,SAAS,CAAC,IAAIF,KAAK,CAACE,QAAQ,CAAC,MAAM,CAAC,EAAE;IACvD,OAAO,SAAS;EAClB;EACA,OAAOL,UAAU;AACnB;AAE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ACG,IAAI,EAAEiC,IAAI,CAC1C,CAAC;QACH;MACF,CAAC,CAAC;MAEFzB,cAAc,CAACiC,QAAQ,CAAC;MACxB/B,UAAU,CAAC,IAAI,CAAC;IAClB,CAAC;IAED0B,QAAQ,CAAC,CAAC;IACV,OAAO,MAAM;MACXd,MAAM,GAAG,IAAI;IACf,CAAC;EACH,CAAC,EAAE,CAACL,SAAS,EAAEX,aAAa,CAACQ,WAAW,CAAC,CAAC;;EAE1C;EACA,MAAM6B,gBAAgB,GAAG9E,OAAO,CAAC,MAAM;IACrC,OAAOwC,QAAQ,CAACa,GAAG,CAAErB,MAAM,IAAK;MAC9B,MAAMM,QAAQ,GAAGI,WAAW,CAAC2B,GAAG,CAACrC,MAAM,CAACvB,QAAQ,CAAC;MACjD,IAAI6B,QAAQ,EAAE;QACZ,OAAO;UAAE,GAAGN,MAAM;UAAEG,IAAI,EAAEG;QAAS,CAAC;MACtC;MACA,OAAON,MAAM;IACf,CAAC,CAAC;EACJ,CAAC,EAAE,CAACQ,QAAQ,EAAEE,WAAW,CAAC,CAAC;EAE3B,OAAO;IAAEoC,gBAAgB;IAAEC,OAAO,EAAE,CAACnC;EAAQ,CAAC;AAChD","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useState","useEffect","useMemo","useRef","ShopifyStorefrontClient","resolveShopifyEntity","transformShopifyEntityToItemData","shopifyEntityCache","Map","cacheKey","entityType","entityId","variantId","normalizeShopifyEntityType","lower","toLowerCase","includes","extractHandleFromUrl","url","trimmed","trim","undefined","pathname","test","URL","withoutQuery","split","withoutLeadingSlash","replace","productsIndex","indexOf","slice","length","collectionsIndex","getShopifyLookup","entity","_entity$data","_entity$data2","urlHandle","data","mergeShopifyEntityData","existing","resolved","_existing$matchedOpti","title","imageUrl","matchedOptions","useResolveShopifyEntityData","entities","shopifyConfig","resolvedMap","setResolvedMap","settled","setSettled","clientRef","configKeyRef","configKey","storeDomain","apiVersion","current","entityIds","map","e","lookup","join","ignore","client","entityLookups","key","toFetch","filter","_ref","has","cached","forEach","_ref2","item","get","set","fetchAll","Promise","allSettled","_ref3","itemData","finalMap","_ref4","enrichedEntities","loading"],"sources":["../../../src/hooks/useResolveShopifyEntityData.ts"],"sourcesContent":["import { useState, useEffect, useMemo, useRef } from 'react';\nimport { ShopifyStorefrontClient } from '../services/shopify/shopifyStorefrontClient';\nimport { resolveShopifyEntity } from '../services/shopify/shopifyEntityResolver';\nimport { transformShopifyEntityToItemData } from '../services/shopify/transformShopifyEntity';\nimport type { ShopifyStorefrontConfig } from '../services/shopify/types';\nimport type { EntityItemData } from '../component/types';\n\n// Session-level cache: entityType:entityId:variantId → resolved EntityItemData\nconst shopifyEntityCache = new Map<string, EntityItemData>();\n\nfunction cacheKey(\n entityType: string,\n entityId: string,\n variantId?: string,\n): string {\n return `${entityType}:${entityId}:${variantId || ''}`;\n}\n\nfunction normalizeShopifyEntityType(entityType: string): string {\n const lower = entityType.toLowerCase();\n if (lower.includes('product')) {\n return 'product';\n }\n if (lower.includes('collection')) {\n return 'collection';\n }\n if (lower.includes('article') || lower.includes('blog')) {\n return 'article';\n }\n return entityType;\n}\n\nfunction extractHandleFromUrl(url: string | undefined): string | undefined {\n const trimmed = url?.trim();\n if (!trimmed) {\n return undefined;\n }\n\n let pathname = trimmed;\n try {\n if (/^https?:\\/\\//i.test(trimmed)) {\n pathname = new URL(trimmed).pathname;\n }\n } catch {\n pathname = trimmed;\n }\n\n const withoutQuery = pathname.split(/[?#]/)[0];\n const withoutLeadingSlash = withoutQuery.replace(/^\\/+/, '');\n const productsIndex = withoutLeadingSlash.indexOf('products/');\n if (productsIndex >= 0) {\n return withoutLeadingSlash.slice(productsIndex + 'products/'.length);\n }\n\n const collectionsIndex = withoutLeadingSlash.indexOf('collections/');\n if (collectionsIndex >= 0) {\n return withoutLeadingSlash.slice(\n collectionsIndex + 'collections/'.length,\n );\n }\n\n return withoutLeadingSlash || undefined;\n}\n\nfunction getShopifyLookup(entity: {\n entityId: string;\n entityType: string;\n data?: EntityItemData;\n}) {\n const entityType = normalizeShopifyEntityType(entity.entityType);\n const urlHandle = extractHandleFromUrl(entity.data?.url);\n const entityId =\n (entityType === 'product' || entityType === 'collection') && urlHandle\n ? urlHandle\n : entity.entityId;\n return { entityType, entityId, variantId: entity.data?.variantId };\n}\n\n/**\n * The turn owns WHICH thing to show; the live fetch owns VOLATILE FACTS about\n * it.\n *\n * Only the turn saw the shopper's question, so only it knows that the brown\n * variant was the one asked for — its `title`, `imageUrl`, `url`,\n * `matchedOptions` and `variantId` all describe that one variant and must\n * survive enrichment. Everything the Storefront answers with that can go stale\n * between the turn and the render — `price`, `compareAtPrice`, `available`,\n * `priceMin`, `priceMax` — comes from `resolved`.\n */\nexport function mergeShopifyEntityData(\n existing: EntityItemData | undefined,\n resolved: EntityItemData,\n): EntityItemData {\n if (!existing) {\n return resolved;\n }\n\n return {\n ...existing,\n ...resolved,\n url: existing.url || resolved.url,\n title: existing.title || resolved.title,\n imageUrl: existing.imageUrl || resolved.imageUrl,\n variantId: existing.variantId || resolved.variantId,\n matchedOptions: existing.matchedOptions?.length\n ? existing.matchedOptions\n : resolved.matchedOptions,\n };\n}\n\n/**\n * Shopify-specific implementation of the entity resolution pattern.\n *\n * Fetches entity data from the Shopify Storefront API (tokenless) and\n * transforms it to the standard EntityItemData shape.\n *\n * Designed to be plugged into ComponentDependencies.useResolveGenericEntityData.\n */\nexport function useResolveShopifyEntityData<\n TEntity extends {\n entityId: string;\n entityUrl: string;\n entityType: string;\n data?: EntityItemData;\n },\n>(\n entities: TEntity[],\n shopifyConfig: ShopifyStorefrontConfig,\n): { enrichedEntities: TEntity[]; loading: boolean } {\n const [resolvedMap, setResolvedMap] = useState<Map<string, EntityItemData>>(\n new Map(),\n );\n const [settled, setSettled] = useState(false);\n\n // Stable client reference — recreated only when config changes\n const clientRef = useRef<ShopifyStorefrontClient | null>(null);\n const configKeyRef = useRef('');\n const configKey = `${shopifyConfig.storeDomain}|${\n shopifyConfig.apiVersion || ''\n }`;\n\n if (!clientRef.current || configKeyRef.current !== configKey) {\n clientRef.current = new ShopifyStorefrontClient(shopifyConfig);\n configKeyRef.current = configKey;\n }\n\n const entityIds = useMemo(\n () =>\n entities\n .map((e) => {\n const lookup = getShopifyLookup(e);\n return `${e.entityType}:${e.entityId}:${cacheKey(\n lookup.entityType,\n lookup.entityId,\n lookup.variantId,\n )}`;\n })\n .join(','),\n [entities],\n );\n\n useEffect(() => {\n let ignore = false;\n const client = clientRef.current;\n\n if (!entities.length || !client || !shopifyConfig.storeDomain) {\n setSettled(true);\n return;\n }\n\n const entityLookups = entities.map((entity) => {\n const lookup = getShopifyLookup(entity);\n return {\n entity,\n lookup,\n // The variant is part of the key: the cached entry carries that\n // variant's live price, so two entities on the same product but\n // different variants must not share it.\n key: cacheKey(lookup.entityType, lookup.entityId, lookup.variantId),\n };\n });\n\n // Identify entities that need fetching. Payload data can provide the handle.\n const toFetch = entityLookups.filter(\n ({ key }) => !shopifyEntityCache.has(key),\n );\n\n // If everything is cached, resolve immediately\n if (toFetch.length === 0) {\n const cached = new Map<string, EntityItemData>();\n entityLookups.forEach(({ entity, key }) => {\n const item = shopifyEntityCache.get(key);\n if (item) {\n cached.set(entity.entityId, mergeShopifyEntityData(entity.data, item));\n }\n });\n setResolvedMap(cached);\n setSettled(true);\n return;\n }\n\n setSettled(false);\n\n const fetchAll = async () => {\n await Promise.allSettled(\n toFetch.map(async ({ entity, lookup, key }) => {\n const resolved = await resolveShopifyEntity(\n client,\n lookup.entityType,\n lookup.entityId,\n shopifyConfig,\n );\n if (resolved) {\n const itemData = transformShopifyEntityToItemData(\n resolved,\n lookup.entityType,\n lookup.variantId,\n );\n shopifyEntityCache.set(\n key,\n mergeShopifyEntityData(entity.data, itemData),\n );\n }\n }),\n );\n\n if (ignore) {\n return;\n }\n\n // Build the resolved map from cache\n const finalMap = new Map<string, EntityItemData>();\n entityLookups.forEach(({ entity, key }) => {\n const item = shopifyEntityCache.get(key);\n if (item) {\n finalMap.set(\n entity.entityId,\n mergeShopifyEntityData(entity.data, item),\n );\n }\n });\n\n setResolvedMap(finalMap);\n setSettled(true);\n };\n\n fetchAll();\n return () => {\n ignore = true;\n };\n }, [entityIds, shopifyConfig.storeDomain]);\n\n // Merge resolved data into entities\n const enrichedEntities = useMemo(() => {\n return entities.map((entity) => {\n const resolved = resolvedMap.get(entity.entityId);\n if (resolved) {\n return { ...entity, data: resolved };\n }\n return entity;\n });\n }, [entities, resolvedMap]);\n\n return { enrichedEntities, loading: !settled };\n}\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAC5D,SAASC,uBAAuB,QAAQ,6CAA6C;AACrF,SAASC,oBAAoB,QAAQ,2CAA2C;AAChF,SAASC,gCAAgC,QAAQ,4CAA4C;AAI7F;AACA,MAAMC,kBAAkB,GAAG,IAAIC,GAAG,CAAyB,CAAC;AAE5D,SAASC,QAAQA,CACfC,UAAkB,EAClBC,QAAgB,EAChBC,SAAkB,EACV;EACR,OAAO,GAAGF,UAAU,IAAIC,QAAQ,IAAIC,SAAS,IAAI,EAAE,EAAE;AACvD;AAEA,SAASC,0BAA0BA,CAACH,UAAkB,EAAU;EAC9D,MAAMI,KAAK,GAAGJ,UAAU,CAACK,WAAW,CAAC,CAAC;EACtC,IAAID,KAAK,CAACE,QAAQ,CAAC,SAAS,CAAC,EAAE;IAC7B,OAAO,SAAS;EAClB;EACA,IAAIF,KAAK,CAACE,QAAQ,CAAC,YAAY,CAAC,EAAE;IAChC,OAAO,YAAY;EACrB;EACA,IAAIF,KAAK,CAACE,QAAQ,CAAC,SAAS,CAAC,IAAIF,KAAK,CAACE,QAAQ,CAAC,MAAM,CAAC,EAAE;IACvD,OAAO,SAAS;EAClB;EACA,OAAON,UAAU;AACnB;AAEA,SAASO,oBAAoBA,CAACC,GAAuB,EAAsB;EACzE,MAAMC,OAAO,GAAGD,GAAG,oBAAHA,GAAG,CAAEE,IAAI,CAAC,CAAC;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EAAE,CAACnC;EAAQ,CAAC;AAChD","ignoreList":[]}
|
|
@@ -64,8 +64,25 @@ function getCompareAtPrice(product) {
|
|
|
64
64
|
}
|
|
65
65
|
return formatPrice(compare);
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The live entry for the variant the turn resolved, if the store still has it.
|
|
70
|
+
* Both sides carry the bare numeric id — `extractVariants` strips the
|
|
71
|
+
* `gid://shopify/ProductVariant/` prefix, and the turn never adds one.
|
|
72
|
+
*/
|
|
73
|
+
function findLiveVariant(variants, variantId) {
|
|
74
|
+
if (!variantId) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
return variants == null ? void 0 : variants.find(variant => variant.variantId === variantId);
|
|
78
|
+
}
|
|
79
|
+
export function transformShopifyProduct(product, variantId) {
|
|
68
80
|
var _product$featuredImag, _product$options;
|
|
81
|
+
const variants = extractVariants(product);
|
|
82
|
+
// The turn decided WHICH variant to show; the live fetch is here for what is
|
|
83
|
+
// true about it right now. With no matched variant — or one the store has
|
|
84
|
+
// since dropped — the product-level range is still the only answer we have.
|
|
85
|
+
const matchedVariant = findLiveVariant(variants, variantId);
|
|
69
86
|
return {
|
|
70
87
|
url: product.onlineStoreUrl || '',
|
|
71
88
|
title: product.title,
|
|
@@ -74,10 +91,14 @@ export function transformShopifyProduct(product) {
|
|
|
74
91
|
imageUrl: (_product$featuredImag = product.featuredImage) == null ? void 0 : _product$featuredImag.url,
|
|
75
92
|
secondaryImageUrl: getSecondaryImage(product),
|
|
76
93
|
vendor: product.vendor,
|
|
77
|
-
price: formatPrice(product.priceRange.minVariantPrice),
|
|
78
|
-
|
|
94
|
+
price: (matchedVariant == null ? void 0 : matchedVariant.price) || formatPrice(product.priceRange.minVariantPrice),
|
|
95
|
+
// Keyed on the variant, not on its value: an unmatched product falls back
|
|
96
|
+
// to the product-level compare-at, but a matched variant that is simply
|
|
97
|
+
// not on sale must not inherit one and print a false strikethrough.
|
|
98
|
+
compareAtPrice: matchedVariant ? matchedVariant.compareAtPrice : getCompareAtPrice(product),
|
|
99
|
+
available: matchedVariant == null ? void 0 : matchedVariant.available,
|
|
79
100
|
sizes: extractSizes(product),
|
|
80
|
-
variants
|
|
101
|
+
variants,
|
|
81
102
|
allImages: getAllImages(product),
|
|
82
103
|
options: (_product$options = product.options) != null && _product$options.length ? product.options : undefined,
|
|
83
104
|
tags: product.tags.length ? product.tags : undefined
|
|
@@ -111,10 +132,10 @@ export function transformShopifyArticle(article) {
|
|
|
111
132
|
* Transform any resolved Shopify entity to the standard EntityItemData shape.
|
|
112
133
|
* Detects the entity type by checking for type-specific fields.
|
|
113
134
|
*/
|
|
114
|
-
export function transformShopifyEntityToItemData(entity, entityType) {
|
|
135
|
+
export function transformShopifyEntityToItemData(entity, entityType, variantId) {
|
|
115
136
|
switch (entityType.toLowerCase()) {
|
|
116
137
|
case 'product':
|
|
117
|
-
return transformShopifyProduct(entity);
|
|
138
|
+
return transformShopifyProduct(entity, variantId);
|
|
118
139
|
case 'collection':
|
|
119
140
|
return transformShopifyCollection(entity);
|
|
120
141
|
case 'article':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["formatShopifyDate","isoDate","date","Date","isNaN","getTime","undefined","day","getDate","month","toLocaleString","year","getFullYear","formatPrice","money","amount","parseFloat","formatted","toFixed","currencyCode","extractSizes","product","sizes","variants","edges","flatMap","e","node","selectedOptions","filter","o","name","toLowerCase","map","value","unique","Set","length","extractVariants","sizeOption","find","numericId","id","replace","label","title","variantId","available","availableForSale","price","compareAtPrice","getSecondaryImage","images","url","getAllImages","getCompareAtPrice","_product$compareAtPri","compare","compareAtPriceRange","minVariantPrice","min","priceRange","transformShopifyProduct","_product$featuredImag","_product$options","onlineStoreUrl","type","description","imageUrl","featuredImage","secondaryImageUrl","vendor","allImages","options","tags","transformShopifyCollection","collection","_collection$image","image","transformShopifyArticle","article","_article$image","_article$authorV","excerpt","publishDate","publishedAt","author","authorV2","transformShopifyEntityToItemData","entity","entityType"],"sources":["../../../../src/services/shopify/transformShopifyEntity.ts"],"sourcesContent":["import type { EntityItemData } from '../../component/types';\nimport type {\n ShopifyProduct,\n ShopifyCollection,\n ShopifyArticle,\n} from './types';\n\nfunction formatShopifyDate(isoDate: string): string | undefined {\n const date = new Date(isoDate);\n if (isNaN(date.getTime())) {\n return undefined;\n }\n const day = date.getDate();\n const month = date.toLocaleString('en-US', { month: 'short' });\n const year = date.getFullYear();\n return `${day} ${month} ${year}`;\n}\n\nfunction formatPrice(\n money: ShopifyProduct['priceRange']['minVariantPrice'],\n): string {\n const amount = parseFloat(money.amount);\n const formatted = amount.toFixed(2);\n return `${formatted} ${money.currencyCode}`;\n}\n\nfunction extractSizes(product: ShopifyProduct): string[] | undefined {\n const sizes = product.variants.edges.flatMap((e) =>\n e.node.selectedOptions\n .filter((o) => o.name.toLowerCase() === 'size')\n .map((o) => o.value),\n );\n const unique = [...new Set(sizes)];\n return unique.length > 0 ? unique : undefined;\n}\n\n/**\n * Extract variant ID → size label mapping for add-to-cart.\n * Shopify global IDs look like \"gid://shopify/ProductVariant/12345\" —\n * we extract just the numeric part for the Ajax API.\n */\nfunction extractVariants(product: ShopifyProduct): EntityItemData['variants'] {\n const variants = product.variants.edges.map((e) => {\n const sizeOption = e.node.selectedOptions.find(\n (o) => o.name.toLowerCase() === 'size',\n );\n const numericId = e.node.id.replace(\n /^gid:\\/\\/shopify\\/ProductVariant\\//,\n '',\n );\n return {\n label: sizeOption?.value || e.node.title,\n variantId: numericId,\n available: e.node.availableForSale,\n selectedOptions: e.node.selectedOptions.map((o) => ({\n name: o.name,\n value: o.value,\n })),\n price: formatPrice(e.node.price),\n compareAtPrice: e.node.compareAtPrice\n ? formatPrice(e.node.compareAtPrice)\n : undefined,\n };\n });\n return variants.length > 0 ? variants : undefined;\n}\n\nfunction getSecondaryImage(product: ShopifyProduct): string | undefined {\n const images = product.images.edges.map((e) => e.node.url);\n return images.length > 1 ? images[1] : undefined;\n}\n\nfunction getAllImages(product: ShopifyProduct): string[] | undefined {\n const images = product.images.edges.map((e) => e.node.url);\n return images.length > 0 ? images : undefined;\n}\n\nfunction getCompareAtPrice(product: ShopifyProduct): string | undefined {\n const compare = product.compareAtPriceRange?.minVariantPrice;\n if (!compare) {\n return undefined;\n }\n const min = product.priceRange.minVariantPrice;\n if (parseFloat(compare.amount) <= parseFloat(min.amount)) {\n return undefined;\n }\n return formatPrice(compare);\n}\n\nexport function transformShopifyProduct(\n product: ShopifyProduct,\n): EntityItemData {\n return {\n url: product.onlineStoreUrl || '',\n title: product.title,\n type: 'product',\n description: product.description,\n imageUrl: product.featuredImage?.url,\n secondaryImageUrl: getSecondaryImage(product),\n vendor: product.vendor,\n price: formatPrice(product.priceRange.minVariantPrice),\n compareAtPrice: getCompareAtPrice(product),\n sizes: extractSizes(product),\n variants: extractVariants(product),\n allImages: getAllImages(product),\n options: product.options?.length ? product.options : undefined,\n tags: product.tags.length ? product.tags : undefined,\n };\n}\n\nexport function transformShopifyCollection(\n collection: ShopifyCollection,\n): EntityItemData {\n return {\n url: collection.onlineStoreUrl || '',\n title: collection.title,\n type: 'collection',\n description: collection.description,\n imageUrl: collection.image?.url,\n };\n}\n\nexport function transformShopifyArticle(\n article: ShopifyArticle,\n): EntityItemData {\n return {\n url: article.onlineStoreUrl || '',\n title: article.title,\n type: 'article',\n description: article.excerpt || undefined,\n imageUrl: article.image?.url,\n publishDate: formatShopifyDate(article.publishedAt),\n author: article.authorV2?.name || undefined,\n tags: article.tags.length ? article.tags : undefined,\n };\n}\n\n/**\n * Transform any resolved Shopify entity to the standard EntityItemData shape.\n * Detects the entity type by checking for type-specific fields.\n */\nexport function transformShopifyEntityToItemData(\n entity: ShopifyProduct | ShopifyCollection | ShopifyArticle,\n entityType: string,\n): EntityItemData {\n switch (entityType.toLowerCase()) {\n case 'product':\n return transformShopifyProduct(entity as ShopifyProduct);\n case 'collection':\n return transformShopifyCollection(entity as ShopifyCollection);\n case 'article':\n return transformShopifyArticle(entity as ShopifyArticle);\n default:\n return {\n url: '',\n title: (entity as { title?: string }).title || '',\n type: entityType,\n };\n }\n}\n"],"mappings":"AAOA,SAASA,iBAAiBA,CAACC,OAAe,EAAsB;EAC9D,MAAMC,IAAI,GAAG,IAAIC,IAAI,CAACF,OAAO,CAAC;EAC9B,IAAIG,KAAK,CAACF,IAAI,CAACG,OAAO,CAAC,CAAC,CAAC,EAAE;IACzB,OAAOC,SAAS;EAClB;EACA,MAAMC,GAAG,GAAGL,IAAI,CAACM,OAAO,CAAC,CAAC;EAC1B,MAAMC,KAAK,GAAGP,IAAI,CAACQ,cAAc,CAAC,OAAO,EAAE;IAAED,KAAK,EAAE;EAAQ,CAAC,CAAC;EAC9D,MAAME,IAAI,GAAGT,IAAI,CAACU,WAAW,CAAC,CAAC;EAC/B,OAAO,GAAGL,GAAG,IAAIE,KAAK,IAAIE,IAAI,EAAE;AAClC;AAEA,SAASE,WAAWA,CAClBC,KAAsD,EAC9C;EACR,MAAMC,MAAM,GAAGC,UAAU,CAACF,KAAK,CAACC,MAAM,CAAC;EACvC,MAAME,SAAS,GAAGF,MAAM,CAACG,OAAO,CAAC,CAAC,CAAC;EACnC,OAAO,GAAGD,SAAS,IAAIH,KAAK,CAACK,YAAY,EAAE;AAC7C;AAEA,SAASC,YAAYA,CAACC,OAAuB,EAAwB;EACnE,MAAMC,KAAK,GAAGD,OAAO,CAACE,QAAQ,CAACC,KAAK,CAACC,OAAO,CAAEC,CAAC,IAC7CA,CAAC,CAACC,IAAI,CAACC,eAAe,CACnBC,MAAM,CAAEC,CAAC,IAAKA,CAAC,CAACC,IAAI,CAACC,WAAW,CAAC,CAAC,KAAK,MAAM,CAAC,CAC9CC,GAAG,CAAEH,CAAC,IAAKA,CAAC,CAACI,KAAK,CACvB,CAAC;EACD,MAAMC,MAAM,GAAG,CAAC,GAAG,IAAIC,GAAG,CAACd,KAAK,CAAC,CAAC;EAClC,OAAOa,MAAM,CAACE,MAAM,GAAG,CAAC,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,qBAAbG,cAAA,CAAe5B,GAAG;IAC5B+B,WAAW,EAAEpF,iBAAiB,CAACgF,OAAO,CAACK,WAAW,CAAC;IACnDC,MAAM,EAAE,EAAAJ,gBAAA,GAAAF,OAAO,CAACO,QAAQ,qBAAhBL,gBAAA,CAAkBnD,IAAI,KAAIzB,SAAS;IAC3CoE,IAAI,EAAEM,OAAO,CAACN,IAAI,CAACrC,MAAM,GAAG2C,OAAO,CAACN,IAAI,GAAGpE;EAC7C,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASkF,gCAAgCA,CAC9CC,MAA2D,EAC3DC,UAAkB,EACF;EAChB,QAAQA,UAAU,CAAC1D,WAAW,CAAC,CAAC;IAC9B,KAAK,SAAS;MACZ,OAAO8B,uBAAuB,CAAC2B,MAAwB,CAAC;IAC1D,KAAK,YAAY;MACf,OAAOd,0BAA0B,CAACc,MAA2B,CAAC;IAChE,KAAK,SAAS;MACZ,OAAOV,uBAAuB,CAACU,MAAwB,CAAC;IAC1D;MACE,OAAO;QACLpC,GAAG,EAAE,EAAE;QACPR,KAAK,EAAG4C,MAAM,CAAwB5C,KAAK,IAAI,EAAE;QACjDqB,IAAI,EAAEwB;MACR,CAAC;EACL;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["formatShopifyDate","isoDate","date","Date","isNaN","getTime","undefined","day","getDate","month","toLocaleString","year","getFullYear","formatPrice","money","amount","parseFloat","formatted","toFixed","currencyCode","extractSizes","product","sizes","variants","edges","flatMap","e","node","selectedOptions","filter","o","name","toLowerCase","map","value","unique","Set","length","extractVariants","sizeOption","find","numericId","id","replace","label","title","variantId","available","availableForSale","price","compareAtPrice","getSecondaryImage","images","url","getAllImages","getCompareAtPrice","_product$compareAtPri","compare","compareAtPriceRange","minVariantPrice","min","priceRange","findLiveVariant","variant","transformShopifyProduct","_product$featuredImag","_product$options","matchedVariant","onlineStoreUrl","type","description","imageUrl","featuredImage","secondaryImageUrl","vendor","allImages","options","tags","transformShopifyCollection","collection","_collection$image","image","transformShopifyArticle","article","_article$image","_article$authorV","excerpt","publishDate","publishedAt","author","authorV2","transformShopifyEntityToItemData","entity","entityType"],"sources":["../../../../src/services/shopify/transformShopifyEntity.ts"],"sourcesContent":["import type { EntityItemData } from '../../component/types';\nimport type {\n ShopifyProduct,\n ShopifyCollection,\n ShopifyArticle,\n} from './types';\n\nfunction formatShopifyDate(isoDate: string): string | undefined {\n const date = new Date(isoDate);\n if (isNaN(date.getTime())) {\n return undefined;\n }\n const day = date.getDate();\n const month = date.toLocaleString('en-US', { month: 'short' });\n const year = date.getFullYear();\n return `${day} ${month} ${year}`;\n}\n\nfunction formatPrice(\n money: ShopifyProduct['priceRange']['minVariantPrice'],\n): string {\n const amount = parseFloat(money.amount);\n const formatted = amount.toFixed(2);\n return `${formatted} ${money.currencyCode}`;\n}\n\nfunction extractSizes(product: ShopifyProduct): string[] | undefined {\n const sizes = product.variants.edges.flatMap((e) =>\n e.node.selectedOptions\n .filter((o) => o.name.toLowerCase() === 'size')\n .map((o) => o.value),\n );\n const unique = [...new Set(sizes)];\n return unique.length > 0 ? unique : undefined;\n}\n\n/**\n * Extract variant ID → size label mapping for add-to-cart.\n * Shopify global IDs look like \"gid://shopify/ProductVariant/12345\" —\n * we extract just the numeric part for the Ajax API.\n */\nfunction extractVariants(product: ShopifyProduct): EntityItemData['variants'] {\n const variants = product.variants.edges.map((e) => {\n const sizeOption = e.node.selectedOptions.find(\n (o) => o.name.toLowerCase() === 'size',\n );\n const numericId = e.node.id.replace(\n /^gid:\\/\\/shopify\\/ProductVariant\\//,\n '',\n );\n return {\n label: sizeOption?.value || e.node.title,\n variantId: numericId,\n available: e.node.availableForSale,\n selectedOptions: e.node.selectedOptions.map((o) => ({\n name: o.name,\n value: o.value,\n })),\n price: formatPrice(e.node.price),\n compareAtPrice: e.node.compareAtPrice\n ? formatPrice(e.node.compareAtPrice)\n : undefined,\n };\n });\n return variants.length > 0 ? variants : undefined;\n}\n\nfunction getSecondaryImage(product: ShopifyProduct): string | undefined {\n const images = product.images.edges.map((e) => e.node.url);\n return images.length > 1 ? images[1] : undefined;\n}\n\nfunction getAllImages(product: ShopifyProduct): string[] | undefined {\n const images = product.images.edges.map((e) => e.node.url);\n return images.length > 0 ? images : undefined;\n}\n\nfunction getCompareAtPrice(product: ShopifyProduct): string | undefined {\n const compare = product.compareAtPriceRange?.minVariantPrice;\n if (!compare) {\n return undefined;\n }\n const min = product.priceRange.minVariantPrice;\n if (parseFloat(compare.amount) <= parseFloat(min.amount)) {\n return undefined;\n }\n return formatPrice(compare);\n}\n\n/**\n * The live entry for the variant the turn resolved, if the store still has it.\n * Both sides carry the bare numeric id — `extractVariants` strips the\n * `gid://shopify/ProductVariant/` prefix, and the turn never adds one.\n */\nfunction findLiveVariant(\n variants: EntityItemData['variants'],\n variantId: string | undefined,\n): NonNullable<EntityItemData['variants']>[number] | undefined {\n if (!variantId) {\n return undefined;\n }\n return variants?.find((variant) => variant.variantId === variantId);\n}\n\nexport function transformShopifyProduct(\n product: ShopifyProduct,\n variantId?: string,\n): EntityItemData {\n const variants = extractVariants(product);\n // The turn decided WHICH variant to show; the live fetch is here for what is\n // true about it right now. With no matched variant — or one the store has\n // since dropped — the product-level range is still the only answer we have.\n const matchedVariant = findLiveVariant(variants, variantId);\n\n return {\n url: product.onlineStoreUrl || '',\n title: product.title,\n type: 'product',\n description: product.description,\n imageUrl: product.featuredImage?.url,\n secondaryImageUrl: getSecondaryImage(product),\n vendor: product.vendor,\n price:\n matchedVariant?.price || formatPrice(product.priceRange.minVariantPrice),\n // Keyed on the variant, not on its value: an unmatched product falls back\n // to the product-level compare-at, but a matched variant that is simply\n // not on sale must not inherit one and print a false strikethrough.\n compareAtPrice: matchedVariant\n ? matchedVariant.compareAtPrice\n : getCompareAtPrice(product),\n available: matchedVariant?.available,\n sizes: extractSizes(product),\n variants,\n allImages: getAllImages(product),\n options: product.options?.length ? product.options : undefined,\n tags: product.tags.length ? product.tags : undefined,\n };\n}\n\nexport function transformShopifyCollection(\n collection: ShopifyCollection,\n): EntityItemData {\n return {\n url: collection.onlineStoreUrl || '',\n title: collection.title,\n type: 'collection',\n description: collection.description,\n imageUrl: collection.image?.url,\n };\n}\n\nexport function transformShopifyArticle(\n article: ShopifyArticle,\n): EntityItemData {\n return {\n url: article.onlineStoreUrl || '',\n title: article.title,\n type: 'article',\n description: article.excerpt || undefined,\n imageUrl: article.image?.url,\n publishDate: formatShopifyDate(article.publishedAt),\n author: article.authorV2?.name || undefined,\n tags: article.tags.length ? article.tags : undefined,\n };\n}\n\n/**\n * Transform any resolved Shopify entity to the standard EntityItemData shape.\n * Detects the entity type by checking for type-specific fields.\n */\nexport function transformShopifyEntityToItemData(\n entity: ShopifyProduct | ShopifyCollection | ShopifyArticle,\n entityType: string,\n variantId?: string,\n): EntityItemData {\n switch (entityType.toLowerCase()) {\n case 'product':\n return transformShopifyProduct(entity as ShopifyProduct, variantId);\n case 'collection':\n return transformShopifyCollection(entity as ShopifyCollection);\n case 'article':\n return transformShopifyArticle(entity as ShopifyArticle);\n default:\n return {\n url: '',\n title: (entity as { title?: string }).title || '',\n type: entityType,\n };\n }\n}\n"],"mappings":"AAOA,SAASA,iBAAiBA,CAACC,OAAe,EAAsB;EAC9D,MAAMC,IAAI,GAAG,IAAIC,IAAI,CAACF,OAAO,CAAC;EAC9B,IAAIG,KAAK,CAACF,IAAI,CAACG,OAAO,CAAC,CAAC,CAAC,EAAE;IACzB,OAAOC,SAAS;EAClB;EACA,MAAMC,GAAG,GAAGL,IAAI,CAACM,OAAO,CAAC,CAAC;EAC1B,MAAMC,KAAK,GAAGP,IAAI,CAACQ,cAAc,CAAC,OAAO,EAAE;IAAED,KAAK,EAAE;EAAQ,CAAC,CAAC;EAC9D,MAAME,IAAI,GAAGT,IAAI,CAACU,WAAW,CAAC,CAAC;EAC/B,OAAO,GAAGL,GAAG,IAAIE,KAAK,IAAIE,IAAI,EAAE;AAClC;AAEA,SAASE,WAAWA,CAClBC,KAAsD,EA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mF,OAAO,CAACK,WAAW,CAAC;IACnDC,MAAM,EAAE,EAAAJ,gBAAA,GAAAF,OAAO,CAACO,QAAQ,qBAAhBL,gBAAA,CAAkBtD,IAAI,KAAIzB,SAAS;IAC3CuE,IAAI,EAAEM,OAAO,CAACN,IAAI,CAACxC,MAAM,GAAG8C,OAAO,CAACN,IAAI,GAAGvE;EAC7C,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASqF,gCAAgCA,CAC9CC,MAA2D,EAC3DC,UAAkB,EAClB/C,SAAkB,EACF;EAChB,QAAQ+C,UAAU,CAAC7D,WAAW,CAAC,CAAC;IAC9B,KAAK,SAAS;MACZ,OAAOgC,uBAAuB,CAAC4B,MAAM,EAAoB9C,SAAS,CAAC;IACrE,KAAK,YAAY;MACf,OAAOgC,0BAA0B,CAACc,MAA2B,CAAC;IAChE,KAAK,SAAS;MACZ,OAAOV,uBAAuB,CAACU,MAAwB,CAAC;IAC1D;MACE,OAAO;QACLvC,GAAG,EAAE,EAAE;QACPR,KAAK,EAAG+C,MAAM,CAAwB/C,KAAK,IAAI,EAAE;QACjDwB,IAAI,EAAEwB;MACR,CAAC;EACL;AACF","ignoreList":[]}
|
|
@@ -84,6 +84,14 @@ export interface EntityItemData {
|
|
|
84
84
|
name: string;
|
|
85
85
|
value: string;
|
|
86
86
|
}[];
|
|
87
|
+
/**
|
|
88
|
+
* Id of the one variant a search matched — the same variant `imageUrl`,
|
|
89
|
+
* `url` and `matchedOptions` describe. Bare store id, no `gid://` prefix.
|
|
90
|
+
* A live enricher reads this to price that variant rather than the product.
|
|
91
|
+
*/
|
|
92
|
+
variantId?: string;
|
|
93
|
+
/** Whether the matched variant is in stock, as of the last live fetch */
|
|
94
|
+
available?: boolean;
|
|
87
95
|
/** Formatted lowest price across the product's variants (e.g. "$107.95") */
|
|
88
96
|
priceMin?: string;
|
|
89
97
|
/** Formatted highest price across the product's variants */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types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AY,CAAC,CAAC;AACnD,MAAM,MAAM,4BAA4B,GAAG,EAAE,CAAC,qBAAqB,CAAC,CAAC;AACrE,MAAM,MAAM,sBAAsB,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC;AAGzD,MAAM,MAAM,uBAAuB,GAAG,EAAE,CAAC,gBAAgB,CAAC,CAAC;AAC3D,MAAM,MAAM,yBAAyB,GAAG,EAAE,CAAC,kBAAkB,CAAC,CAAC;AAC/D,MAAM,MAAM,mCAAmC,GAC7C,EAAE,CAAC,4BAA4B,CAAC,CAAC;AACnC,MAAM,MAAM,oBAAoB,GAAG,EAAE,CAAC,aAAa,CAAC,CAAC;AACrD,MAAM,MAAM,qBAAqB,GAAG,EAAE,CAAC,cAAc,CAAC,CAAC;AACvD,MAAM,MAAM,8BAA8B,GAAG,EAAE,CAAC,uBAAuB,CAAC,CAAC;AACzE,MAAM,MAAM,0BAA0B,GAAG,EAAE,CAAC,mBAAmB,CAAC,CAAC;AACjE,MAAM,MAAM,qCAAqC,GAC/C,EAAE,CAAC,8BAA8B,CAAC,CAAC;AAErC,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,OAAO,GAAG,CAAC,GAAG,KAAK,CAAC;AAE3E,MAAM,WAAW,cAAc,CAAC,MAAM;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3B"}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { SearchSpringConfig } from '../services/searchspring/types';
|
|
2
2
|
import type { EntityItemData } from '../component/types';
|
|
3
|
+
/**
|
|
4
|
+
* The turn owns WHICH thing to show; the live fetch owns VOLATILE FACTS about
|
|
5
|
+
* it.
|
|
6
|
+
*
|
|
7
|
+
* Only the turn saw the shopper's question, so only it knows that the brown
|
|
8
|
+
* variant was the one asked for — its `title`, `imageUrl`, `url`,
|
|
9
|
+
* `matchedOptions` and `variantId` all describe that one variant and must
|
|
10
|
+
* survive enrichment. Everything SearchSpring answers with that can go stale
|
|
11
|
+
* between the turn and the render — `price`, `compareAtPrice`, `available`,
|
|
12
|
+
* `priceMin`, `priceMax` — comes from `resolved`.
|
|
13
|
+
*/
|
|
3
14
|
export declare function mergeSearchSpringEntityData(existing: EntityItemData | undefined, resolved: EntityItemData): EntityItemData;
|
|
4
15
|
/**
|
|
5
16
|
* SearchSpring-backed entity resolution hook.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResolveSearchSpringEntityData.d.ts","sourceRoot":"","sources":["../../../src/hooks/useResolveSearchSpringEntityData.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAsCzD,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,cAAc,GAAG,SAAS,EACpC,QAAQ,EAAE,cAAc,GACvB,cAAc,
|
|
1
|
+
{"version":3,"file":"useResolveSearchSpringEntityData.d.ts","sourceRoot":"","sources":["../../../src/hooks/useResolveSearchSpringEntityData.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAsCzD;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,cAAc,GAAG,SAAS,EACpC,QAAQ,EAAE,cAAc,GACvB,cAAc,CAsBhB;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,SAAS;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB,EAED,QAAQ,EAAE,OAAO,EAAE,EACnB,MAAM,EAAE,kBAAkB,GACzB;IAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAyGnD"}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { ShopifyStorefrontConfig } from '../services/shopify/types';
|
|
2
2
|
import type { EntityItemData } from '../component/types';
|
|
3
|
+
/**
|
|
4
|
+
* The turn owns WHICH thing to show; the live fetch owns VOLATILE FACTS about
|
|
5
|
+
* it.
|
|
6
|
+
*
|
|
7
|
+
* Only the turn saw the shopper's question, so only it knows that the brown
|
|
8
|
+
* variant was the one asked for — its `title`, `imageUrl`, `url`,
|
|
9
|
+
* `matchedOptions` and `variantId` all describe that one variant and must
|
|
10
|
+
* survive enrichment. Everything the Storefront answers with that can go stale
|
|
11
|
+
* between the turn and the render — `price`, `compareAtPrice`, `available`,
|
|
12
|
+
* `priceMin`, `priceMax` — comes from `resolved`.
|
|
13
|
+
*/
|
|
3
14
|
export declare function mergeShopifyEntityData(existing: EntityItemData | undefined, resolved: EntityItemData): EntityItemData;
|
|
4
15
|
/**
|
|
5
16
|
* Shopify-specific implementation of the entity resolution pattern.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResolveShopifyEntityData.d.ts","sourceRoot":"","sources":["../../../src/hooks/useResolveShopifyEntityData.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"useResolveShopifyEntityData.d.ts","sourceRoot":"","sources":["../../../src/hooks/useResolveShopifyEntityData.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAyEzD;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,cAAc,GAAG,SAAS,EACpC,QAAQ,EAAE,cAAc,GACvB,cAAc,CAgBhB;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,SAAS;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB,EAED,QAAQ,EAAE,OAAO,EAAE,EACnB,aAAa,EAAE,uBAAuB,GACrC;IAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAwInD"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { EntityItemData } from '../../component/types';
|
|
2
2
|
import type { ShopifyProduct, ShopifyCollection, ShopifyArticle } from './types';
|
|
3
|
-
export declare function transformShopifyProduct(product: ShopifyProduct): EntityItemData;
|
|
3
|
+
export declare function transformShopifyProduct(product: ShopifyProduct, variantId?: string): EntityItemData;
|
|
4
4
|
export declare function transformShopifyCollection(collection: ShopifyCollection): EntityItemData;
|
|
5
5
|
export declare function transformShopifyArticle(article: ShopifyArticle): EntityItemData;
|
|
6
6
|
/**
|
|
7
7
|
* Transform any resolved Shopify entity to the standard EntityItemData shape.
|
|
8
8
|
* Detects the entity type by checking for type-specific fields.
|
|
9
9
|
*/
|
|
10
|
-
export declare function transformShopifyEntityToItemData(entity: ShopifyProduct | ShopifyCollection | ShopifyArticle, entityType: string): EntityItemData;
|
|
10
|
+
export declare function transformShopifyEntityToItemData(entity: ShopifyProduct | ShopifyCollection | ShopifyArticle, entityType: string, variantId?: string): EntityItemData;
|
|
11
11
|
//# sourceMappingURL=transformShopifyEntity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformShopifyEntity.d.ts","sourceRoot":"","sources":["../../../../src/services/shopify/transformShopifyEntity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,cAAc,EACf,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"transformShopifyEntity.d.ts","sourceRoot":"","sources":["../../../../src/services/shopify/transformShopifyEntity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,cAAc,EACf,MAAM,SAAS,CAAC;AAmGjB,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,cAAc,EACvB,SAAS,CAAC,EAAE,MAAM,GACjB,cAAc,CA8BhB;AAED,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,iBAAiB,GAC5B,cAAc,CAQhB;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,cAAc,GACtB,cAAc,CAWhB;AAED;;;GAGG;AACH,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,cAAc,GAAG,iBAAiB,GAAG,cAAc,EAC3D,UAAU,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,MAAM,GACjB,cAAc,CAehB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/web5-core",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "1.63.
|
|
4
|
+
"version": "1.63.7",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tsachis",
|
|
7
7
|
"email": "tsachis@wix.com"
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"wallaby": {
|
|
101
101
|
"autoDetect": true
|
|
102
102
|
},
|
|
103
|
-
"falconPackageHash": "
|
|
103
|
+
"falconPackageHash": "7a9127005e68e63fa049092b5a05bfa543dfd37583f7136bd17323c1"
|
|
104
104
|
}
|