zephyr-agent
Version:
Zephyr plugin agent
35 lines (34 loc) • 1.41 kB
JavaScript
import "node:module";
import { ZE_API_ENDPOINT, ze_api_gateway } from "zephyr-edge-contract";
import { createHash } from "node:crypto";
import { ZeErrors, ZephyrError } from "../errors/index.mjs";
import { makeRequest } from "../http/http-request.mjs";
import { ze_log } from "../logging/index.mjs";
import { getToken } from "../node-persist/token.mjs";
async function zeUploadBuildStats(dashData) {
ze_log.upload('Uploading build stats to Zephyr...', dashData);
const token = await getToken();
const url = new URL(ze_api_gateway.build_stats, ZE_API_ENDPOINT());
const idempotencyKey = createHash('sha256').update(`${dashData.id}\0${dashData.app.buildId}`).digest('hex');
const [ok, cause, res] = await makeRequest(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
Accept: 'application/json',
'Idempotency-Key': idempotencyKey
},
credentialToken: token
}, JSON.stringify(dashData));
if (!ok || 'ok' !== res.status) throw new ZephyrError(ZeErrors.ERR_FAILED_UPLOAD, {
type: 'build stats',
cause,
data: {
url: url.toString()
}
});
ze_log.upload('Build stats uploaded to Zephyr...');
return res.targets ?? [];
}
export { zeUploadBuildStats };
//# sourceMappingURL=ze-upload-build-stats.mjs.map