| 53 | // FIXME there's probably a better way to get typing to work than |
| 54 | // almost-duplicating the method above |
| 55 | async function getUserOrAdminSessionInput<T extends z.ZodRawShape>( |
| 56 | req: VercelRequest, |
| 57 | schema: InputSchema<T> |
| 58 | ) { |
| 59 | const fullSchema = z.object({ |
| 60 | action: z.object({ name: z.string() }), |
| 61 | input: z.object({ payload: schema }), |
| 62 | session_variables: HasuraUserOrAdminSessionVariables, |
| 63 | request_query: z.string().optional(), |
| 64 | }); |
| 65 | |
| 66 | // this will throw if the input isn't valid |
| 67 | const { action, session_variables, input } = await fullSchema.parseAsync( |
| 68 | req.body |
| 69 | ); |
| 70 | assert(input?.payload, 'input.payload is missing after parsing'); |
| 71 | |
| 72 | return { action, session: session_variables, payload: input.payload }; |
| 73 | } |
| 74 | |
| 75 | async function getUserSessionNoInput(req: VercelRequest) { |
| 76 | const fullSchema = z.object({ |