@slavmak2486/bx24ts 1.2.20 → 1.2.22
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 -1
- package/base/BX24.ts +5 -7
- package/dist/BX24Server.js +1 -1
- package/dist/base/BX24.js +61 -63
- package/package.json +1 -1
package/BX24Server.ts
CHANGED
|
@@ -165,7 +165,7 @@ export class BX24Server extends baseBX24{
|
|
|
165
165
|
|
|
166
166
|
refreshAuthAsync():Promise<getAuth> {
|
|
167
167
|
return new Promise((resolve, reject) => {
|
|
168
|
-
this.call(
|
|
168
|
+
this.call(`https://${this.OAUTH_DOMAIN}/oauth/token/`, {
|
|
169
169
|
method:'refresh_token',
|
|
170
170
|
data:{
|
|
171
171
|
grant_type: 'refresh_token',
|
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";
|
|
@@ -34,6 +34,8 @@ export abstract class baseBX24{
|
|
|
34
34
|
CLIENT_ID: string | undefined="";
|
|
35
35
|
CLIENT_SECRET: string | undefined="";
|
|
36
36
|
|
|
37
|
+
OAUTH_DOMAIN="oauth.bitrix24.tech";
|
|
38
|
+
|
|
37
39
|
isInit=false;
|
|
38
40
|
DOMAIN: string;
|
|
39
41
|
PROTOCOL: number;
|
|
@@ -222,11 +224,7 @@ export abstract class baseBX24{
|
|
|
222
224
|
abstract refreshAuth(cb?:(params:any)=>void):void;
|
|
223
225
|
abstract refreshAuthAsync():Promise<getAuth>;
|
|
224
226
|
|
|
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:{
|
|
227
|
+
public call(url:string, config:{
|
|
230
228
|
method:string,
|
|
231
229
|
data:any,
|
|
232
230
|
callback?:(params: any)=>void
|
|
@@ -278,7 +276,7 @@ export abstract class baseBX24{
|
|
|
278
276
|
if (!err?.response?.data){
|
|
279
277
|
reject(err);
|
|
280
278
|
}
|
|
281
|
-
else if (__get(err, ['response','data','error'], undefined)=='expired_token'&&!url.includes(
|
|
279
|
+
else if (__get(err, ['response','data','error'], undefined)=='expired_token'&&!url.includes(this.OAUTH_DOMAIN)){
|
|
282
280
|
try {
|
|
283
281
|
this.refreshAuth(()=>{
|
|
284
282
|
this.call(url, config).then(resolve).catch(reject);
|
package/dist/BX24Server.js
CHANGED
|
@@ -130,7 +130,7 @@ class BX24Server extends BX24_1.baseBX24 {
|
|
|
130
130
|
}
|
|
131
131
|
refreshAuthAsync() {
|
|
132
132
|
return new Promise((resolve, reject) => {
|
|
133
|
-
this.call(
|
|
133
|
+
this.call(`https://${this.OAUTH_DOMAIN}/oauth/token/`, {
|
|
134
134
|
method: 'refresh_token',
|
|
135
135
|
data: {
|
|
136
136
|
grant_type: 'refresh_token',
|
package/dist/base/BX24.js
CHANGED
|
@@ -8,11 +8,71 @@ 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
|
+
}
|
|
11
70
|
constructor() {
|
|
12
71
|
this.cbArray = [];
|
|
13
72
|
this.AUTH_CONNECTOR = "";
|
|
14
73
|
this.CLIENT_ID = "";
|
|
15
74
|
this.CLIENT_SECRET = "";
|
|
75
|
+
this.OAUTH_DOMAIN = "oauth.bitrix24.tech";
|
|
16
76
|
this.isInit = false;
|
|
17
77
|
this.APP_SID = false;
|
|
18
78
|
this.PATH = "/rest";
|
|
@@ -97,65 +157,6 @@ class baseBX24 {
|
|
|
97
157
|
this.DOMAIN = "";
|
|
98
158
|
this.PROTOCOL = 1;
|
|
99
159
|
}
|
|
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
160
|
utilReady() {
|
|
160
161
|
if (document.readyState === "complete") {
|
|
161
162
|
return this.runReady();
|
|
@@ -198,9 +199,6 @@ class baseBX24 {
|
|
|
198
199
|
}
|
|
199
200
|
return;
|
|
200
201
|
}
|
|
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
202
|
call(url, config) {
|
|
205
203
|
if (this.logger) {
|
|
206
204
|
this.logger.log(`Вызов: ${url}`, {
|
|
@@ -244,7 +242,7 @@ class baseBX24 {
|
|
|
244
242
|
if (!((_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
245
243
|
reject(err);
|
|
246
244
|
}
|
|
247
|
-
else if ((0, lodash_1.get)(err, ['response', 'data', 'error'], undefined) == 'expired_token' && !url.includes(
|
|
245
|
+
else if ((0, lodash_1.get)(err, ['response', 'data', 'error'], undefined) == 'expired_token' && !url.includes(this.OAUTH_DOMAIN)) {
|
|
248
246
|
try {
|
|
249
247
|
this.refreshAuth(() => {
|
|
250
248
|
this.call(url, config).then(resolve).catch(reject);
|