@autifyhq/autify-cli 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -32
- package/dist/autify/connect/client-manager/AccessPoint.d.ts +16 -0
- package/dist/autify/connect/client-manager/AccessPoint.js +26 -0
- package/dist/autify/connect/client-manager/ClientManager.d.ts +57 -0
- package/dist/autify/connect/client-manager/ClientManager.js +245 -0
- package/dist/autify/connect/client-manager/DebugServerClient.d.ts +16 -0
- package/dist/autify/connect/client-manager/DebugServerClient.js +55 -0
- package/dist/autify/connect/client-manager/Logger.d.ts +11 -0
- package/dist/autify/connect/client-manager/Logger.js +43 -0
- package/dist/autify/connect/client-manager/StateMachine.d.ts +54 -0
- package/dist/autify/connect/client-manager/StateMachine.js +149 -0
- package/dist/autify/connect/installClient.d.ts +1 -1
- package/dist/autify/connect/installClient.js +4 -3
- package/dist/commands/connect/access-point/create.js +2 -2
- package/dist/commands/connect/access-point/set.js +1 -1
- package/dist/commands/connect/client/install.js +1 -1
- package/dist/commands/connect/client/start.js +26 -48
- package/dist/commands/web/test/run.js +39 -37
- package/oclif.manifest.json +1 -1
- package/package.json +11 -7
- package/dist/autify/connect/spawnClient.d.ts +0 -28
- package/dist/autify/connect/spawnClient.js +0 -192
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ See our official document: https://help.autify.com/docs/autify-command-line-inte
|
|
|
50
50
|
|
|
51
51
|
## `autify connect access-point create`
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
Create an Autify Connect Access Point
|
|
54
54
|
|
|
55
55
|
```
|
|
56
56
|
USAGE
|
|
@@ -58,10 +58,10 @@ USAGE
|
|
|
58
58
|
|
|
59
59
|
FLAGS
|
|
60
60
|
--name=<value> (required) Name of Autify Connect Access Point to be created
|
|
61
|
-
--web-workspace-id=<value> Workspace ID of Autify for Web to which the Access Point belong
|
|
61
|
+
--web-workspace-id=<value> Workspace ID of Autify for Web to which the Access Point will belong
|
|
62
62
|
|
|
63
63
|
DESCRIPTION
|
|
64
|
-
|
|
64
|
+
Create an Autify Connect Access Point
|
|
65
65
|
|
|
66
66
|
EXAMPLES
|
|
67
67
|
$ autify connect access-point create --name NAME --web-workspace-id ID
|
|
@@ -69,7 +69,7 @@ EXAMPLES
|
|
|
69
69
|
|
|
70
70
|
## `autify connect access-point set`
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
Set Autify Connect Access Point
|
|
73
73
|
|
|
74
74
|
```
|
|
75
75
|
USAGE
|
|
@@ -79,7 +79,7 @@ FLAGS
|
|
|
79
79
|
--name=<value> (required) Name of the Autify Connect Access Point already created
|
|
80
80
|
|
|
81
81
|
DESCRIPTION
|
|
82
|
-
|
|
82
|
+
Set Autify Connect Access Point
|
|
83
83
|
|
|
84
84
|
EXAMPLES
|
|
85
85
|
Start interactive setup:
|
|
@@ -93,17 +93,17 @@ EXAMPLES
|
|
|
93
93
|
|
|
94
94
|
## `autify connect client install [VERSION]`
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
Install Autify Connect Client
|
|
97
97
|
|
|
98
98
|
```
|
|
99
99
|
USAGE
|
|
100
100
|
$ autify connect client install [VERSION]
|
|
101
101
|
|
|
102
102
|
ARGUMENTS
|
|
103
|
-
VERSION [default: v0.6.
|
|
103
|
+
VERSION [default: v0.6.3] Specify the target version of Autify Connect Client.
|
|
104
104
|
|
|
105
105
|
DESCRIPTION
|
|
106
|
-
|
|
106
|
+
Install Autify Connect Client
|
|
107
107
|
|
|
108
108
|
EXAMPLES
|
|
109
109
|
(Recommended) Install the supported version:
|
|
@@ -121,25 +121,31 @@ EXAMPLES
|
|
|
121
121
|
|
|
122
122
|
## `autify connect client start`
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
Start Autify Connect Client
|
|
125
125
|
|
|
126
126
|
```
|
|
127
127
|
USAGE
|
|
128
128
|
$ autify connect client start [--verbose] [--file-logging] [--debug-server-port <value>] [--web-workspace-id <value>]
|
|
129
129
|
|
|
130
130
|
FLAGS
|
|
131
|
-
--debug-server-port=<value>
|
|
132
|
-
|
|
131
|
+
--debug-server-port=<value> The server for debugging and monitoring launches on your local machine on the given port.
|
|
132
|
+
It will use a radom port if not specified.
|
|
133
133
|
--file-logging Logging Autify Connect Client log to a file instead of console.
|
|
134
134
|
--verbose Make the operation more talkative.
|
|
135
135
|
--web-workspace-id=<value> Workspace ID of Autify for Web to create an ephemeral Access Point. If not specified, it
|
|
136
|
-
will use the one configured by `autify connect access-point set`, instead.
|
|
136
|
+
will use the one configured by `autify connect access-point create/set`, instead.
|
|
137
137
|
|
|
138
138
|
DESCRIPTION
|
|
139
|
-
|
|
139
|
+
Start Autify Connect Client
|
|
140
140
|
|
|
141
141
|
EXAMPLES
|
|
142
|
-
|
|
142
|
+
With pre-created Access Point:
|
|
143
|
+
|
|
144
|
+
$ autify connect client start
|
|
145
|
+
|
|
146
|
+
With ephemeral Access Point of Autify for Web:
|
|
147
|
+
|
|
148
|
+
$ autify connect client start --web-workspace-id 000
|
|
143
149
|
```
|
|
144
150
|
|
|
145
151
|
## `autify help [COMMAND]`
|
|
@@ -648,29 +654,26 @@ ARGUMENTS
|
|
|
648
654
|
https://app.autify.com/projects/<ID>/(scenarios|test_plans)/<ID>
|
|
649
655
|
|
|
650
656
|
FLAGS
|
|
651
|
-
-n, --name=<value>
|
|
657
|
+
-n, --name=<value> [Only for test scenario] Name of the test execution.
|
|
652
658
|
-r, --url-replacements=<value>... URL replacements. Example: http://example.com=http://example.net
|
|
653
659
|
-t, --timeout=<value> [default: 300] Timeout seconds when waiting for the finish of the
|
|
654
660
|
test execution.
|
|
655
661
|
-v, --verbose Verbose output
|
|
656
662
|
-w, --wait Wait until the test finishes.
|
|
657
|
-
--autify-connect=<value> Name of the Autify Connect Access Point
|
|
658
|
-
|
|
659
|
-
--autify-connect-client
|
|
660
|
-
|
|
661
|
-
--autify-connect-client-
|
|
662
|
-
|
|
663
|
-
--autify-connect-client-
|
|
664
|
-
|
|
665
|
-
--
|
|
666
|
-
|
|
667
|
-
--
|
|
668
|
-
|
|
669
|
-
--
|
|
670
|
-
--
|
|
671
|
-
(max-retry-count + 1).
|
|
672
|
-
--os=<value> OS to run the test
|
|
673
|
-
--os-version=<value> OS version to run the test
|
|
663
|
+
--autify-connect=<value> [Only for test scenario] Name of the Autify Connect Access Point.
|
|
664
|
+
--autify-connect-client [Only for test scenario] Start Autify Connect Client
|
|
665
|
+
--autify-connect-client-debug-server-port=<value> [Only for test scenario] Port for Autify Connect Client debug
|
|
666
|
+
server. A random port will be used if not specified.
|
|
667
|
+
--autify-connect-client-file-logging [Only for test scenario] Logging Autify Connect Client log to a
|
|
668
|
+
file instead of console.
|
|
669
|
+
--autify-connect-client-verbose [Only for test scenario] Verbose output for Autify Connect Client.
|
|
670
|
+
--browser=<value> [Only for test scenario] Browser to run the test
|
|
671
|
+
--device=<value> [Only for test scenario] Device to run the test
|
|
672
|
+
--device-type=<value> [Only for test scenario] Device type to run the test
|
|
673
|
+
--max-retry-count=<value> Maximum retry count while waiting. The command can take up to
|
|
674
|
+
`timeout * (max-retry-count + 1)`. Only effective with `--wait`.
|
|
675
|
+
--os=<value> [Only for test scenario] OS to run the test
|
|
676
|
+
--os-version=<value> [Only for test scenario] OS version to run the test
|
|
674
677
|
|
|
675
678
|
DESCRIPTION
|
|
676
679
|
Run a scenario or test plan.
|
|
@@ -704,6 +707,10 @@ EXAMPLES
|
|
|
704
707
|
Run a test scenario with Autify Connect:
|
|
705
708
|
|
|
706
709
|
$ autify web test run https://app.autify.com/projects/0000/scenarios/0000 --autify-connect NAME
|
|
710
|
+
|
|
711
|
+
Run a test scenario with Autify Connect Client:
|
|
712
|
+
|
|
713
|
+
$ autify web test run https://app.autify.com/projects/0000/scenarios/0000 --wait --autify-connect-client
|
|
707
714
|
```
|
|
708
715
|
|
|
709
716
|
## `autify web test wait TEST-RESULT-URL`
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WebClient } from "@autifyhq/autify-sdk";
|
|
2
|
+
interface StaticAccessPoint {
|
|
3
|
+
readonly type: "static";
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly key: string;
|
|
6
|
+
}
|
|
7
|
+
interface EphemeralAccessPoint {
|
|
8
|
+
readonly type: "ephemeral";
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly key: string;
|
|
11
|
+
readonly delete: () => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare type AccessPoint = StaticAccessPoint | EphemeralAccessPoint;
|
|
14
|
+
export declare const createStaticAccessPoint: (name: string, key: string) => StaticAccessPoint;
|
|
15
|
+
export declare const createEphemeralAccessPointForWeb: (client: WebClient, workspaceId: number) => Promise<EphemeralAccessPoint>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEphemeralAccessPointForWeb = exports.createStaticAccessPoint = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const ACCESS_POINT_NAME_PREFIX = "autify-cli-";
|
|
6
|
+
const createStaticAccessPoint = (name, key) => {
|
|
7
|
+
return { type: "static", name, key };
|
|
8
|
+
};
|
|
9
|
+
exports.createStaticAccessPoint = createStaticAccessPoint;
|
|
10
|
+
const createEphemeralAccessPointForWeb = async (client, workspaceId) => {
|
|
11
|
+
const randomName = `${ACCESS_POINT_NAME_PREFIX}${(0, uuid_1.v4)()}`;
|
|
12
|
+
const res = await client.createAccessPoint(workspaceId, { name: randomName });
|
|
13
|
+
const name = res.data.name;
|
|
14
|
+
const key = res.data.key;
|
|
15
|
+
return {
|
|
16
|
+
type: "ephemeral",
|
|
17
|
+
name,
|
|
18
|
+
key,
|
|
19
|
+
delete: async () => {
|
|
20
|
+
await client.deleteAccessPoint(workspaceId, {
|
|
21
|
+
name,
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports.createEphemeralAccessPointForWeb = createEphemeralAccessPointForWeb;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { CLIError } from "@oclif/errors";
|
|
3
|
+
import TypedEmitter from "typed-emitter";
|
|
4
|
+
export declare type ClientEvents = TypedEmitter<{
|
|
5
|
+
log: (msg: string) => void;
|
|
6
|
+
starting: (msg: string) => void;
|
|
7
|
+
ready: (msg: string) => void;
|
|
8
|
+
reconnecting: (msg: string) => void;
|
|
9
|
+
error: (error: Error) => void;
|
|
10
|
+
}>;
|
|
11
|
+
export declare type ProcessExit = Readonly<{
|
|
12
|
+
code: number | null;
|
|
13
|
+
signal: NodeJS.Signals | null;
|
|
14
|
+
}>;
|
|
15
|
+
export declare class StateMachineTimeoutError extends CLIError {
|
|
16
|
+
constructor(state: string);
|
|
17
|
+
}
|
|
18
|
+
declare type ClientManagerOptions = Readonly<{
|
|
19
|
+
configDir: string;
|
|
20
|
+
cacheDir: string;
|
|
21
|
+
verbose?: boolean;
|
|
22
|
+
fileLogging?: boolean;
|
|
23
|
+
debugServerPort?: number;
|
|
24
|
+
}>;
|
|
25
|
+
export declare class ClientManager {
|
|
26
|
+
private readonly accessPoint;
|
|
27
|
+
private readonly options;
|
|
28
|
+
static create(options: ClientManagerOptions & {
|
|
29
|
+
userAgent: string;
|
|
30
|
+
webWorkspaceId?: number;
|
|
31
|
+
}): Promise<ClientManager>;
|
|
32
|
+
private static createWithStaticAccessPoint;
|
|
33
|
+
private static createWithEphemeralAccessPointForWeb;
|
|
34
|
+
start(): Promise<void>;
|
|
35
|
+
onceReady(): Promise<void>;
|
|
36
|
+
onceTerminating(): Promise<void>;
|
|
37
|
+
onceDone(): Promise<number | null>;
|
|
38
|
+
exit(options?: {
|
|
39
|
+
ignoreError: boolean;
|
|
40
|
+
}): Promise<number | null>;
|
|
41
|
+
get accessPointName(): string;
|
|
42
|
+
private readonly clientEvents;
|
|
43
|
+
private readonly logger;
|
|
44
|
+
private readonly clientLogger;
|
|
45
|
+
private readonly service;
|
|
46
|
+
private childProcess?;
|
|
47
|
+
private debugServerClient?;
|
|
48
|
+
private constructor();
|
|
49
|
+
private spawn;
|
|
50
|
+
private terminate;
|
|
51
|
+
private kill;
|
|
52
|
+
private cleanup;
|
|
53
|
+
private once;
|
|
54
|
+
private get clientPath();
|
|
55
|
+
private getClientVersion;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientManager = exports.StateMachineTimeoutError = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/* eslint-disable unicorn/filename-case */
|
|
6
|
+
const autify_sdk_1 = require("@autifyhq/autify-sdk");
|
|
7
|
+
const errors_1 = require("@oclif/errors");
|
|
8
|
+
const node_child_process_1 = require("node:child_process");
|
|
9
|
+
const node_process_1 = require("node:process");
|
|
10
|
+
const node_stream_1 = require("node:stream");
|
|
11
|
+
const config_1 = require("../../../config");
|
|
12
|
+
const AccessPoint_1 = require("./AccessPoint");
|
|
13
|
+
const installClient_1 = require("../installClient");
|
|
14
|
+
const waitFor_1 = require("xstate/lib/waitFor");
|
|
15
|
+
const DebugServerClient_1 = require("./DebugServerClient");
|
|
16
|
+
const StateMachine_1 = require("./StateMachine");
|
|
17
|
+
const Logger_1 = require("./Logger");
|
|
18
|
+
const node_path_1 = require("node:path");
|
|
19
|
+
const get_port_1 = tslib_1.__importDefault(require("get-port"));
|
|
20
|
+
class StateMachineTimeoutError extends errors_1.CLIError {
|
|
21
|
+
constructor(state) {
|
|
22
|
+
super(`Autify Connect Manager faced timeout at ${state} state.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.StateMachineTimeoutError = StateMachineTimeoutError;
|
|
26
|
+
class ClientManager {
|
|
27
|
+
constructor(accessPoint, options) {
|
|
28
|
+
this.accessPoint = accessPoint;
|
|
29
|
+
this.options = options;
|
|
30
|
+
this.clientEvents = new node_stream_1.EventEmitter();
|
|
31
|
+
const level = options.verbose ? "debug" : "info";
|
|
32
|
+
this.logger = (0, Logger_1.createManagerLogger)({ level });
|
|
33
|
+
if (accessPoint.type === "ephemeral")
|
|
34
|
+
this.logger.info(`Ephemeral Access Point was created: ${this.accessPointName}`);
|
|
35
|
+
const filename = options.fileLogging
|
|
36
|
+
? (0, node_path_1.join)(options.cacheDir, `autifyconnect-${Date.now()}-${process.pid}.log`)
|
|
37
|
+
: undefined;
|
|
38
|
+
if (filename)
|
|
39
|
+
this.logger.info(`Client log will be written on ${filename}`);
|
|
40
|
+
this.clientLogger = (0, Logger_1.createClientLogger)({ level }, filename);
|
|
41
|
+
this.service = (0, StateMachine_1.createService)({
|
|
42
|
+
spawn: (debugServerPort) => this.spawn(debugServerPort),
|
|
43
|
+
terminate: () => this.terminate(),
|
|
44
|
+
kill: () => this.kill(),
|
|
45
|
+
cleanup: () => this.cleanup(),
|
|
46
|
+
errors: [],
|
|
47
|
+
}).onTransition((state, event) => {
|
|
48
|
+
if (!state.changed)
|
|
49
|
+
return;
|
|
50
|
+
this.logger.debug(`Transition to: ${state.value}, event: ${JSON.stringify(event)}`);
|
|
51
|
+
});
|
|
52
|
+
process.on("SIGINT", () => this.service.send("TERMINATE"));
|
|
53
|
+
process.on("SIGTERM", () => this.service.send("TERMINATE"));
|
|
54
|
+
this.clientEvents.on("ready", () => {
|
|
55
|
+
this.service.send("READY");
|
|
56
|
+
});
|
|
57
|
+
this.clientEvents.on("log", (msg) => {
|
|
58
|
+
// Guardrail in case debug server isn't working well.
|
|
59
|
+
if (msg.includes("Successfully connected")) {
|
|
60
|
+
this.clientEvents.emit("ready", msg);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
this.clientEvents.on("error", (error) => {
|
|
64
|
+
this.logger.warn(`Ignoring client error: ${error}`);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
static async create(options) {
|
|
68
|
+
if (options.webWorkspaceId) {
|
|
69
|
+
const { configDir, userAgent, webWorkspaceId } = options;
|
|
70
|
+
const accessToken = (0, config_1.getOrThrow)(configDir, "AUTIFY_WEB_ACCESS_TOKEN");
|
|
71
|
+
const basePath = (0, config_1.get)(configDir, "AUTIFY_WEB_BASE_PATH");
|
|
72
|
+
const client = new autify_sdk_1.WebClient(accessToken, { basePath, userAgent });
|
|
73
|
+
return this.createWithEphemeralAccessPointForWeb(client, webWorkspaceId, options);
|
|
74
|
+
}
|
|
75
|
+
return this.createWithStaticAccessPoint(options);
|
|
76
|
+
}
|
|
77
|
+
static async createWithStaticAccessPoint(options) {
|
|
78
|
+
const name = (0, config_1.get)(options.configDir, "AUTIFY_CONNECT_ACCESS_POINT_NAME");
|
|
79
|
+
const key = (0, config_1.get)(options.configDir, "AUTIFY_CONNECT_ACCESS_POINT_KEY");
|
|
80
|
+
if (!name || !key)
|
|
81
|
+
throw new errors_1.CLIError("Access Point is not saved. Run `autify connect access-point create/set` first.");
|
|
82
|
+
const accessPoint = (0, AccessPoint_1.createStaticAccessPoint)(name, key);
|
|
83
|
+
return new ClientManager(accessPoint, options);
|
|
84
|
+
}
|
|
85
|
+
static async createWithEphemeralAccessPointForWeb(client, workspaceId, options) {
|
|
86
|
+
const accessPoint = await (0, AccessPoint_1.createEphemeralAccessPointForWeb)(client, workspaceId);
|
|
87
|
+
return new ClientManager(accessPoint, options);
|
|
88
|
+
}
|
|
89
|
+
async start() {
|
|
90
|
+
var _a;
|
|
91
|
+
try {
|
|
92
|
+
this.logger.debug("start");
|
|
93
|
+
const version = await this.getClientVersion();
|
|
94
|
+
const debugServerPort = (_a = this.options.debugServerPort) !== null && _a !== void 0 ? _a : (await (0, get_port_1.default)());
|
|
95
|
+
this.logger.info(`Starting Autify Connect Client (accessPoint: ${this.accessPointName}, debugServerPort: ${debugServerPort}, path: ${this.clientPath}, version: ${version})`);
|
|
96
|
+
this.service.send("SPAWN", { debugServerPort });
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
this.service.send("FAIL", { error });
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async onceReady() {
|
|
104
|
+
this.logger.debug("onceReady");
|
|
105
|
+
await this.once("ready");
|
|
106
|
+
}
|
|
107
|
+
async onceTerminating() {
|
|
108
|
+
this.logger.debug("onceTerminating");
|
|
109
|
+
await this.once("terminating");
|
|
110
|
+
}
|
|
111
|
+
async onceDone() {
|
|
112
|
+
this.logger.debug("onceDone");
|
|
113
|
+
const { context: { processExit }, } = await this.once("done");
|
|
114
|
+
if (!processExit) {
|
|
115
|
+
this.logger.warn("Autify Connect Client exited but unable to capture the exit status");
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
this.logger.info(`Autify Connect Client exited (code: ${processExit.code}, signal: ${processExit.signal})`);
|
|
119
|
+
return processExit.code;
|
|
120
|
+
}
|
|
121
|
+
async exit(options) {
|
|
122
|
+
var _a;
|
|
123
|
+
try {
|
|
124
|
+
this.logger.debug("exit");
|
|
125
|
+
const snapshot = this.service.getSnapshot();
|
|
126
|
+
if (snapshot.done) {
|
|
127
|
+
this.logger.debug("Already exited.");
|
|
128
|
+
return ((_a = snapshot.context.processExit) === null || _a === void 0 ? void 0 : _a.code) || null;
|
|
129
|
+
}
|
|
130
|
+
this.service.send("TERMINATE");
|
|
131
|
+
return await this.onceDone();
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (options === null || options === void 0 ? void 0 : options.ignoreError) {
|
|
135
|
+
this.logger.warn(`Ignoring exit error: ${error}`);
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
get accessPointName() {
|
|
142
|
+
return this.accessPoint.name;
|
|
143
|
+
}
|
|
144
|
+
spawn(debugServerPort) {
|
|
145
|
+
try {
|
|
146
|
+
const args = [
|
|
147
|
+
"--log-format",
|
|
148
|
+
"json",
|
|
149
|
+
"--experimental-debug-server-port",
|
|
150
|
+
debugServerPort.toString(),
|
|
151
|
+
];
|
|
152
|
+
if (this.options.verbose)
|
|
153
|
+
args.push("--verbose");
|
|
154
|
+
this.childProcess = (0, node_child_process_1.spawn)(this.clientPath, args, {
|
|
155
|
+
env: {
|
|
156
|
+
...node_process_1.env,
|
|
157
|
+
AUTIFY_CONNECT_KEY: this.accessPoint.key,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
this.childProcess.on("exit", (code, signal) => {
|
|
161
|
+
this.service.send("EXIT", { processExit: { code, signal } });
|
|
162
|
+
});
|
|
163
|
+
this.debugServerClient = new DebugServerClient_1.DebugServerClient(debugServerPort, this.clientEvents);
|
|
164
|
+
(0, Logger_1.setupClientOutputLogger)(this.childProcess, (log) => {
|
|
165
|
+
this.clientLogger.log(log.level, log.msg);
|
|
166
|
+
this.clientEvents.emit("log", log.msg);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
this.logger.warn(`Ignoring spawn error: ${error}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async terminate() {
|
|
174
|
+
var _a;
|
|
175
|
+
try {
|
|
176
|
+
this.logger.debug("terminate");
|
|
177
|
+
await ((_a = this.debugServerClient) === null || _a === void 0 ? void 0 : _a.requestTerminate());
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
this.logger.warn(`Ignoring terminate error: ${error}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
kill() {
|
|
184
|
+
var _a;
|
|
185
|
+
try {
|
|
186
|
+
this.logger.debug("kill");
|
|
187
|
+
(_a = this.childProcess) === null || _a === void 0 ? void 0 : _a.kill();
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
this.logger.warn(`Ignoring kill error: ${error}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async cleanup() {
|
|
194
|
+
var _a;
|
|
195
|
+
try {
|
|
196
|
+
this.logger.debug("cleanup start");
|
|
197
|
+
(_a = this.debugServerClient) === null || _a === void 0 ? void 0 : _a.stopStatusTimer();
|
|
198
|
+
if (this.accessPoint.type === "ephemeral") {
|
|
199
|
+
await this.accessPoint.delete();
|
|
200
|
+
this.logger.info(`Ephemeral Access Point was deleted: ${this.accessPointName}`);
|
|
201
|
+
}
|
|
202
|
+
this.logger.debug("cleanup done");
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
this.logger.warn(`Ignoring cleanup error: ${error}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async once(waitState) {
|
|
209
|
+
let state;
|
|
210
|
+
try {
|
|
211
|
+
state = await (0, waitFor_1.waitFor)(this.service, (state) => state.matches(waitState) ||
|
|
212
|
+
state.matches("done") ||
|
|
213
|
+
state.matches("failed"), {
|
|
214
|
+
timeout: Number.POSITIVE_INFINITY,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
throw new errors_1.CLIError(`Unknown state transition: ${this.service.getSnapshot().value}`);
|
|
219
|
+
}
|
|
220
|
+
if (state.value === "failed")
|
|
221
|
+
this.logger.warn(`Failed (${state.context.errors})`);
|
|
222
|
+
const timeoutError = state.context.errors.find((error) => error instanceof StateMachineTimeoutError);
|
|
223
|
+
if (timeoutError)
|
|
224
|
+
throw timeoutError;
|
|
225
|
+
return state;
|
|
226
|
+
}
|
|
227
|
+
get clientPath() {
|
|
228
|
+
return (0, installClient_1.getInstallPath)(this.options.configDir, this.options.cacheDir);
|
|
229
|
+
}
|
|
230
|
+
async getClientVersion() {
|
|
231
|
+
const clientVersion = await (0, installClient_1.getInstallVersion)(this.clientPath);
|
|
232
|
+
try {
|
|
233
|
+
await (0, installClient_1.validateVersion)(clientVersion, installClient_1.AUTIFY_CONNECT_CLIENT_SUPPORTED_VERSION);
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
if (error instanceof installClient_1.ConnectClientVersionMismatchError) {
|
|
237
|
+
this.logger.warn("Installed Autify Connect Client version doesn't match our supported version. " +
|
|
238
|
+
"Consider to run `autify connect client install` to install the supported version. " +
|
|
239
|
+
`(version: ${clientVersion}, supported: ${installClient_1.AUTIFY_CONNECT_CLIENT_SUPPORTED_VERSION})`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return clientVersion;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
exports.ClientManager = ClientManager;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ClientEvents } from "./ClientManager";
|
|
2
|
+
declare type DebugServerStatusResponse = Readonly<{
|
|
3
|
+
status: "starting" | "ready" | "reconnecting";
|
|
4
|
+
message: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare class DebugServerClient {
|
|
7
|
+
private readonly port;
|
|
8
|
+
private readonly clientEvents;
|
|
9
|
+
private statusTimer;
|
|
10
|
+
constructor(port: number, clientEvents: ClientEvents);
|
|
11
|
+
stopStatusTimer(): void;
|
|
12
|
+
requestStatus(): Promise<DebugServerStatusResponse>;
|
|
13
|
+
requestTerminate(): Promise<void>;
|
|
14
|
+
private request;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DebugServerClient = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/* eslint-disable unicorn/filename-case */
|
|
6
|
+
const errors_1 = require("@oclif/errors");
|
|
7
|
+
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
8
|
+
const abort_controller_1 = tslib_1.__importDefault(require("abort-controller"));
|
|
9
|
+
class DebugServerClient {
|
|
10
|
+
constructor(port, clientEvents) {
|
|
11
|
+
this.port = port;
|
|
12
|
+
this.clientEvents = clientEvents;
|
|
13
|
+
this.statusTimer = setInterval(async () => {
|
|
14
|
+
try {
|
|
15
|
+
const response = await this.requestStatus();
|
|
16
|
+
this.clientEvents.emit(response.status, response.message);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
this.clientEvents.emit("error", error);
|
|
20
|
+
}
|
|
21
|
+
}, 1000);
|
|
22
|
+
}
|
|
23
|
+
stopStatusTimer() {
|
|
24
|
+
clearInterval(this.statusTimer);
|
|
25
|
+
}
|
|
26
|
+
async requestStatus() {
|
|
27
|
+
const req = { method: "GET", path: "/status" };
|
|
28
|
+
const res = (await this.request(req));
|
|
29
|
+
if (res.status && res.message)
|
|
30
|
+
return res;
|
|
31
|
+
throw new errors_1.CLIError(`Invalid response from ${JSON.stringify(req)}: ${JSON.stringify(res)}`);
|
|
32
|
+
}
|
|
33
|
+
async requestTerminate() {
|
|
34
|
+
const req = { method: "POST", path: "/terminate" };
|
|
35
|
+
await this.request(req);
|
|
36
|
+
}
|
|
37
|
+
async request({ method, path }) {
|
|
38
|
+
const controller = new abort_controller_1.default();
|
|
39
|
+
const timeout = setTimeout(() => controller.abort(), 1000);
|
|
40
|
+
let response;
|
|
41
|
+
try {
|
|
42
|
+
response = await (0, node_fetch_1.default)(`http://localhost:${this.port}${path}`, {
|
|
43
|
+
method,
|
|
44
|
+
signal: controller.signal,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
clearTimeout(timeout);
|
|
49
|
+
}
|
|
50
|
+
if (response.ok)
|
|
51
|
+
return response.json();
|
|
52
|
+
throw new errors_1.CLIError(`Request to debug server failed: ${method} ${path} => ${response.status} ${response.statusText}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.DebugServerClient = DebugServerClient;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ChildProcessWithoutNullStreams } from "node:child_process";
|
|
2
|
+
import { Logger, LoggerOptions } from "winston";
|
|
3
|
+
declare type ClientLog = Readonly<{
|
|
4
|
+
level: string;
|
|
5
|
+
ts: string;
|
|
6
|
+
msg: string;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const createManagerLogger: (options: LoggerOptions) => Logger;
|
|
9
|
+
export declare const createClientLogger: (options: LoggerOptions, filename?: string) => Logger;
|
|
10
|
+
export declare const setupClientOutputLogger: (childProcess: ChildProcessWithoutNullStreams, callback: (log: ClientLog) => void) => void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupClientOutputLogger = exports.createClientLogger = exports.createManagerLogger = void 0;
|
|
4
|
+
const node_readline_1 = require("node:readline");
|
|
5
|
+
const winston_1 = require("winston");
|
|
6
|
+
const logFormatConsole = (prefix) => winston_1.format.combine(winston_1.format.colorize(), winston_1.format.timestamp(), winston_1.format.printf(({ timestamp, level, message }) => `${prefix.padEnd(25)} ${timestamp}\t${level}\t${message}`));
|
|
7
|
+
const logFormatFile = () => winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.printf(({ timestamp, level, message }) => `${timestamp}\t${level}\t${message}`));
|
|
8
|
+
const createManagerLogger = (options) => {
|
|
9
|
+
return (0, winston_1.createLogger)(options).add(new winston_1.transports.Console({
|
|
10
|
+
format: logFormatConsole("[Autify Connect Manager]"),
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
exports.createManagerLogger = createManagerLogger;
|
|
14
|
+
const createClientLogger = (options, filename) => {
|
|
15
|
+
const logger = (0, winston_1.createLogger)(options);
|
|
16
|
+
filename
|
|
17
|
+
? logger.add(new winston_1.transports.File({
|
|
18
|
+
format: logFormatFile(),
|
|
19
|
+
filename,
|
|
20
|
+
}))
|
|
21
|
+
: logger.add(new winston_1.transports.Console({
|
|
22
|
+
format: logFormatConsole("[Autify Connect Client] "),
|
|
23
|
+
}));
|
|
24
|
+
return logger;
|
|
25
|
+
};
|
|
26
|
+
exports.createClientLogger = createClientLogger;
|
|
27
|
+
const setupClientOutputLogger = (childProcess, callback) => {
|
|
28
|
+
// stdout
|
|
29
|
+
(0, node_readline_1.createInterface)({
|
|
30
|
+
input: childProcess.stdout,
|
|
31
|
+
crlfDelay: Number.POSITIVE_INFINITY,
|
|
32
|
+
}).on("line", (line) => {
|
|
33
|
+
try {
|
|
34
|
+
callback(JSON.parse(line));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Ignore errors
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
// stderr
|
|
41
|
+
childProcess.stderr.pipe(process.stderr);
|
|
42
|
+
};
|
|
43
|
+
exports.setupClientOutputLogger = setupClientOutputLogger;
|