Skip to content

Commit

Permalink
feat: deprecate remoteQueryConfig in favor of queryConfig (#10773)
Browse files Browse the repository at this point in the history
Fixes: FRMW-2783
  • Loading branch information
thetutlage authored Jan 3, 2025
1 parent 54e1e70 commit 5e9d86d
Show file tree
Hide file tree
Showing 200 changed files with 375 additions and 399 deletions.
7 changes: 7 additions & 0 deletions .changeset/nice-teachers-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@medusajs/medusa": patch
"@medusajs/framework": patch
"@medusajs/types": patch
---

feat: deprecate remoteQueryConfig in favor of queryConfig
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe("validateAndTransformQuery", () => {
],
order: transformedOrder,
})
expect(mockRequest.remoteQueryConfig).toEqual({
expect(mockRequest.queryConfig).toEqual({
fields: [
"id",
"created_at",
Expand Down Expand Up @@ -387,7 +387,7 @@ describe("validateAndTransformQuery", () => {
],
})
)
expect(mockRequest.remoteQueryConfig).toEqual(
expect(mockRequest.queryConfig).toEqual(
expect.objectContaining({
fields: [
"id",
Expand Down Expand Up @@ -447,7 +447,7 @@ describe("validateAndTransformQuery", () => {
relations: ["store"],
})
)
expect(mockRequest.remoteQueryConfig).toEqual(
expect(mockRequest.queryConfig).toEqual(
expect.objectContaining({
fields: ["store.name", "id"],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ export function applyDefaultFilters<TFilter extends object>(
// Currently we only need it to delete filter keys from the request filter object, but this could
// be used for other purposes. If we can't find other purposes, we can refactor to accept an array
// of strings to delete after filters have been applied.
valueToApply = filterValue(
req.filterableFields,
req.remoteQueryConfig.fields
)
valueToApply = filterValue(req.filterableFields, req.queryConfig.fields)
}

// If the value to apply is an object, we add it to any existing filters thats already applied
Expand Down
21 changes: 16 additions & 5 deletions packages/core/framework/src/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,20 @@ export interface MedusaRequest<
* An object containing the select, relation to be used with medusa internal services
*/
retrieveConfig: FindConfig<unknown>

/**
* An object containing fields and variables to be used with the remoteQuery
*/
remoteQueryConfig: {
queryConfig: {
fields: string[]
pagination: { order?: Record<string, string>; skip: number; take?: number }
}

/**
* @deprecated. Instead use "req.queryConfig"
*/
remoteQueryConfig: MedusaRequest["queryConfig"]

/**
* An object containing the fields that are filterable e.g `{ id: Any<String> }`
*/
Expand Down Expand Up @@ -163,14 +170,18 @@ export interface PublishableKeyContext {
sales_channel_ids: string[]
}

export interface AuthenticatedMedusaRequest<Body = unknown, QueryFields = Record<string, unknown>>
extends MedusaRequest<Body, QueryFields> {
export interface AuthenticatedMedusaRequest<
Body = unknown,
QueryFields = Record<string, unknown>
> extends MedusaRequest<Body, QueryFields> {
auth_context: AuthContext
publishable_key_context?: PublishableKeyContext
}

export interface MedusaStoreRequest<Body = unknown, QueryFields = Record<string, unknown>>
extends MedusaRequest<Body, QueryFields> {
export interface MedusaStoreRequest<
Body = unknown,
QueryFields = Record<string, unknown>
> extends MedusaRequest<Body, QueryFields> {
auth_context?: AuthContext
publishable_key_context: PublishableKeyContext
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/framework/src/http/utils/refetch-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const refetchEntities = async (
idOrFilter: string | object,
scope: MedusaContainer,
fields: string[],
pagination?: MedusaRequest["remoteQueryConfig"]["pagination"]
pagination?: MedusaRequest["queryConfig"]["pagination"]
) => {
const remoteQuery = scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
const filters = isString(idOrFilter) ? { id: idOrFilter } : idOrFilter
Expand Down
3 changes: 2 additions & 1 deletion packages/core/framework/src/http/utils/validate-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ export function validateAndTransformQuery<TEntity extends BaseEntity>(

req.validatedQuery = validated
req.filterableFields = getFilterableFields(req.validatedQuery)
req.remoteQueryConfig = cnf.remoteQueryConfig as any
req.queryConfig = cnf.remoteQueryConfig as any
req.remoteQueryConfig = req.queryConfig
req.listConfig = (cnf as any).listConfig
req.retrieveConfig = (cnf as any).retrieveConfig

Expand Down
2 changes: 1 addition & 1 deletion packages/core/types/src/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export type QueryConfig<TEntity> = {
defaultLimit?: number
/**
* If the route that will use that configuration is supposed to return a list of entities. This
* will change the configuration that will be created on req.listConfig and req.remoteQueryConfig (among
* will change the configuration that will be created on req.listConfig and req.queryConfig (among
* other things it will include pagination and sorting)
*/
isList?: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const POST = async (
const apiKey = await refetchApiKey(
req.params.id,
req.scope,
req.remoteQueryConfig.fields
req.queryConfig.fields
)

res.status(200).json({ api_key: apiKey })
Expand Down
4 changes: 2 additions & 2 deletions packages/medusa/src/api/admin/api-keys/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const GET = async (
const apiKey = await refetchApiKey(
req.params.id,
req.scope,
req.remoteQueryConfig.fields
req.queryConfig.fields
)

if (!apiKey) {
Expand All @@ -46,7 +46,7 @@ export const POST = async (
const apiKey = await refetchApiKey(
req.params.id,
req.scope,
req.remoteQueryConfig.fields
req.queryConfig.fields
)

res.status(200).json({ api_key: apiKey })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const POST = async (
const updatedApiKey = await refetchApiKey(
req.params.id,
req.scope,
req.remoteQueryConfig.fields
req.queryConfig.fields
)

res.status(200).json({ api_key: updatedApiKey })
Expand Down
4 changes: 2 additions & 2 deletions packages/medusa/src/api/admin/api-keys/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export const GET = async (
entryPoint: "api_key",
variables: {
filters: req.filterableFields,
...req.remoteQueryConfig.pagination,
...req.queryConfig.pagination,
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})

const { rows: apiKeys, metadata } = await remoteQuery(queryObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const POST = async (
const campaign = await refetchCampaign(
req.params.id,
req.scope,
req.remoteQueryConfig.fields
req.queryConfig.fields
)

res.status(200).json({ campaign })
Expand Down
4 changes: 2 additions & 2 deletions packages/medusa/src/api/admin/campaigns/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const GET = async (
const campaign = await refetchCampaign(
req.params.id,
req.scope,
req.remoteQueryConfig.fields
req.queryConfig.fields
)

if (!campaign) {
Expand Down Expand Up @@ -62,7 +62,7 @@ export const POST = async (
const campaign = await refetchCampaign(
req.params.id,
req.scope,
req.remoteQueryConfig.fields
req.queryConfig.fields
)
res.status(200).json({ campaign })
}
Expand Down
6 changes: 3 additions & 3 deletions packages/medusa/src/api/admin/campaigns/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const GET = async (
entryPoint: "campaign",
variables: {
filters: req.filterableFields,
...req.remoteQueryConfig.pagination,
...req.queryConfig.pagination,
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})

const { rows: campaigns, metadata } = await remoteQuery(query)
Expand Down Expand Up @@ -54,7 +54,7 @@ export const POST = async (
const campaign = await refetchCampaign(
result[0].id,
req.scope,
req.remoteQueryConfig.fields
req.queryConfig.fields
)

res.status(200).json({ campaign })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const POST = async (
...req.filterableFields,
},
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})

const [orderClaim] = await remoteQuery(queryObject)
Expand Down Expand Up @@ -73,7 +73,7 @@ export const DELETE = async (
...req.filterableFields,
},
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})
const [orderClaim] = await remoteQuery(queryObject)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const POST = async (
...req.filterableFields,
},
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})

const [orderClaim] = await remoteQuery(queryObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const POST = async (
...req.filterableFields,
},
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})

const [orderClaim] = await remoteQuery(queryObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const POST = async (
...req.filterableFields,
},
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})

const [orderClaim] = await remoteQuery(queryObject)
Expand Down Expand Up @@ -72,7 +72,7 @@ export const DELETE = async (
...req.filterableFields,
},
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})
const [orderClaim] = await remoteQuery(queryObject)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const POST = async (
...req.filterableFields,
},
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})

const [orderClaim] = await remoteQuery(queryObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const POST = async (
...req.filterableFields,
},
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})

const [orderClaim] = await remoteQuery(queryObject)
Expand Down Expand Up @@ -73,7 +73,7 @@ export const DELETE = async (
...req.filterableFields,
},
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})
const [orderClaim] = await remoteQuery(queryObject)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const POST = async (
...req.filterableFields,
},
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})

const [orderClaim] = await remoteQuery(queryObject)
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/api/admin/claims/[id]/request/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const POST = async (
...req.filterableFields,
},
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})

const [orderClaim] = await remoteQuery(queryObject, {
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/api/admin/claims/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const GET = async (
"order_claim",
req.params.id,
req.scope,
req.remoteQueryConfig.fields
req.queryConfig.fields
)

if (!claim) {
Expand Down
6 changes: 3 additions & 3 deletions packages/medusa/src/api/admin/claims/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export const GET = async (
filters: {
...req.filterableFields,
},
...req.remoteQueryConfig.pagination,
...req.queryConfig.pagination,
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})

const { rows: claims, metadata } = await remoteQuery(queryObject)
Expand Down Expand Up @@ -64,7 +64,7 @@ export const POST = async (
...req.filterableFields,
},
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})

const [order, orderClaim] = await promiseAll([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const POST = async (
const collection = await refetchCollection(
req.params.id,
req.scope,
req.remoteQueryConfig.fields
req.queryConfig.fields
)

res.status(200).json({
Expand Down
4 changes: 2 additions & 2 deletions packages/medusa/src/api/admin/collections/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const GET = async (
const collection = await refetchCollection(
req.params.id,
req.scope,
req.remoteQueryConfig.fields
req.queryConfig.fields
)

res.status(200).json({ collection })
Expand Down Expand Up @@ -49,7 +49,7 @@ export const POST = async (
const collection = await refetchCollection(
req.params.id,
req.scope,
req.remoteQueryConfig.fields
req.queryConfig.fields
)

res.status(200).json({ collection })
Expand Down
6 changes: 3 additions & 3 deletions packages/medusa/src/api/admin/collections/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export const GET = async (
entryPoint: "product_collection",
variables: {
filters: req.filterableFields,
...req.remoteQueryConfig.pagination,
...req.queryConfig.pagination,
},
fields: req.remoteQueryConfig.fields,
fields: req.queryConfig.fields,
})

const { rows: collections, metadata } = await remoteQuery(query)
Expand Down Expand Up @@ -54,7 +54,7 @@ export const POST = async (
const collection = await refetchCollection(
result[0].id,
req.scope,
req.remoteQueryConfig.fields
req.queryConfig.fields
)

res.status(200).json({ collection })
Expand Down
Loading

0 comments on commit 5e9d86d

Please sign in to comment.