bx-rest 1.0.0 → 1.2.0
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/CHANGELOG.md +53 -0
- package/README.en.md +25 -22
- package/README.md +25 -22
- package/esm2022/functions/errors.mjs +64 -8
- package/esm2022/services/http/HttpBX.mjs +28 -2
- package/esm2022/services/http/sessionKey.mjs +5 -5
- package/esm2022/services/navvy/extends/navvy-pag-base.mjs +12 -3
- package/esm2022/settings.mjs +15 -3
- package/esm2022/typification/rest/batch/batchRequestParam.mjs +1 -1
- package/esm2022/typification/rest/support/param.mjs +1 -1
- package/esm2022/typification/rest/task/access/getaccess.mjs +1 -1
- package/esm2022/typification/rest/task/commentitem/commentitem.mjs +1 -1
- package/esm2022/typification/rest/tasks/task.mjs +1 -1
- package/fesm2022/bx-rest.mjs +117 -15
- package/fesm2022/bx-rest.mjs.map +1 -1
- package/functions/errors.d.ts +46 -6
- package/map/tasks/task.d.ts +1 -3
- package/package.json +2 -1
- package/services/http/HttpBX.d.ts +2 -1
- package/services/navvy/extends/navvy-pag-base.d.ts +7 -4
- package/settings.d.ts +7 -0
- package/typification/rest/batch/batchRequestParam.d.ts +3 -9
- package/typification/rest/support/param.d.ts +0 -2
- package/typification/rest/task/access/getaccess.d.ts +1 -3
- package/typification/rest/task/commentitem/commentitem.d.ts +1 -3
- package/typification/rest/tasks/task.d.ts +5 -9
package/functions/errors.d.ts
CHANGED
|
@@ -1,13 +1,53 @@
|
|
|
1
|
+
export interface BXRestApiErrorDetails {
|
|
2
|
+
/**
|
|
3
|
+
* HTTP status of the portal response. `undefined` when the error came in
|
|
4
|
+
* the body of a successful (2xx) response.
|
|
5
|
+
*/
|
|
6
|
+
status?: number;
|
|
7
|
+
/** REST method that failed, e.g. `crm.deal.get`. */
|
|
8
|
+
method?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The original error, e.g. the `AxiosError` — its `response.data` holds
|
|
11
|
+
* the full response body (including REST v3 `validation`).
|
|
12
|
+
*/
|
|
13
|
+
cause?: unknown;
|
|
14
|
+
}
|
|
1
15
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Bitrix REST call resolves as a Bitrix-level API error, e.g.
|
|
4
|
-
* `INSUFFICIENT_SCOPE` or `expired_token`.
|
|
16
|
+
* A Bitrix-level API error, e.g. `INSUFFICIENT_SCOPE` or `expired_token`.
|
|
5
17
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
18
|
+
* `.res()` fails with it whenever the portal answers with a Bitrix error and
|
|
19
|
+
* a non-2xx HTTP status — which is how Bitrix sends most of its errors. When
|
|
20
|
+
* the error comes in the body of a 2xx response, `.res()` resolves as
|
|
21
|
+
* `undefined` by default and fails with it only with
|
|
22
|
+
* `{ throwOnApiError: true }` — see the "Error handling" section of the README.
|
|
8
23
|
*/
|
|
9
24
|
export declare class BXRestApiError extends Error {
|
|
10
25
|
error: string | undefined;
|
|
11
26
|
error_description: string | undefined;
|
|
12
|
-
|
|
27
|
+
readonly status: number | undefined;
|
|
28
|
+
readonly method: string | undefined;
|
|
29
|
+
constructor(error: string | undefined, error_description: string | undefined, details?: BXRestApiErrorDetails);
|
|
13
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Recognises a Bitrix error body: REST v2 `{ error, error_description }` and
|
|
33
|
+
* REST v3 `{ error: { code, message } }`. Returns `undefined` for anything
|
|
34
|
+
* else — a success payload, an HTML page from a proxy, an empty body.
|
|
35
|
+
*
|
|
36
|
+
* An empty `error` still counts: Bitrix answers e.g. `crm.deal.get` for a
|
|
37
|
+
* missing ID with `{ error: '', error_description: 'Not found' }`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseBXRestErrorBody(body: unknown): {
|
|
40
|
+
error: string;
|
|
41
|
+
error_description: string | undefined;
|
|
42
|
+
} | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Turns an HTTP failure into a `BXRestApiError` when the portal answered with
|
|
45
|
+
* a Bitrix error body. Bitrix sends most errors with a non-2xx status
|
|
46
|
+
* (401 `expired_token`, 404 `ERROR_METHOD_NOT_FOUND`, 503
|
|
47
|
+
* `QUERY_LIMIT_EXCEEDED`, 400 "Not found" from `crm.*.get`, ...), and axios
|
|
48
|
+
* rejects on those.
|
|
49
|
+
*
|
|
50
|
+
* Returns `undefined` for network errors and for responses that are not a
|
|
51
|
+
* Bitrix error body, so the caller can keep its own handling for them.
|
|
52
|
+
*/
|
|
53
|
+
export declare function bxRestApiErrorFromHttp(err: unknown, method: string): BXRestApiError | undefined;
|
package/map/tasks/task.d.ts
CHANGED
|
@@ -6,9 +6,7 @@ import { iBXRestHttpTask, iBXRestTask } from '../../typification/rest/tasks/task
|
|
|
6
6
|
import { iBXRestTaskFieldsName } from '../../typification/rest/tasks/base/fields-name';
|
|
7
7
|
export declare class BXRestMapTasksTask {
|
|
8
8
|
readonly result: typeof BXRestMapTasksTaskResult;
|
|
9
|
-
static getAccess(v: iBXRestTaskGetAccess | undefined):
|
|
10
|
-
[key: number]: import("../../typification/rest/task/access/getaccess").iBXRestTaskGetAccessItem;
|
|
11
|
-
} | undefined;
|
|
9
|
+
static getAccess(v: iBXRestTaskGetAccess | undefined): Record<number, import("../../typification/rest/task/access/getaccess").iBXRestTaskGetAccessItem> | undefined;
|
|
12
10
|
static add(item: {
|
|
13
11
|
task: iBXRestTasksTaskGetHttpDefault;
|
|
14
12
|
} | undefined): iBXRestTask | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bx-rest",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Bitrix24 REST API client and TypeScript SDK for Angular, Vue and browser apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bitrix",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"README.md",
|
|
49
49
|
"README.en.md",
|
|
50
50
|
"LICENSE",
|
|
51
|
+
"CHANGELOG.md",
|
|
51
52
|
"*.d.ts",
|
|
52
53
|
"consts",
|
|
53
54
|
"esm2022",
|
|
@@ -4,7 +4,7 @@ import { iBatchRequestAnswer, iBatchRequestParam, iBatchRequestParamArr, iBatchR
|
|
|
4
4
|
import { iBXRestAnswer } from '../../typification/rest/base/answer';
|
|
5
5
|
export declare class HttpBXServices extends HttpServices {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Не считайте этот метод образцом/финальным API.
|
|
8
8
|
* TODO: Удалить данный метод после реализации его в разделе Navvy
|
|
9
9
|
* @param param
|
|
10
10
|
*/
|
|
@@ -27,6 +27,7 @@ export declare class HttpBXServices extends HttpServices {
|
|
|
27
27
|
*/
|
|
28
28
|
get<T>(name: string[], params?: any): Observable<iBXRestAnswer<T> | undefined>;
|
|
29
29
|
httpPost<T>(url: string, params?: any): Observable<T | undefined>;
|
|
30
|
+
httpGet<T>(url: string, params?: any): Observable<T | undefined>;
|
|
30
31
|
serializeBitrixParams(params: unknown): string;
|
|
31
32
|
getNameMethod(arr: string[]): string;
|
|
32
33
|
}
|
|
@@ -4,10 +4,13 @@ import { HttpBXServices } from '../../http/HttpBX';
|
|
|
4
4
|
import { ReturnTypeNavvy } from '../navvy-support';
|
|
5
5
|
export interface BXRestResOptions {
|
|
6
6
|
/**
|
|
7
|
-
* When `true`, a Bitrix-level API error
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* When `true`, a Bitrix-level API error that comes in the body of a 2xx
|
|
8
|
+
* response makes the `Observable` returned by `.res()` error out with a
|
|
9
|
+
* `BXRestApiError` instead of resolving with `undefined`.
|
|
10
|
+
*
|
|
11
|
+
* Errors that Bitrix sends with a non-2xx HTTP status (most of them, e.g.
|
|
12
|
+
* `expired_token`, `INSUFFICIENT_SCOPE`) fail with `BXRestApiError`
|
|
13
|
+
* regardless of this option.
|
|
11
14
|
*
|
|
12
15
|
* Default: `false` (preserves the historical `.res()` behaviour).
|
|
13
16
|
*/
|
package/settings.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { iBXRestSettings } from './typification/settings';
|
|
2
2
|
export declare const DEFAULT_BX_REST_SETTINGS: iBXRestSettings;
|
|
3
3
|
export declare const BXRestSettings: {
|
|
4
|
+
value: iBXRestSettings;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Переименовано в `BXRestSettings.value` — имя `date` не
|
|
7
|
+
* отражало содержимое (настройки auth/urls, а не дату) и сбивало с толку
|
|
8
|
+
* в публичном API. Геттер/сеттер оставлен только для обратной совместимости
|
|
9
|
+
* с кодом, написанным против API до 1.0.
|
|
10
|
+
*/
|
|
4
11
|
date: iBXRestSettings;
|
|
5
12
|
update(newSettings: Partial<iBXRestSettings>): void;
|
|
6
13
|
};
|
|
@@ -4,12 +4,6 @@ export interface iBatchRequestParam<T> {
|
|
|
4
4
|
name: string;
|
|
5
5
|
param: T;
|
|
6
6
|
}
|
|
7
|
-
export type iBatchRequestParamHttp =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export type iBatchRequestParamArr<T> = {
|
|
11
|
-
[key: keyBatch]: iBatchRequestParam<T>;
|
|
12
|
-
};
|
|
13
|
-
export type iBatchRequestAnswer<T> = iBXRestAnswer<iBXRestAnswer<{
|
|
14
|
-
[key: keyBatch]: T;
|
|
15
|
-
}>>;
|
|
7
|
+
export type iBatchRequestParamHttp = Record<keyBatch, string>;
|
|
8
|
+
export type iBatchRequestParamArr<T> = Record<keyBatch, iBatchRequestParam<T>>;
|
|
9
|
+
export type iBatchRequestAnswer<T> = iBXRestAnswer<iBXRestAnswer<Record<keyBatch, T>>>;
|
|
@@ -6,9 +6,7 @@ export interface iBXRestParamTaskGetAccess {
|
|
|
6
6
|
users?: number[];
|
|
7
7
|
}
|
|
8
8
|
export interface iBXRestTaskGetAccess {
|
|
9
|
-
allowedActions:
|
|
10
|
-
[key: number]: iBXRestTaskGetAccessItem;
|
|
11
|
-
};
|
|
9
|
+
allowedActions: Record<number, iBXRestTaskGetAccessItem>;
|
|
12
10
|
}
|
|
13
11
|
export interface iBXRestTaskGetAccessItem {
|
|
14
12
|
ACCEPT: boolean;
|
|
@@ -5,9 +5,7 @@ export interface iBXRestTaskComment extends iBXRestTaskCommentBase {
|
|
|
5
5
|
POST_DATE: Date;
|
|
6
6
|
}
|
|
7
7
|
export interface iBXRestTaskCommentHtml extends iBXRestTaskCommentBase {
|
|
8
|
-
ATTACHED_OBJECTS?:
|
|
9
|
-
[key: number]: iCommentTaskFileHtml;
|
|
10
|
-
};
|
|
8
|
+
ATTACHED_OBJECTS?: Record<number, iCommentTaskFileHtml>;
|
|
11
9
|
AUTHOR_ID: string;
|
|
12
10
|
ID: string;
|
|
13
11
|
POST_DATE: string;
|
|
@@ -68,9 +68,7 @@ export interface iBXRestHttpTask extends iBXRestBaseTask {
|
|
|
68
68
|
additionalData: any[];
|
|
69
69
|
creator: iBXRestHttpTaskPeople;
|
|
70
70
|
responsible: iBXRestHttpTaskPeople;
|
|
71
|
-
accomplicesData:
|
|
72
|
-
[key: number]: iBXRestHttpTaskPeople;
|
|
73
|
-
};
|
|
71
|
+
accomplicesData: Record<number, iBXRestHttpTaskPeople>;
|
|
74
72
|
allowTimeTracking: iBXRestYesNo;
|
|
75
73
|
tags: iBXRestTaskHttpTag;
|
|
76
74
|
}
|
|
@@ -78,12 +76,10 @@ export interface iBXRestTaskTag {
|
|
|
78
76
|
id: number;
|
|
79
77
|
title: string;
|
|
80
78
|
}
|
|
81
|
-
export
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
};
|
|
86
|
-
}
|
|
79
|
+
export type iBXRestTaskHttpTag = Record<string, {
|
|
80
|
+
id: string;
|
|
81
|
+
title: string;
|
|
82
|
+
}>;
|
|
87
83
|
export interface iBXRestHttpTaskGroupHttp {
|
|
88
84
|
id: string;
|
|
89
85
|
name: string;
|