UNPKG

@camunda8/sdk

Version:

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

51 lines 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stringifyVariables = exports.parseVariablesAndCustomHeadersToJSON = exports.parseVariables = void 0; const lib_1 = require("../../lib"); function parseVariables(input) { return Object.assign({}, input, { variables: (0, lib_1.losslessParse)(input.variables || '{}'), }); } exports.parseVariables = parseVariables; /** * Parse an incoming job and convert its variables and custom headers to JSON. */ function parseVariablesAndCustomHeadersToJSON(response, /* eslint-disable @typescript-eslint/no-explicit-any */ inputVariableDto, customHeadersDto) { return new Promise((resolve, reject) => { try { resolve(Object.assign({}, response, { customHeaders: (0, lib_1.losslessParse)(response.customHeaders, customHeadersDto), variables: (0, lib_1.losslessParse)(response.variables, inputVariableDto), })); } catch (e) { console.error(`Error parsing variables ${e}`); console.error('Job', response); reject(e); } }); } exports.parseVariablesAndCustomHeadersToJSON = parseVariablesAndCustomHeadersToJSON; /** * Turn the `variables` field of a request from a JS object to a JSON string * This should be a key:value object where the keys will be variable names in Zeebe and the values are the corresponding values. * This function is used when sending a job back to Zeebe. */ function stringifyVariables(request) { const variables = request.variables || {}; /** * This is a run-time guard. The type system disallows passing an array, but type erasure and dynamic programming can override that. * If you pass an array as the variables to a CompleteJob RPC call, it will report success, but fail on the broker, stalling the process. * See: https://github.com/camunda/camunda-8-js-sdk/issues/247 */ if (Array.isArray(variables)) { throw new Error('Unable to parse Array into variables'); } const variablesString = (0, lib_1.losslessStringify)(variables); return Object.assign({}, request, { variables: variablesString }); } exports.stringifyVariables = stringifyVariables; //# sourceMappingURL=stringifyVariables.js.map