@bitrix24/b24jssdk
Version:
Bitrix24 REST API JavaScript SDK
1 lines • 4.71 kB
Source Map (JSON)
{"version":3,"file":"b24.cjs","sources":["../../../src/types/b24.ts"],"sourcesContent":["/**\n * Core types for the Bitrix24 REST API client: API version enumeration, batch call options,\n * and the main B24 client interface exposing HTTP, auth, tools, and actions managers.\n *\n * @module\n */\nimport type { LoggerInterface } from './logger'\nimport type { AjaxResult } from '../core/http/ajax-result'\nimport type { Result } from '../core/result'\nimport type { TypeHttp, ICallBatchOptions } from './http'\nimport type { AuthActions } from './auth'\nimport type { RestrictionParams } from './limiters'\nimport type { ActionsManager } from '../core/actions/manager'\nimport type { ToolsManager } from '../core/tools/manager'\n\nexport enum ApiVersion {\n v3 = 'v3',\n v2 = 'v2'\n}\n\n/**\n * Options for batch calls\n */\nexport interface IB24BatchOptions extends ICallBatchOptions {\n /**\n * Api Version\n * If the option is empty, then automatic detection is performed using the specified methods.\n */\n apiVersion?: ApiVersion\n\n /**\n * Whether to return an AjaxResult object instead of data\n * @default false\n */\n returnAjaxResult?: boolean\n}\n\n/**\n * The four shapes a batch answers with, named. `T` is **one command's payload**\n * in all of them.\n *\n * Which one you get is decided by two things you pass in: whether `calls` was a\n * record of named commands or an array, and whether `options.returnAjaxResult`\n * was set. Nothing on the returned value says which — the discriminator is the\n * input — so {@link CallBatchResult} below cannot be narrowed by a type guard.\n * That is why `batch.make` carries overloads: they pick the right member from\n * the arguments, which is the only place the answer exists.\n *\n * Measured, all four (#518):\n *\n * | `calls` | `returnAjaxResult` | `getData()` |\n * | --- | --- | --- |\n * | named record | absent / `false` | `{ [name]: payload }` |\n * | named record | `true` | `{ [name]: AjaxResult }` |\n * | array | absent / `false` | `payload[]` |\n * | array | `true` | `AjaxResult[]` |\n */\nexport type BatchResultByName<T> = Result<Record<string, T>>\n/** @see BatchResultByName */\nexport type BatchResultByIndex<T> = Result<T[]>\n/** @see BatchResultByName */\nexport type BatchResultByNameDetailed<T> = Result<Record<string | number, AjaxResult<T>>>\n/** @see BatchResultByName */\nexport type BatchResultByIndexDetailed<T> = Result<AjaxResult<T>[]>\n\n/**\n * The union of every batch shape — what the implementation signature returns,\n * and what a caller sees when `returnAjaxResult` is a `boolean` the compiler\n * cannot read as a literal. Prefer the overloads; reach for this only when the\n * flag is genuinely dynamic.\n */\nexport type CallBatchResult<T>\n = BatchResultByNameDetailed<T>\n | BatchResultByIndexDetailed<T>\n | BatchResultByName<T>\n | BatchResultByIndex<T>\n | Result<T>\n\nexport type TypeB24 = {\n /**\n * @see {https://bitrix24.github.io/b24jssdk/docs/hook/ Js SDK documentation}\n * @see {https://apidocs.bitrix24.com/sdk/bx24-js-sdk/system-functions/bx24-init.html Bitrix24 REST API documentation}\n */\n readonly isInit: boolean\n init(): Promise<void>\n destroy(): void\n\n getLogger(): LoggerInterface\n setLogger(logger: LoggerInterface): void\n\n /**\n * Returns the AuthActions interface for handling authorization.\n */\n get auth(): AuthActions\n\n /**\n * Returns the ActionsManager interface for working with Bitrix24 methods. Dependent on the REST API version.\n */\n get actions(): ActionsManager\n\n /**\n * Returns the ToolsManager interface for access to Bitrix24 utilities independent of the REST API version.\n */\n get tools(): ToolsManager\n\n /**\n * Sets the restriction parameters\n */\n setRestrictionManagerParams(params: RestrictionParams): Promise<void>\n\n /**\n * Get the account address Bitrix24 ( `https://your_domain.bitrix24.com` )\n */\n getTargetOrigin(): string\n\n /**\n * Get the account address Bitrix24 with path\n * - `restApi:v3` `https://your_domain.bitrix24.com/rest/api/`\n * - `restApi:v2` `https://your_domain.bitrix24.com/rest/`\n */\n getTargetOriginWithPath(): Map<ApiVersion, string>\n\n /**\n * Returns the HTTP client to perform the request.\n */\n getHttpClient(version: ApiVersion): TypeHttp\n\n /**\n * Set HTTP client\n */\n setHttpClient(version: ApiVersion, client: TypeHttp): void\n}\n"],"names":["ApiVersion"],"mappings":";;;;;;;;;;AAeO,IAAK,UAAA,qBAAAA,WAAAA,KAAL;AACL,EAAAA,YAAA,IAAA,CAAA,GAAK,IAAA;AACL,EAAAA,YAAA,IAAA,CAAA,GAAK,IAAA;AAFK,EAAA,OAAAA,WAAAA;AAAA,CAAA,EAAA,UAAA,IAAA,EAAA;;;;"}