UNPKG

@gentrace/core

Version:
107 lines (103 loc) 4.46 kB
'use strict'; var configuration = require('../configuration.js'); var v1Api = require('../api/v1-api.js'); var v2Api = require('../api/v2-api.js'); var v3Api = require('../api/v3-api.js'); var utils = require('./utils.js'); var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; exports.GENTRACE_API_KEY = ""; function getGentraceApiKey() { return exports.GENTRACE_API_KEY; } exports.GENTRACE_BASE_PATH = ""; function getGentraceBasePath() { return exports.GENTRACE_BASE_PATH; } exports.GENTRACE_BRANCH = ""; exports.GENTRACE_COMMIT = ""; exports.GENTRACE_SHOW_CONNECTION_ERRORS = ""; // @deprecated: use GENTRACE_RESULT_NAME instead exports.GENTRACE_RUN_NAME = ""; exports.GENTRACE_RESULT_NAME = ""; exports.GENTRACE_ENVIRONMENT_NAME = ""; exports.globalGentraceConfig = null; exports.globalGentraceApi = null; exports.globalGentraceApiV2 = null; exports.globalGentraceApiV3 = null; exports.globalRequestBuffer = {}; let resetGlobalGentraceApi = () => { exports.globalGentraceConfig = null; }; function init(values) { const { apiKey, basePath, branch, commit, showConnectionErrors, runName, resultName, environmentName, } = values !== null && values !== void 0 ? values : {}; if (!apiKey && !utils.getProcessEnv("GENTRACE_API_KEY")) { throw new Error("Gentrace API key was provided neither by the `apiKey` param in the constructor nor by the `GENTRACE_API_KEY` env variable."); } exports.GENTRACE_API_KEY = apiKey || utils.getProcessEnv("GENTRACE_API_KEY"); exports.GENTRACE_RUN_NAME = runName || utils.getProcessEnv("GENTRACE_RUN_NAME"); exports.GENTRACE_RESULT_NAME = resultName || utils.getProcessEnv("GENTRACE_RESULT_NAME"); exports.GENTRACE_ENVIRONMENT_NAME = environmentName || utils.getProcessEnv("GENTRACE_ENVIRONMENT_NAME"); exports.GENTRACE_SHOW_CONNECTION_ERRORS = showConnectionErrors || utils.getProcessEnv("GENTRACE_SHOW_CONNECTION_ERRORS"); utils.setErrorInterceptor(); if (basePath) { try { const url = new URL(basePath); if (url.pathname.startsWith("/api")) { } else { throw new Error('Gentrace base path must end in "/api".'); } } catch (err) { throw new Error(`Invalid Gentrace base path (${basePath}): ${err.message}`); } exports.GENTRACE_BASE_PATH = basePath; } exports.globalGentraceConfig = new configuration.Configuration({ apiKey: exports.GENTRACE_API_KEY, basePath: exports.GENTRACE_BASE_PATH, }); exports.globalGentraceApi = new v1Api.V1Api(exports.globalGentraceConfig); exports.globalGentraceApiV2 = new v2Api.V2Api(exports.globalGentraceConfig); exports.globalGentraceApiV3 = new v3Api.V3Api(exports.globalGentraceConfig); if (branch) { exports.GENTRACE_BRANCH = branch; } if (commit) { exports.GENTRACE_COMMIT = commit; } } function deinit() { exports.GENTRACE_API_KEY = ""; exports.GENTRACE_BASE_PATH = ""; exports.GENTRACE_BRANCH = ""; exports.GENTRACE_COMMIT = ""; exports.GENTRACE_SHOW_CONNECTION_ERRORS = ""; exports.globalGentraceConfig = null; exports.globalGentraceApi = null; exports.globalGentraceApiV2 = null; exports.globalGentraceApiV3 = null; exports.globalRequestBuffer = {}; } function flush() { return __awaiter(this, void 0, void 0, function* () { return (yield Promise.allSettled(Object.values(exports.globalRequestBuffer))).every((result) => result.status === "fulfilled"); }); } exports.deinit = deinit; exports.flush = flush; exports.getGentraceApiKey = getGentraceApiKey; exports.getGentraceBasePath = getGentraceBasePath; exports.init = init; exports.resetGlobalGentraceApi = resetGlobalGentraceApi; //# sourceMappingURL=init.js.map