Skip to content

Commit c3440e5

Browse files
authored
feat(medusa,types): add enabled plugins route (medusajs#11876)
1 parent 9dd62d9 commit c3440e5

File tree

7 files changed

+69
-0
lines changed

7 files changed

+69
-0
lines changed

.changeset/giant-llamas-study.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@medusajs/types": patch
3+
"@medusajs/medusa": patch
4+
"@medusajs/js-sdk": patch
5+
---
6+
7+
feat(medusa,types,js-sdk): add enabled plugins route

packages/core/js-sdk/src/admin/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Order } from "./order"
1717
import { OrderEdit } from "./order-edit"
1818
import { Payment } from "./payment"
1919
import { PaymentCollection } from "./payment-collection"
20+
import { Plugin } from "./plugin"
2021
import { PriceList } from "./price-list"
2122
import { PricePreference } from "./price-preference"
2223
import { Product } from "./product"
@@ -211,6 +212,10 @@ export class Admin {
211212
* @tags promotion
212213
*/
213214
public campaign: Campaign
215+
/**
216+
* @tags plugin
217+
*/
218+
public plugin: Plugin
214219

215220
constructor(client: Client) {
216221
this.invite = new Invite(client)
@@ -255,5 +260,6 @@ export class Admin {
255260
this.customerGroup = new CustomerGroup(client)
256261
this.promotion = new Promotion(client)
257262
this.campaign = new Campaign(client)
263+
this.plugin = new Plugin(client)
258264
}
259265
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { HttpTypes } from "@medusajs/types"
2+
import { Client } from "../client"
3+
import { ClientHeaders } from "../types"
4+
5+
export class Plugin {
6+
private client: Client
7+
8+
constructor(client: Client) {
9+
this.client = client
10+
}
11+
12+
async list(headers?: ClientHeaders) {
13+
return await this.client.fetch<HttpTypes.AdminPluginsListResponse>(
14+
`/admin/plugins`,
15+
{
16+
headers,
17+
query: {},
18+
}
19+
)
20+
}
21+
}

packages/core/types/src/http/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export * from "./notification"
2222
export * from "./order"
2323
export * from "./order-edit"
2424
export * from "./payment"
25+
export * from "./plugins"
2526
export * from "./price-list"
2627
export * from "./pricing"
2728
export * from "./product"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface AdminPlugin {
2+
name: string
3+
}
4+
5+
export interface AdminPluginsListResponse {
6+
/**
7+
* The plugin's details.
8+
*/
9+
plugins: AdminPlugin[]
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./admin/responses"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2+
import { HttpTypes } from "@medusajs/framework/types"
3+
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
4+
import { isString } from "lodash"
5+
6+
export const GET = async (
7+
req: MedusaRequest<unknown>,
8+
res: MedusaResponse<HttpTypes.AdminPluginsListResponse>
9+
) => {
10+
const configModule = req.scope.resolve(
11+
ContainerRegistrationKeys.CONFIG_MODULE
12+
)
13+
14+
const configPlugins = configModule.plugins ?? []
15+
16+
const plugins = configPlugins.map((plugin) => ({
17+
name: isString(plugin) ? plugin : plugin.resolve,
18+
}))
19+
20+
res.json({
21+
plugins,
22+
})
23+
}

0 commit comments

Comments
 (0)