@appium/types 0.2.1 → 0.2.4

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/lib/index.ts CHANGED
@@ -1,514 +1,49 @@
1
- import type { Method as _Method } from 'axios';
2
- import type { EventEmitter } from 'events';
3
- import type { Server } from 'http';
4
- import type { Logger } from 'npmlog';
5
- import type { Class as _Class, MultidimensionalReadonlyArray } from 'type-fest';
6
- import { ServerArgs } from './config';
7
- import { Capabilities, W3CCapabilities } from './capabilities';
8
-
9
- export { AppiumW3CCapabilities } from './capabilities';
10
- export { AppiumConfig, NormalizedAppiumConfig } from './config';
1
+ import type {Method as _Method} from 'axios';
2
+ import type {Server} from 'http';
3
+ import type {Class as _Class, ConditionalPick, MultidimensionalReadonlyArray} from 'type-fest';
4
+ import {ServerArgs} from './config';
5
+ import {Capabilities, W3CCapabilities} from './capabilities';
6
+ import type {Express} from 'express';
7
+ import {ExternalDriver} from './driver';
8
+ import type {Logger} from 'npmlog';
9
+
10
+ export * from './driver';
11
+ export * from './plugin';
12
+ export {AppiumW3CCapabilities} from './capabilities';
13
+ export {AppiumConfig, NormalizedAppiumConfig} from './config';
11
14
  export * from './appium-config';
12
- export { ServerArgs, Capabilities, W3CCapabilities };
15
+ export {ServerArgs, Capabilities, W3CCapabilities};
13
16
 
14
17
  /**
15
- * Methods and properties which both `AppiumDriver` and `BaseDriver` inherit.
18
+ * A log prefix for {@linkcode AppiumLogger}
19
+ *
20
+ * If a function, the function will return the prefix. Log messages will be prefixed with this value.
16
21
  */
17
- export interface Core {
18
- sessionId: string | null;
19
- opts: ServerArgs;
20
- initialOpts: ServerArgs;
21
- caps?: Capabilities;
22
- originalCaps?: W3CCapabilities;
23
- protocol?: string;
24
- helpers: DriverHelpers;
25
- basePath: string;
26
- relaxedSecurityEnabled: boolean;
27
- allowInsecure: string[];
28
- denyInsecure: string[];
29
- newCommandTimeoutMs: number;
30
- implicitWaitMs: number;
31
- locatorStrategies: string[];
32
- webLocatorStrategies: string[];
33
- eventEmitter: EventEmitter;
34
- settings: DeviceSettings;
35
- log: AppiumLogger;
36
- driverData?: DriverData;
37
- isCommandsQueueEnabled: boolean;
38
- eventHistory: EventHistory;
39
- desiredCapConstraints: Constraints;
40
- onUnexpectedShutdown(handler: () => any): void;
41
- getStatus(): Promise<unknown>;
42
- logExtraCaps(caps: Capabilities): void;
43
- sessionExists(sessionId: string): boolean;
44
- validateDesiredCaps(caps: Capabilities): boolean;
45
- isW3CProtocol(): boolean;
46
- isMjsonwpProtocol(): boolean;
47
- isFeatureEnabled(name: string): boolean;
48
- ensureFeatureEnabled(name: string): void;
49
- validateLocatorStrategy(strategy: string, webContext?: boolean): void;
50
- proxyActive(sessionId?: string): boolean;
51
- getProxyAvoidList(sessionId?: string): [string, RegExp][];
52
- canProxy(sessionId?: string): boolean;
53
- proxyRouteIsAvoided(sessionId: string, method: string, url: string): boolean;
54
- addManagedDriver(driver: Driver): void;
55
- getManagedDrivers(): Driver[];
56
- clearNewCommandTimeout(): Promise<void>;
57
- logEvent(eventName: string): void;
58
- }
59
-
60
- export interface Driver
61
- extends SessionCommands,
62
- LogCommands,
63
- FindCommands,
64
- SettingsCommands,
65
- TimeoutCommands,
66
- EventCommands,
67
- SessionHandler<[string, any], void>,
68
- Core {
69
- // The following methods are implemented by `BaseDriver`.
70
- executeCommand(cmd: string, ...args: any[]): Promise<any>;
71
- startUnexpectedShutdown(err?: Error): Promise<void>;
72
- startNewCommandTimeout(): Promise<void>;
73
- reset(): Promise<void>;
74
-
75
- assignServer?(
76
- server: AppiumServer,
77
- host: string,
78
- port: number,
79
- path: string,
80
- ): void;
81
- }
22
+ export type AppiumLoggerPrefix = string | (() => string);
82
23
 
83
24
  /**
84
- * External drivers must subclass `BaseDriver`, and can implement any of these methods.
85
- * None of these are implemented within Appium itself.
25
+ * Possible "log levels" for {@linkcode AppiumLogger}.
26
+ *
27
+ * Extracted from `npmlog`.
86
28
  */
87
- export interface ExternalDriver extends Driver {
88
- // The following properties are assigned by appium */
89
- readonly server: AppiumServer;
90
- readonly serverHost: string;
91
- readonly serverPort: number;
92
- readonly serverPath: string;
93
-
94
- // WebDriver
95
- setUrl?(url: string): Promise<void>;
96
- getUrl?(): Promise<string>;
97
- back?(): Promise<void>;
98
- forward?(): Promise<void>;
99
- refresh?(): Promise<void>;
100
- title?(): Promise<string>;
101
- getWindowHandle?(): Promise<string>;
102
- closeWindow?(): Promise<string[]>;
103
- setWindow?(handle: string): Promise<void>;
104
- getWindowHandles?(): Promise<string[]>;
105
- setFrame?(id: null | number | string): Promise<void>;
106
- getWindowRect?(): Promise<Rect>;
107
- setWindowRect?(
108
- x: number,
109
- y: number,
110
- width: number,
111
- height: number,
112
- ): Promise<Rect>;
113
- maximizeWindow?(): Promise<Rect>;
114
- minimizeWindow?(): Promise<Rect>;
115
- fullScreenWindow?(): Promise<Rect>;
116
- createNewWindow?(type?: NewWindowType): Promise<NewWindow>;
117
- active?(): Promise<Element>;
118
- elementSelected?(elementId: string): Promise<boolean>;
119
- getAttribute?(name: string, elementId: string): Promise<string | null>;
120
- getProperty?(name: string, elementId: string): Promise<string | null>;
121
- getCssProperty?(name: string, elementId: string): Promise<string>;
122
- getText?(elementId: string): Promise<string>;
123
- getName?(elementId: string): Promise<string>;
124
- getElementRect?(elementId: string): Promise<Rect>;
125
- elementEnabled?(elementId: string): Promise<boolean>;
126
- elementDisplayed?(elementId: string): Promise<boolean>;
127
- click?(elementId: string): Promise<void>;
128
- clear?(elementId: string): Promise<void>;
129
- setValue?(text: string, elementId: string): Promise<void>;
130
- execute?(script: string, args: unknown[]): Promise<unknown>;
131
- executeAsync?(script: string, args: unknown[]): Promise<unknown>;
132
- getCookies?(): Promise<Cookie[]>;
133
- getCookie?(name: string): Promise<Cookie>;
134
- setCookie?(cookie: Cookie): Promise<void>;
135
- deleteCookie?(name: string): Promise<void>;
136
- deleteCookies?(): Promise<void>;
137
- performActions?(actions: Actions[]): Promise<void>;
138
- releaseActions?(): Promise<void>;
139
- postDismissAlert?(): Promise<void>;
140
- postAcceptAlert?(): Promise<void>;
141
- getAlertText?(): Promise<string | null>;
142
- setAlertText?(text: string): Promise<void>;
143
- getScreenshot?(): Promise<string>;
144
- getElementScreenshot?(elementId: string): Promise<string>;
145
-
146
- // Appium W3C WebDriver Extension
147
- mobileShake?(): Promise<void>;
148
- getDeviceTime?(format?: string): Promise<string>;
149
- lock?(seconds?: number): Promise<void>;
150
- unlock?(): Promise<void>;
151
- isLocked?(): Promise<boolean>;
152
- startRecordingScreen?(options?: ScreenRecordOptions): Promise<void>;
153
- stopRecordingScreen?(options?: ScreenRecordOptions): Promise<string>;
154
- getPerformanceDataTypes?(): Promise<string[]>;
155
- getPerformanceData?(
156
- packageName: string,
157
- dataType: string,
158
- dataReadTimeout?: number,
159
- ): Promise<string[]>;
160
- pressKeyCode?(
161
- keycode: number,
162
- metastate?: number,
163
- flags?: number,
164
- ): Promise<void>;
165
- longPressKeyCode?(
166
- keycode: number,
167
- metastate?: number,
168
- flags?: number,
169
- ): Promise<void>;
170
- fingerprint?(fingerprintId: number): Promise<void>;
171
- sendSMS?(phoneNumber: string, message: string): Promise<void>;
172
- gsmCall?(phoneNumber: string, action: string): Promise<void>;
173
- gsmSignal?(signalStrength: string): Promise<void>;
174
- gsmVoice?(state: string): Promise<void>;
175
- powerCapacity?(percent: number): Promise<void>;
176
- powerAC?(state: string): Promise<void>;
177
- networkSpeed?(netspeed: string): Promise<void>;
178
- keyevent?(keycode: string, metastate?: string): Promise<void>;
179
- mobileRotation?(
180
- x: number,
181
- y: number,
182
- radius: number,
183
- rotation: number,
184
- touchCount: number,
185
- duration: string,
186
- elementId?: string,
187
- ): Promise<void>;
188
- getCurrentActivity?(): Promise<string>;
189
- getCurrentPackage?(): Promise<string>;
190
- installApp?(appPath: string, options?: unknown): Promise<void>;
191
- activateApp?(appId: string, options?: unknown): Promise<void>;
192
- removeApp?(appId: string, options?: unknown): Promise<void>;
193
- terminateApp?(appId: string, options?: unknown): Promise<void>;
194
- isAppInstalled?(appId: string): Promise<boolean>;
195
- queryAppState?(appId: string): Promise<number>;
196
- hideKeyboard?(
197
- strategy?: string,
198
- key?: string,
199
- keyCode?: string,
200
- keyName?: string,
201
- ): Promise<void>;
202
- isKeyboardShown?(): Promise<boolean>;
203
- pushFile?(path: string, data: string): Promise<void>;
204
- pullFile?(path: string): Promise<string>;
205
- pullFolder?(path: string): Promise<string>;
206
- toggleFlightMode?(): Promise<void>;
207
- toggleData?(): Promise<void>;
208
- toggleWiFi?(): Promise<void>;
209
- toggleLocationServices?(): Promise<void>;
210
- openNotifications?(): Promise<void>;
211
- startActivity?(
212
- appPackage: string,
213
- appActivity: string,
214
- appWaitPackage?: string,
215
- appWaitActivity?: string,
216
- intentAction?: string,
217
- intentCategory?: string,
218
- intentFlags?: string,
219
- optionalIntentArguments?: string,
220
- dontStopAppOnReset?: boolean,
221
- ): Promise<void>;
222
- getSystemBars?(): Promise<unknown[]>;
223
- getDisplayDensity?(): Promise<number>;
224
- touchId?(match: boolean): Promise<void>;
225
- toggleEnrollTouchId?(enabled: boolean): Promise<void>;
226
- launchApp?(): Promise<void>;
227
- closeApp?(): Promise<void>;
228
- background?(seconds: null | number): Promise<void>;
229
- endCoverage?(intent: string, path: string): Promise<void>;
230
- getStrings?(
231
- language?: string,
232
- stringFile?: string,
233
- ): Promise<Record<string, unknown>>;
234
- setValueImmediate?(value: string, elementId: string): Promise<void>;
235
- replaceValue?(value: string, elementId: string): Promise<void>;
236
- receiveAsyncResponse?(response: unknown): Promise<void>;
237
- setClipboard?(
238
- content: string,
239
- contentType?: string,
240
- label?: string,
241
- ): Promise<void>;
242
- getClipboard?(contentType?: string): Promise<string>;
243
-
244
- // JSONWP
245
- asyncScriptTimeout?(ms: number): Promise<void>;
246
- getWindowSize?(): Promise<Size>;
247
- getLocation?(elementId: string): Promise<Position>;
248
- getLocationInView?(elementId: string): Promise<Position>;
249
- getSize?(elementId: string): Promise<Size>;
250
- elementShadowRoot?(elementId: string): Promise<Element>;
251
- findElementFromShadowRoot?(
252
- strategy: string,
253
- selector: string,
254
- shadowId: string
255
- ): Promise<Element>;
256
- findElementsFromShadowRoot?(
257
- strategy: string,
258
- selector: string,
259
- shadowId: string
260
- ): Promise<Element[]>;
261
- equalsElement?(elementId: string, otherElementId: string): Promise<boolean>;
262
- submit?(elementId: string): Promise<void>;
263
- keys?(value: string[]): Promise<void>;
264
- availableIMEEngines?(): Promise<string[]>;
265
- getActiveIMEEngine?(): Promise<string>;
266
- isIMEActivated?(): Promise<boolean>;
267
- deactivateIMEEngine?(): Promise<void>;
268
- activateIMEEngine?(engine: string): Promise<void>;
269
- getOrientation?(): Promise<string>;
270
- setOrientation?(orientation: string): Promise<void>;
271
- moveTo?(
272
- element?: null | string,
273
- xOffset?: number,
274
- yOffset?: number,
275
- ): Promise<void>;
276
- buttonDown?(button?: number): Promise<void>;
277
- buttonUp?(button?: number): Promise<void>;
278
- clickCurrent?(button?: number): Promise<void>;
279
- doubleClick?(): Promise<void>;
280
- touchDown?(x: number, y: number): Promise<void>;
281
- touchUp?(x: number, y: number): Promise<void>;
282
- touchMove?(x: number, y: number): Promise<void>;
283
- touchLongClick?(elementId: string): Promise<void>;
284
- flick?(
285
- element?: string,
286
- xSpeed?: number,
287
- ySpeed?: number,
288
- xOffset?: number,
289
- yOffset?: number,
290
- speed?: number,
291
- ): Promise<void>;
292
- getGeoLocation?(): Promise<Location>;
293
- setGeoLocation?(location: Partial<Location>): Promise<void>;
294
-
295
- // MJSONWIRE
296
- getCurrentContext?(): Promise<string | null>;
297
- setContext?(name: string): Promise<void>;
298
- getContexts?(): Promise<string[]>;
299
- getPageIndex?(elementId: string): Promise<string>;
300
- getNetworkConnection?(): Promise<number>;
301
- setNetworkConnection?(type: number): Promise<void>;
302
- performTouch?(actions: unknown): Promise<void>;
303
- performMultiAction?(actions: unknown, elementId: string): Promise<void>;
304
- getRotation?(): Promise<Rotation>;
305
- setRotation?(x: number, y: number, z: number): Promise<void>;
306
-
307
- // Chromium DevTools
308
- executeCdp?(cmd: string, params: unknown): Promise<unknown>;
309
-
310
- // Web Authentication
311
- addVirtualAuthenticator?(
312
- protocol: string,
313
- transport: string,
314
- hasResidentKey?: boolean,
315
- hasUserVerification?: boolean,
316
- isUserConsenting?: boolean,
317
- isUserVerified?: boolean,
318
- ): Promise<void>;
319
- removeVirtualAuthenticator?(): Promise<void>;
320
- addAuthCredential?(
321
- credentialId: string,
322
- isResidentCredential: boolean,
323
- rpId: string,
324
- privateKey: string,
325
- userHandle?: string,
326
- signCount?: number,
327
- ): Promise<void>;
328
- getAuthCredential?(): Promise<Credential[]>;
329
- removeAllAuthCredentials?(): Promise<void>;
330
- removeAuthCredential?(): Promise<void>;
331
- setUserAuthVerified?(isUserVerified: boolean): Promise<void>;
332
-
333
- proxyCommand?(
334
- url: string,
335
- method: HTTPMethod,
336
- body?: string,
337
- ): Promise<unknown>;
338
- }
339
-
340
- export interface Method<T extends ExternalDriver = ExternalDriver> {
341
- command?: keyof T; // T[keyof T] needs to return a Promise.
342
- neverProxy?: boolean;
343
- payloadParams?: PayloadParams;
344
- }
345
-
346
- export interface PayloadParams {
347
- wrap?: string;
348
- unwrap?: string;
349
- required?: Readonly<string[]> | MultidimensionalReadonlyArray<string, 2>;
350
- optional?: Readonly<string[]> | MultidimensionalReadonlyArray<string, 2>;
351
- validate?: (obj: any, protocol: string) => boolean | string | undefined;
352
- makeArgs?: (obj: any) => any;
353
- }
354
-
355
- export type MethodMap<T extends ExternalDriver = ExternalDriver> = Record<string, Record<string, Method<T>>>;
356
-
357
- export interface Constraint {
358
- presence?: boolean | {allowEmpty: boolean};
359
- isString?: boolean;
360
- isNumber?: boolean;
361
- isBoolean?: boolean;
362
- isObject?: boolean;
363
- isArray?: boolean;
364
- deprecated?: boolean;
365
- inclusion?: any[];
366
- }
367
- export type Constraints = Record<string, Constraint>;
368
-
369
- export interface Element {
370
- 'element-6066-11e4-a52e-4f735466cecf': string;
371
- }
372
-
373
- export interface DriverHelpers {
374
- configureApp: (
375
- app: string,
376
- supportedAppExtensions: string[],
377
- ) => Promise<string>;
378
- isPackageOrBundle: (app: string) => boolean;
379
- duplicateKeys: <T>(input: T, firstKey: string, secondKey: string) => T;
380
- parseCapsArray: (cap: string | string[]) => string[];
381
- generateDriverLogPrefix: (obj: Core, sessionId?: string) => string;
382
- }
383
-
384
- export type SettingsUpdateListener<
385
- T extends Record<string, unknown> = Record<string, unknown>,
386
- > = (prop: keyof T, newValue: unknown, curValue: unknown) => Promise<void>;
387
-
388
- export interface DeviceSettings<
389
- T extends Record<string, unknown> = Record<string, unknown>,
390
- > {
391
- update(newSettings: T): Promise<void>;
392
- getSettings(): T;
393
- }
394
-
395
- export interface LogType<TDriver, LogEntry = string> {
396
- description: string;
397
- getter: (driver: TDriver) => Promise<LogEntry[]>;
398
- }
399
-
400
- // WebDriver
401
-
402
- export interface Rect {
403
- x: number;
404
- y: number;
405
- width: number;
406
- height: number;
407
- }
408
-
409
- export type NewWindowType = 'tab' | 'window';
410
-
411
- export interface NewWindow {
412
- handle: string;
413
- type: NewWindowType;
414
- }
415
-
416
- export interface Cookie {
417
- name: string;
418
- value: string;
419
- path?: string;
420
- domain?: string;
421
- secure?: boolean;
422
- httpOnly?: boolean;
423
- expiry?: number;
424
- sameSite?: 'Lax' | 'Strict';
425
- }
426
-
427
- export interface Actions {
428
- type?: string;
429
- actions: Action[];
430
- parameters?: {
431
- pointerType?: string;
432
- };
433
- }
434
-
435
- export interface Action {
436
- duration?: number;
437
- type: string;
438
- value?: string;
439
- x?: number;
440
- y?: number;
441
- button?: number;
442
- origin?: string;
443
- }
444
-
445
- // Appium W3C WebDriver Extension
446
-
447
- export interface ScreenRecordOptions {
448
- remotePath?: string;
449
- username?: string;
450
- password?: string;
451
- method?: string;
452
- forceRestart?: boolean;
453
- timeLimit?: string;
454
- videoType?: string;
455
- videoQuality?: string;
456
- videoFps?: string;
457
- videoScale?: string;
458
- bitRate?: string;
459
- videoSize?: string;
460
- bugReport?: string;
461
- }
462
-
463
- // JSONWP
464
-
465
- export type Size = Pick<Rect, 'width' | 'height'>;
466
-
467
- export type Position = Pick<Rect, 'x' | 'y'>;
468
-
469
- export interface Location {
470
- latitude: number;
471
- longitude: number;
472
- altitude: number;
473
- }
474
-
475
- export interface Rotation {
476
- x: number;
477
- y: number;
478
- z: number;
479
- }
480
-
481
- // Web Authentication
482
-
483
- export interface Credential {
484
- credentialId: string;
485
- isResidentCredential: boolean;
486
- rpId: string;
487
- privateKey: string;
488
- userHandle?: string;
489
- signCount: number;
490
- largeBlob?: string;
491
- }
492
-
493
- export interface EventHistory {
494
- commands: EventHistoryCommand[];
495
- [key: string]: any;
496
- }
497
-
498
- export interface EventHistoryCommand {
499
- cmd: string;
500
- startTime: number;
501
- endTime: number;
502
- }
503
- export type HTTPMethod = _Method;
504
-
505
- export type Prefix = string|(() => string);
29
+ export type AppiumLoggerLevel = 'silly' | 'verbose' | 'debug' | 'info' | 'http' | 'warn' | 'error';
506
30
 
31
+ /**
32
+ * Describes the `npmlog`-based internal logger.
33
+ *
34
+ * @see https://npm.im/npmlog
35
+ */
507
36
  export interface AppiumLogger {
37
+ /**
38
+ * Returns the underlying `npmlog` {@link Logger}.
39
+ */
508
40
  unwrap(): Logger;
509
- level: string;
510
- levels: string[];
511
- prefix?: Prefix,
41
+ level: AppiumLoggerLevel;
42
+ levels: AppiumLoggerLevel[];
43
+ /**
44
+ * Log prefix, if applicable.
45
+ */
46
+ prefix?: AppiumLoggerPrefix;
512
47
  debug: (...args: any[]) => void;
513
48
  info: (...args: any[]) => void;
514
49
  warn: (...args: any[]) => void;
@@ -519,114 +54,59 @@ export interface AppiumLogger {
519
54
  errorAndThrow: (...args: any[]) => never;
520
55
  }
521
56
 
57
+ /**
58
+ * Appium's slightly-modified {@linkcode Server http.Server}.
59
+ */
522
60
  export type AppiumServer = Omit<Server, 'close'> & {
523
61
  close: () => Promise<void>;
524
62
  };
525
63
 
526
- export interface TimeoutCommands {
527
- timeouts(
528
- type: string,
529
- ms: number | string,
530
- script?: number,
531
- pageLoad?: number,
532
- implicit?: number | string,
533
- ): Promise<void>;
534
- setNewCommandTimeout(ms: number): void;
535
- implicitWait(ms: number | string): Promise<void>;
536
- setImplicitWait(ms: number): void;
537
- implicitWaitForCondition(condition: () => Promise<any>): Promise<unknown>;
538
- getTimeouts(): Promise<Record<string, number>>;
539
- implicitWaitW3C(ms: number): Promise<void>;
540
- implicitWaitMJSONWP(ms: number): Promise<void>;
541
- pageLoadTimeoutW3C(ms: number): Promise<void>;
542
- pageLoadTimeoutMJSONWP(ms: number): Promise<void>;
543
- scriptTimeoutW3C(ms: number): Promise<void>;
544
- scriptTimeoutMJSONWP(ms: number): Promise<void>;
545
- newCommandTimeout(ms: number): Promise<void>;
546
- parseTimeoutArgument(ms: number | string): number;
547
- }
548
-
549
- export interface EventCommands {
550
- logCustomEvent(vendor: string, event: string): Promise<void>;
551
- getLogEvents(type?: string | string[]): Promise<EventHistory | Record<string, number>>;
552
- }
553
-
554
- export interface SessionCommands {
555
- getSessions(): Promise<MultiSessionData[]>;
556
- getSession(): Promise<SingularSessionData>;
557
- }
558
-
559
- export interface MultiSessionData {
560
- id: string;
561
- capabilities: Capabilities;
562
- }
563
-
564
- export type SingularSessionData = Capabilities & {events?: EventHistory};
565
-
566
- export interface FindCommands {
567
- findElement(strategy: string, selector: string): Promise<Element>;
568
- findElements(strategy: string, selector: string): Promise<Element[]>;
569
- findElementFromElement(
570
- strategy: string,
571
- selector: string,
572
- elementId: string,
573
- ): Promise<Element>;
574
- findElementsFromElement(
575
- strategy: string,
576
- selector: string,
577
- elementId: string,
578
- ): Promise<Element[]>;
579
-
580
- findElOrEls<Mult extends boolean>(
581
- strategy: string,
582
- selector: string,
583
- mult: Mult,
584
- context?: string,
585
- ): Promise<Mult extends true ? Element[] : Element>;
586
-
587
- findElOrElsWithProcessing<Mult extends boolean>(
588
- strategy: string,
589
- selector: string,
590
- mult: Mult,
591
- context?: string,
592
- ): Promise<Mult extends true ? Element[] : Element>;
593
-
594
- getPageSource(): Promise<string>;
595
- }
596
-
597
- export interface LogCommands {
598
- supportedLogTypes: Record<string, LogType<Driver>>;
599
- getLogTypes(): Promise<string[]>;
64
+ /**
65
+ * The definition of an extension method, which will be provided via Appium's API.
66
+ *
67
+ */
68
+ export interface Method<T> {
600
69
  /**
601
- * Gets logs
602
- *
603
- * TODO: `logType` should be a key in `supportedLogTypes`, and the return value of this function
604
- * should be the associated `LogType` object's `LogEntry` parameterized type.
605
- * @param logType - Name/key of log type as defined in {@linkcode LogCommands.supportedLogTypes}.
70
+ * Name of the command.
606
71
  */
607
- getLog(logType: string): Promise<any[]>;
608
- }
609
-
610
- export interface SettingsCommands {
611
- updateSettings: (settings: Record<string, any>) => Promise<void>;
612
- getSettings(): Promise<Record<string, any>>;
72
+ command?: keyof ConditionalPick<Required<T>, DriverCommand>;
73
+ /**
74
+ * If true, this `Method` will never proxy.
75
+ */
76
+ neverProxy?: boolean;
77
+ /**
78
+ * Specifies shape of payload
79
+ */
80
+ payloadParams?: PayloadParams;
613
81
  }
614
82
 
615
- export interface SessionHandler<CreateResult, DeleteResult> {
616
- createSession(
617
- w3cCaps1: W3CCapabilities,
618
- w3cCaps2?: W3CCapabilities,
619
- w3cCaps?: W3CCapabilities,
620
- driverData?: DriverData[],
621
- ): Promise<CreateResult>;
83
+ /**
84
+ * An instance method of a driver class, whose name may be referenced by {@linkcode Method.command}, and serves as an Appium command.
85
+ *
86
+ * Note that this signature differs from a `PluginCommand`.
87
+ */
88
+ export type DriverCommand<TArgs = any, TRetval = unknown> = (...args: TArgs[]) => Promise<TRetval>;
622
89
 
623
- deleteSession(
624
- sessionId?: string,
625
- driverData?: DriverData[],
626
- ): Promise<DeleteResult>;
90
+ /**
91
+ * Defines the shape of a payload for a {@linkcode Method}.
92
+ */
93
+ export interface PayloadParams {
94
+ wrap?: string;
95
+ unwrap?: string;
96
+ required?: Readonly<string[]> | MultidimensionalReadonlyArray<string, 2>;
97
+ optional?: Readonly<string[]> | MultidimensionalReadonlyArray<string, 2>;
98
+ validate?: (obj: any, protocol: string) => boolean | string | undefined;
99
+ makeArgs?: (obj: any) => any;
627
100
  }
628
-
629
- export type DriverData = Record<string, unknown>;
101
+ /**
102
+ * A mapping of URL paths to HTTP methods to {@linkcode Method}s.
103
+ *
104
+ * @todo Should use {@linkcode HTTPMethod} here
105
+ */
106
+ export type MethodMap<Extension = ExternalDriver> = Record<
107
+ string,
108
+ Record<string, Method<Extension & ExternalDriver>>
109
+ >;
630
110
 
631
111
  /**
632
112
  * Wraps {@linkcode _Class `type-fest`'s `Class`} to include static members.
@@ -634,5 +114,42 @@ export type DriverData = Record<string, unknown>;
634
114
  export type Class<
635
115
  Proto,
636
116
  StaticMembers extends object = {},
637
- Args extends unknown[] = any[],
117
+ Args extends unknown[] = any[]
638
118
  > = _Class<Proto, Args> & StaticMembers;
119
+
120
+ /**
121
+ * The string referring to a "driver"-type extension
122
+ */
123
+ export type DriverType = 'driver';
124
+
125
+ /**
126
+ * The string referring to a "plugin"-type extension
127
+ *
128
+ */
129
+ export type PluginType = 'plugin';
130
+
131
+ /**
132
+ * The strings referring to all extension types.
133
+ */
134
+ export type ExtensionType = DriverType | PluginType;
135
+
136
+ /**
137
+ * Optionally updates an Appium express app and http server, by calling
138
+ * methods that may mutate those objects. For example, you could call:
139
+ *
140
+ * `expressApp.get('/foo', handler)`
141
+ *
142
+ * In order to add a new route to Appium with this plugin. Or, you could add
143
+ * new listeners to the httpServer object.
144
+ *
145
+ * @param expressApp - the Express 'app' object used by Appium for route handling
146
+ * @param httpServer - the node HTTP server that hosts the app
147
+ */
148
+ export type UpdateServerCallback = (expressApp: Express, httpServer: AppiumServer) => Promise<void>;
149
+
150
+ /**
151
+ * Possible HTTP methods, as stolen from `axios`.
152
+ *
153
+ * @see https://npm.im/axios
154
+ */
155
+ export type HTTPMethod = _Method;