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.
Files changed (188) hide show
  1. package/README.md +6 -0
  2. package/dist/cjs/core/model/test-case-dto/custom-element.d.ts +2 -2
  3. package/dist/cjs/core/model/test-case-dto/custom-element.js +2 -2
  4. package/dist/cjs/core/model/test-case-dto/custom-element.spec.js +7 -6
  5. package/dist/cjs/execution/dsl.d.ts +6 -17
  6. package/dist/cjs/execution/dsl.js +4 -21
  7. package/dist/cjs/execution/execution-runtime.d.ts +5 -5
  8. package/dist/cjs/execution/execution-runtime.js +14 -14
  9. package/dist/cjs/execution/index.d.ts +2 -1
  10. package/dist/cjs/execution/index.js +5 -3
  11. package/dist/cjs/execution/{control-your-ui-api.d.ts → inference-client.d.ts} +3 -3
  12. package/dist/cjs/execution/{control-your-ui-api.js → inference-client.js} +8 -8
  13. package/dist/cjs/execution/ui-control-client-error.d.ts +2 -0
  14. package/dist/cjs/execution/ui-control-client-error.js +6 -0
  15. package/dist/cjs/execution/ui-control-client.d.ts +34 -0
  16. package/dist/cjs/execution/{client.js → ui-control-client.js} +48 -29
  17. package/dist/cjs/execution/{client-connection-state.d.ts → ui-controller-client-connection-state.d.ts} +1 -1
  18. package/dist/cjs/execution/ui-controller-client-connection-state.js +10 -0
  19. package/dist/cjs/execution/ui-controller-client-interface.d.ts +27 -0
  20. package/dist/cjs/execution/{client-interface.js → ui-controller-client-interface.js} +0 -0
  21. package/dist/cjs/execution/{control-your-ui-client.d.ts → ui-controller-client.d.ts} +6 -6
  22. package/dist/cjs/execution/{control-your-ui-client.js → ui-controller-client.js} +28 -28
  23. package/dist/cjs/lib/download-binaries.js +8 -8
  24. package/dist/cjs/lib/index.d.ts +1 -1
  25. package/dist/cjs/lib/index.js +3 -3
  26. package/dist/cjs/lib/libfuse-error.d.ts +2 -0
  27. package/dist/cjs/lib/libfuse-error.js +6 -0
  28. package/dist/cjs/lib/logger.js +1 -1
  29. package/dist/cjs/lib/timeout-error.d.ts +0 -2
  30. package/dist/cjs/lib/timeout-error.js +0 -5
  31. package/dist/cjs/lib/ui-controller-args.d.ts +47 -0
  32. package/dist/cjs/lib/{control-ui-server-args.js → ui-controller-args.js} +0 -0
  33. package/dist/cjs/lib/{control-ui-server-args.spec.d.ts → ui-controller-args.spec.d.ts} +0 -0
  34. package/dist/cjs/lib/{control-ui-server-args.spec.js → ui-controller-args.spec.js} +7 -7
  35. package/dist/cjs/lib/ui-controller-darwin.d.ts +6 -0
  36. package/dist/cjs/lib/{control-ui-server-darwin.js → ui-controller-darwin.js} +8 -8
  37. package/dist/cjs/lib/ui-controller-facade.d.ts +17 -0
  38. package/dist/cjs/lib/{control-ui-server-facade.js → ui-controller-facade.js} +22 -16
  39. package/dist/cjs/lib/ui-controller-linux.d.ts +5 -0
  40. package/dist/cjs/lib/ui-controller-linux.js +52 -0
  41. package/dist/cjs/lib/ui-controller-win32.d.ts +3 -0
  42. package/dist/cjs/lib/ui-controller-win32.js +7 -0
  43. package/dist/cjs/lib/ui-controller.d.ts +8 -0
  44. package/dist/cjs/lib/{askui-control-server.js → ui-controller.js} +9 -9
  45. package/dist/cjs/lib/unkown-error.d.ts +0 -2
  46. package/dist/cjs/lib/unkown-error.js +0 -5
  47. package/dist/cjs/lib/wayland-error.d.ts +2 -0
  48. package/dist/cjs/lib/wayland-error.js +6 -0
  49. package/dist/cjs/main.d.ts +3 -2
  50. package/dist/cjs/main.js +6 -3
  51. package/dist/cjs/shared/index.d.ts +1 -0
  52. package/dist/cjs/shared/index.js +5 -0
  53. package/dist/cjs/utils/analytics/analytics-interface.d.ts +3 -0
  54. package/dist/cjs/utils/analytics/analytics-interface.js +2 -0
  55. package/dist/cjs/utils/analytics/analytics.d.ts +5 -0
  56. package/dist/cjs/utils/analytics/analytics.js +32 -0
  57. package/dist/cjs/utils/analytics/index.d.ts +1 -0
  58. package/dist/cjs/utils/analytics/index.js +5 -0
  59. package/dist/cjs/utils/analytics/user-identifier-interface.d.ts +3 -0
  60. package/dist/cjs/utils/analytics/user-identifier-interface.js +2 -0
  61. package/dist/cjs/utils/analytics/user-identifier.d.ts +4 -0
  62. package/dist/cjs/utils/analytics/user-identifier.js +22 -0
  63. package/dist/cjs/utils/base_64_image/base-64-image-error.d.ts +2 -0
  64. package/dist/cjs/utils/base_64_image/base-64-image-error.js +6 -0
  65. package/dist/cjs/utils/base_64_image/base-64-image-path-error.d.ts +4 -0
  66. package/dist/cjs/utils/base_64_image/base-64-image-path-error.js +11 -0
  67. package/dist/cjs/utils/base_64_image/base-64-image-string-error.d.ts +4 -0
  68. package/dist/cjs/utils/base_64_image/base-64-image-string-error.js +11 -0
  69. package/dist/cjs/utils/base_64_image/base-64-image.d.ts +18 -0
  70. package/dist/cjs/utils/base_64_image/base-64-image.js +86 -0
  71. package/dist/cjs/utils/http/custom-errors/http-client-error.d.ts +0 -2
  72. package/dist/cjs/utils/http/custom-errors/http-client-error.js +0 -5
  73. package/dist/cjs/utils/http/http-client-got.d.ts +6 -5
  74. package/dist/cjs/utils/http/http-client-got.js +11 -11
  75. package/dist/cjs/utils/image-resize-errors/image-resizing-base-error.d.ts +0 -2
  76. package/dist/cjs/utils/image-resize-errors/image-resizing-base-error.js +0 -5
  77. package/dist/cjs/utils/image-resize-errors/index.d.ts +0 -1
  78. package/dist/cjs/utils/image-resize-errors/index.js +1 -3
  79. package/dist/cjs/utils/transformations.d.ts +0 -2
  80. package/dist/cjs/utils/transformations.js +11 -44
  81. package/dist/esm/core/model/test-case-dto/custom-element.d.ts +2 -2
  82. package/dist/esm/core/model/test-case-dto/custom-element.js +2 -2
  83. package/dist/esm/core/model/test-case-dto/custom-element.spec.js +7 -6
  84. package/dist/esm/execution/dsl.d.ts +6 -17
  85. package/dist/esm/execution/dsl.js +3 -21
  86. package/dist/esm/execution/execution-runtime.d.ts +5 -5
  87. package/dist/esm/execution/execution-runtime.js +14 -14
  88. package/dist/esm/execution/index.d.ts +2 -1
  89. package/dist/esm/execution/index.js +2 -1
  90. package/dist/esm/execution/{control-your-ui-api.d.ts → inference-client.d.ts} +3 -3
  91. package/dist/esm/execution/{control-your-ui-api.js → inference-client.js} +6 -6
  92. package/dist/esm/execution/ui-control-client-error.d.ts +2 -0
  93. package/dist/esm/execution/ui-control-client-error.js +2 -0
  94. package/dist/esm/execution/ui-control-client.d.ts +34 -0
  95. package/dist/esm/execution/{client.js → ui-control-client.js} +46 -27
  96. package/dist/esm/execution/{client-connection-state.d.ts → ui-controller-client-connection-state.d.ts} +1 -1
  97. package/dist/esm/execution/ui-controller-client-connection-state.js +7 -0
  98. package/dist/esm/execution/ui-controller-client-interface.d.ts +27 -0
  99. package/dist/esm/execution/{client-interface.js → ui-controller-client-interface.js} +0 -0
  100. package/dist/esm/execution/{control-your-ui-client.d.ts → ui-controller-client.d.ts} +6 -6
  101. package/dist/esm/execution/{control-your-ui-client.js → ui-controller-client.js} +26 -26
  102. package/dist/esm/lib/download-binaries.js +8 -8
  103. package/dist/esm/lib/index.d.ts +1 -1
  104. package/dist/esm/lib/index.js +1 -1
  105. package/dist/esm/lib/libfuse-error.d.ts +2 -0
  106. package/dist/esm/lib/libfuse-error.js +2 -0
  107. package/dist/esm/lib/logger.js +1 -1
  108. package/dist/esm/lib/timeout-error.d.ts +0 -2
  109. package/dist/esm/lib/timeout-error.js +0 -5
  110. package/dist/esm/lib/ui-controller-args.d.ts +47 -0
  111. package/dist/esm/lib/{control-ui-server-args.js → ui-controller-args.js} +0 -0
  112. package/dist/esm/lib/{control-ui-server-args.spec.d.ts → ui-controller-args.spec.d.ts} +0 -0
  113. package/dist/esm/lib/{control-ui-server-args.spec.js → ui-controller-args.spec.js} +1 -1
  114. package/dist/esm/lib/ui-controller-darwin.d.ts +6 -0
  115. package/dist/esm/lib/{control-ui-server-darwin.js → ui-controller-darwin.js} +6 -6
  116. package/dist/esm/lib/ui-controller-facade.d.ts +17 -0
  117. package/dist/esm/lib/{control-ui-server-facade.js → ui-controller-facade.js} +17 -11
  118. package/dist/esm/lib/ui-controller-linux.d.ts +5 -0
  119. package/dist/esm/lib/ui-controller-linux.js +48 -0
  120. package/dist/esm/lib/ui-controller-win32.d.ts +3 -0
  121. package/dist/esm/lib/ui-controller-win32.js +3 -0
  122. package/dist/esm/lib/ui-controller.d.ts +8 -0
  123. package/dist/esm/lib/{askui-control-server.js → ui-controller.js} +7 -7
  124. package/dist/esm/lib/unkown-error.d.ts +0 -2
  125. package/dist/esm/lib/unkown-error.js +0 -5
  126. package/dist/esm/lib/wayland-error.d.ts +2 -0
  127. package/dist/esm/lib/wayland-error.js +2 -0
  128. package/dist/esm/main.d.ts +3 -2
  129. package/dist/esm/main.js +3 -2
  130. package/dist/esm/shared/index.d.ts +1 -0
  131. package/dist/esm/shared/index.js +1 -0
  132. package/dist/esm/utils/analytics/analytics-interface.d.ts +3 -0
  133. package/dist/esm/utils/analytics/analytics-interface.js +1 -0
  134. package/dist/esm/utils/analytics/analytics.d.ts +5 -0
  135. package/dist/esm/utils/analytics/analytics.js +25 -0
  136. package/dist/esm/utils/analytics/index.d.ts +1 -0
  137. package/dist/esm/utils/analytics/index.js +1 -0
  138. package/dist/esm/utils/analytics/user-identifier-interface.d.ts +3 -0
  139. package/dist/esm/utils/analytics/user-identifier-interface.js +1 -0
  140. package/dist/esm/utils/analytics/user-identifier.d.ts +4 -0
  141. package/dist/esm/utils/analytics/user-identifier.js +18 -0
  142. package/dist/esm/utils/base_64_image/base-64-image-error.d.ts +2 -0
  143. package/dist/esm/utils/base_64_image/base-64-image-error.js +2 -0
  144. package/dist/esm/utils/base_64_image/base-64-image-path-error.d.ts +4 -0
  145. package/dist/esm/utils/base_64_image/base-64-image-path-error.js +7 -0
  146. package/dist/esm/utils/base_64_image/base-64-image-string-error.d.ts +4 -0
  147. package/dist/esm/utils/base_64_image/base-64-image-string-error.js +7 -0
  148. package/dist/esm/utils/base_64_image/base-64-image.d.ts +18 -0
  149. package/dist/esm/utils/base_64_image/base-64-image.js +79 -0
  150. package/dist/esm/utils/http/custom-errors/http-client-error.d.ts +0 -2
  151. package/dist/esm/utils/http/custom-errors/http-client-error.js +0 -5
  152. package/dist/esm/utils/http/http-client-got.d.ts +6 -5
  153. package/dist/esm/utils/http/http-client-got.js +11 -11
  154. package/dist/esm/utils/image-resize-errors/image-resizing-base-error.d.ts +0 -2
  155. package/dist/esm/utils/image-resize-errors/image-resizing-base-error.js +0 -5
  156. package/dist/esm/utils/image-resize-errors/index.d.ts +0 -1
  157. package/dist/esm/utils/image-resize-errors/index.js +0 -1
  158. package/dist/esm/utils/transformations.d.ts +0 -2
  159. package/dist/esm/utils/transformations.js +11 -39
  160. package/dist/example_projects_templates/typescript_jest/test/helper/jest.setup.ts +7 -7
  161. package/dist/example_projects_templates/typescript_jest/test/jest.config.ts +3 -0
  162. package/package.json +9 -6
  163. package/dist/cjs/execution/client-connection-state.js +0 -10
  164. package/dist/cjs/execution/client-error.d.ts +0 -2
  165. package/dist/cjs/execution/client-error.js +0 -6
  166. package/dist/cjs/execution/client-interface.d.ts +0 -13
  167. package/dist/cjs/execution/client.d.ts +0 -25
  168. package/dist/cjs/lib/askui-control-server.d.ts +0 -8
  169. package/dist/cjs/lib/control-ui-server-args.d.ts +0 -21
  170. package/dist/cjs/lib/control-ui-server-darwin.d.ts +0 -6
  171. package/dist/cjs/lib/control-ui-server-facade.d.ts +0 -16
  172. package/dist/cjs/lib/control-ui-server-linux.d.ts +0 -4
  173. package/dist/cjs/lib/control-ui-server-linux.js +0 -13
  174. package/dist/cjs/lib/control-ui-server-win32.d.ts +0 -3
  175. package/dist/cjs/lib/control-ui-server-win32.js +0 -7
  176. package/dist/esm/execution/client-connection-state.js +0 -7
  177. package/dist/esm/execution/client-error.d.ts +0 -2
  178. package/dist/esm/execution/client-error.js +0 -2
  179. package/dist/esm/execution/client-interface.d.ts +0 -13
  180. package/dist/esm/execution/client.d.ts +0 -25
  181. package/dist/esm/lib/askui-control-server.d.ts +0 -8
  182. package/dist/esm/lib/control-ui-server-args.d.ts +0 -21
  183. package/dist/esm/lib/control-ui-server-darwin.d.ts +0 -6
  184. package/dist/esm/lib/control-ui-server-facade.d.ts +0 -16
  185. package/dist/esm/lib/control-ui-server-linux.d.ts +0 -4
  186. package/dist/esm/lib/control-ui-server-linux.js +0 -9
  187. package/dist/esm/lib/control-ui-server-win32.d.ts +0 -3
  188. 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.AskuiControlServer = void 0;
13
- const control_ui_server_darwin_1 = require("./control-ui-server-darwin");
14
- const control_ui_server_linux_1 = require("./control-ui-server-linux");
15
- const control_ui_server_win32_1 = require("./control-ui-server-win32");
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 AskuiControlServer {
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 control_ui_server_darwin_1.ControlUiServerDarwin();
22
+ this.server = new ui_controller_darwin_1.UiControllerDarwin();
23
23
  break;
24
24
  case 'linux':
25
- this.server = new control_ui_server_linux_1.ControlUiServerLinux();
25
+ this.server = new ui_controller_linux_1.UiControllerLinux();
26
26
  break;
27
27
  case 'win32':
28
- this.server = new control_ui_server_win32_1.ControlUiServerWin32();
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.AskuiControlServer = AskuiControlServer;
45
+ exports.UiController = UiController;
@@ -1,4 +1,2 @@
1
1
  export declare class UnkownError extends Error {
2
- contructorName: string;
3
- constructor(message: string);
4
2
  }
@@ -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;
@@ -0,0 +1,2 @@
1
+ export declare class WaylandError extends Error {
2
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WaylandError = void 0;
4
+ class WaylandError extends Error {
5
+ }
6
+ exports.WaylandError = WaylandError;
@@ -1,2 +1,3 @@
1
- export { AskuiControlServer } from './lib';
2
- export { AskuiClient } from './execution';
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.AskuiClient = exports.AskuiControlServer = void 0;
3
+ exports.LogLevels = exports.AnnotationLevel = exports.UiControlClient = exports.UiController = void 0;
4
4
  var lib_1 = require("./lib");
5
- Object.defineProperty(exports, "AskuiControlServer", { enumerable: true, get: function () { return lib_1.AskuiControlServer; } });
5
+ Object.defineProperty(exports, "UiController", { enumerable: true, get: function () { return lib_1.UiController; } });
6
6
  var execution_1 = require("./execution");
7
- Object.defineProperty(exports, "AskuiClient", { enumerable: true, get: function () { return execution_1.AskuiClient; } });
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,3 @@
1
+ export interface AnalyticsInterface {
2
+ getAnalyticsHeaders(): Promise<Record<string, string>>;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { AnalyticsInterface } from './analytics-interface';
2
+ export declare class Analytics implements AnalyticsInterface {
3
+ private userIdentifier;
4
+ getAnalyticsHeaders(): Promise<Record<string, string>>;
5
+ }
@@ -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,3 @@
1
+ export interface UserIdentifierInterface {
2
+ userId(): Promise<string>;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { UserIdentifierInterface } from './user-identifier-interface';
2
+ export declare class UserIdentifier implements UserIdentifierInterface {
3
+ userId(): Promise<string>;
4
+ }
@@ -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,2 @@
1
+ export declare class Base64ImageError extends Error {
2
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Base64ImageError = void 0;
4
+ class Base64ImageError extends Error {
5
+ }
6
+ exports.Base64ImageError = Base64ImageError;
@@ -0,0 +1,4 @@
1
+ import { Base64ImageError } from "./base-64-image-error";
2
+ export declare class Base64ImagePathError extends Base64ImageError {
3
+ constructor(path: string);
4
+ }
@@ -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,4 @@
1
+ import { Base64ImageError } from './base-64-image-error';
2
+ export declare class Base64ImageStringError extends Base64ImageError {
3
+ constructor(str: string, prefix: string);
4
+ }
@@ -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,';
@@ -1,4 +1,2 @@
1
1
  export declare class HttpClientError extends Error {
2
- contructorName: string;
3
- constructor(message: string);
4
2
  }
@@ -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
- private credentialArgs?;
5
- private credentials;
6
- constructor(credentialArgs?: CredentialArgs | undefined);
7
- private get headers();
8
- private injectAuthHeader;
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.credentials = this.credentialArgs ? new credentials_1.Credentials(this.credentialArgs) : undefined;
22
+ this.customHeaders = customHeaders;
23
+ this.headers = {};
24
+ this.initHeaders(credentialArgs, customHeaders);
23
25
  }
24
- get headers() {
25
- var _a;
26
- return {
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
- injectAuthHeader(options) {
31
- return this.credentials ? Object.assign(Object.assign({}, options), { headers: this.headers }) : options;
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.injectAuthHeader({ json: data, responseType: 'json', throwHttpErrors: false });
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.injectAuthHeader(options));
45
+ const response = yield got_1.default.get(url, this.injectHeaders(options));
46
46
  return response.body;
47
47
  });
48
48
  }
@@ -1,4 +1,2 @@
1
1
  export declare class ImageResizingError extends Error {
2
- contructorName: string;
3
- constructor(message: string);
4
2
  }
@@ -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,2 +1 @@
1
1
  export { ImageResizingError } from './image-resizing-base-error';
2
- export { InvalidBase64Image } from './invalid-base64-image-error';
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidBase64Image = exports.ImageResizingError = void 0;
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 = exports.toBase64ImageIfNeeded = exports.toBase64Image = void 0;
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
- let resizeRatio = 1;
58
- const orignalImage = yield (0, jimp_1.read)(Buffer.from(base64ImageString.replace(/^data:image\/png;base64,/, ''), 'base64'));
59
- const imageHeight = orignalImage.getHeight();
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 imageRatio = imageHeight / imageWidth;
65
- const isHeigthBiggerThanWidth = imageRatio > 1;
66
- const newHeigh = isHeigthBiggerThanWidth ? maxEdge : maxEdge * imageRatio;
67
- const newWidth = isHeigthBiggerThanWidth ? maxEdge / imageRatio : maxEdge;
68
- const newImage = orignalImage.resize(newWidth, newHeigh);
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
- return Promise.reject(new image_resize_errors_1.ImageResizingError(`A Problem has occured during the resizeing of the image. Error: ${error}`));
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?: "grayscale" | "RGB" | undefined;
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?: "grayscale" | "RGB" | undefined, mask?: {
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 { toBase64ImageIfNeeded } from '../../../utils/transformations';
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 toBase64ImageIfNeeded(ceJson.customImage);
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;