askui 0.1.6 → 0.2.0
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/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/execution/dsl.d.ts +6 -17
- package/dist/cjs/execution/dsl.js +4 -21
- package/dist/cjs/execution/execution-runtime.d.ts +5 -5
- package/dist/cjs/execution/execution-runtime.js +14 -14
- 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} +3 -3
- package/dist/cjs/execution/{control-your-ui-api.js → inference-client.js} +8 -8
- 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 +34 -0
- package/dist/cjs/execution/{client.js → ui-control-client.js} +48 -29
- 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/download-binaries.js +8 -8
- 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 +32 -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/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-path-error.d.ts +4 -0
- package/dist/cjs/utils/base_64_image/base-64-image-path-error.js +11 -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/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/execution/dsl.d.ts +6 -17
- package/dist/esm/execution/dsl.js +3 -21
- package/dist/esm/execution/execution-runtime.d.ts +5 -5
- package/dist/esm/execution/execution-runtime.js +14 -14
- 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} +3 -3
- package/dist/esm/execution/{control-your-ui-api.js → inference-client.js} +6 -6
- 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 +34 -0
- package/dist/esm/execution/{client.js → ui-control-client.js} +46 -27
- 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/download-binaries.js +8 -8
- 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 +25 -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/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-path-error.d.ts +4 -0
- package/dist/esm/utils/base_64_image/base-64-image-path-error.js +7 -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/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 +9 -6
- 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/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/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/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
|
@@ -9,23 +9,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
12
|
+
exports.UiController = void 0;
|
|
13
|
+
const ui_controller_darwin_1 = require("./ui-controller-darwin");
|
|
14
|
+
const ui_controller_linux_1 = require("./ui-controller-linux");
|
|
15
|
+
const ui_controller_win32_1 = require("./ui-controller-win32");
|
|
16
16
|
const download_binaries_1 = require("./download-binaries");
|
|
17
|
-
class
|
|
17
|
+
class UiController {
|
|
18
18
|
constructor(args) {
|
|
19
19
|
this.args = args;
|
|
20
20
|
switch ((0, download_binaries_1.platform)()) {
|
|
21
21
|
case 'darwin':
|
|
22
|
-
this.server = new
|
|
22
|
+
this.server = new ui_controller_darwin_1.UiControllerDarwin();
|
|
23
23
|
break;
|
|
24
24
|
case 'linux':
|
|
25
|
-
this.server = new
|
|
25
|
+
this.server = new ui_controller_linux_1.UiControllerLinux();
|
|
26
26
|
break;
|
|
27
27
|
case 'win32':
|
|
28
|
-
this.server = new
|
|
28
|
+
this.server = new ui_controller_win32_1.UiControllerWin32();
|
|
29
29
|
break;
|
|
30
30
|
default:
|
|
31
31
|
throw new Error(`Platform "${(0, download_binaries_1.platform)()}" not supported.`);
|
|
@@ -42,4 +42,4 @@ class AskuiControlServer {
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
exports.
|
|
45
|
+
exports.UiController = UiController;
|
|
@@ -2,10 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnkownError = void 0;
|
|
4
4
|
class UnkownError extends Error {
|
|
5
|
-
constructor(message) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.contructorName = this.constructor.name;
|
|
8
|
-
this.name = this.contructorName;
|
|
9
|
-
}
|
|
10
5
|
}
|
|
11
6
|
exports.UnkownError = UnkownError;
|
package/dist/cjs/main.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { UiController } from './lib';
|
|
2
|
+
export { UiControlClient, AnnotationLevel } from './execution';
|
|
3
|
+
export { LogLevels } from './shared';
|
package/dist/cjs/main.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.LogLevels = exports.AnnotationLevel = exports.UiControlClient = exports.UiController = void 0;
|
|
4
4
|
var lib_1 = require("./lib");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "UiController", { enumerable: true, get: function () { return lib_1.UiController; } });
|
|
6
6
|
var execution_1 = require("./execution");
|
|
7
|
-
Object.defineProperty(exports, "
|
|
7
|
+
Object.defineProperty(exports, "UiControlClient", { enumerable: true, get: function () { return execution_1.UiControlClient; } });
|
|
8
|
+
Object.defineProperty(exports, "AnnotationLevel", { enumerable: true, get: function () { return execution_1.AnnotationLevel; } });
|
|
9
|
+
var shared_1 = require("./shared");
|
|
10
|
+
Object.defineProperty(exports, "LogLevels", { enumerable: true, get: function () { return shared_1.LogLevels; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LogLevels } from './log-levels';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogLevels = void 0;
|
|
4
|
+
var log_levels_1 = require("./log-levels");
|
|
5
|
+
Object.defineProperty(exports, "LogLevels", { enumerable: true, get: function () { return log_levels_1.LogLevels; } });
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Analytics = void 0;
|
|
16
|
+
const os_1 = __importDefault(require("os"));
|
|
17
|
+
const user_identifier_1 = require("./user-identifier");
|
|
18
|
+
class Analytics {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.userIdentifier = new user_identifier_1.UserIdentifier();
|
|
21
|
+
}
|
|
22
|
+
getAnalyticsHeaders() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const userID = yield this.userIdentifier.userId();
|
|
25
|
+
return {
|
|
26
|
+
'askui-user-id': userID,
|
|
27
|
+
'askui-user-agent': `os:${os_1.default.platform()};arch:${os_1.default.arch()}`,
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Analytics = Analytics;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Analytics } from './analytics';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Analytics = void 0;
|
|
4
|
+
var analytics_1 = require("./analytics");
|
|
5
|
+
Object.defineProperty(exports, "Analytics", { enumerable: true, get: function () { return analytics_1.Analytics; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UserIdentifier = void 0;
|
|
13
|
+
const node_machine_id_1 = require("node-machine-id");
|
|
14
|
+
class UserIdentifier {
|
|
15
|
+
// eslint-disable-next-line class-methods-use-this
|
|
16
|
+
userId() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
return (0, node_machine_id_1.machineId)();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.UserIdentifier = UserIdentifier;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Base64ImagePathError = void 0;
|
|
4
|
+
const base_64_image_error_1 = require("./base-64-image-error");
|
|
5
|
+
class Base64ImagePathError extends base_64_image_error_1.Base64ImageError {
|
|
6
|
+
constructor(path) {
|
|
7
|
+
super(`Can't create Base64Image instance from path:\n${path}\n\n` +
|
|
8
|
+
`No image exists at path.`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.Base64ImagePathError = Base64ImagePathError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Base64ImageStringError = void 0;
|
|
4
|
+
const base_64_image_error_1 = require("./base-64-image-error");
|
|
5
|
+
class Base64ImageStringError extends base_64_image_error_1.Base64ImageError {
|
|
6
|
+
constructor(str, prefix) {
|
|
7
|
+
super(`Can't create Base64Image instance from string:\n${str}\n\n`
|
|
8
|
+
+ `String should start with "${prefix}".`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.Base64ImageStringError = Base64ImageStringError;
|
|
@@ -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,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Base64Image = void 0;
|
|
16
|
+
const sharp_1 = __importDefault(require("sharp"));
|
|
17
|
+
const base_64_image_string_error_1 = require("./base-64-image-string-error");
|
|
18
|
+
class Base64Image {
|
|
19
|
+
constructor(aSharp, info, buffer) {
|
|
20
|
+
this.aSharp = aSharp;
|
|
21
|
+
this.info = info;
|
|
22
|
+
this.buffer = buffer;
|
|
23
|
+
}
|
|
24
|
+
static fromSharp(s) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const { info, data } = yield s.toBuffer({ resolveWithObject: true });
|
|
27
|
+
return new Base64Image(s, info, data);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
static fromPathOrString(pathOrStr) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
try {
|
|
33
|
+
return yield Base64Image.fromString(pathOrStr);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (!(error instanceof base_64_image_string_error_1.Base64ImageStringError)) {
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return Base64Image.fromPath(pathOrStr);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
static fromPath(path) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
return Base64Image.fromSharp((0, sharp_1.default)(path));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
static fromString(str) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
if (!str.startsWith(Base64Image.strPrefix)) {
|
|
51
|
+
throw new base_64_image_string_error_1.Base64ImageStringError(str, Base64Image.strPrefix);
|
|
52
|
+
}
|
|
53
|
+
const data = str.substring(Base64Image.strPrefix.length);
|
|
54
|
+
return Base64Image.fromSharp((0, sharp_1.default)(Buffer.from(data, 'base64')));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
static fromBuffer(buffer) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
return Base64Image.fromSharp((0, sharp_1.default)(buffer));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
get width() {
|
|
63
|
+
return this.info.width;
|
|
64
|
+
}
|
|
65
|
+
get height() {
|
|
66
|
+
return this.info.height;
|
|
67
|
+
}
|
|
68
|
+
resizeToFitInto(dimension) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const buffer = yield this.aSharp.resize({
|
|
71
|
+
width: this.width >= this.height ? dimension : undefined,
|
|
72
|
+
height: this.height > this.width ? dimension : undefined,
|
|
73
|
+
fit: sharp_1.default.fit.contain,
|
|
74
|
+
}).toBuffer();
|
|
75
|
+
return Base64Image.fromBuffer(buffer);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
toString() {
|
|
79
|
+
return `${Base64Image.strPrefix}${this.buffer.toString('base64')}`;
|
|
80
|
+
}
|
|
81
|
+
toBuffer() {
|
|
82
|
+
return this.buffer;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.Base64Image = Base64Image;
|
|
86
|
+
Base64Image.strPrefix = 'data:image/png;base64,';
|
|
@@ -2,10 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HttpClientError = void 0;
|
|
4
4
|
class HttpClientError extends Error {
|
|
5
|
-
constructor(message) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.contructorName = this.constructor.name;
|
|
8
|
-
this.name = this.contructorName;
|
|
9
|
-
}
|
|
10
5
|
}
|
|
11
6
|
exports.HttpClientError = HttpClientError;
|
|
@@ -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
|
}
|
|
@@ -17,22 +17,22 @@ const got_1 = __importDefault(require("got"));
|
|
|
17
17
|
const credentials_1 = require("./credentials");
|
|
18
18
|
const custom_errors_1 = require("./custom-errors");
|
|
19
19
|
class HttpClientGot {
|
|
20
|
-
constructor(credentialArgs) {
|
|
20
|
+
constructor(credentialArgs, customHeaders) {
|
|
21
21
|
this.credentialArgs = credentialArgs;
|
|
22
|
-
this.
|
|
22
|
+
this.customHeaders = customHeaders;
|
|
23
|
+
this.headers = {};
|
|
24
|
+
this.initHeaders(credentialArgs, customHeaders);
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Authorization: `Basic ${(_a = this.credentials) === null || _a === void 0 ? void 0 : _a.base64Encoded}`,
|
|
28
|
-
};
|
|
26
|
+
initHeaders(credentialArgs, customHeaders = {}) {
|
|
27
|
+
const credentials = credentialArgs ? new credentials_1.Credentials(credentialArgs) : undefined;
|
|
28
|
+
this.headers = Object.assign(Object.assign({}, (credentials ? { Authorization: `Basic ${credentials === null || credentials === void 0 ? void 0 : credentials.base64Encoded}` } : {})), customHeaders);
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
return
|
|
30
|
+
injectHeaders(options) {
|
|
31
|
+
return Object.assign(Object.assign({}, options), { headers: this.headers });
|
|
32
32
|
}
|
|
33
33
|
post(url, data) {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const options = this.
|
|
35
|
+
const options = this.injectHeaders({ json: data, responseType: 'json', throwHttpErrors: false });
|
|
36
36
|
const { body, statusCode } = yield got_1.default.post(url, options);
|
|
37
37
|
if (statusCode !== 200) {
|
|
38
38
|
throw (0, custom_errors_1.httpClientErrorHandler)(statusCode, JSON.stringify(body));
|
|
@@ -42,7 +42,7 @@ class HttpClientGot {
|
|
|
42
42
|
}
|
|
43
43
|
get(url, options = { responseType: 'json' }) {
|
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const response = yield got_1.default.get(url, this.
|
|
45
|
+
const response = yield got_1.default.get(url, this.injectHeaders(options));
|
|
46
46
|
return response.body;
|
|
47
47
|
});
|
|
48
48
|
}
|
|
@@ -2,10 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImageResizingError = void 0;
|
|
4
4
|
class ImageResizingError extends Error {
|
|
5
|
-
constructor(message) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.contructorName = this.constructor.name;
|
|
8
|
-
this.name = this.contructorName;
|
|
9
|
-
}
|
|
10
5
|
}
|
|
11
6
|
exports.ImageResizingError = ImageResizingError;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ImageResizingError = void 0;
|
|
4
4
|
var image_resizing_base_error_1 = require("./image-resizing-base-error");
|
|
5
5
|
Object.defineProperty(exports, "ImageResizingError", { enumerable: true, get: function () { return image_resizing_base_error_1.ImageResizingError; } });
|
|
6
|
-
var invalid_base64_image_error_1 = require("./invalid-base64-image-error");
|
|
7
|
-
Object.defineProperty(exports, "InvalidBase64Image", { enumerable: true, get: function () { return invalid_base64_image_error_1.InvalidBase64Image; } });
|
|
@@ -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.
|
|
@@ -8,35 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.resizeBase64ImageWithSameRatio =
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const jimp_1 = require("jimp");
|
|
12
|
+
exports.resizeBase64ImageWithSameRatio = void 0;
|
|
18
13
|
const lib_1 = require("../lib");
|
|
14
|
+
const base_64_image_1 = require("./base_64_image/base-64-image");
|
|
19
15
|
const image_resize_errors_1 = require("./image-resize-errors");
|
|
20
|
-
function toBase64Image(imagePath) {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
if (!(fs_1.default.existsSync(imagePath))) {
|
|
23
|
-
throw new Error(`the image ${imagePath} does not exists!`);
|
|
24
|
-
}
|
|
25
|
-
const image = yield (0, jimp_1.read)(imagePath);
|
|
26
|
-
return image.getBase64Async('image/png');
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
exports.toBase64Image = toBase64Image;
|
|
30
|
-
function toBase64ImageIfNeeded(pngPathOrBase64Image) {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const isBase64Image = pngPathOrBase64Image.startsWith('data:image');
|
|
33
|
-
if (!isBase64Image) {
|
|
34
|
-
return toBase64Image(pngPathOrBase64Image);
|
|
35
|
-
}
|
|
36
|
-
return pngPathOrBase64Image;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
exports.toBase64ImageIfNeeded = toBase64ImageIfNeeded;
|
|
40
16
|
/**
|
|
41
17
|
* Resizes a base64image only when the height or the width is bigger than the maxEdge Param,so that
|
|
42
18
|
* the returned image keeps the same aspect ratio but have a max size equal to the threshold.
|
|
@@ -50,28 +26,19 @@ exports.toBase64ImageIfNeeded = toBase64ImageIfNeeded;
|
|
|
50
26
|
function resizeBase64ImageWithSameRatio(base64ImageString, maxEdge = 1400) {
|
|
51
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
28
|
lib_1.logger.debug('Image resizing');
|
|
53
|
-
if (!(base64ImageString.startsWith('data:image'))) {
|
|
54
|
-
Promise.reject(new image_resize_errors_1.InvalidBase64Image('Invalid base64 image string'));
|
|
55
|
-
}
|
|
56
29
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const imageWidth = orignalImage.getWidth();
|
|
61
|
-
if (Math.max(imageHeight, imageWidth) <= maxEdge) {
|
|
62
|
-
return yield Promise.resolve({ base64Image: base64ImageString, resizeRatio });
|
|
30
|
+
const image = yield base_64_image_1.Base64Image.fromString(base64ImageString);
|
|
31
|
+
if (image.height <= maxEdge && image.width <= maxEdge) {
|
|
32
|
+
return { base64Image: base64ImageString, resizeRatio: 1 };
|
|
63
33
|
}
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
resizeRatio = imageHeight / newHeigh;
|
|
70
|
-
const newImageBase64 = yield newImage.getBase64Async('image/png');
|
|
71
|
-
return yield Promise.resolve({ base64Image: newImageBase64, resizeRatio });
|
|
34
|
+
const resizedImage = yield image.resizeToFitInto(maxEdge);
|
|
35
|
+
return {
|
|
36
|
+
base64Image: resizedImage.toString(),
|
|
37
|
+
resizeRatio: image.width / resizedImage.width,
|
|
38
|
+
};
|
|
72
39
|
}
|
|
73
40
|
catch (error) {
|
|
74
|
-
|
|
41
|
+
throw new image_resize_errors_1.ImageResizingError(`A Problem has occured during the resizing of the image. Error: ${error}`);
|
|
75
42
|
}
|
|
76
43
|
});
|
|
77
44
|
}
|
|
@@ -4,13 +4,13 @@ export declare class CustomElement implements CustomElementJson {
|
|
|
4
4
|
name?: string | undefined;
|
|
5
5
|
threshold?: number | undefined;
|
|
6
6
|
rotationDegreePerStep?: number | undefined;
|
|
7
|
-
imageCompareFormat?: "
|
|
7
|
+
imageCompareFormat?: "RGB" | "grayscale" | undefined;
|
|
8
8
|
mask?: {
|
|
9
9
|
x: number;
|
|
10
10
|
y: number;
|
|
11
11
|
}[] | undefined;
|
|
12
12
|
private static schema;
|
|
13
|
-
constructor(customImage: string, name?: string | undefined, threshold?: number | undefined, rotationDegreePerStep?: number | undefined, imageCompareFormat?: "
|
|
13
|
+
constructor(customImage: string, name?: string | undefined, threshold?: number | undefined, rotationDegreePerStep?: number | undefined, imageCompareFormat?: "RGB" | "grayscale" | undefined, mask?: {
|
|
14
14
|
x: number;
|
|
15
15
|
y: number;
|
|
16
16
|
}[] | undefined);
|
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { array, number, object, ValidationError, } from 'yup';
|
|
11
|
-
import {
|
|
11
|
+
import { Base64Image } from '../../../utils/base_64_image/base-64-image';
|
|
12
12
|
export class CustomElement {
|
|
13
13
|
constructor(customImage, name, threshold, rotationDegreePerStep, imageCompareFormat, mask) {
|
|
14
14
|
this.customImage = customImage;
|
|
@@ -25,7 +25,7 @@ export class CustomElement {
|
|
|
25
25
|
}
|
|
26
26
|
static fromJsonWithImagePathOrImage(ceJson) {
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
const customImage = yield
|
|
28
|
+
const customImage = (yield Base64Image.fromPathOrString(ceJson.customImage)).toString();
|
|
29
29
|
const customElement = CustomElement.fromJson(Object.assign(Object.assign({}, ceJson), { customImage }));
|
|
30
30
|
customElement.validate();
|
|
31
31
|
return customElement;
|