pcific 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +50 -2
- package/dist/SKILL.md +127 -0
- package/dist/api/catalog.js +637 -0
- package/dist/api/run.js +960 -0
- package/dist/api/search.js +171 -0
- package/dist/api/shortcuts.js +799 -0
- package/dist/bin.js +648 -0
- package/dist/commands/auth.js +513 -0
- package/dist/commands/doctor.js +410 -0
- package/dist/commands/init.js +306 -0
- package/dist/commands/sync.js +214 -0
- package/dist/detect.js +214 -0
- package/dist/env.js +339 -0
- package/dist/goLive.js +629 -0
- package/dist/keyLink.js +305 -0
- package/dist/mcp/server.js +206 -0
- package/dist/mcp/tools.js +689 -0
- package/dist/python/template.js +793 -0
- package/dist/schema/discover.js +324 -0
- package/dist/schema/helpers.js +396 -0
- package/dist/schema/prismaToJsonSchema.js +197 -0
- package/dist/schema/push.js +570 -0
- package/dist/schema/tsToJsonSchema.js +405 -0
- package/dist/schema/zodToJsonSchema.js +442 -0
- package/dist/templates/openapi.json +1 -0
- package/dist/templates/sdk/auth.ts +139 -0
- package/dist/templates/sdk/client.ts +1059 -0
- package/dist/templates/sdk/errors.ts +76 -0
- package/dist/templates/sdk/generated-types.ts +5746 -0
- package/dist/templates/sdk/http.ts +359 -0
- package/dist/templates/sdk/index.ts +84 -0
- package/dist/templates/sdk/json.ts +24 -0
- package/dist/templates/sdk/kit.ts +516 -0
- package/dist/templates/sdk/multipart.ts +99 -0
- package/dist/templates/sdk/sse.ts +131 -0
- package/dist/templates/sdk/verify.ts +766 -0
- package/dist/templates/sdk-js/auth.d.ts +20 -0
- package/dist/templates/sdk-js/auth.js +85 -0
- package/dist/templates/sdk-js/client.d.ts +324 -0
- package/dist/templates/sdk-js/client.js +607 -0
- package/dist/templates/sdk-js/errors.d.ts +51 -0
- package/dist/templates/sdk-js/errors.js +48 -0
- package/dist/templates/sdk-js/generated-types.d.ts +5736 -0
- package/dist/templates/sdk-js/generated-types.js +5 -0
- package/dist/templates/sdk-js/http.d.ts +50 -0
- package/dist/templates/sdk-js/http.js +263 -0
- package/dist/templates/sdk-js/index.d.ts +9 -0
- package/dist/templates/sdk-js/index.js +7 -0
- package/dist/templates/sdk-js/json.d.ts +11 -0
- package/dist/templates/sdk-js/json.js +16 -0
- package/dist/templates/sdk-js/kit.d.ts +220 -0
- package/dist/templates/sdk-js/kit.js +208 -0
- package/dist/templates/sdk-js/multipart.d.ts +23 -0
- package/dist/templates/sdk-js/multipart.js +61 -0
- package/dist/templates/sdk-js/sse.d.ts +12 -0
- package/dist/templates/sdk-js/sse.js +99 -0
- package/dist/templates/sdk-js/verify.d.ts +114 -0
- package/dist/templates/sdk-js/verify.js +506 -0
- package/dist/templates.js +925 -0
- package/dist/ui.js +399 -0
- package/dist/webhooks/events.js +171 -0
- package/dist/webhooks/listen.js +772 -0
- package/package.json +32 -4
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { detectProject } from "../detect.js";
|
|
4
|
+
import { CliError, resolveCliConfig } from "../env.js";
|
|
5
|
+
import { readPcificGenerationMeta } from "../templates.js";
|
|
6
|
+
function isJsonObject(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
function isString(value) {
|
|
10
|
+
return typeof value === "string";
|
|
11
|
+
}
|
|
12
|
+
function isNumber(value) {
|
|
13
|
+
return typeof value === "number";
|
|
14
|
+
}
|
|
15
|
+
function checkGitignoreStatus(cwd) {
|
|
16
|
+
const gitignorePath = path.join(cwd, ".gitignore");
|
|
17
|
+
if (!existsSync(gitignorePath)) {
|
|
18
|
+
return {
|
|
19
|
+
id: "gitignore",
|
|
20
|
+
label: ".gitignore",
|
|
21
|
+
status: "warn",
|
|
22
|
+
detail: "No .gitignore file found to protect .env.",
|
|
23
|
+
tryThis: "Create a .gitignore file containing .env, or run npx pcific init.",
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const content = readFileSync(gitignorePath, "utf8");
|
|
27
|
+
let ignored = false;
|
|
28
|
+
for (const rawLine of content.split(/\r?\n/)) {
|
|
29
|
+
const line = rawLine.trim();
|
|
30
|
+
if (!line || line.startsWith("#"))
|
|
31
|
+
continue;
|
|
32
|
+
if (line === "!.env" || line === "!/.env") {
|
|
33
|
+
ignored = false;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (line === ".env" ||
|
|
37
|
+
line === "/.env" ||
|
|
38
|
+
line === "**/.env" ||
|
|
39
|
+
line === ".env*" ||
|
|
40
|
+
line === "/.env*" ||
|
|
41
|
+
line === "*.env") {
|
|
42
|
+
ignored = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!ignored) {
|
|
46
|
+
return {
|
|
47
|
+
id: "gitignore",
|
|
48
|
+
label: ".gitignore",
|
|
49
|
+
status: "warn",
|
|
50
|
+
detail: ".env is not ignored in .gitignore.",
|
|
51
|
+
tryThis: "Add .env to .gitignore so your API key is never committed.",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
id: "gitignore",
|
|
56
|
+
label: ".gitignore",
|
|
57
|
+
status: "pass",
|
|
58
|
+
detail: ".env is ignored in .gitignore.",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function makeApiHeaders(config) {
|
|
62
|
+
return {
|
|
63
|
+
accept: "application/json",
|
|
64
|
+
authorization: `Bearer ${config.testKey ?? ""}`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function withMarketplaceQuery(url, marketplaceId) {
|
|
68
|
+
if (!marketplaceId)
|
|
69
|
+
return url;
|
|
70
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
71
|
+
return `${url}${separator}marketplaceId=${encodeURIComponent(marketplaceId)}`;
|
|
72
|
+
}
|
|
73
|
+
async function fetchJsonEndpoint(fetchImpl, url, headers) {
|
|
74
|
+
try {
|
|
75
|
+
const requestHeaders = new Headers({
|
|
76
|
+
accept: headers.accept,
|
|
77
|
+
authorization: headers.authorization,
|
|
78
|
+
});
|
|
79
|
+
const response = await fetchImpl(url, { method: "GET", headers: requestHeaders });
|
|
80
|
+
const text = await response.text();
|
|
81
|
+
let parsedObj = null;
|
|
82
|
+
if (text.trim().startsWith("{")) {
|
|
83
|
+
try {
|
|
84
|
+
// SAFETY: JSON.parse returns JSON values matching CliJsonValue.
|
|
85
|
+
const parsed = JSON.parse(text);
|
|
86
|
+
if (isJsonObject(parsed)) {
|
|
87
|
+
parsedObj = parsed;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// Non-JSON payload handled below.
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
return {
|
|
96
|
+
ok: false,
|
|
97
|
+
status: response.status,
|
|
98
|
+
body: parsedObj,
|
|
99
|
+
errorText: parsedObj && isString(parsedObj.error) ? parsedObj.error : `HTTP ${response.status}`,
|
|
100
|
+
tryThis: parsedObj && isString(parsedObj.tryThis) ? parsedObj.tryThis : undefined,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return { ok: true, status: response.status, body: parsedObj };
|
|
104
|
+
}
|
|
105
|
+
catch (failure) {
|
|
106
|
+
const message = failure instanceof Error ? failure.message : "Network request failed.";
|
|
107
|
+
return {
|
|
108
|
+
ok: false,
|
|
109
|
+
status: 0,
|
|
110
|
+
body: null,
|
|
111
|
+
errorText: message,
|
|
112
|
+
tryThis: "Check your internet connection and PCIFIC_BASE_URL, then retry npx pcific doctor.",
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export async function verifyTestKey(options) {
|
|
117
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
118
|
+
const headers = {
|
|
119
|
+
accept: "application/json",
|
|
120
|
+
authorization: `Bearer ${options.testKey}`,
|
|
121
|
+
};
|
|
122
|
+
const res = await fetchJsonEndpoint(fetchImpl, `${options.baseUrl}/api/v1/key`, headers);
|
|
123
|
+
if (!res.ok) {
|
|
124
|
+
return { valid: false, error: res.errorText };
|
|
125
|
+
}
|
|
126
|
+
const body = res.body;
|
|
127
|
+
const name = body && isString(body.name) ? body.name : undefined;
|
|
128
|
+
const kind = body && isString(body.kind) ? body.kind : undefined;
|
|
129
|
+
const marketplaceRaw = body && isJsonObject(body.marketplace) ? body.marketplace : undefined;
|
|
130
|
+
const marketplaceName = marketplaceRaw && isString(marketplaceRaw.name) ? marketplaceRaw.name : undefined;
|
|
131
|
+
const rawCan = body?.can;
|
|
132
|
+
const can = [];
|
|
133
|
+
if (Array.isArray(rawCan)) {
|
|
134
|
+
for (const item of rawCan) {
|
|
135
|
+
if (isString(item))
|
|
136
|
+
can.push(item);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return { valid: true, name, kind, can, marketplaceName };
|
|
140
|
+
}
|
|
141
|
+
export async function runDoctor(options) {
|
|
142
|
+
const { cwd, ui } = options;
|
|
143
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
144
|
+
const checks = [];
|
|
145
|
+
if (!options.suppressHeader) {
|
|
146
|
+
ui.header("Doctor", "Checking local setup and PCIFIC API connectivity");
|
|
147
|
+
}
|
|
148
|
+
let config = null;
|
|
149
|
+
try {
|
|
150
|
+
config = resolveCliConfig(cwd, { baseUrl: options.baseUrl, env: options.env });
|
|
151
|
+
}
|
|
152
|
+
catch (failure) {
|
|
153
|
+
const cliErr = failure instanceof CliError
|
|
154
|
+
? failure
|
|
155
|
+
: new CliError(failure instanceof Error ? failure.message : "Invalid configuration.", {
|
|
156
|
+
tryThis: "Check .env and environment variables, then retry npx pcific doctor.",
|
|
157
|
+
});
|
|
158
|
+
checks.push({
|
|
159
|
+
id: "config",
|
|
160
|
+
label: "Key safety",
|
|
161
|
+
status: "fail",
|
|
162
|
+
detail: cliErr.message,
|
|
163
|
+
tryThis: cliErr.tryThis,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
checks.push(checkGitignoreStatus(cwd));
|
|
167
|
+
if (config) {
|
|
168
|
+
if (config.mode === "live") {
|
|
169
|
+
checks.push({
|
|
170
|
+
id: "mode",
|
|
171
|
+
label: "CLI mode",
|
|
172
|
+
status: "warn",
|
|
173
|
+
detail: 'PCIFIC_MODE is set to "live" locally. CLI commands always use test keys only.',
|
|
174
|
+
tryThis: 'Set PCIFIC_MODE=test in your local .env and reserve PCIFIC_MODE=live for production.',
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
checks.push({
|
|
179
|
+
id: "mode",
|
|
180
|
+
label: "Key safety",
|
|
181
|
+
status: "pass",
|
|
182
|
+
detail: "Test mode active; no live key used by CLI.",
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
if (config.liveKeyPresent) {
|
|
186
|
+
checks.push({
|
|
187
|
+
id: "live-key",
|
|
188
|
+
label: "PCIFIC_LIVE_KEY",
|
|
189
|
+
status: "warn",
|
|
190
|
+
detail: "PCIFIC_LIVE_KEY is present in your local environment or .env. CLI tools never use live keys.",
|
|
191
|
+
tryThis: "Remove PCIFIC_LIVE_KEY from local .env and store it only in your production deployment secrets.",
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (!config.envFileExists && !config.testKey) {
|
|
195
|
+
checks.push({
|
|
196
|
+
id: "env",
|
|
197
|
+
label: ".env file",
|
|
198
|
+
status: "fail",
|
|
199
|
+
detail: "No .env file and no PCIFIC_TEST_KEY in environment.",
|
|
200
|
+
tryThis: "Run npx pcific init to link a test key into .env.",
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
else if (!config.testKey) {
|
|
204
|
+
checks.push({
|
|
205
|
+
id: "env",
|
|
206
|
+
label: "PCIFIC_TEST_KEY",
|
|
207
|
+
status: "fail",
|
|
208
|
+
detail: ".env exists but PCIFIC_TEST_KEY is missing.",
|
|
209
|
+
tryThis: "Run npx pcific init to link a test key into .env.",
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
checks.push({
|
|
214
|
+
id: "env",
|
|
215
|
+
label: "PCIFIC_TEST_KEY",
|
|
216
|
+
status: "pass",
|
|
217
|
+
detail: `Loaded test key from ${config.testKeySource ?? ".env"}.`,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const project = detectProject(cwd);
|
|
222
|
+
const meta = readPcificGenerationMeta(cwd, project);
|
|
223
|
+
if (meta?.mode === "copy") {
|
|
224
|
+
const target = meta.targetDir ?? project.existingCopyDir ?? "pcific";
|
|
225
|
+
checks.push({
|
|
226
|
+
id: "local-files",
|
|
227
|
+
label: "Local SDK files",
|
|
228
|
+
status: "pass",
|
|
229
|
+
detail: `Copy mode detected at ${target}${meta.date ? ` (generated ${meta.date})` : ""}.`,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
else if (meta?.mode === "package" || project.existingMode === "package") {
|
|
233
|
+
checks.push({
|
|
234
|
+
id: "local-files",
|
|
235
|
+
label: "Local SDK package",
|
|
236
|
+
status: "pass",
|
|
237
|
+
detail: "Package mode detected (@pcific/sdk).",
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
checks.push({
|
|
242
|
+
id: "local-files",
|
|
243
|
+
label: "Local SDK setup",
|
|
244
|
+
status: "warn",
|
|
245
|
+
detail: "No generated PCIFIC client files or @pcific/sdk dependency found yet.",
|
|
246
|
+
tryThis: "Run npx pcific init to scaffold your client and PCIFIC.md.",
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
if (config?.testKey) {
|
|
250
|
+
const headers = makeApiHeaders(config);
|
|
251
|
+
const keyRes = await fetchJsonEndpoint(fetchImpl, `${config.baseUrl}/api/v1/key`, headers);
|
|
252
|
+
if (keyRes.ok) {
|
|
253
|
+
const name = keyRes.body && isString(keyRes.body.name) ? keyRes.body.name : "Test key";
|
|
254
|
+
const kind = keyRes.body && isString(keyRes.body.kind) ? keyRes.body.kind : "test";
|
|
255
|
+
const canList = Array.isArray(keyRes.body?.can)
|
|
256
|
+
? keyRes.body.can.filter((entry) => isString(entry))
|
|
257
|
+
: [];
|
|
258
|
+
const permSuffix = canList.length > 0 ? `, ${canList.length} permissions` : "";
|
|
259
|
+
checks.push({
|
|
260
|
+
id: "api-key",
|
|
261
|
+
label: "GET /api/v1/key",
|
|
262
|
+
status: "pass",
|
|
263
|
+
detail: `Authenticated (${name}, ${kind} key${permSuffix}).`,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
checks.push({
|
|
268
|
+
id: "api-key",
|
|
269
|
+
label: "GET /api/v1/key",
|
|
270
|
+
status: "fail",
|
|
271
|
+
detail: keyRes.errorText ?? "API key check failed.",
|
|
272
|
+
tryThis: keyRes.tryThis ?? "Run npx pcific init --reauth to link a fresh test key.",
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
const usageUrl = withMarketplaceQuery(`${config.baseUrl}/api/v1/usage`, config.marketplaceId);
|
|
276
|
+
const usageRes = await fetchJsonEndpoint(fetchImpl, usageUrl, headers);
|
|
277
|
+
if (usageRes.ok) {
|
|
278
|
+
checks.push({
|
|
279
|
+
id: "api-usage",
|
|
280
|
+
label: "GET /api/v1/usage",
|
|
281
|
+
status: "pass",
|
|
282
|
+
detail: "Usage endpoint reachable.",
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
else if (usageRes.status === 403) {
|
|
286
|
+
checks.push({
|
|
287
|
+
id: "api-usage",
|
|
288
|
+
label: "GET /api/v1/usage",
|
|
289
|
+
status: "warn",
|
|
290
|
+
detail: "Key does not have read permission for usage metrics.",
|
|
291
|
+
tryThis: 'Include the "read" permission when linking a key or run npx pcific init --reauth.',
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
checks.push({
|
|
296
|
+
id: "api-usage",
|
|
297
|
+
label: "GET /api/v1/usage",
|
|
298
|
+
status: "fail",
|
|
299
|
+
detail: usageRes.errorText ?? "Could not fetch usage.",
|
|
300
|
+
tryThis: usageRes.tryThis ?? "Check your PCIFIC connection and retry npx pcific doctor.",
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
const catalogueUrl = withMarketplaceQuery(`${config.baseUrl}/api/v1/catalogue/status`, config.marketplaceId);
|
|
304
|
+
const catalogueRes = await fetchJsonEndpoint(fetchImpl, catalogueUrl, headers);
|
|
305
|
+
if (catalogueRes.ok) {
|
|
306
|
+
const catalogueObj = isJsonObject(catalogueRes.body?.catalogue)
|
|
307
|
+
? catalogueRes.body.catalogue
|
|
308
|
+
: null;
|
|
309
|
+
const catStatus = catalogueObj && isString(catalogueObj.status) ? catalogueObj.status : "none";
|
|
310
|
+
if (catStatus === "published") {
|
|
311
|
+
const version = isNumber(catalogueObj?.version) ? `v${catalogueObj.version}` : null;
|
|
312
|
+
const entryCount = isNumber(catalogueObj?.entryCount)
|
|
313
|
+
? `${catalogueObj.entryCount} ${catalogueObj.entryCount === 1 ? "category" : "categories"}`
|
|
314
|
+
: null;
|
|
315
|
+
const summary = [version, entryCount].filter(Boolean).join(", ");
|
|
316
|
+
checks.push({
|
|
317
|
+
id: "api-catalogue",
|
|
318
|
+
label: "GET /api/v1/catalogue/status",
|
|
319
|
+
status: "pass",
|
|
320
|
+
detail: summary ? `Published (${summary}).` : "Published.",
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
else if (catStatus === "none") {
|
|
324
|
+
checks.push({
|
|
325
|
+
id: "api-catalogue",
|
|
326
|
+
label: "GET /api/v1/catalogue/status",
|
|
327
|
+
status: "warn",
|
|
328
|
+
detail: "No listing field schema published yet.",
|
|
329
|
+
tryThis: "Run npx pcific schema push --publish to upload and publish your listing fields.",
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
checks.push({
|
|
334
|
+
id: "api-catalogue",
|
|
335
|
+
label: "GET /api/v1/catalogue/status",
|
|
336
|
+
status: "warn",
|
|
337
|
+
detail: `Catalogue status: ${catStatus}.`,
|
|
338
|
+
tryThis: "Run npx pcific schema push --publish to upload and publish your listing fields.",
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
else if (catalogueRes.status === 404) {
|
|
343
|
+
checks.push({
|
|
344
|
+
id: "api-catalogue",
|
|
345
|
+
label: "GET /api/v1/catalogue/status",
|
|
346
|
+
status: "warn",
|
|
347
|
+
detail: "No listing field schema uploaded yet.",
|
|
348
|
+
tryThis: "Run npx pcific schema push --publish to upload and publish your listing fields.",
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
else if (catalogueRes.status === 403) {
|
|
352
|
+
checks.push({
|
|
353
|
+
id: "api-catalogue",
|
|
354
|
+
label: "GET /api/v1/catalogue/status",
|
|
355
|
+
status: "warn",
|
|
356
|
+
detail: "Key lacks permission to inspect catalogue status.",
|
|
357
|
+
tryThis: 'Enable "read" or "listing-fields" scope on your test key.',
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
checks.push({
|
|
362
|
+
id: "api-catalogue",
|
|
363
|
+
label: "GET /api/v1/catalogue/status",
|
|
364
|
+
status: "fail",
|
|
365
|
+
detail: catalogueRes.errorText ?? "Could not fetch catalogue status.",
|
|
366
|
+
tryThis: catalogueRes.tryThis ?? "Check your PCIFIC connection and retry npx pcific doctor.",
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
for (const check of checks) {
|
|
371
|
+
if (check.status === "pass") {
|
|
372
|
+
ui.ok(`${check.label}: ${check.detail}`);
|
|
373
|
+
}
|
|
374
|
+
else if (check.status === "warn") {
|
|
375
|
+
ui.warn(`${check.label}: ${check.detail}`);
|
|
376
|
+
if (check.tryThis) {
|
|
377
|
+
ui.info(` Next: ${check.tryThis}`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
ui.error(`${check.label}: ${check.detail}`, check.tryThis);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const hasFailure = checks.some((check) => check.status === "fail");
|
|
385
|
+
const result = {
|
|
386
|
+
ok: !hasFailure,
|
|
387
|
+
exitCode: hasFailure ? 1 : 0,
|
|
388
|
+
checks,
|
|
389
|
+
};
|
|
390
|
+
if (ui.json && !options.suppressJson) {
|
|
391
|
+
ui.emitJson({
|
|
392
|
+
command: "doctor",
|
|
393
|
+
ok: result.ok,
|
|
394
|
+
baseUrl: config?.baseUrl ?? null,
|
|
395
|
+
checks: checks.map((check) => {
|
|
396
|
+
const entry = {
|
|
397
|
+
id: check.id,
|
|
398
|
+
label: check.label,
|
|
399
|
+
status: check.status,
|
|
400
|
+
detail: check.detail,
|
|
401
|
+
};
|
|
402
|
+
if (check.tryThis) {
|
|
403
|
+
entry.tryThis = check.tryThis;
|
|
404
|
+
}
|
|
405
|
+
return entry;
|
|
406
|
+
}),
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
return result;
|
|
410
|
+
}
|