@bitrix24/b24jssdk 1.0.6 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-AI.md +28 -3
- package/dist/esm/_virtual/_commonjsHelpers.mjs +1 -1
- package/dist/esm/_virtual/protobuf.mjs +1 -1
- package/dist/esm/_virtual/protobuf2.mjs +1 -1
- package/dist/esm/core/abstract-b24.mjs +1 -1
- package/dist/esm/core/actions/abstract-action.mjs +1 -1
- package/dist/esm/core/actions/abstract-batch.mjs +1 -1
- package/dist/esm/core/actions/manager.mjs +1 -1
- package/dist/esm/core/actions/v2/batch-by-chunk.mjs +1 -1
- package/dist/esm/core/actions/v2/batch.mjs +1 -1
- package/dist/esm/core/actions/v2/call-list.mjs +1 -1
- package/dist/esm/core/actions/v2/call.mjs +1 -1
- package/dist/esm/core/actions/v2/fetch-list.mjs +1 -1
- package/dist/esm/core/actions/v2/manager-v2.mjs +1 -1
- package/dist/esm/core/actions/v3/batch-by-chunk.mjs +1 -1
- package/dist/esm/core/actions/v3/batch.mjs +1 -1
- package/dist/esm/core/actions/v3/call-list.mjs +1 -1
- package/dist/esm/core/actions/v3/call.mjs +1 -1
- package/dist/esm/core/actions/v3/fetch-list.mjs +1 -1
- package/dist/esm/core/actions/v3/manager-v3.mjs +1 -1
- package/dist/esm/core/http/abstract-http.mjs +2 -2
- package/dist/esm/core/http/ajax-error.mjs +1 -1
- package/dist/esm/core/http/ajax-result.mjs +44 -4
- package/dist/esm/core/http/ajax-result.mjs.map +1 -1
- package/dist/esm/core/http/limiters/adaptive-delayer.mjs +1 -1
- package/dist/esm/core/http/limiters/manager.mjs +70 -38
- package/dist/esm/core/http/limiters/manager.mjs.map +1 -1
- package/dist/esm/core/http/limiters/operating-limiter.mjs +1 -1
- package/dist/esm/core/http/limiters/params-factory.mjs +3 -2
- package/dist/esm/core/http/limiters/params-factory.mjs.map +1 -1
- package/dist/esm/core/http/limiters/rate-limiter.mjs +1 -1
- package/dist/esm/core/http/v2.mjs +2 -2
- package/dist/esm/core/http/v3.mjs +2 -2
- package/dist/esm/core/interaction/batch/abstract-interaction-batch.mjs +1 -1
- package/dist/esm/core/interaction/batch/parse-row.mjs +1 -1
- package/dist/esm/core/interaction/batch/processing/interface-strategy.mjs +1 -1
- package/dist/esm/core/interaction/batch/processing/v2/abstract-processing.mjs +2 -2
- package/dist/esm/core/interaction/batch/processing/v2/abstract-processing.mjs.map +1 -1
- package/dist/esm/core/interaction/batch/processing/v2/as-array.mjs +1 -1
- package/dist/esm/core/interaction/batch/processing/v2/as-object.mjs +1 -1
- package/dist/esm/core/interaction/batch/processing/v3/abstract-processing.mjs +16 -9
- package/dist/esm/core/interaction/batch/processing/v3/abstract-processing.mjs.map +1 -1
- package/dist/esm/core/interaction/batch/processing/v3/as-array.mjs +1 -1
- package/dist/esm/core/interaction/batch/processing/v3/as-object.mjs +1 -1
- package/dist/esm/core/interaction/batch/v2.mjs +1 -1
- package/dist/esm/core/interaction/batch/v3.mjs +1 -1
- package/dist/esm/core/language/list.mjs +1 -1
- package/dist/esm/core/request-id-generator.mjs +1 -1
- package/dist/esm/core/result.mjs +1 -1
- package/dist/esm/core/sdk-error.mjs +1 -1
- package/dist/esm/core/tools/abstract-tool.mjs +1 -1
- package/dist/esm/core/tools/healthcheck.mjs +1 -1
- package/dist/esm/core/tools/manager.mjs +1 -1
- package/dist/esm/core/tools/ping.mjs +1 -1
- package/dist/esm/core/version-manager.mjs +1 -1
- package/dist/esm/frame/auth.mjs +1 -1
- package/dist/esm/frame/b24.mjs +1 -1
- package/dist/esm/frame/dialog.mjs +45 -5
- package/dist/esm/frame/dialog.mjs.map +1 -1
- package/dist/esm/frame/frame.mjs +1 -1
- package/dist/esm/frame/message/commands.mjs +1 -1
- package/dist/esm/frame/message/controller.mjs +1 -1
- package/dist/esm/frame/options.mjs +1 -1
- package/dist/esm/frame/parent.mjs +1 -1
- package/dist/esm/frame/placement.mjs +32 -9
- package/dist/esm/frame/placement.mjs.map +1 -1
- package/dist/esm/frame/slider.mjs +1 -1
- package/dist/esm/helper/abstract-helper.mjs +1 -1
- package/dist/esm/helper/app-manager.mjs +1 -1
- package/dist/esm/helper/currency-manager.mjs +1 -1
- package/dist/esm/helper/helper-manager.mjs +1 -1
- package/dist/esm/helper/license-manager.mjs +1 -1
- package/dist/esm/helper/options-manager.mjs +1 -1
- package/dist/esm/helper/payment-manager.mjs +1 -1
- package/dist/esm/helper/profile-manager.mjs +1 -1
- package/dist/esm/helper/use-b24-helper.mjs +1 -1
- package/dist/esm/hook/auth.mjs +1 -1
- package/dist/esm/hook/b24.mjs +1 -1
- package/dist/esm/index.d.mts +174 -11
- package/dist/esm/index.d.ts +174 -11
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/loader-b24frame.mjs +1 -1
- package/dist/esm/logger/abstract-logger.mjs +1 -1
- package/dist/esm/logger/browser.mjs +1 -1
- package/dist/esm/logger/formatter/abstract-formatter.mjs +1 -1
- package/dist/esm/logger/formatter/json-formatter.mjs +1 -1
- package/dist/esm/logger/formatter/line-formatter.mjs +1 -1
- package/dist/esm/logger/formatter/telegram-formatter.mjs +1 -1
- package/dist/esm/logger/handler/abstract-handler.mjs +1 -1
- package/dist/esm/logger/handler/consola-adapter.mjs +1 -1
- package/dist/esm/logger/handler/console-handler.mjs +1 -1
- package/dist/esm/logger/handler/console-v2-handler.mjs +1 -1
- package/dist/esm/logger/handler/memory-handler.mjs +1 -1
- package/dist/esm/logger/handler/stream-handler.mjs +1 -1
- package/dist/esm/logger/handler/telegram-handler.mjs +1 -1
- package/dist/esm/logger/handler/winston-adapter.mjs +1 -1
- package/dist/esm/logger/logger-factory.mjs +1 -1
- package/dist/esm/logger/logger.mjs +1 -1
- package/dist/esm/logger/null-logger.mjs +1 -1
- package/dist/esm/logger/processor/memory-usage-processor.mjs +1 -1
- package/dist/esm/logger/processor/pid-processor.mjs +1 -1
- package/dist/esm/oauth/auth.mjs +1 -1
- package/dist/esm/oauth/b24.mjs +1 -1
- package/dist/esm/oauth/refresh-token-error.mjs +1 -1
- package/dist/esm/pullClient/abstract-connector.mjs +1 -1
- package/dist/esm/pullClient/channel-manager.mjs +1 -1
- package/dist/esm/pullClient/channel-manager.mjs.map +1 -1
- package/dist/esm/pullClient/client.mjs +1 -1
- package/dist/esm/pullClient/errors.mjs +1 -1
- package/dist/esm/pullClient/json-rpc.mjs +1 -1
- package/dist/esm/pullClient/long-polling-connector.mjs +1 -1
- package/dist/esm/pullClient/protobuf/index.mjs +1 -1
- package/dist/esm/pullClient/protobuf/model.mjs +1 -1
- package/dist/esm/pullClient/protobuf/protobuf.mjs +1 -1
- package/dist/esm/pullClient/shared-config.mjs +1 -1
- package/dist/esm/pullClient/storage-manager.mjs +1 -1
- package/dist/esm/pullClient/web-socket-connector.mjs +1 -1
- package/dist/esm/tools/browser.mjs +1 -1
- package/dist/esm/tools/environment.mjs +1 -1
- package/dist/esm/tools/formatters/iban.mjs +1 -1
- package/dist/esm/tools/formatters/numbers.mjs +1 -1
- package/dist/esm/tools/index.mjs +1 -1
- package/dist/esm/tools/scroll-size.mjs +1 -1
- package/dist/esm/tools/text.mjs +1 -1
- package/dist/esm/tools/type.mjs +1 -1
- package/dist/esm/tools/use-formatters.mjs +1 -1
- package/dist/esm/tools/uuidv7.mjs +1 -1
- package/dist/esm/types/b24-helper.mjs +1 -1
- package/dist/esm/types/b24.mjs +1 -1
- package/dist/esm/types/bizproc/index.mjs +1 -1
- package/dist/esm/types/catalog/index.mjs +1 -1
- package/dist/esm/types/common.mjs +1 -1
- package/dist/esm/types/crm/entity-type.mjs +1 -1
- package/dist/esm/types/crm/productrow.mjs +1 -1
- package/dist/esm/types/logger.mjs +1 -1
- package/dist/esm/types/pull.mjs +1 -1
- package/dist/umd/index.js +209 -66
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.min.js +19 -19
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +1 -1
package/README-AI.md
CHANGED
|
@@ -17,6 +17,24 @@ Core building blocks:
|
|
|
17
17
|
|
|
18
18
|
Note: since v0.4.0 the package ships ESM and UMD only (no CommonJS).
|
|
19
19
|
|
|
20
|
+
## Deprecation notice — read before generating code
|
|
21
|
+
|
|
22
|
+
The following surface is `@deprecated` and **scheduled for removal in `2.0.0`**.
|
|
23
|
+
Many examples in this document still reference it because it remains the most
|
|
24
|
+
widely-used path today, but new code should target the `actions.v{2,3}.*` API.
|
|
25
|
+
|
|
26
|
+
| Deprecated | Replacement |
|
|
27
|
+
|---|---|
|
|
28
|
+
| `b24.callMethod(method, params, start?)` | `b24.actions.v2.call.make({ method, params })` / `b24.actions.v3.call.make({ method, params })` |
|
|
29
|
+
| `b24.callBatch(calls, isHaltOnError?, returnAjaxResult?)` | `b24.actions.v2.batch.make({ calls, options })` / `b24.actions.v3.batch.make(...)` |
|
|
30
|
+
| `b24.callBatchByChunk(calls, isHaltOnError)` | `b24.actions.v2.batchByChunk.make({ calls, options })` / `b24.actions.v3.batchByChunk.make(...)` |
|
|
31
|
+
| `b24.callListMethod(method, params, progress?, customKey?)` | `b24.actions.v2.callList.make({ method, params, customKeyForResult })` / `b24.actions.v3.callList.make(...)` |
|
|
32
|
+
| `b24.fetchListMethod(method, params, idKey?, customKey?)` | `b24.actions.v2.fetchList.make({ method, params, idKey, customKeyForResult })` / `b24.actions.v3.fetchList.make(...)` |
|
|
33
|
+
| `AjaxResult#isMore()`, `#hasMore()`, `#getNext()`, `#fetchNext()`, `#getTotal()` | The `next`/`total` envelope fields are `restApi:v2`-only (no `restApi:v3` counterpart). Do not iterate manually — let `actions.v{2,3}.{callList,fetchList}` handle pagination. For element counts in `restApi:v3` use the `aggregate` action with `count` / `countDistinct`. |
|
|
34
|
+
|
|
35
|
+
`AjaxResult.getData()` returns exactly `{ result: T, time: PayloadTime }` — the
|
|
36
|
+
v2-only `next` and `total` fields are no longer surfaced through the public type.
|
|
37
|
+
|
|
20
38
|
|
|
21
39
|
## Frontend in Bitrix24 (TypeScript, ESM)
|
|
22
40
|
|
|
@@ -96,6 +114,8 @@ Patterns
|
|
|
96
114
|
- Destroy on page/component unmount with $b24.destroy().
|
|
97
115
|
- For large result sets prefer callListMethod or fetchListMethod.
|
|
98
116
|
- For big batches use callBatchByChunk to respect limits.
|
|
117
|
+
- A per-command `result` inside a batch can be `null` when the underlying REST method legitimately returns `null` (e.g. `im.chat.get` with non-matching params). Declare the generic as `T | null` and handle the `null` branch — the SDK no longer coerces it to `{}` (see issue #23).
|
|
118
|
+
- `restApi:v3` batch is all-or-nothing: per-command errors are not returned. If any call fails, the whole batch fails and `response.getErrorMessages()` carries the error.
|
|
99
119
|
|
|
100
120
|
|
|
101
121
|
## Frontend via UMD (CDN)
|
|
@@ -405,6 +425,11 @@ async function loadAllDealsStreaming($b24: any) {
|
|
|
405
425
|
|
|
406
426
|
#### C) Manual pagination: callMethod + next pages
|
|
407
427
|
|
|
428
|
+
> **`@deprecated` — slated for removal in `2.0.0`.** `callMethod`, `isMore()`,
|
|
429
|
+
> and `getNext()` rely on the `restApi:v2` envelope field `next`, which
|
|
430
|
+
> `restApi:v3` does not return. Prefer `b24.actions.v{2,3}.fetchList.make` for
|
|
431
|
+
> custom-throttled iteration; that helper hides pagination for both API versions.
|
|
432
|
+
|
|
408
433
|
Use when you need to control page sizes, pauses, or add custom throttling. Iterate until `isMore()` returns false, using `getNext($b24.getHttpClient())`.
|
|
409
434
|
|
|
410
435
|
```ts
|
|
@@ -446,9 +471,9 @@ import { AjaxError } from '@bitrix24/b24jssdk'
|
|
|
446
471
|
|
|
447
472
|
try {
|
|
448
473
|
const res = await $b24.callMethod('crm.item.get', { entityTypeId: 1, id: 10 })
|
|
449
|
-
const payload = res.getData() //
|
|
474
|
+
const payload = res.getData() // { result, time } — see Deprecation notice
|
|
450
475
|
const ok = res.isSuccess // boolean
|
|
451
|
-
const total = res.getTotal()
|
|
476
|
+
// const total = res.getTotal() // @deprecated, removed in 2.0.0; v3 has no `total`
|
|
452
477
|
} catch (e) {
|
|
453
478
|
if (e instanceof AjaxError) {
|
|
454
479
|
console.error(e.code, e.description, e.status, e.requestInfo)
|
|
@@ -557,7 +582,7 @@ This document is based on the SDK source in packages/jssdk/src and the docs unde
|
|
|
557
582
|
```
|
|
558
583
|
|
|
559
584
|
- Unique ID Generator: request IDs are appended automatically via Http
|
|
560
|
-
- Result / AjaxResult: uniform result objects, error aggregation
|
|
585
|
+
- Result / AjaxResult: uniform result objects, error aggregation. (Legacy paging helpers `isMore`/`getNext`/`getTotal` are `@deprecated` for `2.0.0` — see Deprecation notice.)
|
|
561
586
|
- Language List and LoggerBrowser
|
|
562
587
|
|
|
563
588
|
### Tools
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package @bitrix24/b24jssdk
|
|
3
|
-
* @version 1.
|
|
3
|
+
* @version 1.1.1
|
|
4
4
|
* @copyright (c) 2026 Bitrix24
|
|
5
5
|
* @license MIT
|
|
6
6
|
* @see https://github.com/bitrix24/b24jssdk
|
|
@@ -44,7 +44,7 @@ class AbstractHttp {
|
|
|
44
44
|
this._logger = LoggerFactory.createNullLogger();
|
|
45
45
|
const defaultHeaders = {};
|
|
46
46
|
if (this.isServerSide()) {
|
|
47
|
-
defaultHeaders["User-Agent"] = "b24-js-sdk/1.
|
|
47
|
+
defaultHeaders["User-Agent"] = "b24-js-sdk/1.1.1";
|
|
48
48
|
}
|
|
49
49
|
this._authActions = authActions;
|
|
50
50
|
this._requestIdGenerator = new RequestIdGenerator();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package @bitrix24/b24jssdk
|
|
3
|
-
* @version 1.
|
|
3
|
+
* @version 1.1.1
|
|
4
4
|
* @copyright (c) 2026 Bitrix24
|
|
5
5
|
* @license MIT
|
|
6
6
|
* @see https://github.com/bitrix24/b24jssdk
|
|
@@ -45,8 +45,6 @@ class AjaxResult extends Result {
|
|
|
45
45
|
const payload = this._data;
|
|
46
46
|
return Object.freeze({
|
|
47
47
|
result: payload.result,
|
|
48
|
-
next: "next" in payload ? payload.next : void 0,
|
|
49
|
-
total: "total" in payload ? payload.total : void 0,
|
|
50
48
|
time: payload.time
|
|
51
49
|
});
|
|
52
50
|
}
|
|
@@ -103,10 +101,27 @@ class AjaxResult extends Result {
|
|
|
103
101
|
}
|
|
104
102
|
/**
|
|
105
103
|
* Alias for isMore
|
|
104
|
+
*
|
|
105
|
+
* @deprecated Will be removed in `2.0.0`. Tied to the `restApi:v2` envelope
|
|
106
|
+
* field `next`, which `restApi:v3` does not return. Use the SDK's list
|
|
107
|
+
* helpers — they hide pagination entirely:
|
|
108
|
+
* - `restApi:v2`: {@link CallListV2.make `b24.actions.v2.callList.make`} or {@link FetchListV2.make `b24.actions.v2.fetchList.make`}
|
|
109
|
+
* - `restApi:v3`: {@link CallListV3.make `b24.actions.v3.callList.make`} or {@link FetchListV3.make `b24.actions.v3.fetchList.make`}
|
|
110
|
+
*
|
|
111
|
+
* @removed 2.0.0
|
|
106
112
|
*/
|
|
107
113
|
hasMore() {
|
|
108
114
|
return this.isMore();
|
|
109
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* @deprecated Will be removed in `2.0.0`. Tied to the `restApi:v2` envelope
|
|
118
|
+
* field `next`, which `restApi:v3` does not return. Use the SDK's list
|
|
119
|
+
* helpers — they hide pagination entirely:
|
|
120
|
+
* - `restApi:v2`: {@link CallListV2.make `b24.actions.v2.callList.make`} or {@link FetchListV2.make `b24.actions.v2.fetchList.make`}
|
|
121
|
+
* - `restApi:v3`: {@link CallListV3.make `b24.actions.v3.callList.make`} or {@link FetchListV3.make `b24.actions.v3.fetchList.make`}
|
|
122
|
+
*
|
|
123
|
+
* @removed 2.0.0
|
|
124
|
+
*/
|
|
110
125
|
isMore() {
|
|
111
126
|
if (!this.isSuccess) {
|
|
112
127
|
return false;
|
|
@@ -115,6 +130,15 @@ class AjaxResult extends Result {
|
|
|
115
130
|
const nextValue = "next" in payload ? payload.next : void 0;
|
|
116
131
|
return Type.isNumber(nextValue);
|
|
117
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated Will be removed in `2.0.0`. Tied to the `restApi:v2` envelope
|
|
135
|
+
* field `total`, which `restApi:v3` does not return. For `restApi:v3` the
|
|
136
|
+
* SDK exposes element counts via the `aggregate` action (`count` /
|
|
137
|
+
* `countDistinct`); for `restApi:v2` use the list helpers, which iterate
|
|
138
|
+
* without exposing `total`.
|
|
139
|
+
*
|
|
140
|
+
* @removed 2.0.0
|
|
141
|
+
*/
|
|
118
142
|
getTotal() {
|
|
119
143
|
if (!this.isSuccess) {
|
|
120
144
|
return 0;
|
|
@@ -133,7 +157,13 @@ class AjaxResult extends Result {
|
|
|
133
157
|
* Alias for getNext
|
|
134
158
|
* @param http
|
|
135
159
|
*
|
|
136
|
-
* @
|
|
160
|
+
* @deprecated Will be removed in `2.0.0`. `restApi:v3` does not support
|
|
161
|
+
* `getNext()` (the v2 envelope field `next` does not exist). Use the SDK's
|
|
162
|
+
* list helpers instead — they hide pagination entirely:
|
|
163
|
+
* - `restApi:v2`: {@link CallListV2.make `b24.actions.v2.callList.make`} or {@link FetchListV2.make `b24.actions.v2.fetchList.make`}
|
|
164
|
+
* - `restApi:v3`: {@link CallListV3.make `b24.actions.v3.callList.make`} or {@link FetchListV3.make `b24.actions.v3.fetchList.make`}
|
|
165
|
+
*
|
|
166
|
+
* @removed 2.0.0
|
|
137
167
|
*/
|
|
138
168
|
async fetchNext(http) {
|
|
139
169
|
const data = await this.getNext(http);
|
|
@@ -142,6 +172,16 @@ class AjaxResult extends Result {
|
|
|
142
172
|
}
|
|
143
173
|
return data;
|
|
144
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* @deprecated Will be removed in `2.0.0`. Throws on `restApi:v3` because the
|
|
177
|
+
* v2 envelope field `next` is not part of the v3 protocol. Use the SDK's
|
|
178
|
+
* list helpers instead — they hide pagination entirely:
|
|
179
|
+
* - `restApi:v2`: {@link CallListV2.make `b24.actions.v2.callList.make`} or {@link FetchListV2.make `b24.actions.v2.fetchList.make`}
|
|
180
|
+
* - `restApi:v3`: {@link CallListV3.make `b24.actions.v3.callList.make`} or {@link FetchListV3.make `b24.actions.v3.fetchList.make`}
|
|
181
|
+
*
|
|
182
|
+
* @throws {SdkError} `JSSDK_CORE_METHOD_NOT_SUPPORT_IN_API_V3` when called against a `restApi:v3` HTTP client. This throw is preserved until `2.0.0`.
|
|
183
|
+
* @removed 2.0.0
|
|
184
|
+
*/
|
|
145
185
|
async getNext(http) {
|
|
146
186
|
if (http.apiVersion === ApiVersion.v3) {
|
|
147
187
|
throw new SdkError({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ajax-result.mjs","sources":["../../../../src/core/http/ajax-result.ts"],"sourcesContent":["import type { IResult } from '../result'\nimport type { Payload, SuccessPayload } from '../../types/payloads'\nimport type { TypeCallParams, TypeHttp } from '../../types/http'\nimport type { TypeDescriptionError, TypeDescriptionErrorV3 } from '../../types/auth'\nimport { Type } from '../../tools/type'\nimport { Text } from '../../tools/text'\nimport { Result } from '../result'\nimport { AjaxError } from './ajax-error'\nimport { ApiVersion } from '../../types/b24'\nimport { SdkError } from '../sdk-error'\n\nexport type AjaxQuery = Readonly<{\n method: string\n params: TypeCallParams\n requestId: string\n}>\n\ntype AjaxResultOptions<T> = Readonly<{\n answer: Payload<T>\n query: AjaxQuery\n status: number\n}>\n\ntype ErrorData = {\n code: string\n description: string\n status: number\n}\n\n/**\n * Result of request to Rest Api\n *\n * @todo docs\n */\nexport class AjaxResult<T = unknown> extends Result<Payload<T>> implements IResult<Payload<T>> {\n private readonly _status: number\n private readonly _query: AjaxQuery\n protected override _data: Payload<T> | null | undefined\n\n constructor(options: AjaxResultOptions<T>) {\n super()\n\n this._data = options.answer ? Object.freeze(options.answer) : undefined\n this._query = Object.freeze(structuredClone(options.query))\n this._status = options.status\n\n this.#processErrors()\n }\n\n override get isSuccess(): boolean {\n return this.#getIsSuccess()\n }\n\n /**\n * @todo test this predicate\n */\n #getIsSuccess(): this is { getData: () => SuccessPayload<T> } {\n return this._errors.size === 0\n }\n\n override getData(): undefined | SuccessPayload<T> {\n if (!this.isSuccess) {\n return undefined\n }\n\n const payload = this._data as SuccessPayload<T>\n\n return Object.freeze({\n result: payload.result,\n next: 'next' in payload ? payload.next : undefined,\n total: 'total' in payload ? payload.total : undefined,\n time: payload.time\n }) as SuccessPayload<T>\n }\n\n /**\n * If the response contains error data, we'll restore it to an error.\n *\n * @todo make single function\n * @see AbstractHttp._convertAxiosErrorToAjaxError()\n */\n #processErrors(): void {\n if (this._data && typeof this._data === 'object' && 'error' in this._data) {\n const responseData = this._data as TypeDescriptionError | TypeDescriptionErrorV3\n\n if (\n responseData.error\n && typeof responseData.error === 'object'\n && 'code' in responseData.error\n ) {\n const errorCode = responseData.error.code\n let errorDescription = responseData.error.message.trimEnd()\n if (responseData.error.validation) {\n if (errorDescription.length > 0) {\n if (!errorDescription.endsWith('.')) {\n errorDescription += `.`\n }\n errorDescription += ` `\n }\n responseData.error.validation.forEach((row) => {\n errorDescription += `${row?.message || JSON.stringify(row)}`\n })\n }\n\n this.addError(this.#createAjaxError({\n code: errorCode,\n description: errorDescription,\n status: this._status\n }), 'base-error')\n } else if (responseData.error && typeof responseData.error === 'string') {\n const errorCode = responseData.error !== '0' ? responseData.error : 'JSSDK_RESPONSE_ERROR'\n const errorDescription = (responseData as TypeDescriptionError)?.error_description ?? 'Some error in response'\n\n this.addError(this.#createAjaxError({\n code: errorCode,\n description: errorDescription,\n status: this._status\n }), 'base-error')\n }\n }\n }\n\n #createAjaxError(errorData: ErrorData): AjaxError {\n return new AjaxError({\n code: errorData.code,\n description: errorData.description,\n status: errorData.status,\n requestInfo: {\n method: this._query.method,\n params: this._query.params,\n requestId: this._query.requestId\n }\n })\n }\n\n /**\n * Alias for isMore\n */\n hasMore(): boolean {\n return this.isMore()\n }\n\n isMore(): boolean {\n if (!this.isSuccess) {\n return false\n }\n const payload = this._data as SuccessPayload<T>\n const nextValue = 'next' in payload ? payload.next : undefined\n\n return Type.isNumber(nextValue)\n }\n\n getTotal(): number {\n if (!this.isSuccess) {\n return 0\n }\n const payload = this._data as SuccessPayload<T>\n const totalValue = 'total' in payload ? payload.total : undefined\n\n return Text.toInteger(totalValue)\n }\n\n getStatus(): number {\n return this._status\n }\n\n getQuery(): Readonly<AjaxQuery> {\n return this._query\n }\n\n /**\n * Alias for getNext\n * @param http\n *\n * @todo !fix api version\n */\n async fetchNext(http: TypeHttp): Promise<AjaxResult<T> | null> {\n const data = await this.getNext(http)\n if (data === false) {\n return null\n }\n\n return data\n }\n\n async getNext(http: TypeHttp): Promise<AjaxResult<T> | false> {\n // @todo ! Correction -> we can use pagination to navigate to the next page\n if (http.apiVersion === ApiVersion.v3) {\n throw new SdkError({\n code: 'JSSDK_CORE_METHOD_NOT_SUPPORT_IN_API_V3',\n description: `restApi:v3 not support method getNext`,\n status: 500\n })\n }\n if (\n !this.isSuccess\n || !this.isMore()\n ) {\n return false\n }\n\n const nextPageQuery = this.#buildNextPageQuery()\n return http.call(\n nextPageQuery.method,\n nextPageQuery.params\n ) as Promise<AjaxResult<T>>\n }\n\n #buildNextPageQuery(): AjaxQuery {\n const result = { ...this._query }\n\n const payload = this._data as SuccessPayload<T>\n const nextValue = 'next' in payload ? payload.next : undefined\n\n result.params.start = Text.toInteger(Text.toInteger(nextValue))\n\n return result\n }\n\n // Immutable API\n override setData(): never {\n throw new ReferenceError('AjaxResult does not allow data modification')\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAkCO,MAAM,mBAAgC,MAAA,CAAkD;AAAA,EAlC/F;AAkC+F,IAAA,MAAA,CAAA,IAAA,EAAA,YAAA,CAAA;AAAA;AAAA,EAC5E,OAAA;AAAA,EACA,MAAA;AAAA,EACE,KAAA;AAAA,EAEnB,YAAY,OAAA,EAA+B;AACzC,IAAA,KAAA,EAAM;AAEN,IAAA,IAAA,CAAK,QAAQ,OAAA,CAAQ,MAAA,GAAS,OAAO,MAAA,CAA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../../src/core/http/ajax-result.ts"],"sourcesContent":["import type { IResult } from '../result'\nimport type { Payload, SuccessPayload } from '../../types/payloads'\nimport type { TypeCallParams, TypeHttp } from '../../types/http'\nimport type { TypeDescriptionError, TypeDescriptionErrorV3 } from '../../types/auth'\nimport { Type } from '../../tools/type'\nimport { Text } from '../../tools/text'\nimport { Result } from '../result'\nimport { AjaxError } from './ajax-error'\nimport { ApiVersion } from '../../types/b24'\nimport { SdkError } from '../sdk-error'\n\nexport type AjaxQuery = Readonly<{\n method: string\n params: TypeCallParams\n requestId: string\n}>\n\ntype AjaxResultOptions<T> = Readonly<{\n answer: Payload<T>\n query: AjaxQuery\n status: number\n}>\n\ntype ErrorData = {\n code: string\n description: string\n status: number\n}\n\n/**\n * Result of request to Rest Api\n *\n * @todo docs\n */\nexport class AjaxResult<T = unknown> extends Result<Payload<T>> implements IResult<Payload<T>> {\n private readonly _status: number\n private readonly _query: AjaxQuery\n protected override _data: Payload<T> | null | undefined\n\n constructor(options: AjaxResultOptions<T>) {\n super()\n\n this._data = options.answer ? Object.freeze(options.answer) : undefined\n this._query = Object.freeze(structuredClone(options.query))\n this._status = options.status\n\n this.#processErrors()\n }\n\n override get isSuccess(): boolean {\n return this.#getIsSuccess()\n }\n\n /**\n * @todo test this predicate\n */\n #getIsSuccess(): this is { getData: () => SuccessPayload<T> } {\n return this._errors.size === 0\n }\n\n override getData(): undefined | SuccessPayload<T> {\n if (!this.isSuccess) {\n return undefined\n }\n\n const payload = this._data as SuccessPayload<T>\n\n return Object.freeze({\n result: payload.result,\n time: payload.time\n }) as SuccessPayload<T>\n }\n\n /**\n * If the response contains error data, we'll restore it to an error.\n *\n * @todo make single function\n * @see AbstractHttp._convertAxiosErrorToAjaxError()\n */\n #processErrors(): void {\n if (this._data && typeof this._data === 'object' && 'error' in this._data) {\n const responseData = this._data as TypeDescriptionError | TypeDescriptionErrorV3\n\n if (\n responseData.error\n && typeof responseData.error === 'object'\n && 'code' in responseData.error\n ) {\n const errorCode = responseData.error.code\n let errorDescription = responseData.error.message.trimEnd()\n if (responseData.error.validation) {\n if (errorDescription.length > 0) {\n if (!errorDescription.endsWith('.')) {\n errorDescription += `.`\n }\n errorDescription += ` `\n }\n responseData.error.validation.forEach((row) => {\n errorDescription += `${row?.message || JSON.stringify(row)}`\n })\n }\n\n this.addError(this.#createAjaxError({\n code: errorCode,\n description: errorDescription,\n status: this._status\n }), 'base-error')\n } else if (responseData.error && typeof responseData.error === 'string') {\n const errorCode = responseData.error !== '0' ? responseData.error : 'JSSDK_RESPONSE_ERROR'\n const errorDescription = (responseData as TypeDescriptionError)?.error_description ?? 'Some error in response'\n\n this.addError(this.#createAjaxError({\n code: errorCode,\n description: errorDescription,\n status: this._status\n }), 'base-error')\n }\n }\n }\n\n #createAjaxError(errorData: ErrorData): AjaxError {\n return new AjaxError({\n code: errorData.code,\n description: errorData.description,\n status: errorData.status,\n requestInfo: {\n method: this._query.method,\n params: this._query.params,\n requestId: this._query.requestId\n }\n })\n }\n\n /**\n * Alias for isMore\n *\n * @deprecated Will be removed in `2.0.0`. Tied to the `restApi:v2` envelope\n * field `next`, which `restApi:v3` does not return. Use the SDK's list\n * helpers — they hide pagination entirely:\n * - `restApi:v2`: {@link CallListV2.make `b24.actions.v2.callList.make`} or {@link FetchListV2.make `b24.actions.v2.fetchList.make`}\n * - `restApi:v3`: {@link CallListV3.make `b24.actions.v3.callList.make`} or {@link FetchListV3.make `b24.actions.v3.fetchList.make`}\n *\n * @removed 2.0.0\n */\n hasMore(): boolean {\n return this.isMore()\n }\n\n /**\n * @deprecated Will be removed in `2.0.0`. Tied to the `restApi:v2` envelope\n * field `next`, which `restApi:v3` does not return. Use the SDK's list\n * helpers — they hide pagination entirely:\n * - `restApi:v2`: {@link CallListV2.make `b24.actions.v2.callList.make`} or {@link FetchListV2.make `b24.actions.v2.fetchList.make`}\n * - `restApi:v3`: {@link CallListV3.make `b24.actions.v3.callList.make`} or {@link FetchListV3.make `b24.actions.v3.fetchList.make`}\n *\n * @removed 2.0.0\n */\n isMore(): boolean {\n if (!this.isSuccess) {\n return false\n }\n const payload = this._data as { next?: number }\n const nextValue = 'next' in payload ? payload.next : undefined\n\n return Type.isNumber(nextValue)\n }\n\n /**\n * @deprecated Will be removed in `2.0.0`. Tied to the `restApi:v2` envelope\n * field `total`, which `restApi:v3` does not return. For `restApi:v3` the\n * SDK exposes element counts via the `aggregate` action (`count` /\n * `countDistinct`); for `restApi:v2` use the list helpers, which iterate\n * without exposing `total`.\n *\n * @removed 2.0.0\n */\n getTotal(): number {\n if (!this.isSuccess) {\n return 0\n }\n const payload = this._data as { total?: number }\n const totalValue = 'total' in payload ? payload.total : undefined\n\n return Text.toInteger(totalValue)\n }\n\n getStatus(): number {\n return this._status\n }\n\n getQuery(): Readonly<AjaxQuery> {\n return this._query\n }\n\n /**\n * Alias for getNext\n * @param http\n *\n * @deprecated Will be removed in `2.0.0`. `restApi:v3` does not support\n * `getNext()` (the v2 envelope field `next` does not exist). Use the SDK's\n * list helpers instead — they hide pagination entirely:\n * - `restApi:v2`: {@link CallListV2.make `b24.actions.v2.callList.make`} or {@link FetchListV2.make `b24.actions.v2.fetchList.make`}\n * - `restApi:v3`: {@link CallListV3.make `b24.actions.v3.callList.make`} or {@link FetchListV3.make `b24.actions.v3.fetchList.make`}\n *\n * @removed 2.0.0\n */\n async fetchNext(http: TypeHttp): Promise<AjaxResult<T> | null> {\n const data = await this.getNext(http)\n if (data === false) {\n return null\n }\n\n return data\n }\n\n /**\n * @deprecated Will be removed in `2.0.0`. Throws on `restApi:v3` because the\n * v2 envelope field `next` is not part of the v3 protocol. Use the SDK's\n * list helpers instead — they hide pagination entirely:\n * - `restApi:v2`: {@link CallListV2.make `b24.actions.v2.callList.make`} or {@link FetchListV2.make `b24.actions.v2.fetchList.make`}\n * - `restApi:v3`: {@link CallListV3.make `b24.actions.v3.callList.make`} or {@link FetchListV3.make `b24.actions.v3.fetchList.make`}\n *\n * @throws {SdkError} `JSSDK_CORE_METHOD_NOT_SUPPORT_IN_API_V3` when called against a `restApi:v3` HTTP client. This throw is preserved until `2.0.0`.\n * @removed 2.0.0\n */\n async getNext(http: TypeHttp): Promise<AjaxResult<T> | false> {\n // @todo ! Correction -> we can use pagination to navigate to the next page\n if (http.apiVersion === ApiVersion.v3) {\n throw new SdkError({\n code: 'JSSDK_CORE_METHOD_NOT_SUPPORT_IN_API_V3',\n description: `restApi:v3 not support method getNext`,\n status: 500\n })\n }\n if (\n !this.isSuccess\n || !this.isMore()\n ) {\n return false\n }\n\n const nextPageQuery = this.#buildNextPageQuery()\n return http.call(\n nextPageQuery.method,\n nextPageQuery.params\n ) as Promise<AjaxResult<T>>\n }\n\n #buildNextPageQuery(): AjaxQuery {\n const result = { ...this._query }\n\n const payload = this._data as { next?: number }\n const nextValue = 'next' in payload ? payload.next : undefined\n\n result.params.start = Text.toInteger(Text.toInteger(nextValue))\n\n return result\n }\n\n // Immutable API\n override setData(): never {\n throw new ReferenceError('AjaxResult does not allow data modification')\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAkCO,MAAM,mBAAgC,MAAA,CAAkD;AAAA,EAlC/F;AAkC+F,IAAA,MAAA,CAAA,IAAA,EAAA,YAAA,CAAA;AAAA;AAAA,EAC5E,OAAA;AAAA,EACA,MAAA;AAAA,EACE,KAAA;AAAA,EAEnB,YAAY,OAAA,EAA+B;AACzC,IAAA,KAAA,EAAM;AAEN,IAAA,IAAA,CAAK,QAAQ,OAAA,CAAQ,MAAA,GAAS,OAAO,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,GAAI,MAAA;AAC9D,IAAA,IAAA,CAAK,SAAS,MAAA,CAAO,MAAA,CAAO,eAAA,CAAgB,OAAA,CAAQ,KAAK,CAAC,CAAA;AAC1D,IAAA,IAAA,CAAK,UAAU,OAAA,CAAQ,MAAA;AAEvB,IAAA,IAAA,CAAK,cAAA,EAAe;AAAA,EACtB;AAAA,EAEA,IAAa,SAAA,GAAqB;AAChC,IAAA,OAAO,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rictionManager {
|
|
|
152
152
|
].includes(answerError.code) || (answerError.description ?? "").includes("Could not find value for parameter");
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
|
-
*
|
|
155
|
+
* Built-in hard error codes (always throw, never retry).
|
|
156
|
+
*
|
|
157
|
+
* Includes authorization and fatal codes that must never be silently retried.
|
|
158
|
+
* Use `RestrictionParams.hardErrorCodes` to extend this list with custom codes.
|
|
159
|
+
*/
|
|
160
|
+
static BUILT_IN_HARD_ERROR_CODES = [
|
|
161
|
+
"ERR_BAD_REQUEST",
|
|
162
|
+
"JSSDK_UNKNOWN_ERROR",
|
|
163
|
+
"100",
|
|
164
|
+
"INTERNAL_SERVER_ERROR",
|
|
165
|
+
"ERROR_UNEXPECTED_ANSWER",
|
|
166
|
+
"PORTAL_DELETED",
|
|
167
|
+
"ERROR_BATCH_METHOD_NOT_ALLOWED",
|
|
168
|
+
"ERROR_BATCH_LENGTH_EXCEEDED",
|
|
169
|
+
"NO_AUTH_FOUND",
|
|
170
|
+
"INVALID_REQUEST",
|
|
171
|
+
"OVERLOAD_LIMIT",
|
|
172
|
+
"expired_token",
|
|
173
|
+
"ACCESS_DENIED",
|
|
174
|
+
"INVALID_CREDENTIALS",
|
|
175
|
+
"user_access_error",
|
|
176
|
+
"insufficient_scope",
|
|
177
|
+
"ERROR_MANIFEST_IS_NOT_AVAILABLE",
|
|
178
|
+
"allowed_only_intranet_user",
|
|
179
|
+
"NOT_FOUND",
|
|
180
|
+
"INVALID_ARG_VALUE"
|
|
181
|
+
];
|
|
182
|
+
/**
|
|
183
|
+
* Built-in soft error codes (returned as `AjaxResult` with error, never thrown).
|
|
184
|
+
*
|
|
185
|
+
* Use `RestrictionParams.softErrorCodes` to extend this list with custom codes.
|
|
186
|
+
*/
|
|
187
|
+
static BUILT_IN_SOFT_ERROR_CODES = [
|
|
188
|
+
"ERROR_ENTITY_NOT_FOUND",
|
|
189
|
+
"BITRIX_REST_V3_EXCEPTION_ACCESSDENIEDEXCEPTION",
|
|
190
|
+
"BITRIX_REST_V3_EXCEPTION_INVALIDJSONEXCEPTION",
|
|
191
|
+
"BITRIX_REST_V3_EXCEPTION_INVALIDFILTEREXCEPTION",
|
|
192
|
+
"BITRIX_REST_V3_EXCEPTION_INVALIDSELECTEXCEPTION",
|
|
193
|
+
"BITRIX_REST_V3_EXCEPTION_ENTITYNOTFOUNDEXCEPTION",
|
|
194
|
+
"BITRIX_REST_V3_EXCEPTION_METHODNOTFOUNDEXCEPTION",
|
|
195
|
+
"BITRIX_REST_V3_EXCEPTION_UNKNOWNDTOPROPERTYEXCEPTION",
|
|
196
|
+
"BITRIX_REST_V3_EXCEPTION_VALIDATION_REQUESTVALIDATIONEXCEPTION",
|
|
197
|
+
"BITRIX_REST_V3_EXCEPTION_VALIDATION_DTOVALIDATIONEXCEPTION"
|
|
198
|
+
];
|
|
199
|
+
/**
|
|
200
|
+
* Codes that cause the SDK to throw immediately.
|
|
201
|
+
*
|
|
202
|
+
* Composed of:
|
|
203
|
+
* - `BUILT_IN_HARD_ERROR_CODES` (always included)
|
|
204
|
+
* - `NETWORK_ERROR` and `REQUEST_TIMEOUT` when `retryOnNetworkError === false`
|
|
205
|
+
* - `RestrictionParams.hardErrorCodes` (user-provided extensions)
|
|
156
206
|
*/
|
|
157
207
|
get exceptionCodeForHard() {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
"
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
"ERROR_BATCH_METHOD_NOT_ALLOWED",
|
|
167
|
-
"ERROR_BATCH_LENGTH_EXCEEDED",
|
|
168
|
-
"NO_AUTH_FOUND",
|
|
169
|
-
"INVALID_REQUEST",
|
|
170
|
-
"OVERLOAD_LIMIT",
|
|
171
|
-
"expired_token",
|
|
172
|
-
"ACCESS_DENIED",
|
|
173
|
-
"INVALID_CREDENTIALS",
|
|
174
|
-
"user_access_error",
|
|
175
|
-
"insufficient_scope",
|
|
176
|
-
"ERROR_MANIFEST_IS_NOT_AVAILABLE",
|
|
177
|
-
"allowed_only_intranet_user",
|
|
178
|
-
"NOT_FOUND",
|
|
179
|
-
"INVALID_ARG_VALUE"
|
|
180
|
-
];
|
|
208
|
+
const codes = [...RestrictionManager.BUILT_IN_HARD_ERROR_CODES];
|
|
209
|
+
if (this.#config.retryOnNetworkError === false) {
|
|
210
|
+
codes.push("NETWORK_ERROR", "REQUEST_TIMEOUT");
|
|
211
|
+
}
|
|
212
|
+
if (this.#config.hardErrorCodes && this.#config.hardErrorCodes.length > 0) {
|
|
213
|
+
codes.push(...this.#config.hardErrorCodes);
|
|
214
|
+
}
|
|
215
|
+
return codes;
|
|
181
216
|
}
|
|
182
217
|
/**
|
|
183
|
-
*
|
|
218
|
+
* Codes returned as `AjaxResult` with an `AjaxError` payload instead of thrown.
|
|
219
|
+
*
|
|
220
|
+
* Composed of:
|
|
221
|
+
* - `BUILT_IN_SOFT_ERROR_CODES` (always included)
|
|
222
|
+
* - `RestrictionParams.softErrorCodes` (user-provided extensions)
|
|
184
223
|
*/
|
|
185
224
|
get exceptionCodeForSoft() {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
"BITRIX_REST_V3_EXCEPTION_INVALIDSELECTEXCEPTION",
|
|
192
|
-
"BITRIX_REST_V3_EXCEPTION_ENTITYNOTFOUNDEXCEPTION",
|
|
193
|
-
"BITRIX_REST_V3_EXCEPTION_METHODNOTFOUNDEXCEPTION",
|
|
194
|
-
"BITRIX_REST_V3_EXCEPTION_UNKNOWNDTOPROPERTYEXCEPTION",
|
|
195
|
-
"BITRIX_REST_V3_EXCEPTION_VALIDATION_REQUESTVALIDATIONEXCEPTION",
|
|
196
|
-
"BITRIX_REST_V3_EXCEPTION_VALIDATION_DTOVALIDATIONEXCEPTION"
|
|
197
|
-
];
|
|
225
|
+
const codes = [...RestrictionManager.BUILT_IN_SOFT_ERROR_CODES];
|
|
226
|
+
if (this.#config.softErrorCodes && this.#config.softErrorCodes.length > 0) {
|
|
227
|
+
codes.push(...this.#config.softErrorCodes);
|
|
228
|
+
}
|
|
229
|
+
return codes;
|
|
198
230
|
}
|
|
199
231
|
/**
|
|
200
232
|
* Delay due to unknown errors
|