@2bad/bitrix 2.3.1 → 2.5.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/README.md +53 -45
- package/build/main/bitrix.d.ts +25 -16
- package/build/main/bitrix.integration.test.js +0 -1
- package/build/main/bitrix.js +40 -13
- package/build/main/bitrix.unit.test.js +24 -9
- package/build/main/client/client.unit.test.js +13 -10
- package/build/main/client/hooks/addAccessToken.d.ts +5 -2
- package/build/main/client/hooks/addAccessToken.js +3 -1
- package/build/main/client/hooks/addAccessToken.unit.test.js +13 -12
- package/build/main/client/index.d.ts +10 -1
- package/build/main/client/index.js +23 -11
- package/build/main/client/methods/batch.d.ts +24 -5
- package/build/main/client/methods/batch.js +49 -17
- package/build/main/client/methods/batch.unit.test.js +103 -45
- package/build/main/client/methods/call.d.ts +11 -4
- package/build/main/client/methods/call.js +16 -6
- package/build/main/client/methods/call.unit.test.js +36 -21
- package/build/main/client/methods/list.d.ts +15 -3
- package/build/main/client/methods/list.js +36 -14
- package/build/main/client/methods/list.unit.test.js +42 -27
- package/build/main/commands.d.ts +2 -2
- package/build/main/commands.js +0 -1
- package/build/main/methods.d.ts +27 -8
- package/build/main/methods.js +1 -1
- package/build/main/payloads.d.ts +8 -8
- package/build/main/payloads.js +0 -1
- package/build/main/services/common.d.ts +5 -4
- package/build/main/services/common.js +0 -1
- package/build/main/services/companies/entities.d.ts +7 -6
- package/build/main/services/companies/entities.js +0 -1
- package/build/main/services/companies/index.d.ts +7 -6
- package/build/main/services/companies/index.integration.test.js +2 -3
- package/build/main/services/companies/index.js +0 -1
- package/build/main/services/companies/index.unit.test.js +1 -2
- package/build/main/services/companies/methods.d.ts +4 -4
- package/build/main/services/companies/methods.js +0 -1
- package/build/main/services/contacts/entities.d.ts +4 -3
- package/build/main/services/contacts/entities.js +0 -1
- package/build/main/services/contacts/index.d.ts +7 -6
- package/build/main/services/contacts/index.integration.test.js +2 -3
- package/build/main/services/contacts/index.js +0 -1
- package/build/main/services/contacts/index.unit.test.js +1 -2
- package/build/main/services/contacts/methods.d.ts +4 -4
- package/build/main/services/contacts/methods.js +0 -1
- package/build/main/services/currencies/entities.d.ts +2 -2
- package/build/main/services/currencies/entities.js +0 -1
- package/build/main/services/deals/entities.d.ts +2 -2
- package/build/main/services/deals/entities.js +0 -1
- package/build/main/services/deals/index.d.ts +7 -6
- package/build/main/services/deals/index.integration.test.js +2 -3
- package/build/main/services/deals/index.js +0 -1
- package/build/main/services/deals/index.unit.test.js +1 -2
- package/build/main/services/deals/methods.d.ts +4 -4
- package/build/main/services/deals/methods.js +0 -1
- package/build/main/services/leads/entities.d.ts +2 -2
- package/build/main/services/leads/entities.js +0 -1
- package/build/main/services/leads/index.d.ts +7 -6
- package/build/main/services/leads/index.integration.test.js +2 -3
- package/build/main/services/leads/index.js +0 -1
- package/build/main/services/leads/index.unit.test.js +1 -2
- package/build/main/services/leads/methods.d.ts +4 -4
- package/build/main/services/leads/methods.js +0 -1
- package/build/main/services/statuses/entities.d.ts +5 -4
- package/build/main/services/statuses/entities.js +0 -1
- package/build/main/services/statuses/index.d.ts +7 -11
- package/build/main/services/statuses/index.integration.test.js +8 -4
- package/build/main/services/statuses/index.js +0 -1
- package/build/main/services/statuses/index.unit.test.js +1 -2
- package/build/main/services/statuses/methods.d.ts +6 -6
- package/build/main/services/statuses/methods.js +0 -1
- package/build/main/services/users/entities.d.ts +4 -3
- package/build/main/services/users/entities.js +0 -1
- package/build/main/services/users/index.d.ts +3 -3
- package/build/main/services/users/index.integration.test.js +2 -3
- package/build/main/services/users/index.js +0 -1
- package/build/main/services/users/index.unit.test.js +1 -2
- package/build/main/services/users/methods.d.ts +4 -4
- package/build/main/services/users/methods.js +0 -1
- package/build/main/utils/Diff.js +0 -1
- package/build/main/utils/ExtractValue.d.ts +6 -1
- package/build/main/utils/ExtractValue.js +0 -1
- package/build/main/utils/isArray.d.ts +1 -1
- package/build/main/utils/isArray.js +1 -1
- package/build/module/bitrix.d.ts +25 -16
- package/build/module/bitrix.integration.test.js +0 -1
- package/build/module/bitrix.js +19 -3
- package/build/module/bitrix.unit.test.js +0 -1
- package/build/module/client/client.unit.test.js +9 -6
- package/build/module/client/hooks/addAccessToken.d.ts +5 -2
- package/build/module/client/hooks/addAccessToken.js +3 -1
- package/build/module/client/hooks/addAccessToken.unit.test.js +9 -8
- package/build/module/client/index.d.ts +10 -1
- package/build/module/client/index.js +19 -7
- package/build/module/client/methods/batch.d.ts +24 -5
- package/build/module/client/methods/batch.js +28 -3
- package/build/module/client/methods/batch.unit.test.js +61 -19
- package/build/module/client/methods/call.d.ts +11 -4
- package/build/module/client/methods/call.js +10 -3
- package/build/module/client/methods/call.unit.test.js +1 -2
- package/build/module/client/methods/list.d.ts +15 -3
- package/build/module/client/methods/list.js +21 -5
- package/build/module/client/methods/list.unit.test.js +0 -1
- package/build/module/commands.d.ts +2 -2
- package/build/module/commands.js +1 -1
- package/build/module/methods.d.ts +27 -8
- package/build/module/methods.js +0 -1
- package/build/module/payloads.d.ts +8 -8
- package/build/module/payloads.js +1 -1
- package/build/module/services/common.d.ts +5 -4
- package/build/module/services/common.js +1 -1
- package/build/module/services/companies/entities.d.ts +7 -6
- package/build/module/services/companies/entities.js +1 -1
- package/build/module/services/companies/index.d.ts +7 -6
- package/build/module/services/companies/index.integration.test.js +1 -2
- package/build/module/services/companies/index.js +0 -1
- package/build/module/services/companies/index.unit.test.js +0 -1
- package/build/module/services/companies/methods.d.ts +4 -4
- package/build/module/services/companies/methods.js +0 -1
- package/build/module/services/contacts/entities.d.ts +4 -3
- package/build/module/services/contacts/entities.js +1 -1
- package/build/module/services/contacts/index.d.ts +7 -6
- package/build/module/services/contacts/index.integration.test.js +1 -2
- package/build/module/services/contacts/index.js +0 -1
- package/build/module/services/contacts/index.unit.test.js +0 -1
- package/build/module/services/contacts/methods.d.ts +4 -4
- package/build/module/services/contacts/methods.js +0 -1
- package/build/module/services/currencies/entities.d.ts +2 -2
- package/build/module/services/currencies/entities.js +1 -1
- package/build/module/services/deals/entities.d.ts +2 -2
- package/build/module/services/deals/entities.js +1 -1
- package/build/module/services/deals/index.d.ts +7 -6
- package/build/module/services/deals/index.integration.test.js +1 -2
- package/build/module/services/deals/index.js +0 -1
- package/build/module/services/deals/index.unit.test.js +0 -1
- package/build/module/services/deals/methods.d.ts +4 -4
- package/build/module/services/deals/methods.js +0 -1
- package/build/module/services/leads/entities.d.ts +2 -2
- package/build/module/services/leads/entities.js +1 -1
- package/build/module/services/leads/index.d.ts +7 -6
- package/build/module/services/leads/index.integration.test.js +1 -2
- package/build/module/services/leads/index.js +0 -1
- package/build/module/services/leads/index.unit.test.js +0 -1
- package/build/module/services/leads/methods.d.ts +4 -4
- package/build/module/services/leads/methods.js +0 -1
- package/build/module/services/statuses/entities.d.ts +5 -4
- package/build/module/services/statuses/entities.js +1 -1
- package/build/module/services/statuses/index.d.ts +7 -11
- package/build/module/services/statuses/index.integration.test.js +7 -3
- package/build/module/services/statuses/index.js +0 -1
- package/build/module/services/statuses/index.unit.test.js +0 -1
- package/build/module/services/statuses/methods.d.ts +6 -6
- package/build/module/services/statuses/methods.js +0 -1
- package/build/module/services/users/entities.d.ts +4 -3
- package/build/module/services/users/entities.js +1 -1
- package/build/module/services/users/index.d.ts +3 -3
- package/build/module/services/users/index.integration.test.js +1 -2
- package/build/module/services/users/index.js +0 -1
- package/build/module/services/users/index.unit.test.js +0 -1
- package/build/module/services/users/methods.d.ts +4 -4
- package/build/module/services/users/methods.js +0 -1
- package/build/module/utils/Diff.js +1 -1
- package/build/module/utils/ExtractValue.d.ts +6 -1
- package/build/module/utils/ExtractValue.js +1 -1
- package/build/module/utils/isArray.d.ts +1 -1
- package/build/module/utils/isArray.js +1 -1
- package/package.json +64 -60
- package/build/main/bitrix.integration.test.js.map +0 -1
- package/build/main/bitrix.js.map +0 -1
- package/build/main/bitrix.unit.test.js.map +0 -1
- package/build/main/client/client.unit.test.js.map +0 -1
- package/build/main/client/hooks/addAccessToken.js.map +0 -1
- package/build/main/client/hooks/addAccessToken.unit.test.js.map +0 -1
- package/build/main/client/index.js.map +0 -1
- package/build/main/client/methods/batch.js.map +0 -1
- package/build/main/client/methods/batch.unit.test.js.map +0 -1
- package/build/main/client/methods/call.js.map +0 -1
- package/build/main/client/methods/call.unit.test.js.map +0 -1
- package/build/main/client/methods/list.js.map +0 -1
- package/build/main/client/methods/list.unit.test.js.map +0 -1
- package/build/main/commands.js.map +0 -1
- package/build/main/methods.js.map +0 -1
- package/build/main/payloads.js.map +0 -1
- package/build/main/services/common.js.map +0 -1
- package/build/main/services/companies/entities.js.map +0 -1
- package/build/main/services/companies/index.integration.test.js.map +0 -1
- package/build/main/services/companies/index.js.map +0 -1
- package/build/main/services/companies/index.unit.test.js.map +0 -1
- package/build/main/services/companies/methods.js.map +0 -1
- package/build/main/services/contacts/entities.js.map +0 -1
- package/build/main/services/contacts/index.integration.test.js.map +0 -1
- package/build/main/services/contacts/index.js.map +0 -1
- package/build/main/services/contacts/index.unit.test.js.map +0 -1
- package/build/main/services/contacts/methods.js.map +0 -1
- package/build/main/services/currencies/entities.js.map +0 -1
- package/build/main/services/deals/entities.js.map +0 -1
- package/build/main/services/deals/index.integration.test.js.map +0 -1
- package/build/main/services/deals/index.js.map +0 -1
- package/build/main/services/deals/index.unit.test.js.map +0 -1
- package/build/main/services/deals/methods.js.map +0 -1
- package/build/main/services/leads/entities.js.map +0 -1
- package/build/main/services/leads/index.integration.test.js.map +0 -1
- package/build/main/services/leads/index.js.map +0 -1
- package/build/main/services/leads/index.unit.test.js.map +0 -1
- package/build/main/services/leads/methods.js.map +0 -1
- package/build/main/services/statuses/entities.js.map +0 -1
- package/build/main/services/statuses/index.integration.test.js.map +0 -1
- package/build/main/services/statuses/index.js.map +0 -1
- package/build/main/services/statuses/index.unit.test.js.map +0 -1
- package/build/main/services/statuses/methods.js.map +0 -1
- package/build/main/services/users/entities.js.map +0 -1
- package/build/main/services/users/index.integration.test.js.map +0 -1
- package/build/main/services/users/index.js.map +0 -1
- package/build/main/services/users/index.unit.test.js.map +0 -1
- package/build/main/services/users/methods.js.map +0 -1
- package/build/main/utils/Diff.js.map +0 -1
- package/build/main/utils/ExtractValue.js.map +0 -1
- package/build/main/utils/isArray.js.map +0 -1
- package/build/module/bitrix.integration.test.js.map +0 -1
- package/build/module/bitrix.js.map +0 -1
- package/build/module/bitrix.unit.test.js.map +0 -1
- package/build/module/client/client.unit.test.js.map +0 -1
- package/build/module/client/hooks/addAccessToken.js.map +0 -1
- package/build/module/client/hooks/addAccessToken.unit.test.js.map +0 -1
- package/build/module/client/index.js.map +0 -1
- package/build/module/client/methods/batch.js.map +0 -1
- package/build/module/client/methods/batch.unit.test.js.map +0 -1
- package/build/module/client/methods/call.js.map +0 -1
- package/build/module/client/methods/call.unit.test.js.map +0 -1
- package/build/module/client/methods/list.js.map +0 -1
- package/build/module/client/methods/list.unit.test.js.map +0 -1
- package/build/module/commands.js.map +0 -1
- package/build/module/methods.js.map +0 -1
- package/build/module/payloads.js.map +0 -1
- package/build/module/services/common.js.map +0 -1
- package/build/module/services/companies/entities.js.map +0 -1
- package/build/module/services/companies/index.integration.test.js.map +0 -1
- package/build/module/services/companies/index.js.map +0 -1
- package/build/module/services/companies/index.unit.test.js.map +0 -1
- package/build/module/services/companies/methods.js.map +0 -1
- package/build/module/services/contacts/entities.js.map +0 -1
- package/build/module/services/contacts/index.integration.test.js.map +0 -1
- package/build/module/services/contacts/index.js.map +0 -1
- package/build/module/services/contacts/index.unit.test.js.map +0 -1
- package/build/module/services/contacts/methods.js.map +0 -1
- package/build/module/services/currencies/entities.js.map +0 -1
- package/build/module/services/deals/entities.js.map +0 -1
- package/build/module/services/deals/index.integration.test.js.map +0 -1
- package/build/module/services/deals/index.js.map +0 -1
- package/build/module/services/deals/index.unit.test.js.map +0 -1
- package/build/module/services/deals/methods.js.map +0 -1
- package/build/module/services/leads/entities.js.map +0 -1
- package/build/module/services/leads/index.integration.test.js.map +0 -1
- package/build/module/services/leads/index.js.map +0 -1
- package/build/module/services/leads/index.unit.test.js.map +0 -1
- package/build/module/services/leads/methods.js.map +0 -1
- package/build/module/services/statuses/entities.js.map +0 -1
- package/build/module/services/statuses/index.integration.test.js.map +0 -1
- package/build/module/services/statuses/index.js.map +0 -1
- package/build/module/services/statuses/index.unit.test.js.map +0 -1
- package/build/module/services/statuses/methods.js.map +0 -1
- package/build/module/services/users/entities.js.map +0 -1
- package/build/module/services/users/index.integration.test.js.map +0 -1
- package/build/module/services/users/index.js.map +0 -1
- package/build/module/services/users/index.unit.test.js.map +0 -1
- package/build/module/services/users/methods.js.map +0 -1
- package/build/module/utils/Diff.js.map +0 -1
- package/build/module/utils/ExtractValue.js.map +0 -1
- package/build/module/utils/isArray.js.map +0 -1
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import got from 'got';
|
|
2
2
|
import { Commands } from '../../commands';
|
|
3
3
|
import { Method, MethodPayloadType } from '../../methods';
|
|
4
4
|
import { BatchPayload } from '../../payloads';
|
|
5
5
|
export declare const MAX_COMMANDS_PER_BATCH = 50;
|
|
6
|
+
/**
|
|
7
|
+
* Split any number of commands into the chunks with max commands per batch in each chunk
|
|
8
|
+
*/
|
|
6
9
|
export declare const chunkCommands: <C extends Commands>(commands: C, size?: number) => readonly C[];
|
|
10
|
+
/**
|
|
11
|
+
* Prepares list of commands to be used in requests to the Bitrix
|
|
12
|
+
* @note We could avoid that function... if only Bitrix API would support posting of the batch commands as
|
|
13
|
+
* plain objects, like it does with other methods. Instead, it should be a dict or array of string queries
|
|
14
|
+
*/
|
|
7
15
|
export declare const prepareCommandsQueries: <C extends Commands, R = { [K in keyof C]: string; }>(commands: C) => R;
|
|
8
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Merges list of batch responses into a single batch
|
|
18
|
+
* @todo Generics inference is complicated here and might be not super accurate
|
|
19
|
+
*/
|
|
20
|
+
export declare const mergeBatchPayloads: <B extends BatchPayload<unknown>, P = B extends BatchPayload<infer U> ? U : never>(payloads: readonly B[]) => BatchPayload<P>;
|
|
9
21
|
export declare type CommandsPayloads<C extends Commands, CM = {
|
|
10
22
|
[K in keyof C]: C[K] extends {
|
|
11
23
|
readonly method: infer M;
|
|
@@ -14,8 +26,15 @@ export declare type CommandsPayloads<C extends Commands, CM = {
|
|
|
14
26
|
[K in keyof CM]: MethodPayloadType<CM[K] extends Method ? CM[K] : never>;
|
|
15
27
|
};
|
|
16
28
|
export declare type Batch = <C extends Commands, P = CommandsPayloads<C>>(commands: C, commandsPerRequest?: number) => Promise<BatchPayload<P>>;
|
|
17
|
-
|
|
18
|
-
readonly get:
|
|
19
|
-
}
|
|
29
|
+
declare type Dependencies = {
|
|
30
|
+
readonly get: typeof got.get;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Dispatches a batch request with specified commands. Will fill figure out payload type based on the Methods.
|
|
34
|
+
* Supports unlimited number of commands. If they do exceed max amount of commands per batch, will dispatch
|
|
35
|
+
* multiple request and merge result into single batch payload
|
|
36
|
+
* @todo For now due to issues with types it won't check `params` of command, so any Method can be used
|
|
37
|
+
* with any (even wrong) params
|
|
38
|
+
*/
|
|
20
39
|
declare const _default: ({ get }: Dependencies) => Batch;
|
|
21
40
|
export default _default;
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mergeBatchPayloads = exports.prepareCommandsQueries = exports.chunkCommands = exports.MAX_COMMANDS_PER_BATCH = void 0;
|
|
6
7
|
const lodash_chunk_1 = __importDefault(require("lodash.chunk"));
|
|
7
8
|
const lodash_frompairs_1 = __importDefault(require("lodash.frompairs"));
|
|
8
9
|
const qs_1 = require("qs");
|
|
@@ -10,21 +11,44 @@ const methods_1 = require("../../methods");
|
|
|
10
11
|
const isArray_1 = __importDefault(require("../../utils/isArray"));
|
|
11
12
|
const call_1 = require("./call");
|
|
12
13
|
exports.MAX_COMMANDS_PER_BATCH = 50;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Split any number of commands into the chunks with max commands per batch in each chunk
|
|
16
|
+
*/
|
|
17
|
+
const chunkCommands = (commands, size = exports.MAX_COMMANDS_PER_BATCH) => {
|
|
18
|
+
const commandsIsArray = (0, isArray_1.default)(commands);
|
|
19
|
+
const chunks = (0, lodash_chunk_1.default)(Object.entries(commands), size);
|
|
20
|
+
// @todo Generated return type isn't very accurate since it says that it will make array of <C>, while
|
|
21
|
+
// in fact <C> will be distributed among chunks. That gives wrong hints with named commands and arrays as const.
|
|
16
22
|
return chunks.map((c) => commandsIsArray
|
|
23
|
+
// @todo Figure out how to avoid unsafe casting to <C> here
|
|
24
|
+
// Without `<C>` generic it won't work with complex functions like `batch`
|
|
17
25
|
? c.map(([_key, command]) => command)
|
|
18
|
-
: lodash_frompairs_1.default(c));
|
|
26
|
+
: (0, lodash_frompairs_1.default)(c));
|
|
19
27
|
};
|
|
20
|
-
exports.
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
exports.chunkCommands = chunkCommands;
|
|
29
|
+
/**
|
|
30
|
+
* Prepares list of commands to be used in requests to the Bitrix
|
|
31
|
+
* @note We could avoid that function... if only Bitrix API would support posting of the batch commands as
|
|
32
|
+
* plain objects, like it does with other methods. Instead, it should be a dict or array of string queries
|
|
33
|
+
*/
|
|
34
|
+
const prepareCommandsQueries = (commands) => Object.entries(commands).reduce((calls, [name, { method, params }]) => {
|
|
35
|
+
const stringifiedParams = params ? `?${(0, qs_1.stringify)(params)}` : '';
|
|
36
|
+
return {
|
|
37
|
+
...calls,
|
|
38
|
+
[`cmd[${name}]`]: `${method}${stringifiedParams}`
|
|
39
|
+
};
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
|
|
23
41
|
}, {});
|
|
24
|
-
exports.
|
|
25
|
-
|
|
42
|
+
exports.prepareCommandsQueries = prepareCommandsQueries;
|
|
43
|
+
/**
|
|
44
|
+
* Merges list of batch responses into a single batch
|
|
45
|
+
* @todo Generics inference is complicated here and might be not super accurate
|
|
46
|
+
*/
|
|
47
|
+
const mergeBatchPayloads = (payloads) => {
|
|
48
|
+
const merge = (a, b) => (0, isArray_1.default)(a) && (0, isArray_1.default)(b)
|
|
49
|
+
// @todo Gotta find way to avoid unsafe casting here
|
|
26
50
|
? [...a, ...b]
|
|
27
|
-
: (
|
|
51
|
+
: ({ ...a, ...b });
|
|
28
52
|
return payloads.reduce((merged, payload) => ({
|
|
29
53
|
result: {
|
|
30
54
|
result: merge(merged.result.result || [], payload.result.result),
|
|
@@ -33,21 +57,29 @@ exports.mergeBatchPayloads = (payloads) => {
|
|
|
33
57
|
result_time: merge(merged.result.result_time || [], payload.result.result_time),
|
|
34
58
|
result_total: merge(merged.result.result_total || [], payload.result.result_total)
|
|
35
59
|
},
|
|
36
|
-
time:
|
|
60
|
+
time: { ...merged.time, ...payload.time }
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
|
|
37
62
|
}), { result: {}, time: {} });
|
|
38
63
|
};
|
|
64
|
+
exports.mergeBatchPayloads = mergeBatchPayloads;
|
|
65
|
+
/**
|
|
66
|
+
* Dispatches a batch request with specified commands. Will fill figure out payload type based on the Methods.
|
|
67
|
+
* Supports unlimited number of commands. If they do exceed max amount of commands per batch, will dispatch
|
|
68
|
+
* multiple request and merge result into single batch payload
|
|
69
|
+
* @todo For now due to issues with types it won't check `params` of command, so any Method can be used
|
|
70
|
+
* with any (even wrong) params
|
|
71
|
+
*/
|
|
39
72
|
exports.default = ({ get }) => {
|
|
40
73
|
const batch = async (commands, commandsPerRequest = exports.MAX_COMMANDS_PER_BATCH) => {
|
|
41
|
-
const call = (c) => get(methods_1.Method.BATCH, {
|
|
74
|
+
const call = (c) => get(methods_1.Method.BATCH, { searchParams: (0, exports.prepareCommandsQueries)(c) })
|
|
42
75
|
.then(({ body }) => body);
|
|
43
|
-
const calls = exports.chunkCommands(commands, commandsPerRequest)
|
|
76
|
+
const calls = (0, exports.chunkCommands)(commands, commandsPerRequest)
|
|
44
77
|
.map(call);
|
|
45
|
-
return Promise.all(calls)
|
|
78
|
+
return await Promise.all(calls)
|
|
46
79
|
.then((chunkedPayloads) => {
|
|
47
|
-
const payloads = exports.mergeBatchPayloads(chunkedPayloads);
|
|
48
|
-
return call_1.handlePayload(payloads);
|
|
80
|
+
const payloads = (0, exports.mergeBatchPayloads)(chunkedPayloads);
|
|
81
|
+
return (0, call_1.handlePayload)(payloads);
|
|
49
82
|
});
|
|
50
83
|
};
|
|
51
84
|
return batch;
|
|
52
85
|
};
|
|
53
|
-
//# sourceMappingURL=batch.js.map
|
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
5
18
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
6
19
|
if (mod && mod.__esModule) return mod;
|
|
7
20
|
var result = {};
|
|
8
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result
|
|
9
|
-
result
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
10
23
|
return result;
|
|
11
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
12
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
29
|
const got_1 = __importDefault(require("got"));
|
|
14
30
|
const lodash_range_1 = __importDefault(require("lodash.range"));
|
|
@@ -25,7 +41,7 @@ describe('Client `chunkCommands` method', () => {
|
|
|
25
41
|
d: { method: methods_1.Method.CRM_LEAD_LIST },
|
|
26
42
|
e: { method: methods_1.Method.CRM_STATUS_LIST }
|
|
27
43
|
};
|
|
28
|
-
expect(batch_1.chunkCommands(commands, chunkSize)).toMatchSnapshot();
|
|
44
|
+
expect((0, batch_1.chunkCommands)(commands, chunkSize)).toMatchSnapshot();
|
|
29
45
|
});
|
|
30
46
|
it('should chunk array of commands', () => {
|
|
31
47
|
const chunkSize = 2;
|
|
@@ -36,13 +52,16 @@ describe('Client `chunkCommands` method', () => {
|
|
|
36
52
|
{ method: methods_1.Method.CRM_LEAD_LIST },
|
|
37
53
|
{ method: methods_1.Method.CRM_STATUS_LIST }
|
|
38
54
|
];
|
|
39
|
-
expect(batch_1.chunkCommands(commands, chunkSize)).toMatchSnapshot();
|
|
55
|
+
expect((0, batch_1.chunkCommands)(commands, chunkSize)).toMatchSnapshot();
|
|
40
56
|
});
|
|
41
57
|
it('should by default chunk with a size of `MAX_COMMANDS_PER_BATCH`', () => {
|
|
42
58
|
const commandsSets = 2;
|
|
43
|
-
const commands = lodash_range_1.default(0, batch_1.MAX_COMMANDS_PER_BATCH * commandsSets).map(() => ({
|
|
44
|
-
|
|
59
|
+
const commands = (0, lodash_range_1.default)(0, batch_1.MAX_COMMANDS_PER_BATCH * commandsSets).map(() => ({
|
|
60
|
+
method: methods_1.Method.CRM_DEAL_GET
|
|
61
|
+
}));
|
|
62
|
+
const chunked = (0, batch_1.chunkCommands)(commands);
|
|
45
63
|
expect(chunked.length).toBe(commandsSets);
|
|
64
|
+
// @ts-ignore we have asserted it length
|
|
46
65
|
expect(chunked[0].length).toBe(batch_1.MAX_COMMANDS_PER_BATCH);
|
|
47
66
|
});
|
|
48
67
|
});
|
|
@@ -64,24 +83,21 @@ describe('Client `prepareCommandsQueries` method', () => {
|
|
|
64
83
|
}
|
|
65
84
|
}
|
|
66
85
|
};
|
|
67
|
-
expect(batch_1.prepareCommandsQueries(commands)).toMatchSnapshot();
|
|
86
|
+
expect((0, batch_1.prepareCommandsQueries)(commands)).toMatchSnapshot();
|
|
68
87
|
});
|
|
69
88
|
it('should work with numbered commands', () => {
|
|
70
89
|
const commands = {
|
|
71
90
|
0: { method: methods_1.Method.CRM_DEAL_GET },
|
|
72
91
|
1: { method: methods_1.Method.CRM_DEAL_LIST }
|
|
73
92
|
};
|
|
74
|
-
expect(batch_1.prepareCommandsQueries(commands)).toMatchSnapshot();
|
|
93
|
+
expect((0, batch_1.prepareCommandsQueries)(commands)).toMatchSnapshot();
|
|
75
94
|
});
|
|
76
95
|
it('should work with array of commands', () => {
|
|
77
|
-
const commands = [
|
|
78
|
-
|
|
79
|
-
{ method: methods_1.Method.CRM_DEAL_LIST }
|
|
80
|
-
];
|
|
81
|
-
expect(batch_1.prepareCommandsQueries(commands)).toMatchSnapshot();
|
|
96
|
+
const commands = [{ method: methods_1.Method.CRM_DEAL_GET }, { method: methods_1.Method.CRM_DEAL_LIST }];
|
|
97
|
+
expect((0, batch_1.prepareCommandsQueries)(commands)).toMatchSnapshot();
|
|
82
98
|
});
|
|
83
99
|
it('should return empty query object when no commands provided', () => {
|
|
84
|
-
expect(batch_1.prepareCommandsQueries({})).toMatchSnapshot();
|
|
100
|
+
expect((0, batch_1.prepareCommandsQueries)({})).toMatchSnapshot();
|
|
85
101
|
});
|
|
86
102
|
});
|
|
87
103
|
describe('Client `mergeBatchPayloads` method', () => {
|
|
@@ -160,7 +176,7 @@ describe('Client `mergeBatchPayloads` method', () => {
|
|
|
160
176
|
date_finish: '2019-08-30T23:28:13+03:00'
|
|
161
177
|
}
|
|
162
178
|
};
|
|
163
|
-
expect(batch_1.mergeBatchPayloads([batch1, batch2])).toMatchSnapshot();
|
|
179
|
+
expect((0, batch_1.mergeBatchPayloads)([batch1, batch2])).toMatchSnapshot();
|
|
164
180
|
});
|
|
165
181
|
it('should merge array payloads', () => {
|
|
166
182
|
const batch1 = {
|
|
@@ -172,21 +188,24 @@ describe('Client `mergeBatchPayloads` method', () => {
|
|
|
172
188
|
result_error: [],
|
|
173
189
|
result_total: [8, 8],
|
|
174
190
|
result_next: [2, 4],
|
|
175
|
-
result_time: [
|
|
191
|
+
result_time: [
|
|
192
|
+
{
|
|
176
193
|
start: 1567196891.008149,
|
|
177
194
|
finish: 1567196891.022234,
|
|
178
195
|
duration: 0.014085054397583008,
|
|
179
196
|
processing: 0.013998985290527344,
|
|
180
197
|
date_start: '2019-08-30T23:28:11+03:00',
|
|
181
198
|
date_finish: '2019-08-30T23:28:11+03:00'
|
|
182
|
-
},
|
|
199
|
+
},
|
|
200
|
+
{
|
|
183
201
|
start: 1567196891.022316,
|
|
184
202
|
finish: 1567196891.03225,
|
|
185
203
|
duration: 0.009933948516845703,
|
|
186
204
|
processing: 0.009846210479736328,
|
|
187
205
|
date_start: '2019-08-30T23:28:11+03:00',
|
|
188
206
|
date_finish: '2019-08-30T23:28:11+03:00'
|
|
189
|
-
}
|
|
207
|
+
}
|
|
208
|
+
]
|
|
190
209
|
},
|
|
191
210
|
time: {
|
|
192
211
|
start: 1567196890.959017,
|
|
@@ -206,21 +225,24 @@ describe('Client `mergeBatchPayloads` method', () => {
|
|
|
206
225
|
result_error: [],
|
|
207
226
|
result_total: [8, 8],
|
|
208
227
|
result_next: [6, 8],
|
|
209
|
-
result_time: [
|
|
228
|
+
result_time: [
|
|
229
|
+
{
|
|
210
230
|
start: 1567196891.032315,
|
|
211
231
|
finish: 1567196891.035297,
|
|
212
232
|
duration: 0.002981901168823242,
|
|
213
233
|
processing: 0.002897024154663086,
|
|
214
234
|
date_start: '2019-08-30T23:28:11+03:00',
|
|
215
235
|
date_finish: '2019-08-30T23:28:11+03:00'
|
|
216
|
-
},
|
|
236
|
+
},
|
|
237
|
+
{
|
|
217
238
|
start: 1567196891.03536,
|
|
218
239
|
finish: 1567196891.039936,
|
|
219
240
|
duration: 0.004575967788696289,
|
|
220
241
|
processing: 0.00450897216796875,
|
|
221
242
|
date_start: '2019-08-30T23:28:11+03:00',
|
|
222
243
|
date_finish: '2019-08-30T23:28:11+03:00'
|
|
223
|
-
}
|
|
244
|
+
}
|
|
245
|
+
]
|
|
224
246
|
},
|
|
225
247
|
time: {
|
|
226
248
|
start: 1567196890.959517,
|
|
@@ -231,12 +253,12 @@ describe('Client `mergeBatchPayloads` method', () => {
|
|
|
231
253
|
date_finish: '2019-08-30T23:28:13+03:00'
|
|
232
254
|
}
|
|
233
255
|
};
|
|
234
|
-
expect(batch_1.mergeBatchPayloads([batch1, batch2])).toMatchSnapshot();
|
|
256
|
+
expect((0, batch_1.mergeBatchPayloads)([batch1, batch2])).toMatchSnapshot();
|
|
235
257
|
});
|
|
236
258
|
});
|
|
237
259
|
const TEST_URI = 'https://test.com/rest';
|
|
238
|
-
const batch = batch_1.default({
|
|
239
|
-
get: got_1.default.extend({
|
|
260
|
+
const batch = (0, batch_1.default)({
|
|
261
|
+
get: got_1.default.extend({ prefixUrl: TEST_URI, responseType: 'json' }).get
|
|
240
262
|
});
|
|
241
263
|
const RESPONSE_200 = 200;
|
|
242
264
|
describe('Client `batch` method', () => {
|
|
@@ -247,7 +269,10 @@ describe('Client `batch` method', () => {
|
|
|
247
269
|
one: { method: methods_1.Method.CRM_DEAL_GET, params: { ID: dealId } },
|
|
248
270
|
two: { method: methods_1.Method.CRM_DEAL_LIST }
|
|
249
271
|
};
|
|
250
|
-
const scope = nock_1.default(TEST_URI)
|
|
272
|
+
const scope = (0, nock_1.default)(TEST_URI)
|
|
273
|
+
// @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
|
|
274
|
+
// fails to match request when it contains `cmd[someName]`. The issue definitely connected
|
|
275
|
+
// to the `[]`, since it does not appear when only one bracket present
|
|
251
276
|
.get(`/${methods_1.Method.BATCH}?cmd%5Bone%5D=${commands.one.method}%3FID%3D${dealId}&cmd%5Btwo%5D=${commands.two.method}`)
|
|
252
277
|
.reply(RESPONSE_200, payload);
|
|
253
278
|
await batch(commands);
|
|
@@ -260,7 +285,10 @@ describe('Client `batch` method', () => {
|
|
|
260
285
|
0: { method: methods_1.Method.CRM_DEAL_GET, params: { ID: dealId } },
|
|
261
286
|
1: { method: methods_1.Method.CRM_DEAL_LIST }
|
|
262
287
|
};
|
|
263
|
-
const scope = nock_1.default(TEST_URI)
|
|
288
|
+
const scope = (0, nock_1.default)(TEST_URI)
|
|
289
|
+
// @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
|
|
290
|
+
// fails to match request when it contains `cmd[someName]`. The issue definitely
|
|
291
|
+
// connected to the `[]` since it does not appear when only one bracket present
|
|
264
292
|
.get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[0].method}%3FID%3D${dealId}&cmd%5B1%5D=${commands[1].method}`)
|
|
265
293
|
.reply(RESPONSE_200, payload);
|
|
266
294
|
await batch(commands);
|
|
@@ -273,7 +301,10 @@ describe('Client `batch` method', () => {
|
|
|
273
301
|
{ method: methods_1.Method.CRM_DEAL_GET, params: { ID: dealId } },
|
|
274
302
|
{ method: methods_1.Method.CRM_DEAL_LIST }
|
|
275
303
|
];
|
|
276
|
-
const scope = nock_1.default(TEST_URI)
|
|
304
|
+
const scope = (0, nock_1.default)(TEST_URI)
|
|
305
|
+
// @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
|
|
306
|
+
// fails to match request when it contains `cmd[someName]`. The issue definitely
|
|
307
|
+
// connected to the `[]` since it does not appear when only one bracket present
|
|
277
308
|
.get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[0].method}%3FID%3D${dealId}&cmd%5B1%5D=${commands[1].method}`)
|
|
278
309
|
.reply(RESPONSE_200, payload);
|
|
279
310
|
await batch(commands);
|
|
@@ -287,7 +318,10 @@ describe('Client `batch` method', () => {
|
|
|
287
318
|
one: { method: methods_1.Method.CRM_DEAL_GET, params: { ID: dealId } },
|
|
288
319
|
two: { method: methods_1.Method.CRM_DEAL_LIST }
|
|
289
320
|
};
|
|
290
|
-
const scope = nock_1.default(TEST_URI)
|
|
321
|
+
const scope = (0, nock_1.default)(TEST_URI)
|
|
322
|
+
// @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
|
|
323
|
+
// fails to match request when it contains `cmd[someName]`. The issue definitely connected
|
|
324
|
+
// to the `[]`, since it does not appear when only one bracket present
|
|
291
325
|
.get(`/${methods_1.Method.BATCH}?cmd%5Bone%5D=${commands.one.method}%3FID%3D${dealId}`)
|
|
292
326
|
.reply(RESPONSE_200, payload)
|
|
293
327
|
.get(`/${methods_1.Method.BATCH}?cmd%5Btwo%5D=${commands.two.method}`)
|
|
@@ -303,7 +337,10 @@ describe('Client `batch` method', () => {
|
|
|
303
337
|
0: { method: methods_1.Method.CRM_DEAL_GET, params: { ID: dealId } },
|
|
304
338
|
1: { method: methods_1.Method.CRM_DEAL_LIST }
|
|
305
339
|
};
|
|
306
|
-
const scope = nock_1.default(TEST_URI)
|
|
340
|
+
const scope = (0, nock_1.default)(TEST_URI)
|
|
341
|
+
// @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
|
|
342
|
+
// fails to match request when it contains `cmd[someName]`. The issue definitely
|
|
343
|
+
// connected to the `[]` since it does not appear when only one bracket present
|
|
307
344
|
.get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[0].method}%3FID%3D${dealId}`)
|
|
308
345
|
.reply(RESPONSE_200, payload)
|
|
309
346
|
.get(`/${methods_1.Method.BATCH}?cmd%5B1%5D=${commands[1].method}`)
|
|
@@ -319,7 +356,10 @@ describe('Client `batch` method', () => {
|
|
|
319
356
|
{ method: methods_1.Method.CRM_DEAL_GET, params: { ID: dealId } },
|
|
320
357
|
{ method: methods_1.Method.CRM_DEAL_LIST }
|
|
321
358
|
];
|
|
322
|
-
const scope = nock_1.default(TEST_URI)
|
|
359
|
+
const scope = (0, nock_1.default)(TEST_URI)
|
|
360
|
+
// @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
|
|
361
|
+
// fails to match request when it contains `cmd[someName]`. The issue definitely
|
|
362
|
+
// connected to the `[]` since it does not appear when only one bracket present
|
|
323
363
|
.get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[0].method}%3FID%3D${dealId}`)
|
|
324
364
|
.reply(RESPONSE_200, payload)
|
|
325
365
|
.get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[1].method}`)
|
|
@@ -342,11 +382,15 @@ describe('Client `batch` method', () => {
|
|
|
342
382
|
},
|
|
343
383
|
time: {}
|
|
344
384
|
};
|
|
345
|
-
nock_1.default(TEST_URI)
|
|
385
|
+
(0, nock_1.default)(TEST_URI)
|
|
386
|
+
// @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
|
|
387
|
+
// fails to match request when it contains `cmd[someName]`. The issue definitely connected
|
|
388
|
+
// to the `[]`, since it does not appear when only one bracket present
|
|
346
389
|
.get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[0].method}&cmd%5B1%5D=${commands[1].method}`)
|
|
347
390
|
.reply(RESPONSE_200, payload);
|
|
348
391
|
expect(await batch(commands)).toEqual(payload);
|
|
349
392
|
});
|
|
393
|
+
// @todo Test this also for named and numbered commands
|
|
350
394
|
it('should merge payloads when more then max allowed commands provided', async () => {
|
|
351
395
|
const maxAllowedCommands = 1;
|
|
352
396
|
const commands = {
|
|
@@ -373,7 +417,10 @@ describe('Client `batch` method', () => {
|
|
|
373
417
|
},
|
|
374
418
|
time: {}
|
|
375
419
|
};
|
|
376
|
-
nock_1.default(TEST_URI)
|
|
420
|
+
(0, nock_1.default)(TEST_URI)
|
|
421
|
+
// @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
|
|
422
|
+
// fails to match request when it contains `cmd[someName]`. The issue definitely connected
|
|
423
|
+
// to the `[]`, since it does not appear when only one bracket present
|
|
377
424
|
.get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[0].method}`)
|
|
378
425
|
.reply(RESPONSE_200, payload1)
|
|
379
426
|
.get(`/${methods_1.Method.BATCH}?cmd%5B1%5D=${commands[1].method}`)
|
|
@@ -395,7 +442,10 @@ describe('Client `batch` method', () => {
|
|
|
395
442
|
one: { method: methods_1.Method.CRM_DEAL_GET },
|
|
396
443
|
two: { method: methods_1.Method.CRM_DEAL_LIST }
|
|
397
444
|
};
|
|
398
|
-
nock_1.default(TEST_URI)
|
|
445
|
+
(0, nock_1.default)(TEST_URI)
|
|
446
|
+
// @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
|
|
447
|
+
// fails to match request when it contains `cmd[someName]`. The issue definitely connected
|
|
448
|
+
// to the `[]`, since it does not appear when only one bracket present
|
|
399
449
|
.get(`/${methods_1.Method.BATCH}?cmd%5Bone%5D=${commands.one.method}&cmd%5Btwo%5D=${commands.two.method}`)
|
|
400
450
|
.reply(RESPONSE_200, payload);
|
|
401
451
|
return expect(batch(commands)).rejects.toMatchSnapshot();
|
|
@@ -404,14 +454,20 @@ describe('Client `batch` method', () => {
|
|
|
404
454
|
const payload = {
|
|
405
455
|
result: {
|
|
406
456
|
result: ['done'],
|
|
407
|
-
result_error: [
|
|
457
|
+
result_error: [
|
|
458
|
+
'Expected error from numbered `batch` 0',
|
|
459
|
+
'Expected error from numbered `batch` 1'
|
|
460
|
+
]
|
|
408
461
|
}
|
|
409
462
|
};
|
|
410
463
|
const commands = {
|
|
411
464
|
0: { method: methods_1.Method.CRM_DEAL_GET },
|
|
412
465
|
1: { method: methods_1.Method.CRM_DEAL_LIST }
|
|
413
466
|
};
|
|
414
|
-
nock_1.default(TEST_URI)
|
|
467
|
+
(0, nock_1.default)(TEST_URI)
|
|
468
|
+
// @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
|
|
469
|
+
// fails to match request when it contains `cmd[someName]`. The issue definitely connected
|
|
470
|
+
// to the `[]`, since it does not appear when only one bracket present
|
|
415
471
|
.get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[0].method}&cmd%5B1%5D=${commands[1].method}`)
|
|
416
472
|
.reply(RESPONSE_200, payload);
|
|
417
473
|
return expect(batch(commands)).rejects.toMatchSnapshot();
|
|
@@ -420,17 +476,19 @@ describe('Client `batch` method', () => {
|
|
|
420
476
|
const payload = {
|
|
421
477
|
result: {
|
|
422
478
|
result: ['done'],
|
|
423
|
-
result_error: [
|
|
479
|
+
result_error: [
|
|
480
|
+
'Expected error from array of command `batch` 0',
|
|
481
|
+
'Expected error from array of command `batch` 1'
|
|
482
|
+
]
|
|
424
483
|
}
|
|
425
484
|
};
|
|
426
|
-
const commands = [
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
485
|
+
const commands = [{ method: methods_1.Method.CRM_DEAL_GET }, { method: methods_1.Method.CRM_DEAL_LIST }];
|
|
486
|
+
(0, nock_1.default)(TEST_URI)
|
|
487
|
+
// @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
|
|
488
|
+
// fails to match request when it contains `cmd[someName]`. The issue definitely connected
|
|
489
|
+
// to the `[]`, since it does not appear when only one bracket present
|
|
431
490
|
.get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[0].method}&cmd%5B1%5D=${commands[1].method}`)
|
|
432
491
|
.reply(RESPONSE_200, payload);
|
|
433
492
|
return expect(batch(commands)).rejects.toMatchSnapshot();
|
|
434
493
|
});
|
|
435
494
|
});
|
|
436
|
-
//# sourceMappingURL=batch.unit.test.js.map
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import got from 'got';
|
|
2
2
|
import { Method, MethodParams, MethodPayload } from '../../methods';
|
|
3
3
|
import { Payload } from '../../payloads';
|
|
4
|
+
/**
|
|
5
|
+
* Checks wether payload have any errors and if it does — throws them
|
|
6
|
+
* Bitrix payload types do not provide discriminators, so we're forced to type cast them
|
|
7
|
+
*/
|
|
4
8
|
export declare const handlePayload: <P extends Payload<unknown>>(payload: P) => P;
|
|
5
9
|
export declare type Call = <M extends Method>(method: M, params: MethodParams<M>) => Promise<MethodPayload<M>>;
|
|
6
|
-
|
|
7
|
-
readonly get:
|
|
8
|
-
}
|
|
10
|
+
declare type Dependencies = {
|
|
11
|
+
readonly get: typeof got.get;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Dispatches a request with specified method and params. Will fill figure out payload type based on the Method
|
|
15
|
+
*/
|
|
9
16
|
declare const _default: ({ get }: Dependencies) => Call;
|
|
10
17
|
export default _default;
|
|
@@ -3,24 +3,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.handlePayload = void 0;
|
|
6
7
|
const qs_1 = require("qs");
|
|
7
8
|
const isArray_1 = __importDefault(require("../../utils/isArray"));
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Checks wether payload have any errors and if it does — throws them
|
|
11
|
+
* Bitrix payload types do not provide discriminators, so we're forced to type cast them
|
|
12
|
+
*/
|
|
13
|
+
const handlePayload = (payload) => {
|
|
14
|
+
var _a;
|
|
9
15
|
if (payload.error) {
|
|
10
|
-
throw new Error(`[call] failed to get the resource: ${payload.error}.`);
|
|
16
|
+
throw new Error(`[call] failed to get the resource: ${(_a = payload.error) !== null && _a !== void 0 ? _a : ''}.`);
|
|
11
17
|
}
|
|
12
18
|
if (payload.result && payload.result.result_error) {
|
|
13
19
|
const resultErrors = payload.result.result_error;
|
|
14
|
-
const errors = isArray_1.default(resultErrors) ? resultErrors : Object.values(resultErrors);
|
|
20
|
+
const errors = (0, isArray_1.default)(resultErrors) ? resultErrors : Object.values(resultErrors);
|
|
15
21
|
if (errors.length > 0) {
|
|
22
|
+
// @todo We can give better formatting to display errored commands. But it's not important for now
|
|
16
23
|
throw new Error(`[batch] failed to process. Received errors in ${errors.length} commands:\n${errors.join('\n')}`);
|
|
17
24
|
}
|
|
18
25
|
}
|
|
19
26
|
return payload;
|
|
20
27
|
};
|
|
28
|
+
exports.handlePayload = handlePayload;
|
|
29
|
+
/**
|
|
30
|
+
* Dispatches a request with specified method and params. Will fill figure out payload type based on the Method
|
|
31
|
+
*/
|
|
21
32
|
exports.default = ({ get }) => {
|
|
22
|
-
const call = (method, params) => get(method, {
|
|
23
|
-
.then(({ body }) => exports.handlePayload(body));
|
|
33
|
+
const call = (method, params) => get(method, { searchParams: (0, qs_1.stringify)(params) })
|
|
34
|
+
.then(({ body }) => (0, exports.handlePayload)(body));
|
|
24
35
|
return call;
|
|
25
36
|
};
|
|
26
|
-
//# sourceMappingURL=call.js.map
|