@gfed-medusa/sf-lib-common 1.1.0 → 2.0.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.
- package/dist/components/breadcrumbs/index.d.ts +4 -6
- package/dist/components/breadcrumbs/index.d.ts.map +1 -1
- package/dist/components/breadcrumbs/index.js.map +1 -1
- package/dist/components/cart-button/index.d.ts +2 -2
- package/dist/components/cart-button/index.d.ts.map +1 -1
- package/dist/components/cart-button/index.js +11 -17
- package/dist/components/cart-button/index.js.map +1 -0
- package/dist/components/cart-dropdown/index.d.ts +3 -3
- package/dist/components/cart-dropdown/index.d.ts.map +1 -1
- package/dist/components/cart-dropdown/index.js +193 -16
- package/dist/components/cart-dropdown/index.js.map +1 -0
- package/dist/components/cart-mismatch-banner/index.d.ts +3 -3
- package/dist/components/cart-mismatch-banner/index.d.ts.map +1 -1
- package/dist/components/cart-mismatch-banner/index.js +1 -8
- package/dist/components/cart-mismatch-banner/index.js.map +1 -1
- package/dist/components/country-select/index.d.ts +1 -1
- package/dist/components/delete-button/index.d.ts +2 -2
- package/dist/components/delete-button/index.js +27 -11
- package/dist/components/delete-button/index.js.map +1 -0
- package/dist/components/error-message/index.d.ts +2 -2
- package/dist/components/error-message/index.d.ts.map +1 -1
- package/dist/components/footer/index.d.ts +2 -2
- package/dist/components/footer/index.d.ts.map +1 -1
- package/dist/components/footer/index.js +5 -10
- package/dist/components/footer/index.js.map +1 -1
- package/dist/components/free-shipping-price-nudge/index.d.ts +3 -3
- package/dist/components/free-shipping-price-nudge/index.d.ts.map +1 -1
- package/dist/components/free-shipping-price-nudge/index.js +2 -2
- package/dist/components/interactive-link/index.d.ts +2 -2
- package/dist/components/interactive-link/index.js +1 -1
- package/dist/components/layout-country-select/index.d.ts +4 -4
- package/dist/components/layout-country-select/index.js +89 -11
- package/dist/components/layout-country-select/index.js.map +1 -0
- package/dist/components/line-item-options/index.d.ts +3 -3
- package/dist/components/line-item-options/index.js +15 -2
- package/dist/components/line-item-options/index.js.map +1 -0
- package/dist/components/line-item-price/index.d.ts +3 -3
- package/dist/components/line-item-price/index.d.ts.map +1 -1
- package/dist/components/line-item-price/index.js +46 -2
- package/dist/components/line-item-price/index.js.map +1 -0
- package/dist/components/localized-client-link/index.d.ts +5 -12
- package/dist/components/localized-client-link/index.d.ts.map +1 -1
- package/dist/components/localized-client-link/index.js +19 -2
- package/dist/components/localized-client-link/index.js.map +1 -0
- package/dist/components/modal/index.d.ts +2 -2
- package/dist/components/modal/index.js +101 -3
- package/dist/components/modal/index.js.map +1 -0
- package/dist/components/nav/index.d.ts +2 -2
- package/dist/components/nav/index.js +6 -25
- package/dist/components/nav/index.js.map +1 -1
- package/dist/components/portable-text/index.d.ts +3 -3
- package/dist/components/portable-text/index.js +329 -2
- package/dist/components/portable-text/index.js.map +1 -0
- package/dist/components/preview-price/index.d.ts +1 -1
- package/dist/components/preview-price/index.js +19 -2
- package/dist/components/preview-price/index.js.map +1 -0
- package/dist/components/product-card/index.d.ts +2 -2
- package/dist/components/product-card/index.d.ts.map +1 -1
- package/dist/components/product-card/index.js +3 -4
- package/dist/components/product-card/index.js.map +1 -1
- package/dist/components/product-preview/index.d.ts +3 -3
- package/dist/components/product-preview/index.d.ts.map +1 -1
- package/dist/components/product-preview/index.js +4 -4
- package/dist/components/search-modal/index.d.ts +2 -2
- package/dist/components/search-modal/index.d.ts.map +1 -1
- package/dist/components/search-modal/index.js +135 -9
- package/dist/components/search-modal/index.js.map +1 -0
- package/dist/components/side-menu/index.d.ts +3 -3
- package/dist/components/side-menu/index.js +96 -13
- package/dist/components/side-menu/index.js.map +1 -0
- package/dist/components/thumbnail/index.js +43 -2
- package/dist/components/thumbnail/index.js.map +1 -0
- package/dist/lib/config/medusa.js +11 -2
- package/dist/lib/config/medusa.js.map +1 -0
- package/dist/lib/context/apollo-context.js +1 -2
- package/dist/lib/context/apollo-context.js.map +1 -1
- package/dist/lib/context/modal-context.d.ts +2 -2
- package/dist/lib/context/modal-context.js +19 -2
- package/dist/lib/context/modal-context.js.map +1 -0
- package/dist/lib/data/cart.d.ts +1 -1
- package/dist/lib/data/cart.d.ts.map +1 -1
- package/dist/lib/data/cart.js +102 -10
- package/dist/lib/data/cart.js.map +1 -0
- package/dist/lib/data/categories.d.ts +1 -1
- package/dist/lib/data/categories.js +15 -5
- package/dist/lib/data/categories.js.map +1 -0
- package/dist/lib/data/collections.d.ts +1 -1
- package/dist/lib/data/collections.js +21 -5
- package/dist/lib/data/collections.js.map +1 -0
- package/dist/lib/data/cookies.d.ts +2 -1
- package/dist/lib/data/cookies.d.ts.map +1 -1
- package/dist/lib/data/cookies.js +45 -2
- package/dist/lib/data/cookies.js.map +1 -0
- package/dist/lib/data/customer.d.ts +1 -1
- package/dist/lib/data/customer.d.ts.map +1 -1
- package/dist/lib/data/customer.js +39 -9
- package/dist/lib/data/customer.js.map +1 -0
- package/dist/lib/data/footer.js +15 -4
- package/dist/lib/data/footer.js.map +1 -0
- package/dist/lib/data/orders.d.ts +1 -1
- package/dist/lib/data/orders.js +4 -4
- package/dist/lib/data/regions.d.ts +1 -1
- package/dist/lib/data/regions.js +33 -4
- package/dist/lib/data/regions.js.map +1 -0
- package/dist/lib/data/search.d.ts +1 -1
- package/dist/lib/data/search.js +20 -5
- package/dist/lib/data/search.js.map +1 -0
- package/dist/lib/gql/apollo-client.js +66 -2
- package/dist/lib/gql/apollo-client.js.map +1 -0
- package/dist/lib/gql/fragments/cart.d.ts +9 -9
- package/dist/lib/gql/fragments/cart.d.ts.map +1 -1
- package/dist/lib/gql/fragments/cart.js +141 -3
- package/dist/{cart-BNoIGQmw.js.map → lib/gql/fragments/cart.js.map} +1 -1
- package/dist/lib/gql/fragments/customer.d.ts +3 -3
- package/dist/lib/gql/fragments/customer.js +41 -2
- package/dist/{customer-CgN4zI00.js.map → lib/gql/fragments/customer.js.map} +1 -1
- package/dist/lib/gql/fragments/product.d.ts +8 -8
- package/dist/lib/gql/fragments/product.js +89 -2
- package/dist/{product-COu5D1mS.js.map → lib/gql/fragments/product.js.map} +1 -1
- package/dist/lib/gql/mutations/cart.d.ts +4 -4
- package/dist/lib/gql/mutations/cart.d.ts.map +1 -1
- package/dist/lib/gql/mutations/cart.js +41 -4
- package/dist/{cart-IHaLnQC4.js.map → lib/gql/mutations/cart.js.map} +1 -1
- package/dist/lib/gql/mutations/customer.js +0 -1
- package/dist/lib/gql/queries/cart.d.ts +2 -2
- package/dist/lib/gql/queries/cart.d.ts.map +1 -1
- package/dist/lib/gql/queries/cart.js +15 -4
- package/dist/{cart-DH8urwwT.js.map → lib/gql/queries/cart.js.map} +1 -1
- package/dist/lib/gql/queries/collections.d.ts +2 -2
- package/dist/lib/gql/queries/collections.d.ts.map +1 -1
- package/dist/lib/gql/queries/collections.js +19 -3
- package/dist/{collections-DMv3UYgC.js.map → lib/gql/queries/collections.js.map} +1 -1
- package/dist/lib/gql/queries/customer.d.ts +2 -2
- package/dist/lib/gql/queries/customer.d.ts.map +1 -1
- package/dist/lib/gql/queries/customer.js +15 -3
- package/dist/{customer-DIJz6m7L.js.map → lib/gql/queries/customer.js.map} +1 -1
- package/dist/lib/gql/queries/footer.d.ts +2 -2
- package/dist/lib/gql/queries/footer.d.ts.map +1 -1
- package/dist/lib/gql/queries/footer.js +21 -2
- package/dist/lib/gql/queries/footer.js.map +1 -0
- package/dist/lib/gql/queries/product.d.ts +3 -3
- package/dist/lib/gql/queries/product.d.ts.map +1 -1
- package/dist/lib/gql/queries/product.js +46 -3
- package/dist/{product-C3HQUIgX.js.map → lib/gql/queries/product.js.map} +1 -1
- package/dist/lib/hooks/use-apollo.d.ts +2 -2
- package/dist/lib/hooks/use-apollo.js +10 -3
- package/dist/lib/hooks/use-apollo.js.map +1 -0
- package/dist/lib/hooks/use-search.d.ts +1 -1
- package/dist/lib/hooks/use-search.js +66 -6
- package/dist/lib/hooks/use-search.js.map +1 -0
- package/dist/lib/hooks/use-toggle-state.d.ts +23 -2
- package/dist/lib/hooks/use-toggle-state.d.ts.map +1 -0
- package/dist/lib/utils/data-types.js +9 -2
- package/dist/lib/utils/data-types.js.map +1 -0
- package/dist/lib/utils/env.js +1 -1
- package/dist/lib/utils/env.js.map +1 -1
- package/dist/lib/utils/get-percentage-diff.js +7 -2
- package/dist/lib/utils/get-percentage-diff.js.map +1 -0
- package/dist/lib/utils/get-product-price.d.ts +1 -1
- package/dist/lib/utils/get-product-price.js +46 -2
- package/dist/lib/utils/get-product-price.js.map +1 -0
- package/dist/lib/utils/medusa-error.js +16 -2
- package/dist/lib/utils/medusa-error.js.map +1 -0
- package/dist/lib/utils/money.js +14 -2
- package/dist/lib/utils/money.js.map +1 -0
- package/dist/lib/utils/normalize-functions.d.ts +1 -1
- package/dist/lib/utils/normalize-functions.js +69 -2
- package/dist/lib/utils/normalize-functions.js.map +1 -0
- package/dist/types/graphql.d.ts +1368 -2
- package/dist/types/graphql.d.ts.map +1 -0
- package/dist/types/prices.d.ts +20 -2
- package/dist/types/prices.d.ts.map +1 -0
- package/dist/types/prices.js +0 -1
- package/package.json +12 -12
- package/dist/apollo-client-Bw50r80c.js +0 -66
- package/dist/apollo-client-Bw50r80c.js.map +0 -1
- package/dist/cart-BNoIGQmw.js +0 -142
- package/dist/cart-DH8urwwT.js +0 -16
- package/dist/cart-IHaLnQC4.js +0 -42
- package/dist/cart-button-Dj_zRxop.js +0 -12
- package/dist/cart-button-Dj_zRxop.js.map +0 -1
- package/dist/cart-dropdown-D_PUJarp.js +0 -195
- package/dist/cart-dropdown-D_PUJarp.js.map +0 -1
- package/dist/cart-xkcyWLfU.js +0 -103
- package/dist/cart-xkcyWLfU.js.map +0 -1
- package/dist/categories-B-RYCIZ3.js +0 -16
- package/dist/categories-B-RYCIZ3.js.map +0 -1
- package/dist/collections-BgyvhW2p.js +0 -22
- package/dist/collections-BgyvhW2p.js.map +0 -1
- package/dist/collections-DMv3UYgC.js +0 -20
- package/dist/cookies-lksVIe4_.js +0 -38
- package/dist/cookies-lksVIe4_.js.map +0 -1
- package/dist/customer-CgN4zI00.js +0 -42
- package/dist/customer-ClewjBBr.js +0 -38
- package/dist/customer-ClewjBBr.js.map +0 -1
- package/dist/customer-DIJz6m7L.js +0 -16
- package/dist/data-types-CTPJXmJH.js +0 -10
- package/dist/data-types-CTPJXmJH.js.map +0 -1
- package/dist/delete-button-Bnm5bof2.js +0 -28
- package/dist/delete-button-Bnm5bof2.js.map +0 -1
- package/dist/footer-BvNV-R9D.js +0 -16
- package/dist/footer-BvNV-R9D.js.map +0 -1
- package/dist/footer-DCtgtjKS.js +0 -76
- package/dist/footer-DCtgtjKS.js.map +0 -1
- package/dist/get-percentage-diff-B_UVOFgE.js +0 -8
- package/dist/get-percentage-diff-B_UVOFgE.js.map +0 -1
- package/dist/get-product-price-DKWc76ev.js +0 -47
- package/dist/get-product-price-DKWc76ev.js.map +0 -1
- package/dist/graphql-CdTGi4Pp.d.ts +0 -1368
- package/dist/graphql-CdTGi4Pp.d.ts.map +0 -1
- package/dist/layout-country-select-C7Ra-opl.js +0 -90
- package/dist/layout-country-select-C7Ra-opl.js.map +0 -1
- package/dist/line-item-options-l_eRZIIq.js +0 -16
- package/dist/line-item-options-l_eRZIIq.js.map +0 -1
- package/dist/line-item-price-BlTwskFC.js +0 -47
- package/dist/line-item-price-BlTwskFC.js.map +0 -1
- package/dist/localized-client-link-CthmRcvb.js +0 -22
- package/dist/localized-client-link-CthmRcvb.js.map +0 -1
- package/dist/medusa-TumrpCF2.js +0 -12
- package/dist/medusa-TumrpCF2.js.map +0 -1
- package/dist/medusa-error-DDhA6RGC.js +0 -17
- package/dist/medusa-error-DDhA6RGC.js.map +0 -1
- package/dist/modal-BASYY-YM.js +0 -102
- package/dist/modal-BASYY-YM.js.map +0 -1
- package/dist/modal-context-02cA-7jy.js +0 -20
- package/dist/modal-context-02cA-7jy.js.map +0 -1
- package/dist/money-DVQGzXns.js +0 -15
- package/dist/money-DVQGzXns.js.map +0 -1
- package/dist/normalize-functions-Bqr-JkYn.js +0 -70
- package/dist/normalize-functions-Bqr-JkYn.js.map +0 -1
- package/dist/portable-text-CuI022GH.js +0 -330
- package/dist/portable-text-CuI022GH.js.map +0 -1
- package/dist/preview-price-_4sxkXQs.js +0 -20
- package/dist/preview-price-_4sxkXQs.js.map +0 -1
- package/dist/prices-eO1YBciD.d.ts +0 -20
- package/dist/prices-eO1YBciD.d.ts.map +0 -1
- package/dist/product-C3HQUIgX.js +0 -47
- package/dist/product-COu5D1mS.js +0 -90
- package/dist/regions-r1AvxfT8.js +0 -34
- package/dist/regions-r1AvxfT8.js.map +0 -1
- package/dist/search-D7Gw7jAk.js +0 -21
- package/dist/search-D7Gw7jAk.js.map +0 -1
- package/dist/search-modal-DaXadYWM.js +0 -137
- package/dist/search-modal-DaXadYWM.js.map +0 -1
- package/dist/side-menu-B6IjTd5M.js +0 -97
- package/dist/side-menu-B6IjTd5M.js.map +0 -1
- package/dist/thumbnail-C0TU3rh-.js +0 -44
- package/dist/thumbnail-C0TU3rh-.js.map +0 -1
- package/dist/use-apollo-BxAFd1Y5.js +0 -11
- package/dist/use-apollo-BxAFd1Y5.js.map +0 -1
- package/dist/use-search-VX-u8o1D.js +0 -67
- package/dist/use-search-VX-u8o1D.js.map +0 -1
- package/dist/use-toggle-state-DI4Gwlfj.d.ts +0 -23
- package/dist/use-toggle-state-DI4Gwlfj.d.ts.map +0 -1
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
|
-
import "
|
|
4
|
-
import "
|
|
5
|
-
import "../../collections-DMv3UYgC.js";
|
|
6
|
-
import { t as listCollections } from "../../collections-BgyvhW2p.js";
|
|
3
|
+
import { graphqlFetch } from "../gql/apollo-client.js";
|
|
4
|
+
import { GET_COLLECTIONS_QUERY } from "../gql/queries/collections.js";
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
//#region src/lib/data/collections.ts
|
|
7
|
+
const listCollections = async (queryParams = {}) => {
|
|
8
|
+
try {
|
|
9
|
+
return { collections: (await graphqlFetch({
|
|
10
|
+
query: GET_COLLECTIONS_QUERY,
|
|
11
|
+
variables: {
|
|
12
|
+
limit: parseInt(queryParams.limit || "100"),
|
|
13
|
+
offset: parseInt(queryParams.offset || "0")
|
|
14
|
+
}
|
|
15
|
+
}))?.collections };
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.error("Error fetching collections from BFF:", error);
|
|
18
|
+
return { collections: [] };
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { listCollections };
|
|
24
|
+
//# sourceMappingURL=collections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.js","names":[],"sources":["../../../src/lib/data/collections.ts"],"sourcesContent":["'use server';\n\nimport { graphqlFetch } from '@/lib/gql/apollo-client';\nimport { GET_COLLECTIONS_QUERY } from '@/lib/gql/queries/collections';\nimport {\n GetCollectionsQuery,\n GetCollectionsQueryVariables,\n} from '@/types/graphql';\n\nexport const listCollections = async (\n queryParams: Record<string, string> = {}\n) => {\n try {\n const limit = parseInt(queryParams.limit || '100');\n const offset = parseInt(queryParams.offset || '0');\n\n const data = await graphqlFetch<\n GetCollectionsQuery,\n GetCollectionsQueryVariables\n >({\n query: GET_COLLECTIONS_QUERY,\n variables: { limit, offset },\n });\n\n return {\n collections: data?.collections,\n };\n } catch (error) {\n console.error('Error fetching collections from BFF:', error);\n return { collections: [] };\n }\n};\n"],"mappings":";;;;;;AASA,MAAa,kBAAkB,OAC7B,cAAsC,EAAE,KACrC;AACH,KAAI;AAYF,SAAO,EACL,cATW,MAAM,aAGjB;GACA,OAAO;GACP,WAAW;IAAE,OARD,SAAS,YAAY,SAAS,MAAM;IAQ5B,QAPP,SAAS,YAAY,UAAU,IAAI;IAOpB;GAC7B,CAAC,GAGmB,aACpB;UACM,OAAO;AACd,UAAQ,MAAM,wCAAwC,MAAM;AAC5D,SAAO,EAAE,aAAa,EAAE,EAAE"}
|
|
@@ -9,7 +9,8 @@ declare const getCacheOptions: (tag: string) => Promise<{
|
|
|
9
9
|
tags: string[];
|
|
10
10
|
} | {}>;
|
|
11
11
|
declare const getCartId: () => Promise<string | undefined>;
|
|
12
|
+
declare const setCartId: (cartId: string) => Promise<void>;
|
|
12
13
|
declare const removeCartId: () => Promise<void>;
|
|
13
14
|
//#endregion
|
|
14
|
-
export { getAuthHeaders, getCacheOptions, getCacheTag, getCartId, removeCartId };
|
|
15
|
+
export { getAuthHeaders, getCacheOptions, getCacheTag, getCartId, removeCartId, setCartId };
|
|
15
16
|
//# sourceMappingURL=cookies.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.d.ts","names":[],"sources":["../../../src/lib/data/cookies.ts"],"sourcesContent":[],"mappings":";;;cAIa,sBAA2B;;AAAxC,CAAA,GAAa,CAAA,CAAA,CAAA;AAiBA,cAAA,WAAmC,EAAA,CAAA,GAAA,EAAO,MAAA,EAAA,GAAP,OAAO,CAAA,MAAA,CAAA;AAe1C,cAAA,eAEV,EAAA,CAAA,GAAA,EAAO,MAAA,EAAA,GAAP,OAAO,CAAA;EAcG,IAAA,EAAA,MAGZ,EAAA;AAED,CAAA,GAAa,CAAA,CAAA,CAAA;
|
|
1
|
+
{"version":3,"file":"cookies.d.ts","names":[],"sources":["../../../src/lib/data/cookies.ts"],"sourcesContent":[],"mappings":";;;cAIa,sBAA2B;;AAAxC,CAAA,GAAa,CAAA,CAAA,CAAA;AAiBA,cAAA,WAAmC,EAAA,CAAA,GAAA,EAAO,MAAA,EAAA,GAAP,OAAO,CAAA,MAAA,CAAA;AAe1C,cAAA,eAEV,EAAA,CAAA,GAAA,EAAO,MAAA,EAAA,GAAP,OAAO,CAAA;EAcG,IAAA,EAAA,MAGZ,EAAA;AAED,CAAA,GAAa,CAAA,CAAA,CAAA;AAUA,cAfA,SAoBZ,EALwB,GAAA,GAfH,OAeG,CAAA,MAAA,GAAA,SAAA,CAAA;cAVZ,+BAAiC;cAUjC,oBAAY"}
|
package/dist/lib/data/cookies.js
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cookies } from "next/headers";
|
|
2
|
+
import "server-only";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
//#region src/lib/data/cookies.ts
|
|
5
|
+
const getAuthHeaders = async () => {
|
|
6
|
+
try {
|
|
7
|
+
const token = (await cookies()).get("_medusa_jwt")?.value;
|
|
8
|
+
if (!token) return {};
|
|
9
|
+
return { authorization: `Bearer ${token}` };
|
|
10
|
+
} catch {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const getCacheTag = async (tag) => {
|
|
15
|
+
try {
|
|
16
|
+
const cacheId = (await cookies()).get("_medusa_cache_id")?.value;
|
|
17
|
+
if (!cacheId) return "";
|
|
18
|
+
return `${tag}-${cacheId}`;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const getCacheOptions = async (tag) => {
|
|
24
|
+
if (typeof window !== "undefined") return {};
|
|
25
|
+
const cacheTag = await getCacheTag(tag);
|
|
26
|
+
if (!cacheTag) return {};
|
|
27
|
+
return { tags: [`${cacheTag}`] };
|
|
28
|
+
};
|
|
29
|
+
const getCartId = async () => {
|
|
30
|
+
return (await cookies()).get("_medusa_cart_id")?.value;
|
|
31
|
+
};
|
|
32
|
+
const setCartId = async (cartId) => {
|
|
33
|
+
(await cookies()).set("_medusa_cart_id", cartId, {
|
|
34
|
+
maxAge: 3600 * 24 * 7,
|
|
35
|
+
httpOnly: true,
|
|
36
|
+
sameSite: "strict",
|
|
37
|
+
secure: false
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const removeCartId = async () => {
|
|
41
|
+
(await cookies()).set("_medusa_cart_id", "", { maxAge: -1 });
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { getAuthHeaders, getCacheOptions, getCacheTag, getCartId, removeCartId, setCartId };
|
|
46
|
+
//# sourceMappingURL=cookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookies.js","names":["nextCookies"],"sources":["../../../src/lib/data/cookies.ts"],"sourcesContent":["import { cookies as nextCookies } from 'next/headers';\n\nimport 'server-only';\n\nexport const getAuthHeaders = async (): Promise<\n { authorization: string } | {}\n> => {\n try {\n const cookies = await nextCookies();\n const token = cookies.get('_medusa_jwt')?.value;\n\n if (!token) {\n return {};\n }\n\n return { authorization: `Bearer ${token}` };\n } catch {\n return {};\n }\n};\n\nexport const getCacheTag = async (tag: string): Promise<string> => {\n try {\n const cookies = await nextCookies();\n const cacheId = cookies.get('_medusa_cache_id')?.value;\n\n if (!cacheId) {\n return '';\n }\n\n return `${tag}-${cacheId}`;\n } catch (error) {\n return '';\n }\n};\n\nexport const getCacheOptions = async (\n tag: string\n): Promise<{ tags: string[] } | {}> => {\n if (typeof window !== 'undefined') {\n return {};\n }\n\n const cacheTag = await getCacheTag(tag);\n\n if (!cacheTag) {\n return {};\n }\n\n return { tags: [`${cacheTag}`] };\n};\n\nexport const getCartId = async () => {\n const cookies = await nextCookies();\n return cookies.get('_medusa_cart_id')?.value;\n};\n\nexport const setCartId = async (cartId: string) => {\n const cookies = await nextCookies();\n cookies.set('_medusa_cart_id', cartId, {\n maxAge: 60 * 60 * 24 * 7,\n httpOnly: true,\n sameSite: 'strict',\n secure: process.env.NODE_ENV === 'production',\n });\n};\n\nexport const removeCartId = async () => {\n const cookies = await nextCookies();\n cookies.set('_medusa_cart_id', '', {\n maxAge: -1,\n });\n};\n"],"mappings":";;;;AAIA,MAAa,iBAAiB,YAEzB;AACH,KAAI;EAEF,MAAM,SADU,MAAMA,SAAa,EACb,IAAI,cAAc,EAAE;AAE1C,MAAI,CAAC,MACH,QAAO,EAAE;AAGX,SAAO,EAAE,eAAe,UAAU,SAAS;SACrC;AACN,SAAO,EAAE;;;AAIb,MAAa,cAAc,OAAO,QAAiC;AACjE,KAAI;EAEF,MAAM,WADU,MAAMA,SAAa,EACX,IAAI,mBAAmB,EAAE;AAEjD,MAAI,CAAC,QACH,QAAO;AAGT,SAAO,GAAG,IAAI,GAAG;UACV,OAAO;AACd,SAAO;;;AAIX,MAAa,kBAAkB,OAC7B,QACqC;AACrC,KAAI,OAAO,WAAW,YACpB,QAAO,EAAE;CAGX,MAAM,WAAW,MAAM,YAAY,IAAI;AAEvC,KAAI,CAAC,SACH,QAAO,EAAE;AAGX,QAAO,EAAE,MAAM,CAAC,GAAG,WAAW,EAAE;;AAGlC,MAAa,YAAY,YAAY;AAEnC,SADgB,MAAMA,SAAa,EACpB,IAAI,kBAAkB,EAAE;;AAGzC,MAAa,YAAY,OAAO,WAAmB;AAEjD,EADgB,MAAMA,SAAa,EAC3B,IAAI,mBAAmB,QAAQ;EACrC,QAAQ,OAAU,KAAK;EACvB,UAAU;EACV,UAAU;EACV,QAAQ;EACT,CAAC;;AAGJ,MAAa,eAAe,YAAY;AAEtC,EADgB,MAAMA,SAAa,EAC3B,IAAI,mBAAmB,IAAI,EACjC,QAAQ,IACT,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Customer, TransferCartMutation } from "../../types/graphql.js";
|
|
2
2
|
|
|
3
3
|
//#region src/lib/data/customer.d.ts
|
|
4
4
|
declare const transferCart: () => Promise<TransferCartMutation["transferCart"] | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customer.d.ts","names":[],"sources":["../../../src/lib/data/customer.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"customer.d.ts","names":[],"sources":["../../../src/lib/data/customer.ts"],"sourcesContent":[],"mappings":";;;cAuBa,oBAAyB,QACpC;cAgCW,wBAA6B,QAAQ"}
|
|
@@ -1,10 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
import "../../product-COu5D1mS.js";
|
|
3
|
-
import "../../cart-BNoIGQmw.js";
|
|
4
|
-
import "../../cart-IHaLnQC4.js";
|
|
5
|
-
import "../../cookies-lksVIe4_.js";
|
|
6
|
-
import "../../customer-CgN4zI00.js";
|
|
7
|
-
import "../../customer-DIJz6m7L.js";
|
|
8
|
-
import { n as transferCart, t as retrieveCustomer } from "../../customer-ClewjBBr.js";
|
|
1
|
+
'use server';
|
|
9
2
|
|
|
10
|
-
|
|
3
|
+
import { createServerApolloClient, graphqlFetch, graphqlMutation } from "../gql/apollo-client.js";
|
|
4
|
+
import { TRANSFER_CART_MUTATION } from "../gql/mutations/cart.js";
|
|
5
|
+
import { medusaError } from "../utils/medusa-error.js";
|
|
6
|
+
import { getCacheTag, getCartId } from "./cookies.js";
|
|
7
|
+
import { GET_CUSTOMER_QUERY } from "../gql/queries/customer.js";
|
|
8
|
+
import { revalidateTag } from "next/cache";
|
|
9
|
+
import { cookies } from "next/headers";
|
|
10
|
+
|
|
11
|
+
//#region src/lib/data/customer.ts
|
|
12
|
+
const transferCart = async () => {
|
|
13
|
+
const cartId = await getCartId();
|
|
14
|
+
if (!cartId) return null;
|
|
15
|
+
try {
|
|
16
|
+
const cart = (await graphqlMutation({
|
|
17
|
+
mutation: TRANSFER_CART_MUTATION,
|
|
18
|
+
variables: { cartId }
|
|
19
|
+
}))?.transferCart ?? null;
|
|
20
|
+
if (cart) revalidateTag(await getCacheTag("carts"));
|
|
21
|
+
return cart;
|
|
22
|
+
} catch (err) {
|
|
23
|
+
medusaError(err);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const retrieveCustomer = async () => {
|
|
27
|
+
const apolloClient = createServerApolloClient((await cookies()).toString());
|
|
28
|
+
try {
|
|
29
|
+
return await graphqlFetch({
|
|
30
|
+
query: GET_CUSTOMER_QUERY,
|
|
31
|
+
fetchPolicy: "network-only"
|
|
32
|
+
}, apolloClient).then((response) => response?.me ?? null);
|
|
33
|
+
} catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { retrieveCustomer, transferCart };
|
|
40
|
+
//# sourceMappingURL=customer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer.js","names":[],"sources":["../../../src/lib/data/customer.ts"],"sourcesContent":["'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport { cookies } from 'next/headers';\n\nimport {\n Customer,\n GetCustomerQuery,\n GetCustomerQueryVariables,\n TransferCartMutation,\n TransferCartMutationVariables,\n} from '@/types/graphql';\n\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 { getCacheTag, getCartId } from './cookies';\n\nexport const transferCart = async (): Promise<\n TransferCartMutation['transferCart'] | null\n> => {\n const cartId = await getCartId();\n\n if (!cartId) {\n return null;\n }\n\n try {\n const result = await graphqlMutation<\n TransferCartMutation,\n TransferCartMutationVariables\n >({\n mutation: TRANSFER_CART_MUTATION,\n variables: {\n cartId,\n },\n });\n\n const cart = result?.transferCart ?? null;\n\n if (cart) {\n const cartCacheTag = await getCacheTag('carts');\n revalidateTag(cartCacheTag);\n }\n\n return cart;\n } catch (err) {\n medusaError(err);\n }\n};\n\nexport const retrieveCustomer = async (): Promise<Customer | null> => {\n const cookieHeader = (await cookies()).toString();\n const apolloClient = createServerApolloClient(cookieHeader);\n\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\n return customer;\n } catch {\n return null;\n }\n};\n"],"mappings":";;;;;;;;;;;AAuBA,MAAa,eAAe,YAEvB;CACH,MAAM,SAAS,MAAM,WAAW;AAEhC,KAAI,CAAC,OACH,QAAO;AAGT,KAAI;EAWF,MAAM,QAVS,MAAM,gBAGnB;GACA,UAAU;GACV,WAAW,EACT,QACD;GACF,CAAC,GAEmB,gBAAgB;AAErC,MAAI,KAEF,eADqB,MAAM,YAAY,QAAQ,CACpB;AAG7B,SAAO;UACA,KAAK;AACZ,cAAY,IAAI;;;AAIpB,MAAa,mBAAmB,YAAsC;CAEpE,MAAM,eAAe,0BADC,MAAM,SAAS,EAAE,UAAU,CACU;AAE3D,KAAI;AAYF,SAXiB,MAAM,aAIrB;GACE,OAAO;GACP,aAAa;GACd,EACD,aACD,CAAC,MAAM,aAAa,UAAU,MAAM,KAAK;SAGpC;AACN,SAAO"}
|
package/dist/lib/data/footer.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
3
|
-
import { t as getFooterContent } from "../../footer-BvNV-R9D.js";
|
|
1
|
+
import { graphqlFetch } from "../gql/apollo-client.js";
|
|
2
|
+
import { GET_FOOTER_QUERY } from "../gql/queries/footer.js";
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
//#region src/lib/data/footer.ts
|
|
5
|
+
const getFooterContent = async () => {
|
|
6
|
+
try {
|
|
7
|
+
return (await graphqlFetch({ query: GET_FOOTER_QUERY }))?.footer || null;
|
|
8
|
+
} catch (error) {
|
|
9
|
+
console.error("Error fetching footer content:", error);
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getFooterContent };
|
|
16
|
+
//# sourceMappingURL=footer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"footer.js","names":[],"sources":["../../../src/lib/data/footer.ts"],"sourcesContent":["import { graphqlFetch } from '@/lib/gql/apollo-client';\nimport { GET_FOOTER_QUERY } from '@/lib/gql/queries/footer';\nimport { GetFooterQuery, GetFooterQueryVariables } from '@/types/graphql';\n\nexport const getFooterContent = async () => {\n try {\n const data = await graphqlFetch<GetFooterQuery, GetFooterQueryVariables>({\n query: GET_FOOTER_QUERY,\n });\n return data?.footer || null;\n } catch (error) {\n console.error('Error fetching footer content:', error);\n return null;\n }\n};\n"],"mappings":";;;;AAIA,MAAa,mBAAmB,YAAY;AAC1C,KAAI;AAIF,UAHa,MAAM,aAAsD,EACvE,OAAO,kBACR,CAAC,GACW,UAAU;UAChB,OAAO;AACd,UAAQ,MAAM,kCAAkC,MAAM;AACtD,SAAO"}
|
package/dist/lib/data/orders.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { sdk } from "../config/medusa.js";
|
|
2
|
+
import { medusaError } from "../utils/medusa-error.js";
|
|
3
|
+
import { getAuthHeaders, getCacheOptions } from "./cookies.js";
|
|
4
|
+
import { normalizeOrder } from "../utils/normalize-functions.js";
|
|
5
5
|
|
|
6
6
|
//#region src/lib/data/orders.ts
|
|
7
7
|
const retrieveOrder = async (id) => {
|
package/dist/lib/data/regions.js
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
3
|
-
import {
|
|
1
|
+
import { sdk } from "../config/medusa.js";
|
|
2
|
+
import { medusaError } from "../utils/medusa-error.js";
|
|
3
|
+
import { getCacheOptions } from "./cookies.js";
|
|
4
|
+
import { normalizeRegion } from "../utils/normalize-functions.js";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
//#region src/lib/data/regions.ts
|
|
7
|
+
const regionMap = /* @__PURE__ */ new Map();
|
|
8
|
+
const listRegions = async () => {
|
|
9
|
+
const next = { ...await getCacheOptions("regions") };
|
|
10
|
+
return sdk.client.fetch(`/store/regions`, {
|
|
11
|
+
method: "GET",
|
|
12
|
+
next,
|
|
13
|
+
cache: "force-cache"
|
|
14
|
+
}).then(({ regions }) => regions.map(normalizeRegion)).catch(medusaError);
|
|
15
|
+
};
|
|
16
|
+
const getRegion = async (countryCode) => {
|
|
17
|
+
try {
|
|
18
|
+
if (regionMap.has(countryCode)) return regionMap.get(countryCode) ?? null;
|
|
19
|
+
const regions = await listRegions();
|
|
20
|
+
if (!regions) return null;
|
|
21
|
+
regions.forEach((region) => {
|
|
22
|
+
region.countries?.forEach((c) => {
|
|
23
|
+
regionMap.set(c?.iso2 ?? "", region);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
return countryCode ? regionMap.get(countryCode) ?? null : regionMap.get("us") ?? null;
|
|
27
|
+
} catch (e) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { getRegion, listRegions };
|
|
34
|
+
//# sourceMappingURL=regions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regions.js","names":["e: any"],"sources":["../../../src/lib/data/regions.ts"],"sourcesContent":["import { HttpTypes } from '@medusajs/types';\n\nimport { sdk } from '@/lib/config/medusa';\nimport { medusaError } from '@/lib/utils/medusa-error';\nimport { normalizeRegion } from '@/lib/utils/normalize-functions';\nimport { Region } from '@/types/graphql';\n\nimport { getCacheOptions } from './cookies';\n\nconst regionMap = new Map<string, Region>();\n\nexport const listRegions = async () => {\n const next = {\n ...(await getCacheOptions('regions')),\n };\n\n return sdk.client\n .fetch<{ regions: HttpTypes.StoreRegion[] }>(`/store/regions`, {\n method: 'GET',\n next,\n cache: 'force-cache',\n })\n .then(({ regions }) => regions.map(normalizeRegion))\n .catch(medusaError);\n};\n\nexport const getRegion = async (\n countryCode: string\n): Promise<Region | null> => {\n try {\n if (regionMap.has(countryCode)) {\n return regionMap.get(countryCode) ?? null;\n }\n\n const regions = await listRegions();\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":";;;;;;AASA,MAAM,4BAAY,IAAI,KAAqB;AAE3C,MAAa,cAAc,YAAY;CACrC,MAAM,OAAO,EACX,GAAI,MAAM,gBAAgB,UAAU,EACrC;AAED,QAAO,IAAI,OACR,MAA4C,kBAAkB;EAC7D,QAAQ;EACR;EACA,OAAO;EACR,CAAC,CACD,MAAM,EAAE,cAAc,QAAQ,IAAI,gBAAgB,CAAC,CACnD,MAAM,YAAY;;AAGvB,MAAa,YAAY,OACvB,gBAC2B;AAC3B,KAAI;AACF,MAAI,UAAU,IAAI,YAAY,CAC5B,QAAO,UAAU,IAAI,YAAY,IAAI;EAGvC,MAAM,UAAU,MAAM,aAAa;AAEnC,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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProductHit, SearchSuggestionsQueryVariables } from "../../types/graphql.js";
|
|
2
2
|
|
|
3
3
|
//#region src/lib/data/search.d.ts
|
|
4
4
|
declare const searchSuggestions: (params: SearchSuggestionsQueryVariables) => Promise<{
|
package/dist/lib/data/search.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
|
-
import "
|
|
4
|
-
import "
|
|
5
|
-
import "../../product-C3HQUIgX.js";
|
|
6
|
-
import { t as searchSuggestions } from "../../search-D7Gw7jAk.js";
|
|
3
|
+
import { graphqlFetch } from "../gql/apollo-client.js";
|
|
4
|
+
import { SEARCH_SUGGESTIONS_QUERY } from "../gql/queries/product.js";
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
//#region src/lib/data/search.ts
|
|
7
|
+
const searchSuggestions = async (params) => {
|
|
8
|
+
try {
|
|
9
|
+
const response = await graphqlFetch({
|
|
10
|
+
query: SEARCH_SUGGESTIONS_QUERY,
|
|
11
|
+
variables: { query: params.query }
|
|
12
|
+
});
|
|
13
|
+
if (!response?.searchProducts) throw new Error("No search results returned");
|
|
14
|
+
return response.searchProducts;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.error("Search error:", error);
|
|
17
|
+
throw new Error(`Failed to search suggestions: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { searchSuggestions };
|
|
23
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","names":[],"sources":["../../../src/lib/data/search.ts"],"sourcesContent":["'use server';\n\nimport { graphqlFetch } from '@/lib/gql/apollo-client';\nimport { SEARCH_SUGGESTIONS_QUERY } from '@/lib/gql/queries/product';\nimport {\n ProductHit,\n SearchSuggestionsQuery,\n SearchSuggestionsQueryVariables,\n} from '@/types/graphql';\n\nexport const searchSuggestions = async (\n params: SearchSuggestionsQueryVariables\n): Promise<{ items: ProductHit[] }> => {\n try {\n const response = await graphqlFetch<\n SearchSuggestionsQuery,\n SearchSuggestionsQueryVariables\n >({\n query: SEARCH_SUGGESTIONS_QUERY,\n variables: {\n query: params.query,\n },\n });\n\n if (!response?.searchProducts) {\n throw new Error('No search results returned');\n }\n\n return response.searchProducts;\n } catch (error) {\n console.error('Search error:', error);\n throw new Error(\n `Failed to search suggestions: ${error instanceof Error ? error.message : 'Unknown error'}`\n );\n }\n};\n"],"mappings":";;;;;;AAUA,MAAa,oBAAoB,OAC/B,WACqC;AACrC,KAAI;EACF,MAAM,WAAW,MAAM,aAGrB;GACA,OAAO;GACP,WAAW,EACT,OAAO,OAAO,OACf;GACF,CAAC;AAEF,MAAI,CAAC,UAAU,eACb,OAAM,IAAI,MAAM,6BAA6B;AAG/C,SAAO,SAAS;UACT,OAAO;AACd,UAAQ,MAAM,iBAAiB,MAAM;AACrC,QAAM,IAAI,MACR,iCAAiC,iBAAiB,QAAQ,MAAM,UAAU,kBAC3E"}
|
|
@@ -1,3 +1,67 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getBaseURL } from "../utils/env.js";
|
|
2
|
+
import { ApolloClient, ApolloLink, HttpLink, InMemoryCache } from "@apollo/client";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
//#region src/lib/gql/apollo-client.ts
|
|
5
|
+
const isServer = () => typeof window === "undefined";
|
|
6
|
+
const httpLink = new HttpLink({
|
|
7
|
+
uri: isServer() ? `${getBaseURL()}/api/graphql` : "/api/graphql",
|
|
8
|
+
credentials: "include"
|
|
9
|
+
});
|
|
10
|
+
const apolloClient = new ApolloClient({
|
|
11
|
+
link: httpLink,
|
|
12
|
+
cache: new InMemoryCache({}),
|
|
13
|
+
defaultOptions: { watchQuery: { notifyOnNetworkStatusChange: true } }
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* When requests are sent from the server, cookies need to be manually attached.
|
|
17
|
+
*
|
|
18
|
+
* @param cookieHeader Cookies string to forward
|
|
19
|
+
* @returns Server-side Apollo client
|
|
20
|
+
*/
|
|
21
|
+
function createServerApolloClient(cookieHeader) {
|
|
22
|
+
return new ApolloClient({
|
|
23
|
+
link: new ApolloLink((operation, forward) => {
|
|
24
|
+
if (cookieHeader) operation.setContext(({ headers = {} }) => ({ headers: {
|
|
25
|
+
...headers,
|
|
26
|
+
Cookie: cookieHeader
|
|
27
|
+
} }));
|
|
28
|
+
return forward(operation);
|
|
29
|
+
}).concat(httpLink),
|
|
30
|
+
cache: new InMemoryCache({}),
|
|
31
|
+
defaultOptions: { watchQuery: { notifyOnNetworkStatusChange: true } }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function initializeApollo(req = null) {
|
|
35
|
+
if (isServer()) {
|
|
36
|
+
const cookieHeader = req?.headers.cookie;
|
|
37
|
+
return createServerApolloClient(cookieHeader);
|
|
38
|
+
}
|
|
39
|
+
return apolloClient;
|
|
40
|
+
}
|
|
41
|
+
async function graphqlFetch(options, apolloClientOverride) {
|
|
42
|
+
try {
|
|
43
|
+
const { data } = await (apolloClientOverride || apolloClient).query({
|
|
44
|
+
...options,
|
|
45
|
+
fetchPolicy: "network-only"
|
|
46
|
+
});
|
|
47
|
+
return data;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw new Error(error.message || "GraphQL error");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function graphqlMutation(options, apolloClientOverride) {
|
|
53
|
+
try {
|
|
54
|
+
const { data } = await (apolloClientOverride || apolloClient).mutate({
|
|
55
|
+
...options,
|
|
56
|
+
fetchPolicy: "network-only"
|
|
57
|
+
});
|
|
58
|
+
return data;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
throw new Error(error.message || "GraphQL error");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
var apollo_client_default = apolloClient;
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { createServerApolloClient, apollo_client_default as default, graphqlFetch, graphqlMutation, initializeApollo };
|
|
67
|
+
//# sourceMappingURL=apollo-client.js.map
|
|
@@ -0,0 +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 { 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":";;;;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;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,14 +1,14 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _apollo_client2 from "@apollo/client";
|
|
2
2
|
|
|
3
3
|
//#region src/lib/gql/fragments/cart.d.ts
|
|
4
|
-
declare const LINE_ITEM_FRAGMENT:
|
|
5
|
-
declare const COUNTRY_FRAGMENT:
|
|
6
|
-
declare const REGION_FRAGMENT:
|
|
7
|
-
declare const SHIPPING_METHODS_FRAGMENT:
|
|
8
|
-
declare const PAYMENT_COLLECTION_FRAGMENT:
|
|
9
|
-
declare const ADDRESS_FRAGMENT:
|
|
10
|
-
declare const PROMOTION_FRAGMENT:
|
|
11
|
-
declare const CART_FRAGMENT:
|
|
4
|
+
declare const LINE_ITEM_FRAGMENT: _apollo_client2.DocumentNode;
|
|
5
|
+
declare const COUNTRY_FRAGMENT: _apollo_client2.DocumentNode;
|
|
6
|
+
declare const REGION_FRAGMENT: _apollo_client2.DocumentNode;
|
|
7
|
+
declare const SHIPPING_METHODS_FRAGMENT: _apollo_client2.DocumentNode;
|
|
8
|
+
declare const PAYMENT_COLLECTION_FRAGMENT: _apollo_client2.DocumentNode;
|
|
9
|
+
declare const ADDRESS_FRAGMENT: _apollo_client2.DocumentNode;
|
|
10
|
+
declare const PROMOTION_FRAGMENT: _apollo_client2.DocumentNode;
|
|
11
|
+
declare const CART_FRAGMENT: _apollo_client2.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,
|
|
1
|
+
{"version":3,"file":"cart.d.ts","names":[],"sources":["../../../../src/lib/gql/fragments/cart.ts"],"sourcesContent":[],"mappings":";;;cAIa,oBAiBZ,eAAA,CAjB8B;cAmBlB,kBAOZ,eAAA,CAP4B;cAShB,iBAWZ,eAAA,CAX2B;AA5Bf,cAyCA,yBAxBZ,EAkCA,eAAA,CAVqC,YAxBrC;AAEY,cAkCA,2BA3BZ,EA6CA,eAAA,CAlBuC,YA3BvC;AAEY,cA6CA,gBAlCZ,EA4CA,eAAA,CAV4B,YAlC5B;AAEY,cA4CA,kBAlCZ,EA4CA,eAAA,CAV8B,YAlC9B;AAEY,cA4CA,aA1BZ,EAqEA,eAAA,CA3CyB,YA5Cc"}
|
|
@@ -1,4 +1,142 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import {
|
|
1
|
+
import { PRODUCT_VARIANT_FRAGMENT } from "./product.js";
|
|
2
|
+
import { gql } from "@apollo/client";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
//#region src/lib/gql/fragments/cart.ts
|
|
5
|
+
const LINE_ITEM_FRAGMENT = gql`
|
|
6
|
+
fragment CartItemFields on LineItem {
|
|
7
|
+
id
|
|
8
|
+
title
|
|
9
|
+
quantity
|
|
10
|
+
unitPrice
|
|
11
|
+
createdAt
|
|
12
|
+
thumbnail
|
|
13
|
+
productHandle
|
|
14
|
+
productTitle
|
|
15
|
+
total
|
|
16
|
+
originalTotal
|
|
17
|
+
variant {
|
|
18
|
+
...ProductVariant
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
${PRODUCT_VARIANT_FRAGMENT}
|
|
22
|
+
`;
|
|
23
|
+
const COUNTRY_FRAGMENT = gql`
|
|
24
|
+
fragment CountryFields on Country {
|
|
25
|
+
id
|
|
26
|
+
iso2
|
|
27
|
+
name
|
|
28
|
+
displayName
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
const REGION_FRAGMENT = gql`
|
|
32
|
+
fragment RegionFields on Region {
|
|
33
|
+
id
|
|
34
|
+
name
|
|
35
|
+
currencyCode
|
|
36
|
+
createdAt
|
|
37
|
+
countries {
|
|
38
|
+
...CountryFields
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
${COUNTRY_FRAGMENT}
|
|
42
|
+
`;
|
|
43
|
+
const SHIPPING_METHODS_FRAGMENT = gql`
|
|
44
|
+
fragment ShippingMethodFields on ShippingMethod {
|
|
45
|
+
id
|
|
46
|
+
cartId
|
|
47
|
+
name
|
|
48
|
+
amount
|
|
49
|
+
shippingOptionId
|
|
50
|
+
createdAt
|
|
51
|
+
total
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
const PAYMENT_COLLECTION_FRAGMENT = gql`
|
|
55
|
+
fragment PaymentCollectionFields on PaymentCollection {
|
|
56
|
+
id
|
|
57
|
+
currencyCode
|
|
58
|
+
amount
|
|
59
|
+
status
|
|
60
|
+
paymentProviders {
|
|
61
|
+
id
|
|
62
|
+
}
|
|
63
|
+
paymentSessions {
|
|
64
|
+
id
|
|
65
|
+
amount
|
|
66
|
+
currencyCode
|
|
67
|
+
providerId
|
|
68
|
+
data
|
|
69
|
+
status
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
const ADDRESS_FRAGMENT = gql`
|
|
74
|
+
fragment AddressFields on Address {
|
|
75
|
+
firstName
|
|
76
|
+
lastName
|
|
77
|
+
phone
|
|
78
|
+
address1
|
|
79
|
+
city
|
|
80
|
+
countryCode
|
|
81
|
+
postalCode
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
84
|
+
const PROMOTION_FRAGMENT = gql`
|
|
85
|
+
fragment PromotionFields on Promotion {
|
|
86
|
+
id
|
|
87
|
+
code
|
|
88
|
+
applicationMethod {
|
|
89
|
+
value
|
|
90
|
+
type
|
|
91
|
+
currencyCode
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
`;
|
|
95
|
+
const CART_FRAGMENT = gql`
|
|
96
|
+
fragment CartFields on Cart {
|
|
97
|
+
id
|
|
98
|
+
customerId
|
|
99
|
+
regionId
|
|
100
|
+
email
|
|
101
|
+
total
|
|
102
|
+
subtotal
|
|
103
|
+
taxTotal
|
|
104
|
+
itemTotal
|
|
105
|
+
discountTotal
|
|
106
|
+
originalTotal
|
|
107
|
+
currencyCode
|
|
108
|
+
shippingTotal
|
|
109
|
+
giftCardTotal
|
|
110
|
+
promotions {
|
|
111
|
+
...PromotionFields
|
|
112
|
+
}
|
|
113
|
+
items {
|
|
114
|
+
...CartItemFields
|
|
115
|
+
}
|
|
116
|
+
shippingAddress {
|
|
117
|
+
...AddressFields
|
|
118
|
+
}
|
|
119
|
+
billingAddress {
|
|
120
|
+
...AddressFields
|
|
121
|
+
}
|
|
122
|
+
region {
|
|
123
|
+
...RegionFields
|
|
124
|
+
}
|
|
125
|
+
shippingMethods {
|
|
126
|
+
...ShippingMethodFields
|
|
127
|
+
}
|
|
128
|
+
paymentCollection {
|
|
129
|
+
...PaymentCollectionFields
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
${LINE_ITEM_FRAGMENT}
|
|
133
|
+
${ADDRESS_FRAGMENT}
|
|
134
|
+
${REGION_FRAGMENT}
|
|
135
|
+
${SHIPPING_METHODS_FRAGMENT}
|
|
136
|
+
${PAYMENT_COLLECTION_FRAGMENT}
|
|
137
|
+
${PROMOTION_FRAGMENT}
|
|
138
|
+
`;
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
export { ADDRESS_FRAGMENT, CART_FRAGMENT, COUNTRY_FRAGMENT, LINE_ITEM_FRAGMENT, PAYMENT_COLLECTION_FRAGMENT, PROMOTION_FRAGMENT, REGION_FRAGMENT, SHIPPING_METHODS_FRAGMENT };
|
|
142
|
+
//# sourceMappingURL=cart.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cart
|
|
1
|
+
{"version":3,"file":"cart.js","names":[],"sources":["../../../../src/lib/gql/fragments/cart.ts"],"sourcesContent":["import { gql } from '@apollo/client';\n\nimport { PRODUCT_VARIANT_FRAGMENT } from './product';\n\nexport const LINE_ITEM_FRAGMENT = gql`\n fragment CartItemFields on LineItem {\n id\n title\n quantity\n unitPrice\n createdAt\n thumbnail\n productHandle\n productTitle\n total\n originalTotal\n variant {\n ...ProductVariant\n }\n }\n ${PRODUCT_VARIANT_FRAGMENT}\n`;\n\nexport const COUNTRY_FRAGMENT = gql`\n fragment CountryFields on Country {\n id\n iso2\n name\n displayName\n }\n`;\n\nexport const REGION_FRAGMENT = gql`\n fragment RegionFields on Region {\n id\n name\n currencyCode\n createdAt\n countries {\n ...CountryFields\n }\n }\n ${COUNTRY_FRAGMENT}\n`;\n\nexport const SHIPPING_METHODS_FRAGMENT = gql`\n fragment ShippingMethodFields on ShippingMethod {\n id\n cartId\n name\n amount\n shippingOptionId\n createdAt\n total\n }\n`;\n\nexport const PAYMENT_COLLECTION_FRAGMENT = gql`\n fragment PaymentCollectionFields on PaymentCollection {\n id\n currencyCode\n amount\n status\n paymentProviders {\n id\n }\n paymentSessions {\n id\n amount\n currencyCode\n providerId\n data\n status\n }\n }\n`;\n\nexport const ADDRESS_FRAGMENT = gql`\n fragment AddressFields on Address {\n firstName\n lastName\n phone\n address1\n city\n countryCode\n postalCode\n }\n`;\n\nexport const PROMOTION_FRAGMENT = gql`\n fragment PromotionFields on Promotion {\n id\n code\n applicationMethod {\n value\n type\n currencyCode\n }\n }\n`;\n\nexport const CART_FRAGMENT = gql`\n fragment CartFields on Cart {\n id\n customerId\n regionId\n email\n total\n subtotal\n taxTotal\n itemTotal\n discountTotal\n originalTotal\n currencyCode\n shippingTotal\n giftCardTotal\n promotions {\n ...PromotionFields\n }\n items {\n ...CartItemFields\n }\n shippingAddress {\n ...AddressFields\n }\n billingAddress {\n ...AddressFields\n }\n region {\n ...RegionFields\n }\n shippingMethods {\n ...ShippingMethodFields\n }\n paymentCollection {\n ...PaymentCollectionFields\n }\n }\n ${LINE_ITEM_FRAGMENT}\n ${ADDRESS_FRAGMENT}\n ${REGION_FRAGMENT}\n ${SHIPPING_METHODS_FRAGMENT}\n ${PAYMENT_COLLECTION_FRAGMENT}\n ${PROMOTION_FRAGMENT}\n`;\n"],"mappings":";;;;AAIA,MAAa,qBAAqB,GAAG;;;;;;;;;;;;;;;;IAgBjC,yBAAyB;;AAG7B,MAAa,mBAAmB,GAAG;;;;;;;;AASnC,MAAa,kBAAkB,GAAG;;;;;;;;;;IAU9B,iBAAiB;;AAGrB,MAAa,4BAA4B,GAAG;;;;;;;;;;;AAY5C,MAAa,8BAA8B,GAAG;;;;;;;;;;;;;;;;;;;AAoB9C,MAAa,mBAAmB,GAAG;;;;;;;;;;;AAYnC,MAAa,qBAAqB,GAAG;;;;;;;;;;;AAYrC,MAAa,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAqC5B,mBAAmB;IACnB,iBAAiB;IACjB,gBAAgB;IAChB,0BAA0B;IAC1B,4BAA4B;IAC5B,mBAAmB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _apollo_client0 from "@apollo/client";
|
|
2
2
|
|
|
3
3
|
//#region src/lib/gql/fragments/customer.d.ts
|
|
4
|
-
declare const CUSTOMER_ADDRESS_FRAGMENT:
|
|
5
|
-
declare const CUSTOMER_FRAGMENT:
|
|
4
|
+
declare const CUSTOMER_ADDRESS_FRAGMENT: _apollo_client0.DocumentNode;
|
|
5
|
+
declare const CUSTOMER_FRAGMENT: _apollo_client0.DocumentNode;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { CUSTOMER_ADDRESS_FRAGMENT, CUSTOMER_FRAGMENT };
|
|
8
8
|
//# sourceMappingURL=customer.d.ts.map
|