askui 0.1.6 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/README.md +6 -0
  2. package/bin/askui-postinstall +35 -0
  3. package/dist/cjs/core/model/test-case-dto/custom-element.d.ts +2 -2
  4. package/dist/cjs/core/model/test-case-dto/custom-element.js +2 -2
  5. package/dist/cjs/core/model/test-case-dto/custom-element.spec.js +7 -6
  6. package/dist/cjs/core/model/test-case-dto/index.js +1 -3
  7. package/dist/cjs/core/model/test-case-dto/test-step.d.ts +3 -7
  8. package/dist/cjs/core/model/test-case-dto/test-step.js +0 -12
  9. package/dist/cjs/core/ui-control-commands/control-command.d.ts +1 -0
  10. package/dist/cjs/core/ui-control-commands/control-command.js +5 -0
  11. package/dist/cjs/core/ui-control-commands/input-event.d.ts +1 -2
  12. package/dist/cjs/core/ui-control-commands/input-event.js +0 -1
  13. package/dist/cjs/execution/dsl.d.ts +6 -17
  14. package/dist/cjs/execution/dsl.js +4 -21
  15. package/dist/cjs/execution/execution-runtime.d.ts +7 -5
  16. package/dist/cjs/execution/execution-runtime.js +35 -23
  17. package/dist/cjs/execution/index.d.ts +2 -1
  18. package/dist/cjs/execution/index.js +5 -3
  19. package/dist/cjs/execution/{control-your-ui-api.d.ts → inference-client.d.ts} +4 -4
  20. package/dist/cjs/execution/{control-your-ui-api.js → inference-client.js} +9 -9
  21. package/dist/cjs/execution/ui-control-client-error.d.ts +2 -0
  22. package/dist/cjs/execution/ui-control-client-error.js +6 -0
  23. package/dist/cjs/execution/ui-control-client.d.ts +79 -0
  24. package/dist/cjs/execution/ui-control-client.js +185 -0
  25. package/dist/cjs/execution/{client-connection-state.d.ts → ui-controller-client-connection-state.d.ts} +1 -1
  26. package/dist/cjs/execution/ui-controller-client-connection-state.js +10 -0
  27. package/dist/cjs/execution/ui-controller-client-interface.d.ts +27 -0
  28. package/dist/cjs/execution/{client-interface.js → ui-controller-client-interface.js} +0 -0
  29. package/dist/cjs/execution/{control-your-ui-client.d.ts → ui-controller-client.d.ts} +6 -6
  30. package/dist/cjs/execution/{control-your-ui-client.js → ui-controller-client.js} +28 -28
  31. package/dist/cjs/lib/copy-example-project.js +2 -1
  32. package/dist/cjs/lib/download-binaries.js +10 -9
  33. package/dist/cjs/lib/index.d.ts +1 -1
  34. package/dist/cjs/lib/index.js +3 -3
  35. package/dist/cjs/lib/libfuse-error.d.ts +2 -0
  36. package/dist/cjs/lib/libfuse-error.js +6 -0
  37. package/dist/cjs/lib/logger.js +1 -1
  38. package/dist/cjs/lib/timeout-error.d.ts +0 -2
  39. package/dist/cjs/lib/timeout-error.js +0 -5
  40. package/dist/cjs/lib/ui-controller-args.d.ts +47 -0
  41. package/dist/cjs/lib/{control-ui-server-args.js → ui-controller-args.js} +0 -0
  42. package/dist/cjs/lib/{control-ui-server-args.spec.d.ts → ui-controller-args.spec.d.ts} +0 -0
  43. package/dist/cjs/lib/{control-ui-server-args.spec.js → ui-controller-args.spec.js} +7 -7
  44. package/dist/cjs/lib/ui-controller-darwin.d.ts +6 -0
  45. package/dist/cjs/lib/{control-ui-server-darwin.js → ui-controller-darwin.js} +8 -8
  46. package/dist/cjs/lib/ui-controller-facade.d.ts +17 -0
  47. package/dist/cjs/lib/{control-ui-server-facade.js → ui-controller-facade.js} +22 -16
  48. package/dist/cjs/lib/ui-controller-linux.d.ts +5 -0
  49. package/dist/cjs/lib/ui-controller-linux.js +52 -0
  50. package/dist/cjs/lib/ui-controller-win32.d.ts +3 -0
  51. package/dist/cjs/lib/ui-controller-win32.js +7 -0
  52. package/dist/cjs/lib/ui-controller.d.ts +8 -0
  53. package/dist/cjs/lib/{askui-control-server.js → ui-controller.js} +9 -9
  54. package/dist/cjs/lib/unkown-error.d.ts +0 -2
  55. package/dist/cjs/lib/unkown-error.js +0 -5
  56. package/dist/cjs/lib/wayland-error.d.ts +2 -0
  57. package/dist/cjs/lib/wayland-error.js +6 -0
  58. package/dist/cjs/main.d.ts +3 -2
  59. package/dist/cjs/main.js +6 -3
  60. package/dist/cjs/shared/index.d.ts +1 -0
  61. package/dist/cjs/shared/index.js +5 -0
  62. package/dist/cjs/utils/analytics/analytics-interface.d.ts +3 -0
  63. package/dist/cjs/utils/analytics/analytics-interface.js +2 -0
  64. package/dist/cjs/utils/analytics/analytics.d.ts +5 -0
  65. package/dist/cjs/utils/analytics/analytics.js +38 -0
  66. package/dist/cjs/utils/analytics/index.d.ts +1 -0
  67. package/dist/cjs/utils/analytics/index.js +5 -0
  68. package/dist/cjs/utils/analytics/installation-timestamp-create-error.d.ts +4 -0
  69. package/dist/cjs/utils/analytics/installation-timestamp-create-error.js +9 -0
  70. package/dist/cjs/utils/analytics/installation-timestamp-get-error.d.ts +4 -0
  71. package/dist/cjs/utils/analytics/installation-timestamp-get-error.js +9 -0
  72. package/dist/cjs/utils/analytics/installation-timestamp.d.ts +7 -0
  73. package/dist/cjs/utils/analytics/installation-timestamp.js +68 -0
  74. package/dist/cjs/utils/analytics/user-identifier-interface.d.ts +3 -0
  75. package/dist/cjs/utils/analytics/user-identifier-interface.js +2 -0
  76. package/dist/cjs/utils/analytics/user-identifier.d.ts +4 -0
  77. package/dist/cjs/utils/analytics/user-identifier.js +22 -0
  78. package/dist/cjs/utils/base_64_image/base-64-image-error.d.ts +2 -0
  79. package/dist/cjs/utils/base_64_image/base-64-image-error.js +6 -0
  80. package/dist/cjs/utils/base_64_image/base-64-image-string-error.d.ts +4 -0
  81. package/dist/cjs/utils/base_64_image/base-64-image-string-error.js +11 -0
  82. package/dist/cjs/utils/base_64_image/base-64-image.d.ts +18 -0
  83. package/dist/cjs/utils/base_64_image/base-64-image.js +86 -0
  84. package/dist/cjs/utils/http/custom-errors/http-client-error.d.ts +0 -2
  85. package/dist/cjs/utils/http/custom-errors/http-client-error.js +0 -5
  86. package/dist/cjs/utils/http/http-client-got.d.ts +6 -5
  87. package/dist/cjs/utils/http/http-client-got.js +11 -11
  88. package/dist/cjs/utils/image-resize-errors/image-resizing-base-error.d.ts +0 -2
  89. package/dist/cjs/utils/image-resize-errors/image-resizing-base-error.js +0 -5
  90. package/dist/cjs/utils/image-resize-errors/index.d.ts +0 -1
  91. package/dist/cjs/utils/image-resize-errors/index.js +1 -3
  92. package/dist/cjs/utils/path.d.ts +1 -0
  93. package/dist/cjs/utils/path.js +11 -0
  94. package/dist/cjs/utils/transformations.d.ts +0 -2
  95. package/dist/cjs/utils/transformations.js +11 -44
  96. package/dist/esm/core/model/test-case-dto/custom-element.d.ts +2 -2
  97. package/dist/esm/core/model/test-case-dto/custom-element.js +2 -2
  98. package/dist/esm/core/model/test-case-dto/custom-element.spec.js +7 -6
  99. package/dist/esm/core/model/test-case-dto/index.js +0 -1
  100. package/dist/esm/core/model/test-case-dto/test-step.d.ts +3 -7
  101. package/dist/esm/core/model/test-case-dto/test-step.js +1 -10
  102. package/dist/esm/core/ui-control-commands/control-command.d.ts +1 -0
  103. package/dist/esm/core/ui-control-commands/control-command.js +5 -0
  104. package/dist/esm/core/ui-control-commands/input-event.d.ts +1 -2
  105. package/dist/esm/core/ui-control-commands/input-event.js +0 -1
  106. package/dist/esm/execution/dsl.d.ts +6 -17
  107. package/dist/esm/execution/dsl.js +3 -21
  108. package/dist/esm/execution/execution-runtime.d.ts +7 -5
  109. package/dist/esm/execution/execution-runtime.js +35 -23
  110. package/dist/esm/execution/index.d.ts +2 -1
  111. package/dist/esm/execution/index.js +2 -1
  112. package/dist/esm/execution/{control-your-ui-api.d.ts → inference-client.d.ts} +4 -4
  113. package/dist/esm/execution/{control-your-ui-api.js → inference-client.js} +7 -7
  114. package/dist/esm/execution/ui-control-client-error.d.ts +2 -0
  115. package/dist/esm/execution/ui-control-client-error.js +2 -0
  116. package/dist/esm/execution/ui-control-client.d.ts +79 -0
  117. package/dist/esm/execution/ui-control-client.js +181 -0
  118. package/dist/esm/execution/{client-connection-state.d.ts → ui-controller-client-connection-state.d.ts} +1 -1
  119. package/dist/esm/execution/ui-controller-client-connection-state.js +7 -0
  120. package/dist/esm/execution/ui-controller-client-interface.d.ts +27 -0
  121. package/dist/esm/execution/{client-interface.js → ui-controller-client-interface.js} +0 -0
  122. package/dist/esm/execution/{control-your-ui-client.d.ts → ui-controller-client.d.ts} +6 -6
  123. package/dist/esm/execution/{control-your-ui-client.js → ui-controller-client.js} +26 -26
  124. package/dist/esm/lib/copy-example-project.js +2 -1
  125. package/dist/esm/lib/download-binaries.js +10 -9
  126. package/dist/esm/lib/index.d.ts +1 -1
  127. package/dist/esm/lib/index.js +1 -1
  128. package/dist/esm/lib/libfuse-error.d.ts +2 -0
  129. package/dist/esm/lib/libfuse-error.js +2 -0
  130. package/dist/esm/lib/logger.js +1 -1
  131. package/dist/esm/lib/timeout-error.d.ts +0 -2
  132. package/dist/esm/lib/timeout-error.js +0 -5
  133. package/dist/esm/lib/ui-controller-args.d.ts +47 -0
  134. package/dist/esm/lib/{control-ui-server-args.js → ui-controller-args.js} +0 -0
  135. package/dist/esm/lib/{control-ui-server-args.spec.d.ts → ui-controller-args.spec.d.ts} +0 -0
  136. package/dist/esm/lib/{control-ui-server-args.spec.js → ui-controller-args.spec.js} +1 -1
  137. package/dist/esm/lib/ui-controller-darwin.d.ts +6 -0
  138. package/dist/esm/lib/{control-ui-server-darwin.js → ui-controller-darwin.js} +6 -6
  139. package/dist/esm/lib/ui-controller-facade.d.ts +17 -0
  140. package/dist/esm/lib/{control-ui-server-facade.js → ui-controller-facade.js} +17 -11
  141. package/dist/esm/lib/ui-controller-linux.d.ts +5 -0
  142. package/dist/esm/lib/ui-controller-linux.js +48 -0
  143. package/dist/esm/lib/ui-controller-win32.d.ts +3 -0
  144. package/dist/esm/lib/ui-controller-win32.js +3 -0
  145. package/dist/esm/lib/ui-controller.d.ts +8 -0
  146. package/dist/esm/lib/{askui-control-server.js → ui-controller.js} +7 -7
  147. package/dist/esm/lib/unkown-error.d.ts +0 -2
  148. package/dist/esm/lib/unkown-error.js +0 -5
  149. package/dist/esm/lib/wayland-error.d.ts +2 -0
  150. package/dist/esm/lib/wayland-error.js +2 -0
  151. package/dist/esm/main.d.ts +3 -2
  152. package/dist/esm/main.js +3 -2
  153. package/dist/esm/shared/index.d.ts +1 -0
  154. package/dist/esm/shared/index.js +1 -0
  155. package/dist/esm/utils/analytics/analytics-interface.d.ts +3 -0
  156. package/dist/esm/utils/analytics/analytics-interface.js +1 -0
  157. package/dist/esm/utils/analytics/analytics.d.ts +5 -0
  158. package/dist/esm/utils/analytics/analytics.js +31 -0
  159. package/dist/esm/utils/analytics/index.d.ts +1 -0
  160. package/dist/esm/utils/analytics/index.js +1 -0
  161. package/dist/esm/utils/analytics/installation-timestamp-create-error.d.ts +4 -0
  162. package/dist/esm/utils/analytics/installation-timestamp-create-error.js +5 -0
  163. package/dist/esm/utils/analytics/installation-timestamp-get-error.d.ts +4 -0
  164. package/dist/esm/utils/analytics/installation-timestamp-get-error.js +5 -0
  165. package/dist/esm/utils/analytics/installation-timestamp.d.ts +7 -0
  166. package/dist/esm/utils/analytics/installation-timestamp.js +61 -0
  167. package/dist/esm/utils/analytics/user-identifier-interface.d.ts +3 -0
  168. package/dist/esm/utils/analytics/user-identifier-interface.js +1 -0
  169. package/dist/esm/utils/analytics/user-identifier.d.ts +4 -0
  170. package/dist/esm/utils/analytics/user-identifier.js +18 -0
  171. package/dist/esm/utils/base_64_image/base-64-image-error.d.ts +2 -0
  172. package/dist/esm/utils/base_64_image/base-64-image-error.js +2 -0
  173. package/dist/esm/utils/base_64_image/base-64-image-string-error.d.ts +4 -0
  174. package/dist/esm/utils/base_64_image/base-64-image-string-error.js +7 -0
  175. package/dist/esm/utils/base_64_image/base-64-image.d.ts +18 -0
  176. package/dist/esm/utils/base_64_image/base-64-image.js +79 -0
  177. package/dist/esm/utils/http/custom-errors/http-client-error.d.ts +0 -2
  178. package/dist/esm/utils/http/custom-errors/http-client-error.js +0 -5
  179. package/dist/esm/utils/http/http-client-got.d.ts +6 -5
  180. package/dist/esm/utils/http/http-client-got.js +11 -11
  181. package/dist/esm/utils/image-resize-errors/image-resizing-base-error.d.ts +0 -2
  182. package/dist/esm/utils/image-resize-errors/image-resizing-base-error.js +0 -5
  183. package/dist/esm/utils/image-resize-errors/index.d.ts +0 -1
  184. package/dist/esm/utils/image-resize-errors/index.js +0 -1
  185. package/dist/esm/utils/path.d.ts +1 -0
  186. package/dist/esm/utils/path.js +4 -0
  187. package/dist/esm/utils/transformations.d.ts +0 -2
  188. package/dist/esm/utils/transformations.js +11 -39
  189. package/dist/example_projects_templates/typescript_jest/test/helper/jest.setup.ts +7 -7
  190. package/dist/example_projects_templates/typescript_jest/test/jest.config.ts +3 -0
  191. package/package.json +15 -8
  192. package/dist/cjs/execution/client-connection-state.js +0 -10
  193. package/dist/cjs/execution/client-error.d.ts +0 -2
  194. package/dist/cjs/execution/client-error.js +0 -6
  195. package/dist/cjs/execution/client-interface.d.ts +0 -13
  196. package/dist/cjs/execution/client.d.ts +0 -25
  197. package/dist/cjs/execution/client.js +0 -116
  198. package/dist/cjs/lib/askui-control-server.d.ts +0 -8
  199. package/dist/cjs/lib/control-ui-server-args.d.ts +0 -21
  200. package/dist/cjs/lib/control-ui-server-darwin.d.ts +0 -6
  201. package/dist/cjs/lib/control-ui-server-facade.d.ts +0 -16
  202. package/dist/cjs/lib/control-ui-server-linux.d.ts +0 -4
  203. package/dist/cjs/lib/control-ui-server-linux.js +0 -13
  204. package/dist/cjs/lib/control-ui-server-win32.d.ts +0 -3
  205. package/dist/cjs/lib/control-ui-server-win32.js +0 -7
  206. package/dist/cjs/utils/image-resize-errors/invalid-base64-image-error.d.ts +0 -3
  207. package/dist/cjs/utils/image-resize-errors/invalid-base64-image-error.js +0 -7
  208. package/dist/esm/execution/client-connection-state.js +0 -7
  209. package/dist/esm/execution/client-error.d.ts +0 -2
  210. package/dist/esm/execution/client-error.js +0 -2
  211. package/dist/esm/execution/client-interface.d.ts +0 -13
  212. package/dist/esm/execution/client.d.ts +0 -25
  213. package/dist/esm/execution/client.js +0 -112
  214. package/dist/esm/lib/askui-control-server.d.ts +0 -8
  215. package/dist/esm/lib/control-ui-server-args.d.ts +0 -21
  216. package/dist/esm/lib/control-ui-server-darwin.d.ts +0 -6
  217. package/dist/esm/lib/control-ui-server-facade.d.ts +0 -16
  218. package/dist/esm/lib/control-ui-server-linux.d.ts +0 -4
  219. package/dist/esm/lib/control-ui-server-linux.js +0 -9
  220. package/dist/esm/lib/control-ui-server-win32.d.ts +0 -3
  221. package/dist/esm/lib/control-ui-server-win32.js +0 -3
  222. package/dist/esm/utils/image-resize-errors/invalid-base64-image-error.d.ts +0 -3
  223. package/dist/esm/utils/image-resize-errors/invalid-base64-image-error.js +0 -3
@@ -0,0 +1,31 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import os from 'os';
11
+ import { UserIdentifier } from './user-identifier';
12
+ import { InstallationTimestamp } from './installation-timestamp';
13
+ export class Analytics {
14
+ constructor() {
15
+ this.userIdentifier = new UserIdentifier();
16
+ }
17
+ getAnalyticsHeaders() {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const userID = yield this.userIdentifier.userId();
20
+ const headers = {
21
+ 'askui-user-id': userID,
22
+ 'askui-user-agent': `os:${os.platform()};arch:${os.arch()}`,
23
+ };
24
+ const askuiInstalledAt = yield InstallationTimestamp.get();
25
+ if (askuiInstalledAt) {
26
+ headers['askui-installed-at'] = askuiInstalledAt.toISOString();
27
+ }
28
+ return headers;
29
+ });
30
+ }
31
+ }
@@ -0,0 +1 @@
1
+ export { Analytics } from './analytics';
@@ -0,0 +1 @@
1
+ export { Analytics } from './analytics';
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ export declare class InstallationTimestampCreateError extends Error {
3
+ constructor(err: NodeJS.ErrnoException);
4
+ }
@@ -0,0 +1,5 @@
1
+ export class InstallationTimestampCreateError extends Error {
2
+ constructor(err) {
3
+ super(`Installation timestamp could not be created. \n${err.message}`);
4
+ }
5
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ export declare class InstallationTimestampGetError extends Error {
3
+ constructor(err: NodeJS.ErrnoException);
4
+ }
@@ -0,0 +1,5 @@
1
+ export class InstallationTimestampGetError extends Error {
2
+ constructor(err) {
3
+ super(`Installation timestamp does not exist. Try reinstalling the lib to create it. \n${err.message}`);
4
+ }
5
+ }
@@ -0,0 +1,7 @@
1
+ export declare abstract class InstallationTimestamp {
2
+ private static fileName;
3
+ private static value?;
4
+ static create(): Promise<void>;
5
+ static get(): Promise<Date | null>;
6
+ private static getFromFile;
7
+ }
@@ -0,0 +1,61 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import fs from 'fs';
11
+ import path from 'path';
12
+ import { logger } from '../../lib';
13
+ import { InstallationTimestampCreateError } from './installation-timestamp-create-error';
14
+ import { InstallationTimestampGetError } from './installation-timestamp-get-error';
15
+ import { getPathToNodeModulesRoot } from '../path';
16
+ export class InstallationTimestamp {
17
+ static create() {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const timestamp = new Date().toISOString();
20
+ return new Promise((resolve, reject) => {
21
+ fs.writeFile(InstallationTimestamp.fileName, timestamp, { encoding: 'utf-8' }, (err) => {
22
+ if (err) {
23
+ reject(new InstallationTimestampCreateError(err));
24
+ }
25
+ else {
26
+ resolve();
27
+ }
28
+ });
29
+ });
30
+ });
31
+ }
32
+ static get() {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ if (InstallationTimestamp.value === undefined) {
35
+ try {
36
+ InstallationTimestamp.value = yield this.getFromFile();
37
+ }
38
+ catch (err) {
39
+ InstallationTimestamp.value = null;
40
+ logger.warn(err.message);
41
+ }
42
+ }
43
+ return InstallationTimestamp.value;
44
+ });
45
+ }
46
+ static getFromFile() {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return new Promise((resolve, reject) => {
49
+ fs.readFile(InstallationTimestamp.fileName, 'utf-8', (err, isoDateStr) => {
50
+ if (err) {
51
+ reject(new InstallationTimestampGetError(err));
52
+ }
53
+ else {
54
+ resolve(new Date(isoDateStr));
55
+ }
56
+ });
57
+ });
58
+ });
59
+ }
60
+ }
61
+ InstallationTimestamp.fileName = path.join(getPathToNodeModulesRoot(), 'install-timestamp');
@@ -0,0 +1,3 @@
1
+ export interface UserIdentifierInterface {
2
+ userId(): Promise<string>;
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 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';
@@ -0,0 +1 @@
1
+ export declare function getPathToNodeModulesRoot(): string;
@@ -0,0 +1,4 @@
1
+ import path from 'path';
2
+ export function getPathToNodeModulesRoot() {
3
+ return path.join(__dirname, '..', '..');
4
+ }
@@ -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,16 +1,20 @@
1
1
  {
2
2
  "name": "askui",
3
- "version": "0.1.6",
3
+ "version": "0.2.2",
4
4
  "main": "./dist/cjs/main.js",
5
5
  "module": "./dist/esm/main.js",
6
- "bin": "bin/askui",
6
+ "bin": {
7
+ "askui": "bin/askui",
8
+ "askui-postinstall": "bin/askui-postinstall"
9
+ },
7
10
  "scripts": {
8
11
  "build": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && npm run copyTemplate && npm run copyExampleProject",
9
12
  "copyTemplate": "shx cp -r src/core/annotation/template.html dist/cjs/core/annotation/ && shx cp -r src/core/annotation/template.html dist/esm/core/annotation/",
10
13
  "copyExampleProject": "shx cp -r example_projects_templates/ dist/ && shx cp -r bin/* dist/",
11
14
  "lint": "eslint --cache --fix --max-warnings 0 \"./**/*.{js,ts}\"",
12
15
  "lint:staged": "lint-staged",
13
- "test": "jest '/src'"
16
+ "test": "jest '/src'",
17
+ "postinstall": "node -e \"require('./bin/askui-postinstall')\""
14
18
  },
15
19
  "files": [
16
20
  "dist/cjs/",
@@ -23,10 +27,11 @@
23
27
  "fkill": "~7.2.1",
24
28
  "fs-extra": "~10.0.0",
25
29
  "got": "~11.8.2",
26
- "jimp": "~0.16.1",
27
30
  "jsdom": "~19.0.0",
31
+ "node-machine-id": "~1.1.12",
28
32
  "pino": "~7.8.1",
29
33
  "pino-pretty": "~7.5.3",
34
+ "sharp": "~0.30.6",
30
35
  "url-join": "~4.0.1",
31
36
  "wait-port": "~0.2.9",
32
37
  "ws": "~7.4.4",
@@ -37,15 +42,17 @@
37
42
  "@types/jest": "~27.4.0",
38
43
  "@types/jsdom": "~16.2.14",
39
44
  "@types/node": "~17.0.10",
45
+ "@types/sharp": "~0.30.4",
40
46
  "@types/url-join": "~4.0.1",
41
47
  "@types/webrtc": "~0.0.30",
42
48
  "@types/ws": "~7.4.4",
43
- "jest": "~27.4.7",
44
- "shx": "~0.3.4",
45
- "ts-jest": "~27.1.3",
49
+ "jest": "28.1.1",
50
+ "sharp": "^0.30.6",
51
+ "shx": "0.3.4",
52
+ "ts-jest": "28.0.4",
46
53
  "typescript": "~4.5.4"
47
54
  },
48
55
  "lint-staged": {
49
56
  "./**/*.{js,ts}": "eslint --cache --fix --max-warnings 0"
50
57
  }
51
- }
58
+ }
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClientConnectionState = void 0;
4
- var ClientConnectionState;
5
- (function (ClientConnectionState) {
6
- ClientConnectionState[ClientConnectionState["NOT_CONNECTED"] = 0] = "NOT_CONNECTED";
7
- ClientConnectionState[ClientConnectionState["CONNECTING"] = 1] = "CONNECTING";
8
- ClientConnectionState[ClientConnectionState["CONNECTED"] = 2] = "CONNECTED";
9
- ClientConnectionState[ClientConnectionState["ERROR"] = 3] = "ERROR";
10
- })(ClientConnectionState = exports.ClientConnectionState || (exports.ClientConnectionState = {}));
@@ -1,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
- }