| 30 | }; |
| 31 | |
| 32 | export const getVariableMetadata = async ( |
| 33 | id: string, |
| 34 | req: Request, |
| 35 | env: Env, |
| 36 | ) => { |
| 37 | const apiPathname = `/v1/variable/${id}`; |
| 38 | const url = new URL(req.url); |
| 39 | url.pathname = apiPathname; |
| 40 | |
| 41 | // Update incoming request to use new pathname |
| 42 | const newRequest = new Request(url.toString(), { |
| 43 | ...req.clone(), |
| 44 | method: 'GET', |
| 45 | }); |
| 46 | const metadata = await env.METADATA.fetch(newRequest); |
| 47 | if (!metadata.ok) { |
| 48 | const error = await metadata.json<StatusErrorObject>(); |
| 49 | throw new StatusError( |
| 50 | metadata.status, |
| 51 | `Bad response from metadata worker. ${error.error}`, |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | return await metadata.json<VariableMetadata>(); |
| 56 | }; |
| 57 | |
| 58 | export const findVersion = ( |
| 59 | id: string, |