@ibm-cloud/platform-services
Version:
Node.js client library for IBM Cloud Platform Services
996 lines • 56.7 kB
JavaScript
"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.89.1-ed9d96f4-20240417-193115
*/
/* 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 Enterprise Management API enables you to create and manage an enterprise, account groups, and accounts within the
* enterprise.
*
* API Version: 1.0
*/
var EnterpriseManagementV1 = /** @class */ (function (_super) {
__extends(EnterpriseManagementV1, _super);
/**
* Construct a EnterpriseManagementV1 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 {EnterpriseManagementV1}
*/
function EnterpriseManagementV1(options) {
var _this = this;
options = options || {};
_this = _super.call(this, options) || this;
if (options.serviceUrl) {
_this.setServiceUrl(options.serviceUrl);
}
else {
_this.setServiceUrl(EnterpriseManagementV1.DEFAULT_SERVICE_URL);
}
return _this;
}
/*************************
* Factory method
************************/
/**
* Constructs an instance of EnterpriseManagementV1 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 {EnterpriseManagementV1}
*/
EnterpriseManagementV1.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 EnterpriseManagementV1(options);
service.configureService(options.serviceName);
if (options.serviceUrl) {
service.setServiceUrl(options.serviceUrl);
}
return service;
};
/*************************
* enterpriseOperations
************************/
/**
* Create an enterprise.
*
* Create a new enterprise, which you can use to centrally manage multiple accounts. To create an enterprise, you must
* have an active Subscription account. <br/><br/>The API creates an enterprise entity, which is the root of the
* enterprise hierarchy. It also creates a new enterprise account that is used to manage the enterprise. All
* subscriptions, support entitlements, credits, and discounts from the source subscription account are migrated to
* the enterprise account, and the source account becomes a child account in the hierarchy. The user that you assign
* as the enterprise primary contact is also assigned as the owner of the enterprise account.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.sourceAccountId - The ID of the account that is used to create the enterprise.
* @param {string} params.name - The name of the enterprise. This field must have 3 - 60 characters.
* @param {string} params.primaryContactIamId - The IAM ID of the enterprise primary contact, such as `IBMid-0123ABC`.
* The IAM ID must already exist.
* @param {string} [params.domain] - A domain or subdomain for the enterprise, such as `example.com` or
* `my.example.com`.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.CreateEnterpriseResponse>>}
*/
EnterpriseManagementV1.prototype.createEnterprise = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['sourceAccountId', 'name', 'primaryContactIamId'];
var _validParams = ['sourceAccountId', 'name', 'primaryContactIamId', 'domain', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'source_account_id': _params.sourceAccountId,
'name': _params.name,
'primary_contact_iam_id': _params.primaryContactIamId,
'domain': _params.domain,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'createEnterprise');
var parameters = {
options: {
url: '/enterprises',
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);
};
/**
* List enterprises.
*
* Retrieve all enterprises for a given ID by passing the IDs on query parameters. If no ID is passed, the enterprises
* for which the calling identity is the primary contact are returned. You can use pagination parameters to filter the
* results. <br/><br/>This method ensures that only the enterprises that the user has access to are returned. Access
* can be controlled either through a policy on a specific enterprise, or account-level platform services access
* roles, such as Administrator, Editor, Operator, or Viewer. When you call the method with the
* `enterprise_account_id` or `account_id` query parameter, the account ID in the token is compared with that in the
* query parameter. If these account IDs match, authentication isn't performed and the enterprise information is
* returned. If the account IDs don't match, authentication is performed and only then is the enterprise information
* returned in the response.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {string} [params.enterpriseAccountId] - Get enterprises for a given enterprise account ID.
* @param {string} [params.accountGroupId] - Get enterprises for a given account group ID.
* @param {string} [params.accountId] - Get enterprises for a given account ID.
* @param {string} [params.nextDocid] - The first item to be returned in the page of results. This value can be
* obtained from the next_url property from the previous call of the operation. If not specified, then the first page
* of results is returned.
* @param {number} [params.limit] - Return results up to this limit. Valid values are between `0` and `100`.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.ListEnterprisesResponse>>}
*/
EnterpriseManagementV1.prototype.listEnterprises = function (params) {
var _params = __assign({}, params);
var _requiredParams = [];
var _validParams = [
'enterpriseAccountId',
'accountGroupId',
'accountId',
'nextDocid',
'limit',
'headers',
];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'enterprise_account_id': _params.enterpriseAccountId,
'account_group_id': _params.accountGroupId,
'account_id': _params.accountId,
'next_docid': _params.nextDocid,
'limit': _params.limit,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'listEnterprises');
var parameters = {
options: {
url: '/enterprises',
method: 'GET',
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Get enterprise by ID.
*
* Retrieve an enterprise by the `enterprise_id` parameter. All data related to the enterprise is returned only if the
* caller has access to retrieve the enterprise.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.enterpriseId - The ID of the enterprise to retrieve.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.Enterprise>>}
*/
EnterpriseManagementV1.prototype.getEnterprise = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['enterpriseId'];
var _validParams = ['enterpriseId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var path = {
'enterprise_id': _params.enterpriseId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'getEnterprise');
var parameters = {
options: {
url: '/enterprises/{enterprise_id}',
method: 'GET',
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Update an enterprise.
*
* Update the name, domain, or IAM ID of the primary contact for an existing enterprise. The new primary contact must
* already be a user in the enterprise account.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.enterpriseId - The ID of the enterprise to retrieve.
* @param {string} [params.name] - The new name of the enterprise. This field must have 3 - 60 characters.
* @param {string} [params.domain] - The new domain of the enterprise. This field has a limit of 60 characters.
* @param {string} [params.primaryContactIamId] - The IAM ID of the user to be the new primary contact for the
* enterprise.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.EmptyObject>>}
*/
EnterpriseManagementV1.prototype.updateEnterprise = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['enterpriseId'];
var _validParams = ['enterpriseId', 'name', 'domain', 'primaryContactIamId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'name': _params.name,
'domain': _params.domain,
'primary_contact_iam_id': _params.primaryContactIamId,
};
var path = {
'enterprise_id': _params.enterpriseId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'updateEnterprise');
var parameters = {
options: {
url: '/enterprises/{enterprise_id}',
method: 'PATCH',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* accountOperations
************************/
/**
* Import an account into an enterprise.
*
* Import an existing stand-alone account into an enterprise. The existing account can be any type: trial (`TRIAL`),
* Lite (`STANDARD`), Pay-As-You-Go (`PAYG`), or Subscription (`SUBSCRIPTION`). In the case of a `SUBSCRIPTION`
* account, the credits, promotional offers, and discounts are migrated to the billing unit of the enterprise. For a
* billable account (`PAYG` or `SUBSCRIPTION`), the country and currency code of the existing account and the billing
* unit of the enterprise must match. The API returns a `202` response and performs asynchronous operations to import
* the account into the enterprise. <br/></br>For more information about impacts to the account, see [Adding accounts
* to an enterprise](https://{DomainName}/docs/account?topic=account-enterprise-add).
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.enterpriseId - The ID of the enterprise to import the stand-alone account into.
* @param {string} params.accountId - The ID of the existing stand-alone account to be imported.
* @param {string} [params.parent] - The CRN of the expected parent of the imported account. The parent is the
* enterprise or account group that the account is added to.
* @param {string} [params.billingUnitId] - The ID of the [billing unit](/apidocs/enterprise-apis/billing-unit) to use
* for billing this account in the enterprise.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.EmptyObject>>}
*/
EnterpriseManagementV1.prototype.importAccountToEnterprise = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['enterpriseId', 'accountId'];
var _validParams = ['enterpriseId', 'accountId', 'parent', 'billingUnitId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'parent': _params.parent,
'billing_unit_id': _params.billingUnitId,
};
var path = {
'enterprise_id': _params.enterpriseId,
'account_id': _params.accountId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'importAccountToEnterprise');
var parameters = {
options: {
url: '/enterprises/{enterprise_id}/import/accounts/{account_id}',
method: 'PUT',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Create a new account in an enterprise.
*
* Create a new account as a part of an existing enterprise. The API creates an account entity under the parent that
* is specified in the payload of the request. The request also takes in the name and the owner of this new account.
* The owner must have a valid IBMid that's registered with IBM Cloud, but they don't need to be a user in the
* enterprise account.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.parent - The CRN of the parent under which the account will be created. The parent can be an
* existing account group or the enterprise itself.
* @param {string} params.name - The name of the account. This field must have 3 - 60 characters.
* @param {string} params.ownerIamId - The IAM ID of the account owner, such as `IBMid-0123ABC`. The IAM ID must
* already exist.
* @param {CreateAccountRequestTraits} [params.traits] - The traits object can be used to set properties on child
* accounts of an enterprise. You can pass a field to opt-out of the default multi-factor authentication setting or
* enable enterprise-managed IAM when creating a child account in the enterprise. This is an optional field.
* @param {CreateAccountRequestOptions} [params.options] - The options object can be used to set properties on child
* accounts of an enterprise. You can pass a field to to create IAM service id with IAM api key when creating a child
* account in the enterprise. This is an optional field.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.CreateAccountResponse>>}
*/
EnterpriseManagementV1.prototype.createAccount = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['parent', 'name', 'ownerIamId'];
var _validParams = ['parent', 'name', 'ownerIamId', 'traits', 'options', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'parent': _params.parent,
'name': _params.name,
'owner_iam_id': _params.ownerIamId,
'traits': _params.traits,
'options': _params.options,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'createAccount');
var parameters = {
options: {
url: '/accounts',
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);
};
/**
* List accounts.
*
* Retrieve all accounts based on the values that are passed in the query parameters. If no query parameter is passed,
* all of the accounts in the enterprise for which the calling identity has access are returned. <br/><br/>You can use
* pagination parameters to filter the results. The `limit` field can be used to limit the number of results that are
* displayed for this method.<br/><br/>This method ensures that only the accounts that the user has access to are
* returned. Access can be controlled either through a policy on a specific account, or account-level platform
* services access roles, such as Administrator, Editor, Operator, or Viewer. When you call the method with the
* `enterprise_id`, `account_group_id` or `parent` query parameter, all of the accounts that are immediate children of
* this entity are returned. Authentication is performed on all the accounts before they are returned to the user to
* ensure that only those accounts are returned to which the calling identity has access to.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {string} [params.enterpriseId] - Get accounts that are either immediate children or are a part of the
* hierarchy for a given enterprise ID.
* @param {string} [params.accountGroupId] - Get accounts that are either immediate children or are a part of the
* hierarchy for a given account group ID.
* @param {string} [params.nextDocid] - The first item to be returned in the page of results. This value can be
* obtained from the next_url property from the previous call of the operation. If not specified, then the first page
* of results is returned.
* @param {string} [params.parent] - Get accounts that are either immediate children or are a part of the hierarchy
* for a given parent CRN.
* @param {number} [params.limit] - Return results up to this limit. Valid values are between `0` and `100`.
* @param {boolean} [params.includeDeleted] - Include the deleted accounts from an enterprise when used in conjunction
* with enterprise_id.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.ListAccountsResponse>>}
*/
EnterpriseManagementV1.prototype.listAccounts = function (params) {
var _params = __assign({}, params);
var _requiredParams = [];
var _validParams = [
'enterpriseId',
'accountGroupId',
'nextDocid',
'parent',
'limit',
'includeDeleted',
'headers',
];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'enterprise_id': _params.enterpriseId,
'account_group_id': _params.accountGroupId,
'next_docid': _params.nextDocid,
'parent': _params.parent,
'limit': _params.limit,
'include_deleted': _params.includeDeleted,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'listAccounts');
var parameters = {
options: {
url: '/accounts',
method: 'GET',
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Get account by ID.
*
* Retrieve an account by the `account_id` parameter. All data related to the account is returned only if the caller
* has access to retrieve the account.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.accountId - The ID of the target account.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.Account>>}
*/
EnterpriseManagementV1.prototype.getAccount = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['accountId'];
var _validParams = ['accountId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var path = {
'account_id': _params.accountId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'getAccount');
var parameters = {
options: {
url: '/accounts/{account_id}',
method: 'GET',
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Move an account within the enterprise.
*
* Move an account to a different parent within the same enterprise.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.accountId - The ID of the target account.
* @param {string} params.parent - The CRN of the new parent within the enterprise.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.EmptyObject>>}
*/
EnterpriseManagementV1.prototype.updateAccount = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['accountId', 'parent'];
var _validParams = ['accountId', 'parent', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'parent': _params.parent,
};
var path = {
'account_id': _params.accountId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'updateAccount');
var parameters = {
options: {
url: '/accounts/{account_id}',
method: 'PATCH',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Remove an account from its enterprise.
*
* Remove an account from the enterprise its currently in. After an account is removed, it will be canceled and cannot
* be reactivated.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.accountId - The ID of the target account.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.EmptyObject>>}
*/
EnterpriseManagementV1.prototype.deleteAccount = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['accountId'];
var _validParams = ['accountId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var path = {
'account_id': _params.accountId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'deleteAccount');
var parameters = {
options: {
url: '/accounts/{account_id}',
method: 'DELETE',
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* accountGroupOperations
************************/
/**
* Create an account group.
*
* Create a new account group, which can be used to group together multiple accounts. To create an account group, you
* must have an existing enterprise. The API creates an account group entity under the parent that is specified in the
* payload of the request. The request also takes in the name and the primary contact of this new account group.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.parent - The CRN of the parent under which the account group will be created. The parent can
* be an existing account group or the enterprise itself.
* @param {string} params.name - The name of the account group. This field must have 3 - 60 characters.
* @param {string} params.primaryContactIamId - The IAM ID of the primary contact for this account group, such as
* `IBMid-0123ABC`. The IAM ID must already exist.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.CreateAccountGroupResponse>>}
*/
EnterpriseManagementV1.prototype.createAccountGroup = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['parent', 'name', 'primaryContactIamId'];
var _validParams = ['parent', 'name', 'primaryContactIamId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'parent': _params.parent,
'name': _params.name,
'primary_contact_iam_id': _params.primaryContactIamId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'createAccountGroup');
var parameters = {
options: {
url: '/account-groups',
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);
};
/**
* List account groups.
*
* Retrieve all account groups based on the values that are passed in the query parameters. If no query parameter is
* passed, all of the account groups in the enterprise for which the calling identity has access are returned.
* <br/><br/>You can use pagination parameters to filter the results. The `limit` field can be used to limit the
* number of results that are displayed for this method.<br/><br/>This method ensures that only the account groups
* that the user has access to are returned. Access can be controlled either through a policy on a specific account
* group, or account-level platform services access roles, such as Administrator, Editor, Operator, or Viewer. When
* you call the method with the `enterprise_id`, `parent_account_group_id` or `parent` query parameter, all of the
* account groups that are immediate children of this entity are returned. Authentication is performed on all account
* groups before they are returned to the user to ensure that only those account groups are returned to which the
* calling identity has access.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {string} [params.enterpriseId] - Get account groups that are either immediate children or are a part of the
* hierarchy for a given enterprise ID.
* @param {string} [params.parentAccountGroupId] - Get account groups that are either immediate children or are a part
* of the hierarchy for a given account group ID.
* @param {string} [params.nextDocid] - The first item to be returned in the page of results. This value can be
* obtained from the next_url property from the previous call of the operation. If not specified, then the first page
* of results is returned.
* @param {string} [params.parent] - Get account groups that are either immediate children or are a part of the
* hierarchy for a given parent CRN.
* @param {number} [params.limit] - Return results up to this limit. Valid values are between `0` and `100`.
* @param {boolean} [params.includeDeleted] - Include the deleted account groups from an enterprise when used in
* conjunction with other query parameters.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.ListAccountGroupsResponse>>}
*/
EnterpriseManagementV1.prototype.listAccountGroups = function (params) {
var _params = __assign({}, params);
var _requiredParams = [];
var _validParams = [
'enterpriseId',
'parentAccountGroupId',
'nextDocid',
'parent',
'limit',
'includeDeleted',
'headers',
];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'enterprise_id': _params.enterpriseId,
'parent_account_group_id': _params.parentAccountGroupId,
'next_docid': _params.nextDocid,
'parent': _params.parent,
'limit': _params.limit,
'include_deleted': _params.includeDeleted,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'listAccountGroups');
var parameters = {
options: {
url: '/account-groups',
method: 'GET',
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Get account group by ID.
*
* Retrieve an account by the `account_group_id` parameter. All data related to the account group is returned only if
* the caller has access to retrieve the account group.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.accountGroupId - The ID of the account group to retrieve.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.AccountGroup>>}
*/
EnterpriseManagementV1.prototype.getAccountGroup = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['accountGroupId'];
var _validParams = ['accountGroupId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var path = {
'account_group_id': _params.accountGroupId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'getAccountGroup');
var parameters = {
options: {
url: '/account-groups/{account_group_id}',
method: 'GET',
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Update an account group.
*
* Update the name or IAM ID of the primary contact for an existing account group. The new primary contact must
* already be a user in the enterprise account.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.accountGroupId - The ID of the account group to retrieve.
* @param {string} [params.name] - The new name of the account group. This field must have 3 - 60 characters.
* @param {string} [params.primaryContactIamId] - The IAM ID of the user to be the new primary contact for the account
* group.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.EmptyObject>>}
*/
EnterpriseManagementV1.prototype.updateAccountGroup = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['accountGroupId'];
var _validParams = ['accountGroupId', 'name', 'primaryContactIamId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'name': _params.name,
'primary_contact_iam_id': _params.primaryContactIamId,
};
var path = {
'account_group_id': _params.accountGroupId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'updateAccountGroup');
var parameters = {
options: {
url: '/account-groups/{account_group_id}',
method: 'PATCH',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Delete an account group from the enterprise.
*
* Delete an existing account group from the enterprise. You can't delete an account group that has child account
* groups, the delete request will fail. This API doesn't perform a recursive delete on the child account groups, it
* only deletes the current account group.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.accountGroupId - The ID of the account group to retrieve.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<EnterpriseManagementV1.Response<EnterpriseManagementV1.EmptyObject>>}
*/
EnterpriseManagementV1.prototype.deleteAccountGroup = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['accountGroupId'];
var _validParams = ['accountGroupId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var path = {
'account_group_id': _params.accountGroupId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(EnterpriseManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'deleteAccountGroup');
var parameters = {
options: {
url: '/account-groups/{account_group_id}',
method: 'DELETE',
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {}, _params.headers),
}),
};
return this.createRequest(parameters);
};
EnterpriseManagementV1.DEFAULT_SERVICE_URL = 'https://enterprise.cloud.ibm.com/v1';
EnterpriseManagementV1.DEFAULT_SERVICE_NAME = 'enterprise_management';
return EnterpriseManagementV1;
}(ibm_cloud_sdk_core_1.BaseService));
/*************************
* interfaces
************************/
(function (EnterpriseManagementV1) {
/*************************
* pager classes
************************/
/**
* EnterprisesPager can be used to simplify the use of listEnterprises().
*/
var EnterprisesPager = /** @class */ (function () {
/**
* Construct a EnterprisesPager object.
*
* @param {EnterpriseManagementV1} client - The service client instance used to invoke listEnterprises()
* @param {Object} [params] - The parameters to be passed to listEnterprises()
* @constructor
* @returns {EnterprisesPager}
*/
function EnterprisesPager(client, params) {
if (params && params.nextDocid) {
throw new Error("the params.nextDocid 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}
*/
EnterprisesPager.prototype.hasNext = function () {
return this._hasNext;
};
/**
* Returns the next page of results by invoking listEnterprises().
* @returns {Promise<EnterpriseManagementV1.Enterprise[]>}
*/
EnterprisesPager.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.nextDocid = this.pageContext.next;
}
return [4 /*yield*/, this.client.listEnterprises(this.params)];
case 1:
response = _a.sent();
result = response.result;
if (result && result.next_url) {
next = (0, ibm_cloud_sdk_core_1.getQueryParam)(result.next_url, 'next_docid');
}
this.pageContext.next = next;
if (!this.pageContext.next) {
this._hasNext = false;
}
return [2 /*return*/, result.resources];
}
});
});
};
/**
* Returns all results by invoking listEnterprises() repeatedly until all pages of results have been retrieved.
* @returns {Promise<EnterpriseManagementV1.Enterprise[]>}
*/
EnterprisesPager.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 EnterprisesPager;
}());
EnterpriseManagementV1.EnterprisesPager = EnterprisesPager;
/**
* AccountsPager can be used to simplify the use of listAccounts().
*/
var AccountsPager = /** @class */ (function () {
/**
* Construct a AccountsPager object.
*
* @param {EnterpriseManagementV1} client - The service client instance used to invoke listAccounts()
* @param {Object} [params] - The parameters to be passed to listAccounts()
* @constructor
* @returns {AccountsPager}
*/
function AccountsPager(client, params) {
if (params && params.nextDocid) {
throw new Error("the params.nextDocid 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}
*/
AccountsPager.prototype.hasNext = function () {
return this._hasNext;
};
/**
* Returns the next page of results by invoking listAccounts().
* @returns {Promise<EnterpriseManagementV1.Account[