@hubspot/api-client
Version:
NodeJS v3 [HubSpot API](https://developers.hubspot.com/docs/api/overview) SDK(Client) files
312 lines • 20.4 kB
JavaScript
;
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdvancedApiResponseProcessor = exports.AdvancedApiRequestFactory = void 0;
const baseapi_1 = require("./baseapi");
const http_1 = require("../http/http");
const form_data_1 = __importDefault(require("form-data"));
const url_1 = require("url");
const ObjectSerializer_1 = require("../models/ObjectSerializer");
const exception_1 = require("./exception");
const util_1 = require("../util");
class AdvancedApiRequestFactory extends baseapi_1.BaseAPIRequestFactory {
create(environment, path, file, _options) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
let _config = _options || this.configuration;
if (environment === null || environment === undefined) {
throw new baseapi_1.RequiredError("AdvancedApi", "create", "environment");
}
if (path === null || path === undefined) {
throw new baseapi_1.RequiredError("AdvancedApi", "create", "path");
}
const localVarPath = '/cms/v3/source-code/{environment}/content/{path}'
.replace('{' + 'environment' + '}', encodeURIComponent(String(environment)))
.replace('{' + 'path' + '}', encodeURIComponent(String(path)));
const requestContext = _config.baseServer.makeRequestContext(localVarPath, http_1.HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8");
const useForm = (0, util_1.canConsumeForm)([
'multipart/form-data',
]);
let localVarFormParams;
if (useForm) {
localVarFormParams = new form_data_1.default();
}
else {
localVarFormParams = new url_1.URLSearchParams();
}
if (file !== undefined) {
if (localVarFormParams instanceof form_data_1.default) {
localVarFormParams.append('file', file.data, file.name);
}
}
requestContext.setBody(localVarFormParams);
if (!useForm) {
const contentType = ObjectSerializer_1.ObjectSerializer.getPreferredMediaType([
"multipart/form-data"
]);
requestContext.setHeaderParam("Content-Type", contentType);
}
let authMethod;
authMethod = _config.authMethods["oauth2"];
if (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication) {
yield (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication(requestContext));
}
const defaultAuth = (_a = _config === null || _config === void 0 ? void 0 : _config.authMethods) === null || _a === void 0 ? void 0 : _a.default;
if (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication) {
yield (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication(requestContext));
}
return requestContext;
});
}
createOrUpdate(environment, path, file, _options) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
let _config = _options || this.configuration;
if (environment === null || environment === undefined) {
throw new baseapi_1.RequiredError("AdvancedApi", "createOrUpdate", "environment");
}
if (path === null || path === undefined) {
throw new baseapi_1.RequiredError("AdvancedApi", "createOrUpdate", "path");
}
const localVarPath = '/cms/v3/source-code/{environment}/content/{path}'
.replace('{' + 'environment' + '}', encodeURIComponent(String(environment)))
.replace('{' + 'path' + '}', encodeURIComponent(String(path)));
const requestContext = _config.baseServer.makeRequestContext(localVarPath, http_1.HttpMethod.PUT);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8");
const useForm = (0, util_1.canConsumeForm)([
'multipart/form-data',
]);
let localVarFormParams;
if (useForm) {
localVarFormParams = new form_data_1.default();
}
else {
localVarFormParams = new url_1.URLSearchParams();
}
if (file !== undefined) {
if (localVarFormParams instanceof form_data_1.default) {
localVarFormParams.append('file', file.data, file.name);
}
}
requestContext.setBody(localVarFormParams);
if (!useForm) {
const contentType = ObjectSerializer_1.ObjectSerializer.getPreferredMediaType([
"multipart/form-data"
]);
requestContext.setHeaderParam("Content-Type", contentType);
}
let authMethod;
authMethod = _config.authMethods["oauth2"];
if (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication) {
yield (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication(requestContext));
}
const defaultAuth = (_a = _config === null || _config === void 0 ? void 0 : _config.authMethods) === null || _a === void 0 ? void 0 : _a.default;
if (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication) {
yield (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication(requestContext));
}
return requestContext;
});
}
doAsync(fileExtractRequest, _options) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
let _config = _options || this.configuration;
if (fileExtractRequest === null || fileExtractRequest === undefined) {
throw new baseapi_1.RequiredError("AdvancedApi", "doAsync", "fileExtractRequest");
}
const localVarPath = '/cms/v3/source-code/extract/async';
const requestContext = _config.baseServer.makeRequestContext(localVarPath, http_1.HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8");
const contentType = ObjectSerializer_1.ObjectSerializer.getPreferredMediaType([
"application/json"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer_1.ObjectSerializer.stringify(ObjectSerializer_1.ObjectSerializer.serialize(fileExtractRequest, "FileExtractRequest", ""), contentType);
requestContext.setBody(serializedBody);
let authMethod;
authMethod = _config.authMethods["oauth2"];
if (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication) {
yield (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication(requestContext));
}
const defaultAuth = (_a = _config === null || _config === void 0 ? void 0 : _config.authMethods) === null || _a === void 0 ? void 0 : _a.default;
if (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication) {
yield (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication(requestContext));
}
return requestContext;
});
}
doValidate(environment, path, file, _options) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
let _config = _options || this.configuration;
if (environment === null || environment === undefined) {
throw new baseapi_1.RequiredError("AdvancedApi", "doValidate", "environment");
}
if (path === null || path === undefined) {
throw new baseapi_1.RequiredError("AdvancedApi", "doValidate", "path");
}
const localVarPath = '/cms/v3/source-code/{environment}/validate/{path}'
.replace('{' + 'environment' + '}', encodeURIComponent(String(environment)))
.replace('{' + 'path' + '}', encodeURIComponent(String(path)));
const requestContext = _config.baseServer.makeRequestContext(localVarPath, http_1.HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8");
const useForm = (0, util_1.canConsumeForm)([
'multipart/form-data',
]);
let localVarFormParams;
if (useForm) {
localVarFormParams = new form_data_1.default();
}
else {
localVarFormParams = new url_1.URLSearchParams();
}
if (file !== undefined) {
if (localVarFormParams instanceof form_data_1.default) {
localVarFormParams.append('file', file.data, file.name);
}
}
requestContext.setBody(localVarFormParams);
if (!useForm) {
const contentType = ObjectSerializer_1.ObjectSerializer.getPreferredMediaType([
"multipart/form-data"
]);
requestContext.setHeaderParam("Content-Type", contentType);
}
let authMethod;
authMethod = _config.authMethods["oauth2"];
if (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication) {
yield (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication(requestContext));
}
const defaultAuth = (_a = _config === null || _config === void 0 ? void 0 : _config.authMethods) === null || _a === void 0 ? void 0 : _a.default;
if (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication) {
yield (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication(requestContext));
}
return requestContext;
});
}
getAsyncStatus(taskId, _options) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
let _config = _options || this.configuration;
if (taskId === null || taskId === undefined) {
throw new baseapi_1.RequiredError("AdvancedApi", "getAsyncStatus", "taskId");
}
const localVarPath = '/cms/v3/source-code/extract/async/tasks/{taskId}/status'
.replace('{' + 'taskId' + '}', encodeURIComponent(String(taskId)));
const requestContext = _config.baseServer.makeRequestContext(localVarPath, http_1.HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8");
let authMethod;
authMethod = _config.authMethods["oauth2"];
if (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication) {
yield (authMethod === null || authMethod === void 0 ? void 0 : authMethod.applySecurityAuthentication(requestContext));
}
const defaultAuth = (_a = _config === null || _config === void 0 ? void 0 : _config.authMethods) === null || _a === void 0 ? void 0 : _a.default;
if (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication) {
yield (defaultAuth === null || defaultAuth === void 0 ? void 0 : defaultAuth.applySecurityAuthentication(requestContext));
}
return requestContext;
});
}
}
exports.AdvancedApiRequestFactory = AdvancedApiRequestFactory;
class AdvancedApiResponseProcessor {
createWithHttpInfo(response) {
return __awaiter(this, void 0, void 0, function* () {
const contentType = ObjectSerializer_1.ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if ((0, util_1.isCodeInRange)("200", response.httpStatusCode)) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "AssetFileMetadata", "");
return new http_1.HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
if ((0, util_1.isCodeInRange)("0", response.httpStatusCode)) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "Error", "");
throw new exception_1.ApiException(response.httpStatusCode, "An error occurred.", body, response.headers);
}
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "AssetFileMetadata", "");
return new http_1.HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new exception_1.ApiException(response.httpStatusCode, "Unknown API Status Code!", yield response.getBodyAsAny(), response.headers);
});
}
createOrUpdateWithHttpInfo(response) {
return __awaiter(this, void 0, void 0, function* () {
const contentType = ObjectSerializer_1.ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if ((0, util_1.isCodeInRange)("200", response.httpStatusCode)) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "AssetFileMetadata", "");
return new http_1.HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
if ((0, util_1.isCodeInRange)("0", response.httpStatusCode)) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "Error", "");
throw new exception_1.ApiException(response.httpStatusCode, "An error occurred.", body, response.headers);
}
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "AssetFileMetadata", "");
return new http_1.HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new exception_1.ApiException(response.httpStatusCode, "Unknown API Status Code!", yield response.getBodyAsAny(), response.headers);
});
}
doAsyncWithHttpInfo(response) {
return __awaiter(this, void 0, void 0, function* () {
const contentType = ObjectSerializer_1.ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if ((0, util_1.isCodeInRange)("202", response.httpStatusCode)) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "TaskLocator", "");
return new http_1.HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
if ((0, util_1.isCodeInRange)("0", response.httpStatusCode)) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "Error", "");
throw new exception_1.ApiException(response.httpStatusCode, "An error occurred.", body, response.headers);
}
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "TaskLocator", "");
return new http_1.HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new exception_1.ApiException(response.httpStatusCode, "Unknown API Status Code!", yield response.getBodyAsAny(), response.headers);
});
}
doValidateWithHttpInfo(response) {
return __awaiter(this, void 0, void 0, function* () {
const contentType = ObjectSerializer_1.ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if ((0, util_1.isCodeInRange)("0", response.httpStatusCode)) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "Error", "");
throw new exception_1.ApiException(response.httpStatusCode, "An error occurred.", body, response.headers);
}
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return new http_1.HttpInfo(response.httpStatusCode, response.headers, response.body, undefined);
}
throw new exception_1.ApiException(response.httpStatusCode, "Unknown API Status Code!", yield response.getBodyAsAny(), response.headers);
});
}
getAsyncStatusWithHttpInfo(response) {
return __awaiter(this, void 0, void 0, function* () {
const contentType = ObjectSerializer_1.ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if ((0, util_1.isCodeInRange)("200", response.httpStatusCode)) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "ActionResponse", "");
return new http_1.HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
if ((0, util_1.isCodeInRange)("0", response.httpStatusCode)) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "Error", "");
throw new exception_1.ApiException(response.httpStatusCode, "An error occurred.", body, response.headers);
}
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "ActionResponse", "");
return new http_1.HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new exception_1.ApiException(response.httpStatusCode, "Unknown API Status Code!", yield response.getBodyAsAny(), response.headers);
});
}
}
exports.AdvancedApiResponseProcessor = AdvancedApiResponseProcessor;
//# sourceMappingURL=AdvancedApi.js.map