@gfed-medusa/sf-lib-products 1.3.0 → 1.3.3

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 (32) hide show
  1. package/dist/components/product-actions/index.d.ts +2 -2
  2. package/dist/components/product-actions/index.d.ts.map +1 -1
  3. package/dist/components/product-onboarding-cta/index.d.ts +2 -2
  4. package/dist/components/product-price/index.d.ts +2 -2
  5. package/dist/components/refinement-list/index.d.ts +2 -2
  6. package/dist/components/refinement-list/index.d.ts.map +1 -1
  7. package/dist/components/refinement-list/sort-products/index.d.ts +2 -2
  8. package/dist/components/related-products/index.d.ts +2 -2
  9. package/dist/components/related-products/index.d.ts.map +1 -1
  10. package/dist/components/skeleton-product-grid/index.d.ts +2 -2
  11. package/dist/components/skeleton-product-preview/index.d.ts +2 -2
  12. package/dist/components/skeleton-related-products/index.d.ts +2 -2
  13. package/dist/lib/data/cart.js +2 -1
  14. package/dist/lib/data/cart.js.map +1 -1
  15. package/dist/lib/data/regions.d.ts +2 -9
  16. package/dist/lib/data/regions.js +2 -36
  17. package/dist/lib/gql/fragments/cart.d.ts +9 -9
  18. package/dist/lib/gql/fragments/cart.d.ts.map +1 -1
  19. package/dist/lib/gql/mutations/cart.d.ts +10 -10
  20. package/dist/lib/gql/queries/cart.d.ts +2 -2
  21. package/dist/lib/gql/queries/cart.d.ts.map +1 -1
  22. package/dist/lib/gql/queries/product.d.ts +9 -9
  23. package/dist/templates/paginated-products/index.d.ts +2 -2
  24. package/dist/templates/paginated-products/index.d.ts.map +1 -1
  25. package/dist/templates/product-actions-wrapper/index.d.ts +2 -2
  26. package/dist/templates/product-actions-wrapper/index.d.ts.map +1 -1
  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 +2 -2
  31. package/dist/lib/data/regions.d.ts.map +0 -1
  32. package/dist/lib/data/regions.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { Product } from "../../types/graphql.js";
2
- import * as react_jsx_runtime14 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime1 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_runtime14.JSX.Element;
14
+ }: ProductActionsProps): react_jsx_runtime1.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":";;;;KAuBY,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
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/product-actions/index.tsx"],"sourcesContent":[],"mappings":";;;;KAuBY,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,7 +1,7 @@
1
- import * as react_jsx_runtime6 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime2 from "react/jsx-runtime";
2
2
 
3
3
  //#region src/components/product-onboarding-cta/index.d.ts
4
- declare function ProductOnboardingCta(): Promise<react_jsx_runtime6.JSX.Element | null>;
4
+ declare function ProductOnboardingCta(): Promise<react_jsx_runtime2.JSX.Element | null>;
5
5
  //#endregion
6
6
  export { ProductOnboardingCta as default };
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { Product, ProductVariant } from "../../types/graphql.js";
2
- import * as react_jsx_runtime1 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime3 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_runtime1.JSX.Element;
11
+ }): react_jsx_runtime3.JSX.Element;
12
12
  //#endregion
13
13
  export { ProductPrice as default };
14
14
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { SortOptions } from "./sort-products/index.js";
2
- import * as react_jsx_runtime5 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_runtime5.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 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/refinement-list/index.tsx"],"sourcesContent":[],"mappings":";;;;KAQK,mBAAA;UACK;;EADL,aAAA,CAAA,EAAA,MAAmB;AACH,CAAA;cAKf,cAAkB,EAAA,CAAA;EAAA,MAAA;EAAA,aAAA,EAAA;AAAA,CAAA,EAGrB,mBAHqB,EAAA,GAGF,kBAAA,CAAA,GAAA,CAAA,OAHE"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/refinement-list/index.tsx"],"sourcesContent":[],"mappings":";;;;KAQK,mBAAA;UACK;;EADL,aAAA,CAAA,EAAA,MAAmB;AACH,CAAA;cAKf,cAAkB,EAAA,CAAA;EAAA,MAAA;EAAA,aAAA,EAAA;AAAA,CAAA,EAGrB,mBAHqB,EAAA,GAGF,mBAAA,CAAA,GAAA,CAAA,OAHE"}
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime10 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_runtime10.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_runtime7 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime13 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_runtime7.JSX.Element | null>;
12
+ }: RelatedProductsProps): Promise<react_jsx_runtime13.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,kBAAA,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,mBAAA,CAAA,GAAA,CAAA,OAAA,GAHsB,IAAA,CAAA"}
@@ -1,11 +1,11 @@
1
- import * as react_jsx_runtime8 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime5 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_runtime8.JSX.Element;
8
+ }) => react_jsx_runtime5.JSX.Element;
9
9
  //#endregion
10
10
  export { SkeletonProductGrid as default };
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,7 @@
1
- import * as react_jsx_runtime2 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime6 from "react/jsx-runtime";
2
2
 
3
3
  //#region src/components/skeleton-product-preview/index.d.ts
4
- declare const SkeletonProductPreview: () => react_jsx_runtime2.JSX.Element;
4
+ declare const SkeletonProductPreview: () => react_jsx_runtime6.JSX.Element;
5
5
  //#endregion
6
6
  export { SkeletonProductPreview as default };
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,7 @@
1
- import * as react_jsx_runtime3 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime7 from "react/jsx-runtime";
2
2
 
3
3
  //#region src/components/skeleton-related-products/index.d.ts
4
- declare const SkeletonRelatedProducts: () => react_jsx_runtime3.JSX.Element;
4
+ declare const SkeletonRelatedProducts: () => react_jsx_runtime7.JSX.Element;
5
5
  //#endregion
6
6
  export { SkeletonRelatedProducts as default };
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -3,7 +3,8 @@
3
3
  import { CREATE_CART_MUTATION, CREATE_LINE_ITEM_MUTATION, UPDATE_CART_MUTATION } from "../gql/mutations/cart.js";
4
4
  import { GET_CART_QUERY } from "../gql/queries/cart.js";
5
5
  import { getRegion } from "./regions.js";
6
- import { getCacheTag, getCartId, setCartIdAction } from "@gfed-medusa/sf-lib-common/lib/data/cookies";
6
+ import { setCartIdAction } from "@gfed-medusa/sf-lib-common/lib/data/cookies-actions";
7
+ import { getCacheTag, getCartId } from "@gfed-medusa/sf-lib-common/lib/data/cookies-utils";
7
8
  import { graphqlFetch, graphqlMutation } from "@gfed-medusa/sf-lib-common/lib/gql/apollo-client";
8
9
 
9
10
  //#region src/lib/data/cart.ts
@@ -1 +1 @@
1
- {"version":3,"file":"cart.js","names":["error: any"],"sources":["../../../src/lib/data/cart.ts"],"sourcesContent":["'use server';\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 try {\n const { revalidateTag } = await import('next/cache');\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n } catch {\n // Not in Next.js environment, skip revalidation\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 try {\n const { revalidateTag } = await import('next/cache');\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n } catch {\n // Not in Next.js environment\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 try {\n const { revalidateTag } = await import('next/cache');\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n const fulfillmentCacheTag = getCacheTag('fulfillment', ctx);\n revalidateTag(fulfillmentCacheTag);\n } catch {\n // Not in Next.js environment\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":";;;;;;;;;AAiCA,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,gBAAgB,KAAK,GAAG;AAE9B,OAAI;IACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,kBADqB,YAAY,SAAS,IAAI,CACnB;WACrB;;;AAMZ,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;GACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,iBADqB,YAAY,SAAS,IAAI,CACnB;UACrB;;AAMZ,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;GACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,iBADqB,YAAY,SAAS,IAAI,CACnB;AAE3B,iBAD4B,YAAY,eAAe,IAAI,CACzB;UAC5B;AAKV,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 type { StorefrontContext } from '@gfed-medusa/sf-lib-common/lib/data/context';\nimport { setCartIdAction } from '@gfed-medusa/sf-lib-common/lib/data/cookies-actions';\nimport {\n getCacheTag,\n getCartId,\n} from '@gfed-medusa/sf-lib-common/lib/data/cookies-utils';\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 try {\n const { revalidateTag } = await import('next/cache');\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n } catch {\n // Not in Next.js environment, skip revalidation\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 try {\n const { revalidateTag } = await import('next/cache');\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n } catch {\n // Not in Next.js environment\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 try {\n const { revalidateTag } = await import('next/cache');\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n const fulfillmentCacheTag = getCacheTag('fulfillment', ctx);\n revalidateTag(fulfillmentCacheTag);\n } catch {\n // Not in Next.js environment\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":";;;;;;;;;;AAiCA,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,gBAAgB,KAAK,GAAG;AAE9B,OAAI;IACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,kBADqB,YAAY,SAAS,IAAI,CACnB;WACrB;;;AAMZ,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;GACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,iBADqB,YAAY,SAAS,IAAI,CACnB;UACrB;;AAMZ,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;GACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,iBADqB,YAAY,SAAS,IAAI,CACnB;AAE3B,iBAD4B,YAAY,eAAe,IAAI,CACzB;UAC5B;AAKV,SAAO;UACAA,OAAY;AACnB,UAAQ,MAAM,4BAA4B,MAAM,QAAQ;AACxD,QAAM"}
@@ -1,9 +1,2 @@
1
- import { StorefrontContext } from "@gfed-medusa/sf-lib-common/lib/data/context";
2
- import { Region } from "@gfed-medusa/sf-lib-common/types/graphql";
3
-
4
- //#region src/lib/data/regions.d.ts
5
- declare const retrieveRegion: (id: string, ctx: StorefrontContext) => Promise<Region | null>;
6
- declare const getRegion: (countryCode: string, ctx: StorefrontContext) => Promise<Region | null>;
7
- //#endregion
8
- export { getRegion, retrieveRegion };
9
- //# sourceMappingURL=regions.d.ts.map
1
+ import { getRegion, listRegions, retrieveRegion } from "@gfed-medusa/sf-lib-common/lib/data/regions";
2
+ export { getRegion, listRegions, retrieveRegion };
@@ -1,37 +1,3 @@
1
- 'use server';
1
+ import { getRegion, listRegions, retrieveRegion } from "@gfed-medusa/sf-lib-common/lib/data/regions";
2
2
 
3
- import { getCacheOptions } from "@gfed-medusa/sf-lib-common/lib/data/cookies";
4
- import { sdk } from "@gfed-medusa/sf-lib-common/lib/config/medusa";
5
- import { listRegions } from "@gfed-medusa/sf-lib-common/lib/data/regions";
6
- import { medusaError } from "@gfed-medusa/sf-lib-common/lib/utils/medusa-error";
7
- import { normalizeRegion } from "@gfed-medusa/sf-lib-common/lib/utils/normalize-functions";
8
-
9
- //#region src/lib/data/regions.ts
10
- const retrieveRegion = async (id, ctx) => {
11
- const next = { ...getCacheOptions(["regions", id].join("-"), ctx) };
12
- return sdk.client.fetch(`/store/regions/${id}`, {
13
- method: "GET",
14
- next,
15
- cache: "force-cache"
16
- }).then(({ region }) => region ? normalizeRegion(region) : null).catch(medusaError);
17
- };
18
- const regionMap = /* @__PURE__ */ new Map();
19
- const getRegion = async (countryCode, ctx) => {
20
- try {
21
- if (regionMap.has(countryCode)) return regionMap.get(countryCode) ?? null;
22
- const regions = await listRegions(ctx);
23
- if (!regions) return null;
24
- regions.forEach((region) => {
25
- region.countries?.forEach((c) => {
26
- regionMap.set(c?.iso2 ?? "", region);
27
- });
28
- });
29
- return countryCode ? regionMap.get(countryCode) ?? null : regionMap.get("us") ?? null;
30
- } catch (e) {
31
- return null;
32
- }
33
- };
34
-
35
- //#endregion
36
- export { getRegion, retrieveRegion };
37
- //# sourceMappingURL=regions.js.map
3
+ export { getRegion, listRegions, retrieveRegion };
@@ -1,14 +1,14 @@
1
- import * as _apollo_client18 from "@apollo/client";
1
+ import * as _apollo_client9 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/fragments/cart.d.ts
4
- declare const LINE_ITEM_FRAGMENT: _apollo_client18.DocumentNode;
5
- declare const ADDRESS_FRAGMENT: _apollo_client18.DocumentNode;
6
- declare const SHIPPING_METHODS_FRAGMENT: _apollo_client18.DocumentNode;
7
- declare const PAYMENT_COLLECTION_FRAGMENT: _apollo_client18.DocumentNode;
8
- declare const COUNTRY_FRAGMENT: _apollo_client18.DocumentNode;
9
- declare const REGION_FRAGMENT: _apollo_client18.DocumentNode;
10
- declare const PROMOTION_FRAGMENT: _apollo_client18.DocumentNode;
11
- declare const CART_FRAGMENT: _apollo_client18.DocumentNode;
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;
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 +1 @@
1
- {"version":3,"file":"cart.d.ts","names":[],"sources":["../../../../src/lib/gql/fragments/cart.ts"],"sourcesContent":[],"mappings":";;;cAIa,oBAiBZ,gBAAA,CAjB8B;cAmBlB,kBAUZ,gBAAA,CAV4B;cAYhB,2BAUZ,gBAAA,CAVqC;AA/BzB,cA2CA,2BA1BZ,EA4CA,gBAAA,CAlBuC,YA1BvC;AAEY,cA4CA,gBAlCZ,EAyCA,gBAAA,CAP4B,YAlC5B;AAEY,cAyCA,eA/BZ,EA0CA,gBAAA,CAX2B,YA/B3B;AAEY,cA0CA,kBAxBZ,EAkCA,gBAAA,CAV8B,YAxB9B;AAEY,cAkCA,aA3BZ,EAsEA,gBAAA,CA3CyB,YA3BzB"}
1
+ {"version":3,"file":"cart.d.ts","names":[],"sources":["../../../../src/lib/gql/fragments/cart.ts"],"sourcesContent":[],"mappings":";;;cAIa,oBAiBZ,eAAA,CAjB8B;cAmBlB,kBAUZ,eAAA,CAV4B;cAYhB,2BAUZ,eAAA,CAVqC;AA/BzB,cA2CA,2BA1BZ,EA4CA,eAAA,CAlBuC,YA1BvC;AAEY,cA4CA,gBAlCZ,EAyCA,eAAA,CAP4B,YAlC5B;AAEY,cAyCA,eA/BZ,EA0CA,eAAA,CAX2B,YA/B3B;AAEY,cA0CA,kBAxBZ,EAkCA,eAAA,CAV8B,YAxB9B;AAEY,cAkCA,aA3BZ,EAsEA,eAAA,CA3CyB,YA3BzB"}
@@ -1,15 +1,15 @@
1
- import * as _apollo_client26 from "@apollo/client";
1
+ import * as _apollo_client17 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/mutations/cart.d.ts
4
- declare const CREATE_CART_MUTATION: _apollo_client26.DocumentNode;
5
- declare const UPDATE_CART_MUTATION: _apollo_client26.DocumentNode;
6
- declare const CREATE_LINE_ITEM_MUTATION: _apollo_client26.DocumentNode;
7
- declare const UPDATE_LINE_ITEM_MUTATION: _apollo_client26.DocumentNode;
8
- declare const DELETE_LINE_ITEM_MUTATION: _apollo_client26.DocumentNode;
9
- declare const ADD_SHIPPING_METHOD_MUTATION: _apollo_client26.DocumentNode;
10
- declare const COMPLETE_CART_MUTATION: _apollo_client26.DocumentNode;
11
- declare const TRANSFER_CART_MUTATION: _apollo_client26.DocumentNode;
12
- declare const APPLY_PROMOTIONS_MUTATION: _apollo_client26.DocumentNode;
4
+ declare const CREATE_CART_MUTATION: _apollo_client17.DocumentNode;
5
+ declare const UPDATE_CART_MUTATION: _apollo_client17.DocumentNode;
6
+ declare const CREATE_LINE_ITEM_MUTATION: _apollo_client17.DocumentNode;
7
+ declare const UPDATE_LINE_ITEM_MUTATION: _apollo_client17.DocumentNode;
8
+ declare const DELETE_LINE_ITEM_MUTATION: _apollo_client17.DocumentNode;
9
+ declare const ADD_SHIPPING_METHOD_MUTATION: _apollo_client17.DocumentNode;
10
+ declare const COMPLETE_CART_MUTATION: _apollo_client17.DocumentNode;
11
+ declare const TRANSFER_CART_MUTATION: _apollo_client17.DocumentNode;
12
+ declare const APPLY_PROMOTIONS_MUTATION: _apollo_client17.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,7 +1,7 @@
1
- import * as _apollo_client0 from "@apollo/client";
1
+ import * as _apollo_client34 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/queries/cart.d.ts
4
- declare const GET_CART_QUERY: _apollo_client0.DocumentNode;
4
+ declare const GET_CART_QUERY: _apollo_client34.DocumentNode;
5
5
  //#endregion
6
6
  export { GET_CART_QUERY };
7
7
  //# sourceMappingURL=cart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cart.d.ts","names":[],"sources":["../../../../src/lib/gql/queries/cart.ts"],"sourcesContent":[],"mappings":";;;cAIa,gBAOZ,eAAA,CAP0B"}
1
+ {"version":3,"file":"cart.d.ts","names":[],"sources":["../../../../src/lib/gql/queries/cart.ts"],"sourcesContent":[],"mappings":";;;cAIa,gBAOZ,gBAAA,CAP0B"}
@@ -1,14 +1,14 @@
1
- import * as _apollo_client10 from "@apollo/client";
1
+ import * as _apollo_client26 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/queries/product.d.ts
4
- declare const GET_PRODUCTS_QUERY: _apollo_client10.DocumentNode;
5
- declare const GET_PRODUCT_QUERY: _apollo_client10.DocumentNode;
6
- declare const GET_PRODUCT_CATEGORIES_QUERY: _apollo_client10.DocumentNode;
7
- declare const GET_PRODUCT_CATEGORY_QUERY: _apollo_client10.DocumentNode;
8
- declare const GET_COLLECTIONS_QUERY: _apollo_client10.DocumentNode;
9
- declare const GET_COLLECTIONS_SUMMARY_QUERY: _apollo_client10.DocumentNode;
10
- declare const GET_COLLECTION_QUERY: _apollo_client10.DocumentNode;
11
- declare const SEARCH_SUGGESTIONS_QUERY: _apollo_client10.DocumentNode;
4
+ declare const GET_PRODUCTS_QUERY: _apollo_client26.DocumentNode;
5
+ declare const GET_PRODUCT_QUERY: _apollo_client26.DocumentNode;
6
+ declare const GET_PRODUCT_CATEGORIES_QUERY: _apollo_client26.DocumentNode;
7
+ declare const GET_PRODUCT_CATEGORY_QUERY: _apollo_client26.DocumentNode;
8
+ declare const GET_COLLECTIONS_QUERY: _apollo_client26.DocumentNode;
9
+ declare const GET_COLLECTIONS_SUMMARY_QUERY: _apollo_client26.DocumentNode;
10
+ declare const GET_COLLECTION_QUERY: _apollo_client26.DocumentNode;
11
+ declare const SEARCH_SUGGESTIONS_QUERY: _apollo_client26.DocumentNode;
12
12
  //#endregion
13
13
  export { GET_COLLECTIONS_QUERY, GET_COLLECTIONS_SUMMARY_QUERY, GET_COLLECTION_QUERY, GET_PRODUCTS_QUERY, GET_PRODUCT_CATEGORIES_QUERY, GET_PRODUCT_CATEGORY_QUERY, GET_PRODUCT_QUERY, SEARCH_SUGGESTIONS_QUERY };
14
14
  //# sourceMappingURL=product.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { SortOptions } from "../../components/refinement-list/sort-products/index.js";
2
- import * as react_jsx_runtime11 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime8 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_runtime11.JSX.Element | null>;
19
+ }): Promise<react_jsx_runtime8.JSX.Element | null>;
20
20
  //#endregion
21
21
  export { PaginatedProducts as default };
22
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/templates/paginated-products/index.tsx"],"sourcesContent":[],"mappings":";;;;iBAkB8B,iBAAA;;;;;;;;WAQnB;;EARmB,YAAA,CAAA,EAAA,MAAiB;EAC7C,UAAA,CAAA,EAAA,MAAA;EACA,WAAA,CAAA,EAAA,MAAA,EAAA;EACA,WAAA,EAAA,MAAA;CACA,CAAA,EAUD,OAVC,CAUD,mBAAA,CAAA,GAAA,CAAA,OAAA,GAVC,IAAA,CAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/templates/paginated-products/index.tsx"],"sourcesContent":[],"mappings":";;;;iBAkB8B,iBAAA;;;;;;;;WAQnB;;EARmB,YAAA,CAAA,EAAA,MAAiB;EAC7C,UAAA,CAAA,EAAA,MAAA;EACA,WAAA,CAAA,EAAA,MAAA,EAAA;EACA,WAAA,EAAA,MAAA;CACA,CAAA,EAUD,OAVC,CAUD,kBAAA,CAAA,GAAA,CAAA,OAAA,GAVC,IAAA,CAAA"}
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime13 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime9 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_runtime13.JSX.Element | null>;
14
+ }): Promise<react_jsx_runtime9.JSX.Element | null>;
15
15
  //#endregion
16
16
  export { ProductActionsWrapper as default };
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/templates/product-actions-wrapper/index.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAU8B,iBAAA,qBAAA,CAAqB;EAAA,EAAA;EAAA;CAAA,EAAA;EACjD,EAAA,EAAA,MAAA;EACA,MAAA,EAGQ,MAHR;CAGQ,CAAA,EACT,OADS,CACT,mBAAA,CAAA,GAAA,CAAA,OAAA,GADS,IAAA,CAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/templates/product-actions-wrapper/index.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAU8B,iBAAA,qBAAA,CAAqB;EAAA,EAAA;EAAA;CAAA,EAAA;EACjD,EAAA,EAAA,MAAA;EACA,MAAA,EAGQ,MAHR;CAGQ,CAAA,EACT,OADS,CACT,kBAAA,CAAA,GAAA,CAAA,OAAA,GADS,IAAA,CAAA"}
@@ -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_runtime10 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_runtime12.JSX.Element;
10
+ }: ProductInfoProps) => react_jsx_runtime10.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_runtime9 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime11 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_runtime9.JSX.Element;
13
+ }) => react_jsx_runtime11.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,kBAAA,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,mBAAA,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.3.0",
3
+ "version": "1.3.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@apollo/client": "^4.0.9",
54
- "@gfed-medusa/sf-lib-common": "^2.3.0",
54
+ "@gfed-medusa/sf-lib-common": "^3.0.0",
55
55
  "@gfed-medusa/sf-lib-ui": "^1.2.1",
56
56
  "@headlessui/react": "^2.2.9",
57
57
  "@medusajs/icons": "^2.12.1",
@@ -1 +0,0 @@
1
- {"version":3,"file":"regions.d.ts","names":[],"sources":["../../../src/lib/data/regions.ts"],"sourcesContent":[],"mappings":";;;;cAWa,kCAAyC,sBAAiB,QAAA;cAiB1D,sCAEN,sBACJ,QAAQ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"regions.js","names":["e: any"],"sources":["../../../src/lib/data/regions.ts"],"sourcesContent":["'use server';\n\nimport { sdk } from '@gfed-medusa/sf-lib-common/lib/config/medusa';\nimport type { StorefrontContext } from '@gfed-medusa/sf-lib-common/lib/data/context';\nimport { getCacheOptions } from '@gfed-medusa/sf-lib-common/lib/data/cookies';\nimport { listRegions } from '@gfed-medusa/sf-lib-common/lib/data/regions';\nimport { medusaError } from '@gfed-medusa/sf-lib-common/lib/utils/medusa-error';\nimport { normalizeRegion } from '@gfed-medusa/sf-lib-common/lib/utils/normalize-functions';\nimport { Region } from '@gfed-medusa/sf-lib-common/types/graphql';\nimport { HttpTypes } from '@medusajs/types';\n\nexport const retrieveRegion = async (id: string, ctx: StorefrontContext) => {\n const next = {\n ...getCacheOptions(['regions', id].join('-'), ctx),\n };\n\n return sdk.client\n .fetch<{ region: HttpTypes.StoreRegion }>(`/store/regions/${id}`, {\n method: 'GET',\n next,\n cache: 'force-cache',\n })\n .then(({ region }) => (region ? normalizeRegion(region) : null))\n .catch(medusaError);\n};\n\nconst regionMap = new Map<string, Region>();\n\nexport const getRegion = async (\n countryCode: string,\n ctx: StorefrontContext\n): Promise<Region | null> => {\n try {\n if (regionMap.has(countryCode)) {\n return regionMap.get(countryCode) ?? null;\n }\n\n const regions = await listRegions(ctx);\n\n if (!regions) return null;\n\n regions.forEach((region) => {\n region.countries?.forEach((c) => {\n regionMap.set(c?.iso2 ?? '', region);\n });\n });\n\n const region = countryCode\n ? (regionMap.get(countryCode) ?? null)\n : (regionMap.get('us') ?? null);\n\n return region;\n } catch (e: any) {\n return null;\n }\n};\n"],"mappings":";;;;;;;;;AAWA,MAAa,iBAAiB,OAAO,IAAY,QAA2B;CAC1E,MAAM,OAAO,EACX,GAAG,gBAAgB,CAAC,WAAW,GAAG,CAAC,KAAK,IAAI,EAAE,IAAI,EACnD;AAED,QAAO,IAAI,OACR,MAAyC,kBAAkB,MAAM;EAChE,QAAQ;EACR;EACA,OAAO;EACR,CAAC,CACD,MAAM,EAAE,aAAc,SAAS,gBAAgB,OAAO,GAAG,KAAM,CAC/D,MAAM,YAAY;;AAGvB,MAAM,4BAAY,IAAI,KAAqB;AAE3C,MAAa,YAAY,OACvB,aACA,QAC2B;AAC3B,KAAI;AACF,MAAI,UAAU,IAAI,YAAY,CAC5B,QAAO,UAAU,IAAI,YAAY,IAAI;EAGvC,MAAM,UAAU,MAAM,YAAY,IAAI;AAEtC,MAAI,CAAC,QAAS,QAAO;AAErB,UAAQ,SAAS,WAAW;AAC1B,UAAO,WAAW,SAAS,MAAM;AAC/B,cAAU,IAAI,GAAG,QAAQ,IAAI,OAAO;KACpC;IACF;AAMF,SAJe,cACV,UAAU,IAAI,YAAY,IAAI,OAC9B,UAAU,IAAI,KAAK,IAAI;UAGrBA,GAAQ;AACf,SAAO"}