@bitrix24/b24jssdk
Version:
Bitrix24 REST API JavaScript SDK
116 lines (112 loc) • 4.17 kB
JavaScript
/**
* @package @bitrix24/b24jssdk
* @version 2.0.0
* @copyright (c) 2026 Bitrix24
* @license MIT
* @see https://github.com/bitrix24/b24jssdk
* @see https://bitrix24.github.io/b24jssdk/
*/
;
const interfaceStrategy = require('../interface-strategy.cjs');
const sdkError = require('../../../../sdk-error.cjs');
const ajaxResult = require('../../../../http/ajax-result.cjs');
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
class AbstractProcessingV3 extends interfaceStrategy.AbstractProcessing {
static {
__name(this, "AbstractProcessingV3");
}
buildCommands(commands) {
if (commands.length < 1) {
throw new sdkError.SdkError({
code: "JSSDK_INTERACTION_BATCH_BUILD_STRATEGY_V3_EMPTY_COMMANDS",
description: "commands not set",
status: 500
});
}
return commands;
}
// region prepareItems ////
// Soft-error guard lives in AbstractProcessing.prepareItems (#228); this is the
// success-only path for apiVer3 (all-or-nothing — no per-command errors).
async _prepareItemsSuccess(commands, responseHelper, results) {
for (const [index, command] of commands.entries()) {
await this._processResponseItem(
command,
// @memo for apiVer3 in this pace we get objectIndex from array `index` from `commands[]`
index,
responseHelper,
results
);
}
return results;
}
/**
* In `restApi:v3`, `response.getData().result` is the array/record of per-command
* results directly (no `result_error`/`result_time`/`result_total`/`result_next`
* split as in v2). Per-command errors do not exist in this format.
*
* The per-command `result` value is forwarded as-is, including `null` when the
* underlying REST method returns `null` (see issue #23).
*/
async _processResponseItem(command, index, responseHelper, results) {
const responseResult = responseHelper.response.getData().result;
const resultData = this._getBatchResultByIndex(responseResult, index);
if (typeof resultData === "undefined") {
throw new sdkError.SdkError({
code: "JSSDK_INTERACTION_BATCH_STRATEGY_V3_EMPTY_COMMAND_RESPONSE",
description: `There were difficulties parsing the response for batch { index: ${index}, method: ${command.method} }`,
status: 500
});
}
const resultTime = responseHelper.response.getData().time;
const result = new ajaxResult.AjaxResult({
answer: {
result: resultData,
error: void 0,
time: resultTime
},
query: {
method: command.method,
params: command.query || {},
requestId: responseHelper.requestId
},
status: responseHelper.response.getStatus()
});
results.set(index, result);
return;
}
// endregion ////
// region handleResults ////
// Soft-error guard lives in AbstractProcessing.handleResults (#228); this is the
// success-only path for apiVer3.
async _handleResultsSuccess(commands, results, responseHelper, result) {
const dataResult = /* @__PURE__ */ new Map();
for (const [index, data] of results) {
const rowIndex = Number.parseInt(`${index}`);
const command = commands[rowIndex];
if (typeof command === "undefined") {
throw new sdkError.SdkError({
code: "JSSDK_INTERACTION_BATCH_BUILD_STRATEGY_V3_EMPTY_COMMAND",
description: `command for index ${index} not set`,
status: 500
});
}
const commandIndex = command.as ?? index;
if (data.getStatus() !== 200 || !data.isSuccess) {
const ajaxError = this._createErrorFromAjaxResult(data);
this._processResponseError(result, ajaxError, `${commandIndex}`);
dataResult.set(commandIndex, data);
}
dataResult.set(commandIndex, data);
}
result.setData({
result: dataResult,
time: responseHelper.response.getData().time
});
return result;
}
// endregion ////
}
exports.AbstractProcessingV3 = AbstractProcessingV3;
//# sourceMappingURL=abstract-processing.cjs.map