Skip to content

Commit 98f6f7b

Browse files
committed
Add library usage in order to improve it
1 parent 265b10d commit 98f6f7b

9 files changed

+258
-166
lines changed

package-lock.json

Lines changed: 214 additions & 161 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"homepage": "https://github.com/AfipSDK/afip.js#readme",
2525
"dependencies": {
26+
"mixpanel": "^0.17.0",
2627
"node-forge": "^1.0.0",
2728
"soap": "^0.24.0",
2829
"xml2js": "^0.4.22"

src/Afip.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const path = require('path');
33
const soap = require('soap');
44
const forge = require('node-forge');
55
const xml2js = require('xml2js');
6+
const Mixpanel = require('mixpanel');
67

78
// XML parser
89
var xmlParser = new xml2js.Parser({
@@ -85,9 +86,15 @@ function Afip(options = {}){
8586
// Create an Afip instance if it is not
8687
if (!(this instanceof Afip)) {return new Afip(options)}
8788

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';
8894

8995
if (!options.hasOwnProperty('CUIT')) {throw new Error("CUIT field is required in options array");}
9096

97+
9198
// Define default options
9299
if (!options.hasOwnProperty('production')) {options['production'] = false;}
93100
if (!options.hasOwnProperty('cert')) {options['cert'] = 'cert';}
@@ -96,6 +103,13 @@ function Afip(options = {}){
96103
if (!options.hasOwnProperty('ta_folder')) {options['ta_folder'] = __dirname+'/Afip_res/';}
97104
if (options['production'] !== true) {options['production'] = false;}
98105

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+
99113
this.options = options;
100114

101115
this.CUIT = options['CUIT'];
@@ -258,6 +272,28 @@ Afip.prototype.CreateServiceTA = async function(service) {
258272
}));
259273
}
260274

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+
261297
/**
262298
* Create generic Web Service
263299
*

src/Class/AfipWebService.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ module.exports = class AfipWebService {
142142
// Call to SOAP method
143143
let [ result ] = await this.soapClient[operation+'Async'](params);
144144

145+
this.afip.TrackUsage(this.options['service'], operation, params);
146+
145147
//Return response parsed as JSON
146148
return result;
147149
}

src/Class/ElectronicBilling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = class ElectronicBilling extends AfipWebService {
1616
afip
1717
}
1818

19-
super(options);
19+
super(options, { service: 'wsfe' });
2020
}
2121

2222
/**

src/Class/RegisterScopeFive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = class RegisterScopeFive extends AfipWebService {
1616
afip
1717
}
1818

19-
super(options);
19+
super(options, { service: 'ws_sr_padron_a5' });
2020
}
2121
/**
2222
* Asks to web service for servers status {@see WS

src/Class/RegisterScopeFour.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = class RegisterScopeFour extends AfipWebService {
1616
afip
1717
}
1818

19-
super(options);
19+
super(options, { service: 'ws_sr_padron_a4' });
2020
}
2121
/**
2222
* Asks to web service for servers status {@see WS

src/Class/RegisterScopeTen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = class RegisterScopeTen extends AfipWebService {
1616
afip
1717
}
1818

19-
super(options);
19+
super(options, { service: 'ws_sr_padron_a10' });
2020
}
2121
/**
2222
* Asks to web service for servers status {@see WS

src/Class/RegisterScopeThirteen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = class RegisterScopeThirteen extends AfipWebService {
1616
afip
1717
}
1818

19-
super(options);
19+
super(options, { service: 'ws_sr_padron_a13' });
2020
}
2121
/**
2222
* Asks to web service for servers status {@see WS

0 commit comments

Comments
 (0)