@allwright.dev/core 0.1.14 → 0.1.16

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.14";
15
+ const DEFAULT_RELEASE_VERSION = "0.1.16";
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/index.d.ts CHANGED
@@ -3,12 +3,13 @@ import { findConfigFile, loadConfigFile, resolveConfig } from "./config.js";
3
3
  import { mobile } from "./mobile.js";
4
4
  import { PageImpl } from "./page.js";
5
5
  import { setServerAddr, shutdown } from "./runtime.js";
6
- import type { Browser, BrowserKind, BrowserType, LaunchOptions, Page, FileChooser, Download, HookType, ResolveConfigOptions, ResolvedAllwrightConfig } from "./types.js";
6
+ import type { Browser, BrowserKind, BrowserType, LaunchOptions, Page, Dialog, FileChooser, Download, HookType, ResolveConfigOptions, ResolvedAllwrightConfig } from "./types.js";
7
7
  export { findConfigFile, loadConfigFile, resolveConfig, setServerAddr, shutdown };
8
- export type { CapturedOption, BoundingBox, AccessibilitySnapshotOptions, AllwrightConfig, Browser, BrowserInfo, BrowserKind, BrowserType, Hook, HookType, FileChooser, Download, ClickResult, CommandOptions, CountResult, ElementResult, FillResult, HighlightOptions, HighlightResult, LaunchOptions, MobileAndroidConnectOptions, MobileAndroidDevice, MobileAndroidLaunchOptions, MobileAndroidLocator, MobileAndroidApp, Locator, LocatorInfo, MobileSurfaceNamespace, NavigateResult, Page, PageInfo, PressOptions, PressResult, ResolveConfigOptions, ResolvedAllwrightConfig, RetryConfig, ScreenshotOptions, ScreenshotResult, TextResult, WaitForSelectorOptions, WaitForSelectorResult, } from "./types.js";
8
+ export type { CapturedOption, BoundingBox, AccessibilitySnapshotOptions, AllwrightConfig, Browser, BrowserInfo, BrowserKind, BrowserType, Hook, HookType, Dialog, FileChooser, Download, ClickResult, CommandOptions, CountResult, ElementResult, FillResult, HighlightOptions, HighlightResult, LaunchOptions, MobileAndroidConnectOptions, MobileAndroidDevice, MobileAndroidLaunchOptions, MobileAndroidLocator, MobileAndroidApp, MobileIosConnectOptions, MobileIosDevice, MobileIosLaunchOptions, MobileIosLocator, MobileIosApp, Locator, LocatorInfo, MobileSurfaceNamespace, NavigateResult, Page, PageInfo, PressOptions, PressResult, ResolveConfigOptions, ResolvedAllwrightConfig, RetryConfig, ScreenshotOptions, ScreenshotResult, TextResult, WaitForSelectorOptions, WaitForSelectorResult, } from "./types.js";
9
9
  export declare const chromium: BrowserType;
10
10
  export declare const firefox: BrowserType;
11
11
  export declare const hooks: {
12
+ dialog: HookType<Dialog>;
12
13
  newPage: HookType<Page>;
13
14
  fileChooser: HookType<FileChooser>;
14
15
  download: HookType<Download>;
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ export { findConfigFile, loadConfigFile, resolveConfig, setServerAddr, shutdown
8
8
  export const chromium = new BrowserTypeImpl("chromium");
9
9
  export const firefox = new BrowserTypeImpl("firefox");
10
10
  export const hooks = {
11
+ dialog: Object.freeze({ name: "dialog" }),
11
12
  newPage: Object.freeze({ name: "newPage" }),
12
13
  fileChooser: Object.freeze({ name: "fileChooser" }),
13
14
  download: Object.freeze({ name: "download" }),
package/dist/mobile.js CHANGED
@@ -605,6 +605,50 @@ class MobileAndroidDeviceImpl {
605
605
  }
606
606
  }
607
607
  }
608
+ class MobileIosDeviceImpl {
609
+ sessionId;
610
+ surfaceSessionId;
611
+ runtime;
612
+ #stream;
613
+ #queue;
614
+ #closed = false;
615
+ #currentApp;
616
+ constructor(sessionId, surfaceSessionId, runtime, stream, queue, initialAppSessionId) {
617
+ this.sessionId = sessionId;
618
+ this.surfaceSessionId = surfaceSessionId;
619
+ this.runtime = runtime;
620
+ this.#stream = stream;
621
+ this.#queue = queue;
622
+ this.#currentApp = new MobileAndroidAppImpl(runtime, surfaceSessionId, initialAppSessionId);
623
+ }
624
+ app() { return this.#currentApp; }
625
+ initialApp() { return this.#currentApp; }
626
+ async launch(options = {}) {
627
+ if (this.#closed)
628
+ throw new Error(`ios device session ${this.sessionId} is closed`);
629
+ this.#stream.write({
630
+ launchApp: {
631
+ apkPath: options.appPath,
632
+ appId: options.appId,
633
+ stopBeforeLaunch: options.stopBeforeLaunch ?? false,
634
+ retryOptions: retryOptions(options.timeoutMs),
635
+ },
636
+ });
637
+ while (true) {
638
+ const event = await this.#queue.next();
639
+ if (event.appLaunched?.appSessionId) {
640
+ this.#currentApp = new MobileAndroidAppImpl(this.runtime, this.surfaceSessionId, event.appLaunched.appSessionId);
641
+ return this.#currentApp;
642
+ }
643
+ if (event.error?.message)
644
+ throw new Error(event.error.message);
645
+ if (event.closed) {
646
+ this.#closed = true;
647
+ throw new Error(`ios device session ${this.sessionId} closed while launching app`);
648
+ }
649
+ }
650
+ }
651
+ }
608
652
  class MobileAndroidSurfaceImpl {
609
653
  async connect(options = {}) {
610
654
  const runtime = await getRuntime();
@@ -629,6 +673,32 @@ class MobileAndroidSurfaceImpl {
629
673
  }
630
674
  }
631
675
  }
676
+ class MobileIosSurfaceImpl {
677
+ async connect(options = {}) {
678
+ const runtime = await getRuntime();
679
+ const { stream, queue } = await createBrowserSessionHandle(runtime);
680
+ stream.write({
681
+ connectMobile: {
682
+ platform: 2,
683
+ device: options.device,
684
+ // The protobuf slot is transport-internal and shared with the older
685
+ // Android endpoint field; the public iOS API names it accurately.
686
+ adbEndpoint: options.agentEndpoint,
687
+ preserveAppState: options.preserveAppState ?? false,
688
+ retryOptions: retryOptions(options.timeoutMs),
689
+ },
690
+ });
691
+ while (true) {
692
+ const event = await queue.next();
693
+ if (event.mobileConnected?.initialAppSessionId) {
694
+ return new MobileIosDeviceImpl(event.mobileConnected.deviceSessionId ?? event.sessionId ?? "", event.sessionId ?? "", runtime, stream, queue, event.mobileConnected.initialAppSessionId);
695
+ }
696
+ if (event.error?.message)
697
+ throw new Error(event.error.message);
698
+ }
699
+ }
700
+ }
632
701
  export const mobile = {
633
702
  android: new MobileAndroidSurfaceImpl(),
703
+ ios: new MobileIosSurfaceImpl(),
634
704
  };
package/dist/page.js CHANGED
@@ -42,7 +42,7 @@ export class PageImpl extends WebLocatorBuilders {
42
42
  }
43
43
  }
44
44
  async registerHook(type) {
45
- if (type.name !== "newPage" && type.name !== "fileChooser" && type.name !== "download") {
45
+ if (type.name !== "dialog" && type.name !== "newPage" && type.name !== "fileChooser" && type.name !== "download") {
46
46
  throw formatActionError("register hook", `unsupported hook type: ${type.name}`);
47
47
  }
48
48
  const handle = await this.#getHandle();
@@ -50,11 +50,8 @@ export class PageImpl extends WebLocatorBuilders {
50
50
  handle.stream.write({
51
51
  surfaceSessionId: this.browserSessionId,
52
52
  contextSessionId: this.sessionId,
53
- registerHook: type.name === "newPage"
54
- ? { newPage: {} }
55
- : type.name === "fileChooser"
56
- ? { fileChooser: {} }
57
- : { download: {} },
53
+ registerHook: type.name === "dialog" ? { dialog: {} } : type.name === "newPage"
54
+ ? { newPage: {} } : type.name === "fileChooser" ? { fileChooser: {} } : { download: {} },
58
55
  });
59
56
  while (true) {
60
57
  const event = await handle.queue.next();
@@ -79,12 +76,21 @@ export class PageImpl extends WebLocatorBuilders {
79
76
  contextSessionId: this.sessionId,
80
77
  waitForHook: {
81
78
  hookId,
82
- retryOptions: options.timeoutMs ? { timeoutMs: options.timeoutMs } : undefined,
79
+ retryOptions: options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : undefined,
83
80
  },
84
81
  });
85
82
  while (true) {
86
83
  const event = await handle.queue.next();
87
84
  if (event.hookCompleted?.hookId === hookId) {
85
+ if (type.name === "dialog" && event.hookCompleted.dialog?.dialogId) {
86
+ const result = event.hookCompleted.dialog;
87
+ const id = result.dialogId;
88
+ return {
89
+ id, page: this, type: result.type ?? "", message: result.message ?? "", defaultValue: result.defaultValue ?? "",
90
+ accept: (promptText, options = {}) => this.#handleDialog(id, true, promptText, options),
91
+ dismiss: (options = {}) => this.#handleDialog(id, false, undefined, options),
92
+ };
93
+ }
88
94
  if (type.name === "newPage" && event.hookCompleted.newPage?.contextSessionId) {
89
95
  return this.#createPage(event.hookCompleted.newPage.contextSessionId);
90
96
  }
@@ -101,6 +107,25 @@ export class PageImpl extends WebLocatorBuilders {
101
107
  }
102
108
  }
103
109
  }
110
+ async #handleDialog(dialogId, accept, promptText, options) {
111
+ const handle = await this.#getHandle();
112
+ this.#ensureOpen(handle);
113
+ handle.stream.write({ surfaceSessionId: this.browserSessionId, contextSessionId: this.sessionId,
114
+ handleDialog: { dialogId, accept, promptText,
115
+ ...(options.timeoutMs !== undefined ? { retryOptions: { timeoutMs: options.timeoutMs } } : {}),
116
+ } });
117
+ while (true) {
118
+ const event = await handle.queue.next();
119
+ if (event.dialogHandled?.dialogId === dialogId)
120
+ return;
121
+ if (event.error?.message)
122
+ throw formatActionError("handle dialog", event.error.message);
123
+ if (event.closed) {
124
+ handle.closed = true;
125
+ throw new Error("page closed while handling dialog");
126
+ }
127
+ }
128
+ }
104
129
  async setFileChooserFiles(fileChooserId, files, options = {}) {
105
130
  const handle = await this.#getHandle();
106
131
  this.#ensureOpen(handle);
package/dist/types.d.ts CHANGED
@@ -108,6 +108,15 @@ export interface Hook<T> {
108
108
  readonly type: HookType<T>;
109
109
  wait(options?: CommandOptions): Promise<T>;
110
110
  }
111
+ export interface Dialog {
112
+ readonly id: string;
113
+ readonly page: Page;
114
+ readonly type: string;
115
+ readonly message: string;
116
+ readonly defaultValue: string;
117
+ accept(promptText?: string, options?: CommandOptions): Promise<void>;
118
+ dismiss(options?: CommandOptions): Promise<void>;
119
+ }
111
120
  export interface FileChooser {
112
121
  readonly id: string;
113
122
  readonly page: Page | MobileAndroidApp;
@@ -208,10 +217,33 @@ export interface MobileAndroidDevice {
208
217
  initialApp(): MobileAndroidApp;
209
218
  launch(options?: MobileAndroidLaunchOptions): Promise<MobileAndroidApp>;
210
219
  }
220
+ export interface MobileIosConnectOptions {
221
+ device?: string;
222
+ agentEndpoint?: string;
223
+ preserveAppState?: boolean;
224
+ timeoutMs?: number;
225
+ }
226
+ export interface MobileIosLaunchOptions {
227
+ appPath?: string;
228
+ appId?: string;
229
+ stopBeforeLaunch?: boolean;
230
+ timeoutMs?: number;
231
+ }
232
+ export type MobileIosLocator = MobileAndroidLocator;
233
+ export type MobileIosApp = MobileAndroidApp;
234
+ export interface MobileIosDevice {
235
+ readonly sessionId: string;
236
+ app(): MobileIosApp;
237
+ initialApp(): MobileIosApp;
238
+ launch(options?: MobileIosLaunchOptions): Promise<MobileIosApp>;
239
+ }
211
240
  export interface MobileSurfaceNamespace {
212
241
  android: {
213
242
  connect(options?: MobileAndroidConnectOptions): Promise<MobileAndroidDevice>;
214
243
  };
244
+ ios: {
245
+ connect(options?: MobileIosConnectOptions): Promise<MobileIosDevice>;
246
+ };
215
247
  }
216
248
  export interface Locator extends WebLocators {
217
249
  inputValue(options?: CommandOptions): Promise<string>;
@@ -415,8 +447,17 @@ export interface ContextSessionEvent {
415
447
  hookRegistered?: {
416
448
  hookId?: string;
417
449
  };
450
+ dialogHandled?: {
451
+ dialogId?: string;
452
+ };
418
453
  hookCompleted?: {
419
454
  hookId?: string;
455
+ dialog?: {
456
+ dialogId?: string;
457
+ type?: string;
458
+ message?: string;
459
+ defaultValue?: string;
460
+ };
420
461
  newPage?: {
421
462
  contextSessionId?: string;
422
463
  note?: string;
@@ -567,10 +608,23 @@ export interface OpenContextRequest {
567
608
  };
568
609
  };
569
610
  }
611
+ export interface HandleDialogRequest {
612
+ surfaceSessionId: string;
613
+ contextSessionId: string;
614
+ handleDialog: {
615
+ dialogId: string;
616
+ accept: boolean;
617
+ promptText?: string;
618
+ retryOptions?: {
619
+ timeoutMs?: number;
620
+ };
621
+ };
622
+ }
570
623
  export interface RegisterHookRequest {
571
624
  surfaceSessionId: string;
572
625
  contextSessionId: string;
573
626
  registerHook: {
627
+ dialog?: Record<string, never>;
574
628
  newPage?: Record<string, never>;
575
629
  fileChooser?: Record<string, never>;
576
630
  download?: Record<string, never>;
@@ -849,7 +903,7 @@ export type ContextSessionRequest = {
849
903
  timeoutMs: number;
850
904
  };
851
905
  };
852
- } | ContextPingRequest | RegisterHookRequest | WaitForHookRequest | SetFileChooserFilesRequest | SaveDownloadRequest | UploadFileChunkRequest | ReadFileChunkRequest | SetMobileFileChooserFilesRequest | SaveMobileDownloadRequest | NavigateRequest | ClickRequest | CountRequest | HighlightRequest | FocusRequest | FillRequest | HoverRequest | PressRequest | TextContentRequest | InnerTextRequest | WaitForSelectorRequest | AccessibilitySnapshotRequest | ScreenshotRequest | CloseContextRequest;
906
+ } | ContextPingRequest | RegisterHookRequest | WaitForHookRequest | HandleDialogRequest | SetFileChooserFilesRequest | SaveDownloadRequest | UploadFileChunkRequest | ReadFileChunkRequest | SetMobileFileChooserFilesRequest | SaveMobileDownloadRequest | NavigateRequest | ClickRequest | CountRequest | HighlightRequest | FocusRequest | FillRequest | HoverRequest | PressRequest | TextContentRequest | InnerTextRequest | WaitForSelectorRequest | AccessibilitySnapshotRequest | ScreenshotRequest | CloseContextRequest;
853
907
  export type SurfaceSessionStream = grpc.ClientDuplexStream<SurfaceSessionRequest, SurfaceSessionEvent>;
854
908
  export type ContextSessionStream = grpc.ClientDuplexStream<ContextSessionRequest, ContextSessionEvent>;
855
909
  export interface EngineServiceClientShape {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allwright.dev/core",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "High-level TypeScript client for the allwright automation engine.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -39,6 +39,7 @@
39
39
  "build": "tsc -p tsconfig.json",
40
40
  "example:web": "bun run examples/web-basic.ts",
41
41
  "example:android": "bun run examples/android-basic.ts",
42
+ "example:ios": "bun run examples/ios-basic.ts",
42
43
  "prepublishOnly": "bun run build"
43
44
  },
44
45
  "dependencies": {
@@ -39,6 +39,7 @@ message ContextSessionCommand {
39
39
  SaveMobileDownloadCommand save_mobile_download = 25;
40
40
  ResolveFrameCommand resolve_frame = 26;
41
41
  CaptureCommand capture = 27;
42
+ HandleDialogCommand handle_dialog = 28;
42
43
  }
43
44
  }
44
45
 
@@ -80,6 +81,7 @@ message ContextSessionEvent {
80
81
  MobileDownloadSavedEvent mobile_download_saved = 27;
81
82
  FrameResolvedEvent frame_resolved = 28;
82
83
  CaptureResolvedEvent capture_resolved = 29;
84
+ DialogHandledEvent dialog_handled = 30;
83
85
  }
84
86
  }
85
87
 
@@ -106,6 +108,7 @@ message RegisterHookCommand {
106
108
  RegisterDownloadHook download = 3;
107
109
  RegisterMobileFileChooserHook mobile_file_chooser = 4;
108
110
  RegisterMobileDownloadHook mobile_download = 5;
111
+ RegisterDialogHook dialog = 6;
109
112
  }
110
113
  }
111
114
 
@@ -127,6 +130,7 @@ message HookCompletedEvent {
127
130
  DownloadHookResult download = 4;
128
131
  MobileFileChooserHookResult mobile_file_chooser = 5;
129
132
  MobileDownloadHookResult mobile_download = 6;
133
+ DialogHookResult dialog = 7;
130
134
  }
131
135
  }
132
136
 
@@ -40,6 +40,23 @@ message ChromeLaunchedEvent {
40
40
  string initial_page_session_id = 5;
41
41
  }
42
42
 
43
+ // Register before the triggering action; wait returns a pending JavaScript dialog.
44
+ message RegisterDialogHook {}
45
+ message DialogHookResult {
46
+ string dialog_id = 1;
47
+ string type = 2;
48
+ string message = 3;
49
+ string default_value = 4;
50
+ }
51
+ message HandleDialogCommand {
52
+ string dialog_id = 1;
53
+ bool accept = 2;
54
+ optional string prompt_text = 3;
55
+ // A single-attempt deadline, not a retry request.
56
+ optional CommandRetryOptions retry_options = 4;
57
+ }
58
+ message DialogHandledEvent { string dialog_id = 1; }
59
+
43
60
  message RegisterNewPageHook {}
44
61
 
45
62
  message NewPageHookResult {