Skip to content

Commit 645e947

Browse files
committed
Add typescript definitions
1 parent 229b3fe commit 645e947

11 files changed

+424
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ Link del proyecto: [https://github.com/afipsdk/afip.js](https://github.com/afips
145145

146146
_Este software y sus desarrolladores no tienen ninguna relación con la AFIP._
147147

148-
148+
<!--
149+
Generate Types:
150+
npx -p typescript tsc src/**/*.js --declaration --allowJs --emitDeclarationOnly --outDir types
151+
-->
149152
<!-- MARKDOWN LINKS & IMAGES -->
150153
[npm-shield]: https://img.shields.io/npm/dt/@afipsdk/afip.js.svg
151154
[contributors-shield]: https://img.shields.io/github/contributors/afipsdk/afip.js.svg?color=orange

package-lock.json

Lines changed: 12 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@
3131
},
3232
"engines": {
3333
"node": ">=7.0"
34+
},
35+
"devDependencies": {
36+
"@types/bluebird": "^3.5.38",
37+
"@types/node": "^20.1.4"
3438
}
3539
}

src/Afip.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ function Afip(options = {}){
8787
if (!(this instanceof Afip)) {return new Afip(options)}
8888

8989
// Create an instance of the mixpanel client
90+
/** @private */
9091
this.mixpanel = Mixpanel.init('e87ee11c8cc288e5c5dc213c4d957c7e');
92+
/** @private */
9193
this.mixpanelRegister = {};
9294

9395
this.mixpanelRegister['afip_sdk_library'] = 'javascript';
@@ -138,6 +140,7 @@ function Afip(options = {}){
138140
* Gets token authorization for an AFIP Web Service
139141
*
140142
* @param service Service for token authorization
143+
* @private
141144
**/
142145
Afip.prototype.GetServiceTA = async function(service, firstTry = true) {
143146
// Declare token authorization file path
@@ -279,6 +282,7 @@ Afip.prototype.CreateServiceTA = async function(service) {
279282
* @param string web_service ID of the web service used
280283
* @param string operation SOAP operation called
281284
* @param array params Parameters for the ws
285+
* @private
282286
**/
283287
Afip.prototype.TrackUsage = async function(web_service, operation, params = {}) {
284288
options = {};
@@ -298,6 +302,7 @@ Afip.prototype.TrackUsage = async function(web_service, operation, params = {})
298302
} catch (e) {}
299303

300304
if (!this.AdminClient && this.options['production'] === true) {
305+
/** @private */
301306
this.AdminClient = axios.create({
302307
baseURL: 'https://app.afipsdk.com/api/',
303308
timeout: 10000

types/Afip.d.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
export = Afip;
2+
declare function Afip(options?: {}): Afip;
3+
declare class Afip {
4+
constructor(options?: {});
5+
/** @private */
6+
private mixpanel;
7+
/** @private */
8+
private mixpanelRegister;
9+
options: {};
10+
CUIT: any;
11+
RES_FOLDER: any;
12+
TA_FOLDER: any;
13+
CERT: string;
14+
PRIVATEKEY: string;
15+
WSAA_WSDL: string;
16+
WSAA_URL: string;
17+
ElectronicBilling: ElectronicBilling;
18+
RegisterScopeFour: RegisterScopeFour;
19+
RegisterScopeFive: RegisterScopeFive;
20+
RegisterInscriptionProof: RegisterScopeFive;
21+
RegisterScopeTen: RegisterScopeTen;
22+
RegisterScopeThirteen: RegisterScopeThirteen;
23+
private GetServiceTA;
24+
/**
25+
* Create an TA from WSAA
26+
*
27+
* Request to WSAA for a tokent authorization for service
28+
* and save this in a json file
29+
*
30+
* @param service Service for token authorization
31+
**/
32+
CreateServiceTA(service: any): Promise<void>;
33+
private TrackUsage;
34+
/** @private */
35+
private AdminClient;
36+
/**
37+
* Create generic Web Service
38+
*
39+
* @param string service Web Service name
40+
* @param array options Web Service options
41+
*
42+
* @return AfipWebService Token Authorization for AFIP Web Service
43+
**/
44+
WebService(service: any, options: any): AfipWebService;
45+
}
46+
import ElectronicBilling = require("./Class/ElectronicBilling");
47+
import RegisterScopeFour = require("./Class/RegisterScopeFour");
48+
import RegisterScopeFive = require("./Class/RegisterScopeFive");
49+
import RegisterScopeTen = require("./Class/RegisterScopeTen");
50+
import RegisterScopeThirteen = require("./Class/RegisterScopeThirteen");
51+
import AfipWebService = require("./Class/AfipWebService");

types/Class/AfipWebService.d.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
export = AfipWebService;
2+
declare class AfipWebService {
3+
constructor(webServiceOptions: any, options?: {});
4+
/**
5+
* Force to use SOAP Client version 1.2
6+
*
7+
* @var boolean
8+
**/
9+
soapv12: any;
10+
/**
11+
* File name for the Web Services Description Language
12+
*
13+
* @var string
14+
**/
15+
WSDL: any;
16+
/**
17+
* The url to web service
18+
*
19+
* @var string
20+
**/
21+
URL: any;
22+
/**
23+
* File name for the Web Services Description
24+
* Language in test mode
25+
*
26+
* @var string
27+
**/
28+
WSDL_TEST: any;
29+
/**
30+
* The url to web service in test mode
31+
*
32+
* @var string
33+
**/
34+
URL_TEST: any;
35+
/**
36+
* The Afip parent Class
37+
*
38+
* @var Afip
39+
**/
40+
afip: any;
41+
/**
42+
* Options
43+
*
44+
* @var object
45+
**/
46+
options: {};
47+
/**
48+
* Get Web Service Token Authorization from WSAA
49+
*
50+
* @since 0.6
51+
*
52+
* @throws Error if an error occurs
53+
*
54+
* @return TokenAuthorization Token Authorization for AFIP Web Service
55+
**/
56+
getTokenAuthorization(): Promise<any>;
57+
/**
58+
* Send request to AFIP servers
59+
*
60+
* @param operation SOAP operation to execute
61+
* @param params Parameters to send
62+
**/
63+
executeRequest(operation: any, params?: {}): Promise<any>;
64+
soapClient: soap.Client;
65+
}
66+
import soap = require("soap");

types/Class/ElectronicBilling.d.ts

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
export = ElectronicBilling;
2+
declare class ElectronicBilling extends AfipWebService {
3+
constructor(afip: any);
4+
/**
5+
* Gets last voucher number
6+
*
7+
* Asks to Afip servers for number of the last voucher created for
8+
* certain sales point and voucher type {@see WS Specification
9+
* item 4.15}
10+
*
11+
* @param int salesPoint Sales point to ask for last voucher
12+
* @param int type Voucher type to ask for last voucher
13+
*
14+
* @return int
15+
**/
16+
getLastVoucher(salesPoint: any, type: any): Promise<any>;
17+
/**
18+
* Create a voucher from AFIP
19+
*
20+
* Send to AFIP servers request for create a voucher and assign
21+
* CAE to them {@see WS Specification item 4.1}
22+
*
23+
* @param array data Voucher parameters {@see WS Specification
24+
* item 4.1.3}, some arrays were simplified for easy use {@example
25+
* examples/createVoucher.js Example with all allowed
26+
* attributes}
27+
* @param bool returnResponse if is TRUE returns complete response
28+
* from AFIP
29+
*
30+
* @return array if returnResponse is set to false returns
31+
* [CAE : CAE assigned to voucher, CAEFchVto : Expiration date
32+
* for CAE (yyyy-mm-dd)] else returns complete response from
33+
* AFIP {@see WS Specification item 4.1.3}
34+
**/
35+
createVoucher(data: any, returnResponse?: boolean): Promise<any>;
36+
/**
37+
* Create next voucher from AFIP
38+
*
39+
* This method combines Afip.getLastVoucher and Afip.createVoucher
40+
* for create the next voucher
41+
*
42+
* @param array data Same to data in Afip.createVoucher except that
43+
* don't need CbteDesde and CbteHasta attributes
44+
*
45+
* @return array [CAE : CAE assigned to voucher, CAEFchVto : Expiration
46+
* date for CAE (yyyy-mm-dd), voucherNumber : Number assigned to
47+
* voucher]
48+
**/
49+
createNextVoucher(data: any): Promise<any>;
50+
/**
51+
* Get complete voucher information
52+
*
53+
* Asks to AFIP servers for complete information of voucher {@see WS
54+
* Specification item 4.19}
55+
*
56+
* @param int number Number of voucher to get information
57+
* @param int salesPoint Sales point of voucher to get information
58+
* @param int type Type of voucher to get information
59+
*
60+
* @return array|null returns array with complete voucher information
61+
* {@see WS Specification item 4.19} or null if there not exists
62+
**/
63+
getVoucherInfo(number: any, salesPoint: any, type: any): Promise<any>;
64+
/**
65+
* Asks to AFIP Servers for sales points availables {@see WS
66+
* Specification item 4.11}
67+
*
68+
* @return array All sales points availables
69+
**/
70+
getSalesPoints(): Promise<any>;
71+
/**
72+
* Asks to AFIP Servers for voucher types availables {@see WS
73+
* Specification item 4.4}
74+
*
75+
* @return array All voucher types availables
76+
**/
77+
getVoucherTypes(): Promise<any>;
78+
/**
79+
* Asks to AFIP Servers for voucher concepts availables {@see WS
80+
* Specification item 4.5}
81+
*
82+
* @return array All voucher concepts availables
83+
**/
84+
getConceptTypes(): Promise<any>;
85+
/**
86+
* Asks to AFIP Servers for document types availables {@see WS
87+
* Specification item 4.6}
88+
*
89+
* @return array All document types availables
90+
**/
91+
getDocumentTypes(): Promise<any>;
92+
/**
93+
* Asks to AFIP Servers for aliquot availables {@see WS
94+
* Specification item 4.7}
95+
*
96+
* @return array All aliquot availables
97+
**/
98+
getAliquotTypes(): Promise<any>;
99+
/**
100+
* Asks to AFIP Servers for currencies availables {@see WS
101+
* Specification item 4.8}
102+
*
103+
* @return array All currencies availables
104+
**/
105+
getCurrenciesTypes(): Promise<any>;
106+
/**
107+
* Asks to AFIP Servers for voucher optional data available {@see WS
108+
* Specification item 4.9}
109+
*
110+
* @return array All voucher optional data available
111+
**/
112+
getOptionsTypes(): Promise<any>;
113+
/**
114+
* Asks to AFIP Servers for tax availables {@see WS
115+
* Specification item 4.10}
116+
*
117+
* @return array All tax availables
118+
**/
119+
getTaxTypes(): Promise<any>;
120+
/**
121+
* Asks to web service for servers status {@see WS
122+
* Specification item 4.14}
123+
*
124+
* @return object { AppServer : Web Service status,
125+
* DbServer : Database status, AuthServer : Autentication
126+
* server status}
127+
**/
128+
getServerStatus(): Promise<any>;
129+
/**
130+
* Change date from AFIP used format (yyyymmdd) to yyyy-mm-dd
131+
*
132+
* @param string|int date to format
133+
*
134+
* @return string date in format yyyy-mm-dd
135+
**/
136+
formatDate(date: any): any;
137+
/**
138+
* Make default request parameters for most of the operations
139+
*
140+
* @param string operation SOAP Operation to do
141+
*
142+
* @return array Request parameters
143+
**/
144+
getWSInitialRequest(operation: any): Promise<{
145+
Auth?: undefined;
146+
} | {
147+
Auth: {
148+
Token: any;
149+
Sign: any;
150+
Cuit: any;
151+
};
152+
}>;
153+
/**
154+
* Check if occurs an error on Web Service request
155+
*
156+
* @param string operation SOAP operation to check
157+
* @param mixed results AFIP response
158+
*
159+
* @throws Exception if exists an error in response
160+
*
161+
* @return void
162+
**/
163+
_checkErrors(operation: any, results: any): Promise<void>;
164+
}
165+
import AfipWebService = require("./AfipWebService");

types/Class/RegisterScopeFive.d.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export = RegisterScopeFive;
2+
declare class RegisterScopeFive extends AfipWebService {
3+
constructor(afip: any);
4+
/**
5+
* Asks to web service for servers status {@see WS
6+
* Specification item 3.1}
7+
*
8+
* @return object { appserver : Web Service status,
9+
* dbserver : Database status, authserver : Autentication
10+
* server status}
11+
**/
12+
getServerStatus(): Promise<any>;
13+
/**
14+
* Asks to web service for taxpayer details {@see WS
15+
* Specification item 3.2}
16+
*
17+
* @throws Exception if exists an error in response
18+
*
19+
* @return object|null if taxpayer does not exists, return null,
20+
* if it exists, returns full response {@see
21+
* WS Specification item 3.2.2}
22+
**/
23+
getTaxpayerDetails(identifier: any): Promise<any>;
24+
/**
25+
* Asks to web service for taxpayers details
26+
*
27+
* @throws Exception if exists an error in response
28+
*
29+
* @return [object] returns web service full response
30+
**/
31+
getTaxpayersDetails(identifiers: any): Promise<any>;
32+
}
33+
import AfipWebService = require("./AfipWebService");

0 commit comments

Comments
 (0)