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
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type MedusaStoreClientOptions } from "./store-api";
|
|
2
|
+
export interface StoreCustomerAddress {
|
|
3
|
+
id?: string;
|
|
4
|
+
first_name?: string;
|
|
5
|
+
last_name?: string;
|
|
6
|
+
company?: string;
|
|
7
|
+
address_1?: string;
|
|
8
|
+
address_2?: string;
|
|
9
|
+
city?: string;
|
|
10
|
+
postal_code?: string;
|
|
11
|
+
province?: string;
|
|
12
|
+
country_code?: string;
|
|
13
|
+
phone?: string;
|
|
14
|
+
is_default_billing?: boolean;
|
|
15
|
+
is_default_shipping?: boolean;
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface StoreCustomer {
|
|
20
|
+
id: string;
|
|
21
|
+
email?: string;
|
|
22
|
+
first_name?: string;
|
|
23
|
+
last_name?: string;
|
|
24
|
+
phone?: string;
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
|
+
addresses?: StoreCustomerAddress[];
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface StoreCustomerResponse {
|
|
30
|
+
customer: StoreCustomer;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* GET /store/customers/me
|
|
34
|
+
*/
|
|
35
|
+
export declare function medusaCustomerRetrieve(options: MedusaStoreClientOptions, query?: {
|
|
36
|
+
fields?: string;
|
|
37
|
+
}): Promise<StoreCustomerResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* POST /store/customers/me
|
|
40
|
+
*/
|
|
41
|
+
export declare function medusaCustomerUpdate(body: Record<string, unknown>, options: MedusaStoreClientOptions): Promise<StoreCustomerResponse>;
|
|
42
|
+
/**
|
|
43
|
+
* POST /store/customers
|
|
44
|
+
*/
|
|
45
|
+
export declare function medusaCustomerCreate(body: Record<string, unknown>, options: MedusaStoreClientOptions): Promise<StoreCustomerResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* POST /store/customers/me/addresses
|
|
48
|
+
*/
|
|
49
|
+
export declare function medusaCustomerCreateAddress(address: Record<string, unknown>, options: MedusaStoreClientOptions): Promise<StoreCustomerResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* POST /store/customers/me/addresses/:id
|
|
52
|
+
*/
|
|
53
|
+
export declare function medusaCustomerUpdateAddress(addressId: string, address: Record<string, unknown>, options: MedusaStoreClientOptions): Promise<StoreCustomerResponse>;
|
|
54
|
+
/**
|
|
55
|
+
* DELETE /store/customers/me/addresses/:id
|
|
56
|
+
*/
|
|
57
|
+
export declare function medusaCustomerDeleteAddress(addressId: string, options: MedusaStoreClientOptions): Promise<void>;
|
|
58
|
+
export declare function isAccountDeletionPendingError(error: unknown): boolean;
|
|
59
|
+
//# sourceMappingURL=customer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer.d.ts","sourceRoot":"","sources":["../customer.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,KAAK,wBAAwB,EAChC,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,oBAAoB;IACjC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,SAAS,CAAC,EAAE,oBAAoB,EAAE,CAAC;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IAClC,QAAQ,EAAE,aAAa,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CACxC,OAAO,EAAE,wBAAwB,EACjC,KAAK,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5B,OAAO,CAAC,qBAAqB,CAAC,CAOhC;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,qBAAqB,CAAC,CAMhC;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,qBAAqB,CAAC,CAMhC;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAC7C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,qBAAqB,CAAC,CAMhC;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAC7C,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,qBAAqB,CAAC,CAUhC;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAC7C,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,IAAI,CAAC,CASf;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAUrE"}
|
package/dist/customer.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { parseStoreErrorMessage, fieldsQuery, parseStoreJson, storeFetch, } from "./store-api";
|
|
2
|
+
/**
|
|
3
|
+
* GET /store/customers/me
|
|
4
|
+
*/
|
|
5
|
+
export async function medusaCustomerRetrieve(options, query) {
|
|
6
|
+
const response = await storeFetch(`/customers/me${fieldsQuery(query?.fields)}`, options, { method: "GET" });
|
|
7
|
+
return parseStoreJson(response, "Customer retrieve request");
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* POST /store/customers/me
|
|
11
|
+
*/
|
|
12
|
+
export async function medusaCustomerUpdate(body, options) {
|
|
13
|
+
const response = await storeFetch("/customers/me", options, {
|
|
14
|
+
method: "POST",
|
|
15
|
+
body: JSON.stringify(body),
|
|
16
|
+
});
|
|
17
|
+
return parseStoreJson(response, "Customer update request");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* POST /store/customers
|
|
21
|
+
*/
|
|
22
|
+
export async function medusaCustomerCreate(body, options) {
|
|
23
|
+
const response = await storeFetch("/customers", options, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
body: JSON.stringify(body),
|
|
26
|
+
});
|
|
27
|
+
return parseStoreJson(response, "Customer create request");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* POST /store/customers/me/addresses
|
|
31
|
+
*/
|
|
32
|
+
export async function medusaCustomerCreateAddress(address, options) {
|
|
33
|
+
const response = await storeFetch("/customers/me/addresses", options, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
body: JSON.stringify(address),
|
|
36
|
+
});
|
|
37
|
+
return parseStoreJson(response, "Customer address create request");
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* POST /store/customers/me/addresses/:id
|
|
41
|
+
*/
|
|
42
|
+
export async function medusaCustomerUpdateAddress(addressId, address, options) {
|
|
43
|
+
const response = await storeFetch(`/customers/me/addresses/${encodeURIComponent(addressId)}`, options, {
|
|
44
|
+
method: "POST",
|
|
45
|
+
body: JSON.stringify(address),
|
|
46
|
+
});
|
|
47
|
+
return parseStoreJson(response, "Customer address update request");
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* DELETE /store/customers/me/addresses/:id
|
|
51
|
+
*/
|
|
52
|
+
export async function medusaCustomerDeleteAddress(addressId, options) {
|
|
53
|
+
const response = await storeFetch(`/customers/me/addresses/${encodeURIComponent(addressId)}`, options, { method: "DELETE" });
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
throw new Error(await parseStoreErrorMessage(response, "Customer address delete request"));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function isAccountDeletionPendingError(error) {
|
|
59
|
+
const errStr = String(error).toLowerCase();
|
|
60
|
+
if (errStr.includes("active account deletion request")) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
if (error && typeof error === "object" && "message" in error) {
|
|
64
|
+
const message = String(error.message ?? "").toLowerCase();
|
|
65
|
+
return message.includes("active account deletion request");
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ported from B&B_ui/src/modules/account/components/facebook-login-button/actions.ts
|
|
3
|
+
* and B&B_ui/src/app/auth/facebook/callback/actions.ts
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes and validates redirect URI
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeRedirectUri(url: string, isLocalhost: boolean): string;
|
|
9
|
+
/**
|
|
10
|
+
* Validates redirect URI format
|
|
11
|
+
*/
|
|
12
|
+
export declare function validateRedirectUri(uri: string, isLocalhost: boolean, productionDomain: string): {
|
|
13
|
+
valid: boolean;
|
|
14
|
+
expected: string;
|
|
15
|
+
actual: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Initiates Facebook login
|
|
19
|
+
*/
|
|
20
|
+
export declare function performFacebookLogin(sdk: any, redirectUri: string): Promise<any>;
|
|
21
|
+
/**
|
|
22
|
+
* Decodes a JWT token safely
|
|
23
|
+
*/
|
|
24
|
+
export declare function decodeToken(token: string | null | undefined): any;
|
|
25
|
+
/**
|
|
26
|
+
* Refreshes auth token
|
|
27
|
+
*/
|
|
28
|
+
export declare function refreshToken(sdk: any): Promise<any>;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves current customer data
|
|
31
|
+
*/
|
|
32
|
+
export declare function retrieveCustomer(sdk: any, token?: string): Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new customer
|
|
35
|
+
*/
|
|
36
|
+
export declare function createCustomer(sdk: any, email: string, token: string): Promise<any>;
|
|
37
|
+
//# sourceMappingURL=facebook-login.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facebook-login.d.ts","sourceRoot":"","sources":["../facebook-login.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAG,MAAM,CAoB9E;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CA4BrJ;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,gBAavE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,OAmB3D;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,GAAG,gBAU1C;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,MAAM,gBAoB9D;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,gBAY1E"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ported from B&B_ui/src/modules/account/components/facebook-login-button/actions.ts
|
|
3
|
+
* and B&B_ui/src/app/auth/facebook/callback/actions.ts
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes and validates redirect URI
|
|
7
|
+
*/
|
|
8
|
+
export function normalizeRedirectUri(url, isLocalhost) {
|
|
9
|
+
try {
|
|
10
|
+
const urlObj = new URL(url);
|
|
11
|
+
// Remove trailing slash from pathname
|
|
12
|
+
urlObj.pathname = urlObj.pathname.replace(/\/$/, '');
|
|
13
|
+
// Ensure correct protocol
|
|
14
|
+
if (isLocalhost) {
|
|
15
|
+
urlObj.protocol = 'http:';
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
urlObj.protocol = 'https:';
|
|
19
|
+
}
|
|
20
|
+
// Reconstruct URL and remove trailing slash
|
|
21
|
+
return urlObj.toString().replace(/\/$/, '');
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.warn("Failed to normalize redirect URI:", error);
|
|
25
|
+
return url.replace(/\/$/, '');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validates redirect URI format
|
|
30
|
+
*/
|
|
31
|
+
export function validateRedirectUri(uri, isLocalhost, productionDomain) {
|
|
32
|
+
const envBaseUrl = process.env.NEXT_PUBLIC_BASE_URL || process.env.NEXT_PUBLIC_MEDUSA_STOREFRONT_URL;
|
|
33
|
+
let localhostBase = envBaseUrl ? envBaseUrl.replace(/\/$/, '') : '';
|
|
34
|
+
if (!localhostBase && typeof window !== 'undefined') {
|
|
35
|
+
localhostBase = window.location.origin;
|
|
36
|
+
}
|
|
37
|
+
const expected = isLocalhost
|
|
38
|
+
? `${localhostBase}/auth/customer/facebook/callback`
|
|
39
|
+
: `https://${productionDomain}/auth/customer/facebook/callback`;
|
|
40
|
+
const normalized = normalizeRedirectUri(uri, isLocalhost);
|
|
41
|
+
const valid = normalized === expected;
|
|
42
|
+
if (!valid) {
|
|
43
|
+
console.warn('⚠️ Redirect URI validation mismatch:', {
|
|
44
|
+
expected,
|
|
45
|
+
actual: normalized,
|
|
46
|
+
difference: normalized.replace(expected, '') || expected.replace(normalized, ''),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
valid,
|
|
51
|
+
expected,
|
|
52
|
+
actual: normalized,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Initiates Facebook login
|
|
57
|
+
*/
|
|
58
|
+
export async function performFacebookLogin(sdk, redirectUri) {
|
|
59
|
+
try {
|
|
60
|
+
const result = await sdk.client.fetch("/auth/customer/facebook", {
|
|
61
|
+
method: "POST",
|
|
62
|
+
body: {
|
|
63
|
+
redirect_uri: redirectUri
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.error("❌ Facebook login initiation failed:", error);
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Decodes a JWT token safely
|
|
75
|
+
*/
|
|
76
|
+
export function decodeToken(token) {
|
|
77
|
+
if (!token)
|
|
78
|
+
return null;
|
|
79
|
+
try {
|
|
80
|
+
const parts = token.split(".");
|
|
81
|
+
if (parts.length !== 3)
|
|
82
|
+
return null;
|
|
83
|
+
const payload = parts[1];
|
|
84
|
+
const paddedPayload = payload + "=".repeat((4 - (payload.length % 4)) % 4);
|
|
85
|
+
// Base64 decode
|
|
86
|
+
const decoded = typeof Buffer !== 'undefined'
|
|
87
|
+
? Buffer.from(paddedPayload.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf-8")
|
|
88
|
+
: atob(paddedPayload.replace(/-/g, "+").replace(/_/g, "/"));
|
|
89
|
+
return JSON.parse(decoded);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
console.error("Failed to decode token:", error);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Refreshes auth token
|
|
98
|
+
*/
|
|
99
|
+
export async function refreshToken(sdk) {
|
|
100
|
+
try {
|
|
101
|
+
const response = await sdk.client.fetch("/auth/token/refresh", {
|
|
102
|
+
method: "POST"
|
|
103
|
+
});
|
|
104
|
+
return typeof response === "string" ? response : response.token;
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.error("❌ Token refresh failed:", error);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Retrieves current customer data
|
|
113
|
+
*/
|
|
114
|
+
export async function retrieveCustomer(sdk, token) {
|
|
115
|
+
try {
|
|
116
|
+
const headers = {};
|
|
117
|
+
if (token) {
|
|
118
|
+
headers.authorization = `Bearer ${token}`;
|
|
119
|
+
}
|
|
120
|
+
const response = await sdk.client.fetch("/store/customers/me", {
|
|
121
|
+
method: "GET",
|
|
122
|
+
query: {
|
|
123
|
+
fields: "*orders",
|
|
124
|
+
},
|
|
125
|
+
headers,
|
|
126
|
+
});
|
|
127
|
+
return response.customer;
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
console.error("❌ Customer retrieval failed:", error);
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Creates a new customer
|
|
136
|
+
*/
|
|
137
|
+
export async function createCustomer(sdk, email, token) {
|
|
138
|
+
try {
|
|
139
|
+
const result = await sdk.store.customer.create({ email }, {}, { authorization: `Bearer ${token}` });
|
|
140
|
+
return result.customer;
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
console.error("❌ Customer creation failed:", error);
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type MedusaStoreClientOptions } from "./store-api";
|
|
2
|
+
export interface StoreShippingOption {
|
|
3
|
+
id: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
amount?: number;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface StoreShippingOptionsResponse {
|
|
9
|
+
shipping_options: StoreShippingOption[];
|
|
10
|
+
}
|
|
11
|
+
export interface StoreShippingOptionCalculateResponse {
|
|
12
|
+
shipping_option: StoreShippingOption;
|
|
13
|
+
}
|
|
14
|
+
export interface ShiprocketServiceabilityQuery {
|
|
15
|
+
pincode: string;
|
|
16
|
+
variant_id: string;
|
|
17
|
+
cod?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* GET /store/shipping-options?cart_id=
|
|
21
|
+
*/
|
|
22
|
+
export declare function medusaShippingOptionsList(cartId: string, options: MedusaStoreClientOptions, query?: {
|
|
23
|
+
is_return?: boolean;
|
|
24
|
+
}): Promise<StoreShippingOptionsResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* POST /store/shipping-options/:id/calculate
|
|
27
|
+
*/
|
|
28
|
+
export declare function medusaShippingOptionCalculate(optionId: string, cartId: string, options: MedusaStoreClientOptions, data?: Record<string, unknown>): Promise<StoreShippingOptionCalculateResponse>;
|
|
29
|
+
/**
|
|
30
|
+
* GET /store/shiprocket/serviceability
|
|
31
|
+
*/
|
|
32
|
+
export declare function medusaShiprocketServiceability(query: ShiprocketServiceabilityQuery, options: MedusaStoreClientOptions): Promise<Record<string, unknown>>;
|
|
33
|
+
//# sourceMappingURL=fulfillment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fulfillment.d.ts","sourceRoot":"","sources":["../fulfillment.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,wBAAwB,EAChC,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,mBAAmB;IAChC,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,4BAA4B;IACzC,gBAAgB,EAAE,mBAAmB,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,oCAAoC;IACjD,eAAe,EAAE,mBAAmB,CAAC;CACxC;AAED,MAAM,WAAW,6BAA6B;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAsB,yBAAyB,CAC3C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,wBAAwB,EACjC,KAAK,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,GAChC,OAAO,CAAC,4BAA4B,CAAC,CAUvC;AAED;;GAEG;AACH,wBAAsB,6BAA6B,CAC/C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,wBAAwB,EACjC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,oCAAoC,CAAC,CAkB/C;AAED;;GAEG;AACH,wBAAsB,8BAA8B,CAChD,KAAK,EAAE,6BAA6B,EACpC,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAiBlC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { parseStoreErrorMessage, parseStoreJson, storeFetch, } from "./store-api";
|
|
2
|
+
/**
|
|
3
|
+
* GET /store/shipping-options?cart_id=
|
|
4
|
+
*/
|
|
5
|
+
export async function medusaShippingOptionsList(cartId, options, query) {
|
|
6
|
+
const params = new URLSearchParams();
|
|
7
|
+
params.set("cart_id", cartId);
|
|
8
|
+
if (query?.is_return) {
|
|
9
|
+
params.set("is_return", "true");
|
|
10
|
+
}
|
|
11
|
+
const response = await storeFetch(`/shipping-options?${params.toString()}`, options, {
|
|
12
|
+
method: "GET",
|
|
13
|
+
});
|
|
14
|
+
return parseStoreJson(response, "Shipping options request");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* POST /store/shipping-options/:id/calculate
|
|
18
|
+
*/
|
|
19
|
+
export async function medusaShippingOptionCalculate(optionId, cartId, options, data) {
|
|
20
|
+
const body = { cart_id: cartId };
|
|
21
|
+
if (data) {
|
|
22
|
+
body.data = data;
|
|
23
|
+
}
|
|
24
|
+
const response = await storeFetch(`/shipping-options/${encodeURIComponent(optionId)}/calculate`, options, {
|
|
25
|
+
method: "POST",
|
|
26
|
+
body: JSON.stringify(body),
|
|
27
|
+
});
|
|
28
|
+
return parseStoreJson(response, "Shipping option calculate request");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* GET /store/shiprocket/serviceability
|
|
32
|
+
*/
|
|
33
|
+
export async function medusaShiprocketServiceability(query, options) {
|
|
34
|
+
const params = new URLSearchParams();
|
|
35
|
+
params.set("pincode", query.pincode);
|
|
36
|
+
params.set("variant_id", query.variant_id);
|
|
37
|
+
params.set("cod", String(query.cod ?? 0));
|
|
38
|
+
const response = await storeFetch(`/shiprocket/serviceability?${params.toString()}`, options, { method: "GET" });
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new Error(await parseStoreErrorMessage(response, "Shiprocket serviceability request"));
|
|
41
|
+
}
|
|
42
|
+
return response.json();
|
|
43
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface GiftMetadata {
|
|
2
|
+
is_gift?: boolean;
|
|
3
|
+
gift_from?: string;
|
|
4
|
+
gift_to?: string;
|
|
5
|
+
gift_message?: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface UpdateGiftMetadataOptions {
|
|
9
|
+
sdk: any;
|
|
10
|
+
cartId: string;
|
|
11
|
+
lineId: string;
|
|
12
|
+
quantity: number;
|
|
13
|
+
metadata: GiftMetadata;
|
|
14
|
+
}
|
|
15
|
+
export interface RemoveGiftMetadataOptions {
|
|
16
|
+
sdk: any;
|
|
17
|
+
cartId: string;
|
|
18
|
+
lineId: string;
|
|
19
|
+
quantity: number;
|
|
20
|
+
existingMeta: GiftMetadata;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Updates the metadata for a specific line item in a cart to include gift information.
|
|
24
|
+
*/
|
|
25
|
+
export declare function updateGiftMetadata({ sdk, cartId, lineId, quantity, metadata, }: UpdateGiftMetadataOptions): Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* Removes gift-related metadata from a specific line item in a cart.
|
|
28
|
+
*/
|
|
29
|
+
export declare function removeGiftMetadata({ sdk, cartId, lineId, quantity, existingMeta, }: RemoveGiftMetadataOptions): Promise<any>;
|
|
30
|
+
//# sourceMappingURL=gift-wrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gift-wrap.d.ts","sourceRoot":"","sources":["../gift-wrap.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,yBAAyB;IACtC,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,YAAY,CAAA;CACzB;AAED,MAAM,WAAW,yBAAyB;IACtC,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,YAAY,CAAA;CAC7B;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,EACrC,GAAG,EACH,MAAM,EACN,MAAM,EACN,QAAQ,EACR,QAAQ,GACX,EAAE,yBAAyB,gBAK3B;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,EACrC,GAAG,EACH,MAAM,EACN,MAAM,EACN,QAAQ,EACR,YAAY,GACf,EAAE,yBAAyB,gBAwB3B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Updates the metadata for a specific line item in a cart to include gift information.
|
|
3
|
+
*/
|
|
4
|
+
export async function updateGiftMetadata({ sdk, cartId, lineId, quantity, metadata, }) {
|
|
5
|
+
return await sdk.store.cart.updateLineItem(cartId, lineId, {
|
|
6
|
+
quantity,
|
|
7
|
+
metadata,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Removes gift-related metadata from a specific line item in a cart.
|
|
12
|
+
*/
|
|
13
|
+
export async function removeGiftMetadata({ sdk, cartId, lineId, quantity, existingMeta, }) {
|
|
14
|
+
// Create a new metadata object excluding gift fields
|
|
15
|
+
const { is_gift, gift_from, gift_to, gift_message, ...rest } = existingMeta;
|
|
16
|
+
// Medusa metadata update usually merges, but we might need to explicitly set to null/empty
|
|
17
|
+
// or use the rest if we want to "remove" them depending on how the SDK/API handles it.
|
|
18
|
+
// For Medusa v2, we often just pass the new metadata object.
|
|
19
|
+
return await sdk.store.cart.updateLineItem(cartId, lineId, {
|
|
20
|
+
quantity,
|
|
21
|
+
metadata: {
|
|
22
|
+
...rest,
|
|
23
|
+
is_gift: false,
|
|
24
|
+
gift_from: "",
|
|
25
|
+
gift_to: "",
|
|
26
|
+
gift_message: "",
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ported from B&B_ui/src/modules/account/components/google-login-button/actions.ts
|
|
3
|
+
* and B&B_ui/src/app/auth/google/callback/actions.ts
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes and validates redirect URI to match Google OAuth console exactly
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeRedirectUri(url: string, isLocalhost: boolean): string;
|
|
9
|
+
/**
|
|
10
|
+
* Validates and constructs the expected redirect URI
|
|
11
|
+
*/
|
|
12
|
+
export declare function validateRedirectUri(uri: string, isLocalhost: boolean, productionDomain: string, callbackPath?: string): {
|
|
13
|
+
valid: boolean;
|
|
14
|
+
expected: string;
|
|
15
|
+
actual: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Initiates Google login
|
|
19
|
+
*/
|
|
20
|
+
export declare function performGoogleLogin(sdk: any, redirectUri: string): Promise<any>;
|
|
21
|
+
/**
|
|
22
|
+
* Decodes a JWT token safely
|
|
23
|
+
*/
|
|
24
|
+
export declare function decodeToken(token: string | null | undefined): any;
|
|
25
|
+
/**
|
|
26
|
+
* Refreshes auth token
|
|
27
|
+
*/
|
|
28
|
+
export declare function refreshToken(sdk: any): Promise<string | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves current customer data
|
|
31
|
+
*/
|
|
32
|
+
export declare function retrieveCustomer(sdk: any, token?: string): Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new customer
|
|
35
|
+
*/
|
|
36
|
+
export declare function createCustomer(sdk: any, email: string, token: string): Promise<any>;
|
|
37
|
+
//# sourceMappingURL=google-login.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-login.d.ts","sourceRoot":"","sources":["../google-login.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAG,MAAM,CAoB9E;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAC/B,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,OAAO,EACpB,gBAAgB,EAAE,MAAM,EACxB,YAAY,GAAE,MAAyC,GACxD;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAqCtD;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,gBAUrE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,OAmB3D;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,GAAG,0BAQ1C;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,MAAM,gBAoB9D;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,gBAY1E"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ported from B&B_ui/src/modules/account/components/google-login-button/actions.ts
|
|
3
|
+
* and B&B_ui/src/app/auth/google/callback/actions.ts
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes and validates redirect URI to match Google OAuth console exactly
|
|
7
|
+
*/
|
|
8
|
+
export function normalizeRedirectUri(url, isLocalhost) {
|
|
9
|
+
try {
|
|
10
|
+
const urlObj = new URL(url);
|
|
11
|
+
// Remove trailing slash from pathname
|
|
12
|
+
urlObj.pathname = urlObj.pathname.replace(/\/$/, '');
|
|
13
|
+
// Ensure correct protocol
|
|
14
|
+
if (isLocalhost) {
|
|
15
|
+
urlObj.protocol = 'http:';
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
urlObj.protocol = 'https:';
|
|
19
|
+
}
|
|
20
|
+
// Reconstruct URL and remove trailing slash
|
|
21
|
+
return urlObj.toString().replace(/\/$/, '');
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.warn("Failed to normalize redirect URI:", error);
|
|
25
|
+
return url.replace(/\/$/, '');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validates and constructs the expected redirect URI
|
|
30
|
+
*/
|
|
31
|
+
export function validateRedirectUri(uri, isLocalhost, productionDomain, callbackPath = '/auth/customer/google/callback') {
|
|
32
|
+
const getEnvVar = (name) => {
|
|
33
|
+
try {
|
|
34
|
+
return process.env?.[name] || import.meta.env?.[name];
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
let localhostBase = getEnvVar('NEXT_PUBLIC_MEDUSA_STOREFRONT_URL') ||
|
|
41
|
+
getEnvVar('NEXT_PUBLIC_BASE_URL') ||
|
|
42
|
+
'';
|
|
43
|
+
if (!localhostBase && typeof window !== 'undefined') {
|
|
44
|
+
localhostBase = window.location.origin;
|
|
45
|
+
}
|
|
46
|
+
const expected = isLocalhost
|
|
47
|
+
? `${localhostBase.replace(/\/$/, '')}${callbackPath}`
|
|
48
|
+
: `https://${productionDomain}${callbackPath}`;
|
|
49
|
+
const normalized = normalizeRedirectUri(uri, isLocalhost);
|
|
50
|
+
const valid = normalized === expected;
|
|
51
|
+
if (!valid) {
|
|
52
|
+
console.warn('⚠️ Redirect URI validation mismatch:', {
|
|
53
|
+
expected,
|
|
54
|
+
actual: normalized,
|
|
55
|
+
difference: normalized.replace(expected, '') || expected.replace(normalized, ''),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
valid,
|
|
60
|
+
expected,
|
|
61
|
+
actual: normalized,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Initiates Google login
|
|
66
|
+
*/
|
|
67
|
+
export async function performGoogleLogin(sdk, redirectUri) {
|
|
68
|
+
try {
|
|
69
|
+
const result = await sdk.auth.login("customer", "google", {
|
|
70
|
+
redirect_uri: redirectUri
|
|
71
|
+
});
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error("❌ Google login initiation failed:", error);
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Decodes a JWT token safely
|
|
81
|
+
*/
|
|
82
|
+
export function decodeToken(token) {
|
|
83
|
+
if (!token)
|
|
84
|
+
return null;
|
|
85
|
+
try {
|
|
86
|
+
const parts = token.split(".");
|
|
87
|
+
if (parts.length !== 3)
|
|
88
|
+
return null;
|
|
89
|
+
const payload = parts[1];
|
|
90
|
+
const paddedPayload = payload + "=".repeat((4 - (payload.length % 4)) % 4);
|
|
91
|
+
// Base64 decode
|
|
92
|
+
const decoded = typeof Buffer !== 'undefined'
|
|
93
|
+
? Buffer.from(paddedPayload.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf-8")
|
|
94
|
+
: atob(paddedPayload.replace(/-/g, "+").replace(/_/g, "/"));
|
|
95
|
+
return JSON.parse(decoded);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error("Failed to decode token:", error);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Refreshes auth token
|
|
104
|
+
*/
|
|
105
|
+
export async function refreshToken(sdk) {
|
|
106
|
+
try {
|
|
107
|
+
const newToken = await sdk.auth.refresh();
|
|
108
|
+
return newToken;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error("❌ Token refresh failed:", error);
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Retrieves current customer data
|
|
117
|
+
*/
|
|
118
|
+
export async function retrieveCustomer(sdk, token) {
|
|
119
|
+
try {
|
|
120
|
+
const headers = {};
|
|
121
|
+
if (token) {
|
|
122
|
+
headers.authorization = `Bearer ${token}`;
|
|
123
|
+
}
|
|
124
|
+
const response = await sdk.client.fetch("/store/customers/me", {
|
|
125
|
+
method: "GET",
|
|
126
|
+
query: {
|
|
127
|
+
fields: "*orders",
|
|
128
|
+
},
|
|
129
|
+
headers,
|
|
130
|
+
});
|
|
131
|
+
return response.customer;
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error("❌ Customer retrieval failed:", error);
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Creates a new customer
|
|
140
|
+
*/
|
|
141
|
+
export async function createCustomer(sdk, email, token) {
|
|
142
|
+
try {
|
|
143
|
+
const result = await sdk.store.customer.create({ email }, {}, { authorization: `Bearer ${token}` });
|
|
144
|
+
return result.customer;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.error("❌ Customer creation failed:", error);
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}
|