UNPKG

@camunda8/sdk

Version:

[![NPM](https://nodei.co/npm/@camunda8/sdk.png)](https://www.npmjs.com/package/@camunda8/sdk)

281 lines 10.1 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AdminApiClient = void 0; const debug_1 = __importDefault(require("debug")); const got_1 = __importDefault(require("got")); const lib_1 = require("../../lib"); const debug = (0, debug_1.default)('camunda:adminconsole'); /** * This class provides methods to interact with the Camunda Admin API. * @throws {RESTError} An error that may occur during API operations. */ class AdminApiClient { constructor(options) { const config = lib_1.CamundaEnvironmentConfigurator.mergeConfigWithEnvironment(options?.config ?? {}); const prefixUrl = (0, lib_1.RequireConfiguration)(config.CAMUNDA_CONSOLE_BASE_URL, 'CAMUNDA_CONSOLE_BASE_URL'); this.oAuthProvider = options?.oAuthProvider ?? (0, lib_1.constructOAuthProvider)(config); this.userAgentString = (0, lib_1.createUserAgentString)(config); this.rest = (0, lib_1.GetCustomCertificateBuffer)(config).then((certificateAuthority) => got_1.default.extend({ prefixUrl, retry: lib_1.GotRetryConfig, https: { certificateAuthority, }, handlers: [lib_1.gotErrorHandler], hooks: { beforeRetry: [ (0, lib_1.makeBeforeRetryHandlerFor401TokenRetry)(this.getHeaders.bind(this)), ], beforeError: [lib_1.gotBeforeErrorHook], beforeRequest: config.middleware ?? [], }, })); debug('prefixUrl', `${prefixUrl}`); } async getHeaders() { const token = await this.oAuthProvider.getToken('CONSOLE'); const headers = { 'content-type': 'application/json', authorization: token, 'user-agent': this.userAgentString, accept: '*/*', }; return headers; } /** * * @description Get an array of the current API clients for this cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/GetClients) for more details. * @throws {RESTError} * @param clusterUuid - The cluster UUID * */ async getClients(clusterUuid) { const headers = await this.getHeaders(); const rest = await this.rest; return rest(`clusters/${clusterUuid}/clients`, { headers, }).json(); } /** * @description Create a new API client for a cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/CreateClient) for more details. * @throws {RESTError} */ async createClient(req) { const headers = await this.getHeaders(); const rest = await this.rest; return rest .post(`clusters/${req.clusterUuid}/clients`, { body: JSON.stringify({ clientName: req.clientName, permissions: req.permissions, }), headers, }) .json(); } /** * @description Get the details of an API client. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/GetClient) for more details. * @param clusterUuid * @param clientId * @throws {RESTError} * @returns */ async getClient(clusterUuid, clientId) { const headers = await this.getHeaders(); const rest = await this.rest; return rest(`clusters/${clusterUuid}/clients/${clientId}`, { headers, }).json(); } /** * @description See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/DeleteClient) for more details. * @param clusterUuid * @param clientId * @throws {RESTError} */ async deleteClient(clusterUuid, clientId) { const headers = await this.getHeaders(); const rest = await this.rest; return rest .delete(`clusters/${clusterUuid}/clients/${clientId}`, { headers, }) .json(); } /** * * @description Return an array of clusters. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/GetClusters) for more details. * @throws {RESTError} */ async getClusters() { const headers = await this.getHeaders(); const rest = await this.rest; return rest('clusters', { headers, }).json(); } /** * * @description Create a new cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/CreateCluster) for more details. * @throws {RESTError} */ async createCluster(createClusterRequest) { const headers = await this.getHeaders(); const req = { body: JSON.stringify(createClusterRequest), headers, }; const rest = await this.rest; return rest.post('clusters', req).json(); } /** * * @description Retrieve the metadata for a cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/GetCluster) for more details. * @throws {RESTError} * */ async getCluster(clusterUuid) { const headers = await this.getHeaders(); const rest = await this.rest; return rest(`clusters/${clusterUuid}`, { headers, }).json(); } /** * * @description Delete a cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/DeleteCluster) for more details. * @throws {RESTError} * */ async deleteCluster(clusterUuid) { const headers = await this.getHeaders(); const rest = await this.rest; return rest .delete(`clusters/${clusterUuid}`, { headers, }) .json(); } /** * * @description Retrieve the available parameters for cluster creation. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/GetParameters) for more details. * @throws {RESTError} */ async getParameters() { const headers = await this.getHeaders(); const rest = await this.rest; return rest('clusters/parameters', { headers, }).json(); } /** * * @description Retrieve the connector secrets. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/GetSecrets) for more details. * @throws {RESTError} */ async getSecrets(clusterUuid) { const headers = await this.getHeaders(); const rest = await this.rest; return rest(`clusters/${clusterUuid}/secrets`, { headers, }).json(); } /** * * @description Create a new connector secret. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/CreateSecret) for more details. * @throws {RESTError} */ async createSecret({ clusterUuid, secretName, secretValue, }) { const headers = await this.getHeaders(); const req = { body: JSON.stringify({ secretName, secretValue }), headers, }; const rest = await this.rest; return rest.post(`clusters/${clusterUuid}/secrets`, req).json(); } /** * * @description Delete a connector secret. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/DeleteSecret) for more details. * @throws {RESTError} */ async deleteSecret(clusterUuid, secretName) { const headers = await this.getHeaders(); const rest = await this.rest; return rest .delete(`clusters/${clusterUuid}/secrets/${secretName}`, { headers, }) .json(); } /** * * @description Add one or more IPs to the whitelist for the cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/UpdateIpWhitelist) for more details. * @throws {RESTError} * @param ipwhitelist * @returns */ async whitelistIPs(clusterUuid, ipwhitelist) { const headers = await this.getHeaders(); const rest = await this.rest; return rest .put(`clusters/${clusterUuid}/ipwhitelist`, { body: JSON.stringify({ ipwhitelist, }), headers, }) .json(); } /** * * @description Retrieve a list of members and pending invites for your organisation. See the [API Documentation]() for more details. * @throws {RESTError} */ async getUsers() { const headers = await this.getHeaders(); const rest = await this.rest; return rest .get('members', { headers, }) .json(); } /** * * @description Add a member. See the [API Documentation]() for more details. * @throws {RESTError} * */ async createMember(email, orgRoles) { const headers = await this.getHeaders(); const rest = await this.rest; return rest .post(`members/${email}`, { headers, body: JSON.stringify({ orgRoles }), }) .json(); } /** * * @description Delete a member from your organization. See the [API Documentation]() for more details. * @throws {RESTError} * */ async deleteMember(email) { const headers = await this.getHeaders(); const rest = await this.rest; return rest .delete(`members/${email}`, { headers, }) .json(); } } exports.AdminApiClient = AdminApiClient; //# sourceMappingURL=AdminApiClient.js.map