@ibm-cloud/platform-services
Version:
Node.js client library for IBM Cloud Platform Services
831 lines • 37.7 kB
JavaScript
"use strict";
/**
* (C) Copyright IBM Corp. 2022.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
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 __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
/**
* IBM OpenAPI SDK Code Generator Version: 3.60.0-13f6e1ba-20221019-164457
*/
/* eslint-disable max-classes-per-file */
/* eslint-disable no-await-in-loop */
var extend = require("extend");
var ibm_cloud_sdk_core_1 = require("ibm-cloud-sdk-core");
var common_1 = require("../lib/common");
/**
* Case management API for creating cases, getting case statuses, adding comments to a case, adding and removing users
* from a case watchlist, downloading and adding attachments, and more.
*
* API Version: 1.0.0
*/
var CaseManagementV1 = /** @class */ (function (_super) {
__extends(CaseManagementV1, _super);
/**
* Construct a CaseManagementV1 object.
*
* @param {Object} options - Options for the service.
* @param {string} [options.serviceUrl] - The base url to use when contacting the service. The base url may differ between IBM Cloud regions.
* @param {OutgoingHttpHeaders} [options.headers] - Default headers that shall be included with every request to the service.
* @param {Authenticator} options.authenticator - The Authenticator object used to authenticate requests to the service
* @constructor
* @returns {CaseManagementV1}
*/
function CaseManagementV1(options) {
var _this = this;
options = options || {};
_this = _super.call(this, options) || this;
if (options.serviceUrl) {
_this.setServiceUrl(options.serviceUrl);
}
else {
_this.setServiceUrl(CaseManagementV1.DEFAULT_SERVICE_URL);
}
return _this;
}
/*************************
* Factory method
************************/
/**
* Constructs an instance of CaseManagementV1 with passed in options and external configuration.
*
* @param {UserOptions} [options] - The parameters to send to the service.
* @param {string} [options.serviceName] - The name of the service to configure
* @param {Authenticator} [options.authenticator] - The Authenticator object used to authenticate requests to the service
* @param {string} [options.serviceUrl] - The URL for the service
* @returns {CaseManagementV1}
*/
CaseManagementV1.newInstance = function (options) {
options = options || {};
if (!options.serviceName) {
options.serviceName = this.DEFAULT_SERVICE_NAME;
}
if (!options.authenticator) {
options.authenticator = (0, ibm_cloud_sdk_core_1.getAuthenticatorFromEnvironment)(options.serviceName);
}
var service = new CaseManagementV1(options);
service.configureService(options.serviceName);
if (options.serviceUrl) {
service.setServiceUrl(options.serviceUrl);
}
return service;
};
/*************************
* default
************************/
/**
* Get cases in account.
*
* Get cases in the account that are specified by the content of the IAM token.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {number} [params.offset] - Number of cases that are skipped.
* @param {number} [params.limit] - Number of cases that are returned.
* @param {string} [params.search] - String that a case might contain.
* @param {string} [params.sort] - Sort field and direction. If omitted, default to descending of updated date. Prefix
* "~" signifies sort in descending.
* @param {string[]} [params.status] - Case status filter.
* @param {string[]} [params.fields] - Selected fields of interest instead of all of the case information.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<CaseManagementV1.Response<CaseManagementV1.CaseList>>}
*/
CaseManagementV1.prototype.getCases = function (params) {
var _params = __assign({}, params);
var _requiredParams = [];
var _validParams = ['offset', 'limit', 'search', 'sort', 'status', 'fields', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'offset': _params.offset,
'limit': _params.limit,
'search': _params.search,
'sort': _params.sort,
'status': _params.status,
'fields': _params.fields,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(CaseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'getCases');
var parameters = {
options: {
url: '/cases',
method: 'GET',
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Create a case.
*
* Create a support case to resolve issues in your account.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.type - Case type.
* @param {string} params.subject - Short description used to identify the case.
* @param {string} params.description - Detailed description of the issue.
* @param {number} [params.severity] - Severity of the case. Smaller values mean higher severity.
* @param {CasePayloadEu} [params.eu] - Specify if the case should be treated as EU regulated. Only one of the
* following properties is required. Call EU support utility endpoint to determine which property must be specified
* for your account.
* @param {Offering} [params.offering] - Offering details.
* @param {ResourcePayload[]} [params.resources] - List of resources to attach to case. If you attach Classic IaaS
* devices, use the type and id fields if the Cloud Resource Name (CRN) is unavailable. Otherwise, pass the resource
* CRN. The resource list must be consistent with the value that is selected for the resource offering.
* @param {User[]} [params.watchlist] - Array of user IDs to add to the watchlist.
* @param {string} [params.invoiceNumber] - Invoice number of "Billing and Invoice" case type.
* @param {boolean} [params.slaCreditRequest] - Flag to indicate if case is for an Service Level Agreement (SLA)
* credit request.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<CaseManagementV1.Response<CaseManagementV1.Case>>}
*/
CaseManagementV1.prototype.createCase = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['type', 'subject', 'description'];
var _validParams = [
'type',
'subject',
'description',
'severity',
'eu',
'offering',
'resources',
'watchlist',
'invoiceNumber',
'slaCreditRequest',
'headers',
];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'type': _params.type,
'subject': _params.subject,
'description': _params.description,
'severity': _params.severity,
'eu': _params.eu,
'offering': _params.offering,
'resources': _params.resources,
'watchlist': _params.watchlist,
'invoice_number': _params.invoiceNumber,
'sla_credit_request': _params.slaCreditRequest,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(CaseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'createCase');
var parameters = {
options: {
url: '/cases',
method: 'POST',
body: body,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Get a case in account.
*
* View a case in the account that is specified by the case number.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.caseNumber - Unique identifier of a case.
* @param {string[]} [params.fields] - Selected fields of interest instead of all of the case information.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<CaseManagementV1.Response<CaseManagementV1.Case>>}
*/
CaseManagementV1.prototype.getCase = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['caseNumber'];
var _validParams = ['caseNumber', 'fields', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'fields': _params.fields,
};
var path = {
'case_number': _params.caseNumber,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(CaseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'getCase');
var parameters = {
options: {
url: '/cases/{case_number}',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Update case status.
*
* Mark the case as resolved or unresolved, or accept the provided resolution.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.caseNumber - Unique identifier of a case.
* @param {StatusPayload} params.statusPayload -
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<CaseManagementV1.Response<CaseManagementV1.Case>>}
*/
CaseManagementV1.prototype.updateCaseStatus = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['caseNumber', 'statusPayload'];
var _validParams = ['caseNumber', 'statusPayload', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = _params.statusPayload;
var path = {
'case_number': _params.caseNumber,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(CaseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'updateCaseStatus');
var parameters = {
options: {
url: '/cases/{case_number}/status',
method: 'PUT',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Add comment to case.
*
* Add a comment to a case to be viewed by a support engineer.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.caseNumber - Unique identifier of a case.
* @param {string} params.comment - Comment to add to the case.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<CaseManagementV1.Response<CaseManagementV1.Comment>>}
*/
CaseManagementV1.prototype.addComment = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['caseNumber', 'comment'];
var _validParams = ['caseNumber', 'comment', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'comment': _params.comment,
};
var path = {
'case_number': _params.caseNumber,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(CaseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'addComment');
var parameters = {
options: {
url: '/cases/{case_number}/comments',
method: 'PUT',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Add users to watchlist of case.
*
* Add users to the watchlist of case. By adding a user to the watchlist of the case, you are granting them read and
* write permissions, so the user can view the case, receive updates, and make updates to the case. Note that the user
* must be in the account to be added to the watchlist.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.caseNumber - Unique identifier of a case.
* @param {User[]} [params.watchlist] - Array of user ID objects.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<CaseManagementV1.Response<CaseManagementV1.WatchlistAddResponse>>}
*/
CaseManagementV1.prototype.addWatchlist = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['caseNumber'];
var _validParams = ['caseNumber', 'watchlist', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'watchlist': _params.watchlist,
};
var path = {
'case_number': _params.caseNumber,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(CaseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'addWatchlist');
var parameters = {
options: {
url: '/cases/{case_number}/watchlist',
method: 'PUT',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Remove users from watchlist of case.
*
* Remove users from the watchlist of a case if you don't want them to view the case, receive updates, or make updates
* to the case.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.caseNumber - Unique identifier of a case.
* @param {User[]} [params.watchlist] - Array of user ID objects.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<CaseManagementV1.Response<CaseManagementV1.Watchlist>>}
*/
CaseManagementV1.prototype.removeWatchlist = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['caseNumber'];
var _validParams = ['caseNumber', 'watchlist', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'watchlist': _params.watchlist,
};
var path = {
'case_number': _params.caseNumber,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(CaseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'removeWatchlist');
var parameters = {
options: {
url: '/cases/{case_number}/watchlist',
method: 'DELETE',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Add a resource to case.
*
* Add a resource to case by specifying the Cloud Resource Name (CRN), or id and type if attaching a class iaaS
* resource.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.caseNumber - Unique identifier of a case.
* @param {string} [params.crn] - Cloud Resource Name of the resource.
* @param {string} [params.type] - Only used to attach Classic IaaS devices that have no CRN.
* @param {number} [params.id] - Deprecated: Only used to attach Classic IaaS devices that have no CRN. Id of Classic
* IaaS device. This is deprecated in favor of the crn field.
* @param {string} [params.note] - A note about this resource.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<CaseManagementV1.Response<CaseManagementV1.Resource>>}
*/
CaseManagementV1.prototype.addResource = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['caseNumber'];
var _validParams = ['caseNumber', 'crn', 'type', 'id', 'note', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'crn': _params.crn,
'type': _params.type,
'id': _params.id,
'note': _params.note,
};
var path = {
'case_number': _params.caseNumber,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(CaseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'addResource');
var parameters = {
options: {
url: '/cases/{case_number}/resources',
method: 'PUT',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Add attachments to a support case.
*
* You can add attachments to a case to provide more information for the support team about the issue that you're
* experiencing.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.caseNumber - Unique identifier of a case.
* @param {FileWithMetadata[]} params.file - file of supported types, 8MB in size limit.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<CaseManagementV1.Response<CaseManagementV1.Attachment>>}
*/
CaseManagementV1.prototype.uploadFile = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['caseNumber', 'file'];
var _validParams = ['caseNumber', 'file', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var formData = {
'file': _params.file,
};
var path = {
'case_number': _params.caseNumber,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(CaseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'uploadFile');
var parameters = {
options: {
url: '/cases/{case_number}/attachments',
method: 'PUT',
path: path,
formData: formData,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Download an attachment.
*
* Download an attachment from a case.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.caseNumber - Unique identifier of a case.
* @param {string} params.fileId - Unique identifier of a file.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<CaseManagementV1.Response<NodeJS.ReadableStream>>}
*/
CaseManagementV1.prototype.downloadFile = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['caseNumber', 'fileId'];
var _validParams = ['caseNumber', 'fileId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var path = {
'case_number': _params.caseNumber,
'file_id': _params.fileId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(CaseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'downloadFile');
var parameters = {
options: {
url: '/cases/{case_number}/attachments/{file_id}',
method: 'GET',
path: path,
responseType: 'stream',
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/octet-stream',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Remove attachment from case.
*
* Remove an attachment from a case.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.caseNumber - Unique identifier of a case.
* @param {string} params.fileId - Unique identifier of a file.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<CaseManagementV1.Response<CaseManagementV1.AttachmentList>>}
*/
CaseManagementV1.prototype.deleteFile = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['caseNumber', 'fileId'];
var _validParams = ['caseNumber', 'fileId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var path = {
'case_number': _params.caseNumber,
'file_id': _params.fileId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(CaseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'deleteFile');
var parameters = {
options: {
url: '/cases/{case_number}/attachments/{file_id}',
method: 'DELETE',
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
CaseManagementV1.DEFAULT_SERVICE_URL = 'https://support-center.cloud.ibm.com/case-management/v1';
CaseManagementV1.DEFAULT_SERVICE_NAME = 'case_management';
return CaseManagementV1;
}(ibm_cloud_sdk_core_1.BaseService));
/*************************
* interfaces
************************/
(function (CaseManagementV1) {
/** Constants for the `getCases` operation. */
var GetCasesConstants;
(function (GetCasesConstants) {
/** Case status filter. */
var Status;
(function (Status) {
Status["NEW"] = "new";
Status["IN_PROGRESS"] = "in_progress";
Status["WAITING_ON_CLIENT"] = "waiting_on_client";
Status["RESOLUTION_PROVIDED"] = "resolution_provided";
Status["RESOLVED"] = "resolved";
Status["CLOSED"] = "closed";
})(Status = GetCasesConstants.Status || (GetCasesConstants.Status = {}));
/** Selected fields of interest instead of all of the case information. */
var Fields;
(function (Fields) {
Fields["NUMBER"] = "number";
Fields["SHORT_DESCRIPTION"] = "short_description";
Fields["DESCRIPTION"] = "description";
Fields["CREATED_AT"] = "created_at";
Fields["CREATED_BY"] = "created_by";
Fields["UPDATED_AT"] = "updated_at";
Fields["UPDATED_BY"] = "updated_by";
Fields["CONTACT"] = "contact";
Fields["CONTACT_TYPE"] = "contact_type";
Fields["STATUS"] = "status";
Fields["SEVERITY"] = "severity";
Fields["SUPPORT_TIER"] = "support_tier";
Fields["RESOLUTION"] = "resolution";
Fields["CLOSE_NOTES"] = "close_notes";
Fields["INVOICE_NUMBER"] = "invoice_number";
Fields["AGENT_CLOSE_ONLY"] = "agent_close_only";
Fields["EU"] = "eu";
Fields["WATCHLIST"] = "watchlist";
Fields["ATTACHMENTS"] = "attachments";
Fields["RESOURCES"] = "resources";
Fields["COMMENTS"] = "comments";
Fields["OFFERING"] = "offering";
})(Fields = GetCasesConstants.Fields || (GetCasesConstants.Fields = {}));
})(GetCasesConstants = CaseManagementV1.GetCasesConstants || (CaseManagementV1.GetCasesConstants = {}));
/** Constants for the `createCase` operation. */
var CreateCaseConstants;
(function (CreateCaseConstants) {
/** Case type. */
var Type;
(function (Type) {
Type["TECHNICAL"] = "technical";
Type["ACCOUNT_AND_ACCESS"] = "account_and_access";
Type["BILLING_AND_INVOICE"] = "billing_and_invoice";
Type["SALES"] = "sales";
})(Type = CreateCaseConstants.Type || (CreateCaseConstants.Type = {}));
})(CreateCaseConstants = CaseManagementV1.CreateCaseConstants || (CaseManagementV1.CreateCaseConstants = {}));
/** Constants for the `getCase` operation. */
var GetCaseConstants;
(function (GetCaseConstants) {
/** Selected fields of interest instead of all of the case information. */
var Fields;
(function (Fields) {
Fields["NUMBER"] = "number";
Fields["SHORT_DESCRIPTION"] = "short_description";
Fields["DESCRIPTION"] = "description";
Fields["CREATED_AT"] = "created_at";
Fields["CREATED_BY"] = "created_by";
Fields["UPDATED_AT"] = "updated_at";
Fields["UPDATED_BY"] = "updated_by";
Fields["CONTACT"] = "contact";
Fields["CONTACT_TYPE"] = "contact_type";
Fields["STATUS"] = "status";
Fields["SEVERITY"] = "severity";
Fields["SUPPORT_TIER"] = "support_tier";
Fields["RESOLUTION"] = "resolution";
Fields["CLOSE_NOTES"] = "close_notes";
Fields["INVOICE_NUMBER"] = "invoice_number";
Fields["AGENT_CLOSE_ONLY"] = "agent_close_only";
Fields["EU"] = "eu";
Fields["WATCHLIST"] = "watchlist";
Fields["ATTACHMENTS"] = "attachments";
Fields["RESOURCES"] = "resources";
Fields["COMMENTS"] = "comments";
Fields["OFFERING"] = "offering";
})(Fields = GetCaseConstants.Fields || (GetCaseConstants.Fields = {}));
})(GetCaseConstants = CaseManagementV1.GetCaseConstants || (CaseManagementV1.GetCaseConstants = {}));
/*************************
* pager classes
************************/
/**
* GetCasesPager can be used to simplify the use of getCases().
*/
var GetCasesPager = /** @class */ (function () {
/**
* Construct a GetCasesPager object.
*
* @param {CaseManagementV1} client - The service client instance used to invoke getCases()
* @param {Object} [params] - The parameters to be passed to getCases()
* @constructor
* @returns {GetCasesPager}
*/
function GetCasesPager(client, params) {
if (params && params.offset) {
throw new Error("the params.offset field should not be set");
}
this._hasNext = true;
this.pageContext = { next: undefined };
this.client = client;
this.params = JSON.parse(JSON.stringify(params || {}));
}
/**
* Returns true if there are potentially more results to be retrieved by invoking getNext().
* @returns {boolean}
*/
GetCasesPager.prototype.hasNext = function () {
return this._hasNext;
};
/**
* Returns the next page of results by invoking getCases().
* @returns {Promise<CaseManagementV1.Case[]>}
*/
GetCasesPager.prototype.getNext = function () {
return __awaiter(this, void 0, void 0, function () {
var response, result, next;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.hasNext()) {
throw new Error('No more results available');
}
if (this.pageContext.next) {
this.params.offset = this.pageContext.next;
}
return [4 /*yield*/, this.client.getCases(this.params)];
case 1:
response = _a.sent();
result = response.result;
next = null;
if (result && result.next) {
if (result.next.href) {
next = (0, ibm_cloud_sdk_core_1.getQueryParam)(result.next.href, 'offset');
}
}
this.pageContext.next = next;
if (!this.pageContext.next) {
this._hasNext = false;
}
return [2 /*return*/, result.cases];
}
});
});
};
/**
* Returns all results by invoking getCases() repeatedly until all pages of results have been retrieved.
* @returns {Promise<CaseManagementV1.Case[]>}
*/
GetCasesPager.prototype.getAll = function () {
return __awaiter(this, void 0, void 0, function () {
var results, nextPage;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
results = [];
_a.label = 1;
case 1:
if (!this.hasNext()) return [3 /*break*/, 3];
return [4 /*yield*/, this.getNext()];
case 2:
nextPage = _a.sent();
results.push.apply(results, nextPage);
return [3 /*break*/, 1];
case 3: return [2 /*return*/, results];
}
});
});
};
return GetCasesPager;
}());
CaseManagementV1.GetCasesPager = GetCasesPager;
})(CaseManagementV1 || (CaseManagementV1 = {}));
module.exports = CaseManagementV1;
//# sourceMappingURL=v1.js.map