UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

86 lines (82 loc) 2.85 kB
/** * @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/ */ 'use strict'; const abstractHttp = require('./abstract-http.cjs'); const b24 = require('../../types/b24.cjs'); const v2 = require('../interaction/batch/v2.cjs'); const asArray = require('../interaction/batch/processing/v2/as-array.cjs'); const asObject = require('../interaction/batch/processing/v2/as-object.cjs'); const ajaxError = require('./ajax-error.cjs'); var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); class HttpV2 extends abstractHttp.AbstractHttp { static { __name(this, "HttpV2"); } constructor(authActions, options, restrictionParams) { super(authActions, options, restrictionParams); this._version = b24.ApiVersion.v2; } // region batch //// async batch(calls, options) { const opts = { isHaltOnError: true, ...options }; const requestId = opts.requestId ?? this._requestIdGenerator.getRequestId(); this._logBatchStart(requestId, calls, opts); const interactionBatch = new v2.InteractionBatchV2({ requestId, parallelDefaultValue: !opts.isHaltOnError, restrictionManager: this._restrictionManager }); if (Array.isArray(calls)) { interactionBatch.setProcessingStrategy(new asArray.ProcessingAsArrayV2()); } else { interactionBatch.setProcessingStrategy(new asObject.ProcessingAsObjectV2()); } interactionBatch.addCommands(calls); if (interactionBatch.size > interactionBatch.maxSize) { throw new ajaxError.AjaxError({ code: "JSSDK_BATCH_TOO_LARGE", description: `Batch too large: ${interactionBatch.size} commands (max: ${interactionBatch.maxSize})`, status: 400, requestInfo: { method: "batch", params: { cmd: calls }, requestId }, originalError: null }); } if (interactionBatch.size === 0) { throw new ajaxError.AjaxError({ code: "JSSDK_BATCH_EMPTY", description: "Batch must contain at least one command", status: 400, requestInfo: { method: "batch", params: { cmd: calls }, requestId }, originalError: null }); } const responseBatch = await this.call( "batch", { halt: opts.isHaltOnError ? 1 : 0, cmd: interactionBatch.getCommandsForCall() }, requestId ); const response = await interactionBatch.prepareResponse(responseBatch); this._logBatchCompletion( requestId, response.getData()?.result?.size ?? 0, response.getErrorMessages().length ); return response; } // endregion //// } exports.HttpV2 = HttpV2; //# sourceMappingURL=v2.cjs.map