UNPKG

@camunda8/sdk

Version:

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

103 lines 4.23 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZeebeRestClient = void 0; const debug_1 = require("debug"); const got_1 = __importDefault(require("got")); const lib_1 = require("../../lib"); const trace = (0, debug_1.debug)('camunda:zeebe'); const ZEEBE_REST_API_VERSION = 'v1'; /** * @deprecated Since 8.6. Please use `C8RestClient` instead. */ class ZeebeRestClient { // private tenantId: string | undefined constructor(options) { const config = lib_1.CamundaEnvironmentConfigurator.mergeConfigWithEnvironment(options?.config ?? {}); trace('options.config', options?.config); trace('config', config); this.oAuthProvider = options?.oAuthProvider ?? (0, lib_1.constructOAuthProvider)(config); this.userAgentString = (0, lib_1.createUserAgentString)(config); const baseUrl = (0, lib_1.RequireConfiguration)(config.ZEEBE_REST_ADDRESS, 'ZEEBE_REST_ADDRESS'); const prefixUrl = `${baseUrl}/${ZEEBE_REST_API_VERSION}`; 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], }, })); // this.tenantId = config.CAMUNDA_TENANT_ID } async getHeaders() { const authorization = await this.oAuthProvider.getToken('ZEEBE'); const headers = { 'content-type': 'application/json', authorization, 'user-agent': this.userAgentString, accept: '*/*', }; trace('headers', headers); return headers; } /* Get the topology of the Zeebe cluster. */ async getTopology() { const headers = await this.getHeaders(); return this.rest.then((rest) => rest .get('topology', { headers }) .json() .catch((error) => { trace('error', error); throw error; })); } /* Completes a user task with the given key. The method either completes the task or throws 400, 404, or 409. Documentation: https://docs.camunda.io/docs/apis-tools/zeebe-api-rest/specifications/complete-a-user-task/ */ async completeUserTask({ userTaskKey, variables = {}, action = 'complete', }) { const headers = await this.getHeaders(); return this.rest.then((rest) => rest.post(`user-tasks/${userTaskKey}/completion`, { body: JSON.stringify({ variables, action, }), headers, })); } /* Assigns a user task with the given key to the given assignee. */ async assignTask({ userTaskKey, assignee, allowOverride = true, action = 'assign', }) { const headers = await this.getHeaders(); return this.rest.then((rest) => rest.post(`user-tasks/${userTaskKey}/assignment`, { body: JSON.stringify({ allowOverride, action, assignee, }), headers, })); } /** Update a user task with the given key. */ async updateTask({ userTaskKey, changeset, }) { const headers = await this.getHeaders(); return this.rest.then((rest) => rest.post(`user-tasks/${userTaskKey}/update`, { body: JSON.stringify(changeset), headers, })); } /* Removes the assignee of a task with the given key. */ async removeAssignee({ userTaskKey }) { const headers = await this.getHeaders(); return this.rest.then((rest) => rest.delete(`user-tasks/${userTaskKey}/assignee`, { headers })); } } exports.ZeebeRestClient = ZeebeRestClient; //# sourceMappingURL=ZeebeRESTClient.js.map