@gfed-medusa/sf-lib-common 2.3.1 → 2.4.0

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 (55) hide show
  1. package/dist/components/breadcrumbs/index.d.ts +2 -2
  2. package/dist/components/cart-mismatch-banner/index.d.ts +2 -2
  3. package/dist/components/cart-mismatch-banner/index.d.ts.map +1 -1
  4. package/dist/components/delete-button/index.d.ts +2 -2
  5. package/dist/components/delete-button/index.d.ts.map +1 -1
  6. package/dist/components/delete-button/index.js +2 -2
  7. package/dist/components/delete-button/index.js.map +1 -1
  8. package/dist/components/error-message/index.d.ts +2 -2
  9. package/dist/components/free-shipping-price-nudge/index.d.ts +2 -2
  10. package/dist/components/interactive-link/index.d.ts +2 -2
  11. package/dist/components/line-item-options/index.d.ts +2 -2
  12. package/dist/components/line-item-price/index.d.ts +2 -2
  13. package/dist/components/line-item-price/index.d.ts.map +1 -1
  14. package/dist/components/localized-client-link/index.d.ts +2 -2
  15. package/dist/components/localized-client-link/index.d.ts.map +1 -1
  16. package/dist/components/modal/index.d.ts +2 -2
  17. package/dist/lib/data/cart.d.ts.map +1 -1
  18. package/dist/lib/data/cart.js +22 -15
  19. package/dist/lib/data/cart.js.map +1 -1
  20. package/dist/lib/data/context.d.ts +7 -7
  21. package/dist/lib/data/context.d.ts.map +1 -1
  22. package/dist/lib/data/context.js +19 -2
  23. package/dist/lib/data/context.js.map +1 -1
  24. package/dist/lib/data/cookies-utils.d.ts +1 -4
  25. package/dist/lib/data/cookies-utils.d.ts.map +1 -1
  26. package/dist/lib/data/cookies-utils.js +1 -6
  27. package/dist/lib/data/cookies-utils.js.map +1 -1
  28. package/dist/lib/data/customer.js +2 -4
  29. package/dist/lib/data/customer.js.map +1 -1
  30. package/dist/lib/data/next-context.js +0 -1
  31. package/dist/lib/data/next-context.js.map +1 -1
  32. package/dist/lib/data/orders.js +1 -3
  33. package/dist/lib/data/orders.js.map +1 -1
  34. package/dist/lib/globals/expose-globals.js +2 -2
  35. package/dist/lib/gql/apollo-client.d.ts.map +1 -1
  36. package/dist/lib/gql/apollo-client.js +4 -4
  37. package/dist/lib/gql/apollo-client.js.map +1 -1
  38. package/dist/lib/gql/fragments/cart.d.ts +9 -9
  39. package/dist/lib/gql/fragments/customer.d.ts +3 -3
  40. package/dist/lib/gql/fragments/customer.d.ts.map +1 -1
  41. package/dist/lib/gql/mutations/cart.d.ts +4 -4
  42. package/dist/lib/gql/mutations/cart.d.ts.map +1 -1
  43. package/dist/lib/gql/queries/cart.d.ts +2 -2
  44. package/dist/lib/gql/queries/collections.d.ts +2 -2
  45. package/dist/lib/gql/queries/customer.d.ts +2 -2
  46. package/dist/lib/gql/queries/footer.d.ts +2 -2
  47. package/dist/lib/gql/queries/product.d.ts +3 -3
  48. package/dist/lib/gql/queries/product.d.ts.map +1 -1
  49. package/dist/lib/hooks/use-apollo.d.ts +2 -2
  50. package/dist/lib/hooks/use-apollo.d.ts.map +1 -1
  51. package/dist/lib/hooks/use-cart.d.ts +1 -2
  52. package/dist/lib/hooks/use-cart.d.ts.map +1 -1
  53. package/dist/lib/hooks/use-cart.js +9 -5
  54. package/dist/lib/hooks/use-cart.js.map +1 -1
  55. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime2 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
2
2
 
3
3
  //#region src/components/breadcrumbs/index.d.ts
4
4
  declare const SEPARATOR_ICONS: Record<string, React.ComponentType<{
@@ -14,7 +14,7 @@ declare function Breadcrumbs({
14
14
  iconClassName,
15
15
  iconSize,
16
16
  separatorIcon
17
- }: BreadcrumbsProps): react_jsx_runtime2.JSX.Element;
17
+ }: BreadcrumbsProps): react_jsx_runtime0.JSX.Element;
18
18
  //#endregion
19
19
  export { Breadcrumbs };
20
20
  //# sourceMappingURL=index.d.ts.map
@@ -1,11 +1,11 @@
1
1
  import { Cart, Customer } from "../../types/graphql.js";
2
- import * as react_jsx_runtime0 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime14 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/cart-mismatch-banner/index.d.ts
5
5
  declare function CartMismatchBanner(props: {
6
6
  customer: Customer;
7
7
  cart: Cart;
8
- }): react_jsx_runtime0.JSX.Element | undefined;
8
+ }): react_jsx_runtime14.JSX.Element | undefined;
9
9
  //#endregion
10
10
  export { CartMismatchBanner };
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/cart-mismatch-banner/index.tsx"],"sourcesContent":[],"mappings":";;;;iBAYS,kBAAA;YAAsC;EAAtC,IAAA,EAAsD,IAAtD;CAAsC,CAAA,EAAsB,kBAAA,CAAA,GAAA,CAAA,OAAA,GAAtB,SAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/cart-mismatch-banner/index.tsx"],"sourcesContent":[],"mappings":";;;;iBAYS,kBAAA;YAAsC;EAAtC,IAAA,EAAsD,IAAtD;CAAsC,CAAA,EAAsB,mBAAA,CAAA,GAAA,CAAA,OAAA,GAAtB,SAAA"}
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime0 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime13 from "react/jsx-runtime";
2
2
 
3
3
  //#region src/components/delete-button/index.d.ts
4
4
  declare const DeleteButton: ({
@@ -9,7 +9,7 @@ declare const DeleteButton: ({
9
9
  id: string;
10
10
  children?: React.ReactNode;
11
11
  className?: string;
12
- }) => react_jsx_runtime0.JSX.Element;
12
+ }) => react_jsx_runtime13.JSX.Element;
13
13
  //#endregion
14
14
  export { DeleteButton };
15
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/delete-button/index.tsx"],"sourcesContent":[],"mappings":";;;cASM;;;;;;aAMO,KAAA,CAAM;EANb,SAAA,CAAA,EAAA,MAuCL;CAvCqB,EAAA,GAQrB,kBAAA,CAAA,GAAA,CAAA,OARqB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/delete-button/index.tsx"],"sourcesContent":[],"mappings":";;;cASM;;;;;;aAMO,KAAA,CAAM;EANb,SAAA,CAAA,EAAA,MAuCL;CAvCqB,EAAA,GAQrB,mBAAA,CAAA,GAAA,CAAA,OARqB"}
@@ -1,6 +1,6 @@
1
+ import { mutateCart } from "../../lib/hooks/use-cart.js";
1
2
  import { deleteLineItem } from "../../lib/data/cart.js";
2
3
  import { useStorefrontContext } from "../../lib/data/context.js";
3
- import { mutateCart } from "../../lib/hooks/use-cart.js";
4
4
  import { useState } from "react";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
6
  import { Spinner, Trash } from "@medusajs/icons";
@@ -14,7 +14,7 @@ const DeleteButton = ({ id, children, className }) => {
14
14
  setIsDeleting(true);
15
15
  await deleteLineItem(id$1, ctx).then(() => {
16
16
  mutateCart();
17
- }).catch((err) => {
17
+ }).finally(() => {
18
18
  setIsDeleting(false);
19
19
  });
20
20
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["id"],"sources":["../../../src/components/delete-button/index.tsx"],"sourcesContent":["import { useState } from 'react';\n\nimport { Spinner, Trash } from '@medusajs/icons';\nimport { clx } from '@medusajs/ui';\n\nimport { deleteLineItem } from '@/lib/data/cart';\nimport { useStorefrontContext } from '@/lib/data/context';\nimport { mutateCart } from '@/lib/hooks/use-cart';\n\nconst DeleteButton = ({\n id,\n children,\n className,\n}: {\n id: string;\n children?: React.ReactNode;\n className?: string;\n}) => {\n const ctx = useStorefrontContext();\n const [isDeleting, setIsDeleting] = useState(false);\n\n const handleDelete = async (id: string) => {\n setIsDeleting(true);\n await deleteLineItem(id, ctx)\n .then(() => {\n mutateCart();\n })\n .catch((err) => {\n setIsDeleting(false);\n });\n };\n\n return (\n <div\n className={clx(\n 'text-small-regular flex items-center justify-between',\n className\n )}\n >\n <button\n className=\"text-ui-fg-subtle hover:text-ui-fg-base flex cursor-pointer gap-x-1\"\n onClick={() => handleDelete(id)}\n >\n {isDeleting ? <Spinner className=\"animate-spin\" /> : <Trash />}\n <span>{children}</span>\n </button>\n </div>\n );\n};\n\nexport { DeleteButton };\n"],"mappings":";;;;;;;;;AASA,MAAM,gBAAgB,EACpB,IACA,UACA,gBAKI;CACJ,MAAM,MAAM,sBAAsB;CAClC,MAAM,CAAC,YAAY,iBAAiB,SAAS,MAAM;CAEnD,MAAM,eAAe,OAAO,SAAe;AACzC,gBAAc,KAAK;AACnB,QAAM,eAAeA,MAAI,IAAI,CAC1B,WAAW;AACV,eAAY;IACZ,CACD,OAAO,QAAQ;AACd,iBAAc,MAAM;IACpB;;AAGN,QACE,oBAAC;EACC,WAAW,IACT,wDACA,UACD;YAED,qBAAC;GACC,WAAU;GACV,eAAe,aAAa,GAAG;cAE9B,aAAa,oBAAC,WAAQ,WAAU,iBAAiB,GAAG,oBAAC,UAAQ,EAC9D,oBAAC,UAAM,WAAgB;IAChB;GACL"}
1
+ {"version":3,"file":"index.js","names":["id"],"sources":["../../../src/components/delete-button/index.tsx"],"sourcesContent":["import { useState } from 'react';\n\nimport { Spinner, Trash } from '@medusajs/icons';\nimport { clx } from '@medusajs/ui';\n\nimport { deleteLineItem } from '@/lib/data/cart';\nimport { useStorefrontContext } from '@/lib/data/context';\nimport { mutateCart } from '@/lib/hooks/use-cart';\n\nconst DeleteButton = ({\n id,\n children,\n className,\n}: {\n id: string;\n children?: React.ReactNode;\n className?: string;\n}) => {\n const ctx = useStorefrontContext();\n const [isDeleting, setIsDeleting] = useState(false);\n\n const handleDelete = async (id: string) => {\n setIsDeleting(true);\n await deleteLineItem(id, ctx)\n .then(() => {\n mutateCart();\n })\n .finally(() => {\n setIsDeleting(false);\n });\n };\n\n return (\n <div\n className={clx(\n 'text-small-regular flex items-center justify-between',\n className\n )}\n >\n <button\n className=\"text-ui-fg-subtle hover:text-ui-fg-base flex cursor-pointer gap-x-1\"\n onClick={() => handleDelete(id)}\n >\n {isDeleting ? <Spinner className=\"animate-spin\" /> : <Trash />}\n <span>{children}</span>\n </button>\n </div>\n );\n};\n\nexport { DeleteButton };\n"],"mappings":";;;;;;;;;AASA,MAAM,gBAAgB,EACpB,IACA,UACA,gBAKI;CACJ,MAAM,MAAM,sBAAsB;CAClC,MAAM,CAAC,YAAY,iBAAiB,SAAS,MAAM;CAEnD,MAAM,eAAe,OAAO,SAAe;AACzC,gBAAc,KAAK;AACnB,QAAM,eAAeA,MAAI,IAAI,CAC1B,WAAW;AACV,eAAY;IACZ,CACD,cAAc;AACb,iBAAc,MAAM;IACpB;;AAGN,QACE,oBAAC;EACC,WAAW,IACT,wDACA,UACD;YAED,qBAAC;GACC,WAAU;GACV,eAAe,aAAa,GAAG;cAE9B,aAAa,oBAAC,WAAQ,WAAU,iBAAiB,GAAG,oBAAC,UAAQ,EAC9D,oBAAC,UAAM,WAAgB;IAChB;GACL"}
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime3 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime1 from "react/jsx-runtime";
2
2
 
3
3
  //#region src/components/error-message/index.d.ts
4
4
  declare const ErrorMessage: ({
@@ -7,7 +7,7 @@ declare const ErrorMessage: ({
7
7
  }: {
8
8
  error?: string | null;
9
9
  "data-testid"?: string;
10
- }) => react_jsx_runtime3.JSX.Element | null;
10
+ }) => react_jsx_runtime1.JSX.Element | null;
11
11
  //#endregion
12
12
  export { ErrorMessage };
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { Cart } from "../../types/graphql.js";
2
- import * as react_jsx_runtime14 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime12 from "react/jsx-runtime";
3
3
  import { StoreCartShippingOption } from "@medusajs/types";
4
4
 
5
5
  //#region src/components/free-shipping-price-nudge/index.d.ts
@@ -11,7 +11,7 @@ declare function ShippingPriceNudge({
11
11
  variant?: 'popup' | 'inline';
12
12
  cart: Cart;
13
13
  shippingOptions: StoreCartShippingOption[];
14
- }): react_jsx_runtime14.JSX.Element | undefined;
14
+ }): react_jsx_runtime12.JSX.Element | undefined;
15
15
  //#endregion
16
16
  export { ShippingPriceNudge };
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime4 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime2 from "react/jsx-runtime";
2
2
 
3
3
  //#region src/components/interactive-link/index.d.ts
4
4
  type InteractiveLinkProps = {
@@ -11,7 +11,7 @@ declare const InteractiveLink: ({
11
11
  children,
12
12
  onClick,
13
13
  ...props
14
- }: InteractiveLinkProps) => react_jsx_runtime4.JSX.Element;
14
+ }: InteractiveLinkProps) => react_jsx_runtime2.JSX.Element;
15
15
  //#endregion
16
16
  export { InteractiveLink };
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { Maybe, ProductVariant } from "../../types/graphql.js";
2
- import * as react_jsx_runtime5 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime3 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/line-item-options/index.d.ts
5
5
  type LineItemOptionsProps = {
@@ -11,7 +11,7 @@ declare const LineItemOptions: ({
11
11
  variant,
12
12
  "data-testid": dataTestid,
13
13
  "data-value": dataValue
14
- }: LineItemOptionsProps) => react_jsx_runtime5.JSX.Element;
14
+ }: LineItemOptionsProps) => react_jsx_runtime3.JSX.Element;
15
15
  //#endregion
16
16
  export { LineItemOptions };
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { LineItem } from "../../types/graphql.js";
2
- import * as react_jsx_runtime13 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime4 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/line-item-price/index.d.ts
5
5
  type LineItemPriceProps = {
@@ -11,7 +11,7 @@ declare const LineItemPrice: ({
11
11
  item,
12
12
  style,
13
13
  currencyCode
14
- }: LineItemPriceProps) => react_jsx_runtime13.JSX.Element;
14
+ }: LineItemPriceProps) => react_jsx_runtime4.JSX.Element;
15
15
  //#endregion
16
16
  export { LineItemPrice };
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/line-item-price/index.tsx"],"sourcesContent":[],"mappings":";;;;KAMK,kBAAA;QACG;;EADH,YAAA,EAAA,MAAA;AACW,CAAA;cAKV,aAAiB,EAAA,CAAA;EAAA,IAAA;EAAA,KAAA;EAAA;AAAA,CAAA,EAIpB,kBAJoB,EAAA,GAIF,mBAAA,CAAA,GAAA,CAAA,OAJE"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/line-item-price/index.tsx"],"sourcesContent":[],"mappings":";;;;KAMK,kBAAA;QACG;;EADH,YAAA,EAAA,MAAA;AACW,CAAA;cAKV,aAAiB,EAAA,CAAA;EAAA,IAAA;EAAA,KAAA;EAAA;AAAA,CAAA,EAIpB,kBAJoB,EAAA,GAIF,kBAAA,CAAA,GAAA,CAAA,OAJE"}
@@ -1,5 +1,5 @@
1
1
  import { AnchorHTMLAttributes, DetailedHTMLProps } from "react";
2
- import * as react_jsx_runtime15 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime5 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/localized-client-link/index.d.ts
5
5
  type LocalizedClientLinkProps = DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;
@@ -11,7 +11,7 @@ declare const LocalizedClientLink: ({
11
11
  children,
12
12
  href,
13
13
  ...props
14
- }: LocalizedClientLinkProps) => react_jsx_runtime15.JSX.Element;
14
+ }: LocalizedClientLinkProps) => react_jsx_runtime5.JSX.Element;
15
15
  //#endregion
16
16
  export { LocalizedClientLink };
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/localized-client-link/index.tsx"],"sourcesContent":[],"mappings":";;;;KAEK,wBAAA,GAA2B,kBAC9B,qBAAqB,oBACrB;;;AAJ8D;;cAW1D,mBARJ,EAAA,CAAA;EAAA,QAAA;EAAA,IAAA;EAAA,GAAA;AAAA,CAAA,EAYC,wBAZD,EAAA,GAYyB,mBAAA,CAAA,GAAA,CAAA,OAZzB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/components/localized-client-link/index.tsx"],"sourcesContent":[],"mappings":";;;;KAEK,wBAAA,GAA2B,kBAC9B,qBAAqB,oBACrB;;;AAJ8D;;cAW1D,mBARJ,EAAA,CAAA;EAAA,QAAA;EAAA,IAAA;EAAA,GAAA;AAAA,CAAA,EAYC,wBAZD,EAAA,GAYyB,kBAAA,CAAA,GAAA,CAAA,OAZzB"}
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import * as react_jsx_runtime1 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/components/modal/index.d.ts
5
5
  type ModalProps = {
@@ -20,7 +20,7 @@ declare const Modal: {
20
20
  children,
21
21
  "data-testid": dataTestId,
22
22
  "aria-label": ariaLabel
23
- }: ModalProps): react_jsx_runtime1.JSX.Element;
23
+ }: ModalProps): react_jsx_runtime0.JSX.Element;
24
24
  Title: React.FC<{
25
25
  children: React.ReactNode;
26
26
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"cart.d.ts","names":[],"sources":["../../../src/lib/data/cart.ts"],"sourcesContent":[],"mappings":";;;;;cA2Ba,oBACN,sBACJ,QAAQ;cAmBE,mBACL,0CACD,sBACJ,QAAQ;AAxBE,cAkEA,cA/CZ,EAAA,CAAA,MAAA,EAAA,MAAA,EAAA,GAAA,EAiDM,iBAjDN,EAAA,GAkDE,OAlDF,CAkDU,sBAlDV,CAAA,gBAAA,CAAA,GAAA,IAAA,CAAA;AAlBM,iBAiHe,eAAA,CAjHf,GAAA,EAiHoC,iBAjHpC,CAAA,EAiHqD,OAjHrD,CAAA;EACI,gBAAA,EA0HW,SAAA,CAAU,uBA1HrB,EAAA;CAAR,CAAA"}
1
+ {"version":3,"file":"cart.d.ts","names":[],"sources":["../../../src/lib/data/cart.ts"],"sourcesContent":[],"mappings":";;;;;cA2Ba,oBACN,sBACJ,QAAQ;cAyBE,mBACL,0CACD,sBACJ,QAAQ;AA9BE,cAyEA,cAhDZ,EAAA,CAAA,MAAA,EAAA,MAAA,EAAA,GAAA,EAkDM,iBAlDN,EAAA,GAmDE,OAnDF,CAmDU,sBAnDV,CAAA,gBAAA,CAAA,GAAA,IAAA,CAAA;AAxBM,iBAyHe,eAAA,CAzHf,GAAA,EAyHoC,iBAzHpC,CAAA,EAyHqD,OAzHrD,CAAA;EACI,gBAAA,EA+HW,SAAA,CAAU,uBA/HrB,EAAA;CAAR,CAAA"}
@@ -1,19 +1,22 @@
1
1
  import { sdk } from "../config/medusa.js";
2
- import { graphqlFetch, graphqlMutation } from "../gql/apollo-client.js";
2
+ import { createServerApolloClient, graphqlFetch, graphqlMutation } from "../gql/apollo-client.js";
3
3
  import { DELETE_LINE_ITEM_MUTATION, UPDATE_CART_MUTATION } from "../gql/mutations/cart.js";
4
4
  import { GET_CART_QUERY } from "../gql/queries/cart.js";
5
+ import { mutateCart } from "../hooks/use-cart.js";
5
6
  import { medusaError } from "../utils/medusa-error.js";
6
- import { getAuthHeaders, getCacheOptions, getCacheTag, getCartId } from "./cookies-utils.js";
7
+ import { getCacheOptions, getCacheTag, getCartId } from "./cookies-utils.js";
7
8
 
8
9
  //#region src/lib/data/cart.ts
9
10
  const retrieveCart = async (ctx) => {
10
11
  const id = getCartId(ctx);
11
12
  if (!id) return null;
13
+ const cookieHeader = ctx.cookieHeader;
14
+ const apolloClient = createServerApolloClient(cookieHeader);
12
15
  try {
13
16
  return (await graphqlFetch({
14
17
  query: GET_CART_QUERY,
15
18
  variables: { id }
16
- }))?.cart ?? null;
19
+ }, apolloClient))?.cart ?? null;
17
20
  } catch (error) {
18
21
  console.error("Failed to fetch cart:", error);
19
22
  return null;
@@ -30,11 +33,14 @@ const updateCart = async (data, ctx) => {
30
33
  data
31
34
  }
32
35
  }))?.updateCart ?? null;
33
- if (cart) try {
34
- const { revalidateTag } = await import("next/cache");
35
- revalidateTag(getCacheTag("carts", ctx));
36
- revalidateTag(getCacheTag("fulfillment", ctx));
37
- } catch {}
36
+ if (cart) {
37
+ await mutateCart();
38
+ try {
39
+ const { revalidateTag } = await import("next/cache");
40
+ revalidateTag(getCacheTag("carts", ctx));
41
+ revalidateTag(getCacheTag("fulfillment", ctx));
42
+ } catch {}
43
+ }
38
44
  return cart;
39
45
  } catch (err) {
40
46
  medusaError(err);
@@ -52,11 +58,14 @@ const deleteLineItem = async (lineId, ctx) => {
52
58
  lineItemId: lineId
53
59
  }
54
60
  }))?.deleteLineItem ?? null;
55
- if (deletedLineItem) try {
56
- const { revalidateTag } = await import("next/cache");
57
- revalidateTag(getCacheTag("carts", ctx));
58
- revalidateTag(getCacheTag("fulfillment", ctx));
59
- } catch {}
61
+ if (deletedLineItem) {
62
+ await mutateCart();
63
+ try {
64
+ const { revalidateTag } = await import("next/cache");
65
+ revalidateTag(getCacheTag("carts", ctx));
66
+ revalidateTag(getCacheTag("fulfillment", ctx));
67
+ } catch {}
68
+ }
60
69
  return deletedLineItem;
61
70
  } catch (error) {
62
71
  console.error("GraphQL deleteLineItem error:", error.message);
@@ -65,12 +74,10 @@ const deleteLineItem = async (lineId, ctx) => {
65
74
  };
66
75
  async function listCartOptions(ctx) {
67
76
  const cartId = getCartId(ctx);
68
- const headers = { ...getAuthHeaders(ctx) };
69
77
  const next = { ...getCacheOptions("shippingOptions", ctx) };
70
78
  return await sdk.client.fetch("/store/shipping-options", {
71
79
  query: { cart_id: cartId },
72
80
  next,
73
- headers,
74
81
  cache: "force-cache"
75
82
  });
76
83
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cart.js","names":["error: any"],"sources":["../../../src/lib/data/cart.ts"],"sourcesContent":["import { HttpTypes } from '@medusajs/types';\n\nimport {\n Cart,\n DeleteLineItemMutation,\n DeleteLineItemMutationVariables,\n GetCartQuery,\n GetCartQueryVariables,\n UpdateCartMutation,\n UpdateCartMutationVariables,\n} from '../../types/graphql';\nimport { sdk } from '../config/medusa';\nimport { graphqlFetch, graphqlMutation } from '../gql/apollo-client';\nimport {\n DELETE_LINE_ITEM_MUTATION,\n UPDATE_CART_MUTATION,\n} from '../gql/mutations/cart';\nimport { GET_CART_QUERY } from '../gql/queries/cart';\nimport { medusaError } from '../utils/medusa-error';\nimport type { StorefrontContext } from './context';\nimport {\n getAuthHeaders,\n getCacheOptions,\n getCacheTag,\n getCartId,\n} from './cookies-utils';\n\nexport const retrieveCart = async (\n ctx: StorefrontContext\n): Promise<Cart | null> => {\n const id = 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 updateCart = async (\n data: UpdateCartMutationVariables['data'],\n ctx: StorefrontContext\n): Promise<UpdateCartMutation['updateCart'] | null> => {\n const cartId = getCartId(ctx);\n\n if (!cartId) {\n throw new Error(\n 'No existing cart found, please create one before updating'\n );\n }\n\n try {\n const result = await graphqlMutation<\n UpdateCartMutation,\n UpdateCartMutationVariables\n >({\n mutation: UPDATE_CART_MUTATION,\n variables: {\n id: cartId,\n data,\n },\n });\n\n const cart = result?.updateCart ?? null;\n\n if (cart) {\n try {\n const { revalidateTag } = await import('next/cache');\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n\n const fulfillmentCacheTag = getCacheTag('fulfillment', ctx);\n revalidateTag(fulfillmentCacheTag);\n } catch {\n // Not in Next.js environment\n }\n }\n\n return cart;\n } catch (err) {\n medusaError(err);\n }\n};\n\nexport const deleteLineItem = async (\n lineId: string,\n ctx: StorefrontContext\n): Promise<DeleteLineItemMutation['deleteLineItem'] | null> => {\n if (!lineId) {\n throw new Error('Missing lineItem ID when deleting line item');\n }\n\n const cartId = getCartId(ctx);\n\n if (!cartId) {\n throw new Error('Missing cart ID when deleting line item');\n }\n\n try {\n const result = await graphqlMutation<\n DeleteLineItemMutation,\n DeleteLineItemMutationVariables\n >({\n mutation: DELETE_LINE_ITEM_MUTATION,\n variables: {\n cartId,\n lineItemId: lineId,\n },\n });\n\n const deletedLineItem = result?.deleteLineItem ?? null;\n\n if (deletedLineItem) {\n try {\n const { revalidateTag } = await import('next/cache');\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n\n const fulfillmentCacheTag = getCacheTag('fulfillment', ctx);\n revalidateTag(fulfillmentCacheTag);\n } catch {\n // Not in Next.js environment\n }\n }\n\n return deletedLineItem;\n } catch (error: any) {\n console.error('GraphQL deleteLineItem error:', error.message);\n throw error;\n }\n};\n\nexport async function listCartOptions(ctx: StorefrontContext) {\n const cartId = getCartId(ctx);\n const headers = {\n ...getAuthHeaders(ctx),\n };\n const next = {\n ...getCacheOptions('shippingOptions', ctx),\n };\n\n return await sdk.client.fetch<{\n shipping_options: HttpTypes.StoreCartShippingOption[];\n }>('/store/shipping-options', {\n query: { cart_id: cartId },\n next,\n headers,\n cache: 'force-cache',\n });\n}\n"],"mappings":";;;;;;;;AA2BA,MAAa,eAAe,OAC1B,QACyB;CACzB,MAAM,KAAK,UAAU,IAAI;AACzB,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,aAAa,OACxB,MACA,QACqD;CACrD,MAAM,SAAS,UAAU,IAAI;AAE7B,KAAI,CAAC,OACH,OAAM,IAAI,MACR,4DACD;AAGH,KAAI;EAYF,MAAM,QAXS,MAAM,gBAGnB;GACA,UAAU;GACV,WAAW;IACT,IAAI;IACJ;IACD;GACF,CAAC,GAEmB,cAAc;AAEnC,MAAI,KACF,KAAI;GACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,iBADqB,YAAY,SAAS,IAAI,CACnB;AAG3B,iBAD4B,YAAY,eAAe,IAAI,CACzB;UAC5B;AAKV,SAAO;UACA,KAAK;AACZ,cAAY,IAAI;;;AAIpB,MAAa,iBAAiB,OAC5B,QACA,QAC6D;AAC7D,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,8CAA8C;CAGhE,MAAM,SAAS,UAAU,IAAI;AAE7B,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,0CAA0C;AAG5D,KAAI;EAYF,MAAM,mBAXS,MAAM,gBAGnB;GACA,UAAU;GACV,WAAW;IACT;IACA,YAAY;IACb;GACF,CAAC,GAE8B,kBAAkB;AAElD,MAAI,gBACF,KAAI;GACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,iBADqB,YAAY,SAAS,IAAI,CACnB;AAG3B,iBAD4B,YAAY,eAAe,IAAI,CACzB;UAC5B;AAKV,SAAO;UACAA,OAAY;AACnB,UAAQ,MAAM,iCAAiC,MAAM,QAAQ;AAC7D,QAAM;;;AAIV,eAAsB,gBAAgB,KAAwB;CAC5D,MAAM,SAAS,UAAU,IAAI;CAC7B,MAAM,UAAU,EACd,GAAG,eAAe,IAAI,EACvB;CACD,MAAM,OAAO,EACX,GAAG,gBAAgB,mBAAmB,IAAI,EAC3C;AAED,QAAO,MAAM,IAAI,OAAO,MAErB,2BAA2B;EAC5B,OAAO,EAAE,SAAS,QAAQ;EAC1B;EACA;EACA,OAAO;EACR,CAAC"}
1
+ {"version":3,"file":"cart.js","names":["error: any"],"sources":["../../../src/lib/data/cart.ts"],"sourcesContent":["import { HttpTypes } from '@medusajs/types';\n\nimport {\n Cart,\n DeleteLineItemMutation,\n DeleteLineItemMutationVariables,\n GetCartQuery,\n GetCartQueryVariables,\n UpdateCartMutation,\n UpdateCartMutationVariables,\n} from '../../types/graphql';\nimport { sdk } from '../config/medusa';\nimport {\n createServerApolloClient,\n graphqlFetch,\n graphqlMutation,\n} from '../gql/apollo-client';\nimport {\n DELETE_LINE_ITEM_MUTATION,\n UPDATE_CART_MUTATION,\n} from '../gql/mutations/cart';\nimport { GET_CART_QUERY } from '../gql/queries/cart';\nimport { mutateCart } from '../hooks/use-cart';\nimport { medusaError } from '../utils/medusa-error';\nimport type { StorefrontContext } from './context';\nimport { getCacheOptions, getCacheTag, getCartId } from './cookies-utils';\n\nexport const retrieveCart = async (\n ctx: StorefrontContext\n): Promise<Cart | null> => {\n const id = getCartId(ctx);\n if (!id) {\n return null;\n }\n\n const cookieHeader = ctx.cookieHeader;\n const apolloClient = createServerApolloClient(cookieHeader);\n\n try {\n const data = await graphqlFetch<GetCartQuery, GetCartQueryVariables>(\n {\n query: GET_CART_QUERY,\n variables: { id },\n },\n apolloClient\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 updateCart = async (\n data: UpdateCartMutationVariables['data'],\n ctx: StorefrontContext\n): Promise<UpdateCartMutation['updateCart'] | null> => {\n const cartId = getCartId(ctx);\n\n if (!cartId) {\n throw new Error(\n 'No existing cart found, please create one before updating'\n );\n }\n\n try {\n const result = await graphqlMutation<\n UpdateCartMutation,\n UpdateCartMutationVariables\n >({\n mutation: UPDATE_CART_MUTATION,\n variables: {\n id: cartId,\n data,\n },\n });\n\n const cart = result?.updateCart ?? null;\n\n if (cart) {\n await mutateCart();\n try {\n const { revalidateTag } = await import('next/cache');\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n\n const fulfillmentCacheTag = getCacheTag('fulfillment', ctx);\n revalidateTag(fulfillmentCacheTag);\n } catch {\n // Not in Next.js environment\n }\n }\n\n return cart;\n } catch (err) {\n medusaError(err);\n }\n};\n\nexport const deleteLineItem = async (\n lineId: string,\n ctx: StorefrontContext\n): Promise<DeleteLineItemMutation['deleteLineItem'] | null> => {\n if (!lineId) {\n throw new Error('Missing lineItem ID when deleting line item');\n }\n\n const cartId = getCartId(ctx);\n\n if (!cartId) {\n throw new Error('Missing cart ID when deleting line item');\n }\n\n try {\n const result = await graphqlMutation<\n DeleteLineItemMutation,\n DeleteLineItemMutationVariables\n >({\n mutation: DELETE_LINE_ITEM_MUTATION,\n variables: {\n cartId,\n lineItemId: lineId,\n },\n });\n\n const deletedLineItem = result?.deleteLineItem ?? null;\n\n if (deletedLineItem) {\n await mutateCart();\n try {\n const { revalidateTag } = await import('next/cache');\n const cartCacheTag = getCacheTag('carts', ctx);\n revalidateTag(cartCacheTag);\n\n const fulfillmentCacheTag = getCacheTag('fulfillment', ctx);\n revalidateTag(fulfillmentCacheTag);\n } catch {\n // Not in Next.js environment\n }\n }\n\n return deletedLineItem;\n } catch (error: any) {\n console.error('GraphQL deleteLineItem error:', error.message);\n throw error;\n }\n};\n\nexport async function listCartOptions(ctx: StorefrontContext) {\n const cartId = getCartId(ctx);\n const next = {\n ...getCacheOptions('shippingOptions', ctx),\n };\n\n return await sdk.client.fetch<{\n shipping_options: HttpTypes.StoreCartShippingOption[];\n }>('/store/shipping-options', {\n query: { cart_id: cartId },\n next,\n cache: 'force-cache',\n });\n}\n"],"mappings":";;;;;;;;;AA2BA,MAAa,eAAe,OAC1B,QACyB;CACzB,MAAM,KAAK,UAAU,IAAI;AACzB,KAAI,CAAC,GACH,QAAO;CAGT,MAAM,eAAe,IAAI;CACzB,MAAM,eAAe,yBAAyB,aAAa;AAE3D,KAAI;AASF,UARa,MAAM,aACjB;GACE,OAAO;GACP,WAAW,EAAE,IAAI;GAClB,EACD,aACD,GAEY,QAAQ;UACd,OAAO;AACd,UAAQ,MAAM,yBAAyB,MAAM;AAC7C,SAAO;;;AAIX,MAAa,aAAa,OACxB,MACA,QACqD;CACrD,MAAM,SAAS,UAAU,IAAI;AAE7B,KAAI,CAAC,OACH,OAAM,IAAI,MACR,4DACD;AAGH,KAAI;EAYF,MAAM,QAXS,MAAM,gBAGnB;GACA,UAAU;GACV,WAAW;IACT,IAAI;IACJ;IACD;GACF,CAAC,GAEmB,cAAc;AAEnC,MAAI,MAAM;AACR,SAAM,YAAY;AAClB,OAAI;IACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,kBADqB,YAAY,SAAS,IAAI,CACnB;AAG3B,kBAD4B,YAAY,eAAe,IAAI,CACzB;WAC5B;;AAKV,SAAO;UACA,KAAK;AACZ,cAAY,IAAI;;;AAIpB,MAAa,iBAAiB,OAC5B,QACA,QAC6D;AAC7D,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,8CAA8C;CAGhE,MAAM,SAAS,UAAU,IAAI;AAE7B,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,0CAA0C;AAG5D,KAAI;EAYF,MAAM,mBAXS,MAAM,gBAGnB;GACA,UAAU;GACV,WAAW;IACT;IACA,YAAY;IACb;GACF,CAAC,GAE8B,kBAAkB;AAElD,MAAI,iBAAiB;AACnB,SAAM,YAAY;AAClB,OAAI;IACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,kBADqB,YAAY,SAAS,IAAI,CACnB;AAG3B,kBAD4B,YAAY,eAAe,IAAI,CACzB;WAC5B;;AAKV,SAAO;UACAA,OAAY;AACnB,UAAQ,MAAM,iCAAiC,MAAM,QAAQ;AAC7D,QAAM;;;AAIV,eAAsB,gBAAgB,KAAwB;CAC5D,MAAM,SAAS,UAAU,IAAI;CAC7B,MAAM,OAAO,EACX,GAAG,gBAAgB,mBAAmB,IAAI,EAC3C;AAED,QAAO,MAAM,IAAI,OAAO,MAErB,2BAA2B;EAC5B,OAAO,EAAE,SAAS,QAAQ;EAC1B;EACA,OAAO;EACR,CAAC"}
@@ -1,21 +1,21 @@
1
1
  import { useStorefrontActions } from "./client-actions.js";
2
2
  import { ReactNode } from "react";
3
- import * as react_jsx_runtime12 from "react/jsx-runtime";
3
+ import * as react_jsx_runtime15 from "react/jsx-runtime";
4
4
 
5
5
  //#region src/lib/data/context.d.ts
6
6
  interface StorefrontContext {
7
7
  cartId: string;
8
- customerToken: string;
9
8
  cacheId: string;
10
- cookieHeader: string;
9
+ cookieHeader?: string;
10
+ }
11
+ interface StorefrontProviderProps {
12
+ children: ReactNode;
13
+ value?: StorefrontContext;
11
14
  }
12
15
  declare const StorefrontProvider: ({
13
16
  children,
14
17
  value
15
- }: {
16
- children: ReactNode;
17
- value: StorefrontContext;
18
- }) => react_jsx_runtime12.JSX.Element;
18
+ }: StorefrontProviderProps) => react_jsx_runtime15.JSX.Element;
19
19
  declare const useStorefrontContext: () => StorefrontContext;
20
20
  //#endregion
21
21
  export { StorefrontContext, StorefrontProvider, useStorefrontActions, useStorefrontContext };
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","names":[],"sources":["../../../src/lib/data/context.tsx"],"sourcesContent":[],"mappings":";;;;;UAIiB,iBAAA;;;;EAAA,YAAA,EAAA,MAAiB;AAWlC;AAAmC,cAAtB,kBAAsB,EAAA,CAAA;EAAA,QAAA;EAAA;CAAA,EAAA;EAAA,QAAA,EAIvB,SAJuB;EAIvB,KAAA,EACH,iBADG;CACH,EAAA,GACR,mBAAA,CAAA,GAAA,CAAA,OADQ;AACR,cAQY,oBARZ,EAAA,GAAA,GAQgC,iBARhC"}
1
+ {"version":3,"file":"context.d.ts","names":[],"sources":["../../../src/lib/data/context.tsx"],"sourcesContent":[],"mappings":";;;;;UAMiB,iBAAA;;;;AAAjB;AAIC,UAwBS,uBAAA,CAAuB;EAKpB,QAAA,EAJD,SAIC;EAAsB,KAAA,CAAA,EAHzB,iBAGyB;;AAGhC,cAHU,kBAGV,EAAA,CAAA;EAAA,QAAA;EAAA;AAAA,CAAA,EAAA,uBAAA,EAAA,GAAuB,mBAAA,CAAA,GAAA,CAAA,OAAvB;AAAuB,cAwBb,oBAxBa,EAAA,GAAA,GAwBO,iBAxBP"}
@@ -3,12 +3,29 @@
3
3
  import { useStorefrontActions } from "./client-actions.js";
4
4
  import { createContext, useContext } from "react";
5
5
  import { jsx } from "react/jsx-runtime";
6
+ import useSWR from "swr";
6
7
 
7
8
  //#region src/lib/data/context.tsx
8
- const StorefrontReactContext = createContext({});
9
+ const StorefrontReactContext = createContext({
10
+ cartId: "",
11
+ cacheId: ""
12
+ });
13
+ const fetchContext = async () => {
14
+ const response = await fetch("/api/context", { credentials: "include" });
15
+ if (!response.ok) throw new Error("Failed to fetch context");
16
+ return response.json();
17
+ };
9
18
  const StorefrontProvider = ({ children, value }) => {
19
+ const { data: fetchedContext } = useSWR(value ? null : "storefront-context", fetchContext, {
20
+ revalidateOnFocus: true,
21
+ revalidateOnReconnect: true
22
+ });
23
+ const contextValue = value ?? {
24
+ cartId: fetchedContext?.cartId ?? "",
25
+ cacheId: fetchedContext?.cacheId ?? ""
26
+ };
10
27
  return /* @__PURE__ */ jsx(StorefrontReactContext.Provider, {
11
- value,
28
+ value: contextValue,
12
29
  children
13
30
  });
14
31
  };
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":[],"sources":["../../../src/lib/data/context.tsx"],"sourcesContent":["'use client';\n\nimport { type ReactNode, createContext, useContext } from 'react';\n\nexport interface StorefrontContext {\n cartId: string;\n customerToken: string;\n cacheId: string;\n cookieHeader: string;\n}\n\nconst StorefrontReactContext = createContext<StorefrontContext>(\n {} as StorefrontContext\n);\n\nexport const StorefrontProvider = ({\n children,\n value,\n}: {\n children: ReactNode;\n value: StorefrontContext;\n}) => {\n return (\n <StorefrontReactContext.Provider value={value}>\n {children}\n </StorefrontReactContext.Provider>\n );\n};\n\nexport const useStorefrontContext = () => useContext(StorefrontReactContext);\nexport { useStorefrontActions } from './client-actions';\n"],"mappings":";;;;;;;AAWA,MAAM,yBAAyB,cAC7B,EAAE,CACH;AAED,MAAa,sBAAsB,EACjC,UACA,YAII;AACJ,QACE,oBAAC,uBAAuB;EAAgB;EACrC;GAC+B;;AAItC,MAAa,6BAA6B,WAAW,uBAAuB"}
1
+ {"version":3,"file":"context.js","names":["contextValue: StorefrontContext"],"sources":["../../../src/lib/data/context.tsx"],"sourcesContent":["'use client';\n\nimport { type ReactNode, createContext, useContext } from 'react';\n\nimport useSWR from 'swr';\n\nexport interface StorefrontContext {\n cartId: string;\n cacheId: string;\n cookieHeader?: string;\n}\n\ninterface ClientContext {\n cartId: string;\n cacheId: string;\n}\n\nconst StorefrontReactContext = createContext<StorefrontContext>({\n cartId: '',\n cacheId: '',\n});\n\nconst fetchContext = async (): Promise<ClientContext> => {\n const response = await fetch('/api/context', {\n credentials: 'include',\n });\n\n if (!response.ok) {\n throw new Error('Failed to fetch context');\n }\n\n return response.json();\n};\n\ninterface StorefrontProviderProps {\n children: ReactNode;\n value?: StorefrontContext;\n}\n\nexport const StorefrontProvider = ({\n children,\n value,\n}: StorefrontProviderProps) => {\n // If value is provided (host apps), use it directly\n // If no value (horizontal components), fetch from API\n const { data: fetchedContext } = useSWR<ClientContext>(\n value ? null : 'storefront-context',\n fetchContext,\n {\n revalidateOnFocus: true,\n revalidateOnReconnect: true,\n }\n );\n\n const contextValue: StorefrontContext = value ?? {\n cartId: fetchedContext?.cartId ?? '',\n cacheId: fetchedContext?.cacheId ?? '',\n };\n\n return (\n <StorefrontReactContext.Provider value={contextValue}>\n {children}\n </StorefrontReactContext.Provider>\n );\n};\n\nexport const useStorefrontContext = () => useContext(StorefrontReactContext);\nexport { useStorefrontActions } from './client-actions';\n"],"mappings":";;;;;;;;AAiBA,MAAM,yBAAyB,cAAiC;CAC9D,QAAQ;CACR,SAAS;CACV,CAAC;AAEF,MAAM,eAAe,YAAoC;CACvD,MAAM,WAAW,MAAM,MAAM,gBAAgB,EAC3C,aAAa,WACd,CAAC;AAEF,KAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,0BAA0B;AAG5C,QAAO,SAAS,MAAM;;AAQxB,MAAa,sBAAsB,EACjC,UACA,YAC6B;CAG7B,MAAM,EAAE,MAAM,mBAAmB,OAC/B,QAAQ,OAAO,sBACf,cACA;EACE,mBAAmB;EACnB,uBAAuB;EACxB,CACF;CAED,MAAMA,eAAkC,SAAS;EAC/C,QAAQ,gBAAgB,UAAU;EAClC,SAAS,gBAAgB,WAAW;EACrC;AAED,QACE,oBAAC,uBAAuB;EAAS,OAAO;EACrC;GAC+B;;AAItC,MAAa,6BAA6B,WAAW,uBAAuB"}
@@ -1,14 +1,11 @@
1
1
  import { StorefrontContext } from "./context.js";
2
2
 
3
3
  //#region src/lib/data/cookies-utils.d.ts
4
- declare const getAuthHeaders: (ctx: StorefrontContext) => {
5
- authorization: string;
6
- } | {};
7
4
  declare const getCacheTag: (tag: string, ctx: StorefrontContext) => string;
8
5
  declare const getCacheOptions: (tag: string, ctx: StorefrontContext) => {
9
6
  tags: string[];
10
7
  } | {};
11
8
  declare const getCartId: (ctx: StorefrontContext) => string;
12
9
  //#endregion
13
- export { getAuthHeaders, getCacheOptions, getCacheTag, getCartId };
10
+ export { getCacheOptions, getCacheTag, getCartId };
14
11
  //# sourceMappingURL=cookies-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cookies-utils.d.ts","names":[],"sources":["../../../src/lib/data/cookies-utils.ts"],"sourcesContent":[],"mappings":";;;cAEa,sBACN;;AADP,CAAA,GAAa,CAAA,CAAA;AAYA,cAAA,WAAiC,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAAiB,EAAjB,iBAAiB,EAAA,GAAA,MAAA;AAUlD,cAAA,eAEN,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAAiB,EAAjB,iBAAiB,EAAA,GAAA;EAeX,IAAA,EAAA,MAEZ,EAAA;;cAFY,iBAAkB"}
1
+ {"version":3,"file":"cookies-utils.d.ts","names":[],"sources":["../../../src/lib/data/cookies-utils.ts"],"sourcesContent":[],"mappings":";;;cAEa,gCAAiC;cAUjC,oCAEN;EAZM,IAAA,EAAA,MAAA,EAQZ;AAED,CAAA,GAAa,CAAA,CAAA;AAiBA,cAAA,SAAkB,EAAA,CAAA,GAAA,EAAA,iBAAiB,EAAA,GAAA,MAAA"}
@@ -1,9 +1,4 @@
1
1
  //#region src/lib/data/cookies-utils.ts
2
- const getAuthHeaders = (ctx) => {
3
- const token = ctx.customerToken;
4
- if (!token) return {};
5
- return { authorization: `Bearer ${token}` };
6
- };
7
2
  const getCacheTag = (tag, ctx) => {
8
3
  const cacheId = ctx.cacheId;
9
4
  if (!cacheId) return "";
@@ -20,5 +15,5 @@ const getCartId = (ctx) => {
20
15
  };
21
16
 
22
17
  //#endregion
23
- export { getAuthHeaders, getCacheOptions, getCacheTag, getCartId };
18
+ export { getCacheOptions, getCacheTag, getCartId };
24
19
  //# sourceMappingURL=cookies-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cookies-utils.js","names":[],"sources":["../../../src/lib/data/cookies-utils.ts"],"sourcesContent":["import type { StorefrontContext } from './context';\n\nexport const getAuthHeaders = (\n ctx: StorefrontContext\n): { authorization: string } | {} => {\n const token = ctx.customerToken;\n\n if (!token) {\n return {};\n }\n\n return { authorization: `Bearer ${token}` };\n};\n\nexport const getCacheTag = (tag: string, ctx: StorefrontContext): string => {\n const cacheId = ctx.cacheId;\n\n if (!cacheId) {\n return '';\n }\n\n return `${tag}-${cacheId}`;\n};\n\nexport const getCacheOptions = (\n tag: string,\n ctx: StorefrontContext\n): { tags: string[] } | {} => {\n if (typeof window !== 'undefined') {\n return {};\n }\n\n const cacheTag = getCacheTag(tag, ctx);\n\n if (!cacheTag) {\n return {};\n }\n\n return { tags: [`${cacheTag}`] };\n};\n\nexport const getCartId = (ctx: StorefrontContext) => {\n return ctx.cartId;\n};\n"],"mappings":";AAEA,MAAa,kBACX,QACmC;CACnC,MAAM,QAAQ,IAAI;AAElB,KAAI,CAAC,MACH,QAAO,EAAE;AAGX,QAAO,EAAE,eAAe,UAAU,SAAS;;AAG7C,MAAa,eAAe,KAAa,QAAmC;CAC1E,MAAM,UAAU,IAAI;AAEpB,KAAI,CAAC,QACH,QAAO;AAGT,QAAO,GAAG,IAAI,GAAG;;AAGnB,MAAa,mBACX,KACA,QAC4B;AAC5B,KAAI,OAAO,WAAW,YACpB,QAAO,EAAE;CAGX,MAAM,WAAW,YAAY,KAAK,IAAI;AAEtC,KAAI,CAAC,SACH,QAAO,EAAE;AAGX,QAAO,EAAE,MAAM,CAAC,GAAG,WAAW,EAAE;;AAGlC,MAAa,aAAa,QAA2B;AACnD,QAAO,IAAI"}
1
+ {"version":3,"file":"cookies-utils.js","names":[],"sources":["../../../src/lib/data/cookies-utils.ts"],"sourcesContent":["import type { StorefrontContext } from './context';\n\nexport const getCacheTag = (tag: string, ctx: StorefrontContext): string => {\n const cacheId = ctx.cacheId;\n\n if (!cacheId) {\n return '';\n }\n\n return `${tag}-${cacheId}`;\n};\n\nexport const getCacheOptions = (\n tag: string,\n ctx: StorefrontContext\n): { tags: string[] } | {} => {\n if (typeof window !== 'undefined') {\n return {};\n }\n\n const cacheTag = getCacheTag(tag, ctx);\n\n if (!cacheTag) {\n return {};\n }\n\n return { tags: [`${cacheTag}`] };\n};\n\nexport const getCartId = (ctx: StorefrontContext) => {\n return ctx.cartId;\n};\n"],"mappings":";AAEA,MAAa,eAAe,KAAa,QAAmC;CAC1E,MAAM,UAAU,IAAI;AAEpB,KAAI,CAAC,QACH,QAAO;AAGT,QAAO,GAAG,IAAI,GAAG;;AAGnB,MAAa,mBACX,KACA,QAC4B;AAC5B,KAAI,OAAO,WAAW,YACpB,QAAO,EAAE;CAGX,MAAM,WAAW,YAAY,KAAK,IAAI;AAEtC,KAAI,CAAC,SACH,QAAO,EAAE;AAGX,QAAO,EAAE,MAAM,CAAC,GAAG,WAAW,EAAE;;AAGlC,MAAa,aAAa,QAA2B;AACnD,QAAO,IAAI"}
@@ -6,8 +6,7 @@ import { GET_CUSTOMER_QUERY } from "../gql/queries/customer.js";
6
6
 
7
7
  //#region src/lib/data/customer.ts
8
8
  const transferCart = async (ctx) => {
9
- const cookieHeader = ctx.cookieHeader;
10
- const apolloClient = createServerApolloClient(cookieHeader);
9
+ const apolloClient = createServerApolloClient(ctx.cookieHeader ?? "");
11
10
  const cartId = getCartId(ctx);
12
11
  if (!cartId) return null;
13
12
  try {
@@ -26,8 +25,7 @@ const transferCart = async (ctx) => {
26
25
  }
27
26
  };
28
27
  const retrieveCustomer = async (ctx) => {
29
- const cookieHeader = ctx.cookieHeader;
30
- const apolloClient = createServerApolloClient(cookieHeader);
28
+ const apolloClient = createServerApolloClient(ctx.cookieHeader ?? "");
31
29
  try {
32
30
  return await graphqlFetch({
33
31
  query: GET_CUSTOMER_QUERY,
@@ -1 +1 @@
1
- {"version":3,"file":"customer.js","names":[],"sources":["../../../src/lib/data/customer.ts"],"sourcesContent":["import {\n Customer,\n GetCustomerQuery,\n GetCustomerQueryVariables,\n TransferCartMutation,\n TransferCartMutationVariables,\n} from '../../types/graphql';\nimport {\n createServerApolloClient,\n graphqlFetch,\n graphqlMutation,\n} from '../gql/apollo-client';\nimport { TRANSFER_CART_MUTATION } from '../gql/mutations/cart';\nimport { GET_CUSTOMER_QUERY } from '../gql/queries/customer';\nimport { medusaError } from '../utils/medusa-error';\nimport type { StorefrontContext } from './context';\nimport { getCacheTag, getCartId } from './cookies-utils';\n\nexport const transferCart = async (\n ctx: StorefrontContext\n): Promise<TransferCartMutation['transferCart'] | null> => {\n const cookieHeader = ctx.cookieHeader;\n const apolloClient = createServerApolloClient(cookieHeader);\n const cartId = getCartId(ctx);\n\n if (!cartId) {\n return null;\n }\n\n try {\n const result = await graphqlMutation<\n TransferCartMutation,\n TransferCartMutationVariables\n >(\n {\n mutation: TRANSFER_CART_MUTATION,\n variables: {\n cartId,\n },\n },\n apolloClient\n );\n\n const cart = result?.transferCart ?? null;\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 return cart;\n } catch (err) {\n medusaError(err);\n return null;\n }\n};\n\nexport const retrieveCustomer = async (\n ctx: StorefrontContext\n): Promise<Customer | null> => {\n const cookieHeader = ctx.cookieHeader;\n const apolloClient = createServerApolloClient(cookieHeader);\n try {\n const customer = await graphqlFetch<\n GetCustomerQuery,\n GetCustomerQueryVariables\n >(\n {\n query: GET_CUSTOMER_QUERY,\n fetchPolicy: 'network-only',\n },\n apolloClient\n ).then((response) => response?.me ?? null);\n return customer;\n } catch {\n return null;\n }\n};\n"],"mappings":";;;;;;;AAkBA,MAAa,eAAe,OAC1B,QACyD;CACzD,MAAM,eAAe,IAAI;CACzB,MAAM,eAAe,yBAAyB,aAAa;CAC3D,MAAM,SAAS,UAAU,IAAI;AAE7B,KAAI,CAAC,OACH,QAAO;AAGT,KAAI;EAcF,MAAM,QAbS,MAAM,gBAInB;GACE,UAAU;GACV,WAAW,EACT,QACD;GACF,EACD,aACD,GAEoB,gBAAgB;AAErC,MAAI,KACF,KAAI;GACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,iBADqB,YAAY,SAAS,IAAI,CACnB;UACrB;AAKV,SAAO;UACA,KAAK;AACZ,cAAY,IAAI;AAChB,SAAO;;;AAIX,MAAa,mBAAmB,OAC9B,QAC6B;CAC7B,MAAM,eAAe,IAAI;CACzB,MAAM,eAAe,yBAAyB,aAAa;AAC3D,KAAI;AAWF,SAViB,MAAM,aAIrB;GACE,OAAO;GACP,aAAa;GACd,EACD,aACD,CAAC,MAAM,aAAa,UAAU,MAAM,KAAK;SAEpC;AACN,SAAO"}
1
+ {"version":3,"file":"customer.js","names":[],"sources":["../../../src/lib/data/customer.ts"],"sourcesContent":["import {\n Customer,\n GetCustomerQuery,\n GetCustomerQueryVariables,\n TransferCartMutation,\n TransferCartMutationVariables,\n} from '../../types/graphql';\nimport {\n createServerApolloClient,\n graphqlFetch,\n graphqlMutation,\n} from '../gql/apollo-client';\nimport { TRANSFER_CART_MUTATION } from '../gql/mutations/cart';\nimport { GET_CUSTOMER_QUERY } from '../gql/queries/customer';\nimport { medusaError } from '../utils/medusa-error';\nimport type { StorefrontContext } from './context';\nimport { getCacheTag, getCartId } from './cookies-utils';\n\nexport const transferCart = async (\n ctx: StorefrontContext\n): Promise<TransferCartMutation['transferCart'] | null> => {\n const cookieHeader = ctx.cookieHeader ?? '';\n const apolloClient = createServerApolloClient(cookieHeader);\n const cartId = getCartId(ctx);\n\n if (!cartId) {\n return null;\n }\n\n try {\n const result = await graphqlMutation<\n TransferCartMutation,\n TransferCartMutationVariables\n >(\n {\n mutation: TRANSFER_CART_MUTATION,\n variables: {\n cartId,\n },\n },\n apolloClient\n );\n\n const cart = result?.transferCart ?? null;\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 return cart;\n } catch (err) {\n medusaError(err);\n return null;\n }\n};\n\nexport const retrieveCustomer = async (\n ctx: StorefrontContext\n): Promise<Customer | null> => {\n const cookieHeader = ctx.cookieHeader ?? '';\n const apolloClient = createServerApolloClient(cookieHeader);\n try {\n const customer = await graphqlFetch<\n GetCustomerQuery,\n GetCustomerQueryVariables\n >(\n {\n query: GET_CUSTOMER_QUERY,\n fetchPolicy: 'network-only',\n },\n apolloClient\n ).then((response) => response?.me ?? null);\n return customer;\n } catch {\n return null;\n }\n};\n"],"mappings":";;;;;;;AAkBA,MAAa,eAAe,OAC1B,QACyD;CAEzD,MAAM,eAAe,yBADA,IAAI,gBAAgB,GACkB;CAC3D,MAAM,SAAS,UAAU,IAAI;AAE7B,KAAI,CAAC,OACH,QAAO;AAGT,KAAI;EAcF,MAAM,QAbS,MAAM,gBAInB;GACE,UAAU;GACV,WAAW,EACT,QACD;GACF,EACD,aACD,GAEoB,gBAAgB;AAErC,MAAI,KACF,KAAI;GACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,iBADqB,YAAY,SAAS,IAAI,CACnB;UACrB;AAKV,SAAO;UACA,KAAK;AACZ,cAAY,IAAI;AAChB,SAAO;;;AAIX,MAAa,mBAAmB,OAC9B,QAC6B;CAE7B,MAAM,eAAe,yBADA,IAAI,gBAAgB,GACkB;AAC3D,KAAI;AAWF,SAViB,MAAM,aAIrB;GACE,OAAO;GACP,aAAa;GACd,EACD,aACD,CAAC,MAAM,aAAa,UAAU,MAAM,KAAK;SAEpC;AACN,SAAO"}
@@ -7,7 +7,6 @@ const resolveNextContext = async () => {
7
7
  const cookieStore = await cookies();
8
8
  return {
9
9
  cartId: cookieStore.get("_medusa_cart_id")?.value ?? "",
10
- customerToken: cookieStore.get("_medusa_jwt")?.value ?? "",
11
10
  cacheId: cookieStore.get("_medusa_cache_id")?.value ?? "",
12
11
  cookieHeader: cookieStore.toString()
13
12
  };
@@ -1 +1 @@
1
- {"version":3,"file":"next-context.js","names":[],"sources":["../../../src/lib/data/next-context.ts"],"sourcesContent":["'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport { cookies } from 'next/headers';\nimport { redirect } from 'next/navigation';\n\nimport { updateCart } from './cart';\nimport { StorefrontContext } from './context';\nimport { getCacheTag, getCartId } from './cookies-utils';\nimport { getRegion } from './regions';\n\nexport const resolveNextContext = async (): Promise<StorefrontContext> => {\n const cookieStore = await cookies();\n\n return {\n cartId: cookieStore.get('_medusa_cart_id')?.value ?? '',\n customerToken: cookieStore.get('_medusa_jwt')?.value ?? '',\n cacheId: cookieStore.get('_medusa_cache_id')?.value ?? '',\n cookieHeader: cookieStore.toString(),\n };\n};\n"],"mappings":";;;;;AAWA,MAAa,qBAAqB,YAAwC;CACxE,MAAM,cAAc,MAAM,SAAS;AAEnC,QAAO;EACL,QAAQ,YAAY,IAAI,kBAAkB,EAAE,SAAS;EACrD,eAAe,YAAY,IAAI,cAAc,EAAE,SAAS;EACxD,SAAS,YAAY,IAAI,mBAAmB,EAAE,SAAS;EACvD,cAAc,YAAY,UAAU;EACrC"}
1
+ {"version":3,"file":"next-context.js","names":[],"sources":["../../../src/lib/data/next-context.ts"],"sourcesContent":["'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport { cookies } from 'next/headers';\nimport { redirect } from 'next/navigation';\n\nimport { updateCart } from './cart';\nimport { StorefrontContext } from './context';\nimport { getCacheTag, getCartId } from './cookies-utils';\nimport { getRegion } from './regions';\n\nexport const resolveNextContext = async (): Promise<StorefrontContext> => {\n const cookieStore = await cookies();\n\n return {\n cartId: cookieStore.get('_medusa_cart_id')?.value ?? '',\n cacheId: cookieStore.get('_medusa_cache_id')?.value ?? '',\n cookieHeader: cookieStore.toString(),\n };\n};\n"],"mappings":";;;;;AAWA,MAAa,qBAAqB,YAAwC;CACxE,MAAM,cAAc,MAAM,SAAS;AAEnC,QAAO;EACL,QAAQ,YAAY,IAAI,kBAAkB,EAAE,SAAS;EACrD,SAAS,YAAY,IAAI,mBAAmB,EAAE,SAAS;EACvD,cAAc,YAAY,UAAU;EACrC"}
@@ -1,16 +1,14 @@
1
1
  import { sdk } from "../config/medusa.js";
2
2
  import { medusaError } from "../utils/medusa-error.js";
3
- import { getAuthHeaders, getCacheOptions } from "./cookies-utils.js";
3
+ import { getCacheOptions } from "./cookies-utils.js";
4
4
  import { normalizeOrder } from "../utils/normalize-functions.js";
5
5
 
6
6
  //#region src/lib/data/orders.ts
7
7
  const retrieveOrder = async (id, ctx) => {
8
- const headers = { ...getAuthHeaders(ctx) };
9
8
  const next = { ...getCacheOptions("orders", ctx) };
10
9
  return sdk.client.fetch(`/store/orders/${id}`, {
11
10
  method: "GET",
12
11
  query: { fields: "*payment_collections.payments,*items,*items.metadata,*items.variant,*items.product" },
13
- headers,
14
12
  next,
15
13
  cache: "force-cache"
16
14
  }).then(({ order }) => order && normalizeOrder(order)).catch((err) => medusaError(err));
@@ -1 +1 @@
1
- {"version":3,"file":"orders.js","names":[],"sources":["../../../src/lib/data/orders.ts"],"sourcesContent":["import { HttpTypes } from '@medusajs/types';\n\nimport { sdk } from '../config/medusa';\nimport { medusaError } from '../utils/medusa-error';\nimport { normalizeOrder } from '../utils/normalize-functions';\nimport { StorefrontContext } from './context';\nimport { getAuthHeaders, getCacheOptions } from './cookies-utils';\n\nexport const retrieveOrder = async (id: string, ctx: StorefrontContext) => {\n const headers = {\n ...getAuthHeaders(ctx),\n };\n\n const next = {\n ...getCacheOptions('orders', ctx),\n };\n\n return sdk.client\n .fetch<HttpTypes.StoreOrderResponse>(`/store/orders/${id}`, {\n method: 'GET',\n query: {\n fields:\n '*payment_collections.payments,*items,*items.metadata,*items.variant,*items.product',\n },\n headers,\n next,\n cache: 'force-cache',\n })\n .then(({ order }) => order && normalizeOrder(order))\n .catch((err) => medusaError(err));\n};\n"],"mappings":";;;;;;AAQA,MAAa,gBAAgB,OAAO,IAAY,QAA2B;CACzE,MAAM,UAAU,EACd,GAAG,eAAe,IAAI,EACvB;CAED,MAAM,OAAO,EACX,GAAG,gBAAgB,UAAU,IAAI,EAClC;AAED,QAAO,IAAI,OACR,MAAoC,iBAAiB,MAAM;EAC1D,QAAQ;EACR,OAAO,EACL,QACE,sFACH;EACD;EACA;EACA,OAAO;EACR,CAAC,CACD,MAAM,EAAE,YAAY,SAAS,eAAe,MAAM,CAAC,CACnD,OAAO,QAAQ,YAAY,IAAI,CAAC"}
1
+ {"version":3,"file":"orders.js","names":[],"sources":["../../../src/lib/data/orders.ts"],"sourcesContent":["import { HttpTypes } from '@medusajs/types';\n\nimport { sdk } from '../config/medusa';\nimport { medusaError } from '../utils/medusa-error';\nimport { normalizeOrder } from '../utils/normalize-functions';\nimport { StorefrontContext } from './context';\nimport { getCacheOptions } from './cookies-utils';\n\nexport const retrieveOrder = async (id: string, ctx: StorefrontContext) => {\n const next = {\n ...getCacheOptions('orders', ctx),\n };\n\n return sdk.client\n .fetch<HttpTypes.StoreOrderResponse>(`/store/orders/${id}`, {\n method: 'GET',\n query: {\n fields:\n '*payment_collections.payments,*items,*items.metadata,*items.variant,*items.product',\n },\n next,\n cache: 'force-cache',\n })\n .then(({ order }) => order && normalizeOrder(order))\n .catch((err) => medusaError(err));\n};\n"],"mappings":";;;;;;AAQA,MAAa,gBAAgB,OAAO,IAAY,QAA2B;CACzE,MAAM,OAAO,EACX,GAAG,gBAAgB,UAAU,IAAI,EAClC;AAED,QAAO,IAAI,OACR,MAAoC,iBAAiB,MAAM;EAC1D,QAAQ;EACR,OAAO,EACL,QACE,sFACH;EACD;EACA,OAAO;EACR,CAAC,CACD,MAAM,EAAE,YAAY,SAAS,eAAe,MAAM,CAAC,CACnD,OAAO,QAAQ,YAAY,IAAI,CAAC"}
@@ -1,10 +1,10 @@
1
1
  'use client';
2
2
 
3
3
  import * as React$1 from "react";
4
- import Medusa from "@medusajs/js-sdk";
5
- import * as Apollo from "@apollo/client";
6
4
  import * as SWRNamespace from "swr";
7
5
  import useSWR from "swr";
6
+ import Medusa from "@medusajs/js-sdk";
7
+ import * as Apollo from "@apollo/client";
8
8
  import * as ReactDOM from "react-dom";
9
9
  import * as ReactDOMClient from "react-dom/client";
10
10
 
@@ -1 +1 @@
1
- {"version":3,"file":"apollo-client.d.ts","names":[],"sources":["../../../src/lib/gql/apollo-client.ts"],"sourcesContent":[],"mappings":";;;;cAqBM,cAAY;;AAbM;AA6BxB;AAwBA;AASA;;AAIqC,iBArCrB,wBAAA,CAqCqB,YAAA,CAAA,EAAA,MAAA,CAAA,EArCyB,YAqCzB;AAAS,iBAb9B,gBAAA,CAa8B,GAAA,CAAA,EAbR,eAaQ,GAAA,IAAA,CAAA,EAbqB,YAarB;AAAnC,iBAJW,YAIE,CAAA,OAAA,EAAA,mBAFH,kBAEG,CAAA,CAAA,OAAA,EAAb,YAAA,CAAa,YAAA,CAAa,OAAb,EAAsB,UAAtB,CAAA,EAAA,oBAAA,CAAA,EACC,YADD,CAAA,EAErB,OAFqB,CAEb,OAFa,GAAA,SAAA,CAAA;AACC,iBAiBH,eAjBG,CAAA,OAAA,EAAA,mBAmBJ,kBAnBI,CAAA,CAAA,OAAA,EAqBd,YAAA,CAAa,aArBC,CAqBa,OArBb,EAqBsB,UArBtB,CAAA,EAAA,oBAAA,CAAA,EAsBA,YAtBA,CAAA,EAuBtB,OAvBsB,CAuBd,OAvBc,GAAA,SAAA,CAAA"}
1
+ {"version":3,"file":"apollo-client.d.ts","names":[],"sources":["../../../src/lib/gql/apollo-client.ts"],"sourcesContent":[],"mappings":";;;;cAmBM,cAAY;;AAXM;AA2BxB;AA2BA;AASA;;AAIqC,iBAxCrB,wBAAA,CAwCqB,YAAA,CAAA,EAAA,MAAA,CAAA,EAxCyB,YAwCzB;AAAS,iBAb9B,gBAAA,CAa8B,GAAA,CAAA,EAbR,eAaQ,GAAA,IAAA,CAAA,EAbqB,YAarB;AAAnC,iBAJW,YAIE,CAAA,OAAA,EAAA,mBAFH,kBAEG,CAAA,CAAA,OAAA,EAAb,YAAA,CAAa,YAAA,CAAa,OAAb,EAAsB,UAAtB,CAAA,EAAA,oBAAA,CAAA,EACC,YADD,CAAA,EAErB,OAFqB,CAEb,OAFa,GAAA,SAAA,CAAA;AACC,iBAiBH,eAjBG,CAAA,OAAA,EAAA,mBAmBJ,kBAnBI,CAAA,CAAA,OAAA,EAqBd,YAAA,CAAa,aArBC,CAqBa,OArBb,EAqBsB,UArBtB,CAAA,EAAA,oBAAA,CAAA,EAsBA,YAtBA,CAAA,EAuBtB,OAvBsB,CAuBd,OAvBc,GAAA,SAAA,CAAA"}
@@ -21,10 +21,10 @@ const apolloClient = new ApolloClient({
21
21
  function createServerApolloClient(cookieHeader) {
22
22
  return new ApolloClient({
23
23
  link: new ApolloLink((operation, forward) => {
24
- if (cookieHeader) operation.setContext(({ headers = {} }) => ({ headers: {
25
- ...headers,
26
- Cookie: cookieHeader
27
- } }));
24
+ if (cookieHeader) operation.setContext({
25
+ http: { includeCredentials: true },
26
+ headers: { Cookie: cookieHeader }
27
+ });
28
28
  return forward(operation);
29
29
  }).concat(httpLink),
30
30
  cache: new InMemoryCache({}),
@@ -1 +1 @@
1
- {"version":3,"file":"apollo-client.js","names":["error: any"],"sources":["../../../src/lib/gql/apollo-client.ts"],"sourcesContent":["import { IncomingMessage } from 'http';\n\nimport { ApolloLink } from '@apollo/client';\nimport {\n ApolloClient,\n HttpLink,\n InMemoryCache,\n OperationVariables,\n} from '@apollo/client';\n\nimport { StorefrontContext } from '../data/context';\nimport { getAuthHeaders } from '../data/cookies-utils';\nimport { getBaseURL } from '../utils/env';\n\nconst isServer = () => typeof window === 'undefined';\n\nconst httpLink = new HttpLink({\n uri: isServer() ? `${getBaseURL()}/api/graphql` : '/api/graphql',\n credentials: 'include',\n});\n\nconst apolloClient = new ApolloClient({\n link: httpLink,\n cache: new InMemoryCache({}),\n defaultOptions: {\n watchQuery: {\n notifyOnNetworkStatusChange: true,\n },\n },\n});\n\n/**\n * When requests are sent from the server, cookies need to be manually attached.\n *\n * @param cookieHeader Cookies string to forward\n * @returns Server-side Apollo client\n */\nexport function createServerApolloClient(cookieHeader?: string) {\n const authLink = new ApolloLink((operation, forward) => {\n if (cookieHeader) {\n operation.setContext(({ headers = {} }) => ({\n headers: {\n ...headers,\n Cookie: cookieHeader,\n },\n }));\n }\n return forward(operation);\n });\n\n return new ApolloClient({\n link: authLink.concat(httpLink),\n cache: new InMemoryCache({}),\n defaultOptions: {\n watchQuery: {\n notifyOnNetworkStatusChange: true,\n },\n },\n });\n}\n\nexport function initializeApollo(req: IncomingMessage | null = null) {\n if (isServer()) {\n const cookieHeader = req?.headers.cookie;\n return createServerApolloClient(cookieHeader);\n }\n\n return apolloClient;\n}\n\nexport async function graphqlFetch<\n TResult,\n TVariables extends OperationVariables,\n>(\n options: ApolloClient.QueryOptions<TResult, TVariables>,\n apolloClientOverride?: ApolloClient\n): Promise<TResult | undefined> {\n try {\n const client = apolloClientOverride || apolloClient;\n\n const { data } = await client.query<TResult, TVariables>({\n ...options,\n fetchPolicy: 'network-only',\n });\n\n return data;\n } catch (error: any) {\n // TODO - Better error handling\n throw new Error(error.message || 'GraphQL error');\n }\n}\n\nexport async function graphqlMutation<\n TResult,\n TVariables extends OperationVariables,\n>(\n options: ApolloClient.MutateOptions<TResult, TVariables>,\n apolloClientOverride?: ApolloClient\n): Promise<TResult | undefined> {\n try {\n const client = apolloClientOverride || apolloClient;\n\n const { data } = await client.mutate<TResult, TVariables>({\n ...options,\n fetchPolicy: 'network-only',\n });\n\n return data;\n } catch (error: any) {\n // TODO - Better error handling\n throw new Error(error.message || 'GraphQL error');\n }\n}\nexport default apolloClient;\n"],"mappings":";;;;AAcA,MAAM,iBAAiB,OAAO,WAAW;AAEzC,MAAM,WAAW,IAAI,SAAS;CAC5B,KAAK,UAAU,GAAG,GAAG,YAAY,CAAC,gBAAgB;CAClD,aAAa;CACd,CAAC;AAEF,MAAM,eAAe,IAAI,aAAa;CACpC,MAAM;CACN,OAAO,IAAI,cAAc,EAAE,CAAC;CAC5B,gBAAgB,EACd,YAAY,EACV,6BAA6B,MAC9B,EACF;CACF,CAAC;;;;;;;AAQF,SAAgB,yBAAyB,cAAuB;AAa9D,QAAO,IAAI,aAAa;EACtB,MAbe,IAAI,YAAY,WAAW,YAAY;AACtD,OAAI,aACF,WAAU,YAAY,EAAE,UAAU,EAAE,QAAQ,EAC1C,SAAS;IACP,GAAG;IACH,QAAQ;IACT,EACF,EAAE;AAEL,UAAO,QAAQ,UAAU;IACzB,CAGe,OAAO,SAAS;EAC/B,OAAO,IAAI,cAAc,EAAE,CAAC;EAC5B,gBAAgB,EACd,YAAY,EACV,6BAA6B,MAC9B,EACF;EACF,CAAC;;AAGJ,SAAgB,iBAAiB,MAA8B,MAAM;AACnE,KAAI,UAAU,EAAE;EACd,MAAM,eAAe,KAAK,QAAQ;AAClC,SAAO,yBAAyB,aAAa;;AAG/C,QAAO;;AAGT,eAAsB,aAIpB,SACA,sBAC8B;AAC9B,KAAI;EAGF,MAAM,EAAE,SAAS,OAFF,wBAAwB,cAET,MAA2B;GACvD,GAAG;GACH,aAAa;GACd,CAAC;AAEF,SAAO;UACAA,OAAY;AAEnB,QAAM,IAAI,MAAM,MAAM,WAAW,gBAAgB;;;AAIrD,eAAsB,gBAIpB,SACA,sBAC8B;AAC9B,KAAI;EAGF,MAAM,EAAE,SAAS,OAFF,wBAAwB,cAET,OAA4B;GACxD,GAAG;GACH,aAAa;GACd,CAAC;AAEF,SAAO;UACAA,OAAY;AAEnB,QAAM,IAAI,MAAM,MAAM,WAAW,gBAAgB;;;AAGrD,4BAAe"}
1
+ {"version":3,"file":"apollo-client.js","names":["error: any"],"sources":["../../../src/lib/gql/apollo-client.ts"],"sourcesContent":["import { IncomingMessage } from 'http';\n\nimport { ApolloLink } from '@apollo/client';\nimport {\n ApolloClient,\n HttpLink,\n InMemoryCache,\n OperationVariables,\n} from '@apollo/client';\n\nimport { getBaseURL } from '../utils/env';\n\nconst isServer = () => typeof window === 'undefined';\n\nconst httpLink = new HttpLink({\n uri: isServer() ? `${getBaseURL()}/api/graphql` : '/api/graphql',\n credentials: 'include',\n});\n\nconst apolloClient = new ApolloClient({\n link: httpLink,\n cache: new InMemoryCache({}),\n defaultOptions: {\n watchQuery: {\n notifyOnNetworkStatusChange: true,\n },\n },\n});\n\n/**\n * When requests are sent from the server, cookies need to be manually attached.\n *\n * @param cookieHeader Cookies string to forward\n * @returns Server-side Apollo client\n */\nexport function createServerApolloClient(cookieHeader?: string) {\n const authLink = new ApolloLink((operation, forward) => {\n if (cookieHeader) {\n operation.setContext({\n http: {\n includeCredentials: true,\n },\n headers: {\n Cookie: cookieHeader,\n },\n });\n }\n\n return forward(operation);\n });\n\n return new ApolloClient({\n link: authLink.concat(httpLink),\n cache: new InMemoryCache({}),\n defaultOptions: {\n watchQuery: {\n notifyOnNetworkStatusChange: true,\n },\n },\n });\n}\n\nexport function initializeApollo(req: IncomingMessage | null = null) {\n if (isServer()) {\n const cookieHeader = req?.headers.cookie;\n return createServerApolloClient(cookieHeader);\n }\n\n return apolloClient;\n}\n\nexport async function graphqlFetch<\n TResult,\n TVariables extends OperationVariables,\n>(\n options: ApolloClient.QueryOptions<TResult, TVariables>,\n apolloClientOverride?: ApolloClient\n): Promise<TResult | undefined> {\n try {\n const client = apolloClientOverride || apolloClient;\n\n const { data } = await client.query<TResult, TVariables>({\n ...options,\n fetchPolicy: 'network-only',\n });\n\n return data;\n } catch (error: any) {\n // TODO - Better error handling\n throw new Error(error.message || 'GraphQL error');\n }\n}\n\nexport async function graphqlMutation<\n TResult,\n TVariables extends OperationVariables,\n>(\n options: ApolloClient.MutateOptions<TResult, TVariables>,\n apolloClientOverride?: ApolloClient\n): Promise<TResult | undefined> {\n try {\n const client = apolloClientOverride || apolloClient;\n\n const { data } = await client.mutate<TResult, TVariables>({\n ...options,\n fetchPolicy: 'network-only',\n });\n\n return data;\n } catch (error: any) {\n // TODO - Better error handling\n throw new Error(error.message || 'GraphQL error');\n }\n}\nexport default apolloClient;\n"],"mappings":";;;;AAYA,MAAM,iBAAiB,OAAO,WAAW;AAEzC,MAAM,WAAW,IAAI,SAAS;CAC5B,KAAK,UAAU,GAAG,GAAG,YAAY,CAAC,gBAAgB;CAClD,aAAa;CACd,CAAC;AAEF,MAAM,eAAe,IAAI,aAAa;CACpC,MAAM;CACN,OAAO,IAAI,cAAc,EAAE,CAAC;CAC5B,gBAAgB,EACd,YAAY,EACV,6BAA6B,MAC9B,EACF;CACF,CAAC;;;;;;;AAQF,SAAgB,yBAAyB,cAAuB;AAgB9D,QAAO,IAAI,aAAa;EACtB,MAhBe,IAAI,YAAY,WAAW,YAAY;AACtD,OAAI,aACF,WAAU,WAAW;IACnB,MAAM,EACJ,oBAAoB,MACrB;IACD,SAAS,EACP,QAAQ,cACT;IACF,CAAC;AAGJ,UAAO,QAAQ,UAAU;IACzB,CAGe,OAAO,SAAS;EAC/B,OAAO,IAAI,cAAc,EAAE,CAAC;EAC5B,gBAAgB,EACd,YAAY,EACV,6BAA6B,MAC9B,EACF;EACF,CAAC;;AAGJ,SAAgB,iBAAiB,MAA8B,MAAM;AACnE,KAAI,UAAU,EAAE;EACd,MAAM,eAAe,KAAK,QAAQ;AAClC,SAAO,yBAAyB,aAAa;;AAG/C,QAAO;;AAGT,eAAsB,aAIpB,SACA,sBAC8B;AAC9B,KAAI;EAGF,MAAM,EAAE,SAAS,OAFF,wBAAwB,cAET,MAA2B;GACvD,GAAG;GACH,aAAa;GACd,CAAC;AAEF,SAAO;UACAA,OAAY;AAEnB,QAAM,IAAI,MAAM,MAAM,WAAW,gBAAgB;;;AAIrD,eAAsB,gBAIpB,SACA,sBAC8B;AAC9B,KAAI;EAGF,MAAM,EAAE,SAAS,OAFF,wBAAwB,cAET,OAA4B;GACxD,GAAG;GACH,aAAa;GACd,CAAC;AAEF,SAAO;UACAA,OAAY;AAEnB,QAAM,IAAI,MAAM,MAAM,WAAW,gBAAgB;;;AAGrD,4BAAe"}
@@ -1,14 +1,14 @@
1
- import * as _apollo_client17 from "@apollo/client";
1
+ import * as _apollo_client13 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/fragments/cart.d.ts
4
- declare const LINE_ITEM_FRAGMENT: _apollo_client17.DocumentNode;
5
- declare const COUNTRY_FRAGMENT: _apollo_client17.DocumentNode;
6
- declare const REGION_FRAGMENT: _apollo_client17.DocumentNode;
7
- declare const SHIPPING_METHODS_FRAGMENT: _apollo_client17.DocumentNode;
8
- declare const PAYMENT_COLLECTION_FRAGMENT: _apollo_client17.DocumentNode;
9
- declare const ADDRESS_FRAGMENT: _apollo_client17.DocumentNode;
10
- declare const PROMOTION_FRAGMENT: _apollo_client17.DocumentNode;
11
- declare const CART_FRAGMENT: _apollo_client17.DocumentNode;
4
+ declare const LINE_ITEM_FRAGMENT: _apollo_client13.DocumentNode;
5
+ declare const COUNTRY_FRAGMENT: _apollo_client13.DocumentNode;
6
+ declare const REGION_FRAGMENT: _apollo_client13.DocumentNode;
7
+ declare const SHIPPING_METHODS_FRAGMENT: _apollo_client13.DocumentNode;
8
+ declare const PAYMENT_COLLECTION_FRAGMENT: _apollo_client13.DocumentNode;
9
+ declare const ADDRESS_FRAGMENT: _apollo_client13.DocumentNode;
10
+ declare const PROMOTION_FRAGMENT: _apollo_client13.DocumentNode;
11
+ declare const CART_FRAGMENT: _apollo_client13.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,8 +1,8 @@
1
- import * as _apollo_client1 from "@apollo/client";
1
+ import * as _apollo_client24 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/fragments/customer.d.ts
4
- declare const CUSTOMER_ADDRESS_FRAGMENT: _apollo_client1.DocumentNode;
5
- declare const CUSTOMER_FRAGMENT: _apollo_client1.DocumentNode;
4
+ declare const CUSTOMER_ADDRESS_FRAGMENT: _apollo_client24.DocumentNode;
5
+ declare const CUSTOMER_FRAGMENT: _apollo_client24.DocumentNode;
6
6
  //#endregion
7
7
  export { CUSTOMER_ADDRESS_FRAGMENT, CUSTOMER_FRAGMENT };
8
8
  //# sourceMappingURL=customer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"customer.d.ts","names":[],"sources":["../../../../src/lib/gql/fragments/customer.ts"],"sourcesContent":[],"mappings":";;;cAEa,2BAkBZ,eAAA,CAlBqC;cAoBzB,mBAeZ,eAAA,CAf6B"}
1
+ {"version":3,"file":"customer.d.ts","names":[],"sources":["../../../../src/lib/gql/fragments/customer.ts"],"sourcesContent":[],"mappings":";;;cAEa,2BAkBZ,gBAAA,CAlBqC;cAoBzB,mBAeZ,gBAAA,CAf6B"}
@@ -1,9 +1,9 @@
1
- import * as _apollo_client10 from "@apollo/client";
1
+ import * as _apollo_client0 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/mutations/cart.d.ts
4
- declare const UPDATE_CART_MUTATION: _apollo_client10.DocumentNode;
5
- declare const DELETE_LINE_ITEM_MUTATION: _apollo_client10.DocumentNode;
6
- declare const TRANSFER_CART_MUTATION: _apollo_client10.DocumentNode;
4
+ declare const UPDATE_CART_MUTATION: _apollo_client0.DocumentNode;
5
+ declare const DELETE_LINE_ITEM_MUTATION: _apollo_client0.DocumentNode;
6
+ declare const TRANSFER_CART_MUTATION: _apollo_client0.DocumentNode;
7
7
  //#endregion
8
8
  export { DELETE_LINE_ITEM_MUTATION, TRANSFER_CART_MUTATION, UPDATE_CART_MUTATION };
9
9
  //# sourceMappingURL=cart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cart.d.ts","names":[],"sources":["../../../../src/lib/gql/mutations/cart.ts"],"sourcesContent":[],"mappings":";;;cAIa,sBAgBZ,gBAAA,CAhBgC;cAkBpB,2BAQZ,gBAAA,CARqC;cAUzB,wBAOZ,gBAAA,CAPkC"}
1
+ {"version":3,"file":"cart.d.ts","names":[],"sources":["../../../../src/lib/gql/mutations/cart.ts"],"sourcesContent":[],"mappings":";;;cAIa,sBAgBZ,eAAA,CAhBgC;cAkBpB,2BAQZ,eAAA,CARqC;cAUzB,wBAOZ,eAAA,CAPkC"}
@@ -1,7 +1,7 @@
1
- import * as _apollo_client13 from "@apollo/client";
1
+ import * as _apollo_client11 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/queries/cart.d.ts
4
- declare const GET_CART_QUERY: _apollo_client13.DocumentNode;
4
+ declare const GET_CART_QUERY: _apollo_client11.DocumentNode;
5
5
  //#endregion
6
6
  export { GET_CART_QUERY };
7
7
  //# sourceMappingURL=cart.d.ts.map
@@ -1,7 +1,7 @@
1
- import * as _apollo_client14 from "@apollo/client";
1
+ import * as _apollo_client10 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/queries/collections.d.ts
4
- declare const GET_COLLECTIONS_QUERY: _apollo_client14.DocumentNode;
4
+ declare const GET_COLLECTIONS_QUERY: _apollo_client10.DocumentNode;
5
5
  //#endregion
6
6
  export { GET_COLLECTIONS_QUERY };
7
7
  //# sourceMappingURL=collections.d.ts.map
@@ -1,7 +1,7 @@
1
- import * as _apollo_client15 from "@apollo/client";
1
+ import * as _apollo_client12 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/queries/customer.d.ts
4
- declare const GET_CUSTOMER_QUERY: _apollo_client15.DocumentNode;
4
+ declare const GET_CUSTOMER_QUERY: _apollo_client12.DocumentNode;
5
5
  //#endregion
6
6
  export { GET_CUSTOMER_QUERY };
7
7
  //# sourceMappingURL=customer.d.ts.map
@@ -1,7 +1,7 @@
1
- import * as _apollo_client16 from "@apollo/client";
1
+ import * as _apollo_client21 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/queries/footer.d.ts
4
- declare const GET_FOOTER_QUERY: _apollo_client16.DocumentNode;
4
+ declare const GET_FOOTER_QUERY: _apollo_client21.DocumentNode;
5
5
  //#endregion
6
6
  export { GET_FOOTER_QUERY };
7
7
  //# sourceMappingURL=footer.d.ts.map
@@ -1,8 +1,8 @@
1
- import * as _apollo_client0 from "@apollo/client";
1
+ import * as _apollo_client22 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/gql/queries/product.d.ts
4
- declare const SEARCH_SUGGESTIONS_QUERY: _apollo_client0.DocumentNode;
5
- declare const GET_PRODUCT_CATEGORIES_QUERY: _apollo_client0.DocumentNode;
4
+ declare const SEARCH_SUGGESTIONS_QUERY: _apollo_client22.DocumentNode;
5
+ declare const GET_PRODUCT_CATEGORIES_QUERY: _apollo_client22.DocumentNode;
6
6
  //#endregion
7
7
  export { GET_PRODUCT_CATEGORIES_QUERY, SEARCH_SUGGESTIONS_QUERY };
8
8
  //# sourceMappingURL=product.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"product.d.ts","names":[],"sources":["../../../../src/lib/gql/queries/product.ts"],"sourcesContent":[],"mappings":";;;cAOa,0BASZ,eAAA,CAToC;cAWxB,8BA4BZ,eAAA,CA5BwC"}
1
+ {"version":3,"file":"product.d.ts","names":[],"sources":["../../../../src/lib/gql/queries/product.ts"],"sourcesContent":[],"mappings":";;;cAOa,0BASZ,gBAAA,CAToC;cAWxB,8BA4BZ,gBAAA,CA5BwC"}
@@ -1,7 +1,7 @@
1
- import * as _apollo_client25 from "@apollo/client";
1
+ import * as _apollo_client0 from "@apollo/client";
2
2
 
3
3
  //#region src/lib/hooks/use-apollo.d.ts
4
- declare function useApollo(): _apollo_client25.ApolloClient;
4
+ declare function useApollo(): _apollo_client0.ApolloClient;
5
5
  //#endregion
6
6
  export { useApollo };
7
7
  //# sourceMappingURL=use-apollo.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-apollo.d.ts","names":[],"sources":["../../../src/lib/hooks/use-apollo.tsx"],"sourcesContent":[],"mappings":";;;iBAIgB,SAAA,CAAA,GAAS,gBAAA,CAAA"}
1
+ {"version":3,"file":"use-apollo.d.ts","names":[],"sources":["../../../src/lib/hooks/use-apollo.tsx"],"sourcesContent":[],"mappings":";;;iBAIgB,SAAA,CAAA,GAAS,eAAA,CAAA"}
@@ -2,7 +2,6 @@ import { Cart } from "../../types/graphql.js";
2
2
  import * as swr0 from "swr";
3
3
 
4
4
  //#region src/lib/hooks/use-cart.d.ts
5
- declare const CART_SWR_KEY = "medusa-cart";
6
5
  declare const useCart: () => {
7
6
  cart: Cart | null | undefined;
8
7
  error: any;
@@ -11,5 +10,5 @@ declare const useCart: () => {
11
10
  };
12
11
  declare const mutateCart: () => Promise<any>;
13
12
  //#endregion
14
- export { CART_SWR_KEY, mutateCart, useCart };
13
+ export { mutateCart, useCart };
15
14
  //# sourceMappingURL=use-cart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-cart.d.ts","names":[],"sources":["../../../src/lib/hooks/use-cart.ts"],"sourcesContent":[],"mappings":";;;;cAMa,YAAA;cAEA;;EAFA,KAAA,EAAA,GAAA;EAEA,SAAA,EAmBZ,OAAA;;;cAEY,kBAAU"}
1
+ {"version":3,"file":"use-cart.d.ts","names":[],"sources":["../../../src/lib/hooks/use-cart.ts"],"sourcesContent":[],"mappings":";;;;cAQa;;;EAAA,SAAA,EAgCZ,OAAA;;;cAEY,kBAAU"}
@@ -1,12 +1,16 @@
1
- import { retrieveCart } from "../data/cart.js";
2
- import { useStorefrontContext } from "../data/context.js";
1
+ 'use client';
2
+
3
3
  import useSWR, { mutate } from "swr";
4
4
 
5
5
  //#region src/lib/hooks/use-cart.ts
6
6
  const CART_SWR_KEY = "medusa-cart";
7
7
  const useCart = () => {
8
- const ctx = useStorefrontContext();
9
- const { data, error, isLoading, mutate: swrMutate } = useSWR(CART_SWR_KEY, () => retrieveCart(ctx), {
8
+ const { data, error, isLoading, mutate: swrMutate } = useSWR(CART_SWR_KEY, async () => {
9
+ const response = await fetch("/api/cart", { credentials: "include" });
10
+ if (!response.ok) throw new Error("Failed to fetch cart");
11
+ const { cart } = await response.json();
12
+ return cart;
13
+ }, {
10
14
  revalidateOnFocus: true,
11
15
  revalidateOnReconnect: true
12
16
  });
@@ -22,5 +26,5 @@ const mutateCart = () => {
22
26
  };
23
27
 
24
28
  //#endregion
25
- export { CART_SWR_KEY, mutateCart, useCart };
29
+ export { mutateCart, useCart };
26
30
  //# sourceMappingURL=use-cart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-cart.js","names":[],"sources":["../../../src/lib/hooks/use-cart.ts"],"sourcesContent":["import useSWR, { mutate } from 'swr';\n\nimport { Cart } from '../../types/graphql';\nimport { retrieveCart } from '../data/cart';\nimport { useStorefrontContext } from '../data/context';\n\nexport const CART_SWR_KEY = 'medusa-cart';\n\nexport const useCart = () => {\n const ctx = useStorefrontContext();\n\n const {\n data,\n error,\n isLoading,\n mutate: swrMutate,\n } = useSWR<Cart | null>(CART_SWR_KEY, () => retrieveCart(ctx), {\n revalidateOnFocus: true,\n revalidateOnReconnect: true,\n });\n\n return {\n cart: data,\n error,\n isLoading,\n mutate: swrMutate,\n };\n};\n\nexport const mutateCart = () => {\n return mutate(CART_SWR_KEY);\n};\n"],"mappings":";;;;;AAMA,MAAa,eAAe;AAE5B,MAAa,gBAAgB;CAC3B,MAAM,MAAM,sBAAsB;CAElC,MAAM,EACJ,MACA,OACA,WACA,QAAQ,cACN,OAAoB,oBAAoB,aAAa,IAAI,EAAE;EAC7D,mBAAmB;EACnB,uBAAuB;EACxB,CAAC;AAEF,QAAO;EACL,MAAM;EACN;EACA;EACA,QAAQ;EACT;;AAGH,MAAa,mBAAmB;AAC9B,QAAO,OAAO,aAAa"}
1
+ {"version":3,"file":"use-cart.js","names":[],"sources":["../../../src/lib/hooks/use-cart.ts"],"sourcesContent":["'use client';\n\nimport useSWR, { mutate } from 'swr';\n\nimport { Cart } from '../../types/graphql';\n\nconst CART_SWR_KEY = 'medusa-cart';\n\nexport const useCart = () => {\n const {\n data,\n error,\n isLoading,\n mutate: swrMutate,\n } = useSWR<Cart | null>(\n CART_SWR_KEY,\n async () => {\n const response = await fetch('/api/cart', {\n credentials: 'include',\n });\n\n if (!response.ok) {\n throw new Error('Failed to fetch cart');\n }\n\n const { cart } = await response.json();\n return cart;\n },\n {\n revalidateOnFocus: true,\n revalidateOnReconnect: true,\n }\n );\n\n return {\n cart: data,\n error,\n isLoading,\n mutate: swrMutate,\n };\n};\n\nexport const mutateCart = () => {\n return mutate(CART_SWR_KEY);\n};\n"],"mappings":";;;;;AAMA,MAAM,eAAe;AAErB,MAAa,gBAAgB;CAC3B,MAAM,EACJ,MACA,OACA,WACA,QAAQ,cACN,OACF,cACA,YAAY;EACV,MAAM,WAAW,MAAM,MAAM,aAAa,EACxC,aAAa,WACd,CAAC;AAEF,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,uBAAuB;EAGzC,MAAM,EAAE,SAAS,MAAM,SAAS,MAAM;AACtC,SAAO;IAET;EACE,mBAAmB;EACnB,uBAAuB;EACxB,CACF;AAED,QAAO;EACL,MAAM;EACN;EACA;EACA,QAAQ;EACT;;AAGH,MAAa,mBAAmB;AAC9B,QAAO,OAAO,aAAa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gfed-medusa/sf-lib-common",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -73,10 +73,10 @@
73
73
  "madge": "^8.0.0",
74
74
  "tsdown": "^0.17.3",
75
75
  "typescript": "^5",
76
- "@packages/jest-config": "0.0.0",
77
76
  "@packages/eslint-config": "0.0.0",
78
- "@packages/prettier-config": "0.0.0",
79
- "@packages/typescript-config": "0.0.0"
77
+ "@packages/jest-config": "0.0.0",
78
+ "@packages/typescript-config": "0.0.0",
79
+ "@packages/prettier-config": "0.0.0"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "@medusajs/ui": "^4.0.29",