1
1
const fs = require ( 'fs' ) ;
2
2
const path = require ( 'path' ) ;
3
3
const soap = require ( 'soap' ) ;
4
+ const axios = require ( 'axios' ) ;
4
5
const forge = require ( 'node-forge' ) ;
5
6
const xml2js = require ( 'xml2js' ) ;
6
7
const Mixpanel = require ( 'mixpanel' ) ;
@@ -36,7 +37,6 @@ const RegisterScopeThirteen = require('./Class/RegisterScopeThirteen');
36
37
*
37
38
* @author Afip SDK [email protected]
38
39
* @package Afip
39
- * @version 0.6
40
40
**/
41
41
module . exports = Afip ;
42
42
@@ -280,7 +280,7 @@ Afip.prototype.CreateServiceTA = async function(service) {
280
280
* @param string operation SOAP operation called
281
281
* @param array params Parameters for the ws
282
282
**/
283
- Afip . prototype . TrackUsage = function ( web_service , operation , params = { } ) {
283
+ Afip . prototype . TrackUsage = async function ( web_service , operation , params = { } ) {
284
284
options = { } ;
285
285
286
286
if ( web_service === 'wsfe' && operation === 'FECAESolicitar' ) {
@@ -296,6 +296,38 @@ Afip.prototype.TrackUsage = function(web_service, operation, params = {}) {
296
296
try {
297
297
this . mixpanel . track ( web_service + '.' + operation , Object . assign ( { } , this . mixpanelRegister , options ) ) ;
298
298
} catch ( e ) { }
299
+
300
+ if ( ! this . AdminClient && this . options [ 'production' ] === true ) {
301
+ this . AdminClient = axios . create ( {
302
+ baseURL : 'https://app.afipsdk.com/api/' ,
303
+ timeout : 10000
304
+ } ) ;
305
+
306
+ this . AdminClient . defaults . headers . common [ 'sdk-version-number' ] = '0.7.8' ;
307
+ this . AdminClient . defaults . headers . common [ 'sdk-library' ] = 'javascript' ;
308
+
309
+ if ( this . options [ 'access_token' ] ) {
310
+ this . AdminClient . defaults . headers . common [ 'Authorization' ] = `Bearer ${ this . options [ 'access_token' ] } ` ;
311
+ }
312
+
313
+ try {
314
+ await this . AdminClient . post ( 'v1/sdk-events' , {
315
+ "name" : "initialized" ,
316
+ "properties" : {
317
+ "environment" : this . options [ 'production' ] === true ? "prod" : "dev" ,
318
+ "tax_id" : `${ this . options [ 'CUIT' ] } ` ,
319
+ "afip_sdk_library" : "javascript"
320
+ }
321
+ } ) ;
322
+ } catch ( error ) {
323
+ if ( error . response . data && error . response . data . message ) {
324
+ throw Object . assign ( new Error ( error . response . data . message ) , error . response . data ) ;
325
+ }
326
+ else {
327
+ throw Object . assign ( new Error ( error . response . statusText ) , error . response ) ;
328
+ }
329
+ }
330
+ }
299
331
}
300
332
301
333
/**
0 commit comments