fix: Accept invite in admin (#7393)

* fix: Accept invite in admin

* fix: Accept invite in admin

* minor fix
This commit is contained in:
Oli Juhl
2024-05-22 21:40:38 +02:00
committed by GitHub
parent bb5872de48
commit 4ee47cf9b1
13 changed files with 210 additions and 57 deletions
+72
View File
@@ -80,4 +80,76 @@ export class Admin {
)
},
}
public invites = {
accept: async (
input: HttpTypes.AdminAcceptInvite & { invite_token: string },
query?: SelectParams,
headers?: ClientHeaders
) => {
const { invite_token, ...rest } = input
return this.client.fetch<{ user: HttpTypes.AdminUserResponse }>(
`/admin/invites/accept?token=${input.invite_token}`,
{
method: "POST",
headers,
body: rest,
query,
}
)
},
create: async (
body: HttpTypes.AdminCreateInvite,
query?: SelectParams,
headers?: ClientHeaders
) => {
return this.client.fetch<{ invite: HttpTypes.AdminInviteResponse }>(
`/admin/invites`,
{
method: "POST",
headers,
body,
query,
}
)
},
retrieve: async (
id: string,
query?: SelectParams,
headers?: ClientHeaders
) => {
return this.client.fetch<{ invite: HttpTypes.AdminInviteResponse }>(
`/admin/invites/${id}`,
{
headers,
query,
}
)
},
list: async (queryParams?: FindParams, headers?: ClientHeaders) => {
return this.client.fetch<
PaginatedResponse<{ invites: HttpTypes.AdminInviteResponse[] }>
>(`/admin/invites`, {
headers,
query: queryParams,
})
},
resend: async (id: string, headers?: ClientHeaders) => {
return this.client.fetch<{ invite: HttpTypes.AdminInviteResponse }>(
`/admin/invites/${id}/resend`,
{
headers,
}
)
},
delete: async (id: string, headers?: ClientHeaders) => {
return this.client.fetch<DeleteResponse<"invite">>(
`/admin/invites/${id}`,
{
method: "DELETE",
headers,
}
)
},
}
}
+12 -1
View File
@@ -10,7 +10,7 @@ export class Auth {
this.config = config
}
login = async (
public login = async (
scope: "admin" | "store",
method: "emailpass",
payload: { email: string; password: string }
@@ -43,4 +43,15 @@ export class Auth {
this.client.clearToken()
}
create = async (
scope: "admin" | "store",
method: "emailpass",
payload: { email: string; password: string }
): Promise<{ token: string }> => {
return await this.client.fetch(`/auth/${scope}/${method}`, {
method: "POST",
body: payload,
})
}
}
+4 -2
View File
@@ -161,8 +161,10 @@ export class Client {
if (input instanceof URL || typeof input === "string") {
normalizedInput = new URL(input, this.config.baseUrl)
if (init?.query) {
const existing = qs.parse(normalizedInput.search)
const stringifiedQuery = qs.stringify({ existing, ...init.query })
const params = Object.fromEntries(
normalizedInput.searchParams.entries()
)
const stringifiedQuery = qs.stringify({ ...params, ...init.query })
normalizedInput.search = stringifiedQuery
}
}