| 133 | } |
| 134 | |
| 135 | function parseRequestArgs(req: Request, requiredKeys: string[]): Record<string, any> { |
| 136 | if (!util.isPlainObject(req.body)) { |
| 137 | throw new StorageArgumentError(`The request body must be a valid JSON object`); |
| 138 | } |
| 139 | for (const key of requiredKeys) { |
| 140 | if (!Object.hasOwn(req.body, key)) { |
| 141 | throw new StorageArgumentError( |
| 142 | `The required argument '${key}' is missing (expected ${JSON.stringify(requiredKeys)})`, |
| 143 | ); |
| 144 | } |
| 145 | } |
| 146 | return req.body; |
| 147 | } |
| 148 | |
| 149 | async function prepareWebSockets( |
| 150 | httpServer: AppiumServer, |