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
}
}
+10 -8
View File
@@ -1,20 +1,22 @@
export * from "./api-key"
export * from "./campaign"
export * from "./cart"
export * from "./collection"
export * from "./common"
export * from "./customer"
export * from "./fulfillment"
export * from "./inventory"
export * from "./invite"
export * from "./order"
export * from "./payment"
export * from "./pricing"
export * from "./product"
export * from "./product-category"
export * from "./promotion"
export * from "./region"
export * from "./reservation"
export * from "./sales-channel"
export * from "./stock-locations"
export * from "./tax"
export * from "./product-category"
export * from "./reservation"
export * from "./region"
export * from "./product"
export * from "./cart"
export * from "./payment"
export * from "./collection"
export * from "./common"
export * from "./user"
@@ -0,0 +1,20 @@
export type AdminAcceptInvite = {
first_name: string
last_name: string
}
export type AdminCreateInvite = {
email: string
metadata?: Record<string, unknown>
}
export type AdminInviteResponse = {
id: string
email: string
accepted: boolean
token: string
expires_at?: Date
metadata?: Record<string, unknown>
created_at?: Date
updated_at?: Date
}
@@ -0,0 +1 @@
export * from "./admin"
@@ -0,0 +1,3 @@
import { BaseUserResponse } from "./common"
export type AdminUserResponse = BaseUserResponse
@@ -0,0 +1,11 @@
export type BaseUserResponse = {
id: string
email: string
first_name: string | null
last_name: string | null
avatar_url: string | null
metadata: Record<string, unknown> | null
created_at: Date
updated_at: Date
deleted_at: Date | null
}
@@ -0,0 +1,2 @@
export * from "./admin";