@_davideast/stitch-mcp 0.3.2 → 0.5.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 +54 -239
- package/dist/chunk-25wakzyb.js +137 -0
- package/dist/chunk-25wakzyb.js.map +10 -0
- package/dist/chunk-2cetsfw4.js +16531 -0
- package/dist/chunk-2cetsfw4.js.map +95 -0
- package/dist/chunk-2fcdwvrm.js +54 -0
- package/dist/chunk-2fcdwvrm.js.map +10 -0
- package/dist/chunk-2k7n0w2x.js +3980 -0
- package/dist/chunk-2k7n0w2x.js.map +16 -0
- package/dist/chunk-2kyqsrg2.js +403 -0
- package/dist/chunk-2kyqsrg2.js.map +10 -0
- package/dist/chunk-384jmtpy.js +11057 -0
- package/dist/chunk-384jmtpy.js.map +238 -0
- package/dist/chunk-3at4pjgn.js +22 -0
- package/dist/chunk-3at4pjgn.js.map +9 -0
- package/dist/chunk-3sfn889r.js +492 -0
- package/dist/chunk-3sfn889r.js.map +13 -0
- package/dist/chunk-45wx7tn7.js +94 -0
- package/dist/chunk-45wx7tn7.js.map +10 -0
- package/dist/chunk-48d17n29.js +10 -0
- package/dist/chunk-48d17n29.js.map +9 -0
- package/dist/chunk-4jwmvjb4.js +839 -0
- package/dist/chunk-4jwmvjb4.js.map +11 -0
- package/dist/chunk-4jygt4d6.js +14 -0
- package/dist/chunk-4jygt4d6.js.map +10 -0
- package/dist/chunk-4vxy1qce.js +68 -0
- package/dist/chunk-4vxy1qce.js.map +10 -0
- package/dist/chunk-7tx0wn04.js +11 -0
- package/dist/chunk-7tx0wn04.js.map +9 -0
- package/dist/chunk-7xh1y383.js +45188 -0
- package/dist/chunk-7xh1y383.js.map +258 -0
- package/dist/chunk-8yrtq2qs.js +18 -0
- package/dist/chunk-8yrtq2qs.js.map +9 -0
- package/dist/chunk-985f11w6.js +21 -0
- package/dist/chunk-985f11w6.js.map +9 -0
- package/dist/chunk-9tvppjaf.js +250 -0
- package/dist/chunk-9tvppjaf.js.map +14 -0
- package/dist/chunk-9wyra8hs.js +32 -0
- package/dist/chunk-9wyra8hs.js.map +9 -0
- package/dist/chunk-cwkb2wbe.js +733 -0
- package/dist/chunk-cwkb2wbe.js.map +16 -0
- package/dist/chunk-djhzzcgj.js +362 -0
- package/dist/chunk-djhzzcgj.js.map +13 -0
- package/dist/chunk-edp6faw2.js +7 -0
- package/dist/chunk-edp6faw2.js.map +9 -0
- package/dist/chunk-ezmw2j8c.js +14 -0
- package/dist/chunk-ezmw2j8c.js.map +9 -0
- package/dist/chunk-f2hq6bfv.js +22 -0
- package/dist/chunk-f2hq6bfv.js.map +10 -0
- package/dist/chunk-fwb4fnkp.js +31 -0
- package/dist/chunk-fwb4fnkp.js.map +10 -0
- package/dist/chunk-h18jrqed.js +9517 -0
- package/dist/chunk-h18jrqed.js.map +99 -0
- package/dist/chunk-hb3c6f6a.js +42 -0
- package/dist/chunk-hb3c6f6a.js.map +9 -0
- package/dist/chunk-jy2d17pr.js +252 -0
- package/dist/chunk-jy2d17pr.js.map +11 -0
- package/dist/chunk-kbtqrkwh.js +24 -0
- package/dist/chunk-kbtqrkwh.js.map +10 -0
- package/dist/chunk-knbnsf6s.js +92 -0
- package/dist/chunk-knbnsf6s.js.map +10 -0
- package/dist/chunk-mv9ssgmx.js +446 -0
- package/dist/chunk-mv9ssgmx.js.map +17 -0
- package/dist/chunk-nq68kghz.js +1647 -0
- package/dist/chunk-nq68kghz.js.map +10 -0
- package/dist/chunk-nthabjd9.js +3138 -0
- package/dist/chunk-nthabjd9.js.map +34 -0
- package/dist/chunk-nxpzt33t.js +278 -0
- package/dist/chunk-nxpzt33t.js.map +10 -0
- package/dist/chunk-pfyjtfex.js +172 -0
- package/dist/chunk-pfyjtfex.js.map +10 -0
- package/dist/chunk-q1nd6g0y.js +392 -0
- package/dist/chunk-q1nd6g0y.js.map +20 -0
- package/dist/chunk-q4js8r0z.js +4708 -0
- package/dist/chunk-q4js8r0z.js.map +29 -0
- package/dist/chunk-qv44tmn6.js +289 -0
- package/dist/chunk-qv44tmn6.js.map +13 -0
- package/dist/chunk-r2sg2nxa.js +20 -0
- package/dist/chunk-r2sg2nxa.js.map +9 -0
- package/dist/chunk-rp8wjzht.js +16959 -0
- package/dist/chunk-rp8wjzht.js.map +26 -0
- package/dist/chunk-rpxnm86e.js +372 -0
- package/dist/chunk-rpxnm86e.js.map +17 -0
- package/dist/chunk-sdp429xd.js +914 -0
- package/dist/chunk-sdp429xd.js.map +24 -0
- package/dist/chunk-t85nbjjb.js +113 -0
- package/dist/chunk-t85nbjjb.js.map +10 -0
- package/dist/chunk-tz7wnw4s.js +211 -0
- package/dist/chunk-tz7wnw4s.js.map +11 -0
- package/dist/chunk-v7117ywx.js +1477 -0
- package/dist/chunk-v7117ywx.js.map +23 -0
- package/dist/chunk-w8q7nsm7.js +2098 -0
- package/dist/chunk-w8q7nsm7.js.map +44 -0
- package/dist/chunk-wa64nz8b.js +47 -0
- package/dist/chunk-wa64nz8b.js.map +10 -0
- package/dist/chunk-wz8d5vzb.js +234 -0
- package/dist/chunk-wz8d5vzb.js.map +11 -0
- package/dist/chunk-ycfxp056.js +677 -0
- package/dist/chunk-ycfxp056.js.map +17 -0
- package/dist/chunk-z9d2xc83.js +3256 -0
- package/dist/chunk-z9d2xc83.js.map +84 -0
- package/dist/cli.js +111 -125552
- package/dist/cli.js.map +19 -0
- package/dist/commands/autoload.d.ts +2 -0
- package/dist/commands/doctor/command.d.ts +2 -1
- package/dist/commands/doctor/command.js +82 -0
- package/dist/commands/doctor/command.js.map +11 -0
- package/dist/commands/doctor/spec.d.ts +16 -8
- package/dist/commands/init/command.d.ts +2 -1
- package/dist/commands/init/command.js +98 -0
- package/dist/commands/init/command.js.map +11 -0
- package/dist/commands/init/spec.d.ts +29 -9
- package/dist/commands/logout/command.d.ts +2 -1
- package/dist/commands/logout/command.js +79 -0
- package/dist/commands/logout/command.js.map +11 -0
- package/dist/commands/logout/spec.d.ts +11 -0
- package/dist/commands/proxy/command.d.ts +2 -1
- package/dist/commands/proxy/command.js +56 -0
- package/dist/commands/proxy/command.js.map +11 -0
- package/dist/commands/proxy/spec.d.ts +15 -0
- package/dist/commands/screens/command.d.ts +2 -1
- package/dist/commands/screens/command.js +61 -0
- package/dist/commands/screens/command.js.map +11 -0
- package/dist/commands/screens/spec.d.ts +9 -0
- package/dist/commands/serve/command.d.ts +2 -1
- package/dist/commands/serve/command.js +65 -0
- package/dist/commands/serve/command.js.map +11 -0
- package/dist/commands/serve/spec.d.ts +9 -0
- package/dist/commands/site/command.d.ts +2 -1
- package/dist/commands/site/command.js +53 -0
- package/dist/commands/site/command.js.map +11 -0
- package/dist/commands/site/spec.d.ts +15 -0
- package/dist/commands/snapshot/command.d.ts +2 -1
- package/dist/commands/snapshot/command.js +59 -0
- package/dist/commands/snapshot/command.js.map +11 -0
- package/dist/commands/tool/command.d.ts +2 -1
- package/dist/commands/tool/command.js +79 -0
- package/dist/commands/tool/command.js.map +11 -0
- package/dist/commands/tool/handler.d.ts +17 -0
- package/dist/commands/tool/spec.d.ts +17 -0
- package/dist/commands/tool/steps/ValidateToolStep.d.ts +8 -0
- package/dist/commands/tool/virtual-tools/index.d.ts +1 -0
- package/dist/commands/tool/virtual-tools/list-tools.d.ts +2 -0
- package/dist/commands/view/command.d.ts +2 -1
- package/dist/commands/view/command.js +52 -0
- package/dist/commands/view/command.js.map +11 -0
- package/dist/commands/view/spec.d.ts +24 -0
- package/dist/framework/CommandDefinition.d.ts +2 -2
- package/dist/index.js +26 -21668
- package/dist/index.js.map +9 -0
- package/dist/lib/services/site/schemas.d.ts +8 -8
- package/dist/services/config/handler.d.ts +12 -0
- package/dist/services/config/spec.d.ts +82 -0
- package/dist/services/gcloud/auth.d.ts +28 -0
- package/dist/services/gcloud/core.d.ts +21 -0
- package/dist/services/gcloud/handler.d.ts +6 -18
- package/dist/services/gcloud/install.d.ts +23 -0
- package/dist/services/gcloud/projects.d.ts +15 -0
- package/dist/services/gcloud/spec.d.ts +32 -24
- package/dist/services/mcp-client/client.d.ts +0 -5
- package/dist/services/mcp-client/spec.d.ts +6 -6
- package/dist/services/mcp-config/spec.d.ts +12 -12
- package/dist/services/project/spec.d.ts +4 -4
- package/dist/services/proxy/spec.d.ts +3 -3
- package/dist/services/stitch/api.d.ts +10 -0
- package/dist/services/stitch/connection.d.ts +5 -0
- package/dist/services/stitch/handler.d.ts +5 -3
- package/dist/services/stitch/iam.d.ts +11 -0
- package/dist/services/stitch/spec.d.ts +6 -6
- package/dist/services/view/spec.d.ts +7 -7
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/commands/doctor/handler.d.ts +9 -0
- package/dist/src/commands/doctor/handler.test.d.ts +1 -0
- package/dist/src/commands/doctor/spec.d.ts +130 -0
- package/dist/src/commands/doctor/spec.test.d.ts +1 -0
- package/dist/src/commands/init/handler.d.ts +17 -0
- package/dist/src/commands/init/handler.test.d.ts +1 -0
- package/dist/src/commands/init/spec.d.ts +88 -0
- package/dist/src/commands/init/spec.test.d.ts +1 -0
- package/dist/src/commands/proxy/handler.d.ts +7 -0
- package/dist/src/commands/proxy/handler.test.d.ts +1 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/platform/detector.d.ts +29 -0
- package/dist/src/platform/paths.d.ts +20 -0
- package/dist/src/platform/shell.d.ts +26 -0
- package/dist/src/services/gcloud/handler.d.ts +48 -0
- package/dist/src/services/gcloud/handler.test.d.ts +1 -0
- package/dist/src/services/gcloud/spec.d.ts +405 -0
- package/dist/src/services/mcp-config/handler.d.ts +12 -0
- package/dist/src/services/mcp-config/handler.test.d.ts +1 -0
- package/dist/src/services/mcp-config/spec.d.ts +88 -0
- package/dist/src/services/mcp-config/spec.test.d.ts +1 -0
- package/dist/src/services/project/handler.d.ts +11 -0
- package/dist/src/services/project/handler.test.d.ts +1 -0
- package/dist/src/services/project/spec.d.ts +86 -0
- package/dist/src/services/project/spec.test.d.ts +1 -0
- package/dist/src/services/proxy/handler.d.ts +15 -0
- package/dist/src/services/proxy/handler.test.d.ts +1 -0
- package/dist/src/services/proxy/spec.d.ts +83 -0
- package/dist/src/services/proxy/spec.test.d.ts +1 -0
- package/dist/src/services/stitch/handler.d.ts +15 -0
- package/dist/src/services/stitch/handler.test.d.ts +1 -0
- package/dist/src/services/stitch/spec.d.ts +262 -0
- package/dist/src/services/stitch/spec.test.d.ts +1 -0
- package/dist/src/ui/spinner.d.ts +11 -0
- package/dist/src/ui/theme.d.ts +18 -0
- package/dist/src/ui/wizard.d.ts +24 -0
- package/dist/tests/mocks/shell.d.ts +2 -0
- package/dist/ui/JsonTree.d.ts +1 -1
- package/package.json +2 -2
- package/dist/commands/registry.d.ts +0 -2
- package/dist/ui/copy-behaviors/index.d.ts +0 -8
- package/dist/ui/serve-behaviors/index.d.ts +0 -7
- /package/dist/ui/navigation-behaviors/{index.d.ts → handler.d.ts} +0 -0
|
@@ -0,0 +1,914 @@
|
|
|
1
|
+
import {
|
|
2
|
+
require_cli_spinners
|
|
3
|
+
} from "./chunk-nq68kghz.js";
|
|
4
|
+
import {
|
|
5
|
+
eastAsianWidth,
|
|
6
|
+
require_emoji_regex,
|
|
7
|
+
stripAnsi
|
|
8
|
+
} from "./chunk-mv9ssgmx.js";
|
|
9
|
+
import {
|
|
10
|
+
GcloudExecutor
|
|
11
|
+
} from "./chunk-nthabjd9.js";
|
|
12
|
+
import {
|
|
13
|
+
isUnicodeSupported
|
|
14
|
+
} from "./chunk-4jygt4d6.js";
|
|
15
|
+
import {
|
|
16
|
+
onExit
|
|
17
|
+
} from "./chunk-tz7wnw4s.js";
|
|
18
|
+
import {
|
|
19
|
+
source_default
|
|
20
|
+
} from "./chunk-3sfn889r.js";
|
|
21
|
+
import {
|
|
22
|
+
__toESM
|
|
23
|
+
} from "./chunk-9wyra8hs.js";
|
|
24
|
+
|
|
25
|
+
// src/services/stitch/iam.ts
|
|
26
|
+
class StitchIamService {
|
|
27
|
+
executor;
|
|
28
|
+
constructor(executor) {
|
|
29
|
+
this.executor = executor;
|
|
30
|
+
}
|
|
31
|
+
async configureIAM(input) {
|
|
32
|
+
try {
|
|
33
|
+
const role = "roles/serviceusage.serviceUsageConsumer";
|
|
34
|
+
const member = `user:${input.userEmail}`;
|
|
35
|
+
const result = await this.executor.exec([
|
|
36
|
+
"projects",
|
|
37
|
+
"add-iam-policy-binding",
|
|
38
|
+
input.projectId,
|
|
39
|
+
`--member=${member}`,
|
|
40
|
+
`--role=${role}`,
|
|
41
|
+
"--condition=None",
|
|
42
|
+
"--quiet"
|
|
43
|
+
]);
|
|
44
|
+
if (!result.success) {
|
|
45
|
+
const errorMsg = result.stderr || result.error || result.stdout || "Unknown error";
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
error: {
|
|
49
|
+
code: "IAM_CONFIG_FAILED",
|
|
50
|
+
message: `Failed to configure IAM permissions: ${errorMsg}`,
|
|
51
|
+
suggestion: "Ensure you have Owner or Editor role on the project",
|
|
52
|
+
recoverable: true,
|
|
53
|
+
details: `Exit code: ${result.exitCode}
|
|
54
|
+
Stderr: ${result.stderr}
|
|
55
|
+
Stdout: ${result.stdout}`
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
success: true,
|
|
61
|
+
data: {
|
|
62
|
+
role,
|
|
63
|
+
member
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
} catch (error) {
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
error: {
|
|
70
|
+
code: "IAM_CONFIG_FAILED",
|
|
71
|
+
message: error instanceof Error ? error.message : String(error),
|
|
72
|
+
recoverable: false
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async checkIAMRole(input) {
|
|
78
|
+
try {
|
|
79
|
+
const role = "roles/serviceusage.serviceUsageConsumer";
|
|
80
|
+
const member = `user:${input.userEmail}`;
|
|
81
|
+
const result = await this.executor.exec([
|
|
82
|
+
"projects",
|
|
83
|
+
"get-iam-policy",
|
|
84
|
+
input.projectId,
|
|
85
|
+
`--flatten=bindings[].members`,
|
|
86
|
+
`--filter=bindings.role=${role} AND bindings.members=${member}`,
|
|
87
|
+
"--format=value(bindings.members)"
|
|
88
|
+
]);
|
|
89
|
+
return result.success && result.stdout.trim().includes(member);
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/services/stitch/api.ts
|
|
97
|
+
class StitchApiService {
|
|
98
|
+
executor;
|
|
99
|
+
constructor(executor) {
|
|
100
|
+
this.executor = executor;
|
|
101
|
+
}
|
|
102
|
+
async enableAPI(input) {
|
|
103
|
+
try {
|
|
104
|
+
const api = "stitch.googleapis.com";
|
|
105
|
+
const result = await this.executor.exec(["beta", "services", "mcp", "enable", api, `--project=${input.projectId}`, "--quiet"]);
|
|
106
|
+
if (!result.success) {
|
|
107
|
+
const errorMsg = result.stderr || result.error || result.stdout || "Unknown error";
|
|
108
|
+
return {
|
|
109
|
+
success: false,
|
|
110
|
+
error: {
|
|
111
|
+
code: "API_ENABLE_FAILED",
|
|
112
|
+
message: `Failed to enable Stitch API: ${errorMsg}`,
|
|
113
|
+
suggestion: "Ensure the project has billing enabled",
|
|
114
|
+
recoverable: true,
|
|
115
|
+
details: `Exit code: ${result.exitCode}
|
|
116
|
+
Stderr: ${result.stderr}
|
|
117
|
+
Stdout: ${result.stdout}`
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
success: true,
|
|
123
|
+
data: {
|
|
124
|
+
api,
|
|
125
|
+
enabled: true
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
} catch (error) {
|
|
129
|
+
return {
|
|
130
|
+
success: false,
|
|
131
|
+
error: {
|
|
132
|
+
code: "API_ENABLE_FAILED",
|
|
133
|
+
message: error instanceof Error ? error.message : String(error),
|
|
134
|
+
recoverable: false
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async checkAPIEnabled(input) {
|
|
140
|
+
try {
|
|
141
|
+
const result = await this.executor.exec([
|
|
142
|
+
"services",
|
|
143
|
+
"list",
|
|
144
|
+
`--project=${input.projectId}`,
|
|
145
|
+
"--enabled",
|
|
146
|
+
"--filter=name:stitch.googleapis.com",
|
|
147
|
+
"--format=value(name)"
|
|
148
|
+
]);
|
|
149
|
+
return result.success && result.stdout.trim().includes("stitch.googleapis.com");
|
|
150
|
+
} catch {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/services/stitch/connection.ts
|
|
157
|
+
class StitchConnectionService {
|
|
158
|
+
async testConnectionWithApiKey(input) {
|
|
159
|
+
try {
|
|
160
|
+
const url = process.env.STITCH_HOST || "https://stitch.googleapis.com/mcp";
|
|
161
|
+
const payload = {
|
|
162
|
+
method: "tools/call",
|
|
163
|
+
jsonrpc: "2.0",
|
|
164
|
+
params: {
|
|
165
|
+
name: "list_projects",
|
|
166
|
+
arguments: {}
|
|
167
|
+
},
|
|
168
|
+
id: 1
|
|
169
|
+
};
|
|
170
|
+
const response = await fetch(url, {
|
|
171
|
+
method: "POST",
|
|
172
|
+
headers: {
|
|
173
|
+
"Content-Type": "application/json",
|
|
174
|
+
Accept: "application/json, text/event-stream",
|
|
175
|
+
"X-Goog-Api-Key": input.apiKey
|
|
176
|
+
},
|
|
177
|
+
body: JSON.stringify(payload)
|
|
178
|
+
});
|
|
179
|
+
if (!response.ok) {
|
|
180
|
+
let errorDetails = "";
|
|
181
|
+
let errorMessage = `API request failed with status ${response.status}`;
|
|
182
|
+
try {
|
|
183
|
+
const errorBody = await response.json();
|
|
184
|
+
errorDetails = JSON.stringify(errorBody, null, 2);
|
|
185
|
+
if (errorBody?.error?.message) {
|
|
186
|
+
errorMessage = errorBody.error.message;
|
|
187
|
+
}
|
|
188
|
+
} catch {
|
|
189
|
+
try {
|
|
190
|
+
errorDetails = await response.text();
|
|
191
|
+
} catch {
|
|
192
|
+
errorDetails = `Status ${response.status}: ${response.statusText}`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
success: false,
|
|
197
|
+
error: {
|
|
198
|
+
code: response.status === 403 ? "PERMISSION_DENIED" : "CONNECTION_TEST_FAILED",
|
|
199
|
+
message: errorMessage,
|
|
200
|
+
suggestion: response.status === 403 ? "Check that your API key is valid and has access to the Stitch API" : "Verify API key configuration and try again",
|
|
201
|
+
recoverable: true,
|
|
202
|
+
details: errorDetails
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const data = await response.json();
|
|
207
|
+
return {
|
|
208
|
+
success: true,
|
|
209
|
+
data: {
|
|
210
|
+
connected: true,
|
|
211
|
+
statusCode: response.status,
|
|
212
|
+
url,
|
|
213
|
+
response: data
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
} catch (error) {
|
|
217
|
+
return {
|
|
218
|
+
success: false,
|
|
219
|
+
error: {
|
|
220
|
+
code: "CONNECTION_TEST_FAILED",
|
|
221
|
+
message: error instanceof Error ? error.message : String(error),
|
|
222
|
+
recoverable: false
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async testConnection(input) {
|
|
228
|
+
try {
|
|
229
|
+
const url = process.env.STITCH_HOST || "https://stitch.googleapis.com/mcp";
|
|
230
|
+
const payload = {
|
|
231
|
+
method: "tools/call",
|
|
232
|
+
jsonrpc: "2.0",
|
|
233
|
+
params: {
|
|
234
|
+
name: "list_projects",
|
|
235
|
+
arguments: {}
|
|
236
|
+
},
|
|
237
|
+
id: 1
|
|
238
|
+
};
|
|
239
|
+
const response = await fetch(url, {
|
|
240
|
+
method: "POST",
|
|
241
|
+
headers: {
|
|
242
|
+
"Content-Type": "application/json",
|
|
243
|
+
Accept: "application/json, text/event-stream",
|
|
244
|
+
Authorization: `Bearer ${input.accessToken}`,
|
|
245
|
+
"X-Goog-User-Project": input.projectId
|
|
246
|
+
},
|
|
247
|
+
body: JSON.stringify(payload)
|
|
248
|
+
});
|
|
249
|
+
if (!response.ok) {
|
|
250
|
+
let errorDetails = "";
|
|
251
|
+
let errorMessage = `API request failed with status ${response.status}`;
|
|
252
|
+
try {
|
|
253
|
+
const errorBody = await response.json();
|
|
254
|
+
errorDetails = JSON.stringify(errorBody, null, 2);
|
|
255
|
+
if (errorBody?.error?.message) {
|
|
256
|
+
errorMessage = errorBody.error.message;
|
|
257
|
+
}
|
|
258
|
+
} catch {
|
|
259
|
+
try {
|
|
260
|
+
errorDetails = await response.text();
|
|
261
|
+
} catch {
|
|
262
|
+
errorDetails = `Status ${response.status}: ${response.statusText}`;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
success: false,
|
|
267
|
+
error: {
|
|
268
|
+
code: response.status === 403 ? "PERMISSION_DENIED" : "CONNECTION_TEST_FAILED",
|
|
269
|
+
message: errorMessage,
|
|
270
|
+
suggestion: response.status === 403 ? "Check IAM permissions and ensure API is enabled" : "Verify project configuration and try again",
|
|
271
|
+
recoverable: true,
|
|
272
|
+
details: errorDetails
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const data = await response.json();
|
|
277
|
+
return {
|
|
278
|
+
success: true,
|
|
279
|
+
data: {
|
|
280
|
+
connected: true,
|
|
281
|
+
statusCode: response.status,
|
|
282
|
+
url,
|
|
283
|
+
response: data
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
} catch (error) {
|
|
287
|
+
return {
|
|
288
|
+
success: false,
|
|
289
|
+
error: {
|
|
290
|
+
code: "CONNECTION_TEST_FAILED",
|
|
291
|
+
message: error instanceof Error ? error.message : String(error),
|
|
292
|
+
recoverable: false
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/services/stitch/handler.ts
|
|
300
|
+
class StitchHandler {
|
|
301
|
+
executor;
|
|
302
|
+
iamService;
|
|
303
|
+
apiService;
|
|
304
|
+
connectionService;
|
|
305
|
+
constructor() {
|
|
306
|
+
this.executor = new GcloudExecutor;
|
|
307
|
+
this.iamService = new StitchIamService(this.executor);
|
|
308
|
+
this.apiService = new StitchApiService(this.executor);
|
|
309
|
+
this.connectionService = new StitchConnectionService;
|
|
310
|
+
}
|
|
311
|
+
async configureIAM(input) {
|
|
312
|
+
return this.iamService.configureIAM(input);
|
|
313
|
+
}
|
|
314
|
+
async enableAPI(input) {
|
|
315
|
+
return this.apiService.enableAPI(input);
|
|
316
|
+
}
|
|
317
|
+
async checkIAMRole(input) {
|
|
318
|
+
return this.iamService.checkIAMRole(input);
|
|
319
|
+
}
|
|
320
|
+
async checkAPIEnabled(input) {
|
|
321
|
+
return this.apiService.checkAPIEnabled(input);
|
|
322
|
+
}
|
|
323
|
+
async testConnectionWithApiKey(input) {
|
|
324
|
+
return this.connectionService.testConnectionWithApiKey(input);
|
|
325
|
+
}
|
|
326
|
+
async testConnection(input) {
|
|
327
|
+
return this.connectionService.testConnection(input);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// node_modules/ora/index.js
|
|
332
|
+
import process6 from "node:process";
|
|
333
|
+
|
|
334
|
+
// node_modules/ora/node_modules/cli-cursor/index.js
|
|
335
|
+
import process3 from "node:process";
|
|
336
|
+
|
|
337
|
+
// node_modules/ora/node_modules/cli-cursor/node_modules/restore-cursor/index.js
|
|
338
|
+
import process2 from "node:process";
|
|
339
|
+
|
|
340
|
+
// node_modules/mimic-function/index.js
|
|
341
|
+
var copyProperty = (to, from, property, ignoreNonConfigurable) => {
|
|
342
|
+
if (property === "length" || property === "prototype") {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (property === "arguments" || property === "caller") {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
|
|
349
|
+
const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
|
|
350
|
+
if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
Object.defineProperty(to, property, fromDescriptor);
|
|
354
|
+
};
|
|
355
|
+
var canCopyProperty = function(toDescriptor, fromDescriptor) {
|
|
356
|
+
return toDescriptor === undefined || toDescriptor.configurable || toDescriptor.writable === fromDescriptor.writable && toDescriptor.enumerable === fromDescriptor.enumerable && toDescriptor.configurable === fromDescriptor.configurable && (toDescriptor.writable || toDescriptor.value === fromDescriptor.value);
|
|
357
|
+
};
|
|
358
|
+
var changePrototype = (to, from) => {
|
|
359
|
+
const fromPrototype = Object.getPrototypeOf(from);
|
|
360
|
+
if (fromPrototype === Object.getPrototypeOf(to)) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
Object.setPrototypeOf(to, fromPrototype);
|
|
364
|
+
};
|
|
365
|
+
var wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/
|
|
366
|
+
${fromBody}`;
|
|
367
|
+
var toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, "toString");
|
|
368
|
+
var toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, "name");
|
|
369
|
+
var changeToString = (to, from, name) => {
|
|
370
|
+
const withName = name === "" ? "" : `with ${name.trim()}() `;
|
|
371
|
+
const newToString = wrappedToString.bind(null, withName, from.toString());
|
|
372
|
+
Object.defineProperty(newToString, "name", toStringName);
|
|
373
|
+
const { writable, enumerable, configurable } = toStringDescriptor;
|
|
374
|
+
Object.defineProperty(to, "toString", { value: newToString, writable, enumerable, configurable });
|
|
375
|
+
};
|
|
376
|
+
function mimicFunction(to, from, { ignoreNonConfigurable = false } = {}) {
|
|
377
|
+
const { name } = to;
|
|
378
|
+
for (const property of Reflect.ownKeys(from)) {
|
|
379
|
+
copyProperty(to, from, property, ignoreNonConfigurable);
|
|
380
|
+
}
|
|
381
|
+
changePrototype(to, from);
|
|
382
|
+
changeToString(to, from, name);
|
|
383
|
+
return to;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// node_modules/onetime/index.js
|
|
387
|
+
var calledFunctions = new WeakMap;
|
|
388
|
+
var onetime = (function_, options = {}) => {
|
|
389
|
+
if (typeof function_ !== "function") {
|
|
390
|
+
throw new TypeError("Expected a function");
|
|
391
|
+
}
|
|
392
|
+
let returnValue;
|
|
393
|
+
let callCount = 0;
|
|
394
|
+
const functionName = function_.displayName || function_.name || "<anonymous>";
|
|
395
|
+
const onetime2 = function(...arguments_) {
|
|
396
|
+
calledFunctions.set(onetime2, ++callCount);
|
|
397
|
+
if (callCount === 1) {
|
|
398
|
+
returnValue = function_.apply(this, arguments_);
|
|
399
|
+
function_ = undefined;
|
|
400
|
+
} else if (options.throw === true) {
|
|
401
|
+
throw new Error(`Function \`${functionName}\` can only be called once`);
|
|
402
|
+
}
|
|
403
|
+
return returnValue;
|
|
404
|
+
};
|
|
405
|
+
mimicFunction(onetime2, function_);
|
|
406
|
+
calledFunctions.set(onetime2, callCount);
|
|
407
|
+
return onetime2;
|
|
408
|
+
};
|
|
409
|
+
onetime.callCount = (function_) => {
|
|
410
|
+
if (!calledFunctions.has(function_)) {
|
|
411
|
+
throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
|
|
412
|
+
}
|
|
413
|
+
return calledFunctions.get(function_);
|
|
414
|
+
};
|
|
415
|
+
var onetime_default = onetime;
|
|
416
|
+
|
|
417
|
+
// node_modules/ora/node_modules/cli-cursor/node_modules/restore-cursor/index.js
|
|
418
|
+
var terminal = process2.stderr.isTTY ? process2.stderr : process2.stdout.isTTY ? process2.stdout : undefined;
|
|
419
|
+
var restoreCursor = terminal ? onetime_default(() => {
|
|
420
|
+
onExit(() => {
|
|
421
|
+
terminal.write("\x1B[?25h");
|
|
422
|
+
}, { alwaysLast: true });
|
|
423
|
+
}) : () => {};
|
|
424
|
+
var restore_cursor_default = restoreCursor;
|
|
425
|
+
|
|
426
|
+
// node_modules/ora/node_modules/cli-cursor/index.js
|
|
427
|
+
var isHidden = false;
|
|
428
|
+
var cliCursor = {};
|
|
429
|
+
cliCursor.show = (writableStream = process3.stderr) => {
|
|
430
|
+
if (!writableStream.isTTY) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
isHidden = false;
|
|
434
|
+
writableStream.write("\x1B[?25h");
|
|
435
|
+
};
|
|
436
|
+
cliCursor.hide = (writableStream = process3.stderr) => {
|
|
437
|
+
if (!writableStream.isTTY) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
restore_cursor_default();
|
|
441
|
+
isHidden = true;
|
|
442
|
+
writableStream.write("\x1B[?25l");
|
|
443
|
+
};
|
|
444
|
+
cliCursor.toggle = (force, writableStream) => {
|
|
445
|
+
if (force !== undefined) {
|
|
446
|
+
isHidden = force;
|
|
447
|
+
}
|
|
448
|
+
if (isHidden) {
|
|
449
|
+
cliCursor.show(writableStream);
|
|
450
|
+
} else {
|
|
451
|
+
cliCursor.hide(writableStream);
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
var cli_cursor_default = cliCursor;
|
|
455
|
+
|
|
456
|
+
// node_modules/ora/index.js
|
|
457
|
+
var import_cli_spinners = __toESM(require_cli_spinners(), 1);
|
|
458
|
+
|
|
459
|
+
// node_modules/ora/node_modules/log-symbols/node_modules/is-unicode-supported/index.js
|
|
460
|
+
import process4 from "node:process";
|
|
461
|
+
function isUnicodeSupported2() {
|
|
462
|
+
if (process4.platform !== "win32") {
|
|
463
|
+
return process4.env.TERM !== "linux";
|
|
464
|
+
}
|
|
465
|
+
return Boolean(process4.env.CI) || Boolean(process4.env.WT_SESSION) || Boolean(process4.env.TERMINUS_SUBLIME) || process4.env.ConEmuTask === "{cmd::Cmder}" || process4.env.TERM_PROGRAM === "Terminus-Sublime" || process4.env.TERM_PROGRAM === "vscode" || process4.env.TERM === "xterm-256color" || process4.env.TERM === "alacritty" || process4.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// node_modules/ora/node_modules/log-symbols/index.js
|
|
469
|
+
var main = {
|
|
470
|
+
info: source_default.blue("ℹ"),
|
|
471
|
+
success: source_default.green("✔"),
|
|
472
|
+
warning: source_default.yellow("⚠"),
|
|
473
|
+
error: source_default.red("✖")
|
|
474
|
+
};
|
|
475
|
+
var fallback = {
|
|
476
|
+
info: source_default.blue("i"),
|
|
477
|
+
success: source_default.green("√"),
|
|
478
|
+
warning: source_default.yellow("‼"),
|
|
479
|
+
error: source_default.red("×")
|
|
480
|
+
};
|
|
481
|
+
var logSymbols = isUnicodeSupported2() ? main : fallback;
|
|
482
|
+
var log_symbols_default = logSymbols;
|
|
483
|
+
|
|
484
|
+
// node_modules/ora/node_modules/string-width/index.js
|
|
485
|
+
var import_emoji_regex = __toESM(require_emoji_regex(), 1);
|
|
486
|
+
var segmenter = new Intl.Segmenter;
|
|
487
|
+
var defaultIgnorableCodePointRegex = /^\p{Default_Ignorable_Code_Point}$/u;
|
|
488
|
+
function stringWidth(string, options = {}) {
|
|
489
|
+
if (typeof string !== "string" || string.length === 0) {
|
|
490
|
+
return 0;
|
|
491
|
+
}
|
|
492
|
+
const {
|
|
493
|
+
ambiguousIsNarrow = true,
|
|
494
|
+
countAnsiEscapeCodes = false
|
|
495
|
+
} = options;
|
|
496
|
+
if (!countAnsiEscapeCodes) {
|
|
497
|
+
string = stripAnsi(string);
|
|
498
|
+
}
|
|
499
|
+
if (string.length === 0) {
|
|
500
|
+
return 0;
|
|
501
|
+
}
|
|
502
|
+
let width = 0;
|
|
503
|
+
const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
|
|
504
|
+
for (const { segment: character } of segmenter.segment(string)) {
|
|
505
|
+
const codePoint = character.codePointAt(0);
|
|
506
|
+
if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
if (codePoint >= 8203 && codePoint <= 8207 || codePoint === 65279) {
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
if (codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071) {
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (codePoint >= 55296 && codePoint <= 57343) {
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
if (codePoint >= 65024 && codePoint <= 65039) {
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
if (defaultIgnorableCodePointRegex.test(character)) {
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (import_emoji_regex.default().test(character)) {
|
|
525
|
+
width += 2;
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
529
|
+
}
|
|
530
|
+
return width;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// node_modules/is-interactive/index.js
|
|
534
|
+
function isInteractive({ stream = process.stdout } = {}) {
|
|
535
|
+
return Boolean(stream && stream.isTTY && process.env.TERM !== "dumb" && !("CI" in process.env));
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// node_modules/stdin-discarder/index.js
|
|
539
|
+
import process5 from "node:process";
|
|
540
|
+
var ASCII_ETX_CODE = 3;
|
|
541
|
+
|
|
542
|
+
class StdinDiscarder {
|
|
543
|
+
#activeCount = 0;
|
|
544
|
+
start() {
|
|
545
|
+
this.#activeCount++;
|
|
546
|
+
if (this.#activeCount === 1) {
|
|
547
|
+
this.#realStart();
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
stop() {
|
|
551
|
+
if (this.#activeCount <= 0) {
|
|
552
|
+
throw new Error("`stop` called more times than `start`");
|
|
553
|
+
}
|
|
554
|
+
this.#activeCount--;
|
|
555
|
+
if (this.#activeCount === 0) {
|
|
556
|
+
this.#realStop();
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
#realStart() {
|
|
560
|
+
if (process5.platform === "win32" || !process5.stdin.isTTY) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
process5.stdin.setRawMode(true);
|
|
564
|
+
process5.stdin.on("data", this.#handleInput);
|
|
565
|
+
process5.stdin.resume();
|
|
566
|
+
}
|
|
567
|
+
#realStop() {
|
|
568
|
+
if (!process5.stdin.isTTY) {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
process5.stdin.off("data", this.#handleInput);
|
|
572
|
+
process5.stdin.pause();
|
|
573
|
+
process5.stdin.setRawMode(false);
|
|
574
|
+
}
|
|
575
|
+
#handleInput(chunk) {
|
|
576
|
+
if (chunk[0] === ASCII_ETX_CODE) {
|
|
577
|
+
process5.emit("SIGINT");
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
var stdinDiscarder = new StdinDiscarder;
|
|
582
|
+
var stdin_discarder_default = stdinDiscarder;
|
|
583
|
+
|
|
584
|
+
// node_modules/ora/index.js
|
|
585
|
+
var import_cli_spinners2 = __toESM(require_cli_spinners(), 1);
|
|
586
|
+
|
|
587
|
+
class Ora {
|
|
588
|
+
#linesToClear = 0;
|
|
589
|
+
#isDiscardingStdin = false;
|
|
590
|
+
#lineCount = 0;
|
|
591
|
+
#frameIndex = -1;
|
|
592
|
+
#lastSpinnerFrameTime = 0;
|
|
593
|
+
#options;
|
|
594
|
+
#spinner;
|
|
595
|
+
#stream;
|
|
596
|
+
#id;
|
|
597
|
+
#initialInterval;
|
|
598
|
+
#isEnabled;
|
|
599
|
+
#isSilent;
|
|
600
|
+
#indent;
|
|
601
|
+
#text;
|
|
602
|
+
#prefixText;
|
|
603
|
+
#suffixText;
|
|
604
|
+
color;
|
|
605
|
+
constructor(options) {
|
|
606
|
+
if (typeof options === "string") {
|
|
607
|
+
options = {
|
|
608
|
+
text: options
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
this.#options = {
|
|
612
|
+
color: "cyan",
|
|
613
|
+
stream: process6.stderr,
|
|
614
|
+
discardStdin: true,
|
|
615
|
+
hideCursor: true,
|
|
616
|
+
...options
|
|
617
|
+
};
|
|
618
|
+
this.color = this.#options.color;
|
|
619
|
+
this.spinner = this.#options.spinner;
|
|
620
|
+
this.#initialInterval = this.#options.interval;
|
|
621
|
+
this.#stream = this.#options.stream;
|
|
622
|
+
this.#isEnabled = typeof this.#options.isEnabled === "boolean" ? this.#options.isEnabled : isInteractive({ stream: this.#stream });
|
|
623
|
+
this.#isSilent = typeof this.#options.isSilent === "boolean" ? this.#options.isSilent : false;
|
|
624
|
+
this.text = this.#options.text;
|
|
625
|
+
this.prefixText = this.#options.prefixText;
|
|
626
|
+
this.suffixText = this.#options.suffixText;
|
|
627
|
+
this.indent = this.#options.indent;
|
|
628
|
+
if (process6.env.NODE_ENV === "test") {
|
|
629
|
+
this._stream = this.#stream;
|
|
630
|
+
this._isEnabled = this.#isEnabled;
|
|
631
|
+
Object.defineProperty(this, "_linesToClear", {
|
|
632
|
+
get() {
|
|
633
|
+
return this.#linesToClear;
|
|
634
|
+
},
|
|
635
|
+
set(newValue) {
|
|
636
|
+
this.#linesToClear = newValue;
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
Object.defineProperty(this, "_frameIndex", {
|
|
640
|
+
get() {
|
|
641
|
+
return this.#frameIndex;
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
Object.defineProperty(this, "_lineCount", {
|
|
645
|
+
get() {
|
|
646
|
+
return this.#lineCount;
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
get indent() {
|
|
652
|
+
return this.#indent;
|
|
653
|
+
}
|
|
654
|
+
set indent(indent = 0) {
|
|
655
|
+
if (!(indent >= 0 && Number.isInteger(indent))) {
|
|
656
|
+
throw new Error("The `indent` option must be an integer from 0 and up");
|
|
657
|
+
}
|
|
658
|
+
this.#indent = indent;
|
|
659
|
+
this.#updateLineCount();
|
|
660
|
+
}
|
|
661
|
+
get interval() {
|
|
662
|
+
return this.#initialInterval ?? this.#spinner.interval ?? 100;
|
|
663
|
+
}
|
|
664
|
+
get spinner() {
|
|
665
|
+
return this.#spinner;
|
|
666
|
+
}
|
|
667
|
+
set spinner(spinner) {
|
|
668
|
+
this.#frameIndex = -1;
|
|
669
|
+
this.#initialInterval = undefined;
|
|
670
|
+
if (typeof spinner === "object") {
|
|
671
|
+
if (spinner.frames === undefined) {
|
|
672
|
+
throw new Error("The given spinner must have a `frames` property");
|
|
673
|
+
}
|
|
674
|
+
this.#spinner = spinner;
|
|
675
|
+
} else if (!isUnicodeSupported()) {
|
|
676
|
+
this.#spinner = import_cli_spinners.default.line;
|
|
677
|
+
} else if (spinner === undefined) {
|
|
678
|
+
this.#spinner = import_cli_spinners.default.dots;
|
|
679
|
+
} else if (spinner !== "default" && import_cli_spinners.default[spinner]) {
|
|
680
|
+
this.#spinner = import_cli_spinners.default[spinner];
|
|
681
|
+
} else {
|
|
682
|
+
throw new Error(`There is no built-in spinner named '${spinner}'. See https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json for a full list.`);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
get text() {
|
|
686
|
+
return this.#text;
|
|
687
|
+
}
|
|
688
|
+
set text(value = "") {
|
|
689
|
+
this.#text = value;
|
|
690
|
+
this.#updateLineCount();
|
|
691
|
+
}
|
|
692
|
+
get prefixText() {
|
|
693
|
+
return this.#prefixText;
|
|
694
|
+
}
|
|
695
|
+
set prefixText(value = "") {
|
|
696
|
+
this.#prefixText = value;
|
|
697
|
+
this.#updateLineCount();
|
|
698
|
+
}
|
|
699
|
+
get suffixText() {
|
|
700
|
+
return this.#suffixText;
|
|
701
|
+
}
|
|
702
|
+
set suffixText(value = "") {
|
|
703
|
+
this.#suffixText = value;
|
|
704
|
+
this.#updateLineCount();
|
|
705
|
+
}
|
|
706
|
+
get isSpinning() {
|
|
707
|
+
return this.#id !== undefined;
|
|
708
|
+
}
|
|
709
|
+
#getFullPrefixText(prefixText = this.#prefixText, postfix = " ") {
|
|
710
|
+
if (typeof prefixText === "string" && prefixText !== "") {
|
|
711
|
+
return prefixText + postfix;
|
|
712
|
+
}
|
|
713
|
+
if (typeof prefixText === "function") {
|
|
714
|
+
return prefixText() + postfix;
|
|
715
|
+
}
|
|
716
|
+
return "";
|
|
717
|
+
}
|
|
718
|
+
#getFullSuffixText(suffixText = this.#suffixText, prefix = " ") {
|
|
719
|
+
if (typeof suffixText === "string" && suffixText !== "") {
|
|
720
|
+
return prefix + suffixText;
|
|
721
|
+
}
|
|
722
|
+
if (typeof suffixText === "function") {
|
|
723
|
+
return prefix + suffixText();
|
|
724
|
+
}
|
|
725
|
+
return "";
|
|
726
|
+
}
|
|
727
|
+
#updateLineCount() {
|
|
728
|
+
const columns = this.#stream.columns ?? 80;
|
|
729
|
+
const fullPrefixText = this.#getFullPrefixText(this.#prefixText, "-");
|
|
730
|
+
const fullSuffixText = this.#getFullSuffixText(this.#suffixText, "-");
|
|
731
|
+
const fullText = " ".repeat(this.#indent) + fullPrefixText + "--" + this.#text + "--" + fullSuffixText;
|
|
732
|
+
this.#lineCount = 0;
|
|
733
|
+
for (const line of stripAnsi(fullText).split(`
|
|
734
|
+
`)) {
|
|
735
|
+
this.#lineCount += Math.max(1, Math.ceil(stringWidth(line, { countAnsiEscapeCodes: true }) / columns));
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
get isEnabled() {
|
|
739
|
+
return this.#isEnabled && !this.#isSilent;
|
|
740
|
+
}
|
|
741
|
+
set isEnabled(value) {
|
|
742
|
+
if (typeof value !== "boolean") {
|
|
743
|
+
throw new TypeError("The `isEnabled` option must be a boolean");
|
|
744
|
+
}
|
|
745
|
+
this.#isEnabled = value;
|
|
746
|
+
}
|
|
747
|
+
get isSilent() {
|
|
748
|
+
return this.#isSilent;
|
|
749
|
+
}
|
|
750
|
+
set isSilent(value) {
|
|
751
|
+
if (typeof value !== "boolean") {
|
|
752
|
+
throw new TypeError("The `isSilent` option must be a boolean");
|
|
753
|
+
}
|
|
754
|
+
this.#isSilent = value;
|
|
755
|
+
}
|
|
756
|
+
frame() {
|
|
757
|
+
const now = Date.now();
|
|
758
|
+
if (this.#frameIndex === -1 || now - this.#lastSpinnerFrameTime >= this.interval) {
|
|
759
|
+
this.#frameIndex = ++this.#frameIndex % this.#spinner.frames.length;
|
|
760
|
+
this.#lastSpinnerFrameTime = now;
|
|
761
|
+
}
|
|
762
|
+
const { frames } = this.#spinner;
|
|
763
|
+
let frame = frames[this.#frameIndex];
|
|
764
|
+
if (this.color) {
|
|
765
|
+
frame = source_default[this.color](frame);
|
|
766
|
+
}
|
|
767
|
+
const fullPrefixText = typeof this.#prefixText === "string" && this.#prefixText !== "" ? this.#prefixText + " " : "";
|
|
768
|
+
const fullText = typeof this.text === "string" ? " " + this.text : "";
|
|
769
|
+
const fullSuffixText = typeof this.#suffixText === "string" && this.#suffixText !== "" ? " " + this.#suffixText : "";
|
|
770
|
+
return fullPrefixText + frame + fullText + fullSuffixText;
|
|
771
|
+
}
|
|
772
|
+
clear() {
|
|
773
|
+
if (!this.#isEnabled || !this.#stream.isTTY) {
|
|
774
|
+
return this;
|
|
775
|
+
}
|
|
776
|
+
this.#stream.cursorTo(0);
|
|
777
|
+
for (let index = 0;index < this.#linesToClear; index++) {
|
|
778
|
+
if (index > 0) {
|
|
779
|
+
this.#stream.moveCursor(0, -1);
|
|
780
|
+
}
|
|
781
|
+
this.#stream.clearLine(1);
|
|
782
|
+
}
|
|
783
|
+
if (this.#indent || this.lastIndent !== this.#indent) {
|
|
784
|
+
this.#stream.cursorTo(this.#indent);
|
|
785
|
+
}
|
|
786
|
+
this.lastIndent = this.#indent;
|
|
787
|
+
this.#linesToClear = 0;
|
|
788
|
+
return this;
|
|
789
|
+
}
|
|
790
|
+
render() {
|
|
791
|
+
if (this.#isSilent) {
|
|
792
|
+
return this;
|
|
793
|
+
}
|
|
794
|
+
this.clear();
|
|
795
|
+
this.#stream.write(this.frame());
|
|
796
|
+
this.#linesToClear = this.#lineCount;
|
|
797
|
+
return this;
|
|
798
|
+
}
|
|
799
|
+
start(text) {
|
|
800
|
+
if (text) {
|
|
801
|
+
this.text = text;
|
|
802
|
+
}
|
|
803
|
+
if (this.#isSilent) {
|
|
804
|
+
return this;
|
|
805
|
+
}
|
|
806
|
+
if (!this.#isEnabled) {
|
|
807
|
+
if (this.text) {
|
|
808
|
+
this.#stream.write(`- ${this.text}
|
|
809
|
+
`);
|
|
810
|
+
}
|
|
811
|
+
return this;
|
|
812
|
+
}
|
|
813
|
+
if (this.isSpinning) {
|
|
814
|
+
return this;
|
|
815
|
+
}
|
|
816
|
+
if (this.#options.hideCursor) {
|
|
817
|
+
cli_cursor_default.hide(this.#stream);
|
|
818
|
+
}
|
|
819
|
+
if (this.#options.discardStdin && process6.stdin.isTTY) {
|
|
820
|
+
this.#isDiscardingStdin = true;
|
|
821
|
+
stdin_discarder_default.start();
|
|
822
|
+
}
|
|
823
|
+
this.render();
|
|
824
|
+
this.#id = setInterval(this.render.bind(this), this.interval);
|
|
825
|
+
return this;
|
|
826
|
+
}
|
|
827
|
+
stop() {
|
|
828
|
+
if (!this.#isEnabled) {
|
|
829
|
+
return this;
|
|
830
|
+
}
|
|
831
|
+
clearInterval(this.#id);
|
|
832
|
+
this.#id = undefined;
|
|
833
|
+
this.#frameIndex = 0;
|
|
834
|
+
this.clear();
|
|
835
|
+
if (this.#options.hideCursor) {
|
|
836
|
+
cli_cursor_default.show(this.#stream);
|
|
837
|
+
}
|
|
838
|
+
if (this.#options.discardStdin && process6.stdin.isTTY && this.#isDiscardingStdin) {
|
|
839
|
+
stdin_discarder_default.stop();
|
|
840
|
+
this.#isDiscardingStdin = false;
|
|
841
|
+
}
|
|
842
|
+
return this;
|
|
843
|
+
}
|
|
844
|
+
succeed(text) {
|
|
845
|
+
return this.stopAndPersist({ symbol: log_symbols_default.success, text });
|
|
846
|
+
}
|
|
847
|
+
fail(text) {
|
|
848
|
+
return this.stopAndPersist({ symbol: log_symbols_default.error, text });
|
|
849
|
+
}
|
|
850
|
+
warn(text) {
|
|
851
|
+
return this.stopAndPersist({ symbol: log_symbols_default.warning, text });
|
|
852
|
+
}
|
|
853
|
+
info(text) {
|
|
854
|
+
return this.stopAndPersist({ symbol: log_symbols_default.info, text });
|
|
855
|
+
}
|
|
856
|
+
stopAndPersist(options = {}) {
|
|
857
|
+
if (this.#isSilent) {
|
|
858
|
+
return this;
|
|
859
|
+
}
|
|
860
|
+
const prefixText = options.prefixText ?? this.#prefixText;
|
|
861
|
+
const fullPrefixText = this.#getFullPrefixText(prefixText, " ");
|
|
862
|
+
const symbolText = options.symbol ?? " ";
|
|
863
|
+
const text = options.text ?? this.text;
|
|
864
|
+
const separatorText = symbolText ? " " : "";
|
|
865
|
+
const fullText = typeof text === "string" ? separatorText + text : "";
|
|
866
|
+
const suffixText = options.suffixText ?? this.#suffixText;
|
|
867
|
+
const fullSuffixText = this.#getFullSuffixText(suffixText, " ");
|
|
868
|
+
const textToWrite = fullPrefixText + symbolText + fullText + fullSuffixText + `
|
|
869
|
+
`;
|
|
870
|
+
this.stop();
|
|
871
|
+
this.#stream.write(textToWrite);
|
|
872
|
+
return this;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
function ora(options) {
|
|
876
|
+
return new Ora(options);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
// src/ui/spinner.ts
|
|
880
|
+
class Spinner {
|
|
881
|
+
spinner = null;
|
|
882
|
+
start(message) {
|
|
883
|
+
this.spinner = ora({
|
|
884
|
+
text: message,
|
|
885
|
+
color: "blue",
|
|
886
|
+
spinner: "dots"
|
|
887
|
+
}).start();
|
|
888
|
+
}
|
|
889
|
+
succeed(message) {
|
|
890
|
+
if (this.spinner) {
|
|
891
|
+
this.spinner.succeed(message);
|
|
892
|
+
this.spinner = null;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
fail(message) {
|
|
896
|
+
if (this.spinner) {
|
|
897
|
+
this.spinner.fail(message);
|
|
898
|
+
this.spinner = null;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
stop() {
|
|
902
|
+
if (this.spinner) {
|
|
903
|
+
this.spinner.stop();
|
|
904
|
+
this.spinner = null;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
function createSpinner() {
|
|
909
|
+
return new Spinner;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
export { StitchHandler, createSpinner };
|
|
913
|
+
|
|
914
|
+
//# debugId=97879FD05296F9BA64756E2164756E21
|