-
Notifications
You must be signed in to change notification settings - Fork 0
[codex] symmy endpoints #474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c218422
feat(symmy): endpoints
ztomas-codes 4c69d15
fix(symmy): add jose dependency
ztomas-codes 3d2a8b0
fix symmy admin routes
ztomas-codes 558a060
fix(symmy): address review feedback
ztomas-codes 41d79b7
fix(herbatika): sort search classes
ztomas-codes 10eb955
fix(symmy): address review comments
ztomas-codes cdecffa
fix(symmy): guard customer pagination metadata
ztomas-codes a912f41
fix(symmy): avoid auth enumeration
ztomas-codes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
apps/medusa-symmy-plugin/src/api/api/symmy/v1/admin/customers/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http" | ||
| import type { Query } from "@medusajs/framework/types" | ||
| import { ContainerRegistrationKeys } from "@medusajs/framework/utils" | ||
|
|
||
| export const GET = async (req: MedusaRequest, res: MedusaResponse) => { | ||
| const query = req.scope.resolve<Query>(ContainerRegistrationKeys.QUERY) | ||
| const { data, metadata } = await query.graph({ | ||
| entity: "customer", | ||
| fields: req.queryConfig.fields, | ||
| filters: req.filterableFields, | ||
| pagination: req.queryConfig.pagination, | ||
| }) | ||
| const paginationMetadata = metadata ?? { | ||
| count: Array.isArray(data) ? data.length : 0, | ||
| skip: 0, | ||
| take: Array.isArray(data) ? data.length : 0, | ||
| } | ||
|
|
||
| res.json({ | ||
| customers: data, | ||
| count: paginationMetadata.count, | ||
| offset: paginationMetadata.skip, | ||
| limit: paginationMetadata.take, | ||
| }) | ||
| } |
138 changes: 138 additions & 0 deletions
138
apps/medusa-symmy-plugin/src/api/api/symmy/v1/admin/middlewares.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| import type { | ||
| MedusaNextFunction, | ||
| MedusaRequest, | ||
| MedusaResponse, | ||
| MiddlewareRoute, | ||
| } from "@medusajs/framework/http" | ||
| import { | ||
| authenticate, | ||
| maybeApplyLinkFilter, | ||
| validateAndTransformQuery, | ||
| } from "@medusajs/framework/http" | ||
| import { PolicyOperation } from "@medusajs/framework/utils" | ||
| import { | ||
| Entities as CustomersEntities, | ||
| listTransformQueryConfig as customersListTransformQueryConfig, | ||
| } from "@medusajs/medusa/api/admin/customers/query-config" | ||
| import { AdminCustomersParams } from "@medusajs/medusa/api/admin/customers/validators" | ||
| import { | ||
| Entities as OrdersEntities, | ||
| listTransformQueryConfig as ordersListTransformQueryConfig, | ||
| } from "@medusajs/medusa/api/admin/orders/query-config" | ||
| import { AdminGetOrdersParams } from "@medusajs/medusa/api/admin/orders/validators" | ||
| import { | ||
| listProductQueryConfig, | ||
| Entities as ProductsEntities, | ||
| } from "@medusajs/medusa/api/admin/products/query-config" | ||
| import { maybeApplyPriceListsFilter } from "@medusajs/medusa/api/admin/products/utils/maybe-apply-price-lists-filter" | ||
| import { AdminGetProductsParams } from "@medusajs/medusa/api/admin/products/validators" | ||
| import { | ||
| Entities as RegionsEntities, | ||
| listTransformQueryConfig as regionsListTransformQueryConfig, | ||
| } from "@medusajs/medusa/api/admin/regions/query-config" | ||
| import { AdminGetRegionsParams } from "@medusajs/medusa/api/admin/regions/validators" | ||
| import { | ||
| Entities as UsersEntities, | ||
| retrieveTransformQueryConfig as usersRetrieveTransformQueryConfig, | ||
| } from "@medusajs/medusa/api/admin/users/query-config" | ||
| import { AdminGetUserParams } from "@medusajs/medusa/api/admin/users/validators" | ||
|
|
||
| export const symmyAdminRoutes: MiddlewareRoute[] = [ | ||
| { | ||
| methods: ["GET"], | ||
| matcher: "/api/symmy/v1/admin/orders", | ||
| middlewares: [ | ||
| authenticate("user", ["bearer", "session", "api-key"]), | ||
| validateAndTransformQuery( | ||
| AdminGetOrdersParams, | ||
| ordersListTransformQueryConfig | ||
| ), | ||
| ], | ||
| policies: [ | ||
| { | ||
| resource: OrdersEntities.order, | ||
| operation: PolicyOperation.read, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| methods: ["GET"], | ||
| matcher: "/api/symmy/v1/admin/customers", | ||
| middlewares: [ | ||
| authenticate("user", ["bearer", "session", "api-key"]), | ||
| validateAndTransformQuery( | ||
| AdminCustomersParams, | ||
| customersListTransformQueryConfig | ||
| ), | ||
| ], | ||
| policies: [ | ||
| { | ||
| resource: CustomersEntities.customer, | ||
| operation: PolicyOperation.read, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| methods: ["GET"], | ||
| matcher: "/api/symmy/v1/admin/products", | ||
| middlewares: [ | ||
| authenticate("user", ["bearer", "session", "api-key"]), | ||
| validateAndTransformQuery(AdminGetProductsParams, listProductQueryConfig), | ||
| (req: MedusaRequest, res: MedusaResponse, next: MedusaNextFunction) => { | ||
| if ( | ||
| !req.filterableFields || | ||
| Object.keys(req.filterableFields).length === 0 | ||
| ) { | ||
| return next() | ||
| } | ||
|
|
||
| return maybeApplyLinkFilter({ | ||
| entryPoint: "product_sales_channel", | ||
| resourceId: "product_id", | ||
| filterableField: "sales_channel_id", | ||
| })(req, res, next) | ||
| }, | ||
| maybeApplyPriceListsFilter(), | ||
| ], | ||
| policies: [ | ||
| { | ||
| resource: ProductsEntities.product, | ||
| operation: PolicyOperation.read, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| methods: ["GET"], | ||
| matcher: "/api/symmy/v1/admin/regions", | ||
| middlewares: [ | ||
| authenticate("user", ["bearer", "session", "api-key"]), | ||
| validateAndTransformQuery( | ||
| AdminGetRegionsParams, | ||
| regionsListTransformQueryConfig | ||
| ), | ||
| ], | ||
| policies: [ | ||
| { | ||
| resource: RegionsEntities.region, | ||
| operation: PolicyOperation.read, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| methods: ["GET"], | ||
| matcher: "/api/symmy/v1/admin/users/me", | ||
| middlewares: [ | ||
| authenticate("user", ["bearer", "session", "api-key"]), | ||
| validateAndTransformQuery( | ||
| AdminGetUserParams, | ||
| usersRetrieveTransformQueryConfig | ||
| ), | ||
| ], | ||
| policies: [ | ||
| { | ||
| resource: UsersEntities.user, | ||
| operation: PolicyOperation.read, | ||
| }, | ||
| ], | ||
| }, | ||
| ] | ||
37 changes: 37 additions & 0 deletions
37
apps/medusa-symmy-plugin/src/api/api/symmy/v1/admin/orders/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { getOrdersListWorkflow } from "@medusajs/core-flows" | ||
| import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http" | ||
| import { MedusaError } from "@medusajs/framework/utils" | ||
|
|
||
| export const GET = async (req: MedusaRequest, res: MedusaResponse) => { | ||
| const variables = { | ||
| filters: { | ||
| ...req.filterableFields, | ||
| is_draft_order: false, | ||
| }, | ||
| ...req.queryConfig.pagination, | ||
| } | ||
|
|
||
| const workflow = getOrdersListWorkflow(req.scope) | ||
| const { result } = await workflow.run({ | ||
| input: { | ||
| fields: req.queryConfig.fields, | ||
| variables, | ||
| }, | ||
| }) | ||
|
|
||
| if (Array.isArray(result)) { | ||
| throw new MedusaError( | ||
| MedusaError.Types.UNEXPECTED_STATE, | ||
| "Unexpected orders workflow result" | ||
| ) | ||
| } | ||
|
|
||
| const { rows: orders, metadata } = result | ||
|
|
||
| res.json({ | ||
| orders, | ||
| count: metadata.count, | ||
| offset: metadata.skip, | ||
| limit: metadata.take, | ||
| }) | ||
| } |
25 changes: 25 additions & 0 deletions
25
apps/medusa-symmy-plugin/src/api/api/symmy/v1/admin/products/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http" | ||
| import { refetchEntities } from "@medusajs/framework/http" | ||
| import { | ||
| remapKeysForProduct, | ||
| remapProductResponse, | ||
| } from "@medusajs/medusa/api/admin/products/helpers" | ||
|
|
||
| export const GET = async (req: MedusaRequest, res: MedusaResponse) => { | ||
| const selectFields = remapKeysForProduct(req.queryConfig.fields ?? []) | ||
| const { data: products, metadata } = await refetchEntities({ | ||
| entity: "product", | ||
| idOrFilter: req.filterableFields, | ||
| scope: req.scope, | ||
| fields: selectFields, | ||
| pagination: req.queryConfig.pagination, | ||
| withDeleted: req.queryConfig.withDeleted, | ||
| }) | ||
|
|
||
| res.json({ | ||
| products: products.map(remapProductResponse), | ||
| count: metadata.count, | ||
| offset: metadata.skip, | ||
| limit: metadata.take, | ||
| }) | ||
| } |
26 changes: 26 additions & 0 deletions
26
apps/medusa-symmy-plugin/src/api/api/symmy/v1/admin/regions/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http" | ||
| import { | ||
| ContainerRegistrationKeys, | ||
| remoteQueryObjectFromString, | ||
| } from "@medusajs/framework/utils" | ||
|
|
||
| export const GET = async (req: MedusaRequest, res: MedusaResponse) => { | ||
| const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) | ||
| const query = remoteQueryObjectFromString({ | ||
| entryPoint: "region", | ||
| variables: { | ||
| filters: req.filterableFields, | ||
| ...req.queryConfig.pagination, | ||
| }, | ||
| fields: req.queryConfig.fields, | ||
| }) | ||
|
|
||
| const { rows: regions, metadata } = await remoteQuery(query) | ||
|
|
||
| res.json({ | ||
| regions, | ||
| count: metadata.count, | ||
| offset: metadata.skip, | ||
| limit: metadata.take, | ||
| }) | ||
| } |
38 changes: 38 additions & 0 deletions
38
apps/medusa-symmy-plugin/src/api/api/symmy/v1/admin/users/me/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import type { | ||
| AuthenticatedMedusaRequest, | ||
| MedusaResponse, | ||
| } from "@medusajs/framework/http" | ||
| import { | ||
| ContainerRegistrationKeys, | ||
| MedusaError, | ||
| remoteQueryObjectFromString, | ||
| } from "@medusajs/framework/utils" | ||
|
|
||
| export const GET = async ( | ||
| req: AuthenticatedMedusaRequest, | ||
| res: MedusaResponse | ||
| ) => { | ||
| const id = req.auth_context.actor_id | ||
| const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) | ||
|
|
||
| if (!id) { | ||
| throw new MedusaError(MedusaError.Types.UNAUTHORIZED, "User ID not found") | ||
| } | ||
|
|
||
| const query = remoteQueryObjectFromString({ | ||
| entryPoint: "user", | ||
| variables: { id }, | ||
| fields: req.queryConfig.fields, | ||
| }) | ||
|
|
||
| const [user] = await remoteQuery(query) | ||
|
|
||
| if (!user) { | ||
| throw new MedusaError( | ||
| MedusaError.Types.NOT_FOUND, | ||
| `User with id: ${id} was not found` | ||
| ) | ||
| } | ||
|
|
||
| res.status(200).json({ user }) | ||
| } |
11 changes: 11 additions & 0 deletions
11
apps/medusa-symmy-plugin/src/api/api/symmy/v1/auth/user/emailpass/middlewares.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import type { MiddlewareRoute } from "@medusajs/framework/http" | ||
| import { validateAndTransformBody } from "@medusajs/framework/http" | ||
| import { PostSymmyAuthUserEmailPassSchema } from "./validators" | ||
|
|
||
| export const symmyAuthUserEmailPassRoutes: MiddlewareRoute[] = [ | ||
| { | ||
| methods: ["POST"], | ||
| matcher: "/api/symmy/v1/auth/user/emailpass", | ||
| middlewares: [validateAndTransformBody(PostSymmyAuthUserEmailPassSchema)], | ||
| }, | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.