UNPKG

@ibm-cloud/platform-services

Version:

Node.js client library for IBM Cloud Platform Services

729 lines 35.6 kB
"use strict"; /** * (C) Copyright IBM Corp. 2023. * * 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.70.0-7df966bf-20230419-195904 */ /* 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"); /** * Manage the lifecycle of your users using User Management APIs. * * API Version: 1.0 */ var UserManagementV1 = /** @class */ (function (_super) { __extends(UserManagementV1, _super); /** * Construct a UserManagementV1 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 {UserManagementV1} */ function UserManagementV1(options) { var _this = this; options = options || {}; _this = _super.call(this, options) || this; if (options.serviceUrl) { _this.setServiceUrl(options.serviceUrl); } else { _this.setServiceUrl(UserManagementV1.DEFAULT_SERVICE_URL); } return _this; } /************************* * Factory method ************************/ /** * Constructs an instance of UserManagementV1 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 {UserManagementV1} */ UserManagementV1.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 UserManagementV1(options); service.configureService(options.serviceName); if (options.serviceUrl) { service.setServiceUrl(options.serviceUrl); } return service; }; /************************* * users ************************/ /** * List users. * * Retrieve users in the account. You can use the IAM service token or a user token for authorization. To use this * method, the requesting user or service ID must have at least the viewer, editor, or administrator role on the User * Management service. If unrestricted view is enabled, the user can see all users in the same account without an IAM * role. If restricted view is enabled and user has the viewer, editor, or administrator role on the user management * service, the API returns all users in the account. If unrestricted view is enabled and the user does not have these * roles, the API returns only the current user. Users are returned in a paginated list with a default limit of 100 * users. You can iterate through all users by following the `next_url` field. Additional substring search fields are * supported to filter the users. * * @param {Object} params - The parameters to send to the service. * @param {string} params.accountId - The account ID of the specified user. * @param {number} [params.limit] - The number of results to be returned. * @param {boolean} [params.includeSettings] - The user settings to be returned. Set to true to view language, allowed * IP address, and authentication settings. * @param {string} [params.search] - The desired search results to be returned. To view the list of users with the * additional search filter, use the following query options: `firstname`, `lastname`, `email`, `state`, `substate`, * `iam_id`, `realm`, and `userId`. HTML URL encoding for the search query and `:` must be used. For example, * search=state%3AINVALID returns a list of invalid users. Multiple search queries can be combined to obtain `OR` * results using `,` operator (not URL encoded). For example, search=state%3AINVALID,email%3Amail.test.ibm.com. * @param {string} [params.start] - An optional token that indicates the beginning of the page of results to be * returned. If omitted, the first page of results is returned. This value is obtained from the 'next_url' field of * the operation response. * @param {string} [params.userId] - Filter users based on their user ID. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise<UserManagementV1.Response<UserManagementV1.UserList>>} */ UserManagementV1.prototype.listUsers = function (params) { var _params = __assign({}, params); var _requiredParams = ['accountId']; var _validParams = [ 'accountId', 'limit', 'includeSettings', 'search', 'start', 'userId', 'headers', ]; var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams); if (_validationErrors) { return Promise.reject(_validationErrors); } var query = { 'limit': _params.limit, 'include_settings': _params.includeSettings, 'search': _params.search, '_start': _params.start, 'user_id': _params.userId, }; var path = { 'account_id': _params.accountId, }; var sdkHeaders = (0, common_1.getSdkHeaders)(UserManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'listUsers'); var parameters = { options: { url: '/v2/accounts/{account_id}/users', method: 'GET', qs: query, path: path, }, defaultOptions: extend(true, {}, this.baseOptions, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters); }; /** * Invite users to an account. * * Invite users to the account. You must use a user token for authorization. Service IDs can't invite users to the * account. To use this method, the requesting user must have the editor or administrator role on the User Management * service. For more information, see the [Inviting * users](https://cloud.ibm.com/docs/account?topic=account-iamuserinv) documentation. You can specify the user account * role and the corresponding IAM policy information in the request body. <br/><br/>When you invite a user to an * account, the user is initially created in the `PROCESSING` state. After the user is successfully created, all * specified permissions are configured, and the activation email is sent, the invited user is transitioned to the * `PENDING` state. When the invited user clicks the activation email and creates and confirms their IBM Cloud * account, the user is transitioned to `ACTIVE` state. If the user email is already verified, no email is generated. * * @param {Object} params - The parameters to send to the service. * @param {string} params.accountId - The account ID of the specified user. * @param {InviteUser[]} [params.users] - A list of users to be invited. * @param {InviteUserIamPolicy[]} [params.iamPolicy] - A list of IAM policies. * @param {string[]} [params.accessGroups] - A list of access groups. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise<UserManagementV1.Response<UserManagementV1.InvitedUserList>>} */ UserManagementV1.prototype.inviteUsers = function (params) { var _params = __assign({}, params); var _requiredParams = ['accountId']; var _validParams = ['accountId', 'users', 'iamPolicy', 'accessGroups', 'headers']; var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams); if (_validationErrors) { return Promise.reject(_validationErrors); } var body = { 'users': _params.users, 'iam_policy': _params.iamPolicy, 'access_groups': _params.accessGroups, }; var path = { 'account_id': _params.accountId, }; var sdkHeaders = (0, common_1.getSdkHeaders)(UserManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'inviteUsers'); var parameters = { options: { url: '/v2/accounts/{account_id}/users', method: 'POST', 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); }; /** * Get user profile. * * Retrieve a user's profile by the user's IAM ID in your account. You can use the IAM service token or a user token * for authorization. To use this method, the requesting user or service ID must have at least the viewer, editor, or * administrator role on the User Management service. * * @param {Object} params - The parameters to send to the service. * @param {string} params.accountId - The account ID of the specified user. * @param {string} params.iamId - The user's IAM ID. * @param {string} [params.includeActivity] - Include activity information of the user, such as the last * authentication timestamp. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise<UserManagementV1.Response<UserManagementV1.UserProfile>>} */ UserManagementV1.prototype.getUserProfile = function (params) { var _params = __assign({}, params); var _requiredParams = ['accountId', 'iamId']; var _validParams = ['accountId', 'iamId', 'includeActivity', 'headers']; var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams); if (_validationErrors) { return Promise.reject(_validationErrors); } var query = { 'include_activity': _params.includeActivity, }; var path = { 'account_id': _params.accountId, 'iam_id': _params.iamId, }; var sdkHeaders = (0, common_1.getSdkHeaders)(UserManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'getUserProfile'); var parameters = { options: { url: '/v2/accounts/{account_id}/users/{iam_id}', method: 'GET', qs: query, path: path, }, defaultOptions: extend(true, {}, this.baseOptions, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters); }; /** * Partially update user profile. * * Partially update a user's profile by user's IAM ID. You can use the IAM service token or a user token for * authorization. To use this method, the requesting user or service ID must have at least the editor or administrator * role on the User Management service. A user or service ID with these roles can change a user's state between * `ACTIVE`, `VPN_ONLY`, or `DISABLED_CLASSIC_INFRASTRUCTURE`, but they can't change the state to `PROCESSING` or * `PENDING` because these are system states. For other request body fields, a user can update their own profile * without having User Management service permissions. * * @param {Object} params - The parameters to send to the service. * @param {string} params.accountId - The account ID of the specified user. * @param {string} params.iamId - The user's IAM ID. * @param {string} [params.firstname] - The first name of the user. * @param {string} [params.lastname] - The last name of the user. * @param {string} [params.state] - The state of the user. Possible values are `PROCESSING`, `PENDING`, `ACTIVE`, * `DISABLED_CLASSIC_INFRASTRUCTURE`, and `VPN_ONLY`. * @param {string} [params.email] - The email address of the user. * @param {string} [params.phonenumber] - The phone number of the user. * @param {string} [params.altphonenumber] - The alternative phone number of the user. * @param {string} [params.photo] - A link to a photo of the user. * @param {string} [params.includeActivity] - Include activity information of the user, such as the last * authentication timestamp. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise<UserManagementV1.Response<UserManagementV1.EmptyObject>>} */ UserManagementV1.prototype.updateUserProfile = function (params) { var _params = __assign({}, params); var _requiredParams = ['accountId', 'iamId']; var _validParams = [ 'accountId', 'iamId', 'firstname', 'lastname', 'state', 'email', 'phonenumber', 'altphonenumber', 'photo', 'includeActivity', 'headers', ]; var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams); if (_validationErrors) { return Promise.reject(_validationErrors); } var body = { 'firstname': _params.firstname, 'lastname': _params.lastname, 'state': _params.state, 'email': _params.email, 'phonenumber': _params.phonenumber, 'altphonenumber': _params.altphonenumber, 'photo': _params.photo, }; var query = { 'include_activity': _params.includeActivity, }; var path = { 'account_id': _params.accountId, 'iam_id': _params.iamId, }; var sdkHeaders = (0, common_1.getSdkHeaders)(UserManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'updateUserProfile'); var parameters = { options: { url: '/v2/accounts/{account_id}/users/{iam_id}', method: 'PATCH', body: body, qs: query, path: path, }, defaultOptions: extend(true, {}, this.baseOptions, { headers: extend(true, sdkHeaders, { 'Content-Type': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters); }; /** * Remove user from account. * * Remove users from an account by user's IAM ID. You must use a user token for authorization. Service IDs can't * remove users from an account. To use this method, the requesting user must have the editor or administrator role on * the User Management service. For more information, see the [Removing * users](https://cloud.ibm.com/docs/account?topic=account-remove) documentation. * * @param {Object} params - The parameters to send to the service. * @param {string} params.accountId - The account ID of the specified user. * @param {string} params.iamId - The user's IAM ID. * @param {string} [params.includeActivity] - Include activity information of the user, such as the last * authentication timestamp. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise<UserManagementV1.Response<UserManagementV1.EmptyObject>>} */ UserManagementV1.prototype.removeUser = function (params) { var _params = __assign({}, params); var _requiredParams = ['accountId', 'iamId']; var _validParams = ['accountId', 'iamId', 'includeActivity', 'headers']; var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams); if (_validationErrors) { return Promise.reject(_validationErrors); } var query = { 'include_activity': _params.includeActivity, }; var path = { 'account_id': _params.accountId, 'iam_id': _params.iamId, }; var sdkHeaders = (0, common_1.getSdkHeaders)(UserManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'removeUser'); var parameters = { options: { url: '/v2/accounts/{account_id}/users/{iam_id}', method: 'DELETE', qs: query, path: path, }, defaultOptions: extend(true, {}, this.baseOptions, { headers: extend(true, sdkHeaders, {}, _params.headers), }), }; return this.createRequest(parameters); }; /** * Accept an invitation. * * Accept a user invitation to an account. You can use the user's token for authorization. To use this method, the * requesting user must provide the account ID for the account that they are accepting an invitation for. If the user * already accepted the invitation request, it returns 204 with no response body. * * @param {Object} [params] - The parameters to send to the service. * @param {string} [params.accountId] - The account ID. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise<UserManagementV1.Response<UserManagementV1.EmptyObject>>} */ UserManagementV1.prototype.accept = function (params) { var _params = __assign({}, params); var _requiredParams = []; var _validParams = ['accountId', 'headers']; var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams); if (_validationErrors) { return Promise.reject(_validationErrors); } var body = { 'account_id': _params.accountId, }; var sdkHeaders = (0, common_1.getSdkHeaders)(UserManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'accept'); var parameters = { options: { url: '/v2/users/accept', method: 'POST', body: body, }, defaultOptions: extend(true, {}, this.baseOptions, { headers: extend(true, sdkHeaders, { 'Content-Type': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters); }; /** * Remove user from account (Asynchronous). * * Remove users from an account by using the user's IAM ID. You must use a user token for authorization. Service IDs * can't remove users from an account. If removing the user fails it will set the user's state to * ERROR_WHILE_DELETING. To use this method, the requesting user must have the editor or administrator role on the * User Management service. For more information, see the [Removing * users](https://cloud.ibm.com/docs/account?topic=account-remove) documentation. * * @param {Object} params - The parameters to send to the service. * @param {string} params.accountId - The account ID of the specified user. * @param {string} params.iamId - The user's IAM ID. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise<UserManagementV1.Response<UserManagementV1.EmptyObject>>} */ UserManagementV1.prototype.v3RemoveUser = function (params) { var _params = __assign({}, params); var _requiredParams = ['accountId', 'iamId']; var _validParams = ['accountId', 'iamId', '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, 'iam_id': _params.iamId, }; var sdkHeaders = (0, common_1.getSdkHeaders)(UserManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'v3RemoveUser'); var parameters = { options: { url: '/v3/accounts/{account_id}/users/{iam_id}', method: 'DELETE', path: path, }, defaultOptions: extend(true, {}, this.baseOptions, { headers: extend(true, sdkHeaders, {}, _params.headers), }), }; return this.createRequest(parameters); }; /************************* * userSettings ************************/ /** * Get user settings. * * Retrieve a user's settings by the user's IAM ID. You can use the IAM service token or a user token for * authorization. To use this method, the requesting user or service ID must have the viewer, editor, or administrator * role on the User Management service. <br/><br/>The user settings have several fields. The `language` field is the * language setting for the user interface display language. The `notification_language` field is the language setting * for phone and email notifications. The `allowed_ip_addresses` field specifies a list of IP addresses that the user * can log in and perform operations from as described in [Allowing specific IP addresses for a * user](https://cloud.ibm.com/docs/account?topic=account-ips). For information about the `self_manage` field, review * information about the [user-managed login setting](https://cloud.ibm.com/docs/account?topic=account-types). * * @param {Object} params - The parameters to send to the service. * @param {string} params.accountId - The account ID of the specified user. * @param {string} params.iamId - The user's IAM ID. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise<UserManagementV1.Response<UserManagementV1.UserSettings>>} */ UserManagementV1.prototype.getUserSettings = function (params) { var _params = __assign({}, params); var _requiredParams = ['accountId', 'iamId']; var _validParams = ['accountId', 'iamId', '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, 'iam_id': _params.iamId, }; var sdkHeaders = (0, common_1.getSdkHeaders)(UserManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'getUserSettings'); var parameters = { options: { url: '/v2/accounts/{account_id}/users/{iam_id}/settings', method: 'GET', path: path, }, defaultOptions: extend(true, {}, this.baseOptions, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters); }; /** * Partially update user settings. * * Update a user's settings by the user's IAM ID. You can use the IAM service token or a user token for authorization. * To fully use this method, the user or service ID must have the editor or administrator role on the User Management * service. Without these roles, a user can update only their own `language` or `notification_language` fields. If * `self_manage` is `true`, the user can also update the `allowed_ip_addresses` field. * * @param {Object} params - The parameters to send to the service. * @param {string} params.accountId - The account ID of the specified user. * @param {string} params.iamId - The user's IAM ID. * @param {string} [params.language] - The console UI language. By default, this field is empty. * @param {string} [params.notificationLanguage] - The language for email and phone notifications. By default, this * field is empty. * @param {string} [params.allowedIpAddresses] - A comma-separated list of IP addresses. * @param {boolean} [params.selfManage] - Whether user managed login is enabled. The default value is `false`. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise<UserManagementV1.Response<UserManagementV1.EmptyObject>>} */ UserManagementV1.prototype.updateUserSettings = function (params) { var _params = __assign({}, params); var _requiredParams = ['accountId', 'iamId']; var _validParams = [ 'accountId', 'iamId', 'language', 'notificationLanguage', 'allowedIpAddresses', 'selfManage', 'headers', ]; var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams); if (_validationErrors) { return Promise.reject(_validationErrors); } var body = { 'language': _params.language, 'notification_language': _params.notificationLanguage, 'allowed_ip_addresses': _params.allowedIpAddresses, 'self_manage': _params.selfManage, }; var path = { 'account_id': _params.accountId, 'iam_id': _params.iamId, }; var sdkHeaders = (0, common_1.getSdkHeaders)(UserManagementV1.DEFAULT_SERVICE_NAME, 'v1', 'updateUserSettings'); var parameters = { options: { url: '/v2/accounts/{account_id}/users/{iam_id}/settings', 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); }; UserManagementV1.DEFAULT_SERVICE_URL = 'https://user-management.cloud.ibm.com'; UserManagementV1.DEFAULT_SERVICE_NAME = 'user_management'; return UserManagementV1; }(ibm_cloud_sdk_core_1.BaseService)); /************************* * interfaces ************************/ (function (UserManagementV1) { /************************* * pager classes ************************/ /** * UsersPager can be used to simplify the use of listUsers(). */ var UsersPager = /** @class */ (function () { /** * Construct a UsersPager object. * * @param {UserManagementV1} client - The service client instance used to invoke listUsers() * @param {Object} params - The parameters to be passed to listUsers() * @constructor * @returns {UsersPager} */ function UsersPager(client, params) { if (params && params.start) { throw new Error("the params.start 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} */ UsersPager.prototype.hasNext = function () { return this._hasNext; }; /** * Returns the next page of results by invoking listUsers(). * @returns {Promise<UserManagementV1.UserProfile[]>} */ UsersPager.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.start = this.pageContext.next; } return [4 /*yield*/, this.client.listUsers(this.params)]; case 1: response = _a.sent(); result = response.result; next = null; if (result && result.next_url) { next = (0, ibm_cloud_sdk_core_1.getQueryParam)(result.next_url, '_start'); } this.pageContext.next = next; if (!this.pageContext.next) { this._hasNext = false; } return [2 /*return*/, result.resources]; } }); }); }; /** * Returns all results by invoking listUsers() repeatedly until all pages of results have been retrieved. * @returns {Promise<UserManagementV1.UserProfile[]>} */ UsersPager.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 UsersPager; }()); UserManagementV1.UsersPager = UsersPager; })(UserManagementV1 || (UserManagementV1 = {})); module.exports = UserManagementV1; //# sourceMappingURL=v1.js.map