@datadog/datadog-api-client
Version:
OpenAPI client for Datadog APIs
545 lines • 30 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnnotationsApi = exports.AnnotationsApiResponseProcessor = exports.AnnotationsApiRequestFactory = void 0;
const baseapi_1 = require("../../datadog-api-client-common/baseapi");
const configuration_1 = require("../../datadog-api-client-common/configuration");
const http_1 = require("../../datadog-api-client-common/http/http");
const logger_1 = require("../../../logger");
const ObjectSerializer_1 = require("../models/ObjectSerializer");
const exception_1 = require("../../datadog-api-client-common/exception");
class AnnotationsApiRequestFactory extends baseapi_1.BaseAPIRequestFactory {
createAnnotation(body, _options) {
return __awaiter(this, void 0, void 0, function* () {
const _config = _options || this.configuration;
logger_1.logger.warn("Using unstable operation 'createAnnotation'");
if (!_config.unstableOperations["v2.createAnnotation"]) {
throw new Error("Unstable operation 'createAnnotation' is disabled");
}
// verify required parameter 'body' is not null or undefined
if (body === null || body === undefined) {
throw new baseapi_1.RequiredError("body", "createAnnotation");
}
// Path Params
const localVarPath = "/api/v2/annotation";
// Make Request Context
const requestContext = _config
.getServer("v2.AnnotationsApi.createAnnotation")
.makeRequestContext(localVarPath, http_1.HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json");
requestContext.setHttpConfig(_config.httpConfig);
// Body Params
const contentType = ObjectSerializer_1.ObjectSerializer.getPreferredMediaType([
"application/json",
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer_1.ObjectSerializer.stringify(ObjectSerializer_1.ObjectSerializer.serialize(body, "AnnotationCreateRequest", ""), contentType);
requestContext.setBody(serializedBody);
// Apply auth methods
(0, configuration_1.applySecurityAuthentication)(_config, requestContext, [
"apiKeyAuth",
"appKeyAuth",
]);
return requestContext;
});
}
deleteAnnotation(annotationId, _options) {
return __awaiter(this, void 0, void 0, function* () {
const _config = _options || this.configuration;
logger_1.logger.warn("Using unstable operation 'deleteAnnotation'");
if (!_config.unstableOperations["v2.deleteAnnotation"]) {
throw new Error("Unstable operation 'deleteAnnotation' is disabled");
}
// verify required parameter 'annotationId' is not null or undefined
if (annotationId === null || annotationId === undefined) {
throw new baseapi_1.RequiredError("annotationId", "deleteAnnotation");
}
// Path Params
const localVarPath = "/api/v2/annotation/{annotation_id}".replace("{annotation_id}", encodeURIComponent(String(annotationId)));
// Make Request Context
const requestContext = _config
.getServer("v2.AnnotationsApi.deleteAnnotation")
.makeRequestContext(localVarPath, http_1.HttpMethod.DELETE);
requestContext.setHeaderParam("Accept", "*/*");
requestContext.setHttpConfig(_config.httpConfig);
// Apply auth methods
(0, configuration_1.applySecurityAuthentication)(_config, requestContext, [
"apiKeyAuth",
"appKeyAuth",
]);
return requestContext;
});
}
getPageAnnotations(pageId, startTime, endTime, _options) {
return __awaiter(this, void 0, void 0, function* () {
const _config = _options || this.configuration;
logger_1.logger.warn("Using unstable operation 'getPageAnnotations'");
if (!_config.unstableOperations["v2.getPageAnnotations"]) {
throw new Error("Unstable operation 'getPageAnnotations' is disabled");
}
// verify required parameter 'pageId' is not null or undefined
if (pageId === null || pageId === undefined) {
throw new baseapi_1.RequiredError("pageId", "getPageAnnotations");
}
// verify required parameter 'startTime' is not null or undefined
if (startTime === null || startTime === undefined) {
throw new baseapi_1.RequiredError("startTime", "getPageAnnotations");
}
// verify required parameter 'endTime' is not null or undefined
if (endTime === null || endTime === undefined) {
throw new baseapi_1.RequiredError("endTime", "getPageAnnotations");
}
// Path Params
const localVarPath = "/api/v2/annotation/page/{page_id}".replace("{page_id}", encodeURIComponent(String(pageId)));
// Make Request Context
const requestContext = _config
.getServer("v2.AnnotationsApi.getPageAnnotations")
.makeRequestContext(localVarPath, http_1.HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json");
requestContext.setHttpConfig(_config.httpConfig);
// Query Params
if (startTime !== undefined) {
requestContext.setQueryParam("start_time", ObjectSerializer_1.ObjectSerializer.serialize(startTime, "number", "int64"), "");
}
if (endTime !== undefined) {
requestContext.setQueryParam("end_time", ObjectSerializer_1.ObjectSerializer.serialize(endTime, "number", "int64"), "");
}
// Apply auth methods
(0, configuration_1.applySecurityAuthentication)(_config, requestContext, [
"apiKeyAuth",
"appKeyAuth",
]);
return requestContext;
});
}
listAnnotations(pageId, startTime, endTime, widgetId, _options) {
return __awaiter(this, void 0, void 0, function* () {
const _config = _options || this.configuration;
logger_1.logger.warn("Using unstable operation 'listAnnotations'");
if (!_config.unstableOperations["v2.listAnnotations"]) {
throw new Error("Unstable operation 'listAnnotations' is disabled");
}
// verify required parameter 'pageId' is not null or undefined
if (pageId === null || pageId === undefined) {
throw new baseapi_1.RequiredError("pageId", "listAnnotations");
}
// verify required parameter 'startTime' is not null or undefined
if (startTime === null || startTime === undefined) {
throw new baseapi_1.RequiredError("startTime", "listAnnotations");
}
// verify required parameter 'endTime' is not null or undefined
if (endTime === null || endTime === undefined) {
throw new baseapi_1.RequiredError("endTime", "listAnnotations");
}
// Path Params
const localVarPath = "/api/v2/annotation";
// Make Request Context
const requestContext = _config
.getServer("v2.AnnotationsApi.listAnnotations")
.makeRequestContext(localVarPath, http_1.HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json");
requestContext.setHttpConfig(_config.httpConfig);
// Query Params
if (pageId !== undefined) {
requestContext.setQueryParam("page_id", ObjectSerializer_1.ObjectSerializer.serialize(pageId, "string", ""), "");
}
if (startTime !== undefined) {
requestContext.setQueryParam("start_time", ObjectSerializer_1.ObjectSerializer.serialize(startTime, "number", "int64"), "");
}
if (endTime !== undefined) {
requestContext.setQueryParam("end_time", ObjectSerializer_1.ObjectSerializer.serialize(endTime, "number", "int64"), "");
}
if (widgetId !== undefined) {
requestContext.setQueryParam("widget_id", ObjectSerializer_1.ObjectSerializer.serialize(widgetId, "string", ""), "");
}
// Apply auth methods
(0, configuration_1.applySecurityAuthentication)(_config, requestContext, [
"apiKeyAuth",
"appKeyAuth",
]);
return requestContext;
});
}
updateAnnotation(annotationId, body, _options) {
return __awaiter(this, void 0, void 0, function* () {
const _config = _options || this.configuration;
logger_1.logger.warn("Using unstable operation 'updateAnnotation'");
if (!_config.unstableOperations["v2.updateAnnotation"]) {
throw new Error("Unstable operation 'updateAnnotation' is disabled");
}
// verify required parameter 'annotationId' is not null or undefined
if (annotationId === null || annotationId === undefined) {
throw new baseapi_1.RequiredError("annotationId", "updateAnnotation");
}
// verify required parameter 'body' is not null or undefined
if (body === null || body === undefined) {
throw new baseapi_1.RequiredError("body", "updateAnnotation");
}
// Path Params
const localVarPath = "/api/v2/annotation/{annotation_id}".replace("{annotation_id}", encodeURIComponent(String(annotationId)));
// Make Request Context
const requestContext = _config
.getServer("v2.AnnotationsApi.updateAnnotation")
.makeRequestContext(localVarPath, http_1.HttpMethod.PUT);
requestContext.setHeaderParam("Accept", "application/json");
requestContext.setHttpConfig(_config.httpConfig);
// Body Params
const contentType = ObjectSerializer_1.ObjectSerializer.getPreferredMediaType([
"application/json",
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer_1.ObjectSerializer.stringify(ObjectSerializer_1.ObjectSerializer.serialize(body, "AnnotationUpdateRequest", ""), contentType);
requestContext.setBody(serializedBody);
// Apply auth methods
(0, configuration_1.applySecurityAuthentication)(_config, requestContext, [
"apiKeyAuth",
"appKeyAuth",
]);
return requestContext;
});
}
}
exports.AnnotationsApiRequestFactory = AnnotationsApiRequestFactory;
class AnnotationsApiResponseProcessor {
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to createAnnotation
* @throws ApiException if the response code was not in [200, 299]
*/
createAnnotation(response) {
return __awaiter(this, void 0, void 0, function* () {
const contentType = ObjectSerializer_1.ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (response.httpStatusCode === 200) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "AnnotationResponse");
return body;
}
if (response.httpStatusCode === 400 ||
response.httpStatusCode === 403 ||
response.httpStatusCode === 500) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "JSONAPIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
if (response.httpStatusCode === 429) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "APIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "AnnotationResponse", "");
return body;
}
const body = (yield response.body.text()) || "";
throw new exception_1.ApiException(response.httpStatusCode, 'Unknown API Status Code!\nBody: "' + body + '"');
});
}
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to deleteAnnotation
* @throws ApiException if the response code was not in [200, 299]
*/
deleteAnnotation(response) {
return __awaiter(this, void 0, void 0, function* () {
const contentType = ObjectSerializer_1.ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (response.httpStatusCode === 204) {
return;
}
if (response.httpStatusCode === 400 ||
response.httpStatusCode === 403 ||
response.httpStatusCode === 500) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "JSONAPIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
if (response.httpStatusCode === 429) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "APIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return;
}
const body = (yield response.body.text()) || "";
throw new exception_1.ApiException(response.httpStatusCode, 'Unknown API Status Code!\nBody: "' + body + '"');
});
}
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to getPageAnnotations
* @throws ApiException if the response code was not in [200, 299]
*/
getPageAnnotations(response) {
return __awaiter(this, void 0, void 0, function* () {
const contentType = ObjectSerializer_1.ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (response.httpStatusCode === 200) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "PageAnnotationsResponse");
return body;
}
if (response.httpStatusCode === 400 ||
response.httpStatusCode === 403 ||
response.httpStatusCode === 500) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "JSONAPIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
if (response.httpStatusCode === 429) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "APIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "PageAnnotationsResponse", "");
return body;
}
const body = (yield response.body.text()) || "";
throw new exception_1.ApiException(response.httpStatusCode, 'Unknown API Status Code!\nBody: "' + body + '"');
});
}
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to listAnnotations
* @throws ApiException if the response code was not in [200, 299]
*/
listAnnotations(response) {
return __awaiter(this, void 0, void 0, function* () {
const contentType = ObjectSerializer_1.ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (response.httpStatusCode === 200) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "AnnotationsResponse");
return body;
}
if (response.httpStatusCode === 400 ||
response.httpStatusCode === 403 ||
response.httpStatusCode === 500) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "JSONAPIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
if (response.httpStatusCode === 429) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "APIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "AnnotationsResponse", "");
return body;
}
const body = (yield response.body.text()) || "";
throw new exception_1.ApiException(response.httpStatusCode, 'Unknown API Status Code!\nBody: "' + body + '"');
});
}
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to updateAnnotation
* @throws ApiException if the response code was not in [200, 299]
*/
updateAnnotation(response) {
return __awaiter(this, void 0, void 0, function* () {
const contentType = ObjectSerializer_1.ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (response.httpStatusCode === 200) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "AnnotationResponse");
return body;
}
if (response.httpStatusCode === 400 ||
response.httpStatusCode === 403 ||
response.httpStatusCode === 404 ||
response.httpStatusCode === 500) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "JSONAPIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
if (response.httpStatusCode === 429) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "APIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "AnnotationResponse", "");
return body;
}
const body = (yield response.body.text()) || "";
throw new exception_1.ApiException(response.httpStatusCode, 'Unknown API Status Code!\nBody: "' + body + '"');
});
}
}
exports.AnnotationsApiResponseProcessor = AnnotationsApiResponseProcessor;
class AnnotationsApi {
constructor(configuration, requestFactory, responseProcessor) {
this.configuration = configuration;
this.requestFactory =
requestFactory || new AnnotationsApiRequestFactory(configuration);
this.responseProcessor =
responseProcessor || new AnnotationsApiResponseProcessor();
}
/**
* Creates a new annotation on a dashboard or notebook page.
* Valid `color` values: `gray`, `blue`, `purple`, `green`, `yellow`, `red`.
* Valid `type` values: `pointInTime` (marks a single moment) or `timeRegion` (spans a range and requires `end_time`).
* @param param The request object
*/
createAnnotation(param, options) {
const requestContextPromise = this.requestFactory.createAnnotation(param.body, options);
return requestContextPromise.then((requestContext) => {
return this.configuration.httpApi
.send(requestContext)
.then((responseContext) => {
return this.responseProcessor.createAnnotation(responseContext);
});
});
}
/**
* Deletes an existing annotation by ID.
* Returns `204 No Content` if the annotation does not exist (idempotent).
* @param param The request object
*/
deleteAnnotation(param, options) {
const requestContextPromise = this.requestFactory.deleteAnnotation(param.annotationId, options);
return requestContextPromise.then((requestContext) => {
return this.configuration.httpApi
.send(requestContext)
.then((responseContext) => {
return this.responseProcessor.deleteAnnotation(responseContext);
});
});
}
/**
* Returns all annotations on a specific page for a given time window, grouped by widget.
* Unlike `ListAnnotations`, this endpoint returns a single structured object with annotations
* indexed by their ID and a widget-to-annotation mapping for easy UI rendering.
* @param param The request object
*/
getPageAnnotations(param, options) {
const requestContextPromise = this.requestFactory.getPageAnnotations(param.pageId, param.startTime, param.endTime, options);
return requestContextPromise.then((requestContext) => {
return this.configuration.httpApi
.send(requestContext)
.then((responseContext) => {
return this.responseProcessor.getPageAnnotations(responseContext);
});
});
}
/**
* Returns a flat list of annotations matching the given page, time window, and optional widget filter.
* @param param The request object
*/
listAnnotations(param, options) {
const requestContextPromise = this.requestFactory.listAnnotations(param.pageId, param.startTime, param.endTime, param.widgetId, options);
return requestContextPromise.then((requestContext) => {
return this.configuration.httpApi
.send(requestContext)
.then((responseContext) => {
return this.responseProcessor.listAnnotations(responseContext);
});
});
}
/**
* Updates an existing annotation.
* Valid `color` values: `gray`, `blue`, `purple`, `green`, `yellow`, `red`.
* Valid `type` values: `pointInTime` (marks a single moment) or `timeRegion` (spans a range and requires `end_time`).
* @param param The request object
*/
updateAnnotation(param, options) {
const requestContextPromise = this.requestFactory.updateAnnotation(param.annotationId, param.body, options);
return requestContextPromise.then((requestContext) => {
return this.configuration.httpApi
.send(requestContext)
.then((responseContext) => {
return this.responseProcessor.updateAnnotation(responseContext);
});
});
}
}
exports.AnnotationsApi = AnnotationsApi;
//# sourceMappingURL=AnnotationsApi.js.map