Skip to content

Commit 2b773ab

Browse files
(feat Account Management) add new v4 api
Signed-off-by: David <David.Lim0305@ibm.com>
1 parent 0a4e31e commit 2b773ab

File tree

5 files changed

+573
-0
lines changed

5 files changed

+573
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ IBM Cloud services:
7070

7171
Service Name | Import Path
7272
--- | ---
73+
[Account Management](https://test.cloud.ibm.com/apidocs/account-management) | @ibm-cloud/platform-services/account-management/v4
7374
[Case Management](https://cloud.ibm.com/apidocs/case-management?code=node) | @ibm-cloud/platform-services/case-management/v1
7475
[Catalog Management](https://cloud.ibm.com/apidocs/resource-catalog/private-catalog?code=node) | @ibm-cloud/platform-services/catalog-management/v1
7576
[Context Based Restrictions](https://cloud.ibm.com/apidocs/context-based-restrictions?code=node) | @ibm-cloud/platform-services/context-based-restrictions/v1

account-management/v4.ts

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
/**
2+
* (C) Copyright IBM Corp. 2026.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* IBM OpenAPI SDK Code Generator Version: 3.111.0-1bfb72c2-20260206-185521
19+
*/
20+
21+
import * as extend from 'extend';
22+
import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
23+
import {
24+
AbortSignal,
25+
Authenticator,
26+
BaseService,
27+
UserOptions,
28+
getAuthenticatorFromEnvironment,
29+
validateParams,
30+
} from 'ibm-cloud-sdk-core';
31+
import { getSdkHeaders } from '../lib/common';
32+
33+
/**
34+
* The Account Management API allows for the management of Account
35+
*
36+
* API Version: 4.0.0
37+
*/
38+
39+
class AccountManagementV4 extends BaseService {
40+
static DEFAULT_SERVICE_URL: string = 'https://accounts.test.cloud.ibm.com';
41+
42+
static DEFAULT_SERVICE_NAME: string = 'account_management';
43+
44+
/*************************
45+
* Factory method
46+
************************/
47+
48+
/**
49+
* Constructs an instance of AccountManagementV4 with passed in options and external configuration.
50+
*
51+
* @param {UserOptions} [options] - The parameters to send to the service.
52+
* @param {string} [options.serviceName] - The name of the service to configure
53+
* @param {Authenticator} [options.authenticator] - The Authenticator object used to authenticate requests to the service
54+
* @param {string} [options.serviceUrl] - The base URL for the service
55+
* @returns {AccountManagementV4}
56+
*/
57+
58+
public static newInstance(options: UserOptions): AccountManagementV4 {
59+
options = options || {};
60+
61+
if (!options.serviceName) {
62+
options.serviceName = this.DEFAULT_SERVICE_NAME;
63+
}
64+
if (!options.authenticator) {
65+
options.authenticator = getAuthenticatorFromEnvironment(options.serviceName);
66+
}
67+
const service = new AccountManagementV4(options);
68+
service.configureService(options.serviceName);
69+
if (options.serviceUrl) {
70+
service.setServiceUrl(options.serviceUrl);
71+
}
72+
return service;
73+
}
74+
75+
/**
76+
* Construct a AccountManagementV4 object.
77+
*
78+
* @param {Object} options - Options for the service.
79+
* @param {string} [options.serviceUrl] - The base URL for the service
80+
* @param {OutgoingHttpHeaders} [options.headers] - Default headers that shall be included with every request to the service.
81+
* @param {Authenticator} options.authenticator - The Authenticator object used to authenticate requests to the service
82+
* @constructor
83+
* @returns {AccountManagementV4}
84+
*/
85+
constructor(options: UserOptions) {
86+
options = options || {};
87+
88+
super(options);
89+
if (options.serviceUrl) {
90+
this.setServiceUrl(options.serviceUrl);
91+
} else {
92+
this.setServiceUrl(AccountManagementV4.DEFAULT_SERVICE_URL);
93+
}
94+
}
95+
96+
/*************************
97+
* default
98+
************************/
99+
100+
/**
101+
* Get Account by Account ID.
102+
*
103+
* Returns the details of an account.
104+
*
105+
* @param {Object} params - The parameters to send to the service.
106+
* @param {string} params.accountId - The unique identifier of the account you want to retrieve.
107+
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
108+
* @returns {Promise<AccountManagementV4.Response<AccountManagementV4.AccountResponse>>}
109+
*/
110+
public getAccount(
111+
params: AccountManagementV4.GetAccountParams
112+
): Promise<AccountManagementV4.Response<AccountManagementV4.AccountResponse>> {
113+
const _params = { ...params };
114+
const _requiredParams = ['accountId'];
115+
const _validParams = ['accountId', 'signal', 'headers'];
116+
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
117+
if (_validationErrors) {
118+
return Promise.reject(_validationErrors);
119+
}
120+
121+
const path = {
122+
'account_id': _params.accountId,
123+
};
124+
125+
const sdkHeaders = getSdkHeaders(AccountManagementV4.DEFAULT_SERVICE_NAME, 'v4', 'getAccount');
126+
127+
const parameters = {
128+
options: {
129+
url: '/v4/accounts/{account_id}',
130+
method: 'GET',
131+
path,
132+
},
133+
defaultOptions: extend(true, {}, this.baseOptions, {
134+
headers: extend(
135+
true,
136+
sdkHeaders,
137+
this.baseOptions.headers,
138+
{
139+
'Accept': 'application/json',
140+
},
141+
_params.headers
142+
),
143+
axiosOptions: {
144+
signal: _params.signal,
145+
},
146+
}),
147+
};
148+
149+
return this.createRequest(parameters);
150+
}
151+
}
152+
153+
/*************************
154+
* interfaces
155+
************************/
156+
157+
namespace AccountManagementV4 {
158+
/** An operation response. */
159+
export interface Response<T = any> {
160+
result: T;
161+
status: number;
162+
statusText: string;
163+
headers: IncomingHttpHeaders;
164+
}
165+
166+
/** The callback for a service request. */
167+
export type Callback<T> = (error: any, response?: Response<T>) => void;
168+
169+
/** The body of a service request that returns no response data. */
170+
export interface EmptyObject {}
171+
172+
/** A standard JS object, defined to avoid the limitations of `Object` and `object` */
173+
export interface JsonObject {
174+
[key: string]: any;
175+
}
176+
177+
/*************************
178+
* request interfaces
179+
************************/
180+
181+
interface DefaultParams {
182+
headers?: OutgoingHttpHeaders;
183+
signal?: AbortSignal;
184+
}
185+
186+
/** Parameters for the `getAccount` operation. */
187+
export interface GetAccountParams extends DefaultParams {
188+
/** The unique identifier of the account you want to retrieve. */
189+
accountId: string;
190+
}
191+
192+
/*************************
193+
* model interfaces
194+
************************/
195+
196+
/**
197+
* AccountResponseTraits.
198+
*/
199+
export interface AccountResponseTraits {
200+
eu_supported: boolean;
201+
poc: boolean;
202+
hippa: boolean;
203+
}
204+
205+
/**
206+
* AccountResponse.
207+
*/
208+
export interface AccountResponse {
209+
name: string;
210+
id: string;
211+
owner: string;
212+
owner_userid: string;
213+
owner_iamid: string;
214+
type: string;
215+
status: string;
216+
linked_softlayer_account: string;
217+
team_directory_enabled: boolean;
218+
traits: AccountResponseTraits;
219+
}
220+
}
221+
222+
export = AccountManagementV4;
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* @jest-environment node
3+
*/
4+
/**
5+
* (C) Copyright IBM Corp. 2026.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
/* eslint-disable no-console */
21+
22+
const AccountManagementV4 = require('../dist/account-management/v4');
23+
// eslint-disable-next-line node/no-unpublished-require
24+
const authHelper = require('../test/resources/auth-helper.js');
25+
// You can use the readExternalSources method to access additional configuration values
26+
// const { readExternalSources } = require('ibm-cloud-sdk-core');
27+
28+
//
29+
// This file provides an example of how to use the account_management service.
30+
//
31+
// The following configuration properties are assumed to be defined:
32+
// ACCOUNT_MANAGEMENT_URL=<service base url>
33+
// ACCOUNT_MANAGEMENT_AUTH_TYPE=iam
34+
// ACCOUNT_MANAGEMENT_APIKEY=<IAM apikey>
35+
// ACCOUNT_MANAGEMENT_AUTH_URL=<IAM token service base URL - omit this if using the production environment>
36+
//
37+
// These configuration properties can be exported as environment variables, or stored
38+
// in a configuration file and then:
39+
// export IBM_CREDENTIALS_FILE=<name of configuration file>
40+
//
41+
const configFile = 'account_management_v4.env';
42+
43+
const describe = authHelper.prepareTests(configFile);
44+
45+
// Save original console.log
46+
const originalLog = console.log;
47+
const originalWarn = console.warn;
48+
49+
// Mocks for console.log and console.warn
50+
const consoleLogMock = jest.spyOn(console, 'log');
51+
const consoleWarnMock = jest.spyOn(console, 'warn');
52+
53+
describe('AccountManagementV4', () => {
54+
// Service instance
55+
let accountManagementService;
56+
57+
// To access additional configuration values, uncomment this line and extract the values from config
58+
// const config = readExternalSources(AccountManagementV4.DEFAULT_SERVICE_NAME);
59+
60+
test('Initialize service', async () => {
61+
// begin-common
62+
63+
accountManagementService = AccountManagementV4.newInstance();
64+
65+
// end-common
66+
});
67+
68+
test('getAccount request example', async () => {
69+
consoleLogMock.mockImplementation((output) => {
70+
originalLog(output);
71+
});
72+
consoleWarnMock.mockImplementation((output) => {
73+
// if an error occurs, display the message and then fail the test
74+
originalWarn(output);
75+
expect(true).toBeFalsy();
76+
});
77+
78+
originalLog('getAccount() result:');
79+
// begin-getAccount
80+
81+
const params = {
82+
accountId: 'testString',
83+
};
84+
85+
let res;
86+
try {
87+
res = await accountManagementService.getAccount(params);
88+
console.log(JSON.stringify(res.result, null, 2));
89+
} catch (err) {
90+
console.warn(err);
91+
}
92+
93+
// end-getAccount
94+
});
95+
});
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* (C) Copyright IBM Corp. 2026.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/* eslint-disable no-console */
18+
19+
const { readExternalSources } = require('ibm-cloud-sdk-core');
20+
const AccountManagementV4 = require('../../dist/account-management/v4');
21+
const authHelper = require('../resources/auth-helper.js');
22+
23+
// testcase timeout value (200s).
24+
const timeout = 200000;
25+
26+
// Location of our config file.
27+
const configFile = 'account_management_v4.env';
28+
29+
const describe = authHelper.prepareTests(configFile);
30+
31+
describe('AccountManagementV4_integration', () => {
32+
jest.setTimeout(timeout);
33+
34+
// global values used in various test cases
35+
let accountId;
36+
let accountManagementService;
37+
38+
test('Initialize service', async () => {
39+
accountManagementService = AccountManagementV4.newInstance();
40+
41+
expect(accountManagementService).not.toBeNull();
42+
43+
const config = readExternalSources(AccountManagementV4.DEFAULT_SERVICE_NAME);
44+
expect(config).not.toBeNull();
45+
accountId = config.accountId;
46+
expect(accountId).not.toBeNull();
47+
accountManagementService.enableRetries();
48+
});
49+
50+
test('getAccount()', async () => {
51+
const params = {
52+
accountId,
53+
};
54+
55+
const res = await accountManagementService.getAccount(params);
56+
expect(res).toBeDefined();
57+
expect(res.status).toBe(200);
58+
expect(res.result).toBeDefined();
59+
});
60+
});

0 commit comments

Comments
 (0)