@slavmak2486/bx24ts 1.0.6 → 1.0.8

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/BX24Dev.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  import { BX24Server } from "./BX24Server";
2
- import { AuthBaseServe} from "./types/authBaseServe";
3
2
  import qs from 'qs';
4
3
  import { set as __set } from "lodash";
4
+ import { AuthBaseDev } from "./types/authBaseDev";
5
5
 
6
6
 
7
7
  export class BX24Dev extends BX24Server{
8
- constructor(param: AuthBaseServe, cb?:()=>void){
9
- super(param, ()=>{
8
+ constructor(param: AuthBaseDev, cb?:()=>void){
9
+ super(param);
10
+
11
+ this.init(()=>{
10
12
  this.callBatch({
11
13
  getAppOption:['app.option.get', {}],
12
14
  getUserOption:['user.option.get', {}]
@@ -29,14 +31,25 @@ export class BX24Dev extends BX24Server{
29
31
  if (cb){
30
32
  cb();
31
33
  }
32
- // this.init(cb);
33
34
  })
34
35
  this.getPlacementOptions();
35
36
  });
36
37
 
37
-
38
+ if (new Date().getTime()-5*60*1000>this.AUTH_EXPIRES && !param.noUpdateRefresh){
39
+ try {
40
+ this.refreshAuth(()=>{
41
+ this.doInit();
42
+ });
43
+ } catch (error) {
44
+ this.logger.error(error);
45
+ }
46
+ }
47
+ else{
48
+ this.doInit();
49
+ }
38
50
  }
39
51
 
52
+
40
53
  appOption={
41
54
  get: (name:string)=>{
42
55
  return this.APP_OPTIONS[name];
package/BX24Server.ts CHANGED
@@ -10,7 +10,7 @@ export class BX24Server extends baseBX24{
10
10
 
11
11
  logger:logger=console;
12
12
 
13
- constructor(param: AuthBaseServe, cb?:(params:any)=>void){
13
+ constructor(param: AuthBaseServe){
14
14
  super();
15
15
 
16
16
  if (param.auth_connector)
@@ -20,7 +20,6 @@ export class BX24Server extends baseBX24{
20
20
  this.logger=param.logger;
21
21
 
22
22
  this.IS_ADMIN=param.isAdmin===false?false:true;
23
- this.init(cb);
24
23
  this.DOMAIN=param.domain;
25
24
  if (param.member_id){
26
25
  this.MEMBER_ID=param.member_id;
@@ -34,20 +33,6 @@ export class BX24Server extends baseBX24{
34
33
  this.CLIENT_ID=param.client_id;
35
34
  this.CLIENT_SECRET=param.client_secret;
36
35
  this.isInit=true;
37
-
38
- if (new Date().getTime()-5*60*1000>this.AUTH_EXPIRES && !param.noUpdateRefresh){
39
- try {
40
- this.refreshAuth(()=>{
41
- this.doInit();
42
- });
43
- } catch (error) {
44
- this.logger.error(error);
45
- }
46
- }
47
- else{
48
- this.doInit();
49
- }
50
-
51
36
  }
52
37
 
53
38
  getOfflineEvents(debug=false, clear=true):Promise<CallResult>{
@@ -127,7 +112,7 @@ export class BX24Server extends baseBX24{
127
112
  if (cb) cb(newAuth);
128
113
  })
129
114
  .catch(err=>{
130
- throw err;
115
+ if (cb) cb(err);
131
116
  });
132
117
  }
133
118
 
package/dist/BX24Dev.js CHANGED
@@ -9,31 +9,7 @@ const qs_1 = __importDefault(require("qs"));
9
9
  const lodash_1 = require("lodash");
10
10
  class BX24Dev extends BX24Server_1.BX24Server {
11
11
  constructor(param, cb) {
12
- super(param, () => {
13
- this.callBatch({
14
- getAppOption: ['app.option.get', {}],
15
- getUserOption: ['user.option.get', {}]
16
- }, ress => {
17
- for (const idx in ress) {
18
- const res = ress[idx];
19
- if (res.error()) {
20
- console.error(res.error());
21
- }
22
- else {
23
- if (idx == 'getAppOption') {
24
- this.APP_OPTIONS = res.data();
25
- }
26
- else {
27
- this.USER_OPTIONS = res.data();
28
- }
29
- }
30
- }
31
- if (cb) {
32
- cb();
33
- }
34
- });
35
- this.getPlacementOptions();
36
- });
12
+ super(param);
37
13
  this.appOption = {
38
14
  get: (name) => {
39
15
  return this.APP_OPTIONS[name];
@@ -73,6 +49,44 @@ class BX24Dev extends BX24Server_1.BX24Server {
73
49
  });
74
50
  }
75
51
  };
52
+ this.init(() => {
53
+ this.callBatch({
54
+ getAppOption: ['app.option.get', {}],
55
+ getUserOption: ['user.option.get', {}]
56
+ }, ress => {
57
+ for (const idx in ress) {
58
+ const res = ress[idx];
59
+ if (res.error()) {
60
+ console.error(res.error());
61
+ }
62
+ else {
63
+ if (idx == 'getAppOption') {
64
+ this.APP_OPTIONS = res.data();
65
+ }
66
+ else {
67
+ this.USER_OPTIONS = res.data();
68
+ }
69
+ }
70
+ }
71
+ if (cb) {
72
+ cb();
73
+ }
74
+ });
75
+ this.getPlacementOptions();
76
+ });
77
+ if (new Date().getTime() - 5 * 60 * 1000 > this.AUTH_EXPIRES && !param.noUpdateRefresh) {
78
+ try {
79
+ this.refreshAuth(() => {
80
+ this.doInit();
81
+ });
82
+ }
83
+ catch (error) {
84
+ this.logger.error(error);
85
+ }
86
+ }
87
+ else {
88
+ this.doInit();
89
+ }
76
90
  }
77
91
  getPlacementOptions() {
78
92
  const result = {};
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BX24Server = void 0;
4
4
  const BX24_1 = require("./base/BX24");
5
5
  class BX24Server extends BX24_1.baseBX24 {
6
- constructor(param, cb) {
6
+ constructor(param) {
7
7
  var _a;
8
8
  super();
9
9
  this.logger = console;
@@ -12,7 +12,6 @@ class BX24Server extends BX24_1.baseBX24 {
12
12
  if (param.logger)
13
13
  this.logger = param.logger;
14
14
  this.IS_ADMIN = param.isAdmin === false ? false : true;
15
- this.init(cb);
16
15
  this.DOMAIN = param.domain;
17
16
  if (param.member_id) {
18
17
  this.MEMBER_ID = param.member_id;
@@ -24,19 +23,6 @@ class BX24Server extends BX24_1.baseBX24 {
24
23
  this.CLIENT_ID = param.client_id;
25
24
  this.CLIENT_SECRET = param.client_secret;
26
25
  this.isInit = true;
27
- if (new Date().getTime() - 5 * 60 * 1000 > this.AUTH_EXPIRES && !param.noUpdateRefresh) {
28
- try {
29
- this.refreshAuth(() => {
30
- this.doInit();
31
- });
32
- }
33
- catch (error) {
34
- this.logger.error(error);
35
- }
36
- }
37
- else {
38
- this.doInit();
39
- }
40
26
  }
41
27
  getOfflineEvents(debug = false, clear = true) {
42
28
  return new Promise((resolve) => {
@@ -89,7 +75,8 @@ class BX24Server extends BX24_1.baseBX24 {
89
75
  cb(newAuth);
90
76
  })
91
77
  .catch(err => {
92
- throw err;
78
+ if (cb)
79
+ cb(err);
93
80
  });
94
81
  }
95
82
  refreshAuthAsync() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slavmak2486/bx24ts",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Library for bitrix24",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,22 @@
1
+ export interface logger{
2
+ log(message: any, ...optionalParams: any[]): any;
3
+ error(message: any, ...optionalParams: any[]): any;
4
+ warn(message: any, ...optionalParams: any[]): any;
5
+ debug(message: any, ...optionalParams: any[]): any;
6
+ verbose?(message: any, ...optionalParams: any[]): any;
7
+ }
8
+
9
+ export interface AuthBaseDev{
10
+ access_token:string;
11
+ domain:string;
12
+ refresh_token:string;
13
+ member_id?:string;
14
+ expires_in?:number;
15
+ client_id:string;
16
+ client_secret:string;
17
+ app?:number;
18
+ isAdmin?:boolean;
19
+ auth_connector?:string;
20
+ logger?:logger,
21
+ noUpdateRefresh?:boolean
22
+ }
@@ -17,6 +17,5 @@ export interface AuthBaseServe{
17
17
  app?:number;
18
18
  isAdmin?:boolean;
19
19
  auth_connector?:string;
20
- logger?:logger,
21
- noUpdateRefresh?:boolean
20
+ logger?:logger
22
21
  }