UNPKG

@hotglue/cli

Version:
326 lines (293 loc) 6.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resetAvailableEntities = exports.patchLinkedSourceConfig = exports.patchLinkedConnectorConfig = exports.getTenants = exports.getSupportedSources = exports.getSupportedFlows = exports.getSupportedFlow = exports.getSupportedConnectors = exports.getLinkedSources = exports.getLinkedConnectors = exports.genCredentialsOnClientApi = exports.deleteTenantSchedules = void 0; var _axios = _interopRequireDefault(require("axios/dist/node/axios.cjs")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const resetAvailableEntities = async ({ debug, baseUri, env, apiKey }) => { const urlObj = new URL(`${baseUri}/${env}/resetAvailableEntities`); const { data } = await _axios.default.delete(urlObj, { headers: { 'x-api-key': apiKey, 'Content-type': 'application/json' } }); debug({ data }); }; exports.resetAvailableEntities = resetAvailableEntities; const genCredentialsOnClientApi = async ({ debug, baseUri, task, env, apikey, ...params }) => { const urlObj = new URL(`${baseUri}/credentials/${task}/${env}`); if (params) { Object.entries(params).forEach(([key, value]) => { urlObj.searchParams.set(key, value); }); } const uri = urlObj.toString(); debug && debug('uri:', uri); const { data } = await _axios.default.get(uri, { headers: { 'x-api-key': apikey } }); const { accessKeyId, secretAccessKey, sessionToken } = data; return { accessKeyId, secretAccessKey, sessionToken }; }; exports.genCredentialsOnClientApi = genCredentialsOnClientApi; const getTenants = async ({ debug, baseUri, env, apikey }) => { const uri = `${baseUri}/tenants/${env}`; debug('requesting:', uri); const { data } = await _axios.default.get(uri, { headers: { 'x-api-key': apikey } }); debug('response-data', data); return data; }; exports.getTenants = getTenants; const getSupportedSources = async ({ debug, baseUri, env, flow, apikey }) => { const urlObj = new URL(`${baseUri}/${env}/${flow}/supportedSources`); const headers = { 'x-api-key': apikey }; const uri = urlObj.toString(); debug && debug('uri:', uri); const { data } = await _axios.default.get(uri, { headers }); return data; }; exports.getSupportedSources = getSupportedSources; const getSupportedConnectors = async ({ debug, baseUri, env, flow, apikey }) => { const urlObj = new URL(`${baseUri}/v2/${env}/${flow}/supportedConnectors`); const headers = { 'x-api-key': apikey }; const uri = urlObj.toString(); debug && debug('uri:', uri); const { data } = await _axios.default.get(uri, { headers }); return data; }; exports.getSupportedConnectors = getSupportedConnectors; const getLinkedSources = async ({ debug, baseUri, env, flow, tenant, apikey, config }) => { const urlObj = new URL(`${baseUri}/${env}/${flow}/${tenant}/linkedSources`); if (config) { urlObj.searchParams.set('config', 'true'); } const headers = { 'x-api-key': apikey }; const uri = urlObj.toString(); debug && debug('uri:', uri); const { data } = await _axios.default.get(uri, { headers }); return data; }; exports.getLinkedSources = getLinkedSources; const getLinkedConnectors = async ({ debug, baseUri, env, flow, tenant, apikey, config }) => { const urlObj = new URL(`${baseUri}/v2/${env}/${flow}/${tenant}/linkedConnectors`); if (config) { urlObj.searchParams.set('config', 'true'); } const headers = { 'x-api-key': apikey }; const uri = urlObj.toString(); debug && debug('uri:', uri); const { data } = await _axios.default.get(uri, { headers }); return data; }; exports.getLinkedConnectors = getLinkedConnectors; const patchLinkedSourceConfig = async ({ debug, baseUri, env, flow, tenant, apikey, connectorId, config }) => { const urlObj = new URL(`${baseUri}/${env}/${flow}/${tenant}/linkedSources`); const headers = { 'x-api-key': apikey }; const uri = urlObj.toString(); const body = { tap: connectorId, config }; debug && debug('uri:', uri); const { data } = await _axios.default.patch(uri, body, { headers }); return data; }; exports.patchLinkedSourceConfig = patchLinkedSourceConfig; const patchLinkedConnectorConfig = async ({ debug, baseUri, env, flow, tenant, apikey, connectorId, config }) => { const urlObj = new URL(`${baseUri}/v2/${env}/${flow}/${tenant}/linkedConnectors`); const headers = { 'x-api-key': apikey }; const uri = urlObj.toString(); const body = { connector_id: connectorId, config }; debug && debug('uri:', uri); const { data } = await _axios.default.patch(uri, body, { headers }); return data; }; exports.patchLinkedConnectorConfig = patchLinkedConnectorConfig; const getSupportedFlows = async ({ debug, baseUri, env, apikey }) => { const urlObj = new URL(`${baseUri}/${env}/flows/supported`); const headers = { 'x-api-key': apikey }; const uri = urlObj.toString(); debug && debug('uri:', uri); const { data } = await _axios.default.get(uri, { headers }); return data; }; exports.getSupportedFlows = getSupportedFlows; const getSupportedFlow = async ({ debug, baseUri, env, flow, apikey }) => { const urlObj = new URL(`${baseUri}/${env}/flows/${flow}/supported`); const headers = { 'x-api-key': apikey }; const uri = urlObj.toString(); debug && debug('uri:', uri); const { data } = await _axios.default.get(uri, { headers }); return data; }; exports.getSupportedFlow = getSupportedFlow; const deleteTenantSchedules = async ({ debug, baseUri, env, apikey, tenant }) => { const urlObj = new URL(`${baseUri}/tenant/${env}/${tenant}?schedules_only=true`); const headers = { 'x-api-key': apikey }; const uri = urlObj.toString(); debug && debug('uri:', uri); const { data } = await _axios.default.delete(uri, { headers }); return data; }; exports.deleteTenantSchedules = deleteTenantSchedules;