Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions ee/packages/federation-matrix/src/api/_matrix/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,56 @@ const ErrorResponseSchema = {

const isErrorResponseProps = ajv.compile(ErrorResponseSchema);

const GetStateIdsParamsSchema = {
type: 'object',
properties: {
event_id: {
type: 'string',
},
},
required: ['event_id'],
};

const isGetStateIdsParamsProps = ajv.compile(GetStateIdsParamsSchema);

const GetStateIdsResponseSchema = {
type: 'object',
properties: {
stateIds: {
type: 'array',
items: {
type: 'string',
},
},
},
};

const isGetStateIdsResponseProps = ajv.compile(GetStateIdsResponseSchema);
const GetStateParamsSchema = {
type: 'object',
properties: {
event_id: {
type: 'string',
},
},
};
const isGetStateParamsProps = ajv.compile<{
event_id: string
}>(GetStateParamsSchema);

const GetStateResponseSchema = {
type: 'object',
properties: {
state: {
type: 'object',
},
},
};

const isGetStateResponseProps = ajv.compile(GetStateResponseSchema);



export const getMatrixTransactionsRoutes = (services: HomeserverServices) => {
const { event, config } = services;

Expand Down Expand Up @@ -253,6 +303,67 @@ export const getMatrixTransactionsRoutes = (services: HomeserverServices) => {
},
)

// GET /_matrix/federation/v1/state_ids/{roomId}

.get(
'/v1/state_ids/:roomId',
{
params: isGetStateIdsParamsProps,
response: {
200: isGetStateIdsResponseProps,
},
},
async (c) => {
Comment on lines +310 to +316
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Use query validators (not params) for event_id

event_id is a query param; current code places its validator under params so it never runs. Move to options.query.

Apply:

-				{
-					params: isGetStateIdsParamsProps,
+				{
+					query: isGetStateIdsParamsProps,
 					response: {
 					},
 				},

And for state:

-				{
-					params: isGetStateParamsProps,
+				{
+					query: isGetStateParamsProps,
 					response: {
 					},
 				},

Also applies to: 387-394

🤖 Prompt for AI Agents
In ee/packages/federation-matrix/src/api/_matrix/transactions.ts around lines
368-374 (and similarly around 387-394), the schema validators for event_id (and
the state validator) are incorrectly placed under params so they are never
applied to query parameters; move those validators into the options.query object
for the route definitions (replace params: isGetStateIdsParamsProps with query:
isGetStateIdsParamsProps or add query: { event_id: ... } as appropriate) and
remove or adjust the params entry so only path/URL params remain validated under
params.


const roomId = c.req.param('roomId');
const eventId = c.req.query('event_id');

if(!eventId) {
return {
body: {
errcode: 'M_NOT_FOUND',
error: 'Event not found',
},
statusCode: 404,
}
}

const stateIds = await event.getStateIds(roomId, eventId);

return {
body: stateIds,
statusCode: 200,
};
Comment on lines +333 to +336
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Response body shape mismatch with declared schemas

  • state_ids route should return { stateIds }
  • state route should return { state }

Apply:

-					return {
-						body: stateIds,
-						statusCode: 200,
-					};
+					return {
+						body: { stateIds },
+						statusCode: 200,
+					};
-					return {
-						statusCode: 200,
-						body: state,
-					};
+					return {
+						statusCode: 200,
+						body: { state },
+					};

Also applies to: 399-401

🤖 Prompt for AI Agents
In ee/packages/federation-matrix/src/api/_matrix/transactions.ts around lines
380-383 (and similarly lines 399-401), the handlers are returning the raw
variables (e.g. body: stateIds) which does not match the declared response
schema; wrap the values in objects with the expected property names — return {
body: { stateIds } , statusCode: 200 } for the state_ids route and return {
body: { state } , statusCode: 200 } for the state route — ensure the response
keys exactly match the schemas.

},
)
.get(
'/v1/state/:roomId',
{
params: isGetStateParamsProps,
response: {
200: isGetStateResponseProps,
},
},
async (c) => {
const roomId = c.req.param('roomId');
const eventId = c.req.query('event_id');

if(!eventId) {
return {
body: {
errcode: 'M_NOT_FOUND',
error: 'Event not found',
},
statusCode: 404,
}
}
const state = await event.getState(roomId, eventId);
return {
statusCode: 200,
body: state,
};
},
)
// GET /_matrix/federation/v1/event/{eventId}
.get(
'/v1/event/:eventId',
Expand Down
Loading