askui 0.3.1 → 0.3.2
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/dist/cjs/execution/ui-control-client.js +2 -1
- package/dist/cjs/utils/analytics/analytics.d.ts +1 -0
- package/dist/cjs/utils/analytics/analytics.js +8 -0
- package/dist/cjs/utils/http/http-client-got.d.ts +3 -2
- package/dist/cjs/utils/http/http-client-got.js +11 -5
- package/dist/esm/execution/ui-control-client.js +2 -1
- package/dist/esm/utils/analytics/analytics.d.ts +1 -0
- package/dist/esm/utils/analytics/analytics.js +8 -0
- package/dist/esm/utils/http/http-client-got.d.ts +3 -2
- package/dist/esm/utils/http/http-client-got.js +11 -5
- package/package.json +2 -1
|
@@ -36,9 +36,10 @@ class UiControlClient extends dsl_1.FluentCommand {
|
|
|
36
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
37
|
const analytics = new analytics_1.Analytics();
|
|
38
38
|
const analyticsHeaders = yield analytics.getAnalyticsHeaders();
|
|
39
|
+
const analyticsCookies = yield analytics.getAnalyticsCookies();
|
|
39
40
|
const cas = getClientArgsWithDefaults(clientArgs);
|
|
40
41
|
const credentialArgs = cas.credentials || (0, read_environment_credentials_1.envCredentials)();
|
|
41
|
-
const httpClient = new http_client_got_1.HttpClientGot(credentialArgs === null || credentialArgs === void 0 ? void 0 : credentialArgs.token, analyticsHeaders);
|
|
42
|
+
const httpClient = new http_client_got_1.HttpClientGot(credentialArgs === null || credentialArgs === void 0 ? void 0 : credentialArgs.token, analyticsHeaders, analyticsCookies);
|
|
42
43
|
return new UiControlClient(httpClient, cas, credentialArgs === null || credentialArgs === void 0 ? void 0 : credentialArgs.workspaceId);
|
|
43
44
|
});
|
|
44
45
|
}
|
|
@@ -34,5 +34,13 @@ class Analytics {
|
|
|
34
34
|
return headers;
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
+
getAnalyticsCookies() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const userID = yield this.userIdentifier.userId();
|
|
40
|
+
return {
|
|
41
|
+
'askui-user-id': userID,
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
}
|
|
37
45
|
}
|
|
38
46
|
exports.Analytics = Analytics;
|
|
@@ -2,10 +2,11 @@ import { OptionsOfJSONResponseBody } from 'got';
|
|
|
2
2
|
export declare class HttpClientGot {
|
|
3
3
|
readonly token?: string | undefined;
|
|
4
4
|
readonly customHeaders?: Record<string, string> | undefined;
|
|
5
|
+
private readonly cookies;
|
|
5
6
|
private headers;
|
|
6
|
-
constructor(token?: string | undefined, customHeaders?: Record<string, string> | undefined);
|
|
7
|
+
constructor(token?: string | undefined, customHeaders?: Record<string, string> | undefined, cookies?: Record<string, string>);
|
|
7
8
|
private initHeaders;
|
|
8
|
-
private
|
|
9
|
+
private injectHeadersAndCookies;
|
|
9
10
|
post<T>(url: string, data: Record<string | number | symbol, unknown>): Promise<T>;
|
|
10
11
|
get<T>(url: string, options?: OptionsOfJSONResponseBody): Promise<T>;
|
|
11
12
|
}
|
|
@@ -14,12 +14,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.HttpClientGot = void 0;
|
|
16
16
|
const got_1 = __importDefault(require("got"));
|
|
17
|
+
const tough_cookie_1 = require("tough-cookie");
|
|
17
18
|
const credentials_1 = require("./credentials");
|
|
18
19
|
const custom_errors_1 = require("./custom-errors");
|
|
19
20
|
class HttpClientGot {
|
|
20
|
-
constructor(token, customHeaders) {
|
|
21
|
+
constructor(token, customHeaders, cookies = {}) {
|
|
21
22
|
this.token = token;
|
|
22
23
|
this.customHeaders = customHeaders;
|
|
24
|
+
this.cookies = cookies;
|
|
23
25
|
this.headers = {};
|
|
24
26
|
this.initHeaders(token, customHeaders);
|
|
25
27
|
}
|
|
@@ -27,12 +29,16 @@ class HttpClientGot {
|
|
|
27
29
|
const credentials = token ? new credentials_1.Credentials(token) : undefined;
|
|
28
30
|
this.headers = Object.assign(Object.assign({}, (credentials ? { Authorization: `Basic ${credentials === null || credentials === void 0 ? void 0 : credentials.base64Encoded}` } : {})), customHeaders);
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
injectHeadersAndCookies(url, options) {
|
|
33
|
+
const cookieJar = new tough_cookie_1.CookieJar();
|
|
34
|
+
Object.keys(this.cookies).map((key) => `${key}=${this.cookies[key]}`).forEach((cookie) => {
|
|
35
|
+
cookieJar.setCookieSync(cookie, url);
|
|
36
|
+
});
|
|
37
|
+
return Object.assign(Object.assign({}, options), { headers: this.headers, cookieJar });
|
|
32
38
|
}
|
|
33
39
|
post(url, data) {
|
|
34
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const options = this.
|
|
41
|
+
const options = this.injectHeadersAndCookies(url, { json: data, responseType: 'json', throwHttpErrors: false });
|
|
36
42
|
const { body, statusCode } = yield got_1.default.post(url, options);
|
|
37
43
|
if (statusCode !== 200) {
|
|
38
44
|
throw (0, custom_errors_1.httpClientErrorHandler)(statusCode, JSON.stringify(body));
|
|
@@ -42,7 +48,7 @@ class HttpClientGot {
|
|
|
42
48
|
}
|
|
43
49
|
get(url, options = { responseType: 'json' }) {
|
|
44
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const response = yield got_1.default.get(url, this.
|
|
51
|
+
const response = yield got_1.default.get(url, this.injectHeadersAndCookies(url, options));
|
|
46
52
|
return response.body;
|
|
47
53
|
});
|
|
48
54
|
}
|
|
@@ -33,9 +33,10 @@ export class UiControlClient extends FluentCommand {
|
|
|
33
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
34
|
const analytics = new Analytics();
|
|
35
35
|
const analyticsHeaders = yield analytics.getAnalyticsHeaders();
|
|
36
|
+
const analyticsCookies = yield analytics.getAnalyticsCookies();
|
|
36
37
|
const cas = getClientArgsWithDefaults(clientArgs);
|
|
37
38
|
const credentialArgs = cas.credentials || envCredentials();
|
|
38
|
-
const httpClient = new HttpClientGot(credentialArgs === null || credentialArgs === void 0 ? void 0 : credentialArgs.token, analyticsHeaders);
|
|
39
|
+
const httpClient = new HttpClientGot(credentialArgs === null || credentialArgs === void 0 ? void 0 : credentialArgs.token, analyticsHeaders, analyticsCookies);
|
|
39
40
|
return new UiControlClient(httpClient, cas, credentialArgs === null || credentialArgs === void 0 ? void 0 : credentialArgs.workspaceId);
|
|
40
41
|
});
|
|
41
42
|
}
|
|
@@ -28,4 +28,12 @@ export class Analytics {
|
|
|
28
28
|
return headers;
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
+
getAnalyticsCookies() {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const userID = yield this.userIdentifier.userId();
|
|
34
|
+
return {
|
|
35
|
+
'askui-user-id': userID,
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
}
|
|
31
39
|
}
|
|
@@ -2,10 +2,11 @@ import { OptionsOfJSONResponseBody } from 'got';
|
|
|
2
2
|
export declare class HttpClientGot {
|
|
3
3
|
readonly token?: string | undefined;
|
|
4
4
|
readonly customHeaders?: Record<string, string> | undefined;
|
|
5
|
+
private readonly cookies;
|
|
5
6
|
private headers;
|
|
6
|
-
constructor(token?: string | undefined, customHeaders?: Record<string, string> | undefined);
|
|
7
|
+
constructor(token?: string | undefined, customHeaders?: Record<string, string> | undefined, cookies?: Record<string, string>);
|
|
7
8
|
private initHeaders;
|
|
8
|
-
private
|
|
9
|
+
private injectHeadersAndCookies;
|
|
9
10
|
post<T>(url: string, data: Record<string | number | symbol, unknown>): Promise<T>;
|
|
10
11
|
get<T>(url: string, options?: OptionsOfJSONResponseBody): Promise<T>;
|
|
11
12
|
}
|
|
@@ -8,12 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import got from 'got';
|
|
11
|
+
import { CookieJar } from 'tough-cookie';
|
|
11
12
|
import { Credentials } from './credentials';
|
|
12
13
|
import { httpClientErrorHandler } from './custom-errors';
|
|
13
14
|
export class HttpClientGot {
|
|
14
|
-
constructor(token, customHeaders) {
|
|
15
|
+
constructor(token, customHeaders, cookies = {}) {
|
|
15
16
|
this.token = token;
|
|
16
17
|
this.customHeaders = customHeaders;
|
|
18
|
+
this.cookies = cookies;
|
|
17
19
|
this.headers = {};
|
|
18
20
|
this.initHeaders(token, customHeaders);
|
|
19
21
|
}
|
|
@@ -21,12 +23,16 @@ export class HttpClientGot {
|
|
|
21
23
|
const credentials = token ? new Credentials(token) : undefined;
|
|
22
24
|
this.headers = Object.assign(Object.assign({}, (credentials ? { Authorization: `Basic ${credentials === null || credentials === void 0 ? void 0 : credentials.base64Encoded}` } : {})), customHeaders);
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
injectHeadersAndCookies(url, options) {
|
|
27
|
+
const cookieJar = new CookieJar();
|
|
28
|
+
Object.keys(this.cookies).map((key) => `${key}=${this.cookies[key]}`).forEach((cookie) => {
|
|
29
|
+
cookieJar.setCookieSync(cookie, url);
|
|
30
|
+
});
|
|
31
|
+
return Object.assign(Object.assign({}, options), { headers: this.headers, cookieJar });
|
|
26
32
|
}
|
|
27
33
|
post(url, data) {
|
|
28
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const options = this.
|
|
35
|
+
const options = this.injectHeadersAndCookies(url, { json: data, responseType: 'json', throwHttpErrors: false });
|
|
30
36
|
const { body, statusCode } = yield got.post(url, options);
|
|
31
37
|
if (statusCode !== 200) {
|
|
32
38
|
throw httpClientErrorHandler(statusCode, JSON.stringify(body));
|
|
@@ -36,7 +42,7 @@ export class HttpClientGot {
|
|
|
36
42
|
}
|
|
37
43
|
get(url, options = { responseType: 'json' }) {
|
|
38
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
const response = yield got.get(url, this.
|
|
45
|
+
const response = yield got.get(url, this.injectHeadersAndCookies(url, options));
|
|
40
46
|
return response.body;
|
|
41
47
|
});
|
|
42
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "askui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "askui GmbH <info@askui.com> (http://www.askui.com/)",
|
|
6
6
|
"description": "Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"pino": "7.8.1",
|
|
59
59
|
"pino-pretty": "7.5.3",
|
|
60
60
|
"sharp": "0.30.6",
|
|
61
|
+
"tough-cookie": "4.1.2",
|
|
61
62
|
"url-join": "4.0.1",
|
|
62
63
|
"wait-port": "0.2.9",
|
|
63
64
|
"ws": "7.4.4",
|