@slavmak2486/bx24ts 1.2.19 → 1.2.21
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/BX24Server.ts +1 -0
- package/BatchHelper.ts +4 -3
- package/base/BX24.ts +28 -23
- package/dist/BX24Server.js +2 -0
- package/dist/BatchHelper.js +3 -2
- package/dist/base/BX24.js +24 -10
- package/package.json +1 -1
- package/tests/batchHelper.test.ts +9 -7
- package/tests/callMethod.test.ts +0 -1
- package/tests/callMethodCb.test.ts +0 -1
package/BX24Server.ts
CHANGED
package/BatchHelper.ts
CHANGED
|
@@ -26,7 +26,7 @@ export class BatchHelper{
|
|
|
26
26
|
if (!dependencies[parent]) {
|
|
27
27
|
dependencies[parent] = [];
|
|
28
28
|
}
|
|
29
|
-
dependencies[parent]
|
|
29
|
+
dependencies[parent]!.push(key);
|
|
30
30
|
})
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -66,8 +66,9 @@ export class BatchHelper{
|
|
|
66
66
|
|
|
67
67
|
for(const dep of deps){
|
|
68
68
|
alradyInBatch.push(dep);
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
const depValue = obj[dep];
|
|
70
|
+
if (!depValue) continue;
|
|
71
|
+
currentChunk[dep] = depValue;
|
|
71
72
|
currentSize++;
|
|
72
73
|
}
|
|
73
74
|
|
package/base/BX24.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type batchCmdElement } from "../types/batchElement";
|
|
2
2
|
import {type eventElement } from "../types/eventElement";
|
|
3
3
|
|
|
4
|
-
import axios, { AxiosError, type AxiosRequestConfig
|
|
4
|
+
import axios, { AxiosError, type AxiosRequestConfig } from 'axios';
|
|
5
5
|
import { CallResult } from "../callResult";
|
|
6
6
|
import {cloneDeep, get as __get} from 'lodash'
|
|
7
7
|
import { type Logger } from "../types/authBaseServe";
|
|
@@ -99,7 +99,7 @@ export abstract class baseBX24{
|
|
|
99
99
|
for (const idx in arrHandler){
|
|
100
100
|
setTimeout(()=>{
|
|
101
101
|
if (!arrHandler[idx]?.handler) return;
|
|
102
|
-
arrHandler[idx]
|
|
102
|
+
arrHandler[idx]!.handler.call(this, params);
|
|
103
103
|
}, 10);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -222,11 +222,7 @@ export abstract class baseBX24{
|
|
|
222
222
|
abstract refreshAuth(cb?:(params:any)=>void):void;
|
|
223
223
|
abstract refreshAuthAsync():Promise<getAuth>;
|
|
224
224
|
|
|
225
|
-
|
|
226
|
-
return typeof xhr.status=='undefined' || (xhr.status >= 200 && xhr.status < 300) || xhr.status === 304 || xhr.status >= 400 && xhr.status < 500 || xhr.status === 1223 || xhr.status === 0;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
protected call(url:string, config:{
|
|
225
|
+
public call(url:string, config:{
|
|
230
226
|
method:string,
|
|
231
227
|
data:any,
|
|
232
228
|
callback?:(params: any)=>void
|
|
@@ -246,12 +242,24 @@ export abstract class baseBX24{
|
|
|
246
242
|
if (this.AUTH_CONNECTOR&&!params.auth_connector){
|
|
247
243
|
params.auth_connector=this.AUTH_CONNECTOR;
|
|
248
244
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
245
|
+
let options:AxiosRequestConfig;
|
|
246
|
+
|
|
247
|
+
if (config.method.startsWith('api/')){
|
|
248
|
+
options=options={
|
|
249
|
+
method: 'POST',
|
|
250
|
+
headers: { 'content-type': 'application/json' },
|
|
251
|
+
data: JSON.stringify(params),
|
|
252
|
+
url:url
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
else{
|
|
256
|
+
options={
|
|
257
|
+
method: 'POST',
|
|
258
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
259
|
+
data: this.getHttpString(params),
|
|
260
|
+
url:url
|
|
261
|
+
};
|
|
262
|
+
}
|
|
255
263
|
|
|
256
264
|
if (this.timeoutCall){
|
|
257
265
|
options.timeout=this.timeoutCall;
|
|
@@ -288,15 +296,11 @@ export abstract class baseBX24{
|
|
|
288
296
|
: false;
|
|
289
297
|
}
|
|
290
298
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
// cmd:batchCmdElement,
|
|
297
|
-
// cb?:((params:{[key:string|number]:CallResult})=>void)|boolean,
|
|
298
|
-
// haltOnError=false):void|Promise<{[key:string|number]:CallResult
|
|
299
|
-
// }>
|
|
299
|
+
public setProxyUrl(url:string){
|
|
300
|
+
if (!url.startsWith('http')) throw new Error('URL INCORRECT. HOT HAVE PROTOCOL');
|
|
301
|
+
this.url=`${url}/`
|
|
302
|
+
}
|
|
303
|
+
|
|
300
304
|
callBatch<T extends batchCmdElement>(cmd:T, haltOnError?:boolean):Promise<{[key in keyof T]:CallResult}>
|
|
301
305
|
callBatch<T extends batchCmdElement>(cmd:T, cb:(params:{[key in keyof T]:CallResult})=>void):void
|
|
302
306
|
callBatch<T extends batchCmdElement>(cmd:T, cb:(params:{[key in keyof T]:CallResult})=>void, haltOnError:boolean):void
|
|
@@ -466,7 +470,8 @@ export abstract class baseBX24{
|
|
|
466
470
|
callMethod(method:string, params:any):Promise<CallResult>;
|
|
467
471
|
callMethod(method:string, params:any, cb?:(params:CallResult)=>void):void;
|
|
468
472
|
callMethod(method:string, params:any, cb?:(params:CallResult)=>void):void|Promise<CallResult>{
|
|
469
|
-
const
|
|
473
|
+
const methodToCall=method.startsWith('api/')?method:`${method}.json`;
|
|
474
|
+
const url=this.url?`${this.url}${methodToCall}`:`http${this.PROTOCOL?'s':''}://${this.DOMAIN}${this.PATH}/${methodToCall}`;
|
|
470
475
|
|
|
471
476
|
if (!cb){
|
|
472
477
|
if (this.AUTH_EXPIRES<(new Date()).valueOf()){
|
package/dist/BX24Server.js
CHANGED
package/dist/BatchHelper.js
CHANGED
|
@@ -60,9 +60,10 @@ class BatchHelper {
|
|
|
60
60
|
const deps = dependencies[key] || [];
|
|
61
61
|
for (const dep of deps) {
|
|
62
62
|
alradyInBatch.push(dep);
|
|
63
|
-
|
|
63
|
+
const depValue = obj[dep];
|
|
64
|
+
if (!depValue)
|
|
64
65
|
continue;
|
|
65
|
-
currentChunk[dep] =
|
|
66
|
+
currentChunk[dep] = depValue;
|
|
66
67
|
currentSize++;
|
|
67
68
|
}
|
|
68
69
|
currentSize++;
|
package/dist/base/BX24.js
CHANGED
|
@@ -198,9 +198,6 @@ class baseBX24 {
|
|
|
198
198
|
}
|
|
199
199
|
return;
|
|
200
200
|
}
|
|
201
|
-
callSuccess(xhr) {
|
|
202
|
-
return typeof xhr.status == 'undefined' || (xhr.status >= 200 && xhr.status < 300) || xhr.status === 304 || xhr.status >= 400 && xhr.status < 500 || xhr.status === 1223 || xhr.status === 0;
|
|
203
|
-
}
|
|
204
201
|
call(url, config) {
|
|
205
202
|
if (this.logger) {
|
|
206
203
|
this.logger.log(`Вызов: ${url}`, {
|
|
@@ -214,12 +211,23 @@ class baseBX24 {
|
|
|
214
211
|
if (this.AUTH_CONNECTOR && !params.auth_connector) {
|
|
215
212
|
params.auth_connector = this.AUTH_CONNECTOR;
|
|
216
213
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
214
|
+
let options;
|
|
215
|
+
if (config.method.startsWith('api/')) {
|
|
216
|
+
options = options = {
|
|
217
|
+
method: 'POST',
|
|
218
|
+
headers: { 'content-type': 'application/json' },
|
|
219
|
+
data: JSON.stringify(params),
|
|
220
|
+
url: url
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
options = {
|
|
225
|
+
method: 'POST',
|
|
226
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
227
|
+
data: this.getHttpString(params),
|
|
228
|
+
url: url
|
|
229
|
+
};
|
|
230
|
+
}
|
|
223
231
|
if (this.timeoutCall) {
|
|
224
232
|
options.timeout = this.timeoutCall;
|
|
225
233
|
}
|
|
@@ -254,6 +262,11 @@ class baseBX24 {
|
|
|
254
262
|
? { access_token: this.AUTH_ID, refresh_token: this.REFRESH_ID, expires_in: this.AUTH_EXPIRES, domain: this.DOMAIN, member_id: this.MEMBER_ID }
|
|
255
263
|
: false;
|
|
256
264
|
}
|
|
265
|
+
setProxyUrl(url) {
|
|
266
|
+
if (!url.startsWith('http'))
|
|
267
|
+
throw new Error('URL INCORRECT. HOT HAVE PROTOCOL');
|
|
268
|
+
this.url = `${url}/`;
|
|
269
|
+
}
|
|
257
270
|
callBatch(cmd, cb, haltOnError = false) {
|
|
258
271
|
const startCb = cb;
|
|
259
272
|
const startHaltOnError = haltOnError;
|
|
@@ -391,7 +404,8 @@ class baseBX24 {
|
|
|
391
404
|
return result;
|
|
392
405
|
}
|
|
393
406
|
callMethod(method, params, cb) {
|
|
394
|
-
const
|
|
407
|
+
const methodToCall = method.startsWith('api/') ? method : `${method}.json`;
|
|
408
|
+
const url = this.url ? `${this.url}${methodToCall}` : `http${this.PROTOCOL ? 's' : ''}://${this.DOMAIN}${this.PATH}/${methodToCall}`;
|
|
395
409
|
if (!cb) {
|
|
396
410
|
if (this.AUTH_EXPIRES < (new Date()).valueOf()) {
|
|
397
411
|
return new Promise((resolve, reject) => {
|
package/package.json
CHANGED
|
@@ -82,21 +82,23 @@ test('real test', async ()=>{
|
|
|
82
82
|
|
|
83
83
|
const batchRaw=helper.getArrBatches()[0];
|
|
84
84
|
|
|
85
|
+
if (!batchRaw) return;
|
|
86
|
+
|
|
85
87
|
const result=await bx24.callBatch(batchRaw);
|
|
86
88
|
for (const request in result){
|
|
87
89
|
switch (request) {
|
|
88
90
|
case 'getDeals':
|
|
89
|
-
expect(result[request]
|
|
90
|
-
expect(result[request]
|
|
91
|
-
expect(result[request]
|
|
91
|
+
expect(result[request]!.data()).toEqual(batch.result.result.getDeals);
|
|
92
|
+
expect(result[request]!.total()).toEqual(batch.result.result_total.getDeals);
|
|
93
|
+
expect(result[request]!.error()).toBeUndefined();
|
|
92
94
|
break;
|
|
93
95
|
case 'getLeads':
|
|
94
|
-
expect(result[request]
|
|
95
|
-
expect(result[request]
|
|
96
|
-
expect(result[request]
|
|
96
|
+
expect(result[request]!.data()).toEqual(leadList.result);
|
|
97
|
+
expect(result[request]!.total()).toEqual(leadList.total);
|
|
98
|
+
expect(result[request]!.error()).toBeUndefined();
|
|
97
99
|
break;
|
|
98
100
|
case 'getByID':{
|
|
99
|
-
expect(result[request]
|
|
101
|
+
expect(result[request]!.error()).toEqual({
|
|
100
102
|
status: 200,
|
|
101
103
|
ex: { error: '', error_description: 'Not found' }
|
|
102
104
|
});
|
package/tests/callMethod.test.ts
CHANGED