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/guest.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type MedusaStoreClientOptions } from "./store-api";
|
|
2
|
+
export interface GuestOtpResponse {
|
|
3
|
+
success: boolean;
|
|
4
|
+
token?: string;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface GuestOrdersListResponse {
|
|
8
|
+
orders?: Array<Record<string, unknown>>;
|
|
9
|
+
order?: Record<string, unknown>;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* POST /store/otp/request
|
|
14
|
+
*/
|
|
15
|
+
export declare function medusaGuestOtpRequest(email: string, options: MedusaStoreClientOptions): Promise<GuestOtpResponse>;
|
|
16
|
+
/**
|
|
17
|
+
* POST /store/otp/verify
|
|
18
|
+
*/
|
|
19
|
+
export declare function medusaGuestOtpVerify(email: string, otp: string, options: MedusaStoreClientOptions): Promise<GuestOtpResponse>;
|
|
20
|
+
/**
|
|
21
|
+
* GET /store/guest-orders
|
|
22
|
+
*/
|
|
23
|
+
export declare function medusaGuestOrderList(token: string, options: MedusaStoreClientOptions): Promise<GuestOrdersListResponse>;
|
|
24
|
+
/**
|
|
25
|
+
* GET /store/orders/:id (guest token)
|
|
26
|
+
*/
|
|
27
|
+
export declare function medusaGuestOrderRetrieve(orderId: string, token: string, options: MedusaStoreClientOptions): Promise<GuestOrdersListResponse>;
|
|
28
|
+
/**
|
|
29
|
+
* POST /store/guest-orders/:id/cancel
|
|
30
|
+
*/
|
|
31
|
+
export declare function medusaGuestOrderCancelSimple(orderId: string, token: string, options: MedusaStoreClientOptions): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* GET /store/guest/invoice/download/:id
|
|
34
|
+
*/
|
|
35
|
+
export declare function medusaGuestOrderInvoice(orderId: string, token: string, options: MedusaStoreClientOptions): Promise<{
|
|
36
|
+
type: "pdf";
|
|
37
|
+
data: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: "json";
|
|
40
|
+
data: unknown;
|
|
41
|
+
}>;
|
|
42
|
+
export interface GuestReturnItem {
|
|
43
|
+
id: string;
|
|
44
|
+
quantity: number;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=guest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guest.d.ts","sourceRoot":"","sources":["../guest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsD,KAA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AC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAkB1E;AAED,MAAM,WAAW,eAAe;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;CACpB"}
|
package/dist/guest.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { parseStoreErrorMessage, parseStoreJson, storeFetch } from "./store-api";
|
|
2
|
+
const GUEST_ORDER_LIST_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";
|
|
3
|
+
const GUEST_ORDER_DETAIL_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";
|
|
4
|
+
function guestOptions(token, base) {
|
|
5
|
+
return {
|
|
6
|
+
...base,
|
|
7
|
+
authorization: token.startsWith("Bearer ") ? token : `Bearer ${token}`,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* POST /store/otp/request
|
|
12
|
+
*/
|
|
13
|
+
export async function medusaGuestOtpRequest(email, options) {
|
|
14
|
+
try {
|
|
15
|
+
const response = await storeFetch("/otp/request", options, {
|
|
16
|
+
method: "POST",
|
|
17
|
+
body: JSON.stringify({ email }),
|
|
18
|
+
});
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
throw new Error(await parseStoreErrorMessage(response, "OTP request"));
|
|
21
|
+
}
|
|
22
|
+
return { success: true };
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* POST /store/otp/verify
|
|
30
|
+
*/
|
|
31
|
+
export async function medusaGuestOtpVerify(email, otp, options) {
|
|
32
|
+
try {
|
|
33
|
+
const response = await storeFetch("/otp/verify", options, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
body: JSON.stringify({ email, otp }),
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new Error(await parseStoreErrorMessage(response, "OTP verify request"));
|
|
39
|
+
}
|
|
40
|
+
const data = await parseStoreJson(response, "OTP verify request");
|
|
41
|
+
if (!data.token) {
|
|
42
|
+
throw new Error("No token returned");
|
|
43
|
+
}
|
|
44
|
+
return { success: true, token: data.token };
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* GET /store/guest-orders
|
|
52
|
+
*/
|
|
53
|
+
export async function medusaGuestOrderList(token, options) {
|
|
54
|
+
const params = new URLSearchParams();
|
|
55
|
+
params.set("fields", GUEST_ORDER_LIST_FIELDS);
|
|
56
|
+
const response = await storeFetch(`/guest-orders?${params.toString()}`, guestOptions(token, options), { method: "GET" });
|
|
57
|
+
return parseStoreJson(response, "Guest order list request");
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* GET /store/orders/:id (guest token)
|
|
61
|
+
*/
|
|
62
|
+
export async function medusaGuestOrderRetrieve(orderId, token, options) {
|
|
63
|
+
const params = new URLSearchParams();
|
|
64
|
+
params.set("fields", GUEST_ORDER_DETAIL_FIELDS);
|
|
65
|
+
const response = await storeFetch(`/orders/${encodeURIComponent(orderId)}?${params.toString()}`, guestOptions(token, options), { method: "GET" });
|
|
66
|
+
return parseStoreJson(response, "Guest order retrieve request");
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* POST /store/guest-orders/:id/cancel
|
|
70
|
+
*/
|
|
71
|
+
export async function medusaGuestOrderCancelSimple(orderId, token, options) {
|
|
72
|
+
const response = await storeFetch(`/guest-orders/${encodeURIComponent(orderId)}/cancel`, guestOptions(token, options), { method: "POST", body: JSON.stringify({}) });
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
throw new Error(await parseStoreErrorMessage(response, "Guest order cancel request"));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* GET /store/guest/invoice/download/:id
|
|
79
|
+
*/
|
|
80
|
+
export async function medusaGuestOrderInvoice(orderId, token, options) {
|
|
81
|
+
const response = await storeFetch(`/guest/invoice/download/${encodeURIComponent(orderId)}`, guestOptions(token, options), { method: "GET" });
|
|
82
|
+
if (!response.ok) {
|
|
83
|
+
throw new Error(await parseStoreErrorMessage(response, "Guest invoice request"));
|
|
84
|
+
}
|
|
85
|
+
const contentType = response.headers.get("content-type");
|
|
86
|
+
if (contentType?.includes("application/pdf")) {
|
|
87
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
88
|
+
return { type: "pdf", data: Buffer.from(arrayBuffer).toString("base64") };
|
|
89
|
+
}
|
|
90
|
+
return { type: "json", data: await response.json() };
|
|
91
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export * from "./store-api";
|
|
2
|
+
export * from "./cart";
|
|
3
|
+
export * from "./customer";
|
|
4
|
+
export * from "./regions";
|
|
5
|
+
export * from "./orders";
|
|
6
|
+
export * from "./fulfillment";
|
|
7
|
+
export * from "./wishlist";
|
|
8
|
+
export * from "./reviews";
|
|
9
|
+
export * from "./contact-action";
|
|
10
|
+
export * from "./product-listing";
|
|
11
|
+
export * from "./products";
|
|
12
|
+
export * from "./product-detail";
|
|
13
|
+
export * from "./related-products";
|
|
14
|
+
export * from "./recently-viewed";
|
|
15
|
+
export * from "./middleware";
|
|
16
|
+
export * from "./medusa-auth";
|
|
17
|
+
export * from "./auth";
|
|
18
|
+
export * as googleLogin from "./google-login";
|
|
19
|
+
export * as facebookLogin from "./facebook-login";
|
|
20
|
+
export * from "./gift-wrap";
|
|
21
|
+
export * from "./categories";
|
|
22
|
+
export * from "./collections";
|
|
23
|
+
export * from "./payment";
|
|
24
|
+
export * from "./variants";
|
|
25
|
+
export * from "./guest";
|
|
26
|
+
export * from "./returns";
|
|
27
|
+
export * from "./swaps";
|
|
28
|
+
export * from "./locales";
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC;AAClD,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export * from "./store-api";
|
|
2
|
+
export * from "./cart";
|
|
3
|
+
export * from "./customer";
|
|
4
|
+
export * from "./regions";
|
|
5
|
+
export * from "./orders";
|
|
6
|
+
export * from "./fulfillment";
|
|
7
|
+
export * from "./wishlist";
|
|
8
|
+
export * from "./reviews";
|
|
9
|
+
export * from "./contact-action";
|
|
10
|
+
export * from "./product-listing";
|
|
11
|
+
export * from "./products";
|
|
12
|
+
export * from "./product-detail";
|
|
13
|
+
export * from "./related-products";
|
|
14
|
+
export * from "./recently-viewed";
|
|
15
|
+
export * from "./middleware";
|
|
16
|
+
export * from "./medusa-auth";
|
|
17
|
+
export * from "./auth";
|
|
18
|
+
export * as googleLogin from "./google-login";
|
|
19
|
+
export * as facebookLogin from "./facebook-login";
|
|
20
|
+
export * from "./gift-wrap";
|
|
21
|
+
export * from "./categories";
|
|
22
|
+
export * from "./collections";
|
|
23
|
+
export * from "./payment";
|
|
24
|
+
export * from "./variants";
|
|
25
|
+
export * from "./guest";
|
|
26
|
+
export * from "./returns";
|
|
27
|
+
export * from "./swaps";
|
|
28
|
+
export * from "./locales";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type MedusaStoreClientOptions } from "./store-api";
|
|
2
|
+
export interface StoreLocale {
|
|
3
|
+
code: string;
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
export interface StoreLocaleListResponse {
|
|
7
|
+
locales: StoreLocale[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* GET /store/locales
|
|
11
|
+
*/
|
|
12
|
+
export declare function medusaLocaleList(options: MedusaStoreClientOptions): Promise<StoreLocaleListResponse | null>;
|
|
13
|
+
//# sourceMappingURL=locales.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locales.d.ts","sourceRoot":"","sources":["../locales.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAExF,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,uBAAuB;IACpC,OAAO,EAAE,WAAW,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAClC,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAOzC"}
|
package/dist/locales.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { parseStoreJson, storeFetch } from "./store-api";
|
|
2
|
+
/**
|
|
3
|
+
* GET /store/locales
|
|
4
|
+
*/
|
|
5
|
+
export async function medusaLocaleList(options) {
|
|
6
|
+
try {
|
|
7
|
+
const response = await storeFetch("/locales", options, { method: "GET" });
|
|
8
|
+
return parseStoreJson(response, "Locale list request");
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Medusa storefront JWT cookie helpers (Next.js / cookie-store compatible).
|
|
3
|
+
*/
|
|
4
|
+
export declare const MEDUSA_CUSTOMER_JWT_COOKIE = "_medusa_jwt";
|
|
5
|
+
export declare const MEDUSA_GUEST_JWT_COOKIE = "_medusa_guest_jwt";
|
|
6
|
+
/** Legacy guest cookie name used by some storefronts */
|
|
7
|
+
export declare const MEDUSA_GUEST_TOKEN_COOKIE = "_medusa_guest_token";
|
|
8
|
+
export type CookieStoreLike = {
|
|
9
|
+
get: (name: string) => {
|
|
10
|
+
value?: string;
|
|
11
|
+
} | undefined;
|
|
12
|
+
};
|
|
13
|
+
export declare function getMedusaCustomerJwt(cookieStore: CookieStoreLike): string | null;
|
|
14
|
+
export declare function getMedusaGuestJwt(cookieStore: CookieStoreLike): string | null;
|
|
15
|
+
export declare function stripBearerPrefix(authorization: string): string;
|
|
16
|
+
export declare function toBearerAuthorization(token: string): string;
|
|
17
|
+
//# sourceMappingURL=medusa-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"medusa-auth.d.ts","sourceRoot":"","sources":["../medusa-auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,0BAA0B,gBAAgB,CAAC;AACxD,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAC3D,wDAAwD;AACxD,eAAO,MAAM,yBAAyB,wBAAwB,CAAC;AAE/D,MAAM,MAAM,eAAe,GAAG;IAC1B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;CACzD,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,CAGhF;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,CAK7E;AAED,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAI3D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Medusa storefront JWT cookie helpers (Next.js / cookie-store compatible).
|
|
3
|
+
*/
|
|
4
|
+
export const MEDUSA_CUSTOMER_JWT_COOKIE = "_medusa_jwt";
|
|
5
|
+
export const MEDUSA_GUEST_JWT_COOKIE = "_medusa_guest_jwt";
|
|
6
|
+
/** Legacy guest cookie name used by some storefronts */
|
|
7
|
+
export const MEDUSA_GUEST_TOKEN_COOKIE = "_medusa_guest_token";
|
|
8
|
+
export function getMedusaCustomerJwt(cookieStore) {
|
|
9
|
+
const token = cookieStore.get(MEDUSA_CUSTOMER_JWT_COOKIE)?.value;
|
|
10
|
+
return token?.trim() || null;
|
|
11
|
+
}
|
|
12
|
+
export function getMedusaGuestJwt(cookieStore) {
|
|
13
|
+
const token = cookieStore.get(MEDUSA_GUEST_JWT_COOKIE)?.value ||
|
|
14
|
+
cookieStore.get(MEDUSA_GUEST_TOKEN_COOKIE)?.value;
|
|
15
|
+
return token?.trim() || null;
|
|
16
|
+
}
|
|
17
|
+
export function stripBearerPrefix(authorization) {
|
|
18
|
+
return authorization.replace(/^Bearer\s+/i, "").trim();
|
|
19
|
+
}
|
|
20
|
+
export function toBearerAuthorization(token) {
|
|
21
|
+
const t = token.trim();
|
|
22
|
+
if (t.toLowerCase().startsWith("bearer "))
|
|
23
|
+
return t;
|
|
24
|
+
return `Bearer ${t}`;
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Edge-safe Medusa store fetches (no Node SDK). */
|
|
2
|
+
export interface MedusaMiddlewareClientOptions {
|
|
3
|
+
backendUrl: string;
|
|
4
|
+
publishableApiKey: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function medusaListRegions(options: MedusaMiddlewareClientOptions, init?: RequestInit): Promise<{
|
|
7
|
+
regions: unknown[];
|
|
8
|
+
}>;
|
|
9
|
+
export declare function medusaMergeCarts(options: MedusaMiddlewareClientOptions & {
|
|
10
|
+
authorization: string;
|
|
11
|
+
cartId?: string;
|
|
12
|
+
}, init?: RequestInit): Promise<Response>;
|
|
13
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../middleware.ts"],"names":[],"mappings":"AAAA,oDAAoD;AAEpD,MAAM,WAAW,6BAA6B;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;CAC7B;AAMD,wBAAsB,iBAAiB,CACnC,OAAO,EAAE,6BAA6B,EACtC,IAAI,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC,CAejC;AAED,wBAAsB,gBAAgB,CAClC,OAAO,EAAE,6BAA6B,GAAG;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,EACD,IAAI,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,QAAQ,CAAC,CAgBnB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Edge-safe Medusa store fetches (no Node SDK). */
|
|
2
|
+
function normalizeBackendUrl(backendUrl) {
|
|
3
|
+
return backendUrl.replace(/\/$/, "");
|
|
4
|
+
}
|
|
5
|
+
export async function medusaListRegions(options, init) {
|
|
6
|
+
const url = `${normalizeBackendUrl(options.backendUrl)}/store/regions`;
|
|
7
|
+
const response = await fetch(url, {
|
|
8
|
+
...init,
|
|
9
|
+
headers: {
|
|
10
|
+
"x-publishable-api-key": options.publishableApiKey,
|
|
11
|
+
...init?.headers,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
const json = (await response.json());
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
throw new Error(json.message || "Failed to fetch regions");
|
|
17
|
+
}
|
|
18
|
+
return { regions: json.regions ?? [] };
|
|
19
|
+
}
|
|
20
|
+
export async function medusaMergeCarts(options, init) {
|
|
21
|
+
const url = `${normalizeBackendUrl(options.backendUrl)}/store/carts/merge`;
|
|
22
|
+
return fetch(url, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
...init,
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
"x-publishable-api-key": options.publishableApiKey,
|
|
28
|
+
Authorization: options.authorization.startsWith("Bearer ")
|
|
29
|
+
? options.authorization
|
|
30
|
+
: `Bearer ${options.authorization}`,
|
|
31
|
+
...init?.headers,
|
|
32
|
+
},
|
|
33
|
+
body: options.cartId ? JSON.stringify({ cart_id: options.cartId }) : init?.body,
|
|
34
|
+
cache: init?.cache ?? "no-store",
|
|
35
|
+
});
|
|
36
|
+
}
|
package/dist/orders.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { type MedusaStoreClientOptions } from "./store-api";
|
|
2
|
+
export interface StoreOrder {
|
|
3
|
+
id: string;
|
|
4
|
+
display_id?: number;
|
|
5
|
+
email?: string;
|
|
6
|
+
status?: string;
|
|
7
|
+
fulfillment_status?: string;
|
|
8
|
+
payment_status?: string;
|
|
9
|
+
currency_code?: string;
|
|
10
|
+
total?: number;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
items?: Array<Record<string, unknown>>;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface StoreOrderResponse {
|
|
16
|
+
order: StoreOrder;
|
|
17
|
+
}
|
|
18
|
+
export interface StoreOrderListResponse {
|
|
19
|
+
orders: StoreOrder[];
|
|
20
|
+
}
|
|
21
|
+
export declare const MEDUSA_ORDER_DETAIL_FIELDS = "id,display_id,customer_id,email,created_at,status,fulfillment_status,payment_status,currency_code,subtotal,shipping_total,tax_total,discount_total,metadata,total,*payment_collections.payments,*items,*items.metadata,*items.variant,*items.variant.images,*items.variant.product,*items.variant.product.thumbnail,*items.variant.product.images,*items.variant.product.variants,*items.product,*items.product.thumbnail,*items.product.images,*items.product.variants,*fulfillments,*fulfillments.items,*fulfillments.location_id,*returns,*returns.items,*cart,*shipping_address,*billing_address,*region,*shipping_methods";
|
|
22
|
+
export declare const MEDUSA_ORDER_LIST_FIELDS = "*items,+items.metadata,*items.variant,*items.variant.images,*items.product,*returns";
|
|
23
|
+
/**
|
|
24
|
+
* GET /store/orders/:id
|
|
25
|
+
*/
|
|
26
|
+
export declare function medusaOrderRetrieve(orderId: string, options: MedusaStoreClientOptions, query?: {
|
|
27
|
+
fields?: string;
|
|
28
|
+
}): Promise<StoreOrderResponse>;
|
|
29
|
+
/**
|
|
30
|
+
* GET /store/orders
|
|
31
|
+
*/
|
|
32
|
+
export declare function medusaOrderList(options: MedusaStoreClientOptions, query?: {
|
|
33
|
+
limit?: number;
|
|
34
|
+
offset?: number;
|
|
35
|
+
order?: string;
|
|
36
|
+
fields?: string;
|
|
37
|
+
[key: string]: string | number | boolean | undefined;
|
|
38
|
+
}): Promise<StoreOrderListResponse>;
|
|
39
|
+
/**
|
|
40
|
+
* POST /store/orders/:id/transfer/request
|
|
41
|
+
*/
|
|
42
|
+
export declare function medusaOrderRequestTransfer(orderId: string, options: MedusaStoreClientOptions, query?: {
|
|
43
|
+
fields?: string;
|
|
44
|
+
}): Promise<StoreOrderResponse>;
|
|
45
|
+
/**
|
|
46
|
+
* POST /store/orders/:id/transfer/accept
|
|
47
|
+
*/
|
|
48
|
+
export declare function medusaOrderAcceptTransfer(orderId: string, token: string, options: MedusaStoreClientOptions): Promise<StoreOrderResponse>;
|
|
49
|
+
/**
|
|
50
|
+
* POST /store/orders/:id/transfer/decline
|
|
51
|
+
*/
|
|
52
|
+
export declare function medusaOrderDeclineTransfer(orderId: string, token: string, options: MedusaStoreClientOptions): Promise<StoreOrderResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* GET /store/invoice/download/:id (or guest variant)
|
|
55
|
+
*/
|
|
56
|
+
export declare function medusaOrderDownloadInvoice(orderId: string, options: MedusaStoreClientOptions, guest?: boolean): Promise<ArrayBuffer>;
|
|
57
|
+
/**
|
|
58
|
+
* POST /store/orders/cancel/:id (with fallback path)
|
|
59
|
+
*/
|
|
60
|
+
export declare function medusaOrderCancel(orderId: string, reasonId: string, options: MedusaStoreClientOptions): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* POST /store/guest-orders/:id/cancel (with fallback path)
|
|
63
|
+
*/
|
|
64
|
+
export declare function medusaGuestOrderCancel(orderId: string, reasonId: string, options: MedusaStoreClientOptions): Promise<void>;
|
|
65
|
+
export interface MedusaOrderReorderResponse {
|
|
66
|
+
cart?: {
|
|
67
|
+
id?: string;
|
|
68
|
+
};
|
|
69
|
+
id?: string;
|
|
70
|
+
cart_id?: string;
|
|
71
|
+
reorder?: {
|
|
72
|
+
cart_id?: string;
|
|
73
|
+
};
|
|
74
|
+
inventory_issues?: unknown;
|
|
75
|
+
message?: string;
|
|
76
|
+
[key: string]: unknown;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* POST /store/orders/reorder/:id
|
|
80
|
+
*/
|
|
81
|
+
export declare function medusaOrderReorder(orderId: string, options: MedusaStoreClientOptions, query?: {
|
|
82
|
+
force_reorder?: boolean;
|
|
83
|
+
}): Promise<{
|
|
84
|
+
ok: true;
|
|
85
|
+
data: MedusaOrderReorderResponse;
|
|
86
|
+
} | {
|
|
87
|
+
ok: false;
|
|
88
|
+
status: number;
|
|
89
|
+
data: MedusaOrderReorderResponse;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* POST /store/guest-orders/:id/reorder
|
|
93
|
+
*/
|
|
94
|
+
export declare function medusaGuestOrderReorder(orderId: string, options: MedusaStoreClientOptions, query?: {
|
|
95
|
+
force_reorder?: boolean;
|
|
96
|
+
}): Promise<{
|
|
97
|
+
ok: true;
|
|
98
|
+
data: MedusaOrderReorderResponse;
|
|
99
|
+
} | {
|
|
100
|
+
ok: false;
|
|
101
|
+
status: number;
|
|
102
|
+
data: MedusaOrderReorderResponse;
|
|
103
|
+
}>;
|
|
104
|
+
export declare function extractReorderCartId(data: MedusaOrderReorderResponse): string | undefined;
|
|
105
|
+
//# sourceMappingURL=orders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orders.d.ts","sourceRoot":"","sources":["../orders.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,KAAK,wBAAwB,EAChC,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,UAAU;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,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AAI,EAAE,0BAA0B,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,0BAA0B,CAAA;CAAE,CAAC,CAa3H;AAED;;GAEG;AACH,wBAAsB,uBAAuB,CACzC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,wBAAwB,EACjC,KAAK,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,GACpC,OAAO,CAAC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,0BAA0B,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,0BAA0B,CAAA;CAAE,CAAC,CAa3H;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,0BAA0B,GAAG,MAAM,GAAG,SAAS,CAGzF"}
|
package/dist/orders.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { fieldsQuery, parseStoreErrorMessage, parseStoreJson, storeFetch, } from "./store-api";
|
|
2
|
+
export const MEDUSA_ORDER_DETAIL_FIELDS = "id,display_id,customer_id,email,created_at,status,fulfillment_status,payment_status,currency_code,subtotal,shipping_total,tax_total,discount_total,metadata,total,*payment_collections.payments,*items,*items.metadata,*items.variant,*items.variant.images,*items.variant.product,*items.variant.product.thumbnail,*items.variant.product.images,*items.variant.product.variants,*items.product,*items.product.thumbnail,*items.product.images,*items.product.variants,*fulfillments,*fulfillments.items,*fulfillments.location_id,*returns,*returns.items,*cart,*shipping_address,*billing_address,*region,*shipping_methods";
|
|
3
|
+
export const MEDUSA_ORDER_LIST_FIELDS = "*items,+items.metadata,*items.variant,*items.variant.images,*items.product,*returns";
|
|
4
|
+
function listQuery(params) {
|
|
5
|
+
const search = new URLSearchParams();
|
|
6
|
+
for (const [key, value] of Object.entries(params)) {
|
|
7
|
+
if (value !== undefined && value !== null && value !== "") {
|
|
8
|
+
search.set(key, String(value));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const query = search.toString();
|
|
12
|
+
return query ? `?${query}` : "";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* GET /store/orders/:id
|
|
16
|
+
*/
|
|
17
|
+
export async function medusaOrderRetrieve(orderId, options, query) {
|
|
18
|
+
const response = await storeFetch(`/orders/${encodeURIComponent(orderId)}${fieldsQuery(query?.fields, MEDUSA_ORDER_DETAIL_FIELDS)}`, options, { method: "GET" });
|
|
19
|
+
return parseStoreJson(response, "Order retrieve request");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* GET /store/orders
|
|
23
|
+
*/
|
|
24
|
+
export async function medusaOrderList(options, query) {
|
|
25
|
+
const response = await storeFetch(`/orders${listQuery({
|
|
26
|
+
limit: query?.limit ?? 10,
|
|
27
|
+
offset: query?.offset ?? 0,
|
|
28
|
+
order: query?.order ?? "-created_at",
|
|
29
|
+
fields: query?.fields ?? MEDUSA_ORDER_LIST_FIELDS,
|
|
30
|
+
...query,
|
|
31
|
+
})}`, options, { method: "GET" });
|
|
32
|
+
return parseStoreJson(response, "Order list request");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* POST /store/orders/:id/transfer/request
|
|
36
|
+
*/
|
|
37
|
+
export async function medusaOrderRequestTransfer(orderId, options, query) {
|
|
38
|
+
const response = await storeFetch(`/orders/${encodeURIComponent(orderId)}/transfer/request${fieldsQuery(query?.fields)}`, options, { method: "POST", body: JSON.stringify({}) });
|
|
39
|
+
return parseStoreJson(response, "Order transfer request");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* POST /store/orders/:id/transfer/accept
|
|
43
|
+
*/
|
|
44
|
+
export async function medusaOrderAcceptTransfer(orderId, token, options) {
|
|
45
|
+
const response = await storeFetch(`/orders/${encodeURIComponent(orderId)}/transfer/accept`, options, { method: "POST", body: JSON.stringify({ token }) });
|
|
46
|
+
return parseStoreJson(response, "Order transfer accept request");
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* POST /store/orders/:id/transfer/decline
|
|
50
|
+
*/
|
|
51
|
+
export async function medusaOrderDeclineTransfer(orderId, token, options) {
|
|
52
|
+
const response = await storeFetch(`/orders/${encodeURIComponent(orderId)}/transfer/decline`, options, { method: "POST", body: JSON.stringify({ token }) });
|
|
53
|
+
return parseStoreJson(response, "Order transfer decline request");
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* GET /store/invoice/download/:id (or guest variant)
|
|
57
|
+
*/
|
|
58
|
+
export async function medusaOrderDownloadInvoice(orderId, options, guest = false) {
|
|
59
|
+
const path = guest
|
|
60
|
+
? `/guest/invoice/download/${encodeURIComponent(orderId)}`
|
|
61
|
+
: `/invoice/download/${encodeURIComponent(orderId)}`;
|
|
62
|
+
const response = await storeFetch(path, options, { method: "GET" });
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
throw new Error(await parseStoreErrorMessage(response, "Invoice download request"));
|
|
65
|
+
}
|
|
66
|
+
const contentType = response.headers.get("content-type");
|
|
67
|
+
if (!contentType || !contentType.includes("application/pdf")) {
|
|
68
|
+
throw new Error("Server returned non-PDF content");
|
|
69
|
+
}
|
|
70
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
71
|
+
if (arrayBuffer.byteLength === 0) {
|
|
72
|
+
throw new Error("Generated PDF is empty");
|
|
73
|
+
}
|
|
74
|
+
return arrayBuffer;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* POST /store/orders/cancel/:id (with fallback path)
|
|
78
|
+
*/
|
|
79
|
+
export async function medusaOrderCancel(orderId, reasonId, options) {
|
|
80
|
+
const body = JSON.stringify({ reason_id: reasonId });
|
|
81
|
+
let response = await storeFetch(`/orders/cancel/${encodeURIComponent(orderId)}`, options, {
|
|
82
|
+
method: "POST",
|
|
83
|
+
body,
|
|
84
|
+
});
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
const errorData = (await response.json().catch(() => ({})));
|
|
87
|
+
if (response.status === 404 || errorData.message?.includes("resolve")) {
|
|
88
|
+
response = await storeFetch(`/orders/${encodeURIComponent(orderId)}/cancel`, options, {
|
|
89
|
+
method: "POST",
|
|
90
|
+
body,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
const errorData = (await response.json().catch(() => ({})));
|
|
96
|
+
throw new Error(errorData.message || "Failed to cancel order");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* POST /store/guest-orders/:id/cancel (with fallback path)
|
|
101
|
+
*/
|
|
102
|
+
export async function medusaGuestOrderCancel(orderId, reasonId, options) {
|
|
103
|
+
const body = JSON.stringify({ reason_id: reasonId });
|
|
104
|
+
let response = await storeFetch(`/guest-orders/${encodeURIComponent(orderId)}/cancel`, options, { method: "POST", body });
|
|
105
|
+
if (!response.ok) {
|
|
106
|
+
response = await storeFetch(`/guest/orders/${encodeURIComponent(orderId)}/cancel`, options, { method: "POST", body });
|
|
107
|
+
}
|
|
108
|
+
if (!response.ok) {
|
|
109
|
+
throw new Error("Failed to cancel order");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* POST /store/orders/reorder/:id
|
|
114
|
+
*/
|
|
115
|
+
export async function medusaOrderReorder(orderId, options, query) {
|
|
116
|
+
const params = query?.force_reorder ? "?force_reorder=true" : "";
|
|
117
|
+
const response = await storeFetch(`/orders/reorder/${encodeURIComponent(orderId)}${params}`, options, { method: "POST", body: JSON.stringify({}) });
|
|
118
|
+
const data = (await response.json().catch(() => ({})));
|
|
119
|
+
if (!response.ok) {
|
|
120
|
+
return { ok: false, status: response.status, data };
|
|
121
|
+
}
|
|
122
|
+
return { ok: true, data };
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* POST /store/guest-orders/:id/reorder
|
|
126
|
+
*/
|
|
127
|
+
export async function medusaGuestOrderReorder(orderId, options, query) {
|
|
128
|
+
const params = query?.force_reorder ? "?force_reorder=true" : "";
|
|
129
|
+
const response = await storeFetch(`/guest-orders/${encodeURIComponent(orderId)}/reorder${params}`, options, { method: "POST", body: JSON.stringify({}) });
|
|
130
|
+
const data = (await response.json().catch(() => ({})));
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
return { ok: false, status: response.status, data };
|
|
133
|
+
}
|
|
134
|
+
return { ok: true, data };
|
|
135
|
+
}
|
|
136
|
+
export function extractReorderCartId(data) {
|
|
137
|
+
const id = data.cart?.id || data.id || data.cart_id || data.reorder?.cart_id;
|
|
138
|
+
return typeof id === "string" ? id : undefined;
|
|
139
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type MedusaStoreClientOptions } from "./store-api";
|
|
2
|
+
export interface StorePaymentProvider {
|
|
3
|
+
id: string;
|
|
4
|
+
is_enabled?: boolean;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface StorePaymentProviderListResponse {
|
|
8
|
+
payment_providers: StorePaymentProvider[];
|
|
9
|
+
}
|
|
10
|
+
export interface StoreInitializePaymentSessionBody {
|
|
11
|
+
provider_id: string;
|
|
12
|
+
data?: Record<string, unknown>;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface StorePaymentSessionResponse {
|
|
16
|
+
payment_collection?: Record<string, unknown>;
|
|
17
|
+
payment_session?: Record<string, unknown>;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface StorePaymentDetail {
|
|
21
|
+
id: string;
|
|
22
|
+
type?: string;
|
|
23
|
+
detail_json?: Record<string, unknown>;
|
|
24
|
+
is_default?: boolean;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
export interface StorePaymentDetailsListResponse {
|
|
28
|
+
payment_details: StorePaymentDetail[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* GET /store/payment-providers?region_id=
|
|
32
|
+
*/
|
|
33
|
+
export declare function medusaPaymentProvidersList(regionId: string, options: MedusaStoreClientOptions): Promise<StorePaymentProviderListResponse>;
|
|
34
|
+
/**
|
|
35
|
+
* POST /store/payment-collections then POST /store/payment-collections/:id/payment-sessions
|
|
36
|
+
* (Medusa v2 — cart-scoped /payment-sessions is not available)
|
|
37
|
+
*/
|
|
38
|
+
export declare function medusaPaymentSessionInitiate(cartId: string, body: StoreInitializePaymentSessionBody, options: MedusaStoreClientOptions): Promise<StorePaymentSessionResponse>;
|
|
39
|
+
/**
|
|
40
|
+
* GET /store/payment-details
|
|
41
|
+
*/
|
|
42
|
+
export declare function medusaPaymentDetailsList(options: MedusaStoreClientOptions): Promise<StorePaymentDetailsListResponse>;
|
|
43
|
+
/**
|
|
44
|
+
* POST /store/payment-details
|
|
45
|
+
*/
|
|
46
|
+
export declare function medusaPaymentDetailCreate(type: "upi" | "bank" | "card", detail_json: Record<string, string>, options: MedusaStoreClientOptions): Promise<Record<string, unknown>>;
|
|
47
|
+
/**
|
|
48
|
+
* POST /store/payment-details/:id/make-default
|
|
49
|
+
*/
|
|
50
|
+
export declare function medusaPaymentDetailMakeDefault(id: string, options: MedusaStoreClientOptions): Promise<Record<string, unknown>>;
|
|
51
|
+
/**
|
|
52
|
+
* DELETE /store/payment-details/:id
|
|
53
|
+
*/
|
|
54
|
+
export declare function medusaPaymentDetailDelete(id: string, options: MedusaStoreClientOptions): Promise<void>;
|
|
55
|
+
//# sourceMappingURL=payment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../payment.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,wBAAwB,EAChC,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,oBAAoB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,O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