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
@@ -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,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,2 @@
1
+ export declare class Base64ImageError extends Error {
2
+ }
@@ -0,0 +1,2 @@
1
+ export class Base64ImageError extends Error {
2
+ }
@@ -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,7 @@
1
+ import { Base64ImageError } from "./base-64-image-error";
2
+ export class Base64ImagePathError extends Base64ImageError {
3
+ constructor(path) {
4
+ super(`Can't create Base64Image instance from path:\n${path}\n\n` +
5
+ `No image exists at path.`);
6
+ }
7
+ }
@@ -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,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,4 +1,2 @@
1
1
  export declare class HttpClientError extends Error {
2
- contructorName: string;
3
- constructor(message: string);
4
2
  }
@@ -1,7 +1,2 @@
1
1
  export class HttpClientError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.contructorName = this.constructor.name;
5
- this.name = this.contructorName;
6
- }
7
2
  }
@@ -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
  }
@@ -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.credentials = this.credentialArgs ? new Credentials(this.credentialArgs) : undefined;
16
+ this.customHeaders = customHeaders;
17
+ this.headers = {};
18
+ this.initHeaders(credentialArgs, customHeaders);
17
19
  }
18
- get headers() {
19
- var _a;
20
- return {
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
- injectAuthHeader(options) {
25
- return this.credentials ? Object.assign(Object.assign({}, options), { headers: this.headers }) : options;
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.injectAuthHeader({ json: data, responseType: 'json', throwHttpErrors: false });
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.injectAuthHeader(options));
39
+ const response = yield got.get(url, this.injectHeaders(options));
40
40
  return response.body;
41
41
  });
42
42
  }
@@ -1,4 +1,2 @@
1
1
  export declare class ImageResizingError extends Error {
2
- contructorName: string;
3
- constructor(message: string);
4
2
  }
@@ -1,7 +1,2 @@
1
1
  export class ImageResizingError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.contructorName = this.constructor.name;
5
- this.name = this.contructorName;
6
- }
7
2
  }
@@ -1,2 +1 @@
1
1
  export { ImageResizingError } from './image-resizing-base-error';
2
- export { InvalidBase64Image } from './invalid-base64-image-error';
@@ -1,2 +1 @@
1
1
  export { ImageResizingError } from './image-resizing-base-error';
2
- export { InvalidBase64Image } from './invalid-base64-image-error';
@@ -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 { ImageResizingError, InvalidBase64Image } from './image-resize-errors';
14
- export function toBase64Image(imagePath) {
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
- let resizeRatio = 1;
50
- const orignalImage = yield read(Buffer.from(base64ImageString.replace(/^data:image\/png;base64,/, ''), 'base64'));
51
- const imageHeight = orignalImage.getHeight();
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 imageRatio = imageHeight / imageWidth;
57
- const isHeigthBiggerThanWidth = imageRatio > 1;
58
- const newHeigh = isHeigthBiggerThanWidth ? maxEdge : maxEdge * imageRatio;
59
- const newWidth = isHeigthBiggerThanWidth ? maxEdge / imageRatio : maxEdge;
60
- const newImage = orignalImage.resize(newWidth, newHeigh);
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
- return Promise.reject(new ImageResizingError(`A Problem has occured during the resizeing of the image. Error: ${error}`));
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 { AskuiClient, AskuiControlServer } from 'askui';
1
+ import { UiControlClient, UiController } from 'askui';
2
2
 
3
3
  // Server for controlling the operating system
4
- let askuiServer: AskuiControlServer;
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: AskuiClient;
8
+ let aui: UiControlClient;
9
9
 
10
10
  jest.setTimeout(60 * 1000 * 60);
11
11
 
12
12
  beforeAll(async () => {
13
- askuiServer = new AskuiControlServer({
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 askuiServer.start();
21
+ await uiController.start();
22
22
 
23
- aui = new AskuiClient();
23
+ aui = await UiControlClient.build();
24
24
 
25
25
  await aui.connect();
26
26
  });
27
27
 
28
28
  afterAll(async () => {
29
- await askuiServer.stop();
29
+ await uiController.stop();
30
30
 
31
31
  aui.close();
32
32
  });
@@ -4,6 +4,9 @@ const config: Config.InitialOptions = {
4
4
  preset: 'ts-jest',
5
5
  testEnvironment: 'node',
6
6
  setupFilesAfterEnv: ['./helper/jest.setup.ts'],
7
+ sandboxInjectedGlobals: [
8
+ 'Math',
9
+ ],
7
10
  };
8
11
 
9
12
  // eslint-disable-next-line import/no-default-export
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "askui",
3
- "version": "0.1.6",
3
+ "version": "0.2.0",
4
4
  "main": "./dist/cjs/main.js",
5
5
  "module": "./dist/esm/main.js",
6
6
  "bin": "bin/askui",
@@ -23,10 +23,11 @@
23
23
  "fkill": "~7.2.1",
24
24
  "fs-extra": "~10.0.0",
25
25
  "got": "~11.8.2",
26
- "jimp": "~0.16.1",
27
26
  "jsdom": "~19.0.0",
27
+ "node-machine-id": "~1.1.12",
28
28
  "pino": "~7.8.1",
29
29
  "pino-pretty": "~7.5.3",
30
+ "sharp": "~0.30.6",
30
31
  "url-join": "~4.0.1",
31
32
  "wait-port": "~0.2.9",
32
33
  "ws": "~7.4.4",
@@ -37,15 +38,17 @@
37
38
  "@types/jest": "~27.4.0",
38
39
  "@types/jsdom": "~16.2.14",
39
40
  "@types/node": "~17.0.10",
41
+ "@types/sharp": "~0.30.4",
40
42
  "@types/url-join": "~4.0.1",
41
43
  "@types/webrtc": "~0.0.30",
42
44
  "@types/ws": "~7.4.4",
43
- "jest": "~27.4.7",
44
- "shx": "~0.3.4",
45
- "ts-jest": "~27.1.3",
45
+ "jest": "28.1.1",
46
+ "sharp": "^0.30.6",
47
+ "shx": "0.3.4",
48
+ "ts-jest": "28.0.4",
46
49
  "typescript": "~4.5.4"
47
50
  },
48
51
  "lint-staged": {
49
52
  "./**/*.{js,ts}": "eslint --cache --fix --max-warnings 0"
50
53
  }
51
- }
54
+ }
@@ -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,2 +0,0 @@
1
- export declare class ControlUiClientError extends Error {
2
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ControlUiClientError = void 0;
4
- class ControlUiClientError extends Error {
5
- }
6
- exports.ControlUiClientError = ControlUiClientError;
@@ -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
- }
@@ -1,25 +0,0 @@
1
- import { CustomElementJson } from '../core/model/test-case-dto';
2
- import { FluentCommand } from './dsl';
3
- import { ClientConnectionState } from './client-connection-state';
4
- import { Annotation } from '../core/annotation/annotation';
5
- import { AnnotationRequest } from '../core/model/annotation-result/annotation-interface';
6
- import { ClientArgs } from './client-interface';
7
- export declare class AskuiClient extends FluentCommand {
8
- private clientArgs?;
9
- private _controlYourUiClient?;
10
- private httpClient;
11
- constructor(clientArgs?: ClientArgs | undefined);
12
- private get controlYourUiClient();
13
- private get clientArgsWithDefaults();
14
- private get api();
15
- private get executionRuntime();
16
- private annotateByDefault;
17
- connect(): Promise<ClientConnectionState>;
18
- annotate(annotationRequest?: AnnotationRequest): Promise<Annotation>;
19
- annotateInteractively(): Promise<void>;
20
- exec(instruction: string, customElementJson?: CustomElementJson[]): Promise<void>;
21
- /**
22
- * closes the connection to the controlui-server`.
23
- */
24
- close(): void;
25
- }
@@ -1,8 +0,0 @@
1
- import { ControlUiServerArgs } from './control-ui-server-args';
2
- export declare class AskuiControlServer {
3
- private args?;
4
- private server;
5
- constructor(args?: ControlUiServerArgs | undefined);
6
- start(timeoutInSeconds?: number): Promise<void>;
7
- stop(forceStop?: boolean): Promise<void>;
8
- }
@@ -1,21 +0,0 @@
1
- import { LogLevels } from '../shared/log-levels';
2
- export interface ControlUiServerArgs {
3
- readonly display?: number;
4
- readonly binaryVersion?: string;
5
- readonly port?: number;
6
- readonly host?: string;
7
- readonly minimize?: boolean;
8
- readonly overWriteBinary?: boolean;
9
- readonly logLevel?: LogLevels;
10
- readonly logFilePath?: string;
11
- }
12
- export interface ControlUiServerArgsWithDefaults extends ControlUiServerArgs {
13
- readonly display: number;
14
- readonly binaryVersion: string;
15
- readonly overWriteBinary: boolean;
16
- readonly port: number;
17
- readonly host: string;
18
- readonly logLevel?: LogLevels;
19
- }
20
- export declare function createArgsWithDefaults(args?: ControlUiServerArgs): ControlUiServerArgsWithDefaults;
21
- export declare function createCliFlagsFromArgs(args: ControlUiServerArgsWithDefaults): string[];
@@ -1,6 +0,0 @@
1
- import { ControlUiServerFacade } from './control-ui-server-facade';
2
- export declare class ControlUiServerDarwin extends ControlUiServerFacade {
3
- protected makeBinaryExecutable(): void;
4
- protected getStartingCommand(): string;
5
- private makeDiskImageExecutable;
6
- }
@@ -1,16 +0,0 @@
1
- import { ControlUiServerArgs, ControlUiServerArgsWithDefaults } from './control-ui-server-args';
2
- export declare abstract class ControlUiServerFacade {
3
- protected binaryPath: string;
4
- protected serverLogFile: string;
5
- protected readonly DefaultmaxWaitingForStartingInMs: number;
6
- start(args?: ControlUiServerArgs, maxWaitingForStartingInSeconds?: number): Promise<void>;
7
- stop(args?: ControlUiServerArgs, forceStop?: boolean): Promise<void>;
8
- protected serverLogFilePath(args?: ControlUiServerArgsWithDefaults): ControlUiServerArgsWithDefaults;
9
- protected killPort(port: number, forceStop?: boolean): Promise<void>;
10
- protected getStartingCommand(): string;
11
- protected makeBinaryExecutable(): void;
12
- protected waitUntilStarted(args: ControlUiServerArgsWithDefaults, maxWaitingForStartingInSeconds?: number): Promise<void>;
13
- private isBinaryValid;
14
- private getBinary;
15
- private startWithDefaults;
16
- }
@@ -1,4 +0,0 @@
1
- import { ControlUiServerFacade } from './control-ui-server-facade';
2
- export declare class ControlUiServerLinux extends ControlUiServerFacade {
3
- protected makeBinaryExecutable(): void;
4
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ControlUiServerLinux = void 0;
4
- const child_process_1 = require("child_process");
5
- const control_ui_server_facade_1 = require("./control-ui-server-facade");
6
- const logger_1 = require("./logger");
7
- class ControlUiServerLinux extends control_ui_server_facade_1.ControlUiServerFacade {
8
- // eslint-disable-next-line class-methods-use-this
9
- makeBinaryExecutable() {
10
- (0, child_process_1.exec)(`chmod +x ${this.binaryPath}`, (_exception, stdout) => logger_1.logger.debug(stdout));
11
- }
12
- }
13
- exports.ControlUiServerLinux = ControlUiServerLinux;
@@ -1,3 +0,0 @@
1
- import { ControlUiServerFacade } from './control-ui-server-facade';
2
- export declare class ControlUiServerWin32 extends ControlUiServerFacade {
3
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ControlUiServerWin32 = void 0;
4
- const control_ui_server_facade_1 = require("./control-ui-server-facade");
5
- class ControlUiServerWin32 extends control_ui_server_facade_1.ControlUiServerFacade {
6
- }
7
- exports.ControlUiServerWin32 = ControlUiServerWin32;
@@ -1,7 +0,0 @@
1
- export var ClientConnectionState;
2
- (function (ClientConnectionState) {
3
- ClientConnectionState[ClientConnectionState["NOT_CONNECTED"] = 0] = "NOT_CONNECTED";
4
- ClientConnectionState[ClientConnectionState["CONNECTING"] = 1] = "CONNECTING";
5
- ClientConnectionState[ClientConnectionState["CONNECTED"] = 2] = "CONNECTED";
6
- ClientConnectionState[ClientConnectionState["ERROR"] = 3] = "ERROR";
7
- })(ClientConnectionState || (ClientConnectionState = {}));
@@ -1,2 +0,0 @@
1
- export declare class ControlUiClientError extends Error {
2
- }
@@ -1,2 +0,0 @@
1
- export class ControlUiClientError extends Error {
2
- }
@@ -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
- }