@@ -3,6 +3,7 @@ const path = require('path');
3
3
const soap = require ( 'soap' ) ;
4
4
const forge = require ( 'node-forge' ) ;
5
5
const xml2js = require ( 'xml2js' ) ;
6
+ const Mixpanel = require ( 'mixpanel' ) ;
6
7
7
8
// XML parser
8
9
var xmlParser = new xml2js . Parser ( {
@@ -85,9 +86,15 @@ function Afip(options = {}){
85
86
// Create an Afip instance if it is not
86
87
if ( ! ( this instanceof Afip ) ) { return new Afip ( options ) }
87
88
89
+ // Create an instance of the mixpanel client
90
+ this . mixpanel = Mixpanel . init ( 'e87ee11c8cc288e5c5dc213c4d957c7e' ) ;
91
+ this . mixpanelRegister = { } ;
92
+
93
+ this . mixpanelRegister [ 'afip_sdk_library' ] = 'javascript' ;
88
94
89
95
if ( ! options . hasOwnProperty ( 'CUIT' ) ) { throw new Error ( "CUIT field is required in options array" ) ; }
90
96
97
+
91
98
// Define default options
92
99
if ( ! options . hasOwnProperty ( 'production' ) ) { options [ 'production' ] = false ; }
93
100
if ( ! options . hasOwnProperty ( 'cert' ) ) { options [ 'cert' ] = 'cert' ; }
@@ -96,6 +103,13 @@ function Afip(options = {}){
96
103
if ( ! options . hasOwnProperty ( 'ta_folder' ) ) { options [ 'ta_folder' ] = __dirname + '/Afip_res/' ; }
97
104
if ( options [ 'production' ] !== true ) { options [ 'production' ] = false ; }
98
105
106
+ this . mixpanelRegister [ 'distinct_id' ] = options [ 'CUIT' ] ;
107
+ this . mixpanelRegister [ 'production' ] = options [ 'production' ] ;
108
+
109
+ try {
110
+ this . mixpanel . track ( 'initialized' , Object . assign ( { } , this . mixpanelRegister , options ) ) ;
111
+ } catch ( e ) { }
112
+
99
113
this . options = options ;
100
114
101
115
this . CUIT = options [ 'CUIT' ] ;
@@ -258,6 +272,28 @@ Afip.prototype.CreateServiceTA = async function(service) {
258
272
} ) ) ;
259
273
}
260
274
275
+
276
+ /**
277
+ * Track SDK usage
278
+ *
279
+ * @param string web_service ID of the web service used
280
+ * @param string operation SOAP operation called
281
+ * @param array params Parameters for the ws
282
+ **/
283
+ Afip . prototype . TrackUsage = function ( web_service , operation , params = { } ) {
284
+ options = { } ;
285
+
286
+ if ( web_service === 'wsfe' && operation === 'FECAESolicitar' ) {
287
+ if ( params [ 'FeCAEReq' ] && params [ 'FeCAEReq' ] [ 'FeCabReq' ] && params [ 'FeCAEReq' ] [ 'FeCabReq' ] [ 'CbteTipo' ] ) {
288
+ options [ 'CbteTipo' ] = params [ 'FeCAEReq' ] [ 'FeCabReq' ] [ 'CbteTipo' ] ;
289
+ }
290
+ }
291
+
292
+ try {
293
+ this . mixpanel . track ( web_service + '.' + operation , Object . assign ( { } , this . mixpanelRegister , options ) ) ;
294
+ } catch ( e ) { }
295
+ }
296
+
261
297
/**
262
298
* Create generic Web Service
263
299
*
0 commit comments