medusa-storefront-data 1.0.0 → 2.1.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/cookies.d.ts +2 -2
- package/dist/cookies.d.ts.map +1 -1
- package/dist/edge.d.ts +3 -0
- package/dist/edge.d.ts.map +1 -0
- package/dist/edge.js +1 -0
- package/dist/middleware.d.ts +3 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +1 -0
- package/dist/server/cart.d.ts +9 -5
- package/dist/server/cart.d.ts.map +1 -1
- package/dist/server/cart.js +164 -194
- package/dist/server/categories.d.ts +3 -2
- package/dist/server/categories.d.ts.map +1 -1
- package/dist/server/categories.js +14 -51
- package/dist/server/collections.d.ts.map +1 -1
- package/dist/server/collections.js +16 -61
- package/dist/server/contact.d.ts +34 -0
- package/dist/server/contact.d.ts.map +1 -0
- package/dist/server/contact.js +57 -0
- package/dist/server/customer.d.ts +7 -7
- package/dist/server/customer.d.ts.map +1 -1
- package/dist/server/customer.js +96 -145
- package/dist/server/dynamic-config.d.ts.map +1 -1
- package/dist/server/dynamic-config.js +38 -12
- package/dist/server/fulfillment.d.ts +4 -3
- package/dist/server/fulfillment.d.ts.map +1 -1
- package/dist/server/fulfillment.js +16 -41
- package/dist/server/guest.d.ts +35 -63
- package/dist/server/guest.d.ts.map +1 -1
- package/dist/server/guest.js +81 -202
- package/dist/server/home.d.ts +15 -0
- package/dist/server/home.d.ts.map +1 -0
- package/dist/server/home.js +45 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -0
- package/dist/server/locale-actions.d.ts +1 -1
- package/dist/server/locale-actions.d.ts.map +1 -1
- package/dist/server/locale-actions.js +8 -13
- package/dist/server/locales.d.ts +2 -4
- package/dist/server/locales.d.ts.map +1 -1
- package/dist/server/locales.js +5 -13
- package/dist/server/orders.d.ts +5 -11
- package/dist/server/orders.d.ts.map +1 -1
- package/dist/server/orders.js +126 -267
- package/dist/server/payment-details.d.ts +4 -4
- package/dist/server/payment-details.d.ts.map +1 -1
- package/dist/server/payment-details.js +17 -42
- package/dist/server/payment.d.ts +2 -1
- package/dist/server/payment.d.ts.map +1 -1
- package/dist/server/payment.js +9 -21
- package/dist/server/pincode.d.ts +7 -0
- package/dist/server/pincode.d.ts.map +1 -0
- package/dist/server/pincode.js +30 -0
- package/dist/server/products.d.ts +15 -19
- package/dist/server/products.d.ts.map +1 -1
- package/dist/server/products.js +47 -178
- package/dist/server/regions.d.ts +1 -1
- package/dist/server/regions.d.ts.map +1 -1
- package/dist/server/regions.js +6 -3
- package/dist/server/returns.d.ts +4 -4
- package/dist/server/returns.d.ts.map +1 -1
- package/dist/server/returns.js +50 -154
- package/dist/server/swaps.d.ts +7 -6
- package/dist/server/swaps.d.ts.map +1 -1
- package/dist/server/swaps.js +23 -57
- package/dist/server/variants.d.ts.map +1 -1
- package/dist/server/variants.js +11 -22
- package/dist/server/wishlist.d.ts +11 -0
- package/dist/server/wishlist.d.ts.map +1 -0
- package/dist/server/wishlist.js +49 -0
- package/dist/util/get-locale-header.d.ts +1 -1
- package/dist/util/revalidate-cart.d.ts +2 -0
- package/dist/util/revalidate-cart.d.ts.map +1 -0
- package/dist/util/revalidate-cart.js +8 -0
- package/dist/util/sort-products.d.ts +3 -0
- package/dist/util/sort-products.d.ts.map +1 -0
- package/dist/util/sort-products.js +1 -0
- package/dist/util/store-client.d.ts +13 -0
- package/dist/util/store-client.d.ts.map +1 -0
- package/dist/util/store-client.js +77 -0
- package/package.json +95 -37
- package/src/edge.ts +2 -0
- package/src/middleware.ts +2 -2
- package/src/server/cart.ts +214 -267
- package/src/server/categories.ts +19 -72
- package/src/server/collections.ts +25 -82
- package/src/server/contact.ts +92 -0
- package/src/server/customer.ts +146 -190
- package/src/server/dynamic-config.ts +38 -12
- package/src/server/fulfillment.ts +27 -53
- package/src/server/guest.ts +159 -276
- package/src/server/home.ts +68 -0
- package/src/server/index.ts +1 -0
- package/src/server/locale-actions.ts +8 -15
- package/src/server/locales.ts +6 -18
- package/src/server/orders.ts +167 -337
- package/src/server/payment-details.ts +24 -52
- package/src/server/payment.ts +8 -28
- package/src/server/pincode.ts +49 -0
- package/src/server/products.ts +72 -235
- package/src/server/regions.ts +10 -6
- package/src/server/returns.ts +75 -189
- package/src/server/swaps.ts +94 -123
- package/src/server/variants.ts +9 -28
- package/src/server/wishlist.ts +1 -1
- package/src/util/revalidate-cart.ts +10 -0
- package/src/util/sort-products.ts +2 -47
- package/src/util/store-client.ts +93 -0
- package/src/services/middleware.ts +0 -54
package/dist/server/customer.js
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
"use server";
|
|
2
|
-
import { sdk } from "../config";
|
|
3
2
|
import medusaError from "../util/medusa-error";
|
|
4
3
|
import { revalidateTag } from "next/cache";
|
|
5
4
|
import { redirect } from "next/navigation";
|
|
6
5
|
import { cookies } from "next/headers";
|
|
7
6
|
import { getAuthHeaders, getCacheTag, getCartId, removeAuthToken, removeCartId, removeSyncLock, setAuthToken, setCartId, } from "../cookies";
|
|
7
|
+
import { medusaAuthLogin, medusaAuthLogout, medusaAuthRegister, } from "medusa-services/auth";
|
|
8
|
+
import { isAccountDeletionPendingError, medusaCustomerCreate, medusaCustomerCreateAddress, medusaCustomerDeleteAddress, medusaCustomerRetrieve, medusaCustomerUpdate, medusaCustomerUpdateAddress, } from "medusa-services/customer";
|
|
9
|
+
import { medusaCartMerge, medusaCartTransfer } from "medusa-services/cart";
|
|
10
|
+
import { getAuthClientOptions, getMedusaBackendUrl, getStoreCartClientOptions, } from "../util/store-client";
|
|
8
11
|
import { cache } from "react";
|
|
12
|
+
function throwCustomerError(error) {
|
|
13
|
+
if (error && typeof error === "object" && "response" in error) {
|
|
14
|
+
medusaError(error);
|
|
15
|
+
}
|
|
16
|
+
throw error instanceof Error ? error : new Error(String(error));
|
|
17
|
+
}
|
|
9
18
|
export const retrieveCustomer = cache(async () => {
|
|
10
19
|
const authHeaders = await getAuthHeaders();
|
|
11
|
-
if (!authHeaders)
|
|
20
|
+
if (!("authorization" in authHeaders))
|
|
12
21
|
return null;
|
|
13
|
-
const headers = {
|
|
14
|
-
...authHeaders,
|
|
15
|
-
};
|
|
16
22
|
try {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
query: { fields: "*addresses" },
|
|
20
|
-
headers: headers,
|
|
21
|
-
cache: "no-store",
|
|
22
|
-
});
|
|
23
|
+
const options = await getStoreCartClientOptions();
|
|
24
|
+
const { customer } = await medusaCustomerRetrieve(options, { fields: "*addresses" });
|
|
23
25
|
return customer;
|
|
24
26
|
}
|
|
25
27
|
catch (error) {
|
|
26
|
-
|
|
27
|
-
// If the error indicates a pending deletion, return a special object
|
|
28
|
-
if (errStr.includes("active account deletion request") ||
|
|
29
|
-
(error.message && error.message.toLowerCase().includes("active account deletion request"))) {
|
|
28
|
+
if (isAccountDeletionPendingError(error)) {
|
|
30
29
|
const cookieStore = await cookies();
|
|
31
30
|
const cookieEmail = cookieStore.get("_medusa_customer_email")?.value;
|
|
32
31
|
return { id: "pending_deletion", email: cookieEmail || "pending" };
|
|
@@ -35,16 +34,16 @@ export const retrieveCustomer = cache(async () => {
|
|
|
35
34
|
}
|
|
36
35
|
});
|
|
37
36
|
export const updateCustomer = async (body) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
try {
|
|
38
|
+
const options = await getStoreCartClientOptions();
|
|
39
|
+
const { customer } = await medusaCustomerUpdate(body, options);
|
|
40
|
+
const cacheTag = await getCacheTag("customers");
|
|
41
|
+
revalidateTag(cacheTag);
|
|
42
|
+
return customer;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
throwCustomerError(e);
|
|
46
|
+
}
|
|
48
47
|
};
|
|
49
48
|
export async function signup(_currentState, formData) {
|
|
50
49
|
const password = formData.get("password");
|
|
@@ -55,19 +54,12 @@ export async function signup(_currentState, formData) {
|
|
|
55
54
|
phone: formData.get("phone")?.replace(/[^\d+]/g, ""),
|
|
56
55
|
};
|
|
57
56
|
try {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
password: password,
|
|
61
|
-
});
|
|
57
|
+
const authOptions = await getAuthClientOptions();
|
|
58
|
+
const token = await medusaAuthRegister({ email: customerForm.email, password }, authOptions);
|
|
62
59
|
await setAuthToken(token);
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
};
|
|
66
|
-
const { customer: createdCustomer } = await sdk.store.customer.create(customerForm, {}, headers);
|
|
67
|
-
const loginToken = await sdk.auth.login("customer", "emailpass", {
|
|
68
|
-
email: customerForm.email,
|
|
69
|
-
password,
|
|
70
|
-
});
|
|
60
|
+
const options = await getStoreCartClientOptions();
|
|
61
|
+
const { customer: createdCustomer } = await medusaCustomerCreate(customerForm, options);
|
|
62
|
+
const loginToken = await medusaAuthLogin({ email: customerForm.email, password }, authOptions);
|
|
71
63
|
await setAuthToken(loginToken);
|
|
72
64
|
const customerCacheTag = await getCacheTag("customers");
|
|
73
65
|
revalidateTag(customerCacheTag);
|
|
@@ -81,34 +73,30 @@ export async function signup(_currentState, formData) {
|
|
|
81
73
|
export async function login(_currentState, formData) {
|
|
82
74
|
let email = formData.get("email_or_phone");
|
|
83
75
|
const password = formData.get("password");
|
|
84
|
-
// Sanitize phone number: remove spaces, dashes, etc if it looks like a phone number
|
|
85
|
-
// If it doesn't have '@', we treat it as a potential phone number and clean it
|
|
86
76
|
if (email && !email.includes("@")) {
|
|
87
77
|
email = email.replace(/[^\d+]/g, "");
|
|
88
78
|
}
|
|
89
79
|
let shouldRedirect = false;
|
|
90
80
|
let countryCode = "in";
|
|
91
81
|
try {
|
|
92
|
-
const
|
|
82
|
+
const authOptions = await getAuthClientOptions();
|
|
83
|
+
const token = await medusaAuthLogin({ email_or_phone: email, password }, authOptions);
|
|
93
84
|
await setAuthToken(token);
|
|
94
|
-
// Store email in cookie for deletion flow (needed for cancellation modal)
|
|
95
85
|
const cookieStore = await cookies();
|
|
96
86
|
cookieStore.set("_medusa_customer_email", email, { maxAge: 60 * 60 * 24 * 7, path: "/" });
|
|
97
|
-
// Force a check to see if we are blocked
|
|
98
87
|
try {
|
|
99
|
-
await
|
|
100
|
-
|
|
88
|
+
const options = await getStoreCartClientOptions();
|
|
89
|
+
await medusaCustomerRetrieve({
|
|
90
|
+
...options,
|
|
91
|
+
authorization: `Bearer ${token}`,
|
|
101
92
|
});
|
|
102
93
|
}
|
|
103
94
|
catch (err) {
|
|
104
|
-
|
|
105
|
-
if (errStr.includes("active account deletion request")) {
|
|
95
|
+
if (isAccountDeletionPendingError(err)) {
|
|
106
96
|
return "ACCOUNT_DELETION_PENDING";
|
|
107
97
|
}
|
|
108
|
-
// If it's another error, we might still want to know, but deletion is our priority
|
|
109
98
|
throw err;
|
|
110
99
|
}
|
|
111
|
-
// Transfer cart after login success - Moved here to ensure execution
|
|
112
100
|
try {
|
|
113
101
|
await transferCart(token);
|
|
114
102
|
}
|
|
@@ -121,35 +109,37 @@ export async function login(_currentState, formData) {
|
|
|
121
109
|
shouldRedirect = true;
|
|
122
110
|
}
|
|
123
111
|
catch (error) {
|
|
124
|
-
|
|
125
|
-
if (errorStr.includes("active account deletion request") ||
|
|
126
|
-
(error.message && error.message.toLowerCase().includes("active account deletion request"))) {
|
|
127
|
-
// Still set email cookie even if blocked
|
|
112
|
+
if (isAccountDeletionPendingError(error)) {
|
|
128
113
|
const cookieStore = await cookies();
|
|
129
114
|
cookieStore.set("_medusa_customer_email", email, { maxAge: 60 * 60 * 24 * 7, path: "/" });
|
|
130
115
|
return "ACCOUNT_DELETION_PENDING";
|
|
131
116
|
}
|
|
117
|
+
const errorStr = String(error).toLowerCase();
|
|
132
118
|
if (errorStr.includes("invalid") || errorStr.includes("401") || errorStr.includes("not found")) {
|
|
133
119
|
return "Invalid credentials. Please try again.";
|
|
134
120
|
}
|
|
135
|
-
return error.message
|
|
121
|
+
return error instanceof Error ? error.message : String(error);
|
|
136
122
|
}
|
|
137
123
|
if (shouldRedirect) {
|
|
138
124
|
const redirectUrl = formData.get("redirect_url");
|
|
139
|
-
// Check if it's a "keep-me-here" context (Wishlist or Review Popups)
|
|
140
125
|
const hasKeepContext = redirectUrl?.includes("login_context=keep");
|
|
141
|
-
// Security + Context check
|
|
142
126
|
if (redirectUrl && redirectUrl.startsWith("/") && hasKeepContext) {
|
|
143
127
|
redirect(redirectUrl);
|
|
144
128
|
}
|
|
145
129
|
else {
|
|
146
|
-
// DEFAULT: Always Home Page
|
|
147
130
|
redirect(`/${countryCode}`);
|
|
148
131
|
}
|
|
149
132
|
}
|
|
133
|
+
return null;
|
|
150
134
|
}
|
|
151
135
|
export async function signout(countryCode) {
|
|
152
|
-
|
|
136
|
+
try {
|
|
137
|
+
const authOptions = await getAuthClientOptions();
|
|
138
|
+
await medusaAuthLogout(authOptions);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
// Continue local cleanup even if remote logout fails
|
|
142
|
+
}
|
|
153
143
|
await removeAuthToken();
|
|
154
144
|
await removeCartId();
|
|
155
145
|
await removeSyncLock();
|
|
@@ -162,54 +152,34 @@ export async function signout(countryCode) {
|
|
|
162
152
|
}
|
|
163
153
|
export async function transferCart(token) {
|
|
164
154
|
const cartId = await getCartId();
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
:
|
|
155
|
+
const options = await getStoreCartClientOptions();
|
|
156
|
+
const mergeOptions = token
|
|
157
|
+
? { ...options, authorization: `Bearer ${token}` }
|
|
158
|
+
: options;
|
|
168
159
|
console.log("--- TransferCart Debug ---");
|
|
169
160
|
console.log("Token provided:", !!token);
|
|
170
161
|
console.log("Guest Cart ID:", cartId);
|
|
171
|
-
const publishableKey = process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY;
|
|
172
|
-
const backendUrl = process.env.MEDUSA_BACKEND_URL || process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL || "http://localhost:9000";
|
|
173
162
|
try {
|
|
174
163
|
console.log("Calling merge API (always)...");
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
headers: {
|
|
178
|
-
"Content-Type": "application/json",
|
|
179
|
-
"x-publishable-api-key": publishableKey || "",
|
|
180
|
-
...authHeaders,
|
|
181
|
-
},
|
|
182
|
-
// Only include body if cartId exists
|
|
183
|
-
...(cartId ? { body: JSON.stringify({ cart_id: cartId }) } : {}),
|
|
184
|
-
cache: "no-store",
|
|
185
|
-
});
|
|
186
|
-
if (response.ok) {
|
|
187
|
-
const data = await response.json();
|
|
164
|
+
const data = await medusaCartMerge(mergeOptions, cartId ?? undefined);
|
|
165
|
+
if (data) {
|
|
188
166
|
console.log("--- Login Merge Response (JSON) ---");
|
|
189
167
|
console.log(JSON.stringify(data, null, 2));
|
|
190
168
|
console.log("-----------------------------------");
|
|
191
169
|
const activeCartId = data.cart?.id || data.id || data.cart_id;
|
|
192
|
-
if (activeCartId) {
|
|
170
|
+
if (activeCartId && typeof activeCartId === "string") {
|
|
193
171
|
console.log("Storing Cart ID in cookie:", activeCartId);
|
|
194
172
|
await setCartId(activeCartId);
|
|
195
173
|
}
|
|
196
174
|
}
|
|
197
|
-
else if (response.status === 404) {
|
|
198
|
-
// 404 is fine - it just means the customer has no active cart yet
|
|
199
|
-
console.log("No active cart found for this customer (expected).");
|
|
200
|
-
}
|
|
201
175
|
else {
|
|
202
|
-
|
|
203
|
-
console.log(`Merge API Info (${response.status}):`, errorText);
|
|
204
|
-
if (cartId) {
|
|
205
|
-
await sdk.store.cart.transferCart(cartId, {}, authHeaders).catch(() => { });
|
|
206
|
-
}
|
|
176
|
+
console.log("No active cart found for this customer (expected).");
|
|
207
177
|
}
|
|
208
178
|
}
|
|
209
179
|
catch (error) {
|
|
210
|
-
console.error("Merge API error:", error.message);
|
|
180
|
+
console.error("Merge API error:", error instanceof Error ? error.message : error);
|
|
211
181
|
if (cartId) {
|
|
212
|
-
await
|
|
182
|
+
await medusaCartTransfer(cartId, mergeOptions).catch(() => { });
|
|
213
183
|
}
|
|
214
184
|
}
|
|
215
185
|
console.log("--------------------------");
|
|
@@ -234,36 +204,30 @@ export const addCustomerAddress = async (currentState, formData) => {
|
|
|
234
204
|
is_default_shipping: isDefaultShipping,
|
|
235
205
|
metadata: {
|
|
236
206
|
address_type: formData.get("address_type") || "HOME",
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
const headers = {
|
|
240
|
-
...(await getAuthHeaders()),
|
|
207
|
+
},
|
|
241
208
|
};
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
209
|
+
try {
|
|
210
|
+
const options = await getStoreCartClientOptions();
|
|
211
|
+
await medusaCustomerCreateAddress(address, options);
|
|
245
212
|
const customerCacheTag = await getCacheTag("customers");
|
|
246
213
|
revalidateTag(customerCacheTag);
|
|
247
214
|
return { success: true, error: null };
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return { success: false, error: err
|
|
251
|
-
}
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
return { success: false, error: String(err) };
|
|
218
|
+
}
|
|
252
219
|
};
|
|
253
220
|
export const deleteCustomerAddress = async (addressId) => {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
await sdk.store.customer
|
|
258
|
-
.deleteAddress(addressId, headers)
|
|
259
|
-
.then(async () => {
|
|
221
|
+
try {
|
|
222
|
+
const options = await getStoreCartClientOptions();
|
|
223
|
+
await medusaCustomerDeleteAddress(addressId, options);
|
|
260
224
|
const customerCacheTag = await getCacheTag("customers");
|
|
261
225
|
revalidateTag(customerCacheTag);
|
|
262
226
|
return { success: true, error: null };
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
return { success: false, error: err
|
|
266
|
-
}
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
return { success: false, error: String(err) };
|
|
230
|
+
}
|
|
267
231
|
};
|
|
268
232
|
export const updateCustomerAddress = async (currentState, formData) => {
|
|
269
233
|
const addressId = currentState.addressId || formData.get("addressId");
|
|
@@ -282,44 +246,38 @@ export const updateCustomerAddress = async (currentState, formData) => {
|
|
|
282
246
|
country_code: formData.get("country_code"),
|
|
283
247
|
metadata: {
|
|
284
248
|
address_type: formData.get("address_type") || "HOME",
|
|
285
|
-
}
|
|
249
|
+
},
|
|
286
250
|
};
|
|
287
251
|
const phone = formData.get("phone");
|
|
288
252
|
if (phone) {
|
|
289
253
|
address.phone = phone;
|
|
290
254
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return sdk.store.customer
|
|
295
|
-
.updateAddress(addressId, address, {}, headers)
|
|
296
|
-
.then(async () => {
|
|
255
|
+
try {
|
|
256
|
+
const options = await getStoreCartClientOptions();
|
|
257
|
+
await medusaCustomerUpdateAddress(addressId, address, options);
|
|
297
258
|
const customerCacheTag = await getCacheTag("customers");
|
|
298
259
|
revalidateTag(customerCacheTag);
|
|
299
260
|
return { success: true, error: null };
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
return { success: false, error: err
|
|
303
|
-
}
|
|
261
|
+
}
|
|
262
|
+
catch (err) {
|
|
263
|
+
return { success: false, error: String(err) };
|
|
264
|
+
}
|
|
304
265
|
};
|
|
305
266
|
export const setDefaultAddress = async (addressId) => {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
return sdk.store.customer
|
|
310
|
-
.updateAddress(addressId, { is_default_shipping: true }, {}, headers)
|
|
311
|
-
.then(async () => {
|
|
267
|
+
try {
|
|
268
|
+
const options = await getStoreCartClientOptions();
|
|
269
|
+
await medusaCustomerUpdateAddress(addressId, { is_default_shipping: true }, options);
|
|
312
270
|
const customerCacheTag = await getCacheTag("customers");
|
|
313
271
|
revalidateTag(customerCacheTag);
|
|
314
272
|
return { success: true, error: null };
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
return { success: false, error: err
|
|
318
|
-
}
|
|
273
|
+
}
|
|
274
|
+
catch (err) {
|
|
275
|
+
return { success: false, error: String(err) };
|
|
276
|
+
}
|
|
319
277
|
};
|
|
320
278
|
export async function initiateGoogleAuth() {
|
|
321
279
|
try {
|
|
322
|
-
const backendUrl =
|
|
280
|
+
const backendUrl = getMedusaBackendUrl();
|
|
323
281
|
if (!backendUrl) {
|
|
324
282
|
return { error: "Backend URL not configured" };
|
|
325
283
|
}
|
|
@@ -338,18 +296,13 @@ export async function initiateGoogleAuth() {
|
|
|
338
296
|
if (!redirectUrl) {
|
|
339
297
|
return { error: "No redirect URL received from Google OAuth" };
|
|
340
298
|
}
|
|
341
|
-
// Fix redirect URL: Remove country code prefix from callback URL if present
|
|
342
|
-
// Example: https://chocomelon.in/in/auth/customer/google/callback -> https://chocomelon.in/auth/customer/google/callback
|
|
343
299
|
try {
|
|
344
300
|
const url = new URL(redirectUrl);
|
|
345
|
-
const pathParts = url.pathname.split(
|
|
346
|
-
// Check if path starts with country code pattern (2-3 letter code)
|
|
301
|
+
const pathParts = url.pathname.split("/").filter(Boolean);
|
|
347
302
|
if (pathParts.length > 0 && /^[a-z]{2,3}$/i.test(pathParts[0])) {
|
|
348
|
-
|
|
349
|
-
if (pathParts.length > 1 && pathParts[1] === 'auth') {
|
|
350
|
-
// Remove country code from path
|
|
303
|
+
if (pathParts.length > 1 && pathParts[1] === "auth") {
|
|
351
304
|
pathParts.shift();
|
|
352
|
-
url.pathname =
|
|
305
|
+
url.pathname = "/" + pathParts.join("/");
|
|
353
306
|
redirectUrl = url.toString();
|
|
354
307
|
}
|
|
355
308
|
}
|
|
@@ -368,7 +321,7 @@ export async function handleGoogleAuthCallback(params) {
|
|
|
368
321
|
if (!params.code || !params.state) {
|
|
369
322
|
return { error: "Missing authentication parameters" };
|
|
370
323
|
}
|
|
371
|
-
const backendUrl =
|
|
324
|
+
const backendUrl = getMedusaBackendUrl();
|
|
372
325
|
if (!backendUrl) {
|
|
373
326
|
return { error: "Backend URL not configured" };
|
|
374
327
|
}
|
|
@@ -403,13 +356,14 @@ export async function handleGoogleCallback(token, email, first_name, last_name)
|
|
|
403
356
|
if (email && typeof email === "string") {
|
|
404
357
|
const cookieStore = await cookies();
|
|
405
358
|
cookieStore.set("_medusa_customer_email", email, { maxAge: 60 * 60 * 24 * 7, path: "/" });
|
|
406
|
-
const
|
|
407
|
-
if (
|
|
359
|
+
const options = await getStoreCartClientOptions();
|
|
360
|
+
if (options.authorization) {
|
|
408
361
|
try {
|
|
409
|
-
await
|
|
362
|
+
await medusaCustomerCreate({ email, ...(first_name && { first_name }), ...(last_name && { last_name }) }, options);
|
|
410
363
|
}
|
|
411
364
|
catch (err) {
|
|
412
365
|
if (!err.message?.includes("already exists") && !err.message?.includes("duplicate")) {
|
|
366
|
+
// Ignore duplicate customer errors for OAuth sign-in
|
|
413
367
|
}
|
|
414
368
|
}
|
|
415
369
|
}
|
|
@@ -429,7 +383,6 @@ export async function uploadProfileImage(formData) {
|
|
|
429
383
|
if (!imageFile) {
|
|
430
384
|
return { error: "No image file provided" };
|
|
431
385
|
}
|
|
432
|
-
// Create new FormData with 'files' field as expected by the backend
|
|
433
386
|
const uploadFormData = new FormData();
|
|
434
387
|
uploadFormData.append("files", imageFile);
|
|
435
388
|
const { uploadStoreFiles } = await import("medusa-reviews-logic/server");
|
|
@@ -441,14 +394,12 @@ export async function uploadProfileImage(formData) {
|
|
|
441
394
|
if (!imageUrl) {
|
|
442
395
|
throw new Error("No image URL returned from server");
|
|
443
396
|
}
|
|
444
|
-
// Fetch current customer to preserve existing metadata
|
|
445
397
|
const currentCustomer = await retrieveCustomer();
|
|
446
398
|
const existingMetadata = currentCustomer?.metadata || {};
|
|
447
399
|
const newMetadata = {
|
|
448
400
|
...existingMetadata,
|
|
449
401
|
profile_image_url: imageUrl,
|
|
450
402
|
};
|
|
451
|
-
// Update customer metadata
|
|
452
403
|
await updateCustomer({ metadata: newMetadata });
|
|
453
404
|
const customerCacheTag = await getCacheTag("customers");
|
|
454
405
|
if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,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,GAAG,IAAI,CA+B5H,CAAA;AACD,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAcrI,CAAA"}
|
|
@@ -84,10 +84,10 @@ export const getHomeBannersFromConfig = async () => {
|
|
|
84
84
|
const banner = item["homepage-banner"];
|
|
85
85
|
return {
|
|
86
86
|
image: banner?.["homepage-banner-image"],
|
|
87
|
-
title: banner?.["homepage-banner-title"],
|
|
88
|
-
subtitle: banner?.["homepage-banner-subtitle"],
|
|
89
|
-
description: banner?.["homepage-banner-description"],
|
|
90
|
-
buttonName: banner?.["homepage-banner-button-name"],
|
|
87
|
+
title: normalizeCmsText(banner?.["homepage-banner-title"]),
|
|
88
|
+
subtitle: normalizeCmsText(banner?.["homepage-banner-subtitle"]),
|
|
89
|
+
description: normalizeCmsText(banner?.["homepage-banner-description"]),
|
|
90
|
+
buttonName: normalizeBannerButtonName(banner?.["homepage-banner-button-name"]),
|
|
91
91
|
buttonLink: banner?.["homepage-banner-button-link"],
|
|
92
92
|
};
|
|
93
93
|
});
|
|
@@ -107,10 +107,10 @@ export const getAppBannersFromConfig = async () => {
|
|
|
107
107
|
const banner = item["app-banner"];
|
|
108
108
|
return {
|
|
109
109
|
image: banner?.["app-banner-image"],
|
|
110
|
-
title: banner?.["app-banner-title"],
|
|
111
|
-
subtitle: banner?.["app-banner-subtitle"],
|
|
112
|
-
description: banner?.["app-banner-description"],
|
|
113
|
-
buttonName: banner?.["app-banner-button-name"],
|
|
110
|
+
title: normalizeCmsText(banner?.["app-banner-title"]),
|
|
111
|
+
subtitle: normalizeCmsText(banner?.["app-banner-subtitle"]),
|
|
112
|
+
description: normalizeCmsText(banner?.["app-banner-description"]),
|
|
113
|
+
buttonName: normalizeBannerButtonName(banner?.["app-banner-button-name"]),
|
|
114
114
|
buttonLink: banner?.["app-banner-button-link"],
|
|
115
115
|
};
|
|
116
116
|
});
|
|
@@ -143,7 +143,7 @@ export const getFeaturesFromConfig = async () => {
|
|
|
143
143
|
const homepageConfig = config?.["homepage-config"];
|
|
144
144
|
if (!homepageConfig)
|
|
145
145
|
return null;
|
|
146
|
-
const title = homepageConfig["why-choose-us-title"] || "Why Choose
|
|
146
|
+
const title = homepageConfig["why-choose-us-title"] || "Why Choose Us?";
|
|
147
147
|
const featuresRaw = homepageConfig["why-choose-us-features"] || [];
|
|
148
148
|
const features = featuresRaw.map((item) => {
|
|
149
149
|
const feature = item?.feature || item;
|
|
@@ -158,6 +158,32 @@ export const getFeaturesFromConfig = async () => {
|
|
|
158
158
|
return null;
|
|
159
159
|
}
|
|
160
160
|
};
|
|
161
|
+
const EMAIL_PATTERN = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
162
|
+
/** Fix common UTF-8 mojibake from CMS copy-paste (e.g. em dash, apostrophe). */
|
|
163
|
+
function normalizeCmsText(value) {
|
|
164
|
+
if (typeof value !== "string" || !value.trim())
|
|
165
|
+
return undefined;
|
|
166
|
+
return value
|
|
167
|
+
.trim()
|
|
168
|
+
.replace(/ΓÇö/g, "—")
|
|
169
|
+
.replace(/ΓÇÖ/g, "'")
|
|
170
|
+
.replace(/ΓÇ£|ΓÇ¥/g, '"')
|
|
171
|
+
.replace(/≡ƒÿÄ≡ƒæòΓ£¿/g, " 👕✨");
|
|
172
|
+
}
|
|
173
|
+
function normalizeBannerButtonName(value) {
|
|
174
|
+
const text = normalizeCmsText(value);
|
|
175
|
+
if (!text)
|
|
176
|
+
return undefined;
|
|
177
|
+
if (/^shop\s+now\s*1$/i.test(text))
|
|
178
|
+
return "Shop Now";
|
|
179
|
+
return text;
|
|
180
|
+
}
|
|
181
|
+
function normalizeConfigEmail(value) {
|
|
182
|
+
if (typeof value !== "string")
|
|
183
|
+
return undefined;
|
|
184
|
+
const trimmed = value.trim();
|
|
185
|
+
return EMAIL_PATTERN.test(trimmed) ? trimmed : undefined;
|
|
186
|
+
}
|
|
161
187
|
export const getContactInfoFromConfig = async () => {
|
|
162
188
|
try {
|
|
163
189
|
const config = await getDynamicConfig();
|
|
@@ -167,7 +193,7 @@ export const getContactInfoFromConfig = async () => {
|
|
|
167
193
|
}
|
|
168
194
|
return {
|
|
169
195
|
phone: contactConfig["contact-phone"],
|
|
170
|
-
email: contactConfig["contact-email"],
|
|
196
|
+
email: normalizeConfigEmail(contactConfig["contact-email"]),
|
|
171
197
|
address: contactConfig["contact-address"],
|
|
172
198
|
};
|
|
173
199
|
}
|
|
@@ -251,10 +277,10 @@ export const getPromoBarConfig = async () => {
|
|
|
251
277
|
const config = await getDynamicConfig();
|
|
252
278
|
const promoConfig = config?.["homepage-config"]?.["promo-bar"];
|
|
253
279
|
return {
|
|
254
|
-
text: promoConfig?.["promo-text"] || null,
|
|
280
|
+
text: normalizeCmsText(promoConfig?.["promo-text"]) || null,
|
|
255
281
|
code: promoConfig?.["promo-code"] || null,
|
|
256
282
|
value: promoConfig?.["promo-value"] || null,
|
|
257
|
-
active: promoConfig?.["promo-active"] ?? false
|
|
283
|
+
active: promoConfig?.["promo-active"] ?? false,
|
|
258
284
|
};
|
|
259
285
|
}
|
|
260
286
|
catch (error) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
1
|
+
import { HttpTypes } from "@medusajs/types";
|
|
2
|
+
export declare const listCartShippingMethods: (cartId: string) => Promise<HttpTypes.StoreCartShippingOptionWithServiceZone[] | null>;
|
|
3
|
+
export declare const calculatePriceForShippingOption: (optionId: string, cartId: string, data?: Record<string, unknown>) => Promise<HttpTypes.StoreCartShippingOption | null>;
|
|
4
|
+
export declare const getShiprocketServiceability: (pincode: string, variant_id: string, cod?: number) => Promise<import("medusa-services/fulfillment").ShiprocketServiceabilityResult | null>;
|
|
4
5
|
//# sourceMappingURL=fulfillment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fulfillment.d.ts","sourceRoot":"","sources":["../../src/server/fulfillment.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fulfillment.d.ts","sourceRoot":"","sources":["../../src/server/fulfillment.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAQ3C,eAAO,MAAM,uBAAuB,GAAU,QAAQ,MAAM,uEA0B3D,CAAA;AAED,eAAO,MAAM,+BAA+B,GAC1C,UAAU,MAAM,EAChB,QAAQ,MAAM,EACd,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,sDAc/B,CAAA;AAED,eAAO,MAAM,2BAA2B,GAAU,SAAS,MAAM,EAAE,YAAY,MAAM,EAAE,MAAK,MAAU,yFAWrG,CAAA"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { sdk } from "../config";
|
|
3
3
|
import { getAuthHeaders, getCacheOptions } from "../cookies";
|
|
4
|
+
import { medusaShippingOptionCalculate, medusaShiprocketServiceability, } from "medusa-services/fulfillment";
|
|
5
|
+
import { getStoreCartClientOptions } from "../util/store-client";
|
|
4
6
|
export const listCartShippingMethods = async (cartId) => {
|
|
5
7
|
const headers = {
|
|
6
8
|
...(await getAuthHeaders()),
|
|
@@ -24,49 +26,22 @@ export const listCartShippingMethods = async (cartId) => {
|
|
|
24
26
|
});
|
|
25
27
|
};
|
|
26
28
|
export const calculatePriceForShippingOption = async (optionId, cartId, data) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
...(await getCacheOptions("fulfillment")),
|
|
32
|
-
};
|
|
33
|
-
const body = { cart_id: cartId, data };
|
|
34
|
-
if (data) {
|
|
35
|
-
body.data = data;
|
|
29
|
+
try {
|
|
30
|
+
const options = await getStoreCartClientOptions();
|
|
31
|
+
const { shipping_option } = await medusaShippingOptionCalculate(optionId, cartId, options, data);
|
|
32
|
+
return shipping_option;
|
|
36
33
|
}
|
|
37
|
-
|
|
38
|
-
.fetch(`/store/shipping-options/${optionId}/calculate`, {
|
|
39
|
-
method: "POST",
|
|
40
|
-
body,
|
|
41
|
-
headers,
|
|
42
|
-
next,
|
|
43
|
-
})
|
|
44
|
-
.then(({ shipping_option }) => shipping_option)
|
|
45
|
-
.catch((e) => {
|
|
34
|
+
catch (e) {
|
|
46
35
|
return null;
|
|
47
|
-
}
|
|
36
|
+
}
|
|
48
37
|
};
|
|
49
38
|
export const getShiprocketServiceability = async (pincode, variant_id, cod = 0) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
variant_id,
|
|
59
|
-
cod: cod.toString(),
|
|
60
|
-
},
|
|
61
|
-
headers,
|
|
62
|
-
cache: "no-store",
|
|
63
|
-
})
|
|
64
|
-
.then((data) => data)
|
|
65
|
-
.catch(async (e) => {
|
|
66
|
-
if (e.response) {
|
|
67
|
-
const errorData = await e.response.json();
|
|
68
|
-
throw new Error(errorData.message || "Failed to check serviceability");
|
|
69
|
-
}
|
|
70
|
-
throw e;
|
|
71
|
-
});
|
|
39
|
+
try {
|
|
40
|
+
const options = await getStoreCartClientOptions();
|
|
41
|
+
return await medusaShiprocketServiceability({ pincode, variant_id, cod }, options);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Missing variant dimensions or Shiprocket unavailable — checkout must continue.
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
72
47
|
};
|