UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

106 lines (103 loc) • 3.95 kB
/** * @package @bitrix24/b24jssdk * @version 3.0.0 * @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 { InteractionBatchV2 } from '../interaction/batch/v2.mjs'; import { ProcessingAsArrayV2 } from '../interaction/batch/processing/v2/as-array.mjs'; import { ProcessingAsObjectV2 } from '../interaction/batch/processing/v2/as-object.mjs'; import { AjaxError } from './ajax-error.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); class HttpV2 extends AbstractHttp { static { __name(this, "HttpV2"); } constructor(authActions, options, restrictionParams) { super(authActions, options, restrictionParams); this._version = ApiVersion.v2; } /** * Drops `idempotencyKey` and warns instead of sending it. * * `Idempotency-Key` is honoured only under `/rest/api/` — the v3 endpoint. * The v2 endpoint ignores it, so sending it anyway would leave the caller * believing a retry is deduplicated when nothing on the portal side is * deduplicating it. Every other per-request option is passed through. (#462) */ _prepareRequestConfig(requestId, method, options) { if (void 0 === options?.idempotencyKey) { return super._prepareRequestConfig(requestId, method, options); } this.getLogger().warning( "http.call: `idempotencyKey` is ignored on `restApi:v2` \u2014 the portal honours `Idempotency-Key` only on the v3 endpoint (`/rest/api/`). Use `b24.actions.v3.call.make()` for an idempotent write, or an application-layer dedup guard if the method exists only on v2.", { requestId, method } ).catch(() => { }); const { idempotencyKey: _ignoredIdempotencyKey, ...restOptions } = options; return super._prepareRequestConfig(requestId, method, restOptions); } // 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 InteractionBatchV2({ requestId, parallelDefaultValue: !opts.isHaltOnError, restrictionManager: this._restrictionManager, logger: this.getLogger() }); if (Array.isArray(calls)) { interactionBatch.setProcessingStrategy(new ProcessingAsArrayV2()); } else { interactionBatch.setProcessingStrategy(new ProcessingAsObjectV2()); } 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 envelope = { halt: opts.isHaltOnError ? 1 : 0, cmd: interactionBatch.getCommandsForCall() }; const responseBatch = await this.call( "batch", envelope, requestId ); const response = await interactionBatch.prepareResponse(responseBatch); this._logBatchCompletion( requestId, response.getData()?.result?.size ?? 0, response.getErrorMessages().length ); return response; } // endregion //// } export { HttpV2 }; //# sourceMappingURL=v2.mjs.map