medusa-storefront-data 1.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.
Files changed (105) hide show
  1. package/dist/config.d.ts +3 -0
  2. package/dist/config.d.ts.map +1 -0
  3. package/dist/config.js +31 -0
  4. package/dist/cookies.d.ts +23 -0
  5. package/dist/cookies.d.ts.map +1 -0
  6. package/dist/cookies.js +140 -0
  7. package/dist/server/cart.d.ts +92 -0
  8. package/dist/server/cart.d.ts.map +1 -0
  9. package/dist/server/cart.js +827 -0
  10. package/dist/server/categories.d.ts +3 -0
  11. package/dist/server/categories.d.ts.map +1 -0
  12. package/dist/server/categories.js +71 -0
  13. package/dist/server/collections.d.ts +8 -0
  14. package/dist/server/collections.d.ts.map +1 -0
  15. package/dist/server/collections.js +84 -0
  16. package/dist/server/customer-registration.d.ts +142 -0
  17. package/dist/server/customer-registration.d.ts.map +1 -0
  18. package/dist/server/customer-registration.js +295 -0
  19. package/dist/server/customer.d.ts +48 -0
  20. package/dist/server/customer.d.ts.map +1 -0
  21. package/dist/server/customer.js +462 -0
  22. package/dist/server/dynamic-config.d.ts +125 -0
  23. package/dist/server/dynamic-config.d.ts.map +1 -0
  24. package/dist/server/dynamic-config.js +263 -0
  25. package/dist/server/fulfillment.d.ts +4 -0
  26. package/dist/server/fulfillment.d.ts.map +1 -0
  27. package/dist/server/fulfillment.js +72 -0
  28. package/dist/server/guest.d.ts +109 -0
  29. package/dist/server/guest.d.ts.map +1 -0
  30. package/dist/server/guest.js +304 -0
  31. package/dist/server/index.d.ts +21 -0
  32. package/dist/server/index.d.ts.map +1 -0
  33. package/dist/server/index.js +20 -0
  34. package/dist/server/locale-actions.d.ts +14 -0
  35. package/dist/server/locale-actions.d.ts.map +1 -0
  36. package/dist/server/locale-actions.js +63 -0
  37. package/dist/server/locales.d.ts +10 -0
  38. package/dist/server/locales.d.ts.map +1 -0
  39. package/dist/server/locales.js +20 -0
  40. package/dist/server/notifications.d.ts +2 -0
  41. package/dist/server/notifications.d.ts.map +1 -0
  42. package/dist/server/notifications.js +20 -0
  43. package/dist/server/onboarding.d.ts +2 -0
  44. package/dist/server/onboarding.d.ts.map +1 -0
  45. package/dist/server/onboarding.js +8 -0
  46. package/dist/server/orders.d.ts +69 -0
  47. package/dist/server/orders.d.ts.map +1 -0
  48. package/dist/server/orders.js +371 -0
  49. package/dist/server/payment-details.d.ts +5 -0
  50. package/dist/server/payment-details.d.ts.map +1 -0
  51. package/dist/server/payment-details.js +53 -0
  52. package/dist/server/payment.d.ts +2 -0
  53. package/dist/server/payment.d.ts.map +1 -0
  54. package/dist/server/payment.js +25 -0
  55. package/dist/server/products.d.ts +58 -0
  56. package/dist/server/products.d.ts.map +1 -0
  57. package/dist/server/products.js +285 -0
  58. package/dist/server/regions.d.ts +5 -0
  59. package/dist/server/regions.d.ts.map +1 -0
  60. package/dist/server/regions.js +54 -0
  61. package/dist/server/returns.d.ts +29 -0
  62. package/dist/server/returns.d.ts.map +1 -0
  63. package/dist/server/returns.js +236 -0
  64. package/dist/server/swaps.d.ts +14 -0
  65. package/dist/server/swaps.d.ts.map +1 -0
  66. package/dist/server/swaps.js +123 -0
  67. package/dist/server/variants.d.ts +3 -0
  68. package/dist/server/variants.d.ts.map +1 -0
  69. package/dist/server/variants.js +26 -0
  70. package/dist/util/get-locale-header.d.ts +4 -0
  71. package/dist/util/get-locale-header.d.ts.map +1 -0
  72. package/dist/util/get-locale-header.js +7 -0
  73. package/dist/util/medusa-error.d.ts +2 -0
  74. package/dist/util/medusa-error.d.ts.map +1 -0
  75. package/dist/util/medusa-error.js +18 -0
  76. package/package.json +152 -0
  77. package/src/config.ts +39 -0
  78. package/src/cookies.ts +171 -0
  79. package/src/middleware.ts +2 -0
  80. package/src/server/cart.ts +1054 -0
  81. package/src/server/categories.ts +94 -0
  82. package/src/server/collections.ts +113 -0
  83. package/src/server/customer-registration.ts +349 -0
  84. package/src/server/customer.ts +581 -0
  85. package/src/server/dynamic-config.ts +403 -0
  86. package/src/server/fulfillment.ts +97 -0
  87. package/src/server/guest.ts +333 -0
  88. package/src/server/index.ts +21 -0
  89. package/src/server/locale-actions.ts +74 -0
  90. package/src/server/locales.ts +28 -0
  91. package/src/server/notifications.ts +22 -0
  92. package/src/server/onboarding.ts +9 -0
  93. package/src/server/orders.ts +467 -0
  94. package/src/server/payment-details.ts +69 -0
  95. package/src/server/payment.ts +35 -0
  96. package/src/server/products.ts +378 -0
  97. package/src/server/regions.ts +66 -0
  98. package/src/server/returns.ts +294 -0
  99. package/src/server/swaps.ts +150 -0
  100. package/src/server/variants.ts +38 -0
  101. package/src/server/wishlist.ts +64 -0
  102. package/src/services/middleware.ts +54 -0
  103. package/src/util/get-locale-header.ts +8 -0
  104. package/src/util/medusa-error.ts +19 -0
  105. package/src/util/sort-products.ts +47 -0
@@ -0,0 +1,123 @@
1
+ "use server";
2
+ import { sdk } from "../config";
3
+ import { cookies } from "next/headers";
4
+ import { getAuthHeaders } from "../cookies";
5
+ import { revalidateTag } from "next/cache";
6
+ /**
7
+ * Create an exchange (swap) request.
8
+ * Supports both authenticated customers and guest users.
9
+ */
10
+ export const createSwapRequest = async (prevState, formData) => {
11
+ const orderId = formData.get("order_id");
12
+ const returnItemsJson = formData.get("return_items");
13
+ const newItemsJson = formData.get("new_items");
14
+ const reason = formData.get("reason");
15
+ const note = formData.get("note");
16
+ if (!orderId)
17
+ return { success: false, error: "Order ID is required", swap: null };
18
+ if (!returnItemsJson)
19
+ return { success: false, error: "Items to return are required", swap: null };
20
+ if (!newItemsJson)
21
+ return { success: false, error: "New items are required", swap: null };
22
+ let returnItems = [];
23
+ let newItems = [];
24
+ try {
25
+ returnItems = JSON.parse(returnItemsJson);
26
+ newItems = JSON.parse(newItemsJson);
27
+ }
28
+ catch (e) {
29
+ return { success: false, error: "Invalid items data format", swap: null };
30
+ }
31
+ if (returnItems.length === 0) {
32
+ return { success: false, error: "At least one item must be selected for return", swap: null };
33
+ }
34
+ const headers = {
35
+ ...(await getAuthHeaders()),
36
+ };
37
+ try {
38
+ const payload = {
39
+ order_id: orderId,
40
+ return_items: returnItems,
41
+ new_items: newItems,
42
+ reason: reason || "Size exchange",
43
+ note: note || "Exchange requested from storefront",
44
+ };
45
+ const cookieStore = await cookies();
46
+ const guestToken = cookieStore.get("_medusa_guest_jwt")?.value || cookieStore.get("_medusa_guest_token")?.value;
47
+ const token = cookieStore.get("_medusa_jwt")?.value;
48
+ let swapData;
49
+ // Check if we should use the guest endpoint
50
+ if (guestToken && !token) {
51
+ const response = await sdk.client.fetch(`/store/guest-orders/${orderId}/swaps`, {
52
+ method: "POST",
53
+ body: {
54
+ return_items: payload.return_items,
55
+ new_items: payload.new_items,
56
+ reason: payload.reason,
57
+ note: payload.note,
58
+ },
59
+ headers: {
60
+ ...headers,
61
+ "Authorization": `Bearer ${guestToken}`
62
+ },
63
+ cache: "no-store",
64
+ });
65
+ swapData = response.swap || response;
66
+ }
67
+ else {
68
+ const response = await sdk.client.fetch(`/store/swaps`, {
69
+ method: "POST",
70
+ body: payload,
71
+ headers,
72
+ cache: "no-store",
73
+ });
74
+ swapData = response.swap || response;
75
+ }
76
+ revalidateTag("orders");
77
+ return { success: true, error: null, swap: swapData };
78
+ }
79
+ catch (error) {
80
+ // Extract error message from response if possible
81
+ let errorMsg = "Failed to create exchange request";
82
+ if (error.response?.data?.message) {
83
+ errorMsg = error.response.data.message;
84
+ }
85
+ else if (error.message) {
86
+ errorMsg = error.message;
87
+ }
88
+ return { success: false, error: errorMsg, swap: null };
89
+ }
90
+ };
91
+ /**
92
+ * List swaps for an order or customer
93
+ */
94
+ export const listSwaps = async (orderId) => {
95
+ const headers = {
96
+ ...(await getAuthHeaders()),
97
+ };
98
+ // Authenticated flow
99
+ if (headers.authorization) {
100
+ return sdk.client.fetch(`/store/swaps`, {
101
+ method: "GET",
102
+ query: orderId ? { order_id: orderId } : {},
103
+ headers,
104
+ cache: "no-store",
105
+ });
106
+ }
107
+ // Guest flow
108
+ if (orderId) {
109
+ const cookieStore = await cookies();
110
+ const guestToken = cookieStore.get("_medusa_guest_jwt")?.value || cookieStore.get("_medusa_guest_token")?.value;
111
+ if (guestToken) {
112
+ return sdk.client.fetch(`/store/guest-orders/${orderId}/swaps`, {
113
+ method: "GET",
114
+ headers: {
115
+ ...headers,
116
+ "Authorization": `Bearer ${guestToken}`
117
+ },
118
+ cache: "no-store",
119
+ });
120
+ }
121
+ }
122
+ return { swaps: [], count: 0 };
123
+ };
@@ -0,0 +1,3 @@
1
+ import { HttpTypes } from "@medusajs/types";
2
+ export declare const retrieveVariant: (variant_id: string) => Promise<HttpTypes.StoreProductVariant | null>;
3
+ //# sourceMappingURL=variants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../src/server/variants.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAI3C,eAAO,MAAM,eAAe,GAC1B,YAAY,MAAM,KACjB,OAAO,CAAC,SAAS,CAAC,mBAAmB,GAAG,IAAI,CA4B9C,CAAA"}
@@ -0,0 +1,26 @@
1
+ "use server";
2
+ import { sdk } from "../config";
3
+ import { getAuthHeaders, getCacheOptions } from "../cookies";
4
+ export const retrieveVariant = async (variant_id) => {
5
+ const authHeaders = await getAuthHeaders();
6
+ if (!authHeaders)
7
+ return null;
8
+ const headers = {
9
+ ...authHeaders,
10
+ };
11
+ const next = {
12
+ ...(await getCacheOptions("variants")),
13
+ };
14
+ return await sdk.client
15
+ .fetch(`/store/product-variants/${variant_id}`, {
16
+ method: "GET",
17
+ query: {
18
+ fields: "*images",
19
+ },
20
+ headers,
21
+ next,
22
+ cache: "force-cache",
23
+ })
24
+ .then(({ variant }) => variant)
25
+ .catch(() => null);
26
+ };
@@ -0,0 +1,4 @@
1
+ export declare function getLocaleHeader(): Promise<{
2
+ readonly "x-medusa-locale": string;
3
+ }>;
4
+ //# sourceMappingURL=get-locale-header.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-locale-header.d.ts","sourceRoot":"","sources":["../../src/util/get-locale-header.ts"],"names":[],"mappings":"AAEA,wBAAsB,eAAe;;GAKpC"}
@@ -0,0 +1,7 @@
1
+ import { getLocale } from "../server/locale-actions";
2
+ export async function getLocaleHeader() {
3
+ const locale = await getLocale();
4
+ return {
5
+ "x-medusa-locale": locale,
6
+ };
7
+ }
@@ -0,0 +1,2 @@
1
+ export default function medusaError(error: any): never;
2
+ //# sourceMappingURL=medusa-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"medusa-error.d.ts","sourceRoot":"","sources":["../../src/util/medusa-error.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,CAkBrD"}
@@ -0,0 +1,18 @@
1
+ export default function medusaError(error) {
2
+ if (error.response) {
3
+ // The request was made and the server responded with a status code
4
+ // that falls out of the range of 2xx
5
+ const u = new URL(error.config.url, error.config.baseURL);
6
+ // Extracting the error message from the response data
7
+ const message = error.response.data.message || error.response.data;
8
+ throw new Error(message.charAt(0).toUpperCase() + message.slice(1) + ".");
9
+ }
10
+ else if (error.request) {
11
+ // The request was made but no response was received
12
+ throw new Error("No response received: " + error.request);
13
+ }
14
+ else {
15
+ // Something happened in setting up the request that triggered an Error
16
+ throw new Error("Error setting up the request: " + error.message);
17
+ }
18
+ }
package/package.json ADDED
@@ -0,0 +1,152 @@
1
+ {
2
+ "name": "medusa-storefront-data",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "description": "Medusa storefront server data layer extracted from Next.js storefront",
6
+ "license": "MIT",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "files": [
11
+ "src",
12
+ "dist"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "clean": "rm -rf dist"
17
+ },
18
+ "peerDependencies": {
19
+ "next": ">=14",
20
+ "react": ">=18",
21
+ "@medusajs/js-sdk": ">=2",
22
+ "@medusajs/types": ">=2",
23
+ "medusa-reviews-logic": "*",
24
+ "medusa-wishlist-logic": "*"
25
+ },
26
+ "dependencies": {
27
+ "color": "^5.0.3",
28
+ "server-only": "^0.0.1"
29
+ },
30
+ "devDependencies": {
31
+ "typescript": "^5.6.0",
32
+ "@types/react": "^18.3.0",
33
+ "next": "^15.0.0",
34
+ "@medusajs/js-sdk": "^2.0.0",
35
+ "@medusajs/types": "^2.0.0",
36
+ "@types/node": "^22.0.0"
37
+ },
38
+ "exports": {
39
+ ".": {
40
+ "types": "./src/server/index.ts",
41
+ "import": "./src/server/index.ts"
42
+ },
43
+ "./cookies": {
44
+ "types": "./dist/cookies.d.ts",
45
+ "import": "./src/cookies.ts"
46
+ },
47
+ "./config": {
48
+ "types": "./dist/config.d.ts",
49
+ "import": "./src/config.ts"
50
+ },
51
+ "./locale-header": {
52
+ "types": "./dist/util/get-locale-header.d.ts",
53
+ "import": "./src/util/get-locale-header.ts"
54
+ },
55
+ "./medusa-error": {
56
+ "types": "./dist/util/medusa-error.d.ts",
57
+ "import": "./src/util/medusa-error.ts"
58
+ },
59
+ "./sort-products": {
60
+ "types": "./dist/util/sort-products.d.ts",
61
+ "import": "./src/util/sort-products.ts"
62
+ },
63
+ "./cart": {
64
+ "types": "./dist/server/cart.d.ts",
65
+ "import": "./src/server/cart.ts"
66
+ },
67
+ "./categories": {
68
+ "types": "./dist/server/categories.d.ts",
69
+ "import": "./src/server/categories.ts"
70
+ },
71
+ "./collections": {
72
+ "types": "./dist/server/collections.d.ts",
73
+ "import": "./src/server/collections.ts"
74
+ },
75
+ "./customer": {
76
+ "types": "./dist/server/customer.d.ts",
77
+ "import": "./src/server/customer.ts"
78
+ },
79
+ "./customer-registration": {
80
+ "types": "./dist/server/customer-registration.d.ts",
81
+ "import": "./src/server/customer-registration.ts"
82
+ },
83
+ "./dynamic-config": {
84
+ "types": "./dist/server/dynamic-config.d.ts",
85
+ "import": "./src/server/dynamic-config.ts"
86
+ },
87
+ "./fulfillment": {
88
+ "types": "./dist/server/fulfillment.d.ts",
89
+ "import": "./src/server/fulfillment.ts"
90
+ },
91
+ "./guest": {
92
+ "types": "./dist/server/guest.d.ts",
93
+ "import": "./src/server/guest.ts"
94
+ },
95
+ "./locale-actions": {
96
+ "types": "./dist/server/locale-actions.d.ts",
97
+ "import": "./src/server/locale-actions.ts"
98
+ },
99
+ "./locales": {
100
+ "types": "./dist/server/locales.d.ts",
101
+ "import": "./src/server/locales.ts"
102
+ },
103
+ "./notifications": {
104
+ "types": "./dist/server/notifications.d.ts",
105
+ "import": "./src/server/notifications.ts"
106
+ },
107
+ "./onboarding": {
108
+ "types": "./dist/server/onboarding.d.ts",
109
+ "import": "./src/server/onboarding.ts"
110
+ },
111
+ "./orders": {
112
+ "types": "./dist/server/orders.d.ts",
113
+ "import": "./src/server/orders.ts"
114
+ },
115
+ "./payment": {
116
+ "types": "./dist/server/payment.d.ts",
117
+ "import": "./src/server/payment.ts"
118
+ },
119
+ "./payment-details": {
120
+ "types": "./dist/server/payment-details.d.ts",
121
+ "import": "./src/server/payment-details.ts"
122
+ },
123
+ "./products": {
124
+ "types": "./dist/server/products.d.ts",
125
+ "import": "./src/server/products.ts"
126
+ },
127
+ "./regions": {
128
+ "types": "./dist/server/regions.d.ts",
129
+ "import": "./src/server/regions.ts"
130
+ },
131
+ "./returns": {
132
+ "types": "./dist/server/returns.d.ts",
133
+ "import": "./src/server/returns.ts"
134
+ },
135
+ "./swaps": {
136
+ "types": "./dist/server/swaps.d.ts",
137
+ "import": "./src/server/swaps.ts"
138
+ },
139
+ "./variants": {
140
+ "types": "./dist/server/variants.d.ts",
141
+ "import": "./src/server/variants.ts"
142
+ },
143
+ "./wishlist": {
144
+ "types": "./src/server/wishlist.ts",
145
+ "import": "./src/server/wishlist.ts"
146
+ },
147
+ "./middleware": {
148
+ "types": "./src/middleware.ts",
149
+ "import": "./src/middleware.ts"
150
+ }
151
+ }
152
+ }
package/src/config.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { getLocaleHeader } from "./util/get-locale-header"
2
+ import Medusa, { FetchArgs, FetchInput } from "@medusajs/js-sdk"
3
+
4
+ // Defaults to standard port for Medusa server
5
+ let MEDUSA_BACKEND_URL = "http://localhost:9000"
6
+
7
+ if (process.env.MEDUSA_BACKEND_URL) {
8
+ MEDUSA_BACKEND_URL = process.env.MEDUSA_BACKEND_URL
9
+ }
10
+
11
+ export const sdk = new Medusa({
12
+ baseUrl: MEDUSA_BACKEND_URL,
13
+ debug: process.env.NODE_ENV === "development",
14
+ publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
15
+ })
16
+
17
+ const originalFetch = sdk.client.fetch.bind(sdk.client)
18
+
19
+ sdk.client.fetch = async <T>(
20
+ input: FetchInput,
21
+ init?: FetchArgs
22
+ ): Promise<T> => {
23
+ const headers = init?.headers ?? {}
24
+ let localeHeader: Record<string, string | null> | undefined
25
+ try {
26
+ localeHeader = await getLocaleHeader()
27
+ headers["x-medusa-locale"] ??= localeHeader["x-medusa-locale"]
28
+ } catch {}
29
+
30
+ const newHeaders = {
31
+ ...localeHeader,
32
+ ...headers,
33
+ }
34
+ init = {
35
+ ...init,
36
+ headers: newHeaders,
37
+ }
38
+ return originalFetch(input, init)
39
+ }
package/src/cookies.ts ADDED
@@ -0,0 +1,171 @@
1
+ import "server-only"
2
+ import { cookies as nextCookies, headers } from "next/headers"
3
+
4
+ export const getAuthHeaders = async (): Promise<
5
+ { authorization: string } | {}
6
+ > => {
7
+ try {
8
+ const cookies = await nextCookies()
9
+ const token = cookies.get("_medusa_jwt")?.value
10
+
11
+ if (!token) {
12
+ return {}
13
+ }
14
+
15
+ return { authorization: `Bearer ${token}` }
16
+ } catch {
17
+ return {}
18
+ }
19
+ }
20
+
21
+ export const getGuestAuthHeaders = async (): Promise<
22
+ { authorization: string } | {}
23
+ > => {
24
+ try {
25
+ const cookies = await nextCookies()
26
+ const token = cookies.get("_medusa_guest_jwt")?.value
27
+
28
+ if (!token) {
29
+ return {}
30
+ }
31
+
32
+ return { authorization: `Bearer ${token}` }
33
+ } catch {
34
+ return {}
35
+ }
36
+ }
37
+
38
+ export const getCacheTag = async (tag: string): Promise<string> => {
39
+ try {
40
+ const cookies = await nextCookies()
41
+ const cacheId = cookies.get("_medusa_cache_id")?.value
42
+
43
+ if (!cacheId) {
44
+ return ""
45
+ }
46
+
47
+ return `${tag}-${cacheId}`
48
+ } catch (error) {
49
+ return ""
50
+ }
51
+ }
52
+
53
+ export const getCacheOptions = async (
54
+ tag: string
55
+ ): Promise<{ tags: string[] } | {}> => {
56
+ if (typeof window !== "undefined") {
57
+ return {}
58
+ }
59
+
60
+ const cacheTag = await getCacheTag(tag)
61
+
62
+ if (!cacheTag) {
63
+ return {}
64
+ }
65
+
66
+ return { tags: [`${cacheTag}`] }
67
+ }
68
+
69
+ export const setAuthToken = async (token: string) => {
70
+ const cookies = await nextCookies()
71
+ cookies.set("_medusa_jwt", token, {
72
+ maxAge: 60 * 60 * 24 * 7,
73
+ httpOnly: true,
74
+ sameSite: "strict",
75
+ secure: process.env.NODE_ENV === "production",
76
+ })
77
+ }
78
+
79
+ export const removeAuthToken = async () => {
80
+ const cookies = await nextCookies()
81
+ cookies.set("_medusa_jwt", "", {
82
+ maxAge: -1,
83
+ })
84
+ }
85
+
86
+ export const getCartId = async () => {
87
+ const cookies = await nextCookies()
88
+ const headerList = await headers()
89
+
90
+ // Check for x-cart-id header FIRST (as it's the most up-to-date from middleware)
91
+ const headerId = headerList.get("x-cart-id")
92
+ if (headerId) {
93
+ return headerId
94
+ }
95
+
96
+ // Prioritize buy_now_cart_id if it exists
97
+ const buyNowId = cookies.get("buy_now_cart_id")?.value
98
+ if (buyNowId) {
99
+ return buyNowId
100
+ }
101
+
102
+ // Fallback to regular cart cookies
103
+ const id = cookies.get("_medusa_cart_id")?.value ||
104
+ cookies.get("cart_id")?.value ||
105
+ cookies.get("medusa_cart_id")?.value
106
+
107
+ return id
108
+ }
109
+
110
+ export const setCartId = async (cartId: string) => {
111
+ const cookies = await nextCookies()
112
+ cookies.set("_medusa_cart_id", cartId, {
113
+ maxAge: 60 * 60 * 24 * 7,
114
+ httpOnly: true,
115
+ sameSite: "strict",
116
+ secure: process.env.NODE_ENV === "production",
117
+ })
118
+ }
119
+
120
+ export const removeCartId = async () => {
121
+ const cookies = await nextCookies()
122
+ cookies.set("_medusa_cart_id", "", {
123
+ maxAge: -1,
124
+ })
125
+ }
126
+
127
+ export const removeSyncLock = async () => {
128
+ const cookies = await nextCookies()
129
+ cookies.set("_medusa_cart_synced", "", {
130
+ maxAge: -1,
131
+ })
132
+ }
133
+
134
+ export const setHoldCartId = async (cartId: string) => {
135
+ const cookies = await nextCookies()
136
+ cookies.set("_medusa_hold_cart_id", cartId, {
137
+ maxAge: 60 * 60 * 24,
138
+ httpOnly: true,
139
+ sameSite: "strict",
140
+ secure: process.env.NODE_ENV === "production",
141
+ })
142
+ }
143
+
144
+ export const getHoldCartId = async () => {
145
+ const cookies = await nextCookies()
146
+ return cookies.get("_medusa_hold_cart_id")?.value
147
+ }
148
+
149
+ export const removeHoldCartId = async () => {
150
+ const cookies = await nextCookies()
151
+ cookies.set("_medusa_hold_cart_id", "", {
152
+ maxAge: -1,
153
+ })
154
+ }
155
+
156
+ export const setBuyNowCartId = async (cartId: string) => {
157
+ const cookies = await nextCookies()
158
+ cookies.set("buy_now_cart_id", cartId, {
159
+ maxAge: 60 * 60 * 24 * 7,
160
+ httpOnly: true,
161
+ sameSite: "strict",
162
+ secure: process.env.NODE_ENV === "production",
163
+ })
164
+ }
165
+
166
+ export const removeBuyNowCartId = async () => {
167
+ const cookies = await nextCookies()
168
+ cookies.set("buy_now_cart_id", "", {
169
+ maxAge: -1,
170
+ })
171
+ }
@@ -0,0 +1,2 @@
1
+ export { medusaListRegions, medusaMergeCarts } from "./services/middleware";
2
+ export type { MedusaMiddlewareClientOptions } from "./services/middleware";