POST /v1/events the way a client does, then wait for the off-response-path write.
(machineId: string, events: Row[], envelope: Row = {})
| 140 | |
| 141 | /** POST /v1/events the way a client does, then wait for the off-response-path write. */ |
| 142 | async function post(machineId: string, events: Row[], envelope: Row = {}): Promise<number> { |
| 143 | const body = JSON.stringify({ |
| 144 | machine_id: machineId, |
| 145 | codegraph_version: '1.6.2', |
| 146 | os: 'linux', |
| 147 | arch: 'x64', |
| 148 | node_major: 22, |
| 149 | ci: false, |
| 150 | schema_version: 2, |
| 151 | ...envelope, |
| 152 | events, |
| 153 | }); |
| 154 | const pending: Promise<unknown>[] = []; |
| 155 | const request = new Request('https://telemetry.test/v1/events', { |
| 156 | method: 'POST', |
| 157 | headers: { 'content-type': 'application/json', 'content-length': String(Buffer.byteLength(body)) }, |
| 158 | body, |
| 159 | }); |
| 160 | const ctx = { waitUntil: (p: Promise<unknown>) => void pending.push(p), passThroughOnException: () => {} }; |
| 161 | const response = await worker.fetch(request as never, env, ctx as never); |
| 162 | await Promise.all(pending); |
| 163 | return response.status; |
| 164 | } |
| 165 | |
| 166 | /** GET one dashboard endpoint, as the signed-in page does. */ |
| 167 | async function api(pathAndQuery: string): Promise<Row> { |
no test coverage detected