@@ -14,15 +14,21 @@ class BrokerBin {
14
14
* @function
15
15
* @param {Object } auth An object containing the following data:
16
16
*
17
- * - `username` (String): The BrokerBin username.
18
- * - `password` (String): The BrokerBin password.
19
- * - `soap_key` (String): The BrokerBin soap key.
20
- * - `soap_uri` (String): The BrokerBin soap uri.
21
- * - `public_key` (String): The BrokerBin public key.
17
+ * - `username` (String): The BrokerBin username (or ENV variable: `BROKERBIN_USERNAME`)
18
+ * - `password` (String): The BrokerBin password (or ENV variable: `BROKERBIN_PASSWORD`)
19
+ * - `soap_key` (String): The BrokerBin soap key (or ENV variable: `BROKERBIN_SOAP_KEY`)
20
+ * - `soap_uri` (String): The BrokerBin soap uri (or ENV variable: `BROKERBIN_SOAP_URI`)
21
+ * - `public_key` (String): The BrokerBin public key (or ENV variable: `BROKERBIN_PUBLIC_KEY`)
22
22
*
23
23
* @return {Number } Return description.
24
24
*/
25
- constructor ( auth ) {
25
+ constructor ( auth = { } ) {
26
+
27
+ auth . username = auth . username || process . env . BROKERBIN_USERNAME
28
+ auth . password = auth . password || process . env . BROKERBIN_PASSWORD
29
+ auth . soap_key = auth . soap_key || process . env . BROKERBIN_SOAP_KEY
30
+ auth . soap_uri = auth . soap_uri || process . env . BROKERBIN_SOAP_URI
31
+ auth . public_key = auth . public_key || process . env . BROKERBIN_PUBLIC_KEY
26
32
27
33
const {
28
34
username
@@ -84,6 +90,9 @@ class BrokerBin {
84
90
* @return {Promise } Resolves with the results.
85
91
*/
86
92
async search ( reqPart , reqOptions ) {
93
+ if ( ! this . soapUid ) {
94
+ await this . authenticate ( )
95
+ }
87
96
return new Promise ( ( resolve , reject ) => {
88
97
reqOptions . uid = this . soapUid
89
98
this . soapClient . Search ( {
@@ -96,7 +105,7 @@ class BrokerBin {
96
105
try {
97
106
res = phpunserialize ( res . resParam . $value )
98
107
} catch ( e ) {
99
- // TODO This fails silently
108
+ // TODO This fails quite silently
100
109
console . error ( e )
101
110
res = { }
102
111
res . resultset = [ {
0 commit comments