@@ -8,7 +8,7 @@ import Retentions from './resources/retentions';
88import Webhooks from './tools/webhooks' ;
99import Tools from './tools/tools' ;
1010import * as enums from './enums' ;
11- import { createWrapper } from './wrapper' ;
11+ import { createWrapper , WrapperClient } from './wrapper' ;
1212import { DEFAULT_API_VERSION } from './constants' ;
1313
1414export * from './enums' ;
@@ -30,6 +30,7 @@ export interface FacturapiOptions {
3030 */
3131export default class Facturapi {
3232 apiVersion : ApiVersion ;
33+ private _wrapper : WrapperClient ;
3334 customers : Customers ;
3435 products : Products ;
3536 invoices : Invoices ;
@@ -40,6 +41,18 @@ export default class Facturapi {
4041 tools : Tools ;
4142 webhooks : Webhooks ;
4243
44+ /**
45+ * Get or set the base URL used for API requests.
46+ * Allows overriding the default API host, e.g. for testing.
47+ * Usage: facturapi.BASE_URL = 'http://localhost:3000/v2'
48+ */
49+ get BASE_URL ( ) : string {
50+ return this . _wrapper . baseURL ;
51+ }
52+ set BASE_URL ( url : string ) {
53+ this . _wrapper . baseURL = url ;
54+ }
55+
4356 static get TaxType ( ) {
4457 return enums . TaxType ;
4558 }
@@ -96,15 +109,15 @@ export default class Facturapi {
96109 } else {
97110 this . apiVersion = DEFAULT_API_VERSION ;
98111 }
99- const wrapper = createWrapper ( apiKey , this . apiVersion ) ;
100- this . customers = new Customers ( wrapper ) ;
101- this . products = new Products ( wrapper ) ;
102- this . invoices = new Invoices ( wrapper ) ;
103- this . organizations = new Organizations ( wrapper ) ;
104- this . catalogs = new Catalogs ( wrapper ) ;
105- this . receipts = new Receipts ( wrapper ) ;
106- this . retentions = new Retentions ( wrapper ) ;
107- this . tools = new Tools ( wrapper ) ;
108- this . webhooks = new Webhooks ( wrapper ) ;
112+ this . _wrapper = createWrapper ( apiKey , this . apiVersion ) ;
113+ this . customers = new Customers ( this . _wrapper ) ;
114+ this . products = new Products ( this . _wrapper ) ;
115+ this . invoices = new Invoices ( this . _wrapper ) ;
116+ this . organizations = new Organizations ( this . _wrapper ) ;
117+ this . catalogs = new Catalogs ( this . _wrapper ) ;
118+ this . receipts = new Receipts ( this . _wrapper ) ;
119+ this . retentions = new Retentions ( this . _wrapper ) ;
120+ this . tools = new Tools ( this . _wrapper ) ;
121+ this . webhooks = new Webhooks ( this . _wrapper ) ;
109122 }
110123}
0 commit comments