@bitrix24/b24jssdk
Version:
Bitrix24 REST API JavaScript SDK
119 lines (116 loc) • 3.82 kB
JavaScript
/**
* @package @bitrix24/b24jssdk
* @version 1.0.5
* @copyright (c) 2026 Bitrix24
* @license MIT
* @see https://github.com/bitrix24/b24jssdk
* @see https://bitrix24.github.io/b24jssdk/
*/
import { AbstractProcessing } from '../interface-strategy.mjs';
import { SdkError } from '../../../../sdk-error.mjs';
import { AjaxResult } from '../../../../http/ajax-result.mjs';
import { Result } from '../../../../result.mjs';
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
class AbstractProcessingV3 extends AbstractProcessing {
static {
__name(this, "AbstractProcessingV3");
}
buildCommands(commands) {
if (commands.length < 1) {
throw new SdkError({
code: "JSSDK_INTERACTION_BATCH_BUILD_STRATEGY_V3_EMPTY_COMMANDS",
description: "commands not set",
status: 500
});
}
return commands;
}
// region prepareItems ////
async prepareItems(commands, responseHelper) {
const results = /* @__PURE__ */ new Map();
if (!responseHelper.response.isSuccess) {
return 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;
}
/**
* @todo ! api ver3 waite docs
*/
async _processResponseItem(command, index, responseHelper, results) {
const responseResult = responseHelper.response.getData().result;
const resultData = this._getBatchResultByIndex(responseResult, index);
const methodName = command.method;
const resultError = void 0;
const resultTime = responseHelper.response.getData().time;
if (typeof resultTime !== "undefined") {
await responseHelper.restrictionManager.updateStats(responseHelper.requestId, `batch::${methodName}`, resultTime);
}
const result = new AjaxResult({
answer: {
result: resultData ?? {},
error: resultError,
time: resultTime
},
query: {
method: command.method,
params: command.query || {},
requestId: responseHelper.requestId
},
status: responseHelper.response.getStatus()
});
results.set(index, result);
return;
}
// endregion ////
// region handleResults ////
async handleResults(commands, results, responseHelper) {
const result = new Result();
const dataResult = /* @__PURE__ */ new Map();
if (!responseHelper.response.isSuccess) {
for (const [index, error] of responseHelper.response.errors) {
result.addError(error, index);
}
result.setData({
result: dataResult,
time: void 0
});
return result;
}
for (const [index, data] of results) {
const rowIndex = Number.parseInt(`${index}`);
const command = commands[rowIndex];
if (typeof command === "undefined") {
throw new 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 ////
}
export { AbstractProcessingV3 };
//# sourceMappingURL=abstract-processing.mjs.map