@allwright.dev/core 0.1.35 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bootstrap.js CHANGED
@@ -12,7 +12,7 @@ const ALLWRIGHT_HOME_ENV_VAR = "ALLWRIGHT_HOME";
12
12
  const ALLWRIGHT_REPOSITORY_ENV_VAR = "ALLWRIGHT_REPOSITORY";
13
13
  const ALLWRIGHT_VERSION_ENV_VAR = "ALLWRIGHT_VERSION";
14
14
  const DEFAULT_RELEASE_REPOSITORY = "allwright-dev/allwright";
15
- const DEFAULT_RELEASE_VERSION = "0.1.35";
15
+ const DEFAULT_RELEASE_VERSION = "0.2.1";
16
16
  const STARTUP_TIMEOUT_MS = 20_000;
17
17
  const PING_TIMEOUT_MS = 1_000;
18
18
  const PROTO_ROOT = fileURLToPath(new URL("../proto/", import.meta.url));
package/dist/desktop.d.ts CHANGED
@@ -1,2 +1,17 @@
1
- import type { DesktopSurfaceNamespace } from "./types.js";
1
+ import { NativeAppImpl } from "./mobile.js";
2
+ import type { DesktopApp, DesktopSurfaceNamespace, Hook, HookType, RuntimeClient } from "./types.js";
3
+ export declare class DesktopWindowImpl extends NativeAppImpl {
4
+ readonly windowId: string;
5
+ readonly title: string;
6
+ readonly isMain: boolean;
7
+ constructor(runtime: RuntimeClient, surfaceSessionId: string, sessionId: string, windowId: string, title: string, isMain: boolean);
8
+ close(): Promise<void>;
9
+ }
10
+ export declare class DesktopAppImpl extends NativeAppImpl implements DesktopApp {
11
+ windows(): Promise<DesktopWindowImpl[]>;
12
+ mainWindow(): Promise<DesktopWindowImpl>;
13
+ registerHook<T>(type: HookType<T>): Promise<Hook<T>>;
14
+ private waitForWindow;
15
+ private windowFromResult;
16
+ }
2
17
  export declare const desktop: DesktopSurfaceNamespace;
package/dist/desktop.js CHANGED
@@ -3,6 +3,109 @@ import { NativeAppImpl } from "./mobile.js";
3
3
  function retryOptions(timeoutMs) {
4
4
  return timeoutMs === undefined ? undefined : { timeoutMs };
5
5
  }
6
+ export class DesktopWindowImpl extends NativeAppImpl {
7
+ windowId;
8
+ title;
9
+ isMain;
10
+ constructor(runtime, surfaceSessionId, sessionId, windowId, title, isMain) {
11
+ super(runtime, surfaceSessionId, sessionId);
12
+ this.windowId = windowId;
13
+ this.title = title;
14
+ this.isMain = isMain;
15
+ }
16
+ async close() {
17
+ const handle = await this.contextHandle();
18
+ this.assertContextOpen(handle);
19
+ handle.stream.write({
20
+ surfaceSessionId: this.nativeSurfaceSessionId,
21
+ contextSessionId: this.sessionId,
22
+ closeDesktopWindow: {},
23
+ });
24
+ while (true) {
25
+ const event = await handle.queue.next();
26
+ if (event.desktopWindowClosed?.windowId === this.windowId)
27
+ return;
28
+ if (event.error?.message)
29
+ throw new Error(event.error.message);
30
+ }
31
+ }
32
+ }
33
+ export class DesktopAppImpl extends NativeAppImpl {
34
+ async windows() {
35
+ const handle = await this.contextHandle();
36
+ this.assertContextOpen(handle);
37
+ handle.stream.write({
38
+ surfaceSessionId: this.nativeSurfaceSessionId,
39
+ contextSessionId: this.sessionId,
40
+ listDesktopWindows: {},
41
+ });
42
+ while (true) {
43
+ const event = await handle.queue.next();
44
+ if (event.desktopWindowsResolved) {
45
+ return (event.desktopWindowsResolved.windows ?? []).map((window) => this.windowFromResult(window));
46
+ }
47
+ if (event.error?.message)
48
+ throw new Error(event.error.message);
49
+ }
50
+ }
51
+ async mainWindow() {
52
+ const windows = await this.windows();
53
+ const main = windows.find((window) => window.isMain);
54
+ if (!main)
55
+ throw new Error("desktop application does not currently expose a main window");
56
+ return main;
57
+ }
58
+ async registerHook(type) {
59
+ if (type.name !== "window")
60
+ return super.registerHook(type);
61
+ const handle = await this.contextHandle();
62
+ this.assertContextOpen(handle);
63
+ handle.stream.write({
64
+ surfaceSessionId: this.nativeSurfaceSessionId,
65
+ contextSessionId: this.sessionId,
66
+ registerHook: { desktopWindow: {} },
67
+ });
68
+ while (true) {
69
+ const event = await handle.queue.next();
70
+ if (event.hookRegistered?.hookId) {
71
+ const hookId = event.hookRegistered.hookId;
72
+ return {
73
+ id: hookId,
74
+ type,
75
+ wait: (options = {}) => this.waitForWindow(hookId, options),
76
+ };
77
+ }
78
+ if (event.error?.message)
79
+ throw new Error(event.error.message);
80
+ }
81
+ }
82
+ async waitForWindow(hookId, options) {
83
+ const handle = await this.contextHandle();
84
+ this.assertContextOpen(handle);
85
+ handle.stream.write({
86
+ surfaceSessionId: this.nativeSurfaceSessionId,
87
+ contextSessionId: this.sessionId,
88
+ waitForHook: { hookId, retryOptions: retryOptions(options.timeoutMs) },
89
+ });
90
+ while (true) {
91
+ const event = await handle.queue.next();
92
+ if (event.hookCompleted?.hookId === hookId) {
93
+ const window = event.hookCompleted.desktopWindow?.window;
94
+ if (!window)
95
+ throw new Error("desktop window hook returned an invalid result");
96
+ return this.windowFromResult(window);
97
+ }
98
+ if (event.error?.message)
99
+ throw new Error(event.error.message);
100
+ }
101
+ }
102
+ windowFromResult(window) {
103
+ if (!window.contextSessionId || !window.windowId) {
104
+ throw new Error("desktop window result is missing its context or window id");
105
+ }
106
+ return new DesktopWindowImpl(this.runtimeClient, this.nativeSurfaceSessionId, window.contextSessionId, window.windowId, window.title ?? "", window.isMain ?? false);
107
+ }
108
+ }
6
109
  class DesktopMacImpl {
7
110
  sessionId;
8
111
  surfaceSessionId;
@@ -19,7 +122,7 @@ class DesktopMacImpl {
19
122
  this.stream = stream;
20
123
  this.queue = queue;
21
124
  this.platformLabel = platformLabel;
22
- this.#currentApp = new NativeAppImpl(runtime, surfaceSessionId, initialAppSessionId);
125
+ this.#currentApp = new DesktopAppImpl(runtime, surfaceSessionId, initialAppSessionId);
23
126
  }
24
127
  app() {
25
128
  return this.#currentApp;
@@ -37,7 +140,7 @@ class DesktopMacImpl {
37
140
  while (true) {
38
141
  const event = await this.queue.next();
39
142
  if (event.desktopAppLaunched?.appSessionId) {
40
- this.#currentApp = new NativeAppImpl(this.runtime, this.surfaceSessionId, event.desktopAppLaunched.appSessionId);
143
+ this.#currentApp = new DesktopAppImpl(this.runtime, this.surfaceSessionId, event.desktopAppLaunched.appSessionId);
41
144
  return this.#currentApp;
42
145
  }
43
146
  if (event.error?.message)
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import { PageImpl } from "./page.js";
6
6
  import { setServerAddr, shutdown } from "./runtime.js";
7
7
  import type { Browser, BrowserKind, BrowserType, LaunchOptions, Page, Dialog, FileChooser, Download, HookType, ResolveConfigOptions, ResolvedAllwrightConfig } from "./types.js";
8
8
  export { findConfigFile, loadConfigFile, resolveConfig, setServerAddr, shutdown };
9
- export type { CapturedOption, BoundingBox, AccessibilitySnapshotOptions, AllwrightConfig, Browser, BrowserInfo, BrowserKind, BrowserType, Hook, HookType, Dialog, FileChooser, Download, ClickResult, CommandOptions, CountResult, ElementResult, FillResult, HighlightOptions, HighlightResult, LaunchOptions, NativeApp, NativeAppLocator, MobileAndroidConnectOptions, MobileAndroidDevice, MobileAndroidLaunchOptions, MobileAndroidLocator, MobileAndroidApp, MobileIosConnectOptions, MobileIosDevice, MobileIosLaunchOptions, MobileIosLocator, MobileIosApp, Locator, LocatorInfo, MobileSurfaceNamespace, DesktopMacApp, DesktopMacConnectOptions, DesktopMacDesktop, DesktopMacLaunchOptions, DesktopMacLocator, DesktopWindowsApp, DesktopWindowsConnectOptions, DesktopWindowsDesktop, DesktopWindowsLaunchOptions, DesktopWindowsLocator, DesktopSurfaceNamespace, NavigateResult, Page, PageInfo, PressOptions, PressResult, ResolveConfigOptions, ResolvedAllwrightConfig, RetryConfig, ScreenshotOptions, ScreenshotResult, TextResult, WaitForSelectorOptions, WaitForSelectorResult, } from "./types.js";
9
+ export type { CapturedOption, BoundingBox, AccessibilitySnapshotOptions, AllwrightConfig, Browser, BrowserInfo, BrowserKind, BrowserType, Hook, HookType, Dialog, FileChooser, Download, ClickResult, CommandOptions, CountResult, ElementResult, FillResult, HighlightOptions, HighlightResult, LaunchOptions, NativeApp, DesktopApp, DesktopWindow, NativeAppLocator, MobileAndroidConnectOptions, MobileAndroidDevice, MobileAndroidLaunchOptions, MobileAndroidLocator, MobileAndroidApp, MobileIosConnectOptions, MobileIosDevice, MobileIosLaunchOptions, MobileIosLocator, MobileIosApp, Locator, LocatorInfo, MobileSurfaceNamespace, DesktopMacApp, DesktopMacWindow, DesktopMacConnectOptions, DesktopMacDesktop, DesktopMacLaunchOptions, DesktopMacLocator, DesktopWindowsApp, DesktopWindowsWindow, DesktopWindowsConnectOptions, DesktopWindowsDesktop, DesktopWindowsLaunchOptions, DesktopWindowsLocator, DesktopSurfaceNamespace, NavigateResult, Page, PageInfo, PressOptions, PressResult, ResolveConfigOptions, ResolvedAllwrightConfig, RetryConfig, ScreenshotOptions, ScreenshotResult, TextResult, WaitForSelectorOptions, WaitForSelectorResult, } from "./types.js";
10
10
  export declare const chromium: BrowserType;
11
11
  export declare const firefox: BrowserType;
12
12
  export declare const hooks: {
@@ -14,6 +14,7 @@ export declare const hooks: {
14
14
  newPage: HookType<Page>;
15
15
  fileChooser: HookType<FileChooser>;
16
16
  download: HookType<Download>;
17
+ window: HookType<import("./types.js").DesktopWindow>;
17
18
  };
18
19
  export { mobile };
19
20
  export { desktop };
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@ export const hooks = {
13
13
  newPage: Object.freeze({ name: "newPage" }),
14
14
  fileChooser: Object.freeze({ name: "fileChooser" }),
15
15
  download: Object.freeze({ name: "download" }),
16
+ window: Object.freeze({ name: "window" }),
16
17
  };
17
18
  export { mobile };
18
19
  export { desktop };
package/dist/mobile.d.ts CHANGED
@@ -1,9 +1,13 @@
1
1
  import { type RoleOptions, type TextMatcher, type TextOptions } from "./web-locators.js";
2
- import type { AccessibilitySnapshotOptions, BoundingBox, CommandOptions, Hook, HookType, MobileSurfaceNamespace, NativeApp, NativeAppLocator, PressOptions, RuntimeClient, ScreenshotOptions, WaitForSelectorOptions } from "./types.js";
2
+ import type { AccessibilitySnapshotOptions, BoundingBox, CommandOptions, Hook, HookType, MobileSurfaceNamespace, NativeApp, NativeAppLocator, PageHandle, PressOptions, RuntimeClient, ScreenshotOptions, WaitForSelectorOptions } from "./types.js";
3
3
  export declare class NativeAppImpl implements NativeApp {
4
4
  #private;
5
5
  readonly sessionId: string;
6
6
  constructor(runtime: RuntimeClient, surfaceSessionId: string, sessionId: string);
7
+ protected get runtimeClient(): RuntimeClient;
8
+ protected get nativeSurfaceSessionId(): string;
9
+ protected contextHandle(): Promise<PageHandle>;
10
+ protected assertContextOpen(handle: PageHandle): void;
7
11
  locator(selector: string): NativeAppLocator;
8
12
  getByRole(role: string, options?: RoleOptions): NativeAppLocator;
9
13
  getByText(text: TextMatcher, options?: TextOptions): NativeAppLocator;
package/dist/mobile.js CHANGED
@@ -17,6 +17,10 @@ export class NativeAppImpl {
17
17
  this.#runtime = runtime;
18
18
  this.#surfaceSessionId = surfaceSessionId;
19
19
  }
20
+ get runtimeClient() { return this.#runtime; }
21
+ get nativeSurfaceSessionId() { return this.#surfaceSessionId; }
22
+ contextHandle() { return this.#getHandle(); }
23
+ assertContextOpen(handle) { this.#ensureOpen(handle); }
20
24
  locator(selector) {
21
25
  return new NativeAppLocatorImpl(this, normalizeMobileSelectorForTransport(selector));
22
26
  }
package/dist/types.d.ts CHANGED
@@ -235,6 +235,16 @@ export interface NativeApp {
235
235
  screenshot(options?: ScreenshotOptions): Promise<Uint8Array>;
236
236
  registerHook<T>(type: HookType<T>): Promise<Hook<T>>;
237
237
  }
238
+ export interface DesktopWindow extends NativeApp {
239
+ readonly windowId: string;
240
+ readonly title: string;
241
+ readonly isMain: boolean;
242
+ close(): Promise<void>;
243
+ }
244
+ export interface DesktopApp extends NativeApp {
245
+ windows(): Promise<DesktopWindow[]>;
246
+ mainWindow(): Promise<DesktopWindow>;
247
+ }
238
248
  export type MobileAndroidLocator = NativeAppLocator;
239
249
  export type MobileAndroidApp = NativeApp;
240
250
  export interface MobileAndroidDevice {
@@ -280,7 +290,8 @@ export interface DesktopMacLaunchOptions {
280
290
  terminateRunning?: boolean;
281
291
  timeoutMs?: number;
282
292
  }
283
- export type DesktopMacApp = NativeApp;
293
+ export type DesktopMacApp = DesktopApp;
294
+ export type DesktopMacWindow = DesktopWindow;
284
295
  export type DesktopMacLocator = NativeAppLocator;
285
296
  export interface DesktopMacDesktop {
286
297
  readonly sessionId: string;
@@ -289,7 +300,8 @@ export interface DesktopMacDesktop {
289
300
  }
290
301
  export type DesktopWindowsConnectOptions = DesktopMacConnectOptions;
291
302
  export type DesktopWindowsLaunchOptions = DesktopMacLaunchOptions;
292
- export type DesktopWindowsApp = NativeApp;
303
+ export type DesktopWindowsApp = DesktopApp;
304
+ export type DesktopWindowsWindow = DesktopWindow;
293
305
  export type DesktopWindowsLocator = NativeAppLocator;
294
306
  export interface DesktopWindowsDesktop {
295
307
  readonly sessionId: string;
@@ -556,6 +568,25 @@ export interface ContextSessionEvent {
556
568
  suggestedFilename?: string;
557
569
  note?: string;
558
570
  };
571
+ desktopWindow?: {
572
+ window?: {
573
+ contextSessionId?: string;
574
+ windowId?: string;
575
+ title?: string;
576
+ isMain?: boolean;
577
+ };
578
+ };
579
+ };
580
+ desktopWindowsResolved?: {
581
+ windows?: Array<{
582
+ contextSessionId?: string;
583
+ windowId?: string;
584
+ title?: string;
585
+ isMain?: boolean;
586
+ }>;
587
+ };
588
+ desktopWindowClosed?: {
589
+ windowId?: string;
559
590
  };
560
591
  fileChooserFilesSet?: {
561
592
  fileChooserId?: string;
@@ -703,6 +734,7 @@ export interface RegisterHookRequest {
703
734
  download?: Record<string, never>;
704
735
  mobileFileChooser?: Record<string, never>;
705
736
  mobileDownload?: Record<string, never>;
737
+ desktopWindow?: Record<string, never>;
706
738
  };
707
739
  }
708
740
  export interface SaveDownloadRequest {
@@ -975,6 +1007,16 @@ export interface CloseContextRequest {
975
1007
  contextSessionId: string;
976
1008
  close: Record<string, never>;
977
1009
  }
1010
+ export interface ListDesktopWindowsRequest {
1011
+ surfaceSessionId: string;
1012
+ contextSessionId: string;
1013
+ listDesktopWindows: Record<string, never>;
1014
+ }
1015
+ export interface CloseDesktopWindowRequest {
1016
+ surfaceSessionId: string;
1017
+ contextSessionId: string;
1018
+ closeDesktopWindow: Record<string, never>;
1019
+ }
978
1020
  export type SurfaceSessionRequest = LaunchBrowserRequest | LaunchChromeRequest | OpenContextRequest | ConnectMobileRequest | LaunchAppRequest | ConnectDesktopRequest | LaunchDesktopAppRequest | SurfacePingRequest | CloseSurfaceRequest;
979
1021
  export type ContextSessionRequest = {
980
1022
  surfaceSessionId: string;
@@ -996,7 +1038,7 @@ export type ContextSessionRequest = {
996
1038
  timeoutMs: number;
997
1039
  };
998
1040
  };
999
- } | ContextPingRequest | RegisterHookRequest | WaitForHookRequest | HandleDialogRequest | SetFileChooserFilesRequest | SaveDownloadRequest | UploadFileChunkRequest | ReadFileChunkRequest | SetMobileFileChooserFilesRequest | SaveMobileDownloadRequest | NavigateRequest | ClickRequest | CountRequest | HighlightRequest | FocusRequest | FillRequest | HoverRequest | PressRequest | TextContentRequest | InnerTextRequest | WaitForSelectorRequest | AccessibilitySnapshotRequest | ScreenshotRequest | CloseContextRequest;
1041
+ } | ContextPingRequest | RegisterHookRequest | WaitForHookRequest | HandleDialogRequest | SetFileChooserFilesRequest | SaveDownloadRequest | UploadFileChunkRequest | ReadFileChunkRequest | SetMobileFileChooserFilesRequest | SaveMobileDownloadRequest | NavigateRequest | ClickRequest | CountRequest | HighlightRequest | FocusRequest | FillRequest | HoverRequest | PressRequest | TextContentRequest | InnerTextRequest | WaitForSelectorRequest | AccessibilitySnapshotRequest | ScreenshotRequest | ListDesktopWindowsRequest | CloseDesktopWindowRequest | CloseContextRequest;
1000
1042
  export type SurfaceSessionStream = grpc.ClientDuplexStream<SurfaceSessionRequest, SurfaceSessionEvent>;
1001
1043
  export type ContextSessionStream = grpc.ClientDuplexStream<ContextSessionRequest, ContextSessionEvent>;
1002
1044
  export interface EngineServiceClientShape {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allwright.dev/core",
3
- "version": "0.1.35",
3
+ "version": "0.2.1",
4
4
  "description": "High-level TypeScript client for the allwright automation engine.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -6,6 +6,7 @@ option java_package = "dev.allwright.engine.v1";
6
6
  option java_multiple_files = true;
7
7
 
8
8
  import "core/v1/common.proto";
9
+ import "surfaces/desktop/v1/desktop.proto";
9
10
  import "surfaces/mobile/v1/mobile.proto";
10
11
  import "surfaces/web/v1/web.proto";
11
12
 
@@ -40,6 +41,8 @@ message ContextSessionCommand {
40
41
  ResolveFrameCommand resolve_frame = 26;
41
42
  CaptureCommand capture = 27;
42
43
  HandleDialogCommand handle_dialog = 28;
44
+ ListDesktopWindowsCommand list_desktop_windows = 29;
45
+ CloseDesktopWindowCommand close_desktop_window = 30;
43
46
  }
44
47
  }
45
48
 
@@ -82,6 +85,8 @@ message ContextSessionEvent {
82
85
  FrameResolvedEvent frame_resolved = 28;
83
86
  CaptureResolvedEvent capture_resolved = 29;
84
87
  DialogHandledEvent dialog_handled = 30;
88
+ DesktopWindowsResolvedEvent desktop_windows_resolved = 31;
89
+ DesktopWindowClosedEvent desktop_window_closed = 32;
85
90
  }
86
91
  }
87
92
 
@@ -109,6 +114,7 @@ message RegisterHookCommand {
109
114
  RegisterMobileFileChooserHook mobile_file_chooser = 4;
110
115
  RegisterMobileDownloadHook mobile_download = 5;
111
116
  RegisterDialogHook dialog = 6;
117
+ RegisterDesktopWindowHook desktop_window = 7;
112
118
  }
113
119
  }
114
120
 
@@ -131,6 +137,7 @@ message HookCompletedEvent {
131
137
  MobileFileChooserHookResult mobile_file_chooser = 5;
132
138
  MobileDownloadHookResult mobile_download = 6;
133
139
  DialogHookResult dialog = 7;
140
+ DesktopWindowHookResult desktop_window = 8;
134
141
  }
135
142
  }
136
143
 
@@ -38,3 +38,26 @@ message DesktopAppLaunchedEvent {
38
38
  string app_id = 2;
39
39
  string note = 3;
40
40
  }
41
+
42
+ message ListDesktopWindowsCommand {}
43
+ message CloseDesktopWindowCommand {}
44
+ message RegisterDesktopWindowHook {}
45
+
46
+ message DesktopWindowInfo {
47
+ string context_session_id = 1;
48
+ string window_id = 2;
49
+ string title = 3;
50
+ bool is_main = 4;
51
+ }
52
+
53
+ message DesktopWindowsResolvedEvent {
54
+ repeated DesktopWindowInfo windows = 1;
55
+ }
56
+
57
+ message DesktopWindowClosedEvent {
58
+ string window_id = 1;
59
+ }
60
+
61
+ message DesktopWindowHookResult {
62
+ DesktopWindowInfo window = 1;
63
+ }