POST /v1/events the way a client does, then wait for the off-response-path write.
(machineId: string, events: Row[])
| 118 | |
| 119 | /** POST /v1/events the way a client does, then wait for the off-response-path write. */ |
| 120 | async function post(machineId: string, events: Row[]): Promise<number> { |
| 121 | const body = JSON.stringify({ |
| 122 | machine_id: machineId, |
| 123 | codegraph_version: '1.6.2', |
| 124 | os: 'linux', |
| 125 | arch: 'x64', |
| 126 | node_major: 22, |
| 127 | ci: false, |
| 128 | schema_version: 2, |
| 129 | events, |
| 130 | }); |
| 131 | const pending: Promise<unknown>[] = []; |
| 132 | const request = new Request('https://telemetry.test/v1/events', { |
| 133 | method: 'POST', |
| 134 | headers: { 'content-type': 'application/json', 'content-length': String(Buffer.byteLength(body)) }, |
| 135 | body, |
| 136 | }); |
| 137 | const ctx = { waitUntil: (p: Promise<unknown>) => void pending.push(p), passThroughOnException: () => {} }; |
| 138 | const response = await worker.fetch(request as never, env, ctx as never); |
| 139 | await Promise.all(pending); |
| 140 | return response.status; |
| 141 | } |
| 142 | |
| 143 | /** GET one dashboard endpoint, as the signed-in page does. */ |
| 144 | async function api(pathAndQuery: string): Promise<Row> { |
no test coverage detected