UNPKG

@camunda8/sdk

Version:

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

562 lines 21.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, { explicitFromConstructor: Object.prototype.hasOwnProperty.call(options?.config ?? {}, 'CAMUNDA_AUTH_STRATEGY'), }); 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.beforeCallHook], hooks: { beforeError: [(0, lib_1.gotBeforeErrorHook)(config)], beforeRequest: config.middleware ?? [], }, })); debug('prefixUrl', `${prefixUrl}`); } async getHeaders() { const authorization = await this.oAuthProvider.getHeaders('CONSOLE'); const headers = { 'content-type': 'application/json', ...authorization, 'user-agent': this.userAgentString, accept: '*/*', }; return headers; } /** * * 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(); } /** * 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(); } /** * 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(); } /** * 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(); } /** * * 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(); } /** * * 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(); } /** * * 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(); } /** * * 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(); } /** * * 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(); } /** * * 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(); } /** * * 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(); } /** * * 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(); } /** * * 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(); } /** * * 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(); } /** * * 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(); } /** * * 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(); } /** * * Get the egress IP ranges for Camunda SaaS. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/GetMeta) for more details. * @throws {RESTError} */ async getIpRanges() { const headers = await this.getHeaders(); const rest = await this.rest; return rest('meta/ip-ranges', { headers, }).json(); } /** * * Update a cluster's name, description, or stage label. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/UpdateCluster) for more details. * @param clusterUuid - The cluster UUID * @param updateRequest - The fields to update * @throws {RESTError} */ async updateCluster(clusterUuid, updateRequest) { const headers = await this.getHeaders(); const rest = await this.rest; await rest.patch(`clusters/${clusterUuid}`, { body: JSON.stringify(updateRequest), headers, }); } /** * * Upgrade a cluster to the latest available generation. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/UpgradeCluster) for more details. * @param clusterUuid - The cluster UUID * @throws {RESTError} */ async upgradeCluster(clusterUuid) { const headers = await this.getHeaders(); const rest = await this.rest; return rest .put(`clusters/${clusterUuid}/upgrade`, { headers, }) .json(); } /** * * Resume a suspended cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/Wake) for more details. * @param clusterUuid - The cluster UUID * @throws {RESTError} */ async wakeCluster(clusterUuid) { const headers = await this.getHeaders(); const rest = await this.rest; await rest.put(`clusters/${clusterUuid}/wake`, { headers, }); } /** * * Update the IP allowlist for a cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/UpdateIpAllowlist) for more details. * @param clusterUuid - The cluster UUID * @param ipallowlist - Array of IP allowlist entries * @throws {RESTError} */ async updateIpAllowlist(clusterUuid, ipallowlist) { const headers = await this.getHeaders(); const rest = await this.rest; await rest.put(`clusters/${clusterUuid}/ipallowlist`, { body: JSON.stringify({ ipallowlist }), headers, }); } /** * * Update a connector secret value. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/UpdateSecret) for more details. * @param clusterUuid - The cluster UUID * @param secretName - The name of the secret to update * @param secretValue - The new secret value * @throws {RESTError} */ async updateSecret(clusterUuid, secretName, secretValue) { const headers = await this.getHeaders(); const rest = await this.rest; await rest.put(`clusters/${clusterUuid}/secrets/${secretName}`, { body: JSON.stringify({ secretValue }), headers, }); } /** * * Activate Secure Connectivity for a cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/ActivateSecureConnectivity) for more details. * @param clusterUuid - The cluster UUID * @param request - The allowed principals and regions * @throws {RESTError} */ async activateSecureConnectivity(clusterUuid, request) { const headers = await this.getHeaders(); const rest = await this.rest; await rest.post(`clusters/${clusterUuid}/secure-connectivity`, { body: JSON.stringify(request), headers, }); } /** * * Deactivate Secure Connectivity for a cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/DeactivateSecureConnectivity) for more details. * @param clusterUuid - The cluster UUID * @throws {RESTError} */ async deactivateSecureConnectivity(clusterUuid) { const headers = await this.getHeaders(); const rest = await this.rest; await rest.delete(`clusters/${clusterUuid}/secure-connectivity`, { headers, }); } /** * * Get the Secure Connectivity status for a cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/GetSecureConnectivityStatus) for more details. * @param clusterUuid - The cluster UUID * @throws {RESTError} */ async getSecureConnectivityStatus(clusterUuid) { const headers = await this.getHeaders(); const rest = await this.rest; return rest(`clusters/${clusterUuid}/secure-connectivity`, { headers, }).json(); } /** * * Activate External Monitoring (BYOM) for a cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/ActivateMonitoring) for more details. * @param clusterUuid - The cluster UUID * @throws {RESTError} */ async activateMonitoring(clusterUuid) { const headers = await this.getHeaders(); const rest = await this.rest; await rest.post(`clusters/${clusterUuid}/monitoring`, { headers, }); } /** * * Deactivate External Monitoring (BYOM) for a cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/DeactivateMonitoring) for more details. * @param clusterUuid - The cluster UUID * @throws {RESTError} */ async deactivateMonitoring(clusterUuid) { const headers = await this.getHeaders(); const rest = await this.rest; await rest.delete(`clusters/${clusterUuid}/monitoring`, { headers, }); } /** * * Get all External Monitoring clients for a cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/GetMonitoringClients) for more details. * @param clusterUuid - The cluster UUID * @throws {RESTError} */ async getMonitoringClients(clusterUuid) { const headers = await this.getHeaders(); const rest = await this.rest; return rest(`clusters/${clusterUuid}/monitoring/clients`, { headers, }).json(); } /** * * Create a new External Monitoring client for a cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/CreateMonitoringClient) for more details. * @param clusterUuid - The cluster UUID * @param username - The username for the monitoring client * @throws {RESTError} */ async createMonitoringClient(clusterUuid, username) { const headers = await this.getHeaders(); const rest = await this.rest; return rest .post(`clusters/${clusterUuid}/monitoring/clients`, { body: JSON.stringify({ username }), headers, }) .json(); } /** * * Rotate the password for an External Monitoring client. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/RotateMonitoringClientPassword) for more details. * @param clusterUuid - The cluster UUID * @param clientUuid - The monitoring client UUID * @throws {RESTError} */ async rotateMonitoringClientPassword(clusterUuid, clientUuid) { const headers = await this.getHeaders(); const rest = await this.rest; return rest .post(`clusters/${clusterUuid}/monitoring/clients/${clientUuid}/rotate`, { headers, }) .json(); } /** * * Delete an External Monitoring client. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/DeleteMonitoringClient) for more details. * @param clusterUuid - The cluster UUID * @param clientUuid - The monitoring client UUID * @throws {RESTError} */ async deleteMonitoringClient(clusterUuid, clientUuid) { const headers = await this.getHeaders(); const rest = await this.rest; await rest.delete(`clusters/${clusterUuid}/monitoring/clients/${clientUuid}`, { headers, }); } /** * * Get all backups for a cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/GetBackups) for more details. * @param clusterUuid - The cluster UUID * @throws {RESTError} */ async getBackups(clusterUuid) { const headers = await this.getHeaders(); const rest = await this.rest; return rest(`clusters/${clusterUuid}/backups`, { headers, }).json(); } /** * * Create a new backup for a cluster. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/CreateBackup) for more details. * @param clusterUuid - The cluster UUID * @throws {RESTError} */ async createBackup(clusterUuid) { const headers = await this.getHeaders(); const rest = await this.rest; return rest .post(`clusters/${clusterUuid}/backups`, { headers, }) .json(); } /** * * Delete a backup. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/DeleteBackup) for more details. * @param clusterUuid - The cluster UUID * @param backupId - The backup ID * @throws {RESTError} */ async deleteBackup(clusterUuid, backupId) { const headers = await this.getHeaders(); const rest = await this.rest; return rest .delete(`clusters/${clusterUuid}/backups/${backupId}`, { headers, }) .json(); } /** * * Fetch all activity/audit events as JSON. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/GetJson) for more details. * @throws {RESTError} */ async getActivityEvents() { const headers = await this.getHeaders(); const rest = await this.rest; return rest('activity/json', { headers, }).json(); } /** * * Fetch all activity/audit events as CSV. See [the API Documentation](https://console.cloud.camunda.io/customer-api/openapi/docs/#/default/GetCsv) for more details. * @throws {RESTError} */ async getActivityEventsCsv() { const headers = await this.getHeaders(); const rest = await this.rest; return rest('activity/csv', { headers, }).text(); } } exports.AdminApiClient = AdminApiClient; //# sourceMappingURL=AdminApiClient.js.map