feat: Adds Auth Admin API to medusa-js (#917)
This commit is contained in:
1 parent
34ad5bbd4e
commit
5c47184b10
5 files changed
+81
-31
No files matched your search
@@ -1,21 +1,24 @@
|
||||
import MedusaError from "./error"
|
||||
import Client, { Config } from "./request"
|
||||
import Admin from "./resources/admin"
|
||||
import AuthResource from "./resources/auth"
|
||||
import CartsResource from "./resources/carts"
|
||||
import CollectionsResource from "./resources/collections"
|
||||
import CustomersResource from "./resources/customers"
|
||||
import GiftCardsResource from "./resources/gift-cards"
|
||||
import OrdersResource from "./resources/orders"
|
||||
import PaymentMethodsResource from "./resources/payment-methods"
|
||||
import ProductsResource from "./resources/products"
|
||||
import RegionsResource from "./resources/regions"
|
||||
import ReturnReasonsResource from "./resources/return-reasons"
|
||||
import ReturnsResource from "./resources/returns"
|
||||
import ShippingOptionsResource from "./resources/shipping-options"
|
||||
import SwapsResource from "./resources/swaps"
|
||||
import PaymentMethodsResource from "./resources/payment-methods"
|
||||
|
||||
class Medusa {
|
||||
private client: Client
|
||||
public admin: Admin
|
||||
|
||||
public auth: AuthResource
|
||||
public carts: CartsResource
|
||||
public customers: CustomersResource
|
||||
@@ -34,6 +37,8 @@ class Medusa {
|
||||
constructor(config: Config) {
|
||||
this.client = new Client(config)
|
||||
|
||||
this.admin = new Admin(this.client)
|
||||
|
||||
this.auth = new AuthResource(this.client)
|
||||
this.carts = new CartsResource(this.client)
|
||||
this.customers = new CustomersResource(this.client)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { AdminAuthRes, AdminPostAuthReq } from "@medusajs/medusa"
|
||||
import { ResponsePromise } from "../../typings"
|
||||
import BaseResource from "../base"
|
||||
|
||||
class AdminAuthResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves an authenticated session
|
||||
* Usually used to check if authenticated session is alive.
|
||||
* @return {ResponsePromise<AdminAuthRes>}
|
||||
*/
|
||||
getSession(): ResponsePromise<AdminAuthRes> {
|
||||
const path = `/admin/auth`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description destroys an authenticated session
|
||||
* @return {ResponsePromise<void>}
|
||||
*/
|
||||
deleteSession(): ResponsePromise<void> {
|
||||
const path = `/admin/auth`
|
||||
return this.client.request("DELETE", path)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Creates an authenticated session
|
||||
* @param {AdminPostAuthReq} payload
|
||||
* @return {ResponsePromise<AdminAuthRes>}
|
||||
*/
|
||||
createSession(payload: AdminPostAuthReq): ResponsePromise<AdminAuthRes> {
|
||||
const path = `/admin/auth`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
}
|
||||
|
||||
export default AdminAuthResource
|
||||
@@ -0,0 +1,8 @@
|
||||
import BaseResource from "../base"
|
||||
import AdminAuthResource from "./auth"
|
||||
|
||||
class Admin extends BaseResource {
|
||||
public auth = new AdminAuthResource(this.client)
|
||||
}
|
||||
|
||||
export default Admin
|
||||
Reference in new issue
Block a user