-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
customers.ts
110 lines (102 loc) · 3.56 KB
/
customers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import {
StoreCustomersListOrdersRes,
StoreCustomersRes,
StoreGetCustomersCustomerOrdersParams,
StorePostCustomersCustomerPasswordTokenReq,
StorePostCustomersCustomerReq,
StorePostCustomersReq,
StorePostCustomersResetPasswordReq,
} from "@medusajs/medusa"
import qs from "qs"
import { ResponsePromise } from "../typings"
import AddressesResource from "./addresses"
import BaseResource from "./base"
import PaymentMethodsResource from "./payment-methods"
class CustomerResource extends BaseResource {
public paymentMethods = new PaymentMethodsResource(this.client)
public addresses = new AddressesResource(this.client)
/**
* Creates a customer
* @param {StorePostCustomersReq} payload information of customer
* @param customHeaders
* @return { ResponsePromise<StoreCustomersRes>}
*/
create(
payload: StorePostCustomersReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCustomersRes> {
const path = `/store/customers`
return this.client.request("POST", path, payload, {}, customHeaders)
}
/**
* Retrieves the customer that is currently logged
* @param customHeaders
* @return {ResponsePromise<StoreCustomersRes>}
*/
retrieve(
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCustomersRes> {
const path = `/store/customers/me`
return this.client.request("GET", path, undefined, {}, customHeaders)
}
/**
* Updates a customer
* @param {StorePostCustomersCustomerReq} payload information to update customer with
* @param customHeaders
* @return {ResponsePromise<StoreCustomersRes>}
*/
update(
payload: StorePostCustomersCustomerReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCustomersRes> {
const path = `/store/customers/me`
return this.client.request("POST", path, payload, {}, customHeaders)
}
/**
* Retrieve customer orders
* @param {StoreGetCustomersCustomerOrdersParams} params optional params to retrieve orders
* @param customHeaders
* @return {ResponsePromise<StoreCustomersListOrdersRes>}
*/
listOrders(
params?: StoreGetCustomersCustomerOrdersParams,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCustomersListOrdersRes> {
let path = `/store/customers/me/orders`
if (params) {
const query = qs.stringify(params)
if (query) {
path += `?${query}`
}
}
return this.client.request("GET", path, undefined, {}, customHeaders)
}
/**
* Resets customer password
* @param {StorePostCustomersCustomerPasswordTokenReq} payload info used to reset customer password
* @param customHeaders
* @return {ResponsePromise<StoreCustomersRes>}
*/
resetPassword(
payload: StorePostCustomersResetPasswordReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCustomersRes> {
const path = `/store/customers/password-reset`
return this.client.request("POST", path, payload, {}, customHeaders)
}
/**
* Generates a reset password token, which can be used to reset the password.
* The token is not returned but should be sent out to the customer in an email.
* @param {StorePostCustomersCustomerPasswordTokenReq} payload info used to generate token
* @param customHeaders
* @return {ResponsePromise}
*/
generatePasswordToken(
payload: StorePostCustomersCustomerPasswordTokenReq,
customHeaders: Record<string, any> = {}
): ResponsePromise {
const path = `/store/customers/password-token`
return this.client.request("POST", path, payload, {}, customHeaders)
}
}
export default CustomerResource