testdriverai 5.5.4 → 5.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/sdk.js +35 -30
- package/package.json +1 -1
package/lib/sdk.js
CHANGED
|
@@ -9,7 +9,7 @@ const axios = require('axios');
|
|
|
9
9
|
|
|
10
10
|
const { logger } = require('./logger');
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
let token = null;
|
|
13
13
|
|
|
14
14
|
const outputError = async (error) => {
|
|
15
15
|
logger.info(chalk.red(error.status), chalk.red(error.statusText));
|
|
@@ -62,29 +62,32 @@ const parseBody = async (response, body) => {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
let auth = async () => {
|
|
65
|
-
// data.apiKey = process.env.DASHCAM_API_KEY; @todo add-auth
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
66
|
+
if (config["TD_API_KEY"]) {
|
|
67
|
+
|
|
68
|
+
const url = [root, "auth/exchange-api-key"].join("/");
|
|
69
|
+
const c = {
|
|
70
|
+
method: "post",
|
|
71
|
+
headers: {
|
|
72
|
+
"Content-Type": "application/json",
|
|
73
|
+
},
|
|
74
|
+
data: {
|
|
75
|
+
apiKey: config["TD_API_KEY"],
|
|
76
|
+
version
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
let res = await axios(url, c);
|
|
82
|
+
|
|
83
|
+
token = res.data.token;
|
|
84
|
+
return token;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
await outputError(error);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
87
89
|
}
|
|
90
|
+
|
|
88
91
|
};
|
|
89
92
|
|
|
90
93
|
const req = async (path, data, onChunk) => {
|
|
@@ -98,17 +101,19 @@ const req = async (path, data, onChunk) => {
|
|
|
98
101
|
const url = path.startsWith("/api")
|
|
99
102
|
? [root, path].join("")
|
|
100
103
|
: [root, "api", version, "testdriver", path].join("/");
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
const config = {
|
|
105
|
+
method: "post",
|
|
106
|
+
headers: {
|
|
107
|
+
"Content-Type": "application/json",
|
|
108
|
+
...(token && { "Authorization": `Bearer ${token}` }) // Add the authorization bearer token only if token is set
|
|
109
|
+
},
|
|
110
|
+
responseType: typeof onChunk === "function" ? "stream" : "json",
|
|
111
|
+
data: {
|
|
107
112
|
...data,
|
|
108
113
|
session: session.get(),
|
|
109
114
|
stream: typeof onChunk === "function",
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
},
|
|
116
|
+
};
|
|
112
117
|
|
|
113
118
|
try {
|
|
114
119
|
let response;
|