askui 0.1.6 → 0.2.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/README.md +6 -0
- package/bin/askui-postinstall +35 -0
- package/dist/cjs/core/model/test-case-dto/custom-element.d.ts +2 -2
- package/dist/cjs/core/model/test-case-dto/custom-element.js +2 -2
- package/dist/cjs/core/model/test-case-dto/custom-element.spec.js +7 -6
- package/dist/cjs/core/model/test-case-dto/index.js +1 -3
- package/dist/cjs/core/model/test-case-dto/test-step.d.ts +3 -7
- package/dist/cjs/core/model/test-case-dto/test-step.js +0 -12
- package/dist/cjs/core/ui-control-commands/control-command.d.ts +1 -0
- package/dist/cjs/core/ui-control-commands/control-command.js +5 -0
- package/dist/cjs/core/ui-control-commands/input-event.d.ts +1 -2
- package/dist/cjs/core/ui-control-commands/input-event.js +0 -1
- package/dist/cjs/execution/dsl.d.ts +6 -17
- package/dist/cjs/execution/dsl.js +4 -21
- package/dist/cjs/execution/execution-runtime.d.ts +7 -5
- package/dist/cjs/execution/execution-runtime.js +35 -23
- package/dist/cjs/execution/index.d.ts +2 -1
- package/dist/cjs/execution/index.js +5 -3
- package/dist/cjs/execution/{control-your-ui-api.d.ts → inference-client.d.ts} +4 -4
- package/dist/cjs/execution/{control-your-ui-api.js → inference-client.js} +9 -9
- package/dist/cjs/execution/ui-control-client-error.d.ts +2 -0
- package/dist/cjs/execution/ui-control-client-error.js +6 -0
- package/dist/cjs/execution/ui-control-client.d.ts +79 -0
- package/dist/cjs/execution/ui-control-client.js +185 -0
- package/dist/cjs/execution/{client-connection-state.d.ts → ui-controller-client-connection-state.d.ts} +1 -1
- package/dist/cjs/execution/ui-controller-client-connection-state.js +10 -0
- package/dist/cjs/execution/ui-controller-client-interface.d.ts +27 -0
- package/dist/cjs/execution/{client-interface.js → ui-controller-client-interface.js} +0 -0
- package/dist/cjs/execution/{control-your-ui-client.d.ts → ui-controller-client.d.ts} +6 -6
- package/dist/cjs/execution/{control-your-ui-client.js → ui-controller-client.js} +28 -28
- package/dist/cjs/lib/copy-example-project.js +2 -1
- package/dist/cjs/lib/download-binaries.js +10 -9
- package/dist/cjs/lib/index.d.ts +1 -1
- package/dist/cjs/lib/index.js +3 -3
- package/dist/cjs/lib/libfuse-error.d.ts +2 -0
- package/dist/cjs/lib/libfuse-error.js +6 -0
- package/dist/cjs/lib/logger.js +1 -1
- package/dist/cjs/lib/timeout-error.d.ts +0 -2
- package/dist/cjs/lib/timeout-error.js +0 -5
- package/dist/cjs/lib/ui-controller-args.d.ts +47 -0
- package/dist/cjs/lib/{control-ui-server-args.js → ui-controller-args.js} +0 -0
- package/dist/cjs/lib/{control-ui-server-args.spec.d.ts → ui-controller-args.spec.d.ts} +0 -0
- package/dist/cjs/lib/{control-ui-server-args.spec.js → ui-controller-args.spec.js} +7 -7
- package/dist/cjs/lib/ui-controller-darwin.d.ts +6 -0
- package/dist/cjs/lib/{control-ui-server-darwin.js → ui-controller-darwin.js} +8 -8
- package/dist/cjs/lib/ui-controller-facade.d.ts +17 -0
- package/dist/cjs/lib/{control-ui-server-facade.js → ui-controller-facade.js} +22 -16
- package/dist/cjs/lib/ui-controller-linux.d.ts +5 -0
- package/dist/cjs/lib/ui-controller-linux.js +52 -0
- package/dist/cjs/lib/ui-controller-win32.d.ts +3 -0
- package/dist/cjs/lib/ui-controller-win32.js +7 -0
- package/dist/cjs/lib/ui-controller.d.ts +8 -0
- package/dist/cjs/lib/{askui-control-server.js → ui-controller.js} +9 -9
- package/dist/cjs/lib/unkown-error.d.ts +0 -2
- package/dist/cjs/lib/unkown-error.js +0 -5
- package/dist/cjs/lib/wayland-error.d.ts +2 -0
- package/dist/cjs/lib/wayland-error.js +6 -0
- package/dist/cjs/main.d.ts +3 -2
- package/dist/cjs/main.js +6 -3
- package/dist/cjs/shared/index.d.ts +1 -0
- package/dist/cjs/shared/index.js +5 -0
- package/dist/cjs/utils/analytics/analytics-interface.d.ts +3 -0
- package/dist/cjs/utils/analytics/analytics-interface.js +2 -0
- package/dist/cjs/utils/analytics/analytics.d.ts +5 -0
- package/dist/cjs/utils/analytics/analytics.js +38 -0
- package/dist/cjs/utils/analytics/index.d.ts +1 -0
- package/dist/cjs/utils/analytics/index.js +5 -0
- package/dist/cjs/utils/analytics/installation-timestamp-create-error.d.ts +4 -0
- package/dist/cjs/utils/analytics/installation-timestamp-create-error.js +9 -0
- package/dist/cjs/utils/analytics/installation-timestamp-get-error.d.ts +4 -0
- package/dist/cjs/utils/analytics/installation-timestamp-get-error.js +9 -0
- package/dist/cjs/utils/analytics/installation-timestamp.d.ts +7 -0
- package/dist/cjs/utils/analytics/installation-timestamp.js +68 -0
- package/dist/cjs/utils/analytics/user-identifier-interface.d.ts +3 -0
- package/dist/cjs/utils/analytics/user-identifier-interface.js +2 -0
- package/dist/cjs/utils/analytics/user-identifier.d.ts +4 -0
- package/dist/cjs/utils/analytics/user-identifier.js +22 -0
- package/dist/cjs/utils/base_64_image/base-64-image-error.d.ts +2 -0
- package/dist/cjs/utils/base_64_image/base-64-image-error.js +6 -0
- package/dist/cjs/utils/base_64_image/base-64-image-string-error.d.ts +4 -0
- package/dist/cjs/utils/base_64_image/base-64-image-string-error.js +11 -0
- package/dist/cjs/utils/base_64_image/base-64-image.d.ts +18 -0
- package/dist/cjs/utils/base_64_image/base-64-image.js +86 -0
- package/dist/cjs/utils/http/custom-errors/http-client-error.d.ts +0 -2
- package/dist/cjs/utils/http/custom-errors/http-client-error.js +0 -5
- package/dist/cjs/utils/http/http-client-got.d.ts +6 -5
- package/dist/cjs/utils/http/http-client-got.js +11 -11
- package/dist/cjs/utils/image-resize-errors/image-resizing-base-error.d.ts +0 -2
- package/dist/cjs/utils/image-resize-errors/image-resizing-base-error.js +0 -5
- package/dist/cjs/utils/image-resize-errors/index.d.ts +0 -1
- package/dist/cjs/utils/image-resize-errors/index.js +1 -3
- package/dist/cjs/utils/path.d.ts +1 -0
- package/dist/cjs/utils/path.js +11 -0
- package/dist/cjs/utils/transformations.d.ts +0 -2
- package/dist/cjs/utils/transformations.js +11 -44
- package/dist/esm/core/model/test-case-dto/custom-element.d.ts +2 -2
- package/dist/esm/core/model/test-case-dto/custom-element.js +2 -2
- package/dist/esm/core/model/test-case-dto/custom-element.spec.js +7 -6
- package/dist/esm/core/model/test-case-dto/index.js +0 -1
- package/dist/esm/core/model/test-case-dto/test-step.d.ts +3 -7
- package/dist/esm/core/model/test-case-dto/test-step.js +1 -10
- package/dist/esm/core/ui-control-commands/control-command.d.ts +1 -0
- package/dist/esm/core/ui-control-commands/control-command.js +5 -0
- package/dist/esm/core/ui-control-commands/input-event.d.ts +1 -2
- package/dist/esm/core/ui-control-commands/input-event.js +0 -1
- package/dist/esm/execution/dsl.d.ts +6 -17
- package/dist/esm/execution/dsl.js +3 -21
- package/dist/esm/execution/execution-runtime.d.ts +7 -5
- package/dist/esm/execution/execution-runtime.js +35 -23
- package/dist/esm/execution/index.d.ts +2 -1
- package/dist/esm/execution/index.js +2 -1
- package/dist/esm/execution/{control-your-ui-api.d.ts → inference-client.d.ts} +4 -4
- package/dist/esm/execution/{control-your-ui-api.js → inference-client.js} +7 -7
- package/dist/esm/execution/ui-control-client-error.d.ts +2 -0
- package/dist/esm/execution/ui-control-client-error.js +2 -0
- package/dist/esm/execution/ui-control-client.d.ts +79 -0
- package/dist/esm/execution/ui-control-client.js +181 -0
- package/dist/esm/execution/{client-connection-state.d.ts → ui-controller-client-connection-state.d.ts} +1 -1
- package/dist/esm/execution/ui-controller-client-connection-state.js +7 -0
- package/dist/esm/execution/ui-controller-client-interface.d.ts +27 -0
- package/dist/esm/execution/{client-interface.js → ui-controller-client-interface.js} +0 -0
- package/dist/esm/execution/{control-your-ui-client.d.ts → ui-controller-client.d.ts} +6 -6
- package/dist/esm/execution/{control-your-ui-client.js → ui-controller-client.js} +26 -26
- package/dist/esm/lib/copy-example-project.js +2 -1
- package/dist/esm/lib/download-binaries.js +10 -9
- package/dist/esm/lib/index.d.ts +1 -1
- package/dist/esm/lib/index.js +1 -1
- package/dist/esm/lib/libfuse-error.d.ts +2 -0
- package/dist/esm/lib/libfuse-error.js +2 -0
- package/dist/esm/lib/logger.js +1 -1
- package/dist/esm/lib/timeout-error.d.ts +0 -2
- package/dist/esm/lib/timeout-error.js +0 -5
- package/dist/esm/lib/ui-controller-args.d.ts +47 -0
- package/dist/esm/lib/{control-ui-server-args.js → ui-controller-args.js} +0 -0
- package/dist/esm/lib/{control-ui-server-args.spec.d.ts → ui-controller-args.spec.d.ts} +0 -0
- package/dist/esm/lib/{control-ui-server-args.spec.js → ui-controller-args.spec.js} +1 -1
- package/dist/esm/lib/ui-controller-darwin.d.ts +6 -0
- package/dist/esm/lib/{control-ui-server-darwin.js → ui-controller-darwin.js} +6 -6
- package/dist/esm/lib/ui-controller-facade.d.ts +17 -0
- package/dist/esm/lib/{control-ui-server-facade.js → ui-controller-facade.js} +17 -11
- package/dist/esm/lib/ui-controller-linux.d.ts +5 -0
- package/dist/esm/lib/ui-controller-linux.js +48 -0
- package/dist/esm/lib/ui-controller-win32.d.ts +3 -0
- package/dist/esm/lib/ui-controller-win32.js +3 -0
- package/dist/esm/lib/ui-controller.d.ts +8 -0
- package/dist/esm/lib/{askui-control-server.js → ui-controller.js} +7 -7
- package/dist/esm/lib/unkown-error.d.ts +0 -2
- package/dist/esm/lib/unkown-error.js +0 -5
- package/dist/esm/lib/wayland-error.d.ts +2 -0
- package/dist/esm/lib/wayland-error.js +2 -0
- package/dist/esm/main.d.ts +3 -2
- package/dist/esm/main.js +3 -2
- package/dist/esm/shared/index.d.ts +1 -0
- package/dist/esm/shared/index.js +1 -0
- package/dist/esm/utils/analytics/analytics-interface.d.ts +3 -0
- package/dist/esm/utils/analytics/analytics-interface.js +1 -0
- package/dist/esm/utils/analytics/analytics.d.ts +5 -0
- package/dist/esm/utils/analytics/analytics.js +31 -0
- package/dist/esm/utils/analytics/index.d.ts +1 -0
- package/dist/esm/utils/analytics/index.js +1 -0
- package/dist/esm/utils/analytics/installation-timestamp-create-error.d.ts +4 -0
- package/dist/esm/utils/analytics/installation-timestamp-create-error.js +5 -0
- package/dist/esm/utils/analytics/installation-timestamp-get-error.d.ts +4 -0
- package/dist/esm/utils/analytics/installation-timestamp-get-error.js +5 -0
- package/dist/esm/utils/analytics/installation-timestamp.d.ts +7 -0
- package/dist/esm/utils/analytics/installation-timestamp.js +61 -0
- package/dist/esm/utils/analytics/user-identifier-interface.d.ts +3 -0
- package/dist/esm/utils/analytics/user-identifier-interface.js +1 -0
- package/dist/esm/utils/analytics/user-identifier.d.ts +4 -0
- package/dist/esm/utils/analytics/user-identifier.js +18 -0
- package/dist/esm/utils/base_64_image/base-64-image-error.d.ts +2 -0
- package/dist/esm/utils/base_64_image/base-64-image-error.js +2 -0
- package/dist/esm/utils/base_64_image/base-64-image-string-error.d.ts +4 -0
- package/dist/esm/utils/base_64_image/base-64-image-string-error.js +7 -0
- package/dist/esm/utils/base_64_image/base-64-image.d.ts +18 -0
- package/dist/esm/utils/base_64_image/base-64-image.js +79 -0
- package/dist/esm/utils/http/custom-errors/http-client-error.d.ts +0 -2
- package/dist/esm/utils/http/custom-errors/http-client-error.js +0 -5
- package/dist/esm/utils/http/http-client-got.d.ts +6 -5
- package/dist/esm/utils/http/http-client-got.js +11 -11
- package/dist/esm/utils/image-resize-errors/image-resizing-base-error.d.ts +0 -2
- package/dist/esm/utils/image-resize-errors/image-resizing-base-error.js +0 -5
- package/dist/esm/utils/image-resize-errors/index.d.ts +0 -1
- package/dist/esm/utils/image-resize-errors/index.js +0 -1
- package/dist/esm/utils/path.d.ts +1 -0
- package/dist/esm/utils/path.js +4 -0
- package/dist/esm/utils/transformations.d.ts +0 -2
- package/dist/esm/utils/transformations.js +11 -39
- package/dist/example_projects_templates/typescript_jest/test/helper/jest.setup.ts +7 -7
- package/dist/example_projects_templates/typescript_jest/test/jest.config.ts +3 -0
- package/package.json +15 -8
- package/dist/cjs/execution/client-connection-state.js +0 -10
- package/dist/cjs/execution/client-error.d.ts +0 -2
- package/dist/cjs/execution/client-error.js +0 -6
- package/dist/cjs/execution/client-interface.d.ts +0 -13
- package/dist/cjs/execution/client.d.ts +0 -25
- package/dist/cjs/execution/client.js +0 -116
- package/dist/cjs/lib/askui-control-server.d.ts +0 -8
- package/dist/cjs/lib/control-ui-server-args.d.ts +0 -21
- package/dist/cjs/lib/control-ui-server-darwin.d.ts +0 -6
- package/dist/cjs/lib/control-ui-server-facade.d.ts +0 -16
- package/dist/cjs/lib/control-ui-server-linux.d.ts +0 -4
- package/dist/cjs/lib/control-ui-server-linux.js +0 -13
- package/dist/cjs/lib/control-ui-server-win32.d.ts +0 -3
- package/dist/cjs/lib/control-ui-server-win32.js +0 -7
- package/dist/cjs/utils/image-resize-errors/invalid-base64-image-error.d.ts +0 -3
- package/dist/cjs/utils/image-resize-errors/invalid-base64-image-error.js +0 -7
- package/dist/esm/execution/client-connection-state.js +0 -7
- package/dist/esm/execution/client-error.d.ts +0 -2
- package/dist/esm/execution/client-error.js +0 -2
- package/dist/esm/execution/client-interface.d.ts +0 -13
- package/dist/esm/execution/client.d.ts +0 -25
- package/dist/esm/execution/client.js +0 -112
- package/dist/esm/lib/askui-control-server.d.ts +0 -8
- package/dist/esm/lib/control-ui-server-args.d.ts +0 -21
- package/dist/esm/lib/control-ui-server-darwin.d.ts +0 -6
- package/dist/esm/lib/control-ui-server-facade.d.ts +0 -16
- package/dist/esm/lib/control-ui-server-linux.d.ts +0 -4
- package/dist/esm/lib/control-ui-server-linux.js +0 -9
- package/dist/esm/lib/control-ui-server-win32.d.ts +0 -3
- package/dist/esm/lib/control-ui-server-win32.js +0 -3
- package/dist/esm/utils/image-resize-errors/invalid-base64-image-error.d.ts +0 -3
- package/dist/esm/utils/image-resize-errors/invalid-base64-image-error.js +0 -3
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import os from 'os';
|
|
11
|
+
import { UserIdentifier } from './user-identifier';
|
|
12
|
+
import { InstallationTimestamp } from './installation-timestamp';
|
|
13
|
+
export class Analytics {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.userIdentifier = new UserIdentifier();
|
|
16
|
+
}
|
|
17
|
+
getAnalyticsHeaders() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const userID = yield this.userIdentifier.userId();
|
|
20
|
+
const headers = {
|
|
21
|
+
'askui-user-id': userID,
|
|
22
|
+
'askui-user-agent': `os:${os.platform()};arch:${os.arch()}`,
|
|
23
|
+
};
|
|
24
|
+
const askuiInstalledAt = yield InstallationTimestamp.get();
|
|
25
|
+
if (askuiInstalledAt) {
|
|
26
|
+
headers['askui-installed-at'] = askuiInstalledAt.toISOString();
|
|
27
|
+
}
|
|
28
|
+
return headers;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Analytics } from './analytics';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Analytics } from './analytics';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import fs from 'fs';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import { logger } from '../../lib';
|
|
13
|
+
import { InstallationTimestampCreateError } from './installation-timestamp-create-error';
|
|
14
|
+
import { InstallationTimestampGetError } from './installation-timestamp-get-error';
|
|
15
|
+
import { getPathToNodeModulesRoot } from '../path';
|
|
16
|
+
export class InstallationTimestamp {
|
|
17
|
+
static create() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const timestamp = new Date().toISOString();
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
fs.writeFile(InstallationTimestamp.fileName, timestamp, { encoding: 'utf-8' }, (err) => {
|
|
22
|
+
if (err) {
|
|
23
|
+
reject(new InstallationTimestampCreateError(err));
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
resolve();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
static get() {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
if (InstallationTimestamp.value === undefined) {
|
|
35
|
+
try {
|
|
36
|
+
InstallationTimestamp.value = yield this.getFromFile();
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
InstallationTimestamp.value = null;
|
|
40
|
+
logger.warn(err.message);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return InstallationTimestamp.value;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
static getFromFile() {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
fs.readFile(InstallationTimestamp.fileName, 'utf-8', (err, isoDateStr) => {
|
|
50
|
+
if (err) {
|
|
51
|
+
reject(new InstallationTimestampGetError(err));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
resolve(new Date(isoDateStr));
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
InstallationTimestamp.fileName = path.join(getPathToNodeModulesRoot(), 'install-timestamp');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { machineId } from 'node-machine-id';
|
|
11
|
+
export class UserIdentifier {
|
|
12
|
+
// eslint-disable-next-line class-methods-use-this
|
|
13
|
+
userId() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
return machineId();
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Base64ImageError } from './base-64-image-error';
|
|
2
|
+
export class Base64ImageStringError extends Base64ImageError {
|
|
3
|
+
constructor(str, prefix) {
|
|
4
|
+
super(`Can't create Base64Image instance from string:\n${str}\n\n`
|
|
5
|
+
+ `String should start with "${prefix}".`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare class Base64Image {
|
|
3
|
+
private readonly aSharp;
|
|
4
|
+
private info;
|
|
5
|
+
private buffer;
|
|
6
|
+
static readonly strPrefix = "data:image/png;base64,";
|
|
7
|
+
private constructor();
|
|
8
|
+
private static fromSharp;
|
|
9
|
+
static fromPathOrString(pathOrStr: string): Promise<Base64Image>;
|
|
10
|
+
static fromPath(path: string): Promise<Base64Image>;
|
|
11
|
+
static fromString(str: string): Promise<Base64Image>;
|
|
12
|
+
static fromBuffer(buffer: Buffer): Promise<Base64Image>;
|
|
13
|
+
get width(): number;
|
|
14
|
+
get height(): number;
|
|
15
|
+
resizeToFitInto(dimension: number): Promise<Base64Image>;
|
|
16
|
+
toString(): string;
|
|
17
|
+
toBuffer(): Buffer;
|
|
18
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import sharp from 'sharp';
|
|
11
|
+
import { Base64ImageStringError } from './base-64-image-string-error';
|
|
12
|
+
export class Base64Image {
|
|
13
|
+
constructor(aSharp, info, buffer) {
|
|
14
|
+
this.aSharp = aSharp;
|
|
15
|
+
this.info = info;
|
|
16
|
+
this.buffer = buffer;
|
|
17
|
+
}
|
|
18
|
+
static fromSharp(s) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const { info, data } = yield s.toBuffer({ resolveWithObject: true });
|
|
21
|
+
return new Base64Image(s, info, data);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
static fromPathOrString(pathOrStr) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
try {
|
|
27
|
+
return yield Base64Image.fromString(pathOrStr);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (!(error instanceof Base64ImageStringError)) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return Base64Image.fromPath(pathOrStr);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
static fromPath(path) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
return Base64Image.fromSharp(sharp(path));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
static fromString(str) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
if (!str.startsWith(Base64Image.strPrefix)) {
|
|
45
|
+
throw new Base64ImageStringError(str, Base64Image.strPrefix);
|
|
46
|
+
}
|
|
47
|
+
const data = str.substring(Base64Image.strPrefix.length);
|
|
48
|
+
return Base64Image.fromSharp(sharp(Buffer.from(data, 'base64')));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
static fromBuffer(buffer) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
return Base64Image.fromSharp(sharp(buffer));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
get width() {
|
|
57
|
+
return this.info.width;
|
|
58
|
+
}
|
|
59
|
+
get height() {
|
|
60
|
+
return this.info.height;
|
|
61
|
+
}
|
|
62
|
+
resizeToFitInto(dimension) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const buffer = yield this.aSharp.resize({
|
|
65
|
+
width: this.width >= this.height ? dimension : undefined,
|
|
66
|
+
height: this.height > this.width ? dimension : undefined,
|
|
67
|
+
fit: sharp.fit.contain,
|
|
68
|
+
}).toBuffer();
|
|
69
|
+
return Base64Image.fromBuffer(buffer);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
toString() {
|
|
73
|
+
return `${Base64Image.strPrefix}${this.buffer.toString('base64')}`;
|
|
74
|
+
}
|
|
75
|
+
toBuffer() {
|
|
76
|
+
return this.buffer;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
Base64Image.strPrefix = 'data:image/png;base64,';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { OptionsOfJSONResponseBody } from 'got';
|
|
2
2
|
import { CredentialArgs } from './credentials';
|
|
3
3
|
export declare class HttpClientGot {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
private
|
|
4
|
+
readonly credentialArgs?: CredentialArgs | undefined;
|
|
5
|
+
readonly customHeaders?: Record<string, string> | undefined;
|
|
6
|
+
private headers;
|
|
7
|
+
constructor(credentialArgs?: CredentialArgs | undefined, customHeaders?: Record<string, string> | undefined);
|
|
8
|
+
private initHeaders;
|
|
9
|
+
private injectHeaders;
|
|
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
|
}
|
|
@@ -11,22 +11,22 @@ import got from 'got';
|
|
|
11
11
|
import { Credentials } from './credentials';
|
|
12
12
|
import { httpClientErrorHandler } from './custom-errors';
|
|
13
13
|
export class HttpClientGot {
|
|
14
|
-
constructor(credentialArgs) {
|
|
14
|
+
constructor(credentialArgs, customHeaders) {
|
|
15
15
|
this.credentialArgs = credentialArgs;
|
|
16
|
-
this.
|
|
16
|
+
this.customHeaders = customHeaders;
|
|
17
|
+
this.headers = {};
|
|
18
|
+
this.initHeaders(credentialArgs, customHeaders);
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Authorization: `Basic ${(_a = this.credentials) === null || _a === void 0 ? void 0 : _a.base64Encoded}`,
|
|
22
|
-
};
|
|
20
|
+
initHeaders(credentialArgs, customHeaders = {}) {
|
|
21
|
+
const credentials = credentialArgs ? new Credentials(credentialArgs) : undefined;
|
|
22
|
+
this.headers = Object.assign(Object.assign({}, (credentials ? { Authorization: `Basic ${credentials === null || credentials === void 0 ? void 0 : credentials.base64Encoded}` } : {})), customHeaders);
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
return
|
|
24
|
+
injectHeaders(options) {
|
|
25
|
+
return Object.assign(Object.assign({}, options), { headers: this.headers });
|
|
26
26
|
}
|
|
27
27
|
post(url, data) {
|
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const options = this.
|
|
29
|
+
const options = this.injectHeaders({ json: data, responseType: 'json', throwHttpErrors: false });
|
|
30
30
|
const { body, statusCode } = yield got.post(url, options);
|
|
31
31
|
if (statusCode !== 200) {
|
|
32
32
|
throw httpClientErrorHandler(statusCode, JSON.stringify(body));
|
|
@@ -36,7 +36,7 @@ export class HttpClientGot {
|
|
|
36
36
|
}
|
|
37
37
|
get(url, options = { responseType: 'json' }) {
|
|
38
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
const response = yield got.get(url, this.
|
|
39
|
+
const response = yield got.get(url, this.injectHeaders(options));
|
|
40
40
|
return response.body;
|
|
41
41
|
});
|
|
42
42
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPathToNodeModulesRoot(): string;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { ResizedImage } from './resized-image-interface';
|
|
2
|
-
export declare function toBase64Image(imagePath: string): Promise<string>;
|
|
3
|
-
export declare function toBase64ImageIfNeeded(pngPathOrBase64Image: string): Promise<string>;
|
|
4
2
|
/**
|
|
5
3
|
* Resizes a base64image only when the height or the width is bigger than the maxEdge Param,so that
|
|
6
4
|
* the returned image keeps the same aspect ratio but have a max size equal to the threshold.
|
|
@@ -7,28 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import fs from 'fs';
|
|
11
|
-
import { read } from 'jimp';
|
|
12
10
|
import { logger } from '../lib';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
if (!(fs.existsSync(imagePath))) {
|
|
17
|
-
throw new Error(`the image ${imagePath} does not exists!`);
|
|
18
|
-
}
|
|
19
|
-
const image = yield read(imagePath);
|
|
20
|
-
return image.getBase64Async('image/png');
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
export function toBase64ImageIfNeeded(pngPathOrBase64Image) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
const isBase64Image = pngPathOrBase64Image.startsWith('data:image');
|
|
26
|
-
if (!isBase64Image) {
|
|
27
|
-
return toBase64Image(pngPathOrBase64Image);
|
|
28
|
-
}
|
|
29
|
-
return pngPathOrBase64Image;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
11
|
+
import { Base64Image } from './base_64_image/base-64-image';
|
|
12
|
+
import { ImageResizingError } from './image-resize-errors';
|
|
32
13
|
/**
|
|
33
14
|
* Resizes a base64image only when the height or the width is bigger than the maxEdge Param,so that
|
|
34
15
|
* the returned image keeps the same aspect ratio but have a max size equal to the threshold.
|
|
@@ -42,28 +23,19 @@ export function toBase64ImageIfNeeded(pngPathOrBase64Image) {
|
|
|
42
23
|
export function resizeBase64ImageWithSameRatio(base64ImageString, maxEdge = 1400) {
|
|
43
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
25
|
logger.debug('Image resizing');
|
|
45
|
-
if (!(base64ImageString.startsWith('data:image'))) {
|
|
46
|
-
Promise.reject(new InvalidBase64Image('Invalid base64 image string'));
|
|
47
|
-
}
|
|
48
26
|
try {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const imageWidth = orignalImage.getWidth();
|
|
53
|
-
if (Math.max(imageHeight, imageWidth) <= maxEdge) {
|
|
54
|
-
return yield Promise.resolve({ base64Image: base64ImageString, resizeRatio });
|
|
27
|
+
const image = yield Base64Image.fromString(base64ImageString);
|
|
28
|
+
if (image.height <= maxEdge && image.width <= maxEdge) {
|
|
29
|
+
return { base64Image: base64ImageString, resizeRatio: 1 };
|
|
55
30
|
}
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
resizeRatio = imageHeight / newHeigh;
|
|
62
|
-
const newImageBase64 = yield newImage.getBase64Async('image/png');
|
|
63
|
-
return yield Promise.resolve({ base64Image: newImageBase64, resizeRatio });
|
|
31
|
+
const resizedImage = yield image.resizeToFitInto(maxEdge);
|
|
32
|
+
return {
|
|
33
|
+
base64Image: resizedImage.toString(),
|
|
34
|
+
resizeRatio: image.width / resizedImage.width,
|
|
35
|
+
};
|
|
64
36
|
}
|
|
65
37
|
catch (error) {
|
|
66
|
-
|
|
38
|
+
throw new ImageResizingError(`A Problem has occured during the resizing of the image. Error: ${error}`);
|
|
67
39
|
}
|
|
68
40
|
});
|
|
69
41
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UiControlClient, UiController } from 'askui';
|
|
2
2
|
|
|
3
3
|
// Server for controlling the operating system
|
|
4
|
-
let
|
|
4
|
+
let uiController: UiController;
|
|
5
5
|
|
|
6
6
|
// Client is necessary to use the askui API
|
|
7
7
|
// eslint-disable-next-line import/no-mutable-exports
|
|
8
|
-
let aui:
|
|
8
|
+
let aui: UiControlClient;
|
|
9
9
|
|
|
10
10
|
jest.setTimeout(60 * 1000 * 60);
|
|
11
11
|
|
|
12
12
|
beforeAll(async () => {
|
|
13
|
-
|
|
13
|
+
uiController = new UiController({
|
|
14
14
|
/**
|
|
15
15
|
* Select the display you want to run your tests on, display 0 is your main display;
|
|
16
16
|
* ignore if you have only one display
|
|
@@ -18,15 +18,15 @@ beforeAll(async () => {
|
|
|
18
18
|
display: 0,
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
await
|
|
21
|
+
await uiController.start();
|
|
22
22
|
|
|
23
|
-
aui =
|
|
23
|
+
aui = await UiControlClient.build();
|
|
24
24
|
|
|
25
25
|
await aui.connect();
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
afterAll(async () => {
|
|
29
|
-
await
|
|
29
|
+
await uiController.stop();
|
|
30
30
|
|
|
31
31
|
aui.close();
|
|
32
32
|
});
|
package/package.json
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "askui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"main": "./dist/cjs/main.js",
|
|
5
5
|
"module": "./dist/esm/main.js",
|
|
6
|
-
"bin":
|
|
6
|
+
"bin": {
|
|
7
|
+
"askui": "bin/askui",
|
|
8
|
+
"askui-postinstall": "bin/askui-postinstall"
|
|
9
|
+
},
|
|
7
10
|
"scripts": {
|
|
8
11
|
"build": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && npm run copyTemplate && npm run copyExampleProject",
|
|
9
12
|
"copyTemplate": "shx cp -r src/core/annotation/template.html dist/cjs/core/annotation/ && shx cp -r src/core/annotation/template.html dist/esm/core/annotation/",
|
|
10
13
|
"copyExampleProject": "shx cp -r example_projects_templates/ dist/ && shx cp -r bin/* dist/",
|
|
11
14
|
"lint": "eslint --cache --fix --max-warnings 0 \"./**/*.{js,ts}\"",
|
|
12
15
|
"lint:staged": "lint-staged",
|
|
13
|
-
"test": "jest '/src'"
|
|
16
|
+
"test": "jest '/src'",
|
|
17
|
+
"postinstall": "node -e \"require('./bin/askui-postinstall')\""
|
|
14
18
|
},
|
|
15
19
|
"files": [
|
|
16
20
|
"dist/cjs/",
|
|
@@ -23,10 +27,11 @@
|
|
|
23
27
|
"fkill": "~7.2.1",
|
|
24
28
|
"fs-extra": "~10.0.0",
|
|
25
29
|
"got": "~11.8.2",
|
|
26
|
-
"jimp": "~0.16.1",
|
|
27
30
|
"jsdom": "~19.0.0",
|
|
31
|
+
"node-machine-id": "~1.1.12",
|
|
28
32
|
"pino": "~7.8.1",
|
|
29
33
|
"pino-pretty": "~7.5.3",
|
|
34
|
+
"sharp": "~0.30.6",
|
|
30
35
|
"url-join": "~4.0.1",
|
|
31
36
|
"wait-port": "~0.2.9",
|
|
32
37
|
"ws": "~7.4.4",
|
|
@@ -37,15 +42,17 @@
|
|
|
37
42
|
"@types/jest": "~27.4.0",
|
|
38
43
|
"@types/jsdom": "~16.2.14",
|
|
39
44
|
"@types/node": "~17.0.10",
|
|
45
|
+
"@types/sharp": "~0.30.4",
|
|
40
46
|
"@types/url-join": "~4.0.1",
|
|
41
47
|
"@types/webrtc": "~0.0.30",
|
|
42
48
|
"@types/ws": "~7.4.4",
|
|
43
|
-
"jest": "
|
|
44
|
-
"
|
|
45
|
-
"
|
|
49
|
+
"jest": "28.1.1",
|
|
50
|
+
"sharp": "^0.30.6",
|
|
51
|
+
"shx": "0.3.4",
|
|
52
|
+
"ts-jest": "28.0.4",
|
|
46
53
|
"typescript": "~4.5.4"
|
|
47
54
|
},
|
|
48
55
|
"lint-staged": {
|
|
49
56
|
"./**/*.{js,ts}": "eslint --cache --fix --max-warnings 0"
|
|
50
57
|
}
|
|
51
|
-
}
|
|
58
|
+
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ClientConnectionState = void 0;
|
|
4
|
-
var ClientConnectionState;
|
|
5
|
-
(function (ClientConnectionState) {
|
|
6
|
-
ClientConnectionState[ClientConnectionState["NOT_CONNECTED"] = 0] = "NOT_CONNECTED";
|
|
7
|
-
ClientConnectionState[ClientConnectionState["CONNECTING"] = 1] = "CONNECTING";
|
|
8
|
-
ClientConnectionState[ClientConnectionState["CONNECTED"] = 2] = "CONNECTED";
|
|
9
|
-
ClientConnectionState[ClientConnectionState["ERROR"] = 3] = "ERROR";
|
|
10
|
-
})(ClientConnectionState = exports.ClientConnectionState || (exports.ClientConnectionState = {}));
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { CredentialArgs } from '../utils/http/credentials';
|
|
2
|
-
import { AnnotationLevel } from './annotation-level';
|
|
3
|
-
export interface ClientArgs {
|
|
4
|
-
readonly controlServerUrl?: string;
|
|
5
|
-
readonly controlYourUiApi?: string;
|
|
6
|
-
readonly annotationLevel?: AnnotationLevel;
|
|
7
|
-
readonly credentials?: CredentialArgs;
|
|
8
|
-
}
|
|
9
|
-
export interface ClientArgsWithDefaults extends ClientArgs {
|
|
10
|
-
readonly controlServerUrl: string;
|
|
11
|
-
readonly controlYourUiApi: string;
|
|
12
|
-
readonly annotationLevel: AnnotationLevel;
|
|
13
|
-
}
|