UNPKG

@questlabs/core

Version:
199 lines (198 loc) 10.7 kB
"use strict"; var __awaiter = (this && this.__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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EntityDataContract = void 0; const constants_1 = require("../../utils/constants"); const helperFunctions_1 = require("../../utils/helperFunctions"); class EntityDataContract { constructor(questSdk) { this.questSdk = questSdk; } addNewDataContractForEntity() { return __awaiter(this, arguments, void 0, function* ({ entityId, fields, source, name, tags, description } = {}, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, fields, name, token }); const url = `/entities/${defaultEntityId}/dataContracts`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign({ fields, name, tags, description, source }, options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams, body, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getDataContractByIdForAnEntity() { return __awaiter(this, arguments, void 0, function* ({ entityId, dataContractId } = {}, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, dataContractId, userId, token }); const url = `/entities/${defaultEntityId}/dataContracts/${dataContractId}`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.GET, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } getAllDataContractsForAnEntity(_a, options_1) { return __awaiter(this, arguments, void 0, function* ({ entityId }, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, userId, token }); const url = `/entities/${defaultEntityId}/dataContracts/`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.GET, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } updateDataContractForEntity() { return __awaiter(this, arguments, void 0, function* ({ entityId, fields, source, name, tags, description } = {}, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, fields, name, userId, token }); const url = `/entities/${defaultEntityId}/dataContracts/update`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign({ fields, name, tags, description, source }, options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams, body, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } deleteDataContractForEntity() { return __awaiter(this, arguments, void 0, function* ({ entityId, dataContractId } = {}, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, dataContractId, userId, token }); const url = `/entities/${defaultEntityId}/dataContracts/${dataContractId}/delete`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } chatWithDataContractForEntity() { return __awaiter(this, arguments, void 0, function* ({ entityId, dataContractId, userInput, isInternal } = {}, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, dataContractId, userInput, userId, token }); const url = `/entities/${defaultEntityId}/dataContracts/${dataContractId}/chat`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign({ userInput, isInternal }, options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams, body, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } fetchFieldsFromGoogleSheets() { return __awaiter(this, arguments, void 0, function* ({ entityId, googleSheetLink } = {}, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, googleSheetLink, userId, token }); const url = `/entities/${defaultEntityId}/googlesheet`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign({ googleSheetLink }, options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams, body, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } autoGenerateDescription() { return __awaiter(this, arguments, void 0, function* ({ fields, dataContractId, entityId } = {}, options) { try { const { userId, token } = this.questSdk.getUser(); const defaultEntityId = entityId || this.questSdk.getEntityId(); (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, fields, dataContractId, userId, token }); const url = `/entities/${defaultEntityId}/dataContracts/${dataContractId}/autoGenerate`; const queryParams = Object.assign({ userId }, options === null || options === void 0 ? void 0 : options._queryParams); const body = Object.assign({ fields }, options === null || options === void 0 ? void 0 : options._body); return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, headers: options === null || options === void 0 ? void 0 : options._headers, queryParams, body, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } } exports.EntityDataContract = EntityDataContract;