medusa-storefront-data 1.0.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.
Files changed (109) hide show
  1. package/dist/cookies.d.ts +2 -2
  2. package/dist/cookies.d.ts.map +1 -1
  3. package/dist/edge.d.ts +3 -0
  4. package/dist/edge.d.ts.map +1 -0
  5. package/dist/edge.js +1 -0
  6. package/dist/middleware.d.ts +3 -0
  7. package/dist/middleware.d.ts.map +1 -0
  8. package/dist/middleware.js +1 -0
  9. package/dist/server/cart.d.ts +9 -5
  10. package/dist/server/cart.d.ts.map +1 -1
  11. package/dist/server/cart.js +164 -194
  12. package/dist/server/categories.d.ts +3 -2
  13. package/dist/server/categories.d.ts.map +1 -1
  14. package/dist/server/categories.js +14 -51
  15. package/dist/server/collections.d.ts.map +1 -1
  16. package/dist/server/collections.js +16 -61
  17. package/dist/server/contact.d.ts +34 -0
  18. package/dist/server/contact.d.ts.map +1 -0
  19. package/dist/server/contact.js +57 -0
  20. package/dist/server/customer.d.ts +7 -7
  21. package/dist/server/customer.d.ts.map +1 -1
  22. package/dist/server/customer.js +95 -145
  23. package/dist/server/dynamic-config.d.ts.map +1 -1
  24. package/dist/server/dynamic-config.js +5 -2
  25. package/dist/server/fulfillment.d.ts +4 -3
  26. package/dist/server/fulfillment.d.ts.map +1 -1
  27. package/dist/server/fulfillment.js +16 -41
  28. package/dist/server/guest.d.ts +35 -63
  29. package/dist/server/guest.d.ts.map +1 -1
  30. package/dist/server/guest.js +81 -202
  31. package/dist/server/home.d.ts +15 -0
  32. package/dist/server/home.d.ts.map +1 -0
  33. package/dist/server/home.js +45 -0
  34. package/dist/server/index.d.ts +2 -0
  35. package/dist/server/index.d.ts.map +1 -1
  36. package/dist/server/index.js +2 -0
  37. package/dist/server/locale-actions.d.ts +1 -1
  38. package/dist/server/locale-actions.d.ts.map +1 -1
  39. package/dist/server/locale-actions.js +8 -13
  40. package/dist/server/locales.d.ts +2 -4
  41. package/dist/server/locales.d.ts.map +1 -1
  42. package/dist/server/locales.js +5 -13
  43. package/dist/server/orders.d.ts +5 -11
  44. package/dist/server/orders.d.ts.map +1 -1
  45. package/dist/server/orders.js +126 -267
  46. package/dist/server/payment-details.d.ts +4 -4
  47. package/dist/server/payment-details.d.ts.map +1 -1
  48. package/dist/server/payment-details.js +17 -42
  49. package/dist/server/payment.d.ts +2 -1
  50. package/dist/server/payment.d.ts.map +1 -1
  51. package/dist/server/payment.js +9 -21
  52. package/dist/server/pincode.d.ts +7 -0
  53. package/dist/server/pincode.d.ts.map +1 -0
  54. package/dist/server/pincode.js +30 -0
  55. package/dist/server/products.d.ts +15 -19
  56. package/dist/server/products.d.ts.map +1 -1
  57. package/dist/server/products.js +47 -178
  58. package/dist/server/regions.d.ts +1 -1
  59. package/dist/server/regions.d.ts.map +1 -1
  60. package/dist/server/regions.js +6 -3
  61. package/dist/server/returns.d.ts +4 -4
  62. package/dist/server/returns.d.ts.map +1 -1
  63. package/dist/server/returns.js +50 -154
  64. package/dist/server/swaps.d.ts +3 -3
  65. package/dist/server/swaps.d.ts.map +1 -1
  66. package/dist/server/swaps.js +22 -56
  67. package/dist/server/variants.d.ts.map +1 -1
  68. package/dist/server/variants.js +11 -22
  69. package/dist/server/wishlist.d.ts +11 -0
  70. package/dist/server/wishlist.d.ts.map +1 -0
  71. package/dist/server/wishlist.js +49 -0
  72. package/dist/util/get-locale-header.d.ts +1 -1
  73. package/dist/util/revalidate-cart.d.ts +2 -0
  74. package/dist/util/revalidate-cart.d.ts.map +1 -0
  75. package/dist/util/revalidate-cart.js +8 -0
  76. package/dist/util/sort-products.d.ts +3 -0
  77. package/dist/util/sort-products.d.ts.map +1 -0
  78. package/dist/util/sort-products.js +1 -0
  79. package/dist/util/store-client.d.ts +13 -0
  80. package/dist/util/store-client.d.ts.map +1 -0
  81. package/dist/util/store-client.js +77 -0
  82. package/package.json +95 -37
  83. package/src/edge.ts +2 -0
  84. package/src/middleware.ts +2 -2
  85. package/src/server/cart.ts +214 -267
  86. package/src/server/categories.ts +19 -72
  87. package/src/server/collections.ts +25 -82
  88. package/src/server/contact.ts +92 -0
  89. package/src/server/customer.ts +140 -189
  90. package/src/server/dynamic-config.ts +6 -2
  91. package/src/server/fulfillment.ts +27 -53
  92. package/src/server/guest.ts +159 -276
  93. package/src/server/home.ts +68 -0
  94. package/src/server/index.ts +1 -0
  95. package/src/server/locale-actions.ts +8 -15
  96. package/src/server/locales.ts +6 -18
  97. package/src/server/orders.ts +167 -337
  98. package/src/server/payment-details.ts +24 -52
  99. package/src/server/payment.ts +8 -28
  100. package/src/server/pincode.ts +49 -0
  101. package/src/server/products.ts +72 -235
  102. package/src/server/regions.ts +10 -6
  103. package/src/server/returns.ts +75 -189
  104. package/src/server/swaps.ts +90 -121
  105. package/src/server/variants.ts +9 -28
  106. package/src/util/revalidate-cart.ts +10 -0
  107. package/src/util/sort-products.ts +2 -47
  108. package/src/util/store-client.ts +93 -0
  109. package/src/services/middleware.ts +0 -54
@@ -1,109 +1,81 @@
1
+ import { type GuestReturnItem } from "medusa-services/guest";
1
2
  /**
2
3
  * Compatibility wrapper for sendOTP
3
4
  */
4
- export declare function sendOTP(email: string, type?: string): Promise<{
5
- success: boolean;
6
- error?: undefined;
7
- } | {
8
- success: boolean;
9
- error: any;
10
- } | {
11
- success: boolean;
12
- token: string;
13
- }>;
5
+ export declare function sendOTP(email: string, type?: string): Promise<import("medusa-services/guest").GuestOtpResponse>;
14
6
  /**
15
7
  * Compatibility wrapper for verifyOTP
16
8
  */
17
- export declare function verifyOTP(email: string, token: string, otp: string): Promise<{
18
- success: boolean;
19
- token: any;
20
- error?: undefined;
21
- } | {
22
- success: boolean;
23
- error: any;
24
- token?: undefined;
25
- }>;
9
+ export declare function verifyOTP(email: string, token: string, otp: string): Promise<import("medusa-services/guest").GuestOtpResponse>;
26
10
  /**
27
11
  * Compatibility wrapper for listGuestOrders
28
12
  */
29
13
  export declare function listGuestOrders(token: string): Promise<{
30
- orders: any[];
14
+ orders: {
15
+ id?: string;
16
+ }[];
31
17
  count: number;
32
18
  }>;
33
- export declare function requestGuestOTP(email: string): Promise<{
34
- success: boolean;
35
- error?: undefined;
36
- } | {
37
- success: boolean;
38
- error: any;
39
- }>;
40
- export declare function verifyGuestOTP(email: string, otp: string): Promise<{
41
- success: boolean;
42
- token: any;
43
- error?: undefined;
44
- } | {
45
- success: boolean;
46
- error: any;
47
- token?: undefined;
48
- }>;
19
+ export declare function requestGuestOTP(email: string): Promise<import("medusa-services/guest").GuestOtpResponse>;
20
+ export declare function verifyGuestOTP(email: string, otp: string): Promise<import("medusa-services/guest").GuestOtpResponse>;
49
21
  export declare function logoutGuest(): Promise<{
50
22
  success: boolean;
51
23
  }>;
52
24
  export declare function getGuestOrders(token?: string): Promise<{
53
25
  success: boolean;
54
- orders: any;
55
- error?: undefined;
26
+ error: string;
27
+ orders?: undefined;
56
28
  } | {
57
29
  success: boolean;
58
- error: any;
59
- orders?: undefined;
30
+ orders: Record<string, unknown>[];
31
+ error?: undefined;
60
32
  }>;
61
33
  export declare function getGuestOrder(id: string, token?: string): Promise<{
62
34
  success: boolean;
63
- order: any;
64
- error?: undefined;
35
+ error: string;
36
+ order?: undefined;
65
37
  } | {
66
38
  success: boolean;
67
- error: any;
68
- order?: undefined;
39
+ order: Record<string, unknown>;
40
+ error?: undefined;
69
41
  }>;
70
42
  export declare function cancelGuestOrder(orderId: string, token?: string): Promise<{
71
43
  success: boolean;
72
- error?: undefined;
44
+ error: string;
73
45
  } | {
74
46
  success: boolean;
75
- error: any;
47
+ error?: undefined;
76
48
  }>;
77
49
  export declare function getGuestOrderInvoice(orderId: string, token?: string): Promise<{
78
50
  success: boolean;
79
- type: string;
80
- data: any;
51
+ error: string;
52
+ } | {
53
+ type: "pdf";
54
+ data: string;
55
+ success: boolean;
81
56
  error?: undefined;
82
57
  } | {
58
+ type: "json";
59
+ data: unknown;
83
60
  success: boolean;
84
- error: any;
85
- type?: undefined;
86
- data?: undefined;
61
+ error?: undefined;
87
62
  }>;
88
63
  export declare function guestReorder(orderId: string, token?: string): Promise<{
89
64
  success: boolean;
90
- data: any;
91
- error?: undefined;
65
+ error: string;
66
+ data?: undefined;
92
67
  } | {
93
68
  success: boolean;
94
- error: any;
95
- data?: undefined;
69
+ data: import("medusa-services/orders").MedusaOrderReorderResponse;
70
+ error?: undefined;
96
71
  }>;
97
- export declare function createGuestReturn(orderId: string, items: {
98
- id: string;
99
- quantity: number;
100
- }[], reason_id?: string, note?: string, token?: string): Promise<{
72
+ export declare function createGuestReturn(orderId: string, items: GuestReturnItem[], reason_id?: string, note?: string, token?: string): Promise<{
101
73
  success: boolean;
102
- data: any;
103
- error?: undefined;
74
+ error: string;
75
+ data?: undefined;
104
76
  } | {
105
77
  success: boolean;
106
- error: any;
107
- data?: undefined;
78
+ data: import("medusa-services/returns").StoreReturn;
79
+ error?: undefined;
108
80
  }>;
109
81
  //# sourceMappingURL=guest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"guest.d.ts","sourceRoot":"","sources":["../../src/server/guest.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,MAA6B;;;;;;;;;GAQ/E;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;;;;;;;;GAIxE;AAID;;GAEG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM;;;GAmBlD;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM;;;;;;GAsBlD;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;;;;;;;;GAqC9D;AAED,wBAAsB,WAAW;;GAOhC;AAED,wBAAsB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM;;;;;;;;GA4BlD;AAED,wBAAsB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;;;;;;;;GAgC7D;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;;;;;;GA8BrE;AAED,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;;;;;;;;;;GAoCzE;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;;;;;;;;GA+BjE;AAED,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;;;;;;;;GAoCpJ"}
1
+ {"version":3,"file":"guest.d.ts","sourceRoot":"","sources":["../../src/server/guest.ts"],"names":[],"mappings":"AAEA,OAAO,EAOL,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAA;AAsB9B;;GAEG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,MAA6B,6DAO/E;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,6DAExE;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM;;aAOH,MAAM;;;GAUrD;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM,6DAGlD;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,6DAe9D;AAED,wBAAsB,WAAW;;GAOhC;AAED,wBAAsB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM;;;;;;;;GAclD;AAED,wBAAsB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;;;;;;;;GAkB7D;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;;;;;;GAcrE;AAED,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;;;;;;;;;;;;;GAczE;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;;;;;;;;GAqBjE;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,eAAe,EAAE,EACxB,SAAS,CAAC,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM;;;;;;;;GAef"}
@@ -1,16 +1,27 @@
1
1
  "use server";
2
+ import { medusaGuestOrderCancelSimple, medusaGuestOrderInvoice, medusaGuestOrderList, medusaGuestOrderRetrieve, medusaGuestOtpRequest, medusaGuestOtpVerify, } from "medusa-services/guest";
3
+ import { medusaGuestOrderReorder } from "medusa-services/orders";
4
+ import { medusaReturnCreateGuest } from "medusa-services/returns";
2
5
  import { cookies, headers } from "next/headers";
3
- import { getGuestAuthHeaders } from "../cookies";
4
- import { sdk } from "../config";
5
- const BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL || "http://localhost:9000";
6
- const PUBLISHABLE_KEY = process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY;
6
+ import { getStoreClientOptions, getStoreClientOptionsWithToken, } from "../util/store-client";
7
+ import { retrieveOrder } from "./orders";
8
+ async function resolveGuestToken(token) {
9
+ if (token)
10
+ return token;
11
+ const headersStore = await headers();
12
+ const authHeader = headersStore.get("authorization");
13
+ const headerToken = authHeader?.startsWith("Bearer ") ? authHeader.split(" ")[1] : undefined;
14
+ if (headerToken)
15
+ return headerToken;
16
+ const cookieStore = await cookies();
17
+ return cookieStore.get("_medusa_guest_jwt")?.value ?? null;
18
+ }
7
19
  /**
8
20
  * Compatibility wrapper for sendOTP
9
21
  */
10
22
  export async function sendOTP(email, type = "email_verification") {
11
- const res = await requestGuestOTP(email);
12
- // The previous project expected a token or success.
13
- // We return a dummy token if successful because the UI checks for it.
23
+ const options = await getStoreClientOptions();
24
+ const res = await medusaGuestOtpRequest(email, options);
14
25
  if (res.success) {
15
26
  return { success: true, token: "otp_sent_successfully" };
16
27
  }
@@ -20,11 +31,8 @@ export async function sendOTP(email, type = "email_verification") {
20
31
  * Compatibility wrapper for verifyOTP
21
32
  */
22
33
  export async function verifyOTP(email, token, otp) {
23
- // The previous implementation used 3 args, but guest.ts uses 2.
24
- // We ignore the mid 'token' as per user's working code.
25
- return await verifyGuestOTP(email, otp);
34
+ return verifyGuestOTP(email, otp);
26
35
  }
27
- import { retrieveOrder } from "./orders";
28
36
  /**
29
37
  * Compatibility wrapper for listGuestOrders
30
38
  */
@@ -33,76 +41,33 @@ export async function listGuestOrders(token) {
33
41
  if (!res.success) {
34
42
  throw new Error(res.error || "Failed to fetch orders");
35
43
  }
36
- // Fetch full details for each order to ensure latest fulfillment_status is available
37
- // because the custom list endpoint might not return all fields correctly.
38
44
  const fullOrders = await Promise.all((res.orders || []).map(async (order) => {
39
45
  try {
40
46
  return await retrieveOrder(order.id);
41
47
  }
42
- catch (e) {
48
+ catch {
43
49
  return order;
44
50
  }
45
51
  }));
46
52
  return { orders: fullOrders, count: fullOrders.length };
47
53
  }
48
54
  export async function requestGuestOTP(email) {
49
- const headers = {
50
- "Content-Type": "application/json",
51
- };
52
- if (PUBLISHABLE_KEY)
53
- headers["x-publishable-api-key"] = PUBLISHABLE_KEY;
54
- try {
55
- const res = await fetch(`${BACKEND_URL}/store/otp/request`, {
56
- method: "POST",
57
- headers,
58
- body: JSON.stringify({ email }),
59
- cache: "no-store",
60
- });
61
- if (!res.ok) {
62
- const errorData = await res.json().catch(() => ({}));
63
- throw new Error(errorData.message || "Failed to send OTP");
64
- }
65
- return { success: true };
66
- }
67
- catch (error) {
68
- return { success: false, error: error.message };
69
- }
55
+ const options = await getStoreClientOptions();
56
+ return medusaGuestOtpRequest(email, options);
70
57
  }
71
58
  export async function verifyGuestOTP(email, otp) {
72
- const headers = {
73
- "Content-Type": "application/json",
74
- };
75
- if (PUBLISHABLE_KEY)
76
- headers["x-publishable-api-key"] = PUBLISHABLE_KEY;
77
- try {
78
- const res = await fetch(`${BACKEND_URL}/store/otp/verify`, {
79
- method: "POST",
80
- headers,
81
- body: JSON.stringify({ email, otp }),
82
- cache: "no-store",
59
+ const options = await getStoreClientOptions();
60
+ const res = await medusaGuestOtpVerify(email, otp, options);
61
+ if (res.success && res.token) {
62
+ const cookieStore = await cookies();
63
+ cookieStore.set("_medusa_guest_jwt", res.token, {
64
+ httpOnly: true,
65
+ secure: process.env.NODE_ENV === "production",
66
+ maxAge: 60 * 60 * 24,
67
+ path: "/",
83
68
  });
84
- if (!res.ok) {
85
- const errorData = await res.json().catch(() => ({}));
86
- throw new Error(errorData.message || "Failed to verify OTP");
87
- }
88
- const data = await res.json();
89
- if (data.token) {
90
- const cookieStore = await cookies();
91
- cookieStore.set("_medusa_guest_jwt", data.token, {
92
- httpOnly: true,
93
- secure: process.env.NODE_ENV === "production",
94
- maxAge: 60 * 60 * 24, // 1 day
95
- path: "/",
96
- });
97
- }
98
- else {
99
- throw new Error("No token returned");
100
- }
101
- return { success: true, token: data.token };
102
- }
103
- catch (error) {
104
- return { success: false, error: error.message };
105
69
  }
70
+ return res;
106
71
  }
107
72
  export async function logoutGuest() {
108
73
  const cookieStore = await cookies();
@@ -113,192 +78,106 @@ export async function logoutGuest() {
113
78
  return { success: true };
114
79
  }
115
80
  export async function getGuestOrders(token) {
116
- const cookieStore = await cookies();
117
- const headersStore = await headers();
118
- const authHeader = headersStore.get("authorization");
119
- const headerToken = authHeader?.startsWith("Bearer ") ? authHeader.split(" ")[1] : undefined;
120
- const authToken = token || headerToken || cookieStore.get("_medusa_guest_jwt")?.value;
81
+ const authToken = await resolveGuestToken(token);
121
82
  if (!authToken)
122
83
  return { success: false, error: "Unauthorized" };
123
- const requestHeaders = {
124
- "Authorization": `Bearer ${authToken}`
125
- };
126
- if (PUBLISHABLE_KEY)
127
- requestHeaders["x-publishable-api-key"] = PUBLISHABLE_KEY;
128
84
  try {
129
- const response = await sdk.client.fetch(`/store/guest-orders`, {
130
- method: "GET",
131
- headers: requestHeaders,
132
- query: {
133
- fields: "id,display_id,status,fulfillment_status,payment_status,created_at,currency_code,total,subtotal,tax_total,shipping_total,discount_total,metadata,email,*items,*items.variant,*items.variant.product"
134
- },
135
- cache: "no-store",
136
- });
85
+ const options = await getStoreClientOptions();
86
+ const response = await medusaGuestOrderList(authToken, options);
137
87
  return { success: true, orders: response.orders || [] };
138
88
  }
139
89
  catch (error) {
140
- return { success: false, error: error.message };
90
+ return {
91
+ success: false,
92
+ error: error instanceof Error ? error.message : String(error),
93
+ };
141
94
  }
142
95
  }
143
96
  export async function getGuestOrder(id, token) {
144
- const cookieStore = await cookies();
145
- const headersStore = await headers();
146
- const authHeader = headersStore.get("authorization");
147
- const headerToken = authHeader?.startsWith("Bearer ") ? authHeader.split(" ")[1] : undefined;
148
- const authToken = token || headerToken || cookieStore.get("_medusa_guest_jwt")?.value;
97
+ const authToken = await resolveGuestToken(token);
149
98
  if (!authToken)
150
99
  return { success: false, error: "Unauthorized" };
151
- const requestHeaders = {
152
- "Authorization": `Bearer ${authToken}`
153
- };
154
- if (PUBLISHABLE_KEY)
155
- requestHeaders["x-publishable-api-key"] = PUBLISHABLE_KEY;
156
100
  try {
157
- const response = await sdk.client.fetch(`/store/orders/${id}`, {
158
- method: "GET",
159
- headers: requestHeaders,
160
- query: {
161
- fields: "*payment_collections.payments,*items,*items.metadata,*items.variant,*items.variant.images,*items.variant.product,*items.variant.product.thumbnail,*items.variant.product.images,*items.product,*items.product.thumbnail,*items.product.images,*fulfillments,*fulfillments.items,*fulfillments.location_id,*returns,*returns.items,*cart,*shipping_address,*billing_address,*region,*shipping_methods"
162
- },
163
- cache: "no-store"
164
- });
101
+ const options = await getStoreClientOptions();
102
+ const response = await medusaGuestOrderRetrieve(id, authToken, options);
165
103
  if (response.order) {
166
104
  return { success: true, order: response.order };
167
105
  }
168
- else {
169
- return { success: false, error: "Order not found" };
170
- }
106
+ return { success: false, error: "Order not found" };
171
107
  }
172
108
  catch (error) {
173
- return { success: false, error: error.message };
109
+ return {
110
+ success: false,
111
+ error: error instanceof Error ? error.message : String(error),
112
+ };
174
113
  }
175
114
  }
176
115
  export async function cancelGuestOrder(orderId, token) {
177
- const authHeaders = await getGuestAuthHeaders();
178
- const authToken = token || authHeaders.authorization?.split(" ")[1];
116
+ const authToken = await resolveGuestToken(token);
179
117
  if (!authToken)
180
118
  return { success: false, error: "Unauthorized" };
181
- const requestHeaders = {
182
- "Authorization": `Bearer ${authToken}`
183
- };
184
- if (PUBLISHABLE_KEY)
185
- requestHeaders["x-publishable-api-key"] = PUBLISHABLE_KEY;
186
119
  try {
187
- const response = await fetch(`${BACKEND_URL}/store/guest-orders/${orderId}/cancel`, {
188
- method: "POST",
189
- headers: {
190
- "Content-Type": "application/json",
191
- ...requestHeaders
192
- },
193
- cache: "no-store",
194
- });
195
- if (!response.ok) {
196
- const errorData = await response.json().catch(() => ({}));
197
- throw new Error(errorData.message || "Failed to cancel order");
198
- }
120
+ const options = await getStoreClientOptions();
121
+ await medusaGuestOrderCancelSimple(orderId, authToken, options);
199
122
  return { success: true };
200
123
  }
201
124
  catch (error) {
202
- return { success: false, error: error.message };
125
+ return {
126
+ success: false,
127
+ error: error instanceof Error ? error.message : String(error),
128
+ };
203
129
  }
204
130
  }
205
131
  export async function getGuestOrderInvoice(orderId, token) {
206
- const authHeaders = await getGuestAuthHeaders();
207
- const authToken = token || authHeaders.authorization?.split(" ")[1];
132
+ const authToken = await resolveGuestToken(token);
208
133
  if (!authToken)
209
134
  return { success: false, error: "Unauthorized" };
210
- const requestHeaders = {
211
- "Authorization": `Bearer ${authToken}`
212
- };
213
- if (PUBLISHABLE_KEY)
214
- requestHeaders["x-publishable-api-key"] = PUBLISHABLE_KEY;
215
135
  try {
216
- const response = await fetch(`${BACKEND_URL}/store/guest/invoice/download/${orderId}`, {
217
- method: "GET",
218
- headers: requestHeaders,
219
- cache: "no-store",
220
- });
221
- if (!response.ok) {
222
- const errorData = await response.json().catch(() => ({}));
223
- throw new Error(errorData.message || "Failed to get invoice");
224
- }
225
- const contentType = response.headers.get("content-type");
226
- if (contentType && contentType.includes("application/pdf")) {
227
- const arrayBuffer = await response.arrayBuffer();
228
- const base64 = Buffer.from(arrayBuffer).toString('base64');
229
- return { success: true, type: 'pdf', data: base64 };
230
- }
231
- else {
232
- const data = await response.json();
233
- return { success: true, type: 'json', data };
234
- }
136
+ const options = await getStoreClientOptions();
137
+ const result = await medusaGuestOrderInvoice(orderId, authToken, options);
138
+ return { success: true, ...result };
235
139
  }
236
140
  catch (error) {
237
- return { success: false, error: error.message };
141
+ return {
142
+ success: false,
143
+ error: error instanceof Error ? error.message : String(error),
144
+ };
238
145
  }
239
146
  }
240
147
  export async function guestReorder(orderId, token) {
241
- const authHeaders = await getGuestAuthHeaders();
242
- const authToken = token || authHeaders.authorization?.split(" ")[1];
148
+ const authToken = await resolveGuestToken(token);
243
149
  if (!authToken)
244
150
  return { success: false, error: "Unauthorized" };
245
- const requestHeaders = {
246
- "Authorization": `Bearer ${authToken}`
247
- };
248
- if (PUBLISHABLE_KEY)
249
- requestHeaders["x-publishable-api-key"] = PUBLISHABLE_KEY;
250
151
  try {
251
- const response = await fetch(`${BACKEND_URL}/store/guest-orders/${orderId}/reorder`, {
252
- method: "POST",
253
- headers: {
254
- "Content-Type": "application/json",
255
- ...requestHeaders
256
- },
257
- cache: "no-store",
258
- });
259
- if (!response.ok) {
260
- const errorData = await response.json().catch(() => ({}));
261
- throw new Error(errorData.message || "Failed to reorder");
152
+ const options = await getStoreClientOptionsWithToken(authToken);
153
+ const result = await medusaGuestOrderReorder(orderId, options);
154
+ if (!result.ok) {
155
+ throw new Error(typeof result.data.message === "string"
156
+ ? result.data.message
157
+ : "Failed to reorder");
262
158
  }
263
- const data = await response.json();
264
- return { success: true, data };
159
+ return { success: true, data: result.data };
265
160
  }
266
161
  catch (error) {
267
- return { success: false, error: error.message };
162
+ return {
163
+ success: false,
164
+ error: error instanceof Error ? error.message : String(error),
165
+ };
268
166
  }
269
167
  }
270
168
  export async function createGuestReturn(orderId, items, reason_id, note, token) {
271
- const authHeaders = await getGuestAuthHeaders();
272
- const authToken = token || authHeaders.authorization?.split(" ")[1];
169
+ const authToken = await resolveGuestToken(token);
273
170
  if (!authToken)
274
171
  return { success: false, error: "Unauthorized" };
275
- const requestHeaders = {
276
- "Authorization": `Bearer ${authToken}`
277
- };
278
- if (PUBLISHABLE_KEY)
279
- requestHeaders["x-publishable-api-key"] = PUBLISHABLE_KEY;
280
172
  try {
281
- const response = await fetch(`${BACKEND_URL}/store/guest-orders/${orderId}/returns`, {
282
- method: "POST",
283
- headers: {
284
- "Content-Type": "application/json",
285
- ...requestHeaders
286
- },
287
- body: JSON.stringify({
288
- items,
289
- reason_id,
290
- note
291
- }),
292
- cache: "no-store",
293
- });
294
- if (!response.ok) {
295
- const errorData = await response.json().catch(() => ({}));
296
- throw new Error(errorData.message || "Failed to create return request");
297
- }
298
- const data = await response.json();
173
+ const options = await getStoreClientOptionsWithToken(authToken);
174
+ const data = await medusaReturnCreateGuest(orderId, { items, reason_id, note }, options);
299
175
  return { success: true, data };
300
176
  }
301
177
  catch (error) {
302
- return { success: false, error: error.message };
178
+ return {
179
+ success: false,
180
+ error: error instanceof Error ? error.message : String(error),
181
+ };
303
182
  }
304
183
  }
@@ -0,0 +1,15 @@
1
+ import { getRegion } from "./regions";
2
+ export type HomePageData = {
3
+ region: Awaited<ReturnType<typeof getRegion>>;
4
+ collections: Array<Record<string, unknown>>;
5
+ categories: unknown[];
6
+ newArrivals: unknown[];
7
+ bestsellers: unknown[];
8
+ testimonials: unknown | null;
9
+ ratings: unknown[];
10
+ };
11
+ /**
12
+ * Parallel home page data loader (replaces per-page Promise.all boilerplate).
13
+ */
14
+ export declare function loadHomePageData(countryCode: string): Promise<HomePageData | null>;
15
+ //# sourceMappingURL=home.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"home.d.ts","sourceRoot":"","sources":["../../src/server/home.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAItC,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC;IAC9C,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5C,UAAU,EAAE,OAAO,EAAE,CAAC;IACtB,WAAW,EAAE,OAAO,EAAE,CAAC;IACvB,WAAW,EAAE,OAAO,EAAE,CAAC;IACvB,YAAY,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B,OAAO,EAAE,OAAO,EAAE,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CA6CxF"}
@@ -0,0 +1,45 @@
1
+ "use server";
2
+ import { listCollections } from "./collections";
3
+ import { listCategories } from "./categories";
4
+ import { listProductsWithSort, getProductsByTag } from "./products";
5
+ import { getRegion } from "./regions";
6
+ import { getTestimonialsFromConfig } from "./dynamic-config";
7
+ import { fetchRatings } from "medusa-reviews-logic/server";
8
+ /**
9
+ * Parallel home page data loader (replaces per-page Promise.all boilerplate).
10
+ */
11
+ export async function loadHomePageData(countryCode) {
12
+ const region = await getRegion(countryCode);
13
+ if (!region)
14
+ return null;
15
+ const [collectionsResult, categoriesResult, newArrivalsResult, bestsellersResult, testimonialsData, allRatings,] = await Promise.all([
16
+ listCollections({ fields: "id, handle, title, metadata" }).catch(() => ({
17
+ collections: [],
18
+ })),
19
+ listCategories({ limit: 50 }).catch(() => []),
20
+ listProductsWithSort({
21
+ page: 1,
22
+ queryParams: { limit: 8 },
23
+ sortBy: "created_at",
24
+ countryCode,
25
+ }).catch(() => ({ response: { products: [] } })),
26
+ getProductsByTag({
27
+ tagValue: "bestseller",
28
+ limit: 10,
29
+ countryCode,
30
+ }).catch(() => []),
31
+ getTestimonialsFromConfig().catch(() => null),
32
+ fetchRatings(),
33
+ ]);
34
+ const collections = collectionsResult.collections ?? [];
35
+ const newArrivals = newArrivalsResult.response?.products ?? [];
36
+ return {
37
+ region,
38
+ collections: collections,
39
+ categories: categoriesResult ?? [],
40
+ newArrivals,
41
+ bestsellers: bestsellersResult ?? [],
42
+ testimonials: testimonialsData,
43
+ ratings: allRatings ?? [],
44
+ };
45
+ }
@@ -18,4 +18,6 @@ export * from "./regions";
18
18
  export * from "./returns";
19
19
  export * from "./swaps";
20
20
  export * from "./variants";
21
+ export * from "./wishlist";
22
+ export * from "./home";
21
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,yBAAyB,CAAA;AACvC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA;AACvB,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,yBAAyB,CAAA;AACvC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA;AACvB,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,QAAQ,CAAA"}
@@ -18,3 +18,5 @@ export * from "./regions";
18
18
  export * from "./returns";
19
19
  export * from "./swaps";
20
20
  export * from "./variants";
21
+ export * from "./wishlist";
22
+ export * from "./home";
@@ -7,7 +7,7 @@ export declare const getLocale: () => Promise<string | null>;
7
7
  */
8
8
  export declare const setLocaleCookie: (locale: string) => Promise<void>;
9
9
  /**
10
- * Updates the locale preference via SDK and stores in cookie.
10
+ * Updates the locale preference and stores in cookie.
11
11
  * Also updates the cart with the new locale if one exists.
12
12
  */
13
13
  export declare const updateLocale: (localeCode: string) => Promise<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"locale-actions.d.ts","sourceRoot":"","sources":["../../src/server/locale-actions.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,eAAO,MAAM,SAAS,QAAa,OAAO,CAAC,MAAM,GAAG,IAAI,CAOvD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,GAAU,QAAQ,MAAM,kBAQnD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAU,YAAY,MAAM,KAAG,OAAO,CAAC,MAAM,CAmCrE,CAAA"}
1
+ {"version":3,"file":"locale-actions.d.ts","sourceRoot":"","sources":["../../src/server/locale-actions.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,eAAO,MAAM,SAAS,QAAa,OAAO,CAAC,MAAM,GAAG,IAAI,CAOvD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,GAAU,QAAQ,MAAM,kBAQnD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAU,YAAY,MAAM,KAAG,OAAO,CAAC,MAAM,CA0BrE,CAAA"}