Skip to content

Commit 140595c

Browse files
committed
Update tracking
1 parent e348774 commit 140595c

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

package-lock.json

Lines changed: 26 additions & 0 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+
"axios": "^0.19.0",
2627
"mixpanel": "^0.17.0",
2728
"node-forge": "^1.0.0",
2829
"soap": "^0.24.0",

src/Afip.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require('fs');
22
const path = require('path');
33
const soap = require('soap');
4+
const axios = require('axios');
45
const forge = require('node-forge');
56
const xml2js = require('xml2js');
67
const Mixpanel = require('mixpanel');
@@ -36,7 +37,6 @@ const RegisterScopeThirteen = require('./Class/RegisterScopeThirteen');
3637
*
3738
* @author Afip SDK [email protected]
3839
* @package Afip
39-
* @version 0.6
4040
**/
4141
module.exports = Afip;
4242

@@ -280,7 +280,7 @@ Afip.prototype.CreateServiceTA = async function(service) {
280280
* @param string operation SOAP operation called
281281
* @param array params Parameters for the ws
282282
**/
283-
Afip.prototype.TrackUsage = function(web_service, operation, params = {}) {
283+
Afip.prototype.TrackUsage = async function(web_service, operation, params = {}) {
284284
options = {};
285285

286286
if (web_service === 'wsfe' && operation === 'FECAESolicitar') {
@@ -296,6 +296,38 @@ Afip.prototype.TrackUsage = function(web_service, operation, params = {}) {
296296
try {
297297
this.mixpanel.track(web_service+'.'+operation, Object.assign({}, this.mixpanelRegister, options));
298298
} 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+
}
299331
}
300332

301333
/**

src/Class/AfipWebService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ module.exports = class AfipWebService {
139139
this.soapClient.setEndpoint(this.URL);
140140
}
141141

142+
await this.afip.TrackUsage(this.options['service'], operation, params);
143+
142144
// Call to SOAP method
143145
let [ result ] = await this.soapClient[operation+'Async'](params);
144146

145-
this.afip.TrackUsage(this.options['service'], operation, params);
146-
147147
//Return response parsed as JSON
148148
return result;
149149
}

0 commit comments

Comments
 (0)