UNPKG

@ibm-cloud/platform-services

Version:

Node.js client library for IBM Cloud Platform Services

502 lines 25.2 kB
"use strict"; /** * (C) Copyright IBM Corp. 2024. * * 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.96.0-d6dec9d7-20241008-212902 */ /* 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"); /** * The Partner Management APIs enable you to manage the IBM Cloud partner entities and fetch multiple reports in * different formats. * * API Version: 1.0.0 */ var PartnerManagementV1 = /** @class */ (function (_super) { __extends(PartnerManagementV1, _super); /** * Construct a PartnerManagementV1 object. * * @param {Object} options - Options for the service. * @param {string} [options.serviceUrl] - The base URL for the service * @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 {PartnerManagementV1} */ function PartnerManagementV1(options) { var _this = this; options = options || {}; _this = _super.call(this, options) || this; if (options.serviceUrl) { _this.setServiceUrl(options.serviceUrl); } else { _this.setServiceUrl(PartnerManagementV1.DEFAULT_SERVICE_URL); } return _this; } /************************* * Factory method ************************/ /** * Constructs an instance of PartnerManagementV1 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 base URL for the service * @returns {PartnerManagementV1} */ PartnerManagementV1.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 PartnerManagementV1(options); service.configureService(options.serviceName); if (options.serviceUrl) { service.setServiceUrl(options.serviceUrl); } return service; }; /************************* * usageReports ************************/ /** * Get partner resource usage report. * * Returns the summary for the partner for a given month. Partner billing managers are authorized to access this * report. * * @param {Object} params - The parameters to send to the service. * @param {string} params.partnerId - Enterprise ID of the distributor or reseller for which the report is requested. * @param {string} [params.resellerId] - Enterprise ID of the reseller for which the report is requested. This * parameter cannot be used along with `customer_id` query parameter. * @param {string} [params.customerId] - Account ID/Enterprise ID of the end customer for which the report is * requested. This parameter cannot be used along with `reseller_id` query parameter. * @param {boolean} [params.children] - Get report rolled-up to the direct children of the requested entity. Defaults * to false. This parameter cannot be used along with `customer_id` query parameter. * @param {string} [params.month] - The billing month for which the usage report is requested. Format is `yyyy-mm`. * Defaults to current month. * @param {string} [params.viewpoint] - Enables partner to view the cost of provisioned services as applicable at the * given level. Defaults to the type of the calling partner. The valid values are `DISTRIBUTOR`, `RESELLER` and * `END_CUSTOMER`. * @param {boolean} [params.recurse] - Get usage report rolled-up to the end customers of the requesting partner. * Defaults to false. This parameter cannot be used along with `reseller_id` query parameter or `customer_id` query * parameter. * @param {number} [params.limit] - Number of usage records to be returned. The default value is 30. Maximum value is * 100. * @param {string} [params.offset] - An opaque value representing the offset of the first item to be returned by a * search query. If not specified, then the first page of results is returned. To retrieve the next page of search * results, use the 'offset' query parameter value within the 'next.href' URL found within a prior search query * response. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise<PartnerManagementV1.Response<PartnerManagementV1.PartnerUsageReportSummary>>} */ PartnerManagementV1.prototype.getResourceUsageReport = function (params) { var _params = __assign({}, params); var _requiredParams = ['partnerId']; var _validParams = [ 'partnerId', 'resellerId', 'customerId', 'children', 'month', 'viewpoint', 'recurse', 'limit', 'offset', 'headers', ]; var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams); if (_validationErrors) { return Promise.reject(_validationErrors); } var query = { 'partner_id': _params.partnerId, 'reseller_id': _params.resellerId, 'customer_id': _params.customerId, 'children': _params.children, 'month': _params.month, 'viewpoint': _params.viewpoint, 'recurse': _params.recurse, 'limit': _params.limit, 'offset': _params.offset, }; var sdkHeaders = (0, common_1.getSdkHeaders)(PartnerManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'getResourceUsageReport'); var parameters = { options: { url: '/v1/resource-usage-reports', method: 'GET', qs: query, }, defaultOptions: extend(true, {}, this.baseOptions, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters); }; /************************* * billingOptions ************************/ /** * Get customers billing options. * * Returns the billing options for the requested customer for a given month. * * @param {Object} params - The parameters to send to the service. * @param {string} params.partnerId - Enterprise ID of the distributor or reseller for which the report is requested. * @param {string} [params.customerId] - Account ID/Enterprise ID of the end customer for which the report is * requested. This parameter cannot be used along with `reseller_id` query parameter. * @param {string} [params.resellerId] - Enterprise ID of the reseller for which the report is requested. This * parameter cannot be used along with `customer_id` query parameter. * @param {string} [params.date] - The billing month for which the report is requested. Format is yyyy-mm. Defaults to * current month. * @param {number} [params.limit] - Number of billing option reports returned. The default value is 200. Maximum value * is 200. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise<PartnerManagementV1.Response<PartnerManagementV1.BillingOptionsSummary>>} */ PartnerManagementV1.prototype.getBillingOptions = function (params) { var _params = __assign({}, params); var _requiredParams = ['partnerId']; var _validParams = ['partnerId', 'customerId', 'resellerId', 'date', 'limit', 'headers']; var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams); if (_validationErrors) { return Promise.reject(_validationErrors); } var query = { 'partner_id': _params.partnerId, 'customer_id': _params.customerId, 'reseller_id': _params.resellerId, 'date': _params.date, 'limit': _params.limit, }; var sdkHeaders = (0, common_1.getSdkHeaders)(PartnerManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'getBillingOptions'); var parameters = { options: { url: '/v1/billing-options', method: 'GET', qs: query, }, defaultOptions: extend(true, {}, this.baseOptions, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters); }; /************************* * creditPools ************************/ /** * Get credit pools report. * * Returns the subscription or commitment burn-down reports for the end customers for a given month. * * @param {Object} params - The parameters to send to the service. * @param {string} params.partnerId - Enterprise ID of the distributor or reseller for which the report is requested. * @param {string} [params.customerId] - Account ID/Enterprise ID of the end customer for which the report is * requested. This parameter cannot be used along with `reseller_id` query parameter. * @param {string} [params.resellerId] - Enterprise ID of the reseller for which the report is requested. This * parameter cannot be used along with `customer_id` query parameter. * @param {string} [params.date] - The billing month for which the report is requested. Format is yyyy-mm. Defaults to * current month. * @param {number} [params.limit] - Number of billing units fetched to get the credit pools report. The default value * is 30. Maximum value is 30. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise<PartnerManagementV1.Response<PartnerManagementV1.CreditPoolsReportSummary>>} */ PartnerManagementV1.prototype.getCreditPoolsReport = function (params) { var _params = __assign({}, params); var _requiredParams = ['partnerId']; var _validParams = ['partnerId', 'customerId', 'resellerId', 'date', 'limit', 'headers']; var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams); if (_validationErrors) { return Promise.reject(_validationErrors); } var query = { 'partner_id': _params.partnerId, 'customer_id': _params.customerId, 'reseller_id': _params.resellerId, 'date': _params.date, 'limit': _params.limit, }; var sdkHeaders = (0, common_1.getSdkHeaders)(PartnerManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'getCreditPoolsReport'); var parameters = { options: { url: '/v1/credit-pools', method: 'GET', qs: query, }, defaultOptions: extend(true, {}, this.baseOptions, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters); }; PartnerManagementV1.DEFAULT_SERVICE_URL = 'https://partner.cloud.ibm.com'; PartnerManagementV1.DEFAULT_SERVICE_NAME = 'partner_management'; return PartnerManagementV1; }(ibm_cloud_sdk_core_1.BaseService)); /************************* * interfaces ************************/ (function (PartnerManagementV1) { /** Constants for the `getResourceUsageReport` operation. */ var GetResourceUsageReportConstants; (function (GetResourceUsageReportConstants) { /** Enables partner to view the cost of provisioned services as applicable at the given level. Defaults to the type of the calling partner. The valid values are `DISTRIBUTOR`, `RESELLER` and `END_CUSTOMER`. */ var Viewpoint; (function (Viewpoint) { Viewpoint["DISTRIBUTOR"] = "DISTRIBUTOR"; Viewpoint["RESELLER"] = "RESELLER"; Viewpoint["END_CUSTOMER"] = "END_CUSTOMER"; })(Viewpoint = GetResourceUsageReportConstants.Viewpoint || (GetResourceUsageReportConstants.Viewpoint = {})); })(GetResourceUsageReportConstants = PartnerManagementV1.GetResourceUsageReportConstants || (PartnerManagementV1.GetResourceUsageReportConstants = {})); var BillingOption; (function (BillingOption) { var Constants; (function (Constants) { /** The customer type. The valid values are `ENTERPRISE`, `ACCOUNT`, and `ACCOUNT_GROUP`. */ var CustomerType; (function (CustomerType) { CustomerType["ENTERPRISE"] = "ENTERPRISE"; CustomerType["ACCOUNT"] = "ACCOUNT"; CustomerType["ACCOUNT_GROUP"] = "ACCOUNT_GROUP"; })(CustomerType = Constants.CustomerType || (Constants.CustomerType = {})); /** The type of billing option. The valid values are `SUBSCRIPTION` and `OFFER`. */ var Type; (function (Type) { Type["SUBSCRIPTION"] = "SUBSCRIPTION"; Type["OFFER"] = "OFFER"; })(Type = Constants.Type || (Constants.Type = {})); /** The state of the billing option. The valid values include `ACTIVE, `SUSPENDED`, and `CANCELED`. */ var State; (function (State) { State["ACTIVE"] = "ACTIVE"; State["SUSPENDED"] = "SUSPENDED"; State["CANCELED"] = "CANCELED"; })(State = Constants.State || (Constants.State = {})); /** The category of the billing option. The valid values are `PLATFORM`, `SERVICE`, and `SUPPORT`. */ var Category; (function (Category) { Category["PLATFORM"] = "PLATFORM"; Category["SERVICE"] = "SERVICE"; Category["SUPPORT"] = "SUPPORT"; })(Category = Constants.Category || (Constants.Category = {})); })(Constants = BillingOption.Constants || (BillingOption.Constants = {})); })(BillingOption = PartnerManagementV1.BillingOption || (PartnerManagementV1.BillingOption = {})); var CreditPoolsReport; (function (CreditPoolsReport) { var Constants; (function (Constants) { /** The category of the billing option. The valid values are `PLATFORM`, `SERVICE` and `SUPPORT`. */ var Type; (function (Type) { Type["PLATFORM"] = "PLATFORM"; Type["SERVICE"] = "SERVICE"; Type["SUPPORT"] = "SUPPORT"; })(Type = Constants.Type || (Constants.Type = {})); /** The customer type. The valid values are `ENTERPRISE`, `ACCOUNT`, and `ACCOUNT_GROUP`. */ var CustomerType; (function (CustomerType) { CustomerType["ENTERPRISE"] = "ENTERPRISE"; CustomerType["ACCOUNT"] = "ACCOUNT"; CustomerType["ACCOUNT_GROUP"] = "ACCOUNT_GROUP"; })(CustomerType = Constants.CustomerType || (Constants.CustomerType = {})); })(Constants = CreditPoolsReport.Constants || (CreditPoolsReport.Constants = {})); })(CreditPoolsReport = PartnerManagementV1.CreditPoolsReport || (PartnerManagementV1.CreditPoolsReport = {})); var TermCredits; (function (TermCredits) { var Constants; (function (Constants) { /** The category of the billing option. The valid values are `PLATFORM`, `SERVICE`, and `SUPPORT`. */ var Category; (function (Category) { Category["PLATFORM"] = "PLATFORM"; Category["SERVICE"] = "SERVICE"; Category["SUPPORT"] = "SUPPORT"; })(Category = Constants.Category || (Constants.Category = {})); })(Constants = TermCredits.Constants || (TermCredits.Constants = {})); })(TermCredits = PartnerManagementV1.TermCredits || (PartnerManagementV1.TermCredits = {})); /************************* * pager classes ************************/ /** * GetResourceUsageReportPager can be used to simplify the use of getResourceUsageReport(). */ var GetResourceUsageReportPager = /** @class */ (function () { /** * Construct a GetResourceUsageReportPager object. * * @param {PartnerManagementV1} client - The service client instance used to invoke getResourceUsageReport() * @param {Object} params - The parameters to be passed to getResourceUsageReport() * @constructor * @returns {GetResourceUsageReportPager} */ function GetResourceUsageReportPager(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} */ GetResourceUsageReportPager.prototype.hasNext = function () { return this._hasNext; }; /** * Returns the next page of results by invoking getResourceUsageReport(). * @returns {Promise<PartnerManagementV1.PartnerUsageReport[]>} */ GetResourceUsageReportPager.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.getResourceUsageReport(this.params)]; case 1: response = _a.sent(); result = response.result; if (result && result.next) { next = result.next.offset; } this.pageContext.next = next; if (!this.pageContext.next) { this._hasNext = false; } return [2 /*return*/, result.reports]; } }); }); }; /** * Returns all results by invoking getResourceUsageReport() repeatedly until all pages of results have been retrieved. * @returns {Promise<PartnerManagementV1.PartnerUsageReport[]>} */ GetResourceUsageReportPager.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 GetResourceUsageReportPager; }()); PartnerManagementV1.GetResourceUsageReportPager = GetResourceUsageReportPager; })(PartnerManagementV1 || (PartnerManagementV1 = {})); module.exports = PartnerManagementV1; //# sourceMappingURL=v1.js.map