@slavmak2486/bx24ts 1.2.19 → 1.2.20
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 +26 -17
- package/dist/BX24Server.js +2 -0
- package/dist/BatchHelper.js +3 -2
- package/dist/base/BX24.js +83 -66
- 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
|
@@ -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
|
}
|
|
@@ -246,12 +246,24 @@ export abstract class baseBX24{
|
|
|
246
246
|
if (this.AUTH_CONNECTOR&&!params.auth_connector){
|
|
247
247
|
params.auth_connector=this.AUTH_CONNECTOR;
|
|
248
248
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
249
|
+
let options:AxiosRequestConfig;
|
|
250
|
+
|
|
251
|
+
if (config.method.startsWith('api/')){
|
|
252
|
+
options=options={
|
|
253
|
+
method: 'POST',
|
|
254
|
+
headers: { 'content-type': 'application/json' },
|
|
255
|
+
data: JSON.stringify(params),
|
|
256
|
+
url:url
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
else{
|
|
260
|
+
options={
|
|
261
|
+
method: 'POST',
|
|
262
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
263
|
+
data: this.getHttpString(params),
|
|
264
|
+
url:url
|
|
265
|
+
};
|
|
266
|
+
}
|
|
255
267
|
|
|
256
268
|
if (this.timeoutCall){
|
|
257
269
|
options.timeout=this.timeoutCall;
|
|
@@ -288,15 +300,11 @@ export abstract class baseBX24{
|
|
|
288
300
|
: false;
|
|
289
301
|
}
|
|
290
302
|
|
|
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
|
-
// }>
|
|
303
|
+
public setProxyUrl(url:string){
|
|
304
|
+
if (!url.startsWith('http')) throw new Error('URL INCORRECT. HOT HAVE PROTOCOL');
|
|
305
|
+
this.url=`${url}/`
|
|
306
|
+
}
|
|
307
|
+
|
|
300
308
|
callBatch<T extends batchCmdElement>(cmd:T, haltOnError?:boolean):Promise<{[key in keyof T]:CallResult}>
|
|
301
309
|
callBatch<T extends batchCmdElement>(cmd:T, cb:(params:{[key in keyof T]:CallResult})=>void):void
|
|
302
310
|
callBatch<T extends batchCmdElement>(cmd:T, cb:(params:{[key in keyof T]:CallResult})=>void, haltOnError:boolean):void
|
|
@@ -466,7 +474,8 @@ export abstract class baseBX24{
|
|
|
466
474
|
callMethod(method:string, params:any):Promise<CallResult>;
|
|
467
475
|
callMethod(method:string, params:any, cb?:(params:CallResult)=>void):void;
|
|
468
476
|
callMethod(method:string, params:any, cb?:(params:CallResult)=>void):void|Promise<CallResult>{
|
|
469
|
-
const
|
|
477
|
+
const methodToCall=method.startsWith('api/')?method:`${method}.json`;
|
|
478
|
+
const url=this.url?`${this.url}${methodToCall}`:`http${this.PROTOCOL?'s':''}://${this.DOMAIN}${this.PATH}/${methodToCall}`;
|
|
470
479
|
|
|
471
480
|
if (!cb){
|
|
472
481
|
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
|
@@ -8,65 +8,6 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
8
8
|
const callResult_1 = require("../callResult");
|
|
9
9
|
const lodash_1 = require("lodash");
|
|
10
10
|
class baseBX24 {
|
|
11
|
-
getHttpString(value, prefix = '') {
|
|
12
|
-
if (value instanceof Date) {
|
|
13
|
-
return prefix + '=' + encodeURIComponent(value.toISOString());
|
|
14
|
-
}
|
|
15
|
-
else if (typeof value == 'object') {
|
|
16
|
-
const resultObj = [];
|
|
17
|
-
for (const field in value) {
|
|
18
|
-
resultObj.push(this.getHttpString(value[field], prefix + `${prefix != '' ? '[' : ""}${field}${prefix != '' ? ']' : ''}`));
|
|
19
|
-
}
|
|
20
|
-
return resultObj.join('&');
|
|
21
|
-
}
|
|
22
|
-
else if (prefix != '') {
|
|
23
|
-
return encodeURIComponent(prefix) + '=' + encodeURIComponent(value);
|
|
24
|
-
}
|
|
25
|
-
return encodeURIComponent(value);
|
|
26
|
-
}
|
|
27
|
-
setTimeoutCall(ms) {
|
|
28
|
-
this.timeoutCall = ms;
|
|
29
|
-
}
|
|
30
|
-
clearTimeoutCall() {
|
|
31
|
-
this.timeoutCall = 0;
|
|
32
|
-
}
|
|
33
|
-
isFunction(item) {
|
|
34
|
-
return item === null ? false : (typeof (item) == "function" || item instanceof Function);
|
|
35
|
-
}
|
|
36
|
-
addEvent(event, handler) {
|
|
37
|
-
this.arrEvents.push({
|
|
38
|
-
event: event,
|
|
39
|
-
handler: handler
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
emitEvent(event, params) {
|
|
43
|
-
const arrHandler = this.arrEvents.filter(el => { return el.event == event; });
|
|
44
|
-
for (const idx in arrHandler) {
|
|
45
|
-
setTimeout(() => {
|
|
46
|
-
var _a;
|
|
47
|
-
if (!((_a = arrHandler[idx]) === null || _a === void 0 ? void 0 : _a.handler))
|
|
48
|
-
return;
|
|
49
|
-
arrHandler[idx].handler.call(this, params);
|
|
50
|
-
}, 10);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
uniqid() {
|
|
54
|
-
const charsList = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
55
|
-
let s = '';
|
|
56
|
-
for (let i = 0; i < 32; i++)
|
|
57
|
-
s += charsList[Math.round(Math.random() * (charsList.length - 1))];
|
|
58
|
-
return s;
|
|
59
|
-
}
|
|
60
|
-
setCallback(cb) {
|
|
61
|
-
const cbId = this.uniqid();
|
|
62
|
-
if (cb) {
|
|
63
|
-
this.cbArray.push({ uid: cbId, cb: cb });
|
|
64
|
-
}
|
|
65
|
-
return cbId;
|
|
66
|
-
}
|
|
67
|
-
doInit() {
|
|
68
|
-
this.emitEvent('init', this);
|
|
69
|
-
}
|
|
70
11
|
constructor() {
|
|
71
12
|
this.cbArray = [];
|
|
72
13
|
this.AUTH_CONNECTOR = "";
|
|
@@ -156,6 +97,65 @@ class baseBX24 {
|
|
|
156
97
|
this.DOMAIN = "";
|
|
157
98
|
this.PROTOCOL = 1;
|
|
158
99
|
}
|
|
100
|
+
getHttpString(value, prefix = '') {
|
|
101
|
+
if (value instanceof Date) {
|
|
102
|
+
return prefix + '=' + encodeURIComponent(value.toISOString());
|
|
103
|
+
}
|
|
104
|
+
else if (typeof value == 'object') {
|
|
105
|
+
const resultObj = [];
|
|
106
|
+
for (const field in value) {
|
|
107
|
+
resultObj.push(this.getHttpString(value[field], prefix + `${prefix != '' ? '[' : ""}${field}${prefix != '' ? ']' : ''}`));
|
|
108
|
+
}
|
|
109
|
+
return resultObj.join('&');
|
|
110
|
+
}
|
|
111
|
+
else if (prefix != '') {
|
|
112
|
+
return encodeURIComponent(prefix) + '=' + encodeURIComponent(value);
|
|
113
|
+
}
|
|
114
|
+
return encodeURIComponent(value);
|
|
115
|
+
}
|
|
116
|
+
setTimeoutCall(ms) {
|
|
117
|
+
this.timeoutCall = ms;
|
|
118
|
+
}
|
|
119
|
+
clearTimeoutCall() {
|
|
120
|
+
this.timeoutCall = 0;
|
|
121
|
+
}
|
|
122
|
+
isFunction(item) {
|
|
123
|
+
return item === null ? false : (typeof (item) == "function" || item instanceof Function);
|
|
124
|
+
}
|
|
125
|
+
addEvent(event, handler) {
|
|
126
|
+
this.arrEvents.push({
|
|
127
|
+
event: event,
|
|
128
|
+
handler: handler
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
emitEvent(event, params) {
|
|
132
|
+
const arrHandler = this.arrEvents.filter(el => { return el.event == event; });
|
|
133
|
+
for (const idx in arrHandler) {
|
|
134
|
+
setTimeout(() => {
|
|
135
|
+
var _a;
|
|
136
|
+
if (!((_a = arrHandler[idx]) === null || _a === void 0 ? void 0 : _a.handler))
|
|
137
|
+
return;
|
|
138
|
+
arrHandler[idx].handler.call(this, params);
|
|
139
|
+
}, 10);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
uniqid() {
|
|
143
|
+
const charsList = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
144
|
+
let s = '';
|
|
145
|
+
for (let i = 0; i < 32; i++)
|
|
146
|
+
s += charsList[Math.round(Math.random() * (charsList.length - 1))];
|
|
147
|
+
return s;
|
|
148
|
+
}
|
|
149
|
+
setCallback(cb) {
|
|
150
|
+
const cbId = this.uniqid();
|
|
151
|
+
if (cb) {
|
|
152
|
+
this.cbArray.push({ uid: cbId, cb: cb });
|
|
153
|
+
}
|
|
154
|
+
return cbId;
|
|
155
|
+
}
|
|
156
|
+
doInit() {
|
|
157
|
+
this.emitEvent('init', this);
|
|
158
|
+
}
|
|
159
159
|
utilReady() {
|
|
160
160
|
if (document.readyState === "complete") {
|
|
161
161
|
return this.runReady();
|
|
@@ -214,12 +214,23 @@ class baseBX24 {
|
|
|
214
214
|
if (this.AUTH_CONNECTOR && !params.auth_connector) {
|
|
215
215
|
params.auth_connector = this.AUTH_CONNECTOR;
|
|
216
216
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
217
|
+
let options;
|
|
218
|
+
if (config.method.startsWith('api/')) {
|
|
219
|
+
options = options = {
|
|
220
|
+
method: 'POST',
|
|
221
|
+
headers: { 'content-type': 'application/json' },
|
|
222
|
+
data: JSON.stringify(params),
|
|
223
|
+
url: url
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
options = {
|
|
228
|
+
method: 'POST',
|
|
229
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
230
|
+
data: this.getHttpString(params),
|
|
231
|
+
url: url
|
|
232
|
+
};
|
|
233
|
+
}
|
|
223
234
|
if (this.timeoutCall) {
|
|
224
235
|
options.timeout = this.timeoutCall;
|
|
225
236
|
}
|
|
@@ -254,6 +265,11 @@ class baseBX24 {
|
|
|
254
265
|
? { access_token: this.AUTH_ID, refresh_token: this.REFRESH_ID, expires_in: this.AUTH_EXPIRES, domain: this.DOMAIN, member_id: this.MEMBER_ID }
|
|
255
266
|
: false;
|
|
256
267
|
}
|
|
268
|
+
setProxyUrl(url) {
|
|
269
|
+
if (!url.startsWith('http'))
|
|
270
|
+
throw new Error('URL INCORRECT. HOT HAVE PROTOCOL');
|
|
271
|
+
this.url = `${url}/`;
|
|
272
|
+
}
|
|
257
273
|
callBatch(cmd, cb, haltOnError = false) {
|
|
258
274
|
const startCb = cb;
|
|
259
275
|
const startHaltOnError = haltOnError;
|
|
@@ -391,7 +407,8 @@ class baseBX24 {
|
|
|
391
407
|
return result;
|
|
392
408
|
}
|
|
393
409
|
callMethod(method, params, cb) {
|
|
394
|
-
const
|
|
410
|
+
const methodToCall = method.startsWith('api/') ? method : `${method}.json`;
|
|
411
|
+
const url = this.url ? `${this.url}${methodToCall}` : `http${this.PROTOCOL ? 's' : ''}://${this.DOMAIN}${this.PATH}/${methodToCall}`;
|
|
395
412
|
if (!cb) {
|
|
396
413
|
if (this.AUTH_EXPIRES < (new Date()).valueOf()) {
|
|
397
414
|
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