medusa-services 1.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/auth.d.ts +29 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +80 -0
- package/dist/cart.d.ts +148 -0
- package/dist/cart.d.ts.map +1 -0
- package/dist/cart.js +156 -0
- package/dist/categories.d.ts +20 -0
- package/dist/categories.d.ts.map +1 -0
- package/dist/categories.js +36 -0
- package/dist/collections.d.ts +27 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +36 -0
- package/dist/contact-action.d.ts +18 -0
- package/dist/contact-action.d.ts.map +1 -0
- package/dist/contact-action.js +42 -0
- package/dist/customer.d.ts +59 -0
- package/dist/customer.d.ts.map +1 -0
- package/dist/customer.js +68 -0
- package/dist/facebook-login.d.ts +37 -0
- package/dist/facebook-login.d.ts.map +1 -0
- package/dist/facebook-login.js +146 -0
- package/dist/fulfillment.d.ts +33 -0
- package/dist/fulfillment.d.ts.map +1 -0
- package/dist/fulfillment.js +43 -0
- package/dist/gift-wrap.d.ts +30 -0
- package/dist/gift-wrap.d.ts.map +1 -0
- package/dist/gift-wrap.js +29 -0
- package/dist/google-login.d.ts +37 -0
- package/dist/google-login.d.ts.map +1 -0
- package/dist/google-login.js +150 -0
- package/dist/guest.d.ts +46 -0
- package/dist/guest.d.ts.map +1 -0
- package/dist/guest.js +91 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/locales.d.ts +13 -0
- package/dist/locales.d.ts.map +1 -0
- package/dist/locales.js +13 -0
- package/dist/medusa-auth.d.ts +17 -0
- package/dist/medusa-auth.d.ts.map +1 -0
- package/dist/medusa-auth.js +25 -0
- package/dist/middleware.d.ts +13 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +36 -0
- package/dist/orders.d.ts +105 -0
- package/dist/orders.d.ts.map +1 -0
- package/dist/orders.js +139 -0
- package/dist/payment.d.ts +55 -0
- package/dist/payment.d.ts.map +1 -0
- package/dist/payment.js +68 -0
- package/dist/product-detail.d.ts +30 -0
- package/dist/product-detail.d.ts.map +1 -0
- package/dist/product-detail.js +94 -0
- package/dist/product-listing.d.ts +81 -0
- package/dist/product-listing.d.ts.map +1 -0
- package/dist/product-listing.js +189 -0
- package/dist/products.d.ts +41 -0
- package/dist/products.d.ts.map +1 -0
- package/dist/products.js +141 -0
- package/dist/recently-viewed.d.ts +14 -0
- package/dist/recently-viewed.d.ts.map +1 -0
- package/dist/recently-viewed.js +59 -0
- package/dist/regions.d.ts +37 -0
- package/dist/regions.d.ts.map +1 -0
- package/dist/regions.js +30 -0
- package/dist/related-products.d.ts +30 -0
- package/dist/related-products.d.ts.map +1 -0
- package/dist/related-products.js +99 -0
- package/dist/returns.d.ts +75 -0
- package/dist/returns.d.ts.map +1 -0
- package/dist/returns.js +105 -0
- package/dist/reviews.d.ts +135 -0
- package/dist/reviews.d.ts.map +1 -0
- package/dist/reviews.js +202 -0
- package/dist/store-api.d.ts +20 -0
- package/dist/store-api.d.ts.map +1 -0
- package/dist/store-api.js +55 -0
- package/dist/swaps.d.ts +33 -0
- package/dist/swaps.d.ts.map +1 -0
- package/dist/swaps.js +39 -0
- package/dist/variants.d.ts +17 -0
- package/dist/variants.d.ts.map +1 -0
- package/dist/variants.js +8 -0
- package/dist/wishlist.d.ts +65 -0
- package/dist/wishlist.d.ts.map +1 -0
- package/dist/wishlist.js +149 -0
- package/middleware.ts +54 -0
- package/package.json +174 -0
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type MedusaStoreClientOptions } from "./store-api";
|
|
2
|
+
export interface MedusaAuthClientOptions {
|
|
3
|
+
backendUrl: string;
|
|
4
|
+
authorization?: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* POST /auth/customer/emailpass/register
|
|
9
|
+
*/
|
|
10
|
+
export declare function medusaAuthRegister(body: {
|
|
11
|
+
email: string;
|
|
12
|
+
password: string;
|
|
13
|
+
}, options: MedusaAuthClientOptions): Promise<string>;
|
|
14
|
+
export interface MedusaAuthLoginBody {
|
|
15
|
+
email?: string;
|
|
16
|
+
email_or_phone?: string;
|
|
17
|
+
password: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* POST /auth/customer/emailpass
|
|
21
|
+
*/
|
|
22
|
+
export declare function medusaAuthLogin(body: MedusaAuthLoginBody, options: MedusaAuthClientOptions): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* DELETE /auth/session
|
|
25
|
+
*/
|
|
26
|
+
export declare function medusaAuthLogout(options: MedusaAuthClientOptions): Promise<void>;
|
|
27
|
+
export declare function getAuthClientOptions(backendUrl: string, authorization?: string): MedusaAuthClientOptions;
|
|
28
|
+
export declare function getStoreAuthOptions(storeOptions: MedusaStoreClientOptions): MedusaAuthClientOptions;
|
|
29
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,wBAAwB,EAChC,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,uBAAuB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AA0CD;;GAEG;AACH,wBAAsB,kBAAkB,CACpC,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EACzC,OAAO,EAAE,uBAAuB,GACjC,OAAO,CAAC,MAAM,CAAC,CAOjB;AAED,MAAM,WAAW,mBAAmB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAsB,eAAe,CACjC,IAAI,EAAE,mBAAmB,EACzB,OAAO,EAAE,uBAAuB,GACjC,OAAO,CAAC,MAAM,CAAC,CAOjB;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAOtF;AAED,wBAAgB,oBAAoB,CAChC,UAAU,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,MAAM,GACvB,uBAAuB,CAKzB;AAED,wBAAgB,mBAAmB,CAC/B,YAAY,EAAE,wBAAwB,GACvC,uBAAuB,CAMzB"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { parseStoreErrorMessage, parseStoreJson, } from "./store-api";
|
|
2
|
+
function normalizeBackendUrl(backendUrl) {
|
|
3
|
+
return backendUrl.replace(/\/$/, "");
|
|
4
|
+
}
|
|
5
|
+
async function authFetch(path, options, init) {
|
|
6
|
+
const url = `${normalizeBackendUrl(options.backendUrl)}/auth${path}`;
|
|
7
|
+
return fetch(url, {
|
|
8
|
+
...init,
|
|
9
|
+
headers: {
|
|
10
|
+
"Content-Type": "application/json",
|
|
11
|
+
...options.headers,
|
|
12
|
+
...(options.authorization
|
|
13
|
+
? {
|
|
14
|
+
Authorization: options.authorization.startsWith("Bearer ")
|
|
15
|
+
? options.authorization
|
|
16
|
+
: `Bearer ${options.authorization}`,
|
|
17
|
+
}
|
|
18
|
+
: {}),
|
|
19
|
+
...init.headers,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function extractAuthToken(data) {
|
|
24
|
+
if (typeof data === "string" && data.trim()) {
|
|
25
|
+
return data.trim();
|
|
26
|
+
}
|
|
27
|
+
if (data && typeof data === "object" && "token" in data) {
|
|
28
|
+
const token = data.token;
|
|
29
|
+
if (typeof token === "string" && token.trim()) {
|
|
30
|
+
return token.trim();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw new Error("No authentication token received");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* POST /auth/customer/emailpass/register
|
|
37
|
+
*/
|
|
38
|
+
export async function medusaAuthRegister(body, options) {
|
|
39
|
+
const response = await authFetch("/customer/emailpass/register", options, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
body: JSON.stringify(body),
|
|
42
|
+
});
|
|
43
|
+
const data = await parseStoreJson(response, "Registration request");
|
|
44
|
+
return extractAuthToken(data);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* POST /auth/customer/emailpass
|
|
48
|
+
*/
|
|
49
|
+
export async function medusaAuthLogin(body, options) {
|
|
50
|
+
const response = await authFetch("/customer/emailpass", options, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
body: JSON.stringify(body),
|
|
53
|
+
});
|
|
54
|
+
const data = await parseStoreJson(response, "Login request");
|
|
55
|
+
return extractAuthToken(data);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* DELETE /auth/session
|
|
59
|
+
*/
|
|
60
|
+
export async function medusaAuthLogout(options) {
|
|
61
|
+
const response = await authFetch("/session", options, {
|
|
62
|
+
method: "DELETE",
|
|
63
|
+
});
|
|
64
|
+
if (!response.ok && response.status !== 401) {
|
|
65
|
+
throw new Error(await parseStoreErrorMessage(response, "Logout request"));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export function getAuthClientOptions(backendUrl, authorization) {
|
|
69
|
+
return {
|
|
70
|
+
backendUrl,
|
|
71
|
+
authorization,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export function getStoreAuthOptions(storeOptions) {
|
|
75
|
+
return {
|
|
76
|
+
backendUrl: storeOptions.backendUrl,
|
|
77
|
+
authorization: storeOptions.authorization,
|
|
78
|
+
headers: storeOptions.headers,
|
|
79
|
+
};
|
|
80
|
+
}
|
package/dist/cart.d.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { type MedusaStoreCartClientOptions } from "./store-api";
|
|
2
|
+
export type { MedusaStoreCartClientOptions } from "./store-api";
|
|
3
|
+
/** Default `fields` for cart detail pages (tweak per backend / performance). */
|
|
4
|
+
export declare const MEDUSA_STORE_CART_DEFAULT_FIELDS = "*items,*items.variant,*items.variant.product,*items.product,*promotions,*region";
|
|
5
|
+
/** Rich `fields` used by Next.js storefront cart pages. */
|
|
6
|
+
export declare const MEDUSA_STORE_CART_DETAIL_FIELDS = "*items, *region, *items.product, *items.product.thumbnail, *items.product.images, *items.product.options, *items.product.variants, +items.product.variants.inventory_quantity, +items.product.variants.manage_inventory, +items.product.variants.allow_backorder, *items.product.variants.options, *items.variant, +items.variant.inventory_quantity, +items.variant.manage_inventory, +items.variant.allow_backorder, *items.variant.images, *items.variant.product, *items.variant.product.thumbnail, *items.variant.product.images, *items.variant.options, *items.thumbnail, *items.metadata, +items.total, +items.adjustments, *promotions, +shipping_methods.name, +shipping_methods.adjustments";
|
|
7
|
+
export interface StoreCartPromotion {
|
|
8
|
+
id: string;
|
|
9
|
+
code?: string | null;
|
|
10
|
+
is_automatic?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface StoreCartLineItem {
|
|
13
|
+
id: string;
|
|
14
|
+
title?: string;
|
|
15
|
+
quantity: number;
|
|
16
|
+
variant_id?: string | null;
|
|
17
|
+
product_id?: string | null;
|
|
18
|
+
unit_price?: number;
|
|
19
|
+
subtotal?: number;
|
|
20
|
+
total?: number;
|
|
21
|
+
thumbnail?: string | null;
|
|
22
|
+
variant?: Record<string, unknown> | null;
|
|
23
|
+
product?: Record<string, unknown> | null;
|
|
24
|
+
}
|
|
25
|
+
export interface StoreCart {
|
|
26
|
+
id: string;
|
|
27
|
+
currency_code: string;
|
|
28
|
+
region_id?: string | null;
|
|
29
|
+
email?: string | null;
|
|
30
|
+
items?: StoreCartLineItem[];
|
|
31
|
+
subtotal?: number;
|
|
32
|
+
item_subtotal?: number;
|
|
33
|
+
discount_total?: number;
|
|
34
|
+
shipping_total?: number;
|
|
35
|
+
tax_total?: number;
|
|
36
|
+
total?: number;
|
|
37
|
+
promotions?: StoreCartPromotion[];
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
export interface StoreCartResponse {
|
|
41
|
+
cart: StoreCart;
|
|
42
|
+
}
|
|
43
|
+
export interface StoreCartListResponse {
|
|
44
|
+
carts: StoreCart[];
|
|
45
|
+
}
|
|
46
|
+
export interface StoreCartCompleteResponse {
|
|
47
|
+
type: "order" | "cart";
|
|
48
|
+
order?: Record<string, unknown>;
|
|
49
|
+
cart?: StoreCart;
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
export type { StoreShippingOption, StoreShippingOptionsResponse, } from "./fulfillment";
|
|
53
|
+
export { medusaShippingOptionsList } from "./fulfillment";
|
|
54
|
+
/**
|
|
55
|
+
* POST /store/carts — create a new cart (response includes `cart.id`; cookie may be set by backend).
|
|
56
|
+
*/
|
|
57
|
+
export declare function medusaCartCreate(options: MedusaStoreCartClientOptions, body?: Record<string, unknown>): Promise<StoreCartResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* GET /store/carts/:id
|
|
60
|
+
*/
|
|
61
|
+
export declare function medusaCartRetrieve(cartId: string, options: MedusaStoreCartClientOptions, query?: {
|
|
62
|
+
fields?: string;
|
|
63
|
+
}): Promise<StoreCartResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* POST /store/carts/:id — update cart (region, email, metadata, etc.).
|
|
66
|
+
*/
|
|
67
|
+
export declare function medusaCartUpdate(cartId: string, body: Record<string, unknown>, options: MedusaStoreCartClientOptions, query?: {
|
|
68
|
+
fields?: string;
|
|
69
|
+
}): Promise<StoreCartResponse>;
|
|
70
|
+
export interface MedusaAddLineItemBody {
|
|
71
|
+
variant_id: string;
|
|
72
|
+
quantity: number;
|
|
73
|
+
metadata?: Record<string, unknown>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* POST /store/carts/:id/line-items
|
|
77
|
+
*/
|
|
78
|
+
export declare function medusaCartAddLineItem(cartId: string, item: MedusaAddLineItemBody, options: MedusaStoreCartClientOptions, query?: {
|
|
79
|
+
fields?: string;
|
|
80
|
+
}): Promise<StoreCartResponse>;
|
|
81
|
+
export interface MedusaUpdateLineItemBody {
|
|
82
|
+
quantity?: number;
|
|
83
|
+
variant_id?: string;
|
|
84
|
+
metadata?: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* POST /store/carts/:id/line-items/:line_id
|
|
88
|
+
*/
|
|
89
|
+
export declare function medusaCartUpdateLineItem(cartId: string, lineId: string, body: MedusaUpdateLineItemBody, options: MedusaStoreCartClientOptions, query?: {
|
|
90
|
+
fields?: string;
|
|
91
|
+
}): Promise<StoreCartResponse>;
|
|
92
|
+
/**
|
|
93
|
+
* DELETE /store/carts/:id/line-items/:line_id
|
|
94
|
+
*/
|
|
95
|
+
export declare function medusaCartRemoveLineItem(cartId: string, lineId: string, options: MedusaStoreCartClientOptions, query?: {
|
|
96
|
+
fields?: string;
|
|
97
|
+
}): Promise<StoreCartResponse>;
|
|
98
|
+
/**
|
|
99
|
+
* POST /store/carts/:id/promotions — apply promotion codes.
|
|
100
|
+
*/
|
|
101
|
+
export declare function medusaCartApplyPromotions(cartId: string, promoCodes: string[], options: MedusaStoreCartClientOptions, query?: {
|
|
102
|
+
fields?: string;
|
|
103
|
+
}): Promise<StoreCartResponse>;
|
|
104
|
+
/**
|
|
105
|
+
* DELETE /store/carts/:id/promotions — remove promotion codes (body: promo_codes).
|
|
106
|
+
*/
|
|
107
|
+
export declare function medusaCartRemovePromotions(cartId: string, promoCodes: string[], options: MedusaStoreCartClientOptions, query?: {
|
|
108
|
+
fields?: string;
|
|
109
|
+
}): Promise<StoreCartResponse>;
|
|
110
|
+
/**
|
|
111
|
+
* POST /store/carts/:id/shipping-methods
|
|
112
|
+
*/
|
|
113
|
+
export declare function medusaCartAddShippingMethod(cartId: string, optionId: string, options: MedusaStoreCartClientOptions, query?: {
|
|
114
|
+
fields?: string;
|
|
115
|
+
}): Promise<StoreCartResponse>;
|
|
116
|
+
/**
|
|
117
|
+
* POST /store/carts/:id/complete
|
|
118
|
+
*/
|
|
119
|
+
export declare function medusaCartComplete(cartId: string, options: MedusaStoreCartClientOptions): Promise<StoreCartCompleteResponse>;
|
|
120
|
+
/**
|
|
121
|
+
* POST /store/carts/merge/skip
|
|
122
|
+
*/
|
|
123
|
+
export declare function medusaCartSkipMerge(cartId: string, options: MedusaStoreCartClientOptions): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* DELETE /store/carts/:id
|
|
126
|
+
*/
|
|
127
|
+
export declare function medusaCartDelete(cartId: string, options: MedusaStoreCartClientOptions): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* GET /store/carts
|
|
130
|
+
*/
|
|
131
|
+
export declare function medusaCartList(options: MedusaStoreCartClientOptions, query?: {
|
|
132
|
+
fields?: string;
|
|
133
|
+
}): Promise<StoreCartListResponse>;
|
|
134
|
+
export interface StoreCartMergeResponse {
|
|
135
|
+
cart?: StoreCart;
|
|
136
|
+
id?: string;
|
|
137
|
+
cart_id?: string;
|
|
138
|
+
[key: string]: unknown;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* POST /store/carts/merge
|
|
142
|
+
*/
|
|
143
|
+
export declare function medusaCartMerge(options: MedusaStoreCartClientOptions, cartId?: string): Promise<StoreCartMergeResponse | null>;
|
|
144
|
+
/**
|
|
145
|
+
* POST /store/carts/:id/transfer
|
|
146
|
+
*/
|
|
147
|
+
export declare function medusaCartTransfer(cartId: string, options: MedusaStoreCartClientOptions): Promise<void>;
|
|
148
|
+
//# sourceMappingURL=cart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cart.d.ts","sourceRoot":"","sources":["../cart.ts"],"names":[],"mappings":"AAEA,OAAO,EAKH,KAAK,4BAA4B,E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ACrC,MAAM,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAexC;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,4BAA4B,GACtC,OAAO,CAAC,IAAI,CAAC,CASf"}
|
package/dist/cart.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// --- Medusa Store API: carts (guest + session cookie via credentials) ---
|
|
2
|
+
import { fieldsQuery, parseStoreErrorMessage, parseStoreJson, storeFetch, } from "./store-api";
|
|
3
|
+
/** Default `fields` for cart detail pages (tweak per backend / performance). */
|
|
4
|
+
export const MEDUSA_STORE_CART_DEFAULT_FIELDS = "*items,*items.variant,*items.variant.product,*items.product,*promotions,*region";
|
|
5
|
+
/** Rich `fields` used by Next.js storefront cart pages. */
|
|
6
|
+
export const MEDUSA_STORE_CART_DETAIL_FIELDS = "*items, *region, *items.product, *items.product.thumbnail, *items.product.images, *items.product.options, *items.product.variants, +items.product.variants.inventory_quantity, +items.product.variants.manage_inventory, +items.product.variants.allow_backorder, *items.product.variants.options, *items.variant, +items.variant.inventory_quantity, +items.variant.manage_inventory, +items.variant.allow_backorder, *items.variant.images, *items.variant.product, *items.variant.product.thumbnail, *items.variant.product.images, *items.variant.options, *items.thumbnail, *items.metadata, +items.total, +items.adjustments, *promotions, +shipping_methods.name, +shipping_methods.adjustments";
|
|
7
|
+
export { medusaShippingOptionsList } from "./fulfillment";
|
|
8
|
+
async function storeCartFetch(path, options, init) {
|
|
9
|
+
return storeFetch(`/carts${path}`, options, init);
|
|
10
|
+
}
|
|
11
|
+
async function parseCartJson(response) {
|
|
12
|
+
return parseStoreJson(response, "Cart request");
|
|
13
|
+
}
|
|
14
|
+
function cartFieldsQuery(fields) {
|
|
15
|
+
return fieldsQuery(fields, MEDUSA_STORE_CART_DEFAULT_FIELDS);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* POST /store/carts — create a new cart (response includes `cart.id`; cookie may be set by backend).
|
|
19
|
+
*/
|
|
20
|
+
export async function medusaCartCreate(options, body) {
|
|
21
|
+
const response = await storeCartFetch("", options, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
body: JSON.stringify(body ?? {}),
|
|
24
|
+
});
|
|
25
|
+
return parseCartJson(response);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* GET /store/carts/:id
|
|
29
|
+
*/
|
|
30
|
+
export async function medusaCartRetrieve(cartId, options, query) {
|
|
31
|
+
const response = await storeCartFetch(`/${encodeURIComponent(cartId)}${cartFieldsQuery(query?.fields)}`, options, { method: "GET" });
|
|
32
|
+
return parseCartJson(response);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* POST /store/carts/:id — update cart (region, email, metadata, etc.).
|
|
36
|
+
*/
|
|
37
|
+
export async function medusaCartUpdate(cartId, body, options, query) {
|
|
38
|
+
const response = await storeCartFetch(`/${encodeURIComponent(cartId)}${cartFieldsQuery(query?.fields)}`, options, { method: "POST", body: JSON.stringify(body) });
|
|
39
|
+
return parseCartJson(response);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* POST /store/carts/:id/line-items
|
|
43
|
+
*/
|
|
44
|
+
export async function medusaCartAddLineItem(cartId, item, options, query) {
|
|
45
|
+
const response = await storeCartFetch(`/${encodeURIComponent(cartId)}/line-items${cartFieldsQuery(query?.fields)}`, options, { method: "POST", body: JSON.stringify(item) });
|
|
46
|
+
return parseCartJson(response);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* POST /store/carts/:id/line-items/:line_id
|
|
50
|
+
*/
|
|
51
|
+
export async function medusaCartUpdateLineItem(cartId, lineId, body, options, query) {
|
|
52
|
+
const response = await storeCartFetch(`/${encodeURIComponent(cartId)}/line-items/${encodeURIComponent(lineId)}${cartFieldsQuery(query?.fields)}`, options, { method: "POST", body: JSON.stringify(body) });
|
|
53
|
+
return parseCartJson(response);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* DELETE /store/carts/:id/line-items/:line_id
|
|
57
|
+
*/
|
|
58
|
+
export async function medusaCartRemoveLineItem(cartId, lineId, options, query) {
|
|
59
|
+
const response = await storeCartFetch(`/${encodeURIComponent(cartId)}/line-items/${encodeURIComponent(lineId)}${cartFieldsQuery(query?.fields)}`, options, { method: "DELETE" });
|
|
60
|
+
return parseCartJson(response);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* POST /store/carts/:id/promotions — apply promotion codes.
|
|
64
|
+
*/
|
|
65
|
+
export async function medusaCartApplyPromotions(cartId, promoCodes, options, query) {
|
|
66
|
+
const response = await storeCartFetch(`/${encodeURIComponent(cartId)}/promotions${cartFieldsQuery(query?.fields)}`, options, { method: "POST", body: JSON.stringify({ promo_codes: promoCodes }) });
|
|
67
|
+
return parseCartJson(response);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* DELETE /store/carts/:id/promotions — remove promotion codes (body: promo_codes).
|
|
71
|
+
*/
|
|
72
|
+
export async function medusaCartRemovePromotions(cartId, promoCodes, options, query) {
|
|
73
|
+
const response = await storeCartFetch(`/${encodeURIComponent(cartId)}/promotions${cartFieldsQuery(query?.fields)}`, options, { method: "DELETE", body: JSON.stringify({ promo_codes: promoCodes }) });
|
|
74
|
+
return parseCartJson(response);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* POST /store/carts/:id/shipping-methods
|
|
78
|
+
*/
|
|
79
|
+
export async function medusaCartAddShippingMethod(cartId, optionId, options, query) {
|
|
80
|
+
const response = await storeCartFetch(`/${encodeURIComponent(cartId)}/shipping-methods${cartFieldsQuery(query?.fields)}`, options, { method: "POST", body: JSON.stringify({ option_id: optionId }) });
|
|
81
|
+
return parseCartJson(response);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* POST /store/carts/:id/complete
|
|
85
|
+
*/
|
|
86
|
+
export async function medusaCartComplete(cartId, options) {
|
|
87
|
+
const response = await storeCartFetch(`/${encodeURIComponent(cartId)}/complete`, options, {
|
|
88
|
+
method: "POST",
|
|
89
|
+
body: JSON.stringify({}),
|
|
90
|
+
});
|
|
91
|
+
if (!response.ok) {
|
|
92
|
+
throw new Error(await parseStoreErrorMessage(response, "Cart request"));
|
|
93
|
+
}
|
|
94
|
+
return response.json();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* POST /store/carts/merge/skip
|
|
98
|
+
*/
|
|
99
|
+
export async function medusaCartSkipMerge(cartId, options) {
|
|
100
|
+
const response = await storeCartFetch("/merge/skip", options, {
|
|
101
|
+
method: "POST",
|
|
102
|
+
body: JSON.stringify({ cart_id: cartId }),
|
|
103
|
+
});
|
|
104
|
+
if (!response.ok) {
|
|
105
|
+
throw new Error(await parseStoreErrorMessage(response, "Cart request"));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* DELETE /store/carts/:id
|
|
110
|
+
*/
|
|
111
|
+
export async function medusaCartDelete(cartId, options) {
|
|
112
|
+
const response = await storeCartFetch(`/${encodeURIComponent(cartId)}`, options, {
|
|
113
|
+
method: "DELETE",
|
|
114
|
+
});
|
|
115
|
+
if (!response.ok) {
|
|
116
|
+
throw new Error(await parseStoreErrorMessage(response, "Cart request"));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* GET /store/carts
|
|
121
|
+
*/
|
|
122
|
+
export async function medusaCartList(options, query) {
|
|
123
|
+
const response = await storeCartFetch(cartFieldsQuery(query?.fields), options, { method: "GET" });
|
|
124
|
+
if (!response.ok) {
|
|
125
|
+
throw new Error(await parseStoreErrorMessage(response, "Cart request"));
|
|
126
|
+
}
|
|
127
|
+
return response.json();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* POST /store/carts/merge
|
|
131
|
+
*/
|
|
132
|
+
export async function medusaCartMerge(options, cartId) {
|
|
133
|
+
const response = await storeCartFetch("/merge", options, {
|
|
134
|
+
method: "POST",
|
|
135
|
+
...(cartId ? { body: JSON.stringify({ cart_id: cartId }) } : {}),
|
|
136
|
+
});
|
|
137
|
+
if (response.status === 404) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
if (!response.ok) {
|
|
141
|
+
throw new Error(await parseStoreErrorMessage(response, "Cart merge request"));
|
|
142
|
+
}
|
|
143
|
+
return response.json();
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* POST /store/carts/:id/transfer
|
|
147
|
+
*/
|
|
148
|
+
export async function medusaCartTransfer(cartId, options) {
|
|
149
|
+
const response = await storeCartFetch(`/${encodeURIComponent(cartId)}/transfer`, options, {
|
|
150
|
+
method: "POST",
|
|
151
|
+
body: JSON.stringify({}),
|
|
152
|
+
});
|
|
153
|
+
if (!response.ok && response.status !== 404) {
|
|
154
|
+
throw new Error(await parseStoreErrorMessage(response, "Cart transfer request"));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type MedusaStoreClientOptions } from "./store-api";
|
|
2
|
+
export interface StoreProductCategory {
|
|
3
|
+
id: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
handle?: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface StoreProductCategoryListResponse {
|
|
9
|
+
product_categories: StoreProductCategory[];
|
|
10
|
+
}
|
|
11
|
+
export declare const MEDUSA_CATEGORY_LIST_FIELDS = "*category_children, *products, *parent_category, *parent_category.parent_category";
|
|
12
|
+
/**
|
|
13
|
+
* GET /store/product-categories
|
|
14
|
+
*/
|
|
15
|
+
export declare function medusaCategoryList(options: MedusaStoreClientOptions, query?: Record<string, string | number | undefined>): Promise<StoreProductCategoryListResponse>;
|
|
16
|
+
/**
|
|
17
|
+
* GET /store/product-categories?handle[]
|
|
18
|
+
*/
|
|
19
|
+
export declare function medusaCategoryByHandle(handle: string, options: MedusaStoreClientOptions): Promise<StoreProductCategory | null>;
|
|
20
|
+
//# sourceMappingURL=categories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"categories.d.ts","sourceRoot":"","sources":["../categories.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,wBAAwB,EAChC,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,oBAAoB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,gCAAgC;IAC7C,kBAAkB,EAAE,oBAAoB,EAAE,CAAC;CAC9C;AAED,eAAO,MAAM,2BAA2B,sFAC+C,CAAC;AAExF;;GAEG;AACH,wBAAsB,kBAAkB,CACpC,OAAO,EAAE,wBAAwB,EACjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,GACpD,OAAO,CAAC,gCAAgC,CAAC,CAkB3C;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CACxC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAWtC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { parseStoreJson, storeFetch, } from "./store-api";
|
|
2
|
+
export const MEDUSA_CATEGORY_LIST_FIELDS = "*category_children, *products, *parent_category, *parent_category.parent_category";
|
|
3
|
+
/**
|
|
4
|
+
* GET /store/product-categories
|
|
5
|
+
*/
|
|
6
|
+
export async function medusaCategoryList(options, query) {
|
|
7
|
+
const params = new URLSearchParams();
|
|
8
|
+
params.set("fields", MEDUSA_CATEGORY_LIST_FIELDS);
|
|
9
|
+
params.set("limit", String(query?.limit ?? 100));
|
|
10
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
11
|
+
if (key === "limit" || value === undefined)
|
|
12
|
+
continue;
|
|
13
|
+
if (Array.isArray(value)) {
|
|
14
|
+
value.forEach((v) => params.append(`${key}[]`, String(v)));
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
params.set(key, String(value));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const response = await storeFetch(`/product-categories?${params.toString()}`, options, {
|
|
21
|
+
method: "GET",
|
|
22
|
+
});
|
|
23
|
+
return parseStoreJson(response, "Category list request");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* GET /store/product-categories?handle[]
|
|
27
|
+
*/
|
|
28
|
+
export async function medusaCategoryByHandle(handle, options) {
|
|
29
|
+
const params = new URLSearchParams();
|
|
30
|
+
params.append("handle[]", handle);
|
|
31
|
+
const response = await storeFetch(`/product-categories?${params.toString()}`, options, {
|
|
32
|
+
method: "GET",
|
|
33
|
+
});
|
|
34
|
+
const data = await parseStoreJson(response, "Category by handle request");
|
|
35
|
+
return data.product_categories?.[0] ?? null;
|
|
36
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type MedusaStoreClientOptions } from "./store-api";
|
|
2
|
+
export interface StoreCollection {
|
|
3
|
+
id: string;
|
|
4
|
+
title?: string;
|
|
5
|
+
handle?: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface StoreCollectionResponse {
|
|
9
|
+
collection: StoreCollection;
|
|
10
|
+
}
|
|
11
|
+
export interface StoreCollectionListResponse {
|
|
12
|
+
collections: StoreCollection[];
|
|
13
|
+
count?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* GET /store/collections/:id
|
|
17
|
+
*/
|
|
18
|
+
export declare function medusaCollectionRetrieve(id: string, options: MedusaStoreClientOptions): Promise<StoreCollectionResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* GET /store/collections
|
|
21
|
+
*/
|
|
22
|
+
export declare function medusaCollectionList(options: MedusaStoreClientOptions, query?: Record<string, string>): Promise<StoreCollectionListResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* GET /store/collections?handle[]
|
|
25
|
+
*/
|
|
26
|
+
export declare function medusaCollectionByHandle(handle: string, options: MedusaStoreClientOptions): Promise<StoreCollection | null>;
|
|
27
|
+
//# sourceMappingURL=collections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../collections.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAExF,MAAM,WAAW,eAAe;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACpC,UAAU,EAAE,eAAe,CAAC;CAC/B;AAED,MAAM,WAAW,2BAA2B;IACxC,WAAW,EAAE,eAAe,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC1C,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,uBAAuB,CAAC,CAKlC;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACtC,OAAO,EAAE,wBAAwB,EACjC,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,OAAO,CAAC,2BAA2B,CAAC,CAWtC;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC1C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAWjC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { parseStoreJson, storeFetch } from "./store-api";
|
|
2
|
+
/**
|
|
3
|
+
* GET /store/collections/:id
|
|
4
|
+
*/
|
|
5
|
+
export async function medusaCollectionRetrieve(id, options) {
|
|
6
|
+
const response = await storeFetch(`/collections/${encodeURIComponent(id)}`, options, {
|
|
7
|
+
method: "GET",
|
|
8
|
+
});
|
|
9
|
+
return parseStoreJson(response, "Collection retrieve request");
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* GET /store/collections
|
|
13
|
+
*/
|
|
14
|
+
export async function medusaCollectionList(options, query = {}) {
|
|
15
|
+
const params = new URLSearchParams({
|
|
16
|
+
limit: query.limit || "100",
|
|
17
|
+
offset: query.offset || "0",
|
|
18
|
+
...query,
|
|
19
|
+
});
|
|
20
|
+
const response = await storeFetch(`/collections?${params.toString()}`, options, {
|
|
21
|
+
method: "GET",
|
|
22
|
+
});
|
|
23
|
+
return parseStoreJson(response, "Collection list request");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* GET /store/collections?handle[]
|
|
27
|
+
*/
|
|
28
|
+
export async function medusaCollectionByHandle(handle, options) {
|
|
29
|
+
const params = new URLSearchParams();
|
|
30
|
+
params.append("handle[]", handle);
|
|
31
|
+
const response = await storeFetch(`/collections?${params.toString()}`, options, {
|
|
32
|
+
method: "GET",
|
|
33
|
+
});
|
|
34
|
+
const data = await parseStoreJson(response, "Collection by handle request");
|
|
35
|
+
return data.collections?.[0] ?? null;
|
|
36
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ContactSubmissionData {
|
|
2
|
+
backendUrl: string;
|
|
3
|
+
publishableKey?: string;
|
|
4
|
+
data: Record<string, any>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Server-side compatible function to send contact request
|
|
8
|
+
*/
|
|
9
|
+
export declare function sendContactRequest({ backendUrl, publishableKey, data }: ContactSubmissionData): Promise<any>;
|
|
10
|
+
export interface NewsletterSubscribeInput {
|
|
11
|
+
backendUrl: string;
|
|
12
|
+
publishableApiKey?: string;
|
|
13
|
+
email: string;
|
|
14
|
+
status?: "subscribed" | "unsubscribed";
|
|
15
|
+
source?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function subscribeToNewsletter({ backendUrl, publishableApiKey, email, status, source, }: NewsletterSubscribeInput): Promise<any>;
|
|
18
|
+
//# sourceMappingURL=contact-action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contact-action.d.ts","sourceRoot":"","sources":["../contact-action.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,qBAAqB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,EAAE,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,qBAAqB,gBAwBnG;AAED,MAAM,WAAW,wBAAwB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,qBAAqB,CAAC,EACxC,UAAU,EACV,iBAAiB,EACjB,KAAK,EACL,MAAqB,EACrB,MAAiB,GACpB,EAAE,wBAAwB,gBAyB1B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side compatible function to send contact request
|
|
3
|
+
*/
|
|
4
|
+
export async function sendContactRequest({ backendUrl, publishableKey, data }) {
|
|
5
|
+
const baseUrl = backendUrl;
|
|
6
|
+
const finalUrl = `${baseUrl.replace(/\/$/, '')}/store/contact-requests`;
|
|
7
|
+
const headers = {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
};
|
|
10
|
+
if (publishableKey) {
|
|
11
|
+
headers['x-publishable-api-key'] = publishableKey;
|
|
12
|
+
}
|
|
13
|
+
const response = await fetch(finalUrl, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers: headers,
|
|
16
|
+
body: JSON.stringify(data),
|
|
17
|
+
});
|
|
18
|
+
if (!response.ok) {
|
|
19
|
+
const errorData = await response.json().catch(() => ({}));
|
|
20
|
+
throw new Error(errorData.message || 'Failed to send message');
|
|
21
|
+
}
|
|
22
|
+
return await response.json();
|
|
23
|
+
}
|
|
24
|
+
export async function subscribeToNewsletter({ backendUrl, publishableApiKey, email, status = "subscribed", source = "footer", }) {
|
|
25
|
+
const finalUrl = `${backendUrl.replace(/\/$/, "")}/store/contact-email-subscriptions`;
|
|
26
|
+
const headers = {
|
|
27
|
+
"Content-Type": "application/json",
|
|
28
|
+
};
|
|
29
|
+
if (publishableApiKey) {
|
|
30
|
+
headers["x-publishable-api-key"] = publishableApiKey;
|
|
31
|
+
}
|
|
32
|
+
const response = await fetch(finalUrl, {
|
|
33
|
+
method: "POST",
|
|
34
|
+
headers,
|
|
35
|
+
body: JSON.stringify({ email, status, source }),
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const errorData = await response.json().catch(() => ({}));
|
|
39
|
+
throw new Error(errorData.message || "Failed to subscribe to newsletter");
|
|
40
|
+
}
|
|
41
|
+
return response.json();
|
|
42
|
+
}
|