UNPKG

zephyr-agent

Version:
37 lines (36 loc) • 1.35 kB
import "node:module"; import { getApplicationConfiguration } from "../edge-requests/get-application-configuration.mjs"; import { ZeErrors, ZephyrError } from "../errors/index.mjs"; import { ze_log } from "../logging/index.mjs"; import { makeRequest } from "./http-request.mjs"; async function uploadEnvs({ body, application_uid, logEvent }) { ze_log.upload(`Uploading envs to Zephyr, for ${application_uid}`); const { EDGE_URL, jwt } = await getApplicationConfiguration({ application_uid }); const json = JSON.stringify(body); const options = { method: 'POST', headers: { 'Content-Length': Buffer.byteLength(json).toString(), 'Content-Type': 'application/json; charset=utf-8', can_write_jwt: jwt } }; const url = new URL('/upload', EDGE_URL); url.searchParams.append('type', 'envs'); const [ok, cause, data] = await makeRequest(url, options, JSON.stringify(body)); if (!ok || !data) { logEvent({ level: 'error', action: 'deploy:edge:failed', message: 'failed deploying local build to edge' }); throw new ZephyrError(ZeErrors.ERR_FAILED_UPLOAD, { type: 'envs', cause: cause }); } } export { uploadEnvs }; //# sourceMappingURL=upload-envs.mjs.map