UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

95 lines (92 loc) 3.28 kB
/** * @package @bitrix24/b24jssdk * @version 1.0.3 * @copyright (c) 2026 Bitrix24 * @license MIT * @see https://github.com/bitrix24/b24jssdk * @see https://bitrix24.github.io/b24jssdk/ */ import { AbstractHttp } from './abstract-http.mjs'; import { ApiVersion } from '../../types/b24.mjs'; import { AjaxError } from './ajax-error.mjs'; import { InteractionBatchV3 } from '../interaction/batch/v3.mjs'; import { ProcessingAsArrayV3 } from '../interaction/batch/processing/v3/as-array.mjs'; import { ProcessingAsObjectV3 } from '../interaction/batch/processing/v3/as-object.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); class HttpV3 extends AbstractHttp { static { __name(this, "HttpV3"); } constructor(authActions, options, restrictionParams) { super(authActions, options, restrictionParams); this._version = ApiVersion.v3; } // 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 InteractionBatchV3({ requestId, parallelDefaultValue: !opts.isHaltOnError, restrictionManager: this._restrictionManager }); if (Array.isArray(calls)) { interactionBatch.setProcessingStrategy(new ProcessingAsArrayV3()); } else { interactionBatch.setProcessingStrategy(new ProcessingAsObjectV3()); } interactionBatch.addCommands(calls); if (interactionBatch.size > interactionBatch.maxSize) { throw new 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({ 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", interactionBatch.getCommandsForCall(), requestId ); const response = await interactionBatch.prepareResponse(responseBatch); this._logBatchCompletion( requestId, response.getData()?.result?.size ?? 0, response.getErrorMessages().length ); return response; } // endregion //// // region Prepare //// /** * @inheritDoc */ _prepareMethod(requestId, method, baseUrl) { const methodUrl = `/${encodeURIComponent(method)}`; const queryParams = new URLSearchParams({ [this._requestIdGenerator.getQueryStringParameterName()]: requestId, [this._requestIdGenerator.getQueryStringSdkParameterName()]: "1.0.3", [this._requestIdGenerator.getQueryStringSdkTypeParameterName()]: "b24-js-sdk" }); return `${baseUrl}${methodUrl}?${queryParams.toString()}`; } // endregion //// } export { HttpV3 }; //# sourceMappingURL=v3.mjs.map