UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

1 lines 2.91 kB
{"version":3,"file":"call.cjs","sources":["../../../../../src/core/actions/v3/call.ts"],"sourcesContent":["import type { TypeCallParamsV3 } from '../../../types/http'\nimport type { AjaxResult } from '../../http/ajax-result'\nimport { AbstractAction } from '../abstract-action'\nimport { ApiVersion } from '../../../types/b24'\n\nexport type ActionCallV3 = {\n method: string\n params?: TypeCallParamsV3\n requestId?: string\n}\n\n/**\n * Calls the Bitrix24 REST API method `restApi:v3`\n *\n * Executes a single REST API request against the v3 HTTP client and returns the raw response.\n * Unlike its v2 counterpart `CallV2`, it routes through the v3 endpoint without a client-side\n * method allowlist — the server validates the method and returns `METHODNOTFOUNDEXCEPTION` for\n * unknown ones. Like `CallV2`, it makes exactly one HTTP call with no pagination or batching.\n */\nexport class CallV3 extends AbstractAction {\n /**\n * Calls the Bitrix24 REST API method.\n *\n * @template T - The expected data type in the response (default is `unknown`).\n *\n * @param {ActionCallV3} options - parameters for executing the request.\n * - `method: string` - REST API method name (eg: `crm.item.get`)\n * - `params?: TypeCallParamsV3` - Parameters for calling the method.\n * - `requestId?: string` - Unique request identifier for tracking. Used for query deduplication and debugging.\n *\n * @returns {Promise<AjaxResult<T>>} A promise that resolves to the result of an REST API call.\n *\n * @example\n * interface TaskItem { id: number, title: string }\n * const response = await b24.actions.v3.call.make<{ item: TaskItem }>({\n * method: 'tasks.task.get',\n * params: { id: 123, select: ['id', 'title'] },\n * requestId: 'task-123'\n * })\n * if (!response.isSuccess) {\n * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`)\n * }\n * console.log(response.getData().result.item.title)\n */\n public override async make<T = unknown>(options: ActionCallV3): Promise<AjaxResult<T>> {\n // No client-side allowlist: the method is sent straight to the v3 endpoint\n // and the server decides (an unknown method returns METHODNOTFOUNDEXCEPTION).\n const params = options.params || {}\n return this._b24.getHttpClient(ApiVersion.v3).call<T>(options.method, params, options.requestId)\n }\n}\n"],"names":["AbstractAction","ApiVersion"],"mappings":";;;;;;;;;;;;;;;AAmBO,MAAM,eAAeA,6BAAA,CAAe;AAAA,EAnB3C;AAmB2C,IAAA,MAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBzC,MAAsB,KAAkB,OAAA,EAA+C;AAGrF,IAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,MAAA,IAAU,EAAC;AAClC,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,aAAA,CAAcC,cAAA,CAAW,EAAE,CAAA,CAAE,IAAA,CAAQ,OAAA,CAAQ,MAAA,EAAQ,MAAA,EAAQ,OAAA,CAAQ,SAAS,CAAA;AAAA,EACjG;AACF;;;;"}