feat: Update customer related typings and sdk methods (#7440)
This commit is contained in:
@@ -28,8 +28,15 @@ const server = setupServer(
|
||||
})
|
||||
}
|
||||
}),
|
||||
http.get(`${baseUrl}/replaced-header`, ({ request, params, cookies }) => {
|
||||
request.headers
|
||||
if (request.headers.get("Content-Type") === "application/xml") {
|
||||
return HttpResponse.json({
|
||||
test: "test",
|
||||
})
|
||||
}
|
||||
}),
|
||||
http.get(`${baseUrl}/apikey`, ({ request, params, cookies }) => {
|
||||
console.log(request.headers.get("authorization"))
|
||||
if (request.headers.get("authorization")?.startsWith("Basic")) {
|
||||
return HttpResponse.json({
|
||||
test: "test",
|
||||
@@ -85,6 +92,14 @@ describe("Client", () => {
|
||||
expect(resp).toEqual({ test: "test" })
|
||||
})
|
||||
|
||||
it("should allow replacing a default header", async () => {
|
||||
const resp = await client.fetch<any>("replaced-header", {
|
||||
headers: { "content-Type": "application/xml" },
|
||||
})
|
||||
|
||||
expect(resp).toEqual({ test: "test" })
|
||||
})
|
||||
|
||||
it("should allow passing global headers", async () => {
|
||||
const headClient = new Client({
|
||||
baseUrl,
|
||||
|
||||
@@ -152,4 +152,68 @@ export class Admin {
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
public customer = {
|
||||
create: async (
|
||||
body: HttpTypes.AdminCreateCustomer,
|
||||
query?: SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) => {
|
||||
return this.client.fetch<{
|
||||
customer: HttpTypes.AdminCustomer
|
||||
token: string
|
||||
}>(`/admin/customers`, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
})
|
||||
},
|
||||
update: async (
|
||||
id: string,
|
||||
body: HttpTypes.AdminUpdateCustomer,
|
||||
query?: SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) => {
|
||||
return this.client.fetch<{ customer: HttpTypes.AdminCustomer }>(
|
||||
`/admin/customers/${id}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
},
|
||||
list: async (queryParams?: FindParams, headers?: ClientHeaders) => {
|
||||
return this.client.fetch<
|
||||
PaginatedResponse<{ customers: HttpTypes.AdminCustomer[] }>
|
||||
>(`/admin/customers`, {
|
||||
headers,
|
||||
query: queryParams,
|
||||
})
|
||||
},
|
||||
retrieve: async (
|
||||
id: string,
|
||||
query?: SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) => {
|
||||
return this.client.fetch<{ customer: HttpTypes.AdminCustomer }>(
|
||||
`/admin/customers/${id}`,
|
||||
{
|
||||
query,
|
||||
headers,
|
||||
}
|
||||
)
|
||||
},
|
||||
delete: async (id: string, headers?: ClientHeaders) => {
|
||||
return this.client.fetch<DeleteResponse<"customer">>(
|
||||
`/admin/customers/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers,
|
||||
}
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ export class Auth {
|
||||
} else {
|
||||
this.client.setToken(token)
|
||||
}
|
||||
|
||||
return token
|
||||
}
|
||||
|
||||
logout = async () => {
|
||||
|
||||
@@ -20,7 +20,7 @@ const toBase64 = (str: string) => {
|
||||
const sanitizeHeaders = (headers: Headers) => {
|
||||
return {
|
||||
...Object.fromEntries(headers.entries()),
|
||||
Authorization: "<REDACTED>",
|
||||
authorization: "<REDACTED>",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,9 @@ const normalizeRequest = (
|
||||
|
||||
const normalizeResponse = async (resp: Response, reqHeaders: Headers) => {
|
||||
if (resp.status >= 300) {
|
||||
const jsonError = await resp.json().catch(() => ({})) as { message?: string }
|
||||
const jsonError = (await resp.json().catch(() => ({}))) as {
|
||||
message?: string
|
||||
}
|
||||
throw new FetchError(
|
||||
jsonError.message ?? resp.statusText,
|
||||
resp.statusText,
|
||||
|
||||
@@ -314,6 +314,17 @@ export class Store {
|
||||
}
|
||||
|
||||
public order = {
|
||||
list: async (
|
||||
query?: FindParams & HttpTypes.StoreOrderFilters,
|
||||
headers?: ClientHeaders
|
||||
) => {
|
||||
return this.client.fetch<
|
||||
PaginatedResponse<{ orders: HttpTypes.StoreOrder[] }>
|
||||
>(`/store/orders`, {
|
||||
query,
|
||||
headers,
|
||||
})
|
||||
},
|
||||
retrieve: async (
|
||||
id: string,
|
||||
query?: SelectParams,
|
||||
@@ -328,4 +339,46 @@ export class Store {
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
public customer = {
|
||||
create: async (
|
||||
body: HttpTypes.StoreCreateCustomer,
|
||||
query?: SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) => {
|
||||
return this.client.fetch<{
|
||||
customer: HttpTypes.StoreCustomer
|
||||
token: string
|
||||
}>(`/store/customers`, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
})
|
||||
},
|
||||
update: async (
|
||||
body: HttpTypes.StoreUpdateCustomer,
|
||||
query?: SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) => {
|
||||
return this.client.fetch<{ customer: HttpTypes.StoreCustomer }>(
|
||||
`/store/customers/me`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
},
|
||||
retrieve: async (query?: SelectParams, headers?: ClientHeaders) => {
|
||||
return this.client.fetch<{ customer: HttpTypes.StoreCustomer }>(
|
||||
`/store/customers/me`,
|
||||
{
|
||||
query,
|
||||
headers,
|
||||
}
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user