@questlabs/core
Version:
This is the quest SDK
199 lines (198 loc) • 10.7 kB
JavaScript
"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({ entityId, fields, source, name, tags, description } = {}, options) {
return __awaiter(this, void 0, void 0, function* () {
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({ entityId, dataContractId } = {}, options) {
return __awaiter(this, void 0, void 0, function* () {
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({ entityId }, options) {
return __awaiter(this, void 0, void 0, function* () {
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({ entityId, fields, source, name, tags, description } = {}, options) {
return __awaiter(this, void 0, void 0, function* () {
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({ entityId, dataContractId } = {}, options) {
return __awaiter(this, void 0, void 0, function* () {
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({ entityId, dataContractId, userInput, isInternal } = {}, options) {
return __awaiter(this, void 0, void 0, function* () {
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({ entityId, googleSheetLink } = {}, options) {
return __awaiter(this, void 0, void 0, function* () {
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({ fields, dataContractId, entityId } = {}, options) {
return __awaiter(this, void 0, void 0, function* () {
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;