@gfed-medusa/sf-lib-products 1.2.0 → 1.2.1

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.
Files changed (30) hide show
  1. package/dist/components/image-gallery/index.d.ts +2 -2
  2. package/dist/components/product-actions/index.d.ts +2 -2
  3. package/dist/components/product-actions/index.d.ts.map +1 -1
  4. package/dist/components/product-actions/index.js.map +1 -1
  5. package/dist/components/product-onboarding-cta/index.d.ts +2 -2
  6. package/dist/components/product-onboarding-cta/index.d.ts.map +1 -1
  7. package/dist/components/product-price/index.d.ts +2 -2
  8. package/dist/components/product-price/index.d.ts.map +1 -1
  9. package/dist/components/product-tabs/index.d.ts +2 -2
  10. package/dist/components/product-tabs/index.d.ts.map +1 -1
  11. package/dist/components/refinement-list/index.d.ts +2 -2
  12. package/dist/components/refinement-list/sort-products/index.d.ts +2 -2
  13. package/dist/components/related-products/index.d.ts +2 -2
  14. package/dist/components/related-products/index.d.ts.map +1 -1
  15. package/dist/components/skeleton-product-grid/index.d.ts +2 -2
  16. package/dist/lib/data/cart.d.ts.map +1 -1
  17. package/dist/lib/data/cart.js +5 -16
  18. package/dist/lib/data/cart.js.map +1 -1
  19. package/dist/lib/gql/fragments/cart.d.ts +9 -9
  20. package/dist/lib/gql/fragments/product.d.ts +11 -11
  21. package/dist/lib/gql/fragments/product.d.ts.map +1 -1
  22. package/dist/lib/gql/mutations/cart.d.ts +10 -10
  23. package/dist/lib/gql/mutations/cart.d.ts.map +1 -1
  24. package/dist/lib/gql/queries/cart.d.ts +2 -2
  25. package/dist/templates/paginated-products/index.d.ts +2 -2
  26. package/dist/templates/product-actions-wrapper/index.d.ts +2 -2
  27. package/dist/templates/product-info/index.d.ts +2 -2
  28. package/dist/templates/store-template/index.d.ts +2 -2
  29. package/dist/templates/store-template/index.d.ts.map +1 -1
  30. package/package.json +3 -3
@@ -1,5 +1,5 @@
1
1
  import { ProductImage } from "../../types/graphql.js";
2
- import * as react_jsx_runtime0 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime5 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/image-gallery/index.d.ts
5
5
  type ImageGalleryProps = {
@@ -7,7 +7,7 @@ type ImageGalleryProps = {
7
7
  };
8
8
  declare const ImageGallery: ({
9
9
  images
10
- }: ImageGalleryProps) => react_jsx_runtime0.JSX.Element;
10
+ }: ImageGalleryProps) => react_jsx_runtime5.JSX.Element;
11
11
  //#endregion
12
12
  export { ImageGallery as default };
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { Product } from "../../types/graphql.js";
2
- import * as react_jsx_runtime1 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime10 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/product-actions/index.d.ts
5
5
  type ProductActionsProps = {
@@ -11,7 +11,7 @@ declare function ProductActions({
11
11
  product,
12
12
  disabled,
13
13
  enableMobileActions
14
- }: ProductActionsProps): react_jsx_runtime1.JSX.Element;
14
+ }: ProductActionsProps): react_jsx_runtime10.JSX.Element;
15
15
  //#endregion
16
16
  export { ProductActionsProps, ProductActions as default };
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/product-actions/index.tsx"],"sourcesContent":[],"mappings":";;;;KAsBY,mBAAA;WACD;;EADC,mBAAA,CAAA,EAAmB,OAAA;AAI7B,CAAA;AAmBA,iBADsB,cAAA,CACtB;EAAA,OAAA;EAAA,QAAA;EAAA;AAAA,CAAA,EAGC,mBAHD,CAAA,EAGoB,kBAAA,CAAA,GAAA,CAAA,OAHpB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/product-actions/index.tsx"],"sourcesContent":[],"mappings":";;;;KAsBY,mBAAA;WACD;;EADC,mBAAA,CAAA,EAAmB,OAAA;AAI7B,CAAA;AAmBA,iBADsB,cAAA,CACtB;EAAA,OAAA;EAAA,QAAA;EAAA;AAAA,CAAA,EAGC,mBAHD,CAAA,EAGoB,mBAAA,CAAA,GAAA,CAAA,OAHpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["OptionSelect","MobileActions"],"sources":["../../../src/components/product-actions/index.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\n\nimport { useParams } from 'next/navigation';\n\nimport { isEqual } from 'lodash';\n\nimport { ErrorMessage } from '@gfed-medusa/sf-lib-common/components/error-message';\nimport { useStorefrontContext } from '@gfed-medusa/sf-lib-common/lib/data/context';\nimport { Divider } from '@gfed-medusa/sf-lib-ui/components/divider';\nimport { HttpTypes } from '@medusajs/types';\nimport { Button } from '@medusajs/ui';\n\nimport OptionSelect from '@/components/product-actions/option-select';\nimport { addToCart } from '@/lib/data/cart';\nimport { useIntersection } from '@/lib/hooks/use-intersection';\nimport { Product } from '@/types/graphql';\n\nimport ProductPrice from '../product-price';\nimport MobileActions from './mobile-actions';\n\nexport type ProductActionsProps = {\n product: Product;\n disabled?: boolean;\n enableMobileActions?: boolean;\n};\n\nenum AddToCartStatus {\n IDLE = 'idle',\n ADDING = 'adding',\n SUCCESS = 'success',\n ERROR = 'error',\n}\n\nconst optionsAsKeymap = (\n variantOptions: HttpTypes.StoreProductVariant['options']\n) => {\n return variantOptions?.reduce((acc: Record<string, string>, varopt: any) => {\n acc[varopt.optionId] = varopt.value;\n return acc;\n }, {});\n};\n\nexport default function ProductActions({\n product,\n disabled,\n enableMobileActions = true,\n}: ProductActionsProps) {\n const [options, setOptions] = useState<Record<string, string | undefined>>(\n {}\n );\n const [status, setStatus] = useState<AddToCartStatus>(AddToCartStatus.IDLE);\n const countryCode = useParams().countryCode as string;\n\n // If there is only 1 variant, preselect the options\n useEffect(() => {\n if (product?.variants && product.variants.length === 1) {\n const variantOptions = optionsAsKeymap(\n product.variants[0]?.options || null\n );\n setOptions(variantOptions ?? {});\n }\n }, [product.variants]);\n\n const selectedVariant = useMemo(() => {\n if (!product.variants || product.variants.length === 0) {\n return;\n }\n\n return product.variants.find((v) => {\n const variantOptions = optionsAsKeymap(v.options);\n return isEqual(variantOptions, options);\n });\n }, [product.variants, options]);\n\n // update the options when a variant is selected\n const setOptionValue = (optionId: string, value: string) => {\n setOptions((prev) => ({\n ...prev,\n [optionId]: value,\n }));\n };\n\n //check if the selected options produce a valid variant\n const isValidVariant = useMemo(() => {\n return product.variants?.some((v) => {\n const variantOptions = optionsAsKeymap(v.options);\n return isEqual(variantOptions, options);\n });\n }, [product.variants, options]);\n\n // check if the selected variant is in stock\n const inStock = useMemo(() => {\n // If we don't manage inventory, we can always add to cart\n if (selectedVariant && !selectedVariant.manageInventory) {\n return true;\n }\n\n // If we allow back orders on the variant, we can add to cart\n if (selectedVariant?.allowBackorder) {\n return true;\n }\n\n // If there is inventory available, we can add to cart\n if (\n selectedVariant?.manageInventory &&\n (selectedVariant?.inventoryQuantity || 0) > 0\n ) {\n return true;\n }\n\n // Otherwise, we can't add to cart\n return false;\n }, [selectedVariant]);\n\n const actionsRef = useRef<HTMLDivElement>(null);\n\n const inView = useIntersection(actionsRef, '0px');\n const ctx = useStorefrontContext();\n\n // add the selected variant to the cart\n const handleAddToCart = async () => {\n if (!selectedVariant?.id) return null;\n\n setStatus(AddToCartStatus.ADDING);\n\n try {\n await addToCart(\n {\n variantId: selectedVariant.id,\n quantity: 1,\n countryCode,\n },\n ctx\n );\n\n setStatus(AddToCartStatus.SUCCESS);\n } catch(error) {\n console.log(error);\n setStatus(AddToCartStatus.ERROR);\n }\n };\n\n return (\n <>\n <div className=\"flex flex-col gap-y-2\" ref={actionsRef}>\n <div>\n {(product.variants?.length ?? 0) > 1 && (\n <div className=\"flex flex-col gap-y-4\">\n {(product.options || []).map((option) => {\n return (\n <div key={option.id}>\n <OptionSelect\n option={option}\n current={options[option.id]}\n updateOption={setOptionValue}\n title={option.title ?? ''}\n data-testid=\"product-options\"\n disabled={!!disabled || status === AddToCartStatus.ADDING}\n />\n </div>\n );\n })}\n <Divider />\n </div>\n )}\n </div>\n\n <ProductPrice product={product} variant={selectedVariant} />\n\n {status === AddToCartStatus.ERROR && (\n <ErrorMessage error=\"Failed adding product to cart. Please try again.\" />\n )}\n {status === AddToCartStatus.SUCCESS && (\n <div className=\"text-small-regular pt-2 text-green-700\">\n Successfully added product to cart\n </div>\n )}\n <Button\n onClick={handleAddToCart}\n disabled={\n !inStock ||\n !selectedVariant ||\n !!disabled ||\n status === AddToCartStatus.ADDING ||\n !isValidVariant\n }\n variant=\"primary\"\n className=\"h-10 w-full\"\n isLoading={status === AddToCartStatus.ADDING}\n data-testid=\"add-product-button\"\n >\n {!selectedVariant\n ? 'Select variant'\n : !inStock || !isValidVariant\n ? 'Out of stock'\n : 'Add to cart'}\n </Button>\n {enableMobileActions && (\n <MobileActions\n product={product}\n variant={selectedVariant}\n options={options}\n updateOptions={setOptionValue}\n inStock={inStock}\n handleAddToCart={handleAddToCart}\n isAdding={status === AddToCartStatus.ADDING}\n show={!inView}\n optionsDisabled={!!disabled || status === AddToCartStatus.ADDING}\n />\n )}\n </div>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA4BA,IAAK,8DAAL;AACE;AACA;AACA;AACA;;EAJG;AAOL,MAAM,mBACJ,mBACG;AACH,QAAO,gBAAgB,QAAQ,KAA6B,WAAgB;AAC1E,MAAI,OAAO,YAAY,OAAO;AAC9B,SAAO;IACN,EAAE,CAAC;;AAGR,SAAwB,eAAe,EACrC,SACA,UACA,sBAAsB,QACA;CACtB,MAAM,CAAC,SAAS,cAAc,SAC5B,EAAE,CACH;CACD,MAAM,CAAC,QAAQ,aAAa,SAA0B,gBAAgB,KAAK;CAC3E,MAAM,cAAc,WAAW,CAAC;AAGhC,iBAAgB;AACd,MAAI,SAAS,YAAY,QAAQ,SAAS,WAAW,EAInD,YAHuB,gBACrB,QAAQ,SAAS,IAAI,WAAW,KACjC,IAC4B,EAAE,CAAC;IAEjC,CAAC,QAAQ,SAAS,CAAC;CAEtB,MAAM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MACR,SAAS,QAAQ,OAAO;MACxB,cAAc;MACd,OAAO,OAAO,SAAS;MACvB,eAAY;MACZ,UAAU,CAAC,CAAC,YAAY,WAAW,gBAAgB;OACnD,IARM,OAAO,GASX;MAER,EACF,oBAAC,YAAU;KACP,GAEJ;GAEN,oBAAC;IAAsB;IAAS,SAAS;KAAmB;GAE3D,WAAW,gBAAgB,SAC1B,oBAAC,gBAAa,OAAM,qDAAqD;GAE1E,WAAW,gBAAgB,WAC1B,oBAAC;IAAI,WAAU;cAAyC;KAElD;GAER,oBAAC;IACC,SAAS;IACT,UACE,CAAC,WACD,CAAC,mBACD,CAAC,CAAC,YACF,WAAW,gBAAgB,UAC3B,CAAC;IAEH,SAAQ;IACR,WAAU;IACV,WAAW,WAAW,gBAAgB;IACtC,eAAY;cAEX,CAAC,kBACE,mBACA,CAAC,WAAW,CAAC,iBACX,iBACA;KACC;GACR,uBACC,oBAACC;IACU;IACT,SAAS;IACA;IACT,eAAe;IACN;IACQ;IACjB,UAAU,WAAW,gBAAgB;IACrC,MAAM,CAAC;IACP,iBAAiB,CAAC,CAAC,YAAY,WAAW,gBAAgB;KAC1D;;GAEA,GACL"}
1
+ {"version":3,"file":"index.js","names":["OptionSelect","MobileActions"],"sources":["../../../src/components/product-actions/index.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\n\nimport { useParams } from 'next/navigation';\n\nimport { isEqual } from 'lodash';\n\nimport { ErrorMessage } from '@gfed-medusa/sf-lib-common/components/error-message';\nimport { useStorefrontContext } from '@gfed-medusa/sf-lib-common/lib/data/context';\nimport { Divider } from '@gfed-medusa/sf-lib-ui/components/divider';\nimport { HttpTypes } from '@medusajs/types';\nimport { Button } from '@medusajs/ui';\n\nimport OptionSelect from '@/components/product-actions/option-select';\nimport { addToCart } from '@/lib/data/cart';\nimport { useIntersection } from '@/lib/hooks/use-intersection';\nimport { Product } from '@/types/graphql';\n\nimport ProductPrice from '../product-price';\nimport MobileActions from './mobile-actions';\n\nexport type ProductActionsProps = {\n product: Product;\n disabled?: boolean;\n enableMobileActions?: boolean;\n};\n\nenum AddToCartStatus {\n IDLE = 'idle',\n ADDING = 'adding',\n SUCCESS = 'success',\n ERROR = 'error',\n}\n\nconst optionsAsKeymap = (\n variantOptions: HttpTypes.StoreProductVariant['options']\n) => {\n return variantOptions?.reduce((acc: Record<string, string>, varopt: any) => {\n acc[varopt.optionId] = varopt.value;\n return acc;\n }, {});\n};\n\nexport default function ProductActions({\n product,\n disabled,\n enableMobileActions = true,\n}: ProductActionsProps) {\n const [options, setOptions] = useState<Record<string, string | undefined>>(\n {}\n );\n const [status, setStatus] = useState<AddToCartStatus>(AddToCartStatus.IDLE);\n const countryCode = useParams().countryCode as string;\n\n // If there is only 1 variant, preselect the options\n useEffect(() => {\n if (product?.variants && product.variants.length === 1) {\n const variantOptions = optionsAsKeymap(\n product.variants[0]?.options || null\n );\n setOptions(variantOptions ?? {});\n }\n }, [product.variants]);\n\n const selectedVariant = useMemo(() => {\n if (!product.variants || product.variants.length === 0) {\n return;\n }\n\n return product.variants.find((v) => {\n const variantOptions = optionsAsKeymap(v.options);\n return isEqual(variantOptions, options);\n });\n }, [product.variants, options]);\n\n // update the options when a variant is selected\n const setOptionValue = (optionId: string, value: string) => {\n setOptions((prev) => ({\n ...prev,\n [optionId]: value,\n }));\n };\n\n //check if the selected options produce a valid variant\n const isValidVariant = useMemo(() => {\n return product.variants?.some((v) => {\n const variantOptions = optionsAsKeymap(v.options);\n return isEqual(variantOptions, options);\n });\n }, [product.variants, options]);\n\n // check if the selected variant is in stock\n const inStock = useMemo(() => {\n // If we don't manage inventory, we can always add to cart\n if (selectedVariant && !selectedVariant.manageInventory) {\n return true;\n }\n\n // If we allow back orders on the variant, we can add to cart\n if (selectedVariant?.allowBackorder) {\n return true;\n }\n\n // If there is inventory available, we can add to cart\n if (\n selectedVariant?.manageInventory &&\n (selectedVariant?.inventoryQuantity || 0) > 0\n ) {\n return true;\n }\n\n // Otherwise, we can't add to cart\n return false;\n }, [selectedVariant]);\n\n const actionsRef = useRef<HTMLDivElement>(null);\n\n const inView = useIntersection(actionsRef, '0px');\n const ctx = useStorefrontContext();\n\n // add the selected variant to the cart\n const handleAddToCart = async () => {\n if (!selectedVariant?.id) return null;\n\n setStatus(AddToCartStatus.ADDING);\n\n try {\n await addToCart(\n {\n variantId: selectedVariant.id,\n quantity: 1,\n countryCode,\n },\n ctx\n );\n\n setStatus(AddToCartStatus.SUCCESS);\n } catch (error) {\n console.log(error);\n setStatus(AddToCartStatus.ERROR);\n }\n };\n\n return (\n <>\n <div className=\"flex flex-col gap-y-2\" ref={actionsRef}>\n <div>\n {(product.variants?.length ?? 0) > 1 && (\n <div className=\"flex flex-col gap-y-4\">\n {(product.options || []).map((option) => {\n return (\n <div key={option.id}>\n <OptionSelect\n option={option}\n current={options[option.id]}\n updateOption={setOptionValue}\n title={option.title ?? ''}\n data-testid=\"product-options\"\n disabled={!!disabled || status === AddToCartStatus.ADDING}\n />\n </div>\n );\n })}\n <Divider />\n </div>\n )}\n </div>\n\n <ProductPrice product={product} variant={selectedVariant} />\n\n {status === AddToCartStatus.ERROR && (\n <ErrorMessage error=\"Failed adding product to cart. Please try again.\" />\n )}\n {status === AddToCartStatus.SUCCESS && (\n <div className=\"text-small-regular pt-2 text-green-700\">\n Successfully added product to cart\n </div>\n )}\n <Button\n onClick={handleAddToCart}\n disabled={\n !inStock ||\n !selectedVariant ||\n !!disabled ||\n status === AddToCartStatus.ADDING ||\n !isValidVariant\n }\n variant=\"primary\"\n className=\"h-10 w-full\"\n isLoading={status === AddToCartStatus.ADDING}\n data-testid=\"add-product-button\"\n >\n {!selectedVariant\n ? 'Select variant'\n : !inStock || !isValidVariant\n ? 'Out of stock'\n : 'Add to cart'}\n </Button>\n {enableMobileActions && (\n <MobileActions\n product={product}\n variant={selectedVariant}\n options={options}\n updateOptions={setOptionValue}\n inStock={inStock}\n handleAddToCart={handleAddToCart}\n isAdding={status === AddToCartStatus.AD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eAAe;IACN;IACQ;IACjB,UAAU,WAAW,gBAAgB;IACrC,MAAM,CAAC;IACP,iBAAiB,CAAC,CAAC,YAAY,WAAW,gBAAgB;KAC1D;;GAEA,GACL"}
@@ -1,7 +1,7 @@
1
- import * as react_jsx_runtime8 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime11 from "react/jsx-runtime";
2
2
 
3
3
  //#region src/components/product-onboarding-cta/index.d.ts
4
- declare function ProductOnboardingCta(): Promise<react_jsx_runtime8.JSX.Element | null>;
4
+ declare function ProductOnboardingCta(): Promise<react_jsx_runtime11.JSX.Element | null>;
5
5
  //#endregion
6
6
  export { ProductOnboardingCta as default };
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/product-onboarding-cta/index.tsx"],"sourcesContent":[],"mappings":";;;iBAIe,oBAAA,CAAA,GAAoB,QAAA,kBAAA,CAAA,GAAA,CAAA,OAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/product-onboarding-cta/index.tsx"],"sourcesContent":[],"mappings":";;;iBAIe,oBAAA,CAAA,GAAoB,QAAA,mBAAA,CAAA,GAAA,CAAA,OAAA"}
@@ -1,5 +1,5 @@
1
1
  import { Product, ProductVariant } from "../../types/graphql.js";
2
- import * as react_jsx_runtime9 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime13 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/product-price/index.d.ts
5
5
  declare function ProductPrice({
@@ -8,7 +8,7 @@ declare function ProductPrice({
8
8
  }: {
9
9
  product: Product;
10
10
  variant?: ProductVariant;
11
- }): react_jsx_runtime9.JSX.Element;
11
+ }): react_jsx_runtime13.JSX.Element;
12
12
  //#endregion
13
13
  export { ProductPrice as default };
14
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/product-price/index.tsx"],"sourcesContent":[],"mappings":";;;;iBAKwB,YAAA;;;AAFkC;WAM/C;YACC;AAP8C,CAAA,CAAA,EAQzD,kBAAA,CAAA,GAAA,CAAA,OANmC"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/product-price/index.tsx"],"sourcesContent":[],"mappings":";;;;iBAKwB,YAAA;;;AAFkC;WAM/C;YACC;AAP8C,CAAA,CAAA,EAQzD,mBAAA,CAAA,GAAA,CAAA,OANmC"}
@@ -1,5 +1,5 @@
1
1
  import { Product } from "../../types/graphql.js";
2
- import * as react_jsx_runtime10 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/product-tabs/index.d.ts
5
5
  type ProductTabsProps = {
@@ -7,7 +7,7 @@ type ProductTabsProps = {
7
7
  };
8
8
  declare const ProductTabs: ({
9
9
  product
10
- }: ProductTabsProps) => react_jsx_runtime10.JSX.Element;
10
+ }: ProductTabsProps) => react_jsx_runtime0.JSX.Element;
11
11
  //#endregion
12
12
  export { ProductTabs as default };
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/product-tabs/index.tsx"],"sourcesContent":[],"mappings":";;;;KAUK,gBAAA;WACM;;AAL+B,cAQpC,WAJe,EAAA,CAAA;EAAA;AACH,CAAP,EAGuB,gBAHhB,EAAA,GAGgC,mBAAA,CAAA,GAAA,CAAA,OAHhC"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/product-tabs/index.tsx"],"sourcesContent":[],"mappings":";;;;KAUK,gBAAA;WACM;;AAL+B,cAQpC,WAJe,EAAA,CAAA;EAAA;AACH,CAAP,EAGuB,gBAHhB,EAAA,GAGgC,kBAAA,CAAA,GAAA,CAAA,OAHhC"}
@@ -1,5 +1,5 @@
1
1
  import { SortOptions } from "./sort-products/index.js";
2
- import * as react_jsx_runtime11 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime14 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/refinement-list/index.d.ts
5
5
  type RefinementListProps = {
@@ -10,7 +10,7 @@ type RefinementListProps = {
10
10
  declare const RefinementList: ({
11
11
  sortBy,
12
12
  "data-testid": dataTestId
13
- }: RefinementListProps) => react_jsx_runtime11.JSX.Element;
13
+ }: RefinementListProps) => react_jsx_runtime14.JSX.Element;
14
14
  //#endregion
15
15
  export { RefinementList as default };
16
16
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime13 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime12 from "react/jsx-runtime";
2
2
 
3
3
  //#region src/components/refinement-list/sort-products/index.d.ts
4
4
  type SortOptions = 'price_asc' | 'price_desc' | 'created_at';
@@ -11,7 +11,7 @@ declare const SortProducts: ({
11
11
  "data-testid": dataTestId,
12
12
  sortBy,
13
13
  setQueryParams
14
- }: SortProductsProps) => react_jsx_runtime13.JSX.Element;
14
+ }: SortProductsProps) => react_jsx_runtime12.JSX.Element;
15
15
  //#endregion
16
16
  export { SortOptions, SortProducts as default };
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { Product } from "../../types/graphql.js";
2
- import * as react_jsx_runtime12 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/related-products/index.d.ts
5
5
  type RelatedProductsProps = {
@@ -9,7 +9,7 @@ type RelatedProductsProps = {
9
9
  declare function RelatedProducts({
10
10
  product,
11
11
  countryCode
12
- }: RelatedProductsProps): Promise<react_jsx_runtime12.JSX.Element | null>;
12
+ }: RelatedProductsProps): Promise<react_jsx_runtime0.JSX.Element | null>;
13
13
  //#endregion
14
14
  export { RelatedProducts as default };
15
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/related-products/index.tsx"],"sourcesContent":[],"mappings":";;;;KAUK,oBAAA;WACM;;AAHc,CAAA;AAOK,iBAAA,eAAA,CAAe;EAAA,OAAA;EAAA;AAAA,CAAA,EAG1C,oBAH0C,CAAA,EAGtB,OAHsB,CAGtB,mBAAA,CAAA,GAAA,CAAA,OAAA,GAHsB,IAAA,CAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/related-products/index.tsx"],"sourcesContent":[],"mappings":";;;;KAUK,oBAAA;WACM;;AAHc,CAAA;AAOK,iBAAA,eAAA,CAAe;EAAA,OAAA;EAAA;AAAA,CAAA,EAG1C,oBAH0C,CAAA,EAGtB,OAHsB,CAGtB,kBAAA,CAAA,GAAA,CAAA,OAAA,GAHsB,IAAA,CAAA"}
@@ -1,11 +1,11 @@
1
- import * as react_jsx_runtime7 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime1 from "react/jsx-runtime";
2
2
 
3
3
  //#region src/components/skeleton-product-grid/index.d.ts
4
4
  declare const SkeletonProductGrid: ({
5
5
  numberOfProducts
6
6
  }: {
7
7
  numberOfProducts?: number;
8
- }) => react_jsx_runtime7.JSX.Element;
8
+ }) => react_jsx_runtime1.JSX.Element;
9
9
  //#endregion
10
10
  export { SkeletonProductGrid as default };
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cart.d.ts","names":[],"sources":["../../../src/lib/data/cart.ts"],"sourcesContent":[],"mappings":";;;;cAmCa,oCAEN,sBACJ,QAAQ;cAmBE,yCAEN,sBACJ,QAAQ;AAzBE,cAwFA,SApEZ,EAAA,CAAA;EAAA,SAAA;EAAA,QAAA;EAAA;CAAA,EAAA;EAlBM,SAAA,EAAA,MAAA;EACI,QAAA,EAAA,MAAA;EAAR,WAAA,EAAA,MAAA;CAAO,EAAA,GAAA,EA+FH,iBA/FG,EAAA,GAgGP,OAhGO,CAgGC,sBAhGD,CAAA,gBAAA,CAAA,GAAA,IAAA,CAAA"}
1
+ {"version":3,"file":"cart.d.ts","names":[],"sources":["../../../src/lib/data/cart.ts"],"sourcesContent":[],"mappings":";;;;cAmCa,oCAEN,sBACJ,QAAQ;cAmBE,yCAEN,sBACJ,QAAQ;AAzBE,cA8EA,SA1DZ,EAAA,CAAA;EAAA,SAAA;EAAA,QAAA;EAAA;CAAA,EAAA;EAlBM,SAAA,EAAA,MAAA;EACI,QAAA,EAAA,MAAA;EAAR,WAAA,EAAA,MAAA;CAAO,EAAA,GAAA,EAqFH,iBArFG,EAAA,GAsFP,OAtFO,CAsFC,sBAtFD,CAAA,gBAAA,CAAA,GAAA,IAAA,CAAA"}
@@ -4,7 +4,7 @@ import { CREATE_CART_MUTATION, CREATE_LINE_ITEM_MUTATION, UPDATE_CART_MUTATION }
4
4
  import { GET_CART_QUERY } from "../gql/queries/cart.js";
5
5
  import { getRegion } from "./regions.js";
6
6
  import { revalidateTag } from "next/cache";
7
- import { getCacheTag, getCartId, setCartId } from "@gfed-medusa/sf-lib-common/lib/data/cookies";
7
+ import { getCacheTag, getCartId, setCartIdAction } from "@gfed-medusa/sf-lib-common/lib/data/cookies";
8
8
  import { graphqlFetch, graphqlMutation } from "@gfed-medusa/sf-lib-common/lib/gql/apollo-client";
9
9
 
10
10
  //#region src/lib/data/cart.ts
@@ -31,11 +31,8 @@ const getOrSetCart = async (countryCode, ctx) => {
31
31
  variables: { data: { regionId: region.id } }
32
32
  }))?.createCart ?? null;
33
33
  if (cart) {
34
- await setCartId(cart.id, ctx);
35
- if (ctx.revalidate) {
36
- const cartCacheTag = getCacheTag("carts", ctx);
37
- ctx.revalidate(cartCacheTag);
38
- } else revalidateTag(getCacheTag("carts", ctx));
34
+ await setCartIdAction(cart.id);
35
+ revalidateTag(getCacheTag("carts", ctx));
39
36
  }
40
37
  }
41
38
  if (cart && cart.regionId !== region.id) {
@@ -46,10 +43,7 @@ const getOrSetCart = async (countryCode, ctx) => {
46
43
  data: { regionId: region.id }
47
44
  }
48
45
  }))?.updateCart ?? cart;
49
- if (cart) if (ctx.revalidate) {
50
- const cartCacheTag = getCacheTag("carts", ctx);
51
- ctx.revalidate(cartCacheTag);
52
- } else revalidateTag(getCacheTag("carts", ctx));
46
+ if (cart) revalidateTag(getCacheTag("carts", ctx));
53
47
  }
54
48
  return cart;
55
49
  };
@@ -69,12 +63,7 @@ const addToCart = async ({ variantId, quantity, countryCode }, ctx) => {
69
63
  }
70
64
  }
71
65
  }))?.createLineItem ?? null;
72
- if (lineItem) if (ctx.revalidate) {
73
- const cartCacheTag = getCacheTag("carts", ctx);
74
- ctx.revalidate(cartCacheTag);
75
- const fulfillmentCacheTag = getCacheTag("fulfillment", ctx);
76
- ctx.revalidate(fulfillmentCacheTag);
77
- } else {
66
+ if (lineItem) {
78
67
  revalidateTag(getCacheTag("carts", ctx));
79
68
  revalidateTag(getCacheTag("fulfillment", ctx));
80
69
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cart.js","names":["error: any"],"sources":["../../../src/lib/data/cart.ts"],"sourcesContent":["'use server';\n\nimport { revalidateTag } from 'next/cache';\n\nimport type { StorefrontContext } from '@gfed-medusa/sf-lib-common/lib/data/context';\nimport {\n getCacheTag,\n getCartId,\n setCartId,\n} from '@gfed-medusa/sf-lib-common/lib/data/cookies';\nimport {\n graphqlFetch,\n graphqlMutation,\n} from '@gfed-medusa/sf-lib-common/lib/gql/apollo-client';\nimport {\n Cart,\n CreateCartMutation,\n CreateCartMutationVariables,\n CreateLineItemMutation,\n CreateLineItemMutationVariables,\n GetCartQuery,\n GetCartQueryVariables,\n UpdateCartMutation,\n UpdateCartMutationVariables,\n} from '@gfed-medusa/sf-lib-common/types/graphql';\n\nimport {\n CREATE_CART_MUTATION,\n CREATE_LINE_ITEM_MUTATION,\n UPDATE_CART_MUTATION,\n} from '@/lib/gql/mutations/cart';\nimport { GET_CART_QUERY } from '@/lib/gql/queries/cart';\n\nimport { getRegion } from './regions';\n\nexport const retrieveCart = async (\n cartId: string,\n ctx: StorefrontContext\n): Promise<Cart | null> => {\n const id = cartId || getCartId(ctx);\n if (!id) {\n return null;\n }\n\n try {\n const data = await graphqlFetch<GetCartQuery, GetCartQueryVariables>({\n query: GET_CART_QUERY,\n variables: { id },\n });\n\n return data?.cart ?? null;\n } catch (error) {\n console.error('Failed to fetch cart:', error);\n return null;\n }\n};\n\nexport const getOrSetCart = async (\n countryCode: string,\n ctx: StorefrontContext\n): Promise<Cart | null> => {\n const region = await getRegion(countryCode, ctx);\n\n if (!region) {\n throw new Error(`Region not found for country code: ${countryCode}`);\n }\n\n let cart = await retrieveCart(getCartId(ctx) || '', ctx);\n\n if (!cart) {\n const data = await graphqlMutation<\n CreateCartMutation,\n CreateCartMutationVariables\n >({\n mutation: CREATE_CART_MUTATION,\n variables: {\n data: { regionId: region.id },\n },\n });\n\n cart = data?.createCart ?? null;\n\n if (cart) {\n await setCartId(cart.id, ctx);\n\n if (ctx.revalidate) {\n const cartCacheTag = getCacheTag('carts', ctx);\n ctx.revalidate(cartCacheTag);\n } else {\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n }\n }\n }\n\n if (cart && cart.regionId !== region.id) {\n const data = await graphqlMutation<\n UpdateCartMutation,\n UpdateCartMutationVariables\n >({\n mutation: UPDATE_CART_MUTATION,\n variables: {\n id: cart.id,\n data: { regionId: region.id },\n },\n });\n\n cart = data?.updateCart ?? cart;\n\n if (cart) {\n if (ctx.revalidate) {\n const cartCacheTag = getCacheTag('carts', ctx);\n ctx.revalidate(cartCacheTag);\n } else {\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n }\n }\n }\n\n return cart;\n};\n\nexport const addToCart = async (\n {\n variantId,\n quantity,\n countryCode,\n }: {\n variantId: string;\n quantity: number;\n countryCode: string;\n },\n ctx: StorefrontContext\n): Promise<CreateLineItemMutation['createLineItem'] | null> => {\n if (!variantId) {\n throw new Error('Missing variant ID when adding to cart');\n }\n\n if (!countryCode) {\n throw new Error('Missing country code when adding to cart');\n }\n\n const cart = await getOrSetCart(countryCode, ctx);\n\n if (!cart) {\n throw new Error('Error retrieving or creating cart');\n }\n\n try {\n const result = await graphqlMutation<\n CreateLineItemMutation,\n CreateLineItemMutationVariables\n >({\n mutation: CREATE_LINE_ITEM_MUTATION,\n variables: {\n cartId: cart.id,\n data: {\n variantId: variantId,\n quantity,\n },\n },\n });\n\n const lineItem = result?.createLineItem ?? null;\n\n if (lineItem) {\n if (ctx.revalidate) {\n const cartCacheTag = getCacheTag('carts', ctx);\n ctx.revalidate(cartCacheTag);\n\n const fulfillmentCacheTag = getCacheTag('fulfillment', ctx);\n ctx.revalidate(fulfillmentCacheTag);\n } else {\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n\n const fulfillmentCacheTag = getCacheTag('fulfillment', ctx);\n revalidateTag(fulfillmentCacheTag);\n }\n }\n\n return lineItem;\n } catch (error: any) {\n console.error('GraphQL addToCart error:', error.message);\n throw error;\n }\n};\n"],"mappings":";;;;;;;;;;AAmCA,MAAa,eAAe,OAC1B,QACA,QACyB;CACzB,MAAM,KAAK,UAAU,UAAU,IAAI;AACnC,KAAI,CAAC,GACH,QAAO;AAGT,KAAI;AAMF,UALa,MAAM,aAAkD;GACnE,OAAO;GACP,WAAW,EAAE,IAAI;GAClB,CAAC,GAEW,QAAQ;UACd,OAAO;AACd,UAAQ,MAAM,yBAAyB,MAAM;AAC7C,SAAO;;;AAIX,MAAa,eAAe,OAC1B,aACA,QACyB;CACzB,MAAM,SAAS,MAAM,UAAU,aAAa,IAAI;AAEhD,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,sCAAsC,cAAc;CAGtE,IAAI,OAAO,MAAM,aAAa,UAAU,IAAI,IAAI,IAAI,IAAI;AAExD,KAAI,CAAC,MAAM;AAWT,UAVa,MAAM,gBAGjB;GACA,UAAU;GACV,WAAW,EACT,MAAM,EAAE,UAAU,OAAO,IAAI,EAC9B;GACF,CAAC,GAEW,cAAc;AAE3B,MAAI,MAAM;AACR,SAAM,UAAU,KAAK,IAAI,IAAI;AAE7B,OAAI,IAAI,YAAY;IAClB,MAAM,eAAe,YAAY,SAAS,IAAI;AAC9C,QAAI,WAAW,aAAa;SAG5B,eADqB,YAAY,SAAS,IAAI,CACnB;;;AAKjC,KAAI,QAAQ,KAAK,aAAa,OAAO,IAAI;AAYvC,UAXa,MAAM,gBAGjB;GACA,UAAU;GACV,WAAW;IACT,IAAI,KAAK;IACT,MAAM,EAAE,UAAU,OAAO,IAAI;IAC9B;GACF,CAAC,GAEW,cAAc;AAE3B,MAAI,KACF,KAAI,IAAI,YAAY;GAClB,MAAM,eAAe,YAAY,SAAS,IAAI;AAC9C,OAAI,WAAW,aAAa;QAG5B,eADqB,YAAY,SAAS,IAAI,CACnB;;AAKjC,QAAO;;AAGT,MAAa,YAAY,OACvB,EACE,WACA,UACA,eAMF,QAC6D;AAC7D,KAAI,CAAC,UACH,OAAM,IAAI,MAAM,yCAAyC;AAG3D,KAAI,CAAC,YACH,OAAM,IAAI,MAAM,2CAA2C;CAG7D,MAAM,OAAO,MAAM,aAAa,aAAa,IAAI;AAEjD,KAAI,CAAC,KACH,OAAM,IAAI,MAAM,oCAAoC;AAGtD,KAAI;EAeF,MAAM,YAdS,MAAM,gBAGnB;GACA,UAAU;GACV,WAAW;IACT,QAAQ,KAAK;IACb,MAAM;KACO;KACX;KACD;IACF;GACF,CAAC,GAEuB,kBAAkB;AAE3C,MAAI,SACF,KAAI,IAAI,YAAY;GAClB,MAAM,eAAe,YAAY,SAAS,IAAI;AAC9C,OAAI,WAAW,aAAa;GAE5B,MAAM,sBAAsB,YAAY,eAAe,IAAI;AAC3D,OAAI,WAAW,oBAAoB;SAC9B;AAEL,iBADqB,YAAY,SAAS,IAAI,CACnB;AAG3B,iBAD4B,YAAY,eAAe,IAAI,CACzB;;AAItC,SAAO;UACAA,OAAY;AACnB,UAAQ,MAAM,4BAA4B,MAAM,QAAQ;AACxD,QAAM"}
1
+ {"version":3,"file":"cart.js","names":["error: any"],"sources":["../../../src/lib/data/cart.ts"],"sourcesContent":["'use server';\n\nimport { revalidateTag } from 'next/cache';\n\nimport type { StorefrontContext } from '@gfed-medusa/sf-lib-common/lib/data/context';\nimport {\n getCacheTag,\n getCartId,\n setCartIdAction,\n} from '@gfed-medusa/sf-lib-common/lib/data/cookies';\nimport {\n graphqlFetch,\n graphqlMutation,\n} from '@gfed-medusa/sf-lib-common/lib/gql/apollo-client';\nimport {\n Cart,\n CreateCartMutation,\n CreateCartMutationVariables,\n CreateLineItemMutation,\n CreateLineItemMutationVariables,\n GetCartQuery,\n GetCartQueryVariables,\n UpdateCartMutation,\n UpdateCartMutationVariables,\n} from '@gfed-medusa/sf-lib-common/types/graphql';\n\nimport {\n CREATE_CART_MUTATION,\n CREATE_LINE_ITEM_MUTATION,\n UPDATE_CART_MUTATION,\n} from '@/lib/gql/mutations/cart';\nimport { GET_CART_QUERY } from '@/lib/gql/queries/cart';\n\nimport { getRegion } from './regions';\n\nexport const retrieveCart = async (\n cartId: string,\n ctx: StorefrontContext\n): Promise<Cart | null> => {\n const id = cartId || getCartId(ctx);\n if (!id) {\n return null;\n }\n\n try {\n const data = await graphqlFetch<GetCartQuery, GetCartQueryVariables>({\n query: GET_CART_QUERY,\n variables: { id },\n });\n\n return data?.cart ?? null;\n } catch (error) {\n console.error('Failed to fetch cart:', error);\n return null;\n }\n};\n\nexport const getOrSetCart = async (\n countryCode: string,\n ctx: StorefrontContext\n): Promise<Cart | null> => {\n const region = await getRegion(countryCode, ctx);\n\n if (!region) {\n throw new Error(`Region not found for country code: ${countryCode}`);\n }\n\n let cart = await retrieveCart(getCartId(ctx) || '', ctx);\n\n if (!cart) {\n const data = await graphqlMutation<\n CreateCartMutation,\n CreateCartMutationVariables\n >({\n mutation: CREATE_CART_MUTATION,\n variables: {\n data: { regionId: region.id },\n },\n });\n\n cart = data?.createCart ?? null;\n\n if (cart) {\n await setCartIdAction(cart.id);\n\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n }\n }\n\n if (cart && cart.regionId !== region.id) {\n const data = await graphqlMutation<\n UpdateCartMutation,\n UpdateCartMutationVariables\n >({\n mutation: UPDATE_CART_MUTATION,\n variables: {\n id: cart.id,\n data: { regionId: region.id },\n },\n });\n\n cart = data?.updateCart ?? cart;\n\n if (cart) {\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n }\n }\n\n return cart;\n};\n\nexport const addToCart = async (\n {\n variantId,\n quantity,\n countryCode,\n }: {\n variantId: string;\n quantity: number;\n countryCode: string;\n },\n ctx: StorefrontContext\n): Promise<CreateLineItemMutation['createLineItem'] | null> => {\n if (!variantId) {\n throw new Error('Missing variant ID when adding to cart');\n }\n\n if (!countryCode) {\n throw new Error('Missing country code when adding to cart');\n }\n\n const cart = await getOrSetCart(countryCode, ctx);\n\n if (!cart) {\n throw new Error('Error retrieving or creating cart');\n }\n\n try {\n const result = await graphqlMutation<\n CreateLineItemMutation,\n CreateLineItemMutationVariables\n >({\n mutation: CREATE_LINE_ITEM_MUTATION,\n variables: {\n cartId: cart.id,\n data: {\n variantId: variantId,\n quantity,\n },\n },\n });\n\n const lineItem = result?.createLineItem ?? null;\n\n if (lineItem) {\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n\n const fulfillmentCacheTag = getCacheTag('fulfillment', ctx);\n revalidateTag(fulfillmentCacheTag);\n }\n\n return lineItem;\n } catch (error: any) {\n console.error('GraphQL addToCart error:', error.message);\n throw error;\n }\n};\n"],"mappings":";;;;;;;;;;AAmCA,MAAa,eAAe,OAC1B,QACA,QACyB;CACzB,MAAM,KAAK,UAAU,UAAU,IAAI;AACnC,KAAI,CAAC,GACH,QAAO;AAGT,KAAI;AAMF,UALa,MAAM,aAAkD;GACnE,OAAO;GACP,WAAW,EAAE,IAAI;GAClB,CAAC,GAEW,QAAQ;UACd,OAAO;AACd,UAAQ,MAAM,yBAAyB,MAAM;AAC7C,SAAO;;;AAIX,MAAa,eAAe,OAC1B,aACA,QACyB;CACzB,MAAM,SAAS,M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* as _apollo_client0 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/fragments/cart.d.ts
4
- declare const LINE_ITEM_FRAGMENT: _apollo_client9.DocumentNode;
5
- declare const ADDRESS_FRAGMENT: _apollo_client9.DocumentNode;
6
- declare const SHIPPING_METHODS_FRAGMENT: _apollo_client9.DocumentNode;
7
- declare const PAYMENT_COLLECTION_FRAGMENT: _apollo_client9.DocumentNode;
8
- declare const COUNTRY_FRAGMENT: _apollo_client9.DocumentNode;
9
- declare const REGION_FRAGMENT: _apollo_client9.DocumentNode;
10
- declare const PROMOTION_FRAGMENT: _apollo_client9.DocumentNode;
11
- declare const CART_FRAGMENT: _apollo_client9.DocumentNode;
4
+ declare const LINE_ITEM_FRAGMENT: _apollo_client0.DocumentNode;
5
+ declare const ADDRESS_FRAGMENT: _apollo_client0.DocumentNode;
6
+ declare const SHIPPING_METHODS_FRAGMENT: _apollo_client0.DocumentNode;
7
+ declare const PAYMENT_COLLECTION_FRAGMENT: _apollo_client0.DocumentNode;
8
+ declare const COUNTRY_FRAGMENT: _apollo_client0.DocumentNode;
9
+ declare const REGION_FRAGMENT: _apollo_client0.DocumentNode;
10
+ declare const PROMOTION_FRAGMENT: _apollo_client0.DocumentNode;
11
+ declare const CART_FRAGMENT: _apollo_client0.DocumentNode;
12
12
  //#endregion
13
13
  export { ADDRESS_FRAGMENT, CART_FRAGMENT, COUNTRY_FRAGMENT, LINE_ITEM_FRAGMENT, PAYMENT_COLLECTION_FRAGMENT, PROMOTION_FRAGMENT, REGION_FRAGMENT, SHIPPING_METHODS_FRAGMENT };
14
14
  //# sourceMappingURL=cart.d.ts.map
@@ -1,16 +1,16 @@
1
- import * as _apollo_client0 from "@apollo/client";
1
+ import * as _apollo_client16 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/fragments/product.d.ts
4
- declare const PRODUCT_IMAGE_FRAGMENT: _apollo_client0.DocumentNode;
5
- declare const PRODUCT_TAG_FRAGMENT: _apollo_client0.DocumentNode;
6
- declare const PRODUCT_OPTION_FRAGMENT: _apollo_client0.DocumentNode;
7
- declare const PRICE_FRAGMENT: _apollo_client0.DocumentNode;
8
- declare const PRODUCT_VARIANT_FRAGMENT: _apollo_client0.DocumentNode;
9
- declare const PRODUCT_CATEGORY_FRAGMENT: _apollo_client0.DocumentNode;
10
- declare const PRODUCT_COLLECTION_FRAGMENT: _apollo_client0.DocumentNode;
11
- declare const PRODUCT_FRAGMENT: _apollo_client0.DocumentNode;
12
- declare const COLLECTION_PRODUCTS_FRAGMENT: _apollo_client0.DocumentNode;
13
- declare const PRODUCT_HIT_FRAGMENT: _apollo_client0.DocumentNode;
4
+ declare const PRODUCT_IMAGE_FRAGMENT: _apollo_client16.DocumentNode;
5
+ declare const PRODUCT_TAG_FRAGMENT: _apollo_client16.DocumentNode;
6
+ declare const PRODUCT_OPTION_FRAGMENT: _apollo_client16.DocumentNode;
7
+ declare const PRICE_FRAGMENT: _apollo_client16.DocumentNode;
8
+ declare const PRODUCT_VARIANT_FRAGMENT: _apollo_client16.DocumentNode;
9
+ declare const PRODUCT_CATEGORY_FRAGMENT: _apollo_client16.DocumentNode;
10
+ declare const PRODUCT_COLLECTION_FRAGMENT: _apollo_client16.DocumentNode;
11
+ declare const PRODUCT_FRAGMENT: _apollo_client16.DocumentNode;
12
+ declare const COLLECTION_PRODUCTS_FRAGMENT: _apollo_client16.DocumentNode;
13
+ declare const PRODUCT_HIT_FRAGMENT: _apollo_client16.DocumentNode;
14
14
  //#endregion
15
15
  export { COLLECTION_PRODUCTS_FRAGMENT, PRICE_FRAGMENT, PRODUCT_CATEGORY_FRAGMENT, PRODUCT_COLLECTION_FRAGMENT, PRODUCT_FRAGMENT, PRODUCT_HIT_FRAGMENT, PRODUCT_IMAGE_FRAGMENT, PRODUCT_OPTION_FRAGMENT, PRODUCT_TAG_FRAGMENT, PRODUCT_VARIANT_FRAGMENT };
16
16
  //# sourceMappingURL=product.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"product.d.ts","names":[],"sources":["../../../../src/lib/gql/fragments/product.ts"],"sourcesContent":[],"mappings":";;;cAEa,wBAKZ,eAAA,CALkC;cAOtB,sBAIZ,eAAA,CAJgC;cAMpB,yBASZ,eAAA,CATmC;AAbvB,cAwBA,cAnBZ,EAyBA,eAAA,CAN0B,YAnB1B;AAEY,cAyBA,wBArBZ,EA0CA,eAAA,CArBoC,YArBpC;AAEY,cA0CA,yBAjCZ,EAwCA,eAAA,CAPqC,YAjCrC;AAEY,cAwCA,2BAlCZ,EAwCA,eAAA,CANuC,YAlCvC;AAEY,cAwCA,gBAnBZ,EAwDA,eAAA,CArC4B,YAnB5B;AAEY,cAwDA,4BAjDZ,EAwEA,eAAA,CAvBwC,YAjDxC;AAEY,cAwEA,oBAlEZ,EA0EA,eAAA,CARgC,YAlEhC"}
1
+ {"version":3,"file":"product.d.ts","names":[],"sources":["../../../../src/lib/gql/fragments/product.ts"],"sourcesContent":[],"mappings":";;;cAEa,wBAKZ,gBAAA,CALkC;cAOtB,sBAIZ,gBAAA,CAJgC;cAMpB,yBASZ,gBAAA,CATmC;AAbvB,cAwBA,cAnBZ,EAyBA,gBAAA,CAN0B,YAnB1B;AAEY,cAyBA,wBArBZ,EA0CA,gBAAA,CArBoC,YArBpC;AAEY,cA0CA,yBAjCZ,EAwCA,gBAAA,CAPqC,YAjCrC;AAEY,cAwCA,2BAlCZ,EAwCA,gBAAA,CANuC,YAlCvC;AAEY,cAwCA,gBAnBZ,EAwDA,gBAAA,CArC4B,YAnB5B;AAEY,cAwDA,4BAjDZ,EAwEA,gBAAA,CAvBwC,YAjDxC;AAEY,cAwEA,oBAlEZ,EA0EA,gBAAA,CARgC,YAlEhC"}
@@ -1,15 +1,15 @@
1
- import * as _apollo_client18 from "@apollo/client";
1
+ import * as _apollo_client7 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/mutations/cart.d.ts
4
- declare const CREATE_CART_MUTATION: _apollo_client18.DocumentNode;
5
- declare const UPDATE_CART_MUTATION: _apollo_client18.DocumentNode;
6
- declare const CREATE_LINE_ITEM_MUTATION: _apollo_client18.DocumentNode;
7
- declare const UPDATE_LINE_ITEM_MUTATION: _apollo_client18.DocumentNode;
8
- declare const DELETE_LINE_ITEM_MUTATION: _apollo_client18.DocumentNode;
9
- declare const ADD_SHIPPING_METHOD_MUTATION: _apollo_client18.DocumentNode;
10
- declare const COMPLETE_CART_MUTATION: _apollo_client18.DocumentNode;
11
- declare const TRANSFER_CART_MUTATION: _apollo_client18.DocumentNode;
12
- declare const APPLY_PROMOTIONS_MUTATION: _apollo_client18.DocumentNode;
4
+ declare const CREATE_CART_MUTATION: _apollo_client7.DocumentNode;
5
+ declare const UPDATE_CART_MUTATION: _apollo_client7.DocumentNode;
6
+ declare const CREATE_LINE_ITEM_MUTATION: _apollo_client7.DocumentNode;
7
+ declare const UPDATE_LINE_ITEM_MUTATION: _apollo_client7.DocumentNode;
8
+ declare const DELETE_LINE_ITEM_MUTATION: _apollo_client7.DocumentNode;
9
+ declare const ADD_SHIPPING_METHOD_MUTATION: _apollo_client7.DocumentNode;
10
+ declare const COMPLETE_CART_MUTATION: _apollo_client7.DocumentNode;
11
+ declare const TRANSFER_CART_MUTATION: _apollo_client7.DocumentNode;
12
+ declare const APPLY_PROMOTIONS_MUTATION: _apollo_client7.DocumentNode;
13
13
  //#endregion
14
14
  export { ADD_SHIPPING_METHOD_MUTATION, APPLY_PROMOTIONS_MUTATION, COMPLETE_CART_MUTATION, CREATE_CART_MUTATION, CREATE_LINE_ITEM_MUTATION, DELETE_LINE_ITEM_MUTATION, TRANSFER_CART_MUTATION, UPDATE_CART_MUTATION, UPDATE_LINE_ITEM_MUTATION };
15
15
  //# sourceMappingURL=cart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cart.d.ts","names":[],"sources":["../../../../src/lib/gql/mutations/cart.ts"],"sourcesContent":[],"mappings":";;;cAUa,sBAOZ,gBAAA,CAPgC;cASpB,sBAgBZ,gBAAA,CAhBgC;cAkBpB,2BAWZ,gBAAA,CAXqC;AA3BzB,cAwCA,yBAjCZ,EAgDA,gBAAA,CAfqC,YAjCrC;AAEY,cAgDA,yBAhCZ,EAwCA,gBAAA,CARqC,YAhCrC;AAEY,cAwCA,4BA7BZ,EA4CA,gBAAA,CAfwC,YA7BxC;AAEY,cA4CA,sBA7BZ,EAqFA,gBAAA,CAxDkC,YA7BlC;AAEY,cAqFA,sBA7EZ,EAoFA,gBAAA,CAPkC,YA7ElC;AAEY,cAoFA,yBArEZ,EA4EA,gBAAA,CAPqC,YArErC"}
1
+ {"version":3,"file":"cart.d.ts","names":[],"sources":["../../../../src/lib/gql/mutations/cart.ts"],"sourcesContent":[],"mappings":";;;cAUa,sBAOZ,eAAA,CAPgC;cASpB,sBAgBZ,eAAA,CAhBgC;cAkBpB,2BAWZ,eAAA,CAXqC;AA3BzB,cAwCA,yBAjCZ,EAgDA,eAAA,CAfqC,YAjCrC;AAEY,cAgDA,yBAhCZ,EAwCA,eAAA,CARqC,YAhCrC;AAEY,cAwCA,4BA7BZ,EA4CA,eAAA,CAfwC,YA7BxC;AAEY,cA4CA,sBA7BZ,EAqFA,eAAA,CAxDkC,YA7BlC;AAEY,cAqFA,sBA7EZ,EAoFA,eAAA,CAPkC,YA7ElC;AAEY,cAoFA,yBArEZ,EA4EA,eAAA,CAPqC,YArErC"}
@@ -1,7 +1,7 @@
1
- import * as _apollo_client17 from "@apollo/client";
1
+ import * as _apollo_client26 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/queries/cart.d.ts
4
- declare const GET_CART_QUERY: _apollo_client17.DocumentNode;
4
+ declare const GET_CART_QUERY: _apollo_client26.DocumentNode;
5
5
  //#endregion
6
6
  export { GET_CART_QUERY };
7
7
  //# sourceMappingURL=cart.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { SortOptions } from "../../components/refinement-list/sort-products/index.js";
2
- import * as react_jsx_runtime4 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime9 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/templates/paginated-products/index.d.ts
5
5
  declare function PaginatedProducts({
@@ -16,7 +16,7 @@ declare function PaginatedProducts({
16
16
  categoryId?: string;
17
17
  productsIds?: string[];
18
18
  countryCode: string;
19
- }): Promise<react_jsx_runtime4.JSX.Element | null>;
19
+ }): Promise<react_jsx_runtime9.JSX.Element | null>;
20
20
  //#endregion
21
21
  export { PaginatedProducts as default };
22
22
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime5 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime4 from "react/jsx-runtime";
2
2
  import { Region } from "@gfed-medusa/sf-lib-common/types/graphql";
3
3
 
4
4
  //#region src/templates/product-actions-wrapper/index.d.ts
@@ -11,7 +11,7 @@ declare function ProductActionsWrapper({
11
11
  }: {
12
12
  id: string;
13
13
  region: Region;
14
- }): Promise<react_jsx_runtime5.JSX.Element | null>;
14
+ }): Promise<react_jsx_runtime4.JSX.Element | null>;
15
15
  //#endregion
16
16
  export { ProductActionsWrapper as default };
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { Product } from "../../types/graphql.js";
2
- import * as react_jsx_runtime0 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime7 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/templates/product-info/index.d.ts
5
5
  type ProductInfoProps = {
@@ -7,7 +7,7 @@ type ProductInfoProps = {
7
7
  };
8
8
  declare const ProductInfo: ({
9
9
  product
10
- }: ProductInfoProps) => react_jsx_runtime0.JSX.Element;
10
+ }: ProductInfoProps) => react_jsx_runtime7.JSX.Element;
11
11
  //#endregion
12
12
  export { ProductInfo as default };
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { SortOptions } from "../../components/refinement-list/sort-products/index.js";
2
- import * as react_jsx_runtime14 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime8 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/templates/store-template/index.d.ts
5
5
  declare const StoreTemplate: ({
@@ -10,7 +10,7 @@ declare const StoreTemplate: ({
10
10
  sortBy?: SortOptions;
11
11
  page?: string;
12
12
  countryCode: string;
13
- }) => react_jsx_runtime14.JSX.Element;
13
+ }) => react_jsx_runtime8.JSX.Element;
14
14
  //#endregion
15
15
  export { StoreTemplate as default };
16
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/templates/store-template/index.tsx"],"sourcesContent":[],"mappings":";;;;cAQM;;;;;WAKK;;EALL,WAAA,EAAA,MAgCL;CAhCsB,EAAA,GAQtB,mBAAA,CAAA,GAAA,CAAA,OARsB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/templates/store-template/index.tsx"],"sourcesContent":[],"mappings":";;;;cAQM;;;;;WAKK;;EALL,WAAA,EAAA,MAgCL;CAhCsB,EAAA,GAQtB,kBAAA,CAAA,GAAA,CAAA,OARsB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gfed-medusa/sf-lib-products",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
@@ -51,8 +51,8 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@apollo/client": "^4.0.9",
54
- "@gfed-medusa/sf-lib-common": "^2.2.0",
55
- "@gfed-medusa/sf-lib-ui": "^1.2.0",
54
+ "@gfed-medusa/sf-lib-common": "^2.2.1",
55
+ "@gfed-medusa/sf-lib-ui": "^1.2.1",
56
56
  "@headlessui/react": "^2.2.9",
57
57
  "@medusajs/icons": "^2.12.1",
58
58
  "@medusajs/types": "^2.12.1",