@@ -42,6 +42,11 @@ const RegisterScopeThirteen = require('./Class/RegisterScopeThirteen');
42
42
module . exports = Afip ;
43
43
44
44
function Afip ( options = { } ) {
45
+ /**
46
+ * SDK version
47
+ **/
48
+ this . sdk_version_number = '0.7.8' ;
49
+
45
50
/**
46
51
* File name for the WSDL corresponding to WSAA
47
52
*
@@ -129,6 +134,20 @@ function Afip(options = {}){
129
134
this . WSAA_URL = 'https://wsaahomo.afip.gov.ar/ws/services/LoginCms' ;
130
135
}
131
136
137
+ // Create an instance of the admin client
138
+ /** @private */
139
+ this . AdminClient = axios . create ( {
140
+ baseURL : 'https://app.afipsdk.com/api/' ,
141
+ timeout : 10000
142
+ } ) ;
143
+
144
+ this . AdminClient . defaults . headers . common [ 'sdk-version-number' ] = this . sdk_version_number ;
145
+ this . AdminClient . defaults . headers . common [ 'sdk-library' ] = 'javascript' ;
146
+
147
+ if ( this . options [ 'access_token' ] ) {
148
+ this . AdminClient . defaults . headers . common [ 'Authorization' ] = `Bearer ${ this . options [ 'access_token' ] } ` ;
149
+ }
150
+
132
151
this . ElectronicBilling = new ElectronicBilling ( this ) ;
133
152
this . RegisterScopeFour = new RegisterScopeFour ( this ) ;
134
153
this . RegisterScopeFive = new RegisterScopeFive ( this ) ;
@@ -302,20 +321,7 @@ Afip.prototype.TrackUsage = async function(web_service, operation, params = {})
302
321
this . mixpanel . track ( web_service + '.' + operation , Object . assign ( { } , this . mixpanelRegister , options ) ) ;
303
322
} catch ( e ) { }
304
323
305
- if ( ! this . AdminClient && this . options [ 'production' ] === true ) {
306
- /** @private */
307
- this . AdminClient = axios . create ( {
308
- baseURL : 'https://app.afipsdk.com/api/' ,
309
- timeout : 10000
310
- } ) ;
311
-
312
- this . AdminClient . defaults . headers . common [ 'sdk-version-number' ] = '0.7.8' ;
313
- this . AdminClient . defaults . headers . common [ 'sdk-library' ] = 'javascript' ;
314
-
315
- if ( this . options [ 'access_token' ] ) {
316
- this . AdminClient . defaults . headers . common [ 'Authorization' ] = `Bearer ${ this . options [ 'access_token' ] } ` ;
317
- }
318
-
324
+ if ( ! this . AdminClientInitialized && this . options [ 'production' ] === true ) {
319
325
try {
320
326
await this . AdminClient . post ( 'v1/sdk-events' , {
321
327
"name" : "initialized" ,
@@ -325,6 +331,9 @@ Afip.prototype.TrackUsage = async function(web_service, operation, params = {})
325
331
"afip_sdk_library" : "javascript"
326
332
}
327
333
} ) ;
334
+
335
+ /** @private */
336
+ this . AdminClientInitialized = true ;
328
337
} catch ( error ) {
329
338
if ( ! error . response ) {
330
339
throw error ;
0 commit comments