UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

1 lines • 5.05 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 * `Idempotency-Key` for this call — an arbitrary string naming one business\n * operation, so that a repeat of it does not create a second entity.\n *\n * Opt-in: the SDK never generates one, because the dedup scope is\n * webhook/application x user x method and only the caller knows which\n * operation a call belongs to. Pass the *same* key on a retry of the *same*\n * operation, and read {@link AjaxResult.isIdempotentReplay} to tell a replay\n * from a fresh write.\n *\n * @see https://apidocs.bitrix24.ru/api-reference/rest-v3.html — section\n * «Повторный вызов без дублей»\n */\n idempotencyKey?: 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: `tasks.task.get`)\n * - `params?: TypeCallParamsV3` - Parameters for calling the method.\n * - `requestId?: string` - Unique request identifier for tracking and debugging — sent as the `bx24_request_id` query parameter. It does not deduplicate anything; for that see `idempotencyKey` (restApi:v3).\n * - `idempotencyKey?: string` - `Idempotency-Key` header; a repeat with the same key and body\n * replays the stored response instead of writing again.\n * Server-side only: in a browser it throws `JSSDK_HTTP_IDEMPOTENCY_KEY_BROWSER` (#573).\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 * @example\n * declare const orderId: number\n * // A write that is safe to retry: the same key means the same operation.\n * // Derive the key from your own identifiers rather than minting one at the\n * // call site — a `crypto.randomUUID()` here would be a fresh key on every\n * // attempt, so a retry from another process would still write a duplicate.\n * const created = await b24.actions.v3.call.make<{ item: { id: number } }>({\n * method: 'tasks.task.add',\n * params: { fields: { title: 'Ship it', creatorId: 1, responsibleId: 1 } },\n * idempotencyKey: `ship-task-for-order-${orderId}`\n * })\n * // Sending the very same call again returns the very same task,\n * // and `created.isIdempotentReplay()` is `true` on that second response.\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>(\n options.method,\n params,\n options.requestId,\n undefined === options.idempotencyKey ? undefined : { idempotencyKey: options.idempotencyKey }\n )\n }\n}\n"],"names":["AbstractAction","ApiVersion"],"mappings":";;;;;;;;;;;;;;;AAiCO,MAAM,eAAeA,6BAAA,CAAe;AAAA,EAjC3C;AAiC2C,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0CzC,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;AAAA,MAC5C,OAAA,CAAQ,MAAA;AAAA,MACR,MAAA;AAAA,MACA,OAAA,CAAQ,SAAA;AAAA,MACR,WAAc,OAAA,CAAQ,cAAA,GAAiB,SAAY,EAAE,cAAA,EAAgB,QAAQ,cAAA;AAAe,KAC9F;AAAA,EACF;AACF;;;;"}