pingcode-cli-unofficial 2.2.0 → 2.3.1
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 +63 -17
- package/dist/bin/pingcode.js +479 -164
- package/dist/bin/pingcode.js.map +1 -1
- package/package.json +3 -1
- package/skills/pingcode/SKILL.md +19 -0
- package/skills/pingcode/modules/api.md +11 -8
package/dist/bin/pingcode.js
CHANGED
|
@@ -978,7 +978,7 @@ var require_command = __commonJS({
|
|
|
978
978
|
"use strict";
|
|
979
979
|
var EventEmitter = __require("events").EventEmitter;
|
|
980
980
|
var childProcess = __require("child_process");
|
|
981
|
-
var
|
|
981
|
+
var path12 = __require("path");
|
|
982
982
|
var fs = __require("fs");
|
|
983
983
|
var process2 = __require("process");
|
|
984
984
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
@@ -1911,9 +1911,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1911
1911
|
let launchWithNode = false;
|
|
1912
1912
|
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1913
1913
|
function findFile(baseDir, baseName) {
|
|
1914
|
-
const localBin =
|
|
1914
|
+
const localBin = path12.resolve(baseDir, baseName);
|
|
1915
1915
|
if (fs.existsSync(localBin)) return localBin;
|
|
1916
|
-
if (sourceExt.includes(
|
|
1916
|
+
if (sourceExt.includes(path12.extname(baseName))) return void 0;
|
|
1917
1917
|
const foundExt = sourceExt.find(
|
|
1918
1918
|
(ext) => fs.existsSync(`${localBin}${ext}`)
|
|
1919
1919
|
);
|
|
@@ -1931,17 +1931,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1931
1931
|
} catch (err) {
|
|
1932
1932
|
resolvedScriptPath = this._scriptPath;
|
|
1933
1933
|
}
|
|
1934
|
-
executableDir =
|
|
1935
|
-
|
|
1934
|
+
executableDir = path12.resolve(
|
|
1935
|
+
path12.dirname(resolvedScriptPath),
|
|
1936
1936
|
executableDir
|
|
1937
1937
|
);
|
|
1938
1938
|
}
|
|
1939
1939
|
if (executableDir) {
|
|
1940
1940
|
let localFile = findFile(executableDir, executableFile);
|
|
1941
1941
|
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1942
|
-
const legacyName =
|
|
1942
|
+
const legacyName = path12.basename(
|
|
1943
1943
|
this._scriptPath,
|
|
1944
|
-
|
|
1944
|
+
path12.extname(this._scriptPath)
|
|
1945
1945
|
);
|
|
1946
1946
|
if (legacyName !== this._name) {
|
|
1947
1947
|
localFile = findFile(
|
|
@@ -1952,7 +1952,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1952
1952
|
}
|
|
1953
1953
|
executableFile = localFile || executableFile;
|
|
1954
1954
|
}
|
|
1955
|
-
launchWithNode = sourceExt.includes(
|
|
1955
|
+
launchWithNode = sourceExt.includes(path12.extname(executableFile));
|
|
1956
1956
|
let proc;
|
|
1957
1957
|
if (process2.platform !== "win32") {
|
|
1958
1958
|
if (launchWithNode) {
|
|
@@ -2792,7 +2792,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2792
2792
|
* @return {Command}
|
|
2793
2793
|
*/
|
|
2794
2794
|
nameFromFilename(filename) {
|
|
2795
|
-
this._name =
|
|
2795
|
+
this._name = path12.basename(filename, path12.extname(filename));
|
|
2796
2796
|
return this;
|
|
2797
2797
|
}
|
|
2798
2798
|
/**
|
|
@@ -2806,9 +2806,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2806
2806
|
* @param {string} [path]
|
|
2807
2807
|
* @return {(string|null|Command)}
|
|
2808
2808
|
*/
|
|
2809
|
-
executableDir(
|
|
2810
|
-
if (
|
|
2811
|
-
this._executableDir =
|
|
2809
|
+
executableDir(path13) {
|
|
2810
|
+
if (path13 === void 0) return this._executableDir;
|
|
2811
|
+
this._executableDir = path13;
|
|
2812
2812
|
return this;
|
|
2813
2813
|
}
|
|
2814
2814
|
/**
|
|
@@ -3421,12 +3421,41 @@ var init_output = __esm({
|
|
|
3421
3421
|
}
|
|
3422
3422
|
});
|
|
3423
3423
|
|
|
3424
|
+
// src/core/package-version.ts
|
|
3425
|
+
import { readFileSync } from "fs";
|
|
3426
|
+
function readPackageVersion() {
|
|
3427
|
+
try {
|
|
3428
|
+
const raw = readFileSync(new URL("../../package.json", import.meta.url), "utf8");
|
|
3429
|
+
const parsed = JSON.parse(raw);
|
|
3430
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
|
|
3431
|
+
const record = parsed;
|
|
3432
|
+
if (record.name !== PACKAGE_NAME) return void 0;
|
|
3433
|
+
return typeof record.version === "string" ? record.version : void 0;
|
|
3434
|
+
} catch {
|
|
3435
|
+
return void 0;
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
3438
|
+
function requirePackageVersion() {
|
|
3439
|
+
const version = readPackageVersion();
|
|
3440
|
+
if (version === void 0) {
|
|
3441
|
+
throw new Error("cannot read version from the running package.json");
|
|
3442
|
+
}
|
|
3443
|
+
return version;
|
|
3444
|
+
}
|
|
3445
|
+
var PACKAGE_NAME, VERSION;
|
|
3446
|
+
var init_package_version = __esm({
|
|
3447
|
+
"src/core/package-version.ts"() {
|
|
3448
|
+
"use strict";
|
|
3449
|
+
PACKAGE_NAME = "pingcode-cli-unofficial";
|
|
3450
|
+
VERSION = requirePackageVersion();
|
|
3451
|
+
}
|
|
3452
|
+
});
|
|
3453
|
+
|
|
3424
3454
|
// src/version.ts
|
|
3425
|
-
var VERSION;
|
|
3426
3455
|
var init_version = __esm({
|
|
3427
3456
|
"src/version.ts"() {
|
|
3428
3457
|
"use strict";
|
|
3429
|
-
|
|
3458
|
+
init_package_version();
|
|
3430
3459
|
}
|
|
3431
3460
|
});
|
|
3432
3461
|
|
|
@@ -3464,7 +3493,7 @@ import {
|
|
|
3464
3493
|
chmodSync,
|
|
3465
3494
|
existsSync,
|
|
3466
3495
|
mkdirSync,
|
|
3467
|
-
readFileSync,
|
|
3496
|
+
readFileSync as readFileSync2,
|
|
3468
3497
|
renameSync,
|
|
3469
3498
|
rmSync,
|
|
3470
3499
|
statSync,
|
|
@@ -3519,7 +3548,7 @@ function loadConfig(env = process.env, logger = silentLogger) {
|
|
|
3519
3548
|
const file = configFilePath(env);
|
|
3520
3549
|
let raw;
|
|
3521
3550
|
try {
|
|
3522
|
-
raw =
|
|
3551
|
+
raw = readFileSync2(file, "utf8");
|
|
3523
3552
|
} catch (error) {
|
|
3524
3553
|
if (isNotFound(error)) return {};
|
|
3525
3554
|
throw new UsageError(`cannot read ${file}: ${errorMessage(error)}`, { cause: error });
|
|
@@ -3611,12 +3640,33 @@ function coerceConfig(raw) {
|
|
|
3611
3640
|
if (token !== void 0) config.token = token;
|
|
3612
3641
|
const userToken = coerceUserToken(record.userToken);
|
|
3613
3642
|
if (userToken !== void 0) config.userToken = userToken;
|
|
3643
|
+
const patToken = coercePatToken(record.patToken);
|
|
3644
|
+
if (patToken !== void 0) config.patToken = patToken;
|
|
3614
3645
|
const authMode = asAuthMode(record.authMode);
|
|
3615
3646
|
if (authMode !== void 0) config.authMode = authMode;
|
|
3616
3647
|
return config;
|
|
3617
3648
|
}
|
|
3618
3649
|
function asAuthMode(raw) {
|
|
3619
|
-
return raw === "enterprise" || raw === "user" ? raw : void 0;
|
|
3650
|
+
return raw === "enterprise" || raw === "user" || raw === "pat" ? raw : void 0;
|
|
3651
|
+
}
|
|
3652
|
+
function normalizeToken(raw) {
|
|
3653
|
+
return raw.trim().replace(/^Bearer\s+/i, "").trim();
|
|
3654
|
+
}
|
|
3655
|
+
function coercePatToken(raw) {
|
|
3656
|
+
if (typeof raw !== "object" || raw === null) return void 0;
|
|
3657
|
+
const record = raw;
|
|
3658
|
+
if (asAuthMode(record.kind) !== "pat") return void 0;
|
|
3659
|
+
const base = coerceTokenBase(record);
|
|
3660
|
+
if (base === void 0) return void 0;
|
|
3661
|
+
const token = {
|
|
3662
|
+
...base,
|
|
3663
|
+
accessToken: normalizeToken(base.accessToken),
|
|
3664
|
+
kind: "pat",
|
|
3665
|
+
unrefreshable: true
|
|
3666
|
+
};
|
|
3667
|
+
const scope = asString(record.scope);
|
|
3668
|
+
if (scope !== void 0) token.scope = scope;
|
|
3669
|
+
return token;
|
|
3620
3670
|
}
|
|
3621
3671
|
function coerceUserToken(raw) {
|
|
3622
3672
|
if (typeof raw !== "object" || raw === null) return void 0;
|
|
@@ -3673,8 +3723,32 @@ function resolveSettings(input) {
|
|
|
3673
3723
|
readEnv(env, ENV_USER_CLIENT_SECRET),
|
|
3674
3724
|
file.userClientSecret
|
|
3675
3725
|
).value;
|
|
3676
|
-
const
|
|
3677
|
-
const
|
|
3726
|
+
const envTokenRaw = readEnv(env, ENV_TOKEN);
|
|
3727
|
+
const envToken = envTokenRaw === void 0 ? void 0 : normalizeToken(envTokenRaw);
|
|
3728
|
+
const authMode = envToken !== void 0 ? "pat" : inferAuthMode(file);
|
|
3729
|
+
let activeToken;
|
|
3730
|
+
let tokenSource;
|
|
3731
|
+
const envPatToken = envToken === void 0 ? void 0 : {
|
|
3732
|
+
accessToken: envToken,
|
|
3733
|
+
expiresAtMs: 0,
|
|
3734
|
+
obtainedAtMs: 0,
|
|
3735
|
+
kind: "pat",
|
|
3736
|
+
unrefreshable: true
|
|
3737
|
+
};
|
|
3738
|
+
if (envPatToken !== void 0) {
|
|
3739
|
+
activeToken = envPatToken;
|
|
3740
|
+
tokenSource = "env";
|
|
3741
|
+
} else if (authMode === "pat") {
|
|
3742
|
+
activeToken = file.patToken;
|
|
3743
|
+
tokenSource = activeToken === void 0 ? "none" : "file";
|
|
3744
|
+
} else if (authMode === "user") {
|
|
3745
|
+
activeToken = file.userToken;
|
|
3746
|
+
tokenSource = activeToken === void 0 ? "none" : "file";
|
|
3747
|
+
} else {
|
|
3748
|
+
activeToken = file.token;
|
|
3749
|
+
tokenSource = activeToken === void 0 ? "none" : "file";
|
|
3750
|
+
}
|
|
3751
|
+
const tokenRefreshable = activeToken !== void 0 && activeToken.unrefreshable !== true && activeToken.kind !== "pat" && authMode !== "pat";
|
|
3678
3752
|
return {
|
|
3679
3753
|
host,
|
|
3680
3754
|
apiBase,
|
|
@@ -3683,6 +3757,9 @@ function resolveSettings(input) {
|
|
|
3683
3757
|
userClientId,
|
|
3684
3758
|
userClientSecret,
|
|
3685
3759
|
token: activeToken,
|
|
3760
|
+
patToken: envPatToken ?? file.patToken,
|
|
3761
|
+
tokenSource,
|
|
3762
|
+
tokenRefreshable,
|
|
3686
3763
|
authMode,
|
|
3687
3764
|
sources: {
|
|
3688
3765
|
host: hostSource,
|
|
@@ -3694,6 +3771,7 @@ function resolveSettings(input) {
|
|
|
3694
3771
|
}
|
|
3695
3772
|
function inferAuthMode(file) {
|
|
3696
3773
|
if (file.authMode !== void 0) return file.authMode;
|
|
3774
|
+
if (file.patToken !== void 0) return "pat";
|
|
3697
3775
|
if (file.userToken !== void 0) return "user";
|
|
3698
3776
|
if (file.token !== void 0) return "enterprise";
|
|
3699
3777
|
return "user";
|
|
@@ -3732,7 +3810,7 @@ function isNotFound(error) {
|
|
|
3732
3810
|
function errorMessage(error) {
|
|
3733
3811
|
return error instanceof Error ? error.message : String(error);
|
|
3734
3812
|
}
|
|
3735
|
-
var DEFAULT_HOST, CONFIG_DIR_MODE, CONFIG_FILE_MODE, ENV_CONFIG_DIR, ENV_HOST, ENV_CLIENT_ID, ENV_CLIENT_SECRET, ENV_USER_CLIENT_ID, ENV_USER_CLIENT_SECRET;
|
|
3813
|
+
var DEFAULT_HOST, CONFIG_DIR_MODE, CONFIG_FILE_MODE, ENV_CONFIG_DIR, ENV_HOST, ENV_CLIENT_ID, ENV_CLIENT_SECRET, ENV_USER_CLIENT_ID, ENV_USER_CLIENT_SECRET, ENV_TOKEN;
|
|
3736
3814
|
var init_config = __esm({
|
|
3737
3815
|
"src/core/config.ts"() {
|
|
3738
3816
|
"use strict";
|
|
@@ -3747,6 +3825,7 @@ var init_config = __esm({
|
|
|
3747
3825
|
ENV_CLIENT_SECRET = "PINGCODE_CLIENT_SECRET";
|
|
3748
3826
|
ENV_USER_CLIENT_ID = "PINGCODE_USER_CLIENT_ID";
|
|
3749
3827
|
ENV_USER_CLIENT_SECRET = "PINGCODE_USER_CLIENT_SECRET";
|
|
3828
|
+
ENV_TOKEN = "PINGCODE_TOKEN";
|
|
3750
3829
|
}
|
|
3751
3830
|
});
|
|
3752
3831
|
|
|
@@ -3828,10 +3907,10 @@ function buildContext(input) {
|
|
|
3828
3907
|
const override = input.credentials;
|
|
3829
3908
|
const activeClientId = mode === "user" ? override?.clientId ?? settings2.userClientId ?? settings2.clientId : override?.clientId ?? settings2.clientId;
|
|
3830
3909
|
const activeClientSecret = mode === "user" ? override?.clientSecret ?? settings2.userClientSecret ?? settings2.clientSecret : override?.clientSecret ?? settings2.clientSecret;
|
|
3831
|
-
const activeToken = mode === "user" ? file.userToken : file.token;
|
|
3910
|
+
const activeToken = mode === "pat" ? settings2.patToken : mode === "user" ? file.userToken : file.token;
|
|
3832
3911
|
const ctx = createContext({
|
|
3833
3912
|
apiBase: settings2.apiBase,
|
|
3834
|
-
credentials: { clientId: activeClientId, clientSecret: activeClientSecret },
|
|
3913
|
+
credentials: mode === "pat" ? {} : { clientId: activeClientId, clientSecret: activeClientSecret },
|
|
3835
3914
|
auth: {
|
|
3836
3915
|
token: activeToken,
|
|
3837
3916
|
clampWarned: false,
|
|
@@ -3845,7 +3924,8 @@ function buildContext(input) {
|
|
|
3845
3924
|
env,
|
|
3846
3925
|
// Mode-aware persist (D5): route by the token's kind to the right slot and
|
|
3847
3926
|
// stamp the active mode. saveConfig re-reads + merges, so this writes only
|
|
3848
|
-
// the owned field (never a whole stale Config).
|
|
3927
|
+
// the owned field (never a whole stale Config). A PAT is never refreshed, so
|
|
3928
|
+
// this only ever fires from `auth login --mode pat`.
|
|
3849
3929
|
persistToken: (token) => {
|
|
3850
3930
|
if (token.kind === "user") {
|
|
3851
3931
|
saveConfig(
|
|
@@ -3855,6 +3935,8 @@ function buildContext(input) {
|
|
|
3855
3935
|
},
|
|
3856
3936
|
env
|
|
3857
3937
|
);
|
|
3938
|
+
} else if (token.kind === "pat") {
|
|
3939
|
+
saveConfig({ patToken: { ...token, kind: "pat", unrefreshable: true }, authMode: "pat" }, env);
|
|
3858
3940
|
} else {
|
|
3859
3941
|
saveConfig({ token, authMode: "enterprise" }, env);
|
|
3860
3942
|
}
|
|
@@ -4471,9 +4553,9 @@ var init_catalog = __esm({
|
|
|
4471
4553
|
function isMutating(method) {
|
|
4472
4554
|
return MUTATING.has(method.toUpperCase());
|
|
4473
4555
|
}
|
|
4474
|
-
function buildUrl(apiBase,
|
|
4556
|
+
function buildUrl(apiBase, path12, query) {
|
|
4475
4557
|
const base = apiBase.replace(/\/+$/, "");
|
|
4476
|
-
const relative =
|
|
4558
|
+
const relative = path12.startsWith("/") ? path12 : `/${path12}`;
|
|
4477
4559
|
const url = new URL(`${base}${relative}`);
|
|
4478
4560
|
if (query !== void 0) {
|
|
4479
4561
|
for (const [key, value] of Object.entries(query)) {
|
|
@@ -5108,8 +5190,37 @@ async function refreshUserToken(ctx, refreshToken) {
|
|
|
5108
5190
|
ctx.persistToken?.(token);
|
|
5109
5191
|
return token;
|
|
5110
5192
|
}
|
|
5193
|
+
function setPersonalAccessToken(ctx, raw, options = {}) {
|
|
5194
|
+
const accessToken = normalizeToken(raw);
|
|
5195
|
+
if (accessToken === "") {
|
|
5196
|
+
throw new AuthError("the personal access token is empty", { hint: PAT_HINT });
|
|
5197
|
+
}
|
|
5198
|
+
const now = ctx.now();
|
|
5199
|
+
const token = {
|
|
5200
|
+
accessToken,
|
|
5201
|
+
expiresAtMs: 0,
|
|
5202
|
+
obtainedAtMs: now,
|
|
5203
|
+
kind: "pat",
|
|
5204
|
+
unrefreshable: true
|
|
5205
|
+
};
|
|
5206
|
+
ctx.auth.token = token;
|
|
5207
|
+
ctx.auth.mode = "pat";
|
|
5208
|
+
if (options.persist !== false) ctx.persistToken?.(token);
|
|
5209
|
+
return token;
|
|
5210
|
+
}
|
|
5211
|
+
function personalAccessToken(ctx, force) {
|
|
5212
|
+
const accessToken = ctx.auth.token?.accessToken ?? "";
|
|
5213
|
+
if (accessToken === "") {
|
|
5214
|
+
throw new AuthError("no personal access token configured", { hint: PAT_HINT });
|
|
5215
|
+
}
|
|
5216
|
+
if (force) {
|
|
5217
|
+
throw new AuthError("PingCode rejected the personal access token (401)", { hint: PAT_HINT });
|
|
5218
|
+
}
|
|
5219
|
+
return accessToken;
|
|
5220
|
+
}
|
|
5111
5221
|
async function ensureFreshToken(ctx, options = {}) {
|
|
5112
5222
|
const force = options.force === true;
|
|
5223
|
+
if (ctx.auth.mode === "pat") return personalAccessToken(ctx, force);
|
|
5113
5224
|
if (force) {
|
|
5114
5225
|
ctx.auth.inflight = void 0;
|
|
5115
5226
|
if (ctx.auth.mode !== "user") ctx.auth.token = void 0;
|
|
@@ -5124,6 +5235,11 @@ async function ensureFreshToken(ctx, options = {}) {
|
|
|
5124
5235
|
return token.accessToken;
|
|
5125
5236
|
}
|
|
5126
5237
|
async function acquireForMode(ctx) {
|
|
5238
|
+
if (ctx.auth.mode === "pat") {
|
|
5239
|
+
throw new AuthError("a personal access token cannot be acquired or refreshed", {
|
|
5240
|
+
hint: PAT_HINT
|
|
5241
|
+
});
|
|
5242
|
+
}
|
|
5127
5243
|
if (ctx.auth.mode === "user") {
|
|
5128
5244
|
const refreshToken = ctx.auth.token?.refreshToken;
|
|
5129
5245
|
if (refreshToken === void 0) {
|
|
@@ -5143,16 +5259,18 @@ function clearToken(ctx) {
|
|
|
5143
5259
|
ctx.auth.token = void 0;
|
|
5144
5260
|
ctx.auth.inflight = void 0;
|
|
5145
5261
|
}
|
|
5146
|
-
var THIRTY_DAYS_MS, REFRESH_WINDOW_MS, TOKEN_PATH;
|
|
5262
|
+
var THIRTY_DAYS_MS, REFRESH_WINDOW_MS, TOKEN_PATH, PAT_HINT;
|
|
5147
5263
|
var init_auth = __esm({
|
|
5148
5264
|
"src/core/auth.ts"() {
|
|
5149
5265
|
"use strict";
|
|
5266
|
+
init_config();
|
|
5150
5267
|
init_errors();
|
|
5151
5268
|
init_redact();
|
|
5152
5269
|
init_wire();
|
|
5153
5270
|
THIRTY_DAYS_MS = 30 * 24 * 3600 * 1e3;
|
|
5154
5271
|
REFRESH_WINDOW_MS = 12e4;
|
|
5155
5272
|
TOKEN_PATH = "/v1/auth/token";
|
|
5273
|
+
PAT_HINT = "personal access tokens cannot be renewed by this CLI: check that it is not expired or revoked, that its scopes cover this endpoint, or create a new token in PingCode personal settings and run `pingcode auth login --mode pat --token <token>` (or set PINGCODE_TOKEN)";
|
|
5156
5274
|
}
|
|
5157
5275
|
});
|
|
5158
5276
|
|
|
@@ -5297,12 +5415,12 @@ function normalizeEnvelope(raw, requested) {
|
|
|
5297
5415
|
values
|
|
5298
5416
|
};
|
|
5299
5417
|
}
|
|
5300
|
-
async function fetchPage(ctx,
|
|
5418
|
+
async function fetchPage(ctx, path12, query = {}, page = {}) {
|
|
5301
5419
|
const pageIndex = validatePageIndex(page.pageIndex ?? 0);
|
|
5302
5420
|
const pageSize = validatePageSize(page.pageSize ?? DEFAULT_PAGE_SIZE);
|
|
5303
5421
|
const raw = await request(ctx, {
|
|
5304
5422
|
method: "GET",
|
|
5305
|
-
path:
|
|
5423
|
+
path: path12,
|
|
5306
5424
|
query: { ...query, page_index: pageIndex, page_size: pageSize }
|
|
5307
5425
|
});
|
|
5308
5426
|
return normalizeEnvelope(raw, { pageIndex, pageSize });
|
|
@@ -5335,8 +5453,8 @@ async function* walkPages(ctx, fetchOne, options, label) {
|
|
|
5335
5453
|
pageIndex += 1;
|
|
5336
5454
|
}
|
|
5337
5455
|
}
|
|
5338
|
-
async function* paginate(ctx,
|
|
5339
|
-
yield* walkPages(ctx, (page) => fetchPage(ctx,
|
|
5456
|
+
async function* paginate(ctx, path12, query = {}, options = {}) {
|
|
5457
|
+
yield* walkPages(ctx, (page) => fetchPage(ctx, path12, query, page), options, "GET-list");
|
|
5340
5458
|
}
|
|
5341
5459
|
function asReadContext(ctx) {
|
|
5342
5460
|
return ctx.dryRun ? { ...ctx, dryRun: false } : ctx;
|
|
@@ -5352,20 +5470,20 @@ function buildSearchBody(payload, page) {
|
|
|
5352
5470
|
body.page_size = page.pageSize;
|
|
5353
5471
|
return { mode: "query", payload: body };
|
|
5354
5472
|
}
|
|
5355
|
-
async function fetchSearchPage(ctx,
|
|
5473
|
+
async function fetchSearchPage(ctx, path12, payload = {}, page = {}) {
|
|
5356
5474
|
const pageIndex = validatePageIndex(page.pageIndex ?? 0);
|
|
5357
5475
|
const pageSize = validatePageSize(page.pageSize ?? DEFAULT_PAGE_SIZE);
|
|
5358
5476
|
const raw = await request(asReadContext(ctx), {
|
|
5359
5477
|
method: "POST",
|
|
5360
|
-
path:
|
|
5478
|
+
path: path12,
|
|
5361
5479
|
body: buildSearchBody(payload, { pageIndex, pageSize })
|
|
5362
5480
|
});
|
|
5363
5481
|
return normalizeEnvelope(raw, { pageIndex, pageSize });
|
|
5364
5482
|
}
|
|
5365
|
-
async function* searchPaginate(ctx,
|
|
5483
|
+
async function* searchPaginate(ctx, path12, payload = {}, options = {}) {
|
|
5366
5484
|
yield* walkPages(
|
|
5367
5485
|
ctx,
|
|
5368
|
-
(page) => fetchSearchPage(ctx,
|
|
5486
|
+
(page) => fetchSearchPage(ctx, path12, payload, page),
|
|
5369
5487
|
options,
|
|
5370
5488
|
"search"
|
|
5371
5489
|
);
|
|
@@ -6966,7 +7084,7 @@ var init_registry = __esm({
|
|
|
6966
7084
|
|
|
6967
7085
|
// src/core/metadata/resolve.ts
|
|
6968
7086
|
import { createHash } from "crypto";
|
|
6969
|
-
import { mkdirSync as mkdirSync2, readFileSync as
|
|
7087
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
6970
7088
|
import path2 from "path";
|
|
6971
7089
|
function cacheKeyFor(parts) {
|
|
6972
7090
|
const material = JSON.stringify([
|
|
@@ -6995,7 +7113,7 @@ function readCache(ctx, key) {
|
|
|
6995
7113
|
if (!ctx.useCache) return void 0;
|
|
6996
7114
|
let raw;
|
|
6997
7115
|
try {
|
|
6998
|
-
raw =
|
|
7116
|
+
raw = readFileSync3(cacheFilePath(ctx, key), "utf8");
|
|
6999
7117
|
} catch {
|
|
7000
7118
|
return void 0;
|
|
7001
7119
|
}
|
|
@@ -7083,9 +7201,9 @@ async function loadSuiteTree(ctx, path_, query) {
|
|
|
7083
7201
|
}
|
|
7084
7202
|
const candidates = [];
|
|
7085
7203
|
for (const [id, node] of nodes) {
|
|
7086
|
-
const
|
|
7087
|
-
const candidate = { id, name: node.name, path:
|
|
7088
|
-
if (
|
|
7204
|
+
const path12 = suitePath(nodes, id);
|
|
7205
|
+
const candidate = { id, name: node.name, path: path12 };
|
|
7206
|
+
if (path12 !== void 0 && path12 !== node.name) candidate.aliases = [path12];
|
|
7089
7207
|
candidates.push(candidate);
|
|
7090
7208
|
}
|
|
7091
7209
|
return candidates;
|
|
@@ -7857,29 +7975,29 @@ endpoints; a wiki page and a code branch are the two with no recovery path at al
|
|
|
7857
7975
|
}
|
|
7858
7976
|
}
|
|
7859
7977
|
async function runVerb(method, pathArgument, flags, self) {
|
|
7860
|
-
const { candidates, path:
|
|
7978
|
+
const { candidates, path: path12 } = resolveEntry2(method, pathArgument);
|
|
7861
7979
|
const { ctx } = contextFor(self);
|
|
7862
7980
|
refuseUserTokenEndpoint(ctx, candidates);
|
|
7863
7981
|
const query = parseQueryFlags(flags.query);
|
|
7864
|
-
refuseUnconfirmedDelete(method,
|
|
7982
|
+
refuseUnconfirmedDelete(method, path12, query, flags);
|
|
7865
7983
|
const body = await readBodyFlags(flags);
|
|
7866
7984
|
const entry = chooseEntry(candidates, query, body);
|
|
7867
7985
|
const paging = readPagingFor(entry, flags);
|
|
7868
7986
|
try {
|
|
7869
|
-
await send(ctx, entry,
|
|
7987
|
+
await send(ctx, entry, path12, query, body, paging);
|
|
7870
7988
|
} catch (error) {
|
|
7871
7989
|
if (error instanceof PermissionError) errLine(paint.dim(declaredScopeLine(entry)));
|
|
7872
7990
|
throw error;
|
|
7873
7991
|
}
|
|
7874
7992
|
}
|
|
7875
|
-
async function send(ctx, entry,
|
|
7993
|
+
async function send(ctx, entry, path12, query, body, paging) {
|
|
7876
7994
|
if (entry.paged === "search") {
|
|
7877
|
-
await sendSearch(ctx,
|
|
7995
|
+
await sendSearch(ctx, path12, body, paging);
|
|
7878
7996
|
return;
|
|
7879
7997
|
}
|
|
7880
7998
|
if (entry.paged === "query" && paging.all) {
|
|
7881
7999
|
const values = await collect(
|
|
7882
|
-
paginate(ctx,
|
|
8000
|
+
paginate(ctx, path12, query, {
|
|
7883
8001
|
pageSize: paging.pageSize,
|
|
7884
8002
|
startPage: paging.pageIndex,
|
|
7885
8003
|
limit: paging.limit
|
|
@@ -7890,17 +8008,17 @@ async function send(ctx, entry, path11, query, body, paging) {
|
|
|
7890
8008
|
}
|
|
7891
8009
|
const raw = await request(ctx, {
|
|
7892
8010
|
method: entry.method,
|
|
7893
|
-
path:
|
|
8011
|
+
path: path12,
|
|
7894
8012
|
query: paging.requested ? { ...query, page_index: paging.pageIndex, page_size: paging.pageSize } : query,
|
|
7895
8013
|
...body === void 0 ? {} : { body }
|
|
7896
8014
|
});
|
|
7897
8015
|
printResponse(raw);
|
|
7898
8016
|
}
|
|
7899
|
-
async function sendSearch(ctx,
|
|
8017
|
+
async function sendSearch(ctx, path12, body, paging) {
|
|
7900
8018
|
const payload = searchPayloadOf(body);
|
|
7901
8019
|
if (paging.all) {
|
|
7902
8020
|
const values = await collect(
|
|
7903
|
-
searchPaginate(ctx,
|
|
8021
|
+
searchPaginate(ctx, path12, payload, {
|
|
7904
8022
|
pageSize: paging.pageSize,
|
|
7905
8023
|
startPage: paging.pageIndex,
|
|
7906
8024
|
limit: paging.limit
|
|
@@ -7909,7 +8027,7 @@ async function sendSearch(ctx, path11, body, paging) {
|
|
|
7909
8027
|
printJson({ values, count: values.length, all: true });
|
|
7910
8028
|
return;
|
|
7911
8029
|
}
|
|
7912
|
-
const page = await fetchSearchPage(ctx,
|
|
8030
|
+
const page = await fetchSearchPage(ctx, path12, payload, {
|
|
7913
8031
|
pageIndex: paging.pageIndex,
|
|
7914
8032
|
pageSize: paging.pageSize
|
|
7915
8033
|
});
|
|
@@ -7943,8 +8061,8 @@ function resolveEntry2(method, pathArgument) {
|
|
|
7943
8061
|
hint: `drop everything from "?" and pass the parameters as --query key=value (repeatable), so they are serialised the same way every other command does it`
|
|
7944
8062
|
});
|
|
7945
8063
|
}
|
|
7946
|
-
const
|
|
7947
|
-
const unfilled = unfilledPathParams(
|
|
8064
|
+
const path12 = normalizePath(raw);
|
|
8065
|
+
const unfilled = unfilledPathParams(path12);
|
|
7948
8066
|
if (unfilled.length > 0) {
|
|
7949
8067
|
throw new UsageError(
|
|
7950
8068
|
`the path still contains the placeholder${unfilled.length > 1 ? "s" : ""} ${unfilled.map((name) => `{${name}}`).join(", ")}`,
|
|
@@ -7953,32 +8071,32 @@ function resolveEntry2(method, pathArgument) {
|
|
|
7953
8071
|
}
|
|
7954
8072
|
);
|
|
7955
8073
|
}
|
|
7956
|
-
const onPath = matchPath(
|
|
7957
|
-
if (onPath.length === 0) throw unknownPath(
|
|
8074
|
+
const onPath = matchPath(path12);
|
|
8075
|
+
if (onPath.length === 0) throw unknownPath(path12);
|
|
7958
8076
|
const candidates = onPath.filter((candidate) => candidate.method === method);
|
|
7959
8077
|
if (candidates.length === 0) {
|
|
7960
|
-
const supported = methodsFor(
|
|
7961
|
-
throw new UsageError(`${method} ${
|
|
8078
|
+
const supported = methodsFor(path12);
|
|
8079
|
+
throw new UsageError(`${method} ${path12} is not a documented endpoint`, {
|
|
7962
8080
|
hint: `that path supports ${supported.join(", ")} \u2014 this API is missing several symmetric operations on purpose (there is no project delete, no sprint delete, and nothing in \u4EA7\u54C1\u7BA1\u7406 can be deleted at all)`
|
|
7963
8081
|
});
|
|
7964
8082
|
}
|
|
7965
|
-
return { candidates, path:
|
|
8083
|
+
return { candidates, path: path12 };
|
|
7966
8084
|
}
|
|
7967
|
-
function unknownPath(
|
|
7968
|
-
if (segmentsOf2(
|
|
8085
|
+
function unknownPath(path12) {
|
|
8086
|
+
if (segmentsOf2(path12).includes("authorize")) {
|
|
7969
8087
|
return new UsageError(
|
|
7970
|
-
`${
|
|
8088
|
+
`${path12} is the browser authorization page of the OAuth2 authorization-code flow, not a REST endpoint: it renders HTML for a human to click and redirects, it returns no JSON, and it is not under /v1`,
|
|
7971
8089
|
{ hint: AUTHORIZE_HINT }
|
|
7972
8090
|
);
|
|
7973
8091
|
}
|
|
7974
|
-
const suggestions = nearestPaths(
|
|
7975
|
-
const hint = suggestions.length === 0 ? `no documented path has ${segmentsOf2(
|
|
7976
|
-
return new UsageError(`${
|
|
8092
|
+
const suggestions = nearestPaths(path12);
|
|
8093
|
+
const hint = suggestions.length === 0 ? `no documented path has ${segmentsOf2(path12).length} segments like this one \u2014 search the catalog with \`pingcode api list --search <text>\`` : `did you mean ${suggestions.join(" , ")} ? \u2014 or search with \`pingcode api list --search <text>\``;
|
|
8094
|
+
return new UsageError(`${path12} is not in the endpoint catalog (459 documented v1 endpoints)`, {
|
|
7977
8095
|
hint
|
|
7978
8096
|
});
|
|
7979
8097
|
}
|
|
7980
|
-
function nearestPaths(
|
|
7981
|
-
const actual = segmentsOf2(
|
|
8098
|
+
function nearestPaths(path12) {
|
|
8099
|
+
const actual = segmentsOf2(path12);
|
|
7982
8100
|
const scored = /* @__PURE__ */ new Map();
|
|
7983
8101
|
for (const entry of CATALOG2) {
|
|
7984
8102
|
const template = segmentsOf2(entry.path);
|
|
@@ -8007,27 +8125,27 @@ function editDistance(a2, b3) {
|
|
|
8007
8125
|
}
|
|
8008
8126
|
return previous[b3.length] ?? Math.max(a2.length, b3.length);
|
|
8009
8127
|
}
|
|
8010
|
-
function segmentsOf2(
|
|
8011
|
-
return
|
|
8128
|
+
function segmentsOf2(path12) {
|
|
8129
|
+
return path12.split("/").filter((segment) => segment !== "");
|
|
8012
8130
|
}
|
|
8013
8131
|
function isPlaceholder2(segment) {
|
|
8014
8132
|
return segment.startsWith("{") && segment.endsWith("}");
|
|
8015
8133
|
}
|
|
8016
8134
|
function refuseUserTokenEndpoint(ctx, candidates) {
|
|
8017
8135
|
if (!candidates.every((entry2) => entry2.tokenType === "USER")) return;
|
|
8018
|
-
if (ctx.auth.mode === "user") return;
|
|
8136
|
+
if (ctx.auth.mode === "user" || ctx.auth.mode === "pat") return;
|
|
8019
8137
|
const entry = candidates[0];
|
|
8020
8138
|
if (entry === void 0) return;
|
|
8021
8139
|
throw new UsageError(
|
|
8022
|
-
`${entry.method} ${entry.path} requires a \u7528\u6237\u4EE4\u724C (user token), but the active token is an \u4F01\u4E1A\u4EE4\u724C (enterprise) \u2014 run \`pingcode auth login --mode user
|
|
8140
|
+
`${entry.method} ${entry.path} requires a \u7528\u6237\u4EE4\u724C (user token), but the active token is an \u4F01\u4E1A\u4EE4\u724C (enterprise) \u2014 run \`pingcode auth login --mode user\`, or use a personal access token with --mode pat / PINGCODE_TOKEN`,
|
|
8023
8141
|
{
|
|
8024
8142
|
hint: "seven endpoints are user-token-only \u2014 /v1/myself, /v1/permission/my/* and /v1/permission/check/*. GET /v1/permission/points does work with the enterprise token. " + AUTHORIZE_HINT
|
|
8025
8143
|
}
|
|
8026
8144
|
);
|
|
8027
8145
|
}
|
|
8028
|
-
function refuseUnconfirmedDelete(method,
|
|
8146
|
+
function refuseUnconfirmedDelete(method, path12, query, flags) {
|
|
8029
8147
|
if (method !== "DELETE" || flags.yes === true) return;
|
|
8030
|
-
throw new UsageError(`refusing to send DELETE ${
|
|
8148
|
+
throw new UsageError(`refusing to send DELETE ${path12}${displayQuery(query)} without --yes`, {
|
|
8031
8149
|
hint: "re-run with --yes to send it, or with --yes --dry-run to print the full request plan without sending anything"
|
|
8032
8150
|
});
|
|
8033
8151
|
}
|
|
@@ -8189,22 +8307,22 @@ function registerDescribe(api) {
|
|
|
8189
8307
|
"\nAn id is exact; a method + path is matched through the same wildcard rules the\nexecutor uses. GET /v1/auth/token is the one path three entries share (the three\ngrants), so address those by id.\n--json prints the catalog entry verbatim.\n"
|
|
8190
8308
|
);
|
|
8191
8309
|
addGlobalOptions(command, { hidden: true }).action(
|
|
8192
|
-
(idOrMethod,
|
|
8310
|
+
(idOrMethod, path12, _flags, self) => {
|
|
8193
8311
|
const { ctx } = contextFor(self);
|
|
8194
|
-
const entry = lookupForDescribe(idOrMethod,
|
|
8312
|
+
const entry = lookupForDescribe(idOrMethod, path12);
|
|
8195
8313
|
printEntry(entry, modeOf(ctx));
|
|
8196
8314
|
}
|
|
8197
8315
|
);
|
|
8198
8316
|
}
|
|
8199
|
-
function lookupForDescribe(idOrMethod,
|
|
8200
|
-
if (
|
|
8317
|
+
function lookupForDescribe(idOrMethod, path12) {
|
|
8318
|
+
if (path12 !== void 0) {
|
|
8201
8319
|
const method = idOrMethod.trim().toUpperCase();
|
|
8202
8320
|
if (!METHODS.includes(method)) {
|
|
8203
8321
|
throw new UsageError(`"${idOrMethod}" is not an HTTP method`, {
|
|
8204
8322
|
hint: `the methods are ${METHODS.join(", ")} \u2014 or pass a single catalog id instead`
|
|
8205
8323
|
});
|
|
8206
8324
|
}
|
|
8207
|
-
const normalized = normalizePath(
|
|
8325
|
+
const normalized = normalizePath(path12.trim());
|
|
8208
8326
|
const matches = matchPath(normalized).filter((entry2) => entry2.method === method);
|
|
8209
8327
|
const entry = matches[0];
|
|
8210
8328
|
if (entry === void 0) {
|
|
@@ -8381,26 +8499,26 @@ function parseRefList(raw) {
|
|
|
8381
8499
|
function parseProperties(raw) {
|
|
8382
8500
|
return typeof raw === "object" && raw !== null && !Array.isArray(raw) ? raw : void 0;
|
|
8383
8501
|
}
|
|
8384
|
-
async function fetchPageOf(ctx,
|
|
8385
|
-
const raw = await fetchPage(ctx,
|
|
8502
|
+
async function fetchPageOf(ctx, path12, query, page, parse) {
|
|
8503
|
+
const raw = await fetchPage(ctx, path12, query, page);
|
|
8386
8504
|
return { ...raw, values: raw.values.map(parse) };
|
|
8387
8505
|
}
|
|
8388
|
-
async function* iterateOf(ctx,
|
|
8389
|
-
for await (const raw of paginate(ctx,
|
|
8506
|
+
async function* iterateOf(ctx, path12, query, options, parse) {
|
|
8507
|
+
for await (const raw of paginate(ctx, path12, query, options)) {
|
|
8390
8508
|
yield parse(raw);
|
|
8391
8509
|
}
|
|
8392
8510
|
}
|
|
8393
|
-
async function listAllOf(ctx,
|
|
8511
|
+
async function listAllOf(ctx, path12, query, parse, options = {}) {
|
|
8394
8512
|
return await collect(
|
|
8395
|
-
iterateOf(ctx,
|
|
8513
|
+
iterateOf(ctx, path12, query, { pageSize: 100, limit: 1e3, ...options }, parse)
|
|
8396
8514
|
);
|
|
8397
8515
|
}
|
|
8398
|
-
async function fetchSearchPageOf(ctx,
|
|
8399
|
-
const raw = await fetchSearchPage(ctx,
|
|
8516
|
+
async function fetchSearchPageOf(ctx, path12, payload, page, parse) {
|
|
8517
|
+
const raw = await fetchSearchPage(ctx, path12, payload, page);
|
|
8400
8518
|
return { ...raw, values: raw.values.map(parse) };
|
|
8401
8519
|
}
|
|
8402
|
-
async function* iterateSearchOf(ctx,
|
|
8403
|
-
for await (const raw of searchPaginate(ctx,
|
|
8520
|
+
async function* iterateSearchOf(ctx, path12, payload, options, parse) {
|
|
8521
|
+
for await (const raw of searchPaginate(ctx, path12, payload, options)) {
|
|
8404
8522
|
yield parse(raw);
|
|
8405
8523
|
}
|
|
8406
8524
|
}
|
|
@@ -9904,12 +10022,15 @@ var init_oauth = __esm({
|
|
|
9904
10022
|
// src/cli/commands/auth.ts
|
|
9905
10023
|
import { createInterface } from "readline/promises";
|
|
9906
10024
|
function registerAuthCommands(program2) {
|
|
9907
|
-
const auth = program2.command("auth").description("authenticate against PingCode (enterprise app or
|
|
10025
|
+
const auth = program2.command("auth").description("authenticate against PingCode (enterprise app, user token or personal access token)");
|
|
9908
10026
|
addGlobalOptions(
|
|
9909
10027
|
auth.command("login").description("acquire a token (user token by default) and verify it").option("--client-id <id>", "app client id (or PINGCODE_CLIENT_ID)").option("--client-secret <secret>", "app client secret (or PINGCODE_CLIENT_SECRET)").option("--save", "also store the client id/secret in the config file (mode 0600)").option(
|
|
9910
10028
|
"--mode <mode>",
|
|
9911
|
-
"auth mode: user (authorization_code, default)
|
|
9912
|
-
).option("--code <code>", "authorization code (skips the interactive paste)")
|
|
10029
|
+
"auth mode: user (authorization_code, default), enterprise (client_credentials) or pat (personal access token)"
|
|
10030
|
+
).option("--code <code>", "authorization code (skips the interactive paste)").option(
|
|
10031
|
+
"--token <token>",
|
|
10032
|
+
"personal access token for --mode pat (or PINGCODE_TOKEN; skips the hidden prompt)"
|
|
10033
|
+
),
|
|
9913
10034
|
{ hidden: true }
|
|
9914
10035
|
).action(async (flags, command) => {
|
|
9915
10036
|
await runLogin(flags, command);
|
|
@@ -9921,7 +10042,7 @@ function registerAuthCommands(program2) {
|
|
|
9921
10042
|
await runStatus(flags, command);
|
|
9922
10043
|
});
|
|
9923
10044
|
addGlobalOptions(
|
|
9924
|
-
auth.command("logout").description("clear the active token slot (
|
|
10045
|
+
auth.command("logout").description("clear the active token slot (all three with --all) and the metadata cache").option("--all", "clear the enterprise, user and personal-token slots (and authMode)"),
|
|
9925
10046
|
{ hidden: true }
|
|
9926
10047
|
).action((flags, command) => {
|
|
9927
10048
|
runLogout(flags, command);
|
|
@@ -9930,6 +10051,10 @@ function registerAuthCommands(program2) {
|
|
|
9930
10051
|
async function runLogin(flags, command) {
|
|
9931
10052
|
const probe = contextFor(command);
|
|
9932
10053
|
const authMode = await resolveMode(flags.mode, probe.ctx.json);
|
|
10054
|
+
if (authMode === "pat") {
|
|
10055
|
+
await runLoginPat(flags, command);
|
|
10056
|
+
return;
|
|
10057
|
+
}
|
|
9933
10058
|
let built = contextFor(
|
|
9934
10059
|
command,
|
|
9935
10060
|
{ clientId: flags.clientId, clientSecret: flags.clientSecret },
|
|
@@ -9983,12 +10108,52 @@ async function runLogin(flags, command) {
|
|
|
9983
10108
|
clearMetadataCache(ctx);
|
|
9984
10109
|
finishLogin(built, flags, { authMode, tokenKind, user, verifiedWith, token });
|
|
9985
10110
|
}
|
|
10111
|
+
async function runLoginPat(flags, command) {
|
|
10112
|
+
const built = contextFor(command, void 0, "pat");
|
|
10113
|
+
const { ctx, settings: settings2 } = built;
|
|
10114
|
+
const stored = ctx.auth.token?.accessToken;
|
|
10115
|
+
const provided = flags.token !== void 0 && flags.token !== "" ? flags.token : void 0;
|
|
10116
|
+
const source = provided !== void 0 ? "flag" : stored === void 0 ? "prompt" : settings2.tokenSource === "env" ? "env" : "file";
|
|
10117
|
+
const raw = provided ?? stored ?? await loginHooks.readToken(ctx.json);
|
|
10118
|
+
clearToken(ctx);
|
|
10119
|
+
const token = setPersonalAccessToken(ctx, raw, { persist: false });
|
|
10120
|
+
const verified = await verifyPatToken(ctx);
|
|
10121
|
+
ctx.persistToken?.(token);
|
|
10122
|
+
clearMetadataCache(ctx);
|
|
10123
|
+
finishLogin(built, flags, {
|
|
10124
|
+
authMode: "pat",
|
|
10125
|
+
tokenKind: "pat",
|
|
10126
|
+
tokenSource: source,
|
|
10127
|
+
token,
|
|
10128
|
+
...verified
|
|
10129
|
+
});
|
|
10130
|
+
}
|
|
10131
|
+
async function verifyPatToken(ctx) {
|
|
10132
|
+
try {
|
|
10133
|
+
const me = await getMyself(ctx);
|
|
10134
|
+
const user = { id: me.id };
|
|
10135
|
+
if (me.name !== void 0) user.name = me.name;
|
|
10136
|
+
if (me.display_name !== void 0) user.display_name = me.display_name;
|
|
10137
|
+
if (me.username !== void 0) user.username = me.username;
|
|
10138
|
+
return { verifiedWith: "GET /v1/myself", user };
|
|
10139
|
+
} catch (error) {
|
|
10140
|
+
if (!(error instanceof PermissionError)) throw error;
|
|
10141
|
+
}
|
|
10142
|
+
try {
|
|
10143
|
+
const projectsTotal = await verifyAccess(ctx);
|
|
10144
|
+
return { verifiedWith: "GET /v1/pjm/projects?page_size=1", projectsTotal };
|
|
10145
|
+
} catch (error) {
|
|
10146
|
+
if (!(error instanceof PermissionError)) throw error;
|
|
10147
|
+
return {};
|
|
10148
|
+
}
|
|
10149
|
+
}
|
|
9986
10150
|
function finishLogin(built, flags, outcome) {
|
|
9987
10151
|
const { settings: settings2, file } = built;
|
|
9988
10152
|
const save = flags.save === true;
|
|
9989
10153
|
const patch = { host: settings2.host };
|
|
9990
10154
|
let storeId = false;
|
|
9991
10155
|
let storeSecret = false;
|
|
10156
|
+
const isPat = outcome.authMode === "pat";
|
|
9992
10157
|
if (outcome.authMode === "user") {
|
|
9993
10158
|
const userId = flags.clientId ?? settings2.userClientId;
|
|
9994
10159
|
if (userId !== void 0) {
|
|
@@ -10008,16 +10173,25 @@ function finishLogin(built, flags, outcome) {
|
|
|
10008
10173
|
storeSecret = true;
|
|
10009
10174
|
}
|
|
10010
10175
|
}
|
|
10011
|
-
} else {
|
|
10176
|
+
} else if (!isPat) {
|
|
10012
10177
|
storeId = shouldPersistSecret(settings2.sources.clientId, save);
|
|
10013
10178
|
storeSecret = shouldPersistSecret(settings2.sources.clientSecret, save);
|
|
10014
10179
|
if (storeId) patch.clientId = settings2.clientId;
|
|
10015
10180
|
if (storeSecret) patch.clientSecret = settings2.clientSecret;
|
|
10016
10181
|
}
|
|
10017
10182
|
saveConfig(patch, process.env);
|
|
10018
|
-
const alreadyInFile = outcome.authMode === "user" ? file.userClientId !== void 0 && file.userClientSecret !== void 0 : file.clientId !== void 0 && file.clientSecret !== void 0;
|
|
10183
|
+
const alreadyInFile = isPat ? true : outcome.authMode === "user" ? file.userClientId !== void 0 && file.userClientSecret !== void 0 : file.clientId !== void 0 && file.clientSecret !== void 0;
|
|
10019
10184
|
const credentialsStored = alreadyInFile || storeId && storeSecret;
|
|
10020
10185
|
const mode = modeOf(built.ctx);
|
|
10186
|
+
const effectiveSource = isPat ? outcome.tokenSource ?? "none" : "file";
|
|
10187
|
+
const refreshable = !isPat;
|
|
10188
|
+
if (isPat && outcome.verifiedWith === void 0) {
|
|
10189
|
+
errLine(
|
|
10190
|
+
paint.yellow(
|
|
10191
|
+
"stored, but no granted scope allowed a live check \u2014 a 401 will still fail hard, and `auth status --check` will tell you when that happens"
|
|
10192
|
+
)
|
|
10193
|
+
);
|
|
10194
|
+
}
|
|
10021
10195
|
if (mode.json) {
|
|
10022
10196
|
printJson({
|
|
10023
10197
|
ok: true,
|
|
@@ -10025,33 +10199,42 @@ function finishLogin(built, flags, outcome) {
|
|
|
10025
10199
|
kind: outcome.tokenKind,
|
|
10026
10200
|
host: settings2.host,
|
|
10027
10201
|
api_base: settings2.apiBase,
|
|
10028
|
-
client_id: maskIdentifier(settings2.clientId),
|
|
10029
|
-
credentials_stored: credentialsStored,
|
|
10202
|
+
client_id: isPat ? null : maskIdentifier(settings2.clientId),
|
|
10203
|
+
credentials_stored: isPat ? false : credentialsStored,
|
|
10030
10204
|
...outcome.user === void 0 ? {} : { user: outcome.user },
|
|
10031
10205
|
...outcome.projectsTotal === void 0 ? {} : { projects_total: outcome.projectsTotal },
|
|
10032
|
-
|
|
10033
|
-
|
|
10206
|
+
// A PAT's validity is set in PingCode and unknown to us — never invent one.
|
|
10207
|
+
token_expires_at: isPat ? null : Math.floor(outcome.token.expiresAtMs / 1e3),
|
|
10208
|
+
token_source: effectiveSource,
|
|
10209
|
+
token_refreshable: refreshable,
|
|
10210
|
+
verified_with: outcome.verifiedWith ?? null
|
|
10034
10211
|
});
|
|
10035
10212
|
return;
|
|
10036
10213
|
}
|
|
10037
10214
|
const fields = [
|
|
10038
10215
|
["host", settings2.host],
|
|
10039
|
-
["api base", settings2.apiBase]
|
|
10040
|
-
["client id", maskIdentifier(settings2.clientId)],
|
|
10041
|
-
["mode", outcome.authMode],
|
|
10042
|
-
["token kind", outcome.tokenKind]
|
|
10216
|
+
["api base", settings2.apiBase]
|
|
10043
10217
|
];
|
|
10218
|
+
if (isPat) {
|
|
10219
|
+
fields.push(["token source", effectiveSource]);
|
|
10220
|
+
} else {
|
|
10221
|
+
fields.push(["client id", maskIdentifier(settings2.clientId)]);
|
|
10222
|
+
}
|
|
10223
|
+
fields.push(["mode", outcome.authMode], ["token kind", outcome.tokenKind]);
|
|
10044
10224
|
if (outcome.user !== void 0) {
|
|
10045
10225
|
fields.push(["user", outcome.user.display_name ?? outcome.user.name ?? outcome.user.username ?? outcome.user.id]);
|
|
10046
10226
|
}
|
|
10047
10227
|
if (outcome.projectsTotal !== void 0) {
|
|
10048
10228
|
fields.push(["projects visible", String(outcome.projectsTotal)]);
|
|
10049
10229
|
}
|
|
10050
|
-
fields.push([
|
|
10230
|
+
fields.push([
|
|
10231
|
+
"token expires",
|
|
10232
|
+
isPat ? "unknown \u2014 set by the token in PingCode personal settings" : formatTimestamp(Math.floor(outcome.token.expiresAtMs / 1e3))
|
|
10233
|
+
]);
|
|
10051
10234
|
fields.push(["config file", configFilePath(process.env)]);
|
|
10052
10235
|
printFields(fields);
|
|
10053
|
-
errLine(paint.green("authenticated"));
|
|
10054
|
-
if (!credentialsStored) {
|
|
10236
|
+
errLine(paint.green(outcome.verifiedWith === void 0 ? "token stored" : "authenticated"));
|
|
10237
|
+
if (!isPat && !credentialsStored) {
|
|
10055
10238
|
errLine(
|
|
10056
10239
|
paint.dim(
|
|
10057
10240
|
"the client id/secret were not written to disk (pass --save to store them); the token was stored, but a re-login will be needed once it expires"
|
|
@@ -10060,9 +10243,9 @@ function finishLogin(built, flags, outcome) {
|
|
|
10060
10243
|
}
|
|
10061
10244
|
}
|
|
10062
10245
|
async function resolveMode(flag, json) {
|
|
10063
|
-
if (flag === "enterprise" || flag === "user") return flag;
|
|
10246
|
+
if (flag === "enterprise" || flag === "user" || flag === "pat") return flag;
|
|
10064
10247
|
if (flag !== void 0) {
|
|
10065
|
-
throw new UsageError(`--mode must be "enterprise" or "
|
|
10248
|
+
throw new UsageError(`--mode must be "enterprise", "user" or "pat", got "${flag}"`);
|
|
10066
10249
|
}
|
|
10067
10250
|
return await loginHooks.selectMode(json);
|
|
10068
10251
|
}
|
|
@@ -10076,12 +10259,13 @@ async function runStatus(flags, command) {
|
|
|
10076
10259
|
const { ctx, settings: settings2, file } = contextFor(command);
|
|
10077
10260
|
const mode = modeOf(ctx);
|
|
10078
10261
|
const token = settings2.token;
|
|
10079
|
-
const expiresAt = token === void 0 ? void 0 : Math.floor(token.expiresAtMs / 1e3);
|
|
10262
|
+
const expiresAt = token === void 0 || !settings2.tokenRefreshable ? void 0 : Math.floor(token.expiresAtMs / 1e3);
|
|
10080
10263
|
const authMode = settings2.authMode;
|
|
10081
|
-
const tokenKind = token?.kind ?? "enterprise";
|
|
10264
|
+
const tokenKind = token?.kind ?? (authMode === "pat" ? "pat" : "enterprise");
|
|
10265
|
+
const fresh = settings2.tokenRefreshable ? tokenIsFresh(token, ctx.now()) : null;
|
|
10082
10266
|
let check;
|
|
10083
10267
|
if (flags.check === true) {
|
|
10084
|
-
if (authMode === "user") {
|
|
10268
|
+
if (authMode === "user" || authMode === "pat") {
|
|
10085
10269
|
const me = await getMyself(ctx);
|
|
10086
10270
|
check = { ok: true, endpoint: "GET /v1/myself", user: me.display_name ?? me.name ?? me.username ?? me.id };
|
|
10087
10271
|
} else {
|
|
@@ -10102,39 +10286,57 @@ async function runStatus(flags, command) {
|
|
|
10102
10286
|
credentials_stored: file.clientId !== void 0 && file.clientSecret !== void 0,
|
|
10103
10287
|
token_present: token !== void 0,
|
|
10104
10288
|
token_kind: tokenKind,
|
|
10105
|
-
|
|
10289
|
+
token_source: settings2.tokenSource,
|
|
10290
|
+
token_refreshable: settings2.tokenRefreshable,
|
|
10291
|
+
token_fresh: fresh,
|
|
10106
10292
|
token_expires_at: expiresAt ?? null,
|
|
10107
10293
|
token_scope: token?.scope ?? null,
|
|
10108
10294
|
// User-slot refresh-token presence (AC8) — boolean only, never the value.
|
|
10109
10295
|
user_token_present: file.userToken !== void 0,
|
|
10110
10296
|
user_refresh_token_present: file.userToken?.refreshToken !== void 0,
|
|
10297
|
+
// Personal-token slot presence — boolean only, never the value.
|
|
10298
|
+
pat_token_present: file.patToken !== void 0,
|
|
10299
|
+
env_token_present: settings2.tokenSource === "env" && authMode === "pat",
|
|
10111
10300
|
config_file: configFilePath(process.env),
|
|
10112
10301
|
...check === void 0 ? {} : { check }
|
|
10113
10302
|
});
|
|
10114
10303
|
return;
|
|
10115
10304
|
}
|
|
10116
|
-
|
|
10305
|
+
const fields = [
|
|
10117
10306
|
["host", settings2.host],
|
|
10118
|
-
["api base", settings2.apiBase]
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
|
|
10307
|
+
["api base", settings2.apiBase]
|
|
10308
|
+
];
|
|
10309
|
+
if (authMode === "pat") {
|
|
10310
|
+
fields.push(["token source", settings2.tokenSource]);
|
|
10311
|
+
} else {
|
|
10312
|
+
fields.push(
|
|
10313
|
+
["client id", `${maskIdentifier(settings2.clientId)} (${settings2.sources.clientId})`],
|
|
10314
|
+
[
|
|
10315
|
+
"client secret",
|
|
10316
|
+
settings2.clientSecret === void 0 ? "(not set)" : `(set, ${settings2.sources.clientSecret})`
|
|
10317
|
+
]
|
|
10318
|
+
);
|
|
10319
|
+
}
|
|
10320
|
+
fields.push(
|
|
10124
10321
|
["auth mode", authMode],
|
|
10125
10322
|
[
|
|
10126
10323
|
"token",
|
|
10127
|
-
token === void 0 ? "(none) \u2014 run `pingcode auth login`" :
|
|
10324
|
+
token === void 0 ? "(none) \u2014 run `pingcode auth login`" : fresh === null ? `present (${tokenKind}; not refreshable)` : fresh ? `present (${tokenKind})` : `present but stale (${tokenKind}) \u2014 it will be re-acquired on the next call`
|
|
10325
|
+
],
|
|
10326
|
+
[
|
|
10327
|
+
"token expires",
|
|
10328
|
+
expiresAt === void 0 ? authMode === "pat" && token !== void 0 ? "unknown \u2014 set by the token in PingCode personal settings" : "" : formatTimestamp(expiresAt)
|
|
10128
10329
|
],
|
|
10129
|
-
["token expires", expiresAt === void 0 ? "" : formatTimestamp(expiresAt)],
|
|
10130
10330
|
["token scope", token?.scope ?? ""],
|
|
10131
10331
|
["user slot", file.userToken === void 0 ? "(none)" : "present (with refresh token)"],
|
|
10332
|
+
["personal token slot", file.patToken === void 0 ? "(none)" : "present (not refreshable)"],
|
|
10132
10333
|
["config file", configFilePath(process.env)],
|
|
10133
10334
|
[
|
|
10134
10335
|
"live check",
|
|
10135
10336
|
check === void 0 ? "(skipped \u2014 pass --check)" : check.endpoint === "GET /v1/myself" ? `ok \xB7 signed in as ${check.user} via ${check.endpoint}` : `ok \xB7 ${check.projects_total} project(s) visible via ${check.endpoint}`
|
|
10136
10337
|
]
|
|
10137
|
-
|
|
10338
|
+
);
|
|
10339
|
+
printFields(fields);
|
|
10138
10340
|
}
|
|
10139
10341
|
function runLogout(flags, command) {
|
|
10140
10342
|
const { ctx, settings: settings2 } = contextFor(command);
|
|
@@ -10143,14 +10345,38 @@ function runLogout(flags, command) {
|
|
|
10143
10345
|
let cleared;
|
|
10144
10346
|
if (all) {
|
|
10145
10347
|
saveConfig(
|
|
10146
|
-
{
|
|
10348
|
+
{
|
|
10349
|
+
host: settings2.host,
|
|
10350
|
+
token: null,
|
|
10351
|
+
userToken: null,
|
|
10352
|
+
patToken: null,
|
|
10353
|
+
authMode: null,
|
|
10354
|
+
clientId: null,
|
|
10355
|
+
clientSecret: null,
|
|
10356
|
+
userClientId: null,
|
|
10357
|
+
userClientSecret: null
|
|
10358
|
+
},
|
|
10147
10359
|
process.env
|
|
10148
10360
|
);
|
|
10149
|
-
cleared = [
|
|
10361
|
+
cleared = [
|
|
10362
|
+
"token",
|
|
10363
|
+
"user_token",
|
|
10364
|
+
"pat_token",
|
|
10365
|
+
"auth_mode",
|
|
10366
|
+
"client_id",
|
|
10367
|
+
"client_secret",
|
|
10368
|
+
"user_client_id",
|
|
10369
|
+
"user_client_secret",
|
|
10370
|
+
"metadata_cache"
|
|
10371
|
+
];
|
|
10150
10372
|
} else {
|
|
10151
|
-
const slot = settings2.authMode === "user" ? "userToken" : "token";
|
|
10373
|
+
const slot = settings2.authMode === "pat" ? "patToken" : settings2.authMode === "user" ? "userToken" : "token";
|
|
10152
10374
|
saveConfig({ [slot]: null, authMode: null }, process.env);
|
|
10153
|
-
cleared = [
|
|
10375
|
+
cleared = [
|
|
10376
|
+
slot === "patToken" ? "pat_token" : slot === "userToken" ? "user_token" : "token",
|
|
10377
|
+
"auth_mode",
|
|
10378
|
+
"metadata_cache"
|
|
10379
|
+
];
|
|
10154
10380
|
}
|
|
10155
10381
|
clearToken(ctx);
|
|
10156
10382
|
clearMetadataCache(ctx);
|
|
@@ -10165,8 +10391,10 @@ function runLogout(flags, command) {
|
|
|
10165
10391
|
errLine(`cleared ${cleared.join(", ")} (${configFilePath(process.env)})`);
|
|
10166
10392
|
}
|
|
10167
10393
|
function missingCredential(what) {
|
|
10394
|
+
const flag = what === "client id" ? "--client-id" : what === "personal access token" ? "--token" : "--client-secret";
|
|
10395
|
+
const env = what === "client id" ? "PINGCODE_CLIENT_ID" : what === "personal access token" ? "PINGCODE_TOKEN" : "PINGCODE_CLIENT_SECRET";
|
|
10168
10396
|
return new UsageError(`no ${what} available`, {
|
|
10169
|
-
hint: `pass
|
|
10397
|
+
hint: `pass ${flag}, set ${env}, or run the command from a terminal to be prompted`
|
|
10170
10398
|
});
|
|
10171
10399
|
}
|
|
10172
10400
|
async function promptVisible(question, json) {
|
|
@@ -10180,9 +10408,9 @@ async function promptVisible(question, json) {
|
|
|
10180
10408
|
rl.close();
|
|
10181
10409
|
}
|
|
10182
10410
|
}
|
|
10183
|
-
async function promptHidden(question, json) {
|
|
10411
|
+
async function promptHidden(question, json, what = "client secret") {
|
|
10184
10412
|
const input = process.stdin;
|
|
10185
|
-
if (json || input.isTTY !== true) throw missingCredential(
|
|
10413
|
+
if (json || input.isTTY !== true) throw missingCredential(what);
|
|
10186
10414
|
process.stderr.write(question);
|
|
10187
10415
|
input.setRawMode(true);
|
|
10188
10416
|
input.resume();
|
|
@@ -10218,7 +10446,7 @@ async function promptHidden(question, json) {
|
|
|
10218
10446
|
input.on("data", onData);
|
|
10219
10447
|
});
|
|
10220
10448
|
const trimmed = value.trim();
|
|
10221
|
-
if (trimmed === "") throw missingCredential(
|
|
10449
|
+
if (trimmed === "") throw missingCredential(what);
|
|
10222
10450
|
return trimmed;
|
|
10223
10451
|
}
|
|
10224
10452
|
async function readPasteFromTerminal(json) {
|
|
@@ -10234,6 +10462,12 @@ async function readPasteFromTerminal(json) {
|
|
|
10234
10462
|
rl.close();
|
|
10235
10463
|
}
|
|
10236
10464
|
}
|
|
10465
|
+
async function readTokenFromTerminal(json) {
|
|
10466
|
+
if (json || process.stdin.isTTY !== true) throw missingCredential("personal access token");
|
|
10467
|
+
const token = await promptHidden("personal access token: ", json, "personal access token");
|
|
10468
|
+
if (token.trim() === "") throw missingCredential("personal access token");
|
|
10469
|
+
return token;
|
|
10470
|
+
}
|
|
10237
10471
|
async function promptChoice(question, choices, defaultKey) {
|
|
10238
10472
|
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
10239
10473
|
try {
|
|
@@ -10260,6 +10494,7 @@ async function defaultSelectMode(json) {
|
|
|
10260
10494
|
if (json || process.stdin.isTTY !== true) return "user";
|
|
10261
10495
|
return await promptChoice("auth mode", [
|
|
10262
10496
|
{ key: "user", label: "authorization_code \u2014 acts as you (default)" },
|
|
10497
|
+
{ key: "pat", label: "personal access token \u2014 paste a token, no app needed" },
|
|
10263
10498
|
{ key: "enterprise", label: "client_credentials \u2014 app/admin identity" }
|
|
10264
10499
|
], "user");
|
|
10265
10500
|
}
|
|
@@ -10280,7 +10515,8 @@ var init_auth2 = __esm({
|
|
|
10280
10515
|
init_common();
|
|
10281
10516
|
loginHooks = {
|
|
10282
10517
|
selectMode: defaultSelectMode,
|
|
10283
|
-
readPaste: readPasteFromTerminal
|
|
10518
|
+
readPaste: readPasteFromTerminal,
|
|
10519
|
+
readToken: readTokenFromTerminal
|
|
10284
10520
|
};
|
|
10285
10521
|
}
|
|
10286
10522
|
});
|
|
@@ -12896,13 +13132,13 @@ var init_projectMember = __esm({
|
|
|
12896
13132
|
|
|
12897
13133
|
// src/cli/commands/_shared/bulkEntries.ts
|
|
12898
13134
|
async function readBulkEntries(source, options) {
|
|
12899
|
-
const
|
|
12900
|
-
if (
|
|
13135
|
+
const path12 = source.file?.trim() ?? "";
|
|
13136
|
+
if (path12 === "") {
|
|
12901
13137
|
throw new UsageError("--file <path|-> is required", {
|
|
12902
13138
|
hint: "pass a JSON array of entries, or - to read it from stdin. Each entry needs name, start and end; project and assignee may be shared with --project / --assignee"
|
|
12903
13139
|
});
|
|
12904
13140
|
}
|
|
12905
|
-
const document =
|
|
13141
|
+
const document = path12 === "-" ? await readJsonStdin() : parseJsonDocument(await readTextFile(path12, "--file"), `--file ${path12}`);
|
|
12906
13142
|
const list = unwrap(document, options.wrapperKey);
|
|
12907
13143
|
if (list.length === 0) {
|
|
12908
13144
|
throw new UsageError("--file contained no entries", {
|
|
@@ -17454,6 +17690,67 @@ function compareSemver(a2, b3) {
|
|
|
17454
17690
|
}
|
|
17455
17691
|
return 0;
|
|
17456
17692
|
}
|
|
17693
|
+
function parseComparableVersion(raw) {
|
|
17694
|
+
let version = raw.startsWith("v") ? raw.slice(1) : raw;
|
|
17695
|
+
const buildIndex = version.indexOf("+");
|
|
17696
|
+
if (buildIndex !== -1) {
|
|
17697
|
+
const build = version.slice(buildIndex + 1);
|
|
17698
|
+
if (build.includes("+") || !build.split(".").every((identifier) => SEMVER_IDENTIFIER.test(identifier))) {
|
|
17699
|
+
return void 0;
|
|
17700
|
+
}
|
|
17701
|
+
version = version.slice(0, buildIndex);
|
|
17702
|
+
}
|
|
17703
|
+
const prereleaseIndex = version.indexOf("-");
|
|
17704
|
+
const coreText = prereleaseIndex === -1 ? version : version.slice(0, prereleaseIndex);
|
|
17705
|
+
const prereleaseText = prereleaseIndex === -1 ? void 0 : version.slice(prereleaseIndex + 1);
|
|
17706
|
+
const parts = coreText.split(".");
|
|
17707
|
+
if (parts.length !== 3 || !SEMVER_COMPONENT.test(parts[0]) || !SEMVER_COMPONENT.test(parts[1]) || !SEMVER_COMPONENT.test(parts[2])) {
|
|
17708
|
+
return void 0;
|
|
17709
|
+
}
|
|
17710
|
+
let prerelease;
|
|
17711
|
+
if (prereleaseText !== void 0) {
|
|
17712
|
+
prerelease = prereleaseText.split(".");
|
|
17713
|
+
const valid = prerelease.every((identifier) => SEMVER_IDENTIFIER.test(identifier) && (!/^\d+$/.test(identifier) || SEMVER_COMPONENT.test(identifier)));
|
|
17714
|
+
if (!valid) return void 0;
|
|
17715
|
+
}
|
|
17716
|
+
return {
|
|
17717
|
+
core: [BigInt(parts[0]), BigInt(parts[1]), BigInt(parts[2])],
|
|
17718
|
+
prerelease
|
|
17719
|
+
};
|
|
17720
|
+
}
|
|
17721
|
+
function comparePrerelease(left, right) {
|
|
17722
|
+
const sharedLength = Math.min(left.length, right.length);
|
|
17723
|
+
for (let index = 0; index < sharedLength; index += 1) {
|
|
17724
|
+
const leftIdentifier = left[index];
|
|
17725
|
+
const rightIdentifier = right[index];
|
|
17726
|
+
if (leftIdentifier === rightIdentifier) continue;
|
|
17727
|
+
const leftNumeric = /^\d+$/.test(leftIdentifier);
|
|
17728
|
+
const rightNumeric = /^\d+$/.test(rightIdentifier);
|
|
17729
|
+
if (leftNumeric && rightNumeric) {
|
|
17730
|
+
return BigInt(leftIdentifier) < BigInt(rightIdentifier) ? -1 : 1;
|
|
17731
|
+
}
|
|
17732
|
+
if (leftNumeric !== rightNumeric) return leftNumeric ? -1 : 1;
|
|
17733
|
+
return leftIdentifier < rightIdentifier ? -1 : 1;
|
|
17734
|
+
}
|
|
17735
|
+
return left.length - right.length;
|
|
17736
|
+
}
|
|
17737
|
+
function compareComparableVersions(left, right) {
|
|
17738
|
+
for (let index = 0; index < left.core.length; index += 1) {
|
|
17739
|
+
const leftPart = left.core[index];
|
|
17740
|
+
const rightPart = right.core[index];
|
|
17741
|
+
if (leftPart !== rightPart) return leftPart < rightPart ? -1 : 1;
|
|
17742
|
+
}
|
|
17743
|
+
if (left.prerelease === void 0 || right.prerelease === void 0) {
|
|
17744
|
+
if (left.prerelease === right.prerelease) return 0;
|
|
17745
|
+
return left.prerelease === void 0 ? 1 : -1;
|
|
17746
|
+
}
|
|
17747
|
+
return comparePrerelease(left.prerelease, right.prerelease);
|
|
17748
|
+
}
|
|
17749
|
+
function isNewerVersion(candidate, current) {
|
|
17750
|
+
const candidateVersion = parseComparableVersion(candidate);
|
|
17751
|
+
const currentVersion = parseComparableVersion(current);
|
|
17752
|
+
return candidateVersion !== void 0 && currentVersion !== void 0 && compareComparableVersions(currentVersion, candidateVersion) < 0;
|
|
17753
|
+
}
|
|
17457
17754
|
function cacheFilePath2() {
|
|
17458
17755
|
return path3.join(configDir(), CACHE_FILENAME);
|
|
17459
17756
|
}
|
|
@@ -17530,29 +17827,25 @@ async function checkForUpdate(env = process.env, opts) {
|
|
|
17530
17827
|
return { status: "unknown" };
|
|
17531
17828
|
}
|
|
17532
17829
|
function compareVersions(remote) {
|
|
17533
|
-
|
|
17534
|
-
const remoteParts = parseSemver(remote);
|
|
17535
|
-
if (localParts === void 0 || remoteParts === void 0) {
|
|
17536
|
-
return { status: "up-to-date" };
|
|
17537
|
-
}
|
|
17538
|
-
if (compareSemver(localParts, remoteParts) < 0) {
|
|
17830
|
+
if (isNewerVersion(remote, VERSION)) {
|
|
17539
17831
|
return { status: "update-available", current: VERSION, latest: remote };
|
|
17540
17832
|
}
|
|
17541
17833
|
return { status: "up-to-date" };
|
|
17542
17834
|
}
|
|
17543
|
-
var
|
|
17835
|
+
var PACKAGE_NAME2, REGISTRY_URL, CHECK_TIMEOUT_MS, CACHE_TTL_MS2, CACHE_FILENAME, ENV_NO_UPDATE_CHECK, SEMVER_COMPONENT, SEMVER_IDENTIFIER;
|
|
17544
17836
|
var init_update_check = __esm({
|
|
17545
17837
|
"src/core/update-check.ts"() {
|
|
17546
17838
|
"use strict";
|
|
17547
17839
|
init_config();
|
|
17548
17840
|
init_version();
|
|
17549
|
-
|
|
17550
|
-
REGISTRY_URL = `https://registry.npmjs.org/${encodeURIComponent(
|
|
17841
|
+
PACKAGE_NAME2 = "pingcode-cli-unofficial";
|
|
17842
|
+
REGISTRY_URL = `https://registry.npmjs.org/${encodeURIComponent(PACKAGE_NAME2)}`;
|
|
17551
17843
|
CHECK_TIMEOUT_MS = 5e3;
|
|
17552
17844
|
CACHE_TTL_MS2 = 24 * 60 * 60 * 1e3;
|
|
17553
17845
|
CACHE_FILENAME = "update-check.json";
|
|
17554
17846
|
ENV_NO_UPDATE_CHECK = "PINGCODE_NO_UPDATE_CHECK";
|
|
17555
17847
|
SEMVER_COMPONENT = /^(0|[1-9]\d*)$/;
|
|
17848
|
+
SEMVER_IDENTIFIER = /^[0-9A-Za-z-]+$/;
|
|
17556
17849
|
}
|
|
17557
17850
|
});
|
|
17558
17851
|
|
|
@@ -17635,7 +17928,7 @@ import {
|
|
|
17635
17928
|
copyFileSync,
|
|
17636
17929
|
existsSync as existsSync2,
|
|
17637
17930
|
mkdirSync as mkdirSync3,
|
|
17638
|
-
readFileSync as
|
|
17931
|
+
readFileSync as readFileSync4,
|
|
17639
17932
|
readdirSync,
|
|
17640
17933
|
rmSync as rmSync3,
|
|
17641
17934
|
statSync as statSync2,
|
|
@@ -17725,7 +18018,7 @@ async function installViaNpm(exec2, version) {
|
|
|
17725
18018
|
{ hint: `install Node.js, then re-run this command` }
|
|
17726
18019
|
);
|
|
17727
18020
|
}
|
|
17728
|
-
const spec = `${
|
|
18021
|
+
const spec = `${PACKAGE_NAME3}@${version}`;
|
|
17729
18022
|
let output;
|
|
17730
18023
|
try {
|
|
17731
18024
|
output = exec2(npm, ["install", "--global", spec]);
|
|
@@ -17748,20 +18041,12 @@ async function installViaNpm(exec2, version) {
|
|
|
17748
18041
|
if (installed !== version) {
|
|
17749
18042
|
throw new TransportError(
|
|
17750
18043
|
`npm install --global ${spec} exited 0 but the installed version is ${installed ?? "unreadable"}, expected ${version}`,
|
|
17751
|
-
{ hint: `verify with: ${npm} list --global --depth=0 ${
|
|
18044
|
+
{ hint: `verify with: ${npm} list --global --depth=0 ${PACKAGE_NAME3}` }
|
|
17752
18045
|
);
|
|
17753
18046
|
}
|
|
17754
18047
|
}
|
|
17755
18048
|
function readInstalledVersion() {
|
|
17756
|
-
|
|
17757
|
-
const raw = readFileSync3(fileURLToPath(new URL("../../package.json", import.meta.url)), "utf8");
|
|
17758
|
-
const parsed = JSON.parse(raw);
|
|
17759
|
-
if (typeof parsed !== "object" || parsed === null) return void 0;
|
|
17760
|
-
const version = parsed.version;
|
|
17761
|
-
return typeof version === "string" ? version : void 0;
|
|
17762
|
-
} catch {
|
|
17763
|
-
return void 0;
|
|
17764
|
-
}
|
|
18049
|
+
return readPackageVersion();
|
|
17765
18050
|
}
|
|
17766
18051
|
function exitStatusOf(error) {
|
|
17767
18052
|
if (typeof error === "object" && error !== null && "status" in error) {
|
|
@@ -17829,7 +18114,7 @@ function acquireLock(dir) {
|
|
|
17829
18114
|
}
|
|
17830
18115
|
let holderDead = false;
|
|
17831
18116
|
try {
|
|
17832
|
-
const pid = parseInt(
|
|
18117
|
+
const pid = parseInt(readFileSync4(lockPath, "utf8").trim(), 10);
|
|
17833
18118
|
process.kill(pid, 0);
|
|
17834
18119
|
} catch {
|
|
17835
18120
|
holderDead = true;
|
|
@@ -17867,7 +18152,7 @@ function touchCooldown(dir) {
|
|
|
17867
18152
|
}
|
|
17868
18153
|
function readHint(dir) {
|
|
17869
18154
|
try {
|
|
17870
|
-
const raw =
|
|
18155
|
+
const raw = readFileSync4(path5.join(dir, HINT_FILENAME), "utf8");
|
|
17871
18156
|
const parsed = JSON.parse(raw);
|
|
17872
18157
|
if (typeof parsed !== "object" || parsed === null) return void 0;
|
|
17873
18158
|
const version = parsed.version;
|
|
@@ -17936,7 +18221,7 @@ async function runAutoUpdate(env = process.env, fetchFn = defaultFetch, exec2 =
|
|
|
17936
18221
|
lock.release();
|
|
17937
18222
|
}
|
|
17938
18223
|
}
|
|
17939
|
-
var
|
|
18224
|
+
var PACKAGE_NAME3, REGISTRY_URL2, NETWORK_TIMEOUT_MS, MODULES_DIR, LOCK_FILENAME, HINT_FILENAME, COOLDOWN_FILENAME, DEFAULT_COOLDOWN_MS;
|
|
17940
18225
|
var init_update = __esm({
|
|
17941
18226
|
"src/core/update.ts"() {
|
|
17942
18227
|
"use strict";
|
|
@@ -17944,9 +18229,10 @@ var init_update = __esm({
|
|
|
17944
18229
|
init_errors();
|
|
17945
18230
|
init_update_check();
|
|
17946
18231
|
init_version();
|
|
18232
|
+
init_package_version();
|
|
17947
18233
|
init_paths();
|
|
17948
|
-
|
|
17949
|
-
REGISTRY_URL2 = `https://registry.npmjs.org/${encodeURIComponent(
|
|
18234
|
+
PACKAGE_NAME3 = "pingcode-cli-unofficial";
|
|
18235
|
+
REGISTRY_URL2 = `https://registry.npmjs.org/${encodeURIComponent(PACKAGE_NAME3)}`;
|
|
17950
18236
|
NETWORK_TIMEOUT_MS = 6e4;
|
|
17951
18237
|
MODULES_DIR = "modules";
|
|
17952
18238
|
LOCK_FILENAME = "update.lock";
|
|
@@ -18205,7 +18491,7 @@ import {
|
|
|
18205
18491
|
existsSync as existsSync3,
|
|
18206
18492
|
mkdirSync as mkdirSync4,
|
|
18207
18493
|
readdirSync as readdirSync2,
|
|
18208
|
-
readFileSync as
|
|
18494
|
+
readFileSync as readFileSync5,
|
|
18209
18495
|
rmSync as rmSync4,
|
|
18210
18496
|
statSync as statSync3
|
|
18211
18497
|
} from "fs";
|
|
@@ -18231,7 +18517,7 @@ function collectSkillPayload(skillDir) {
|
|
|
18231
18517
|
function readSkillVersion(skillDir) {
|
|
18232
18518
|
const mdPath = path7.join(skillDir, SKILL_MD);
|
|
18233
18519
|
try {
|
|
18234
|
-
const content =
|
|
18520
|
+
const content = readFileSync5(mdPath, "utf8");
|
|
18235
18521
|
const match = content.match(/^version:\s*(.+)$/m);
|
|
18236
18522
|
return match?.[1]?.trim();
|
|
18237
18523
|
} catch {
|
|
@@ -22008,11 +22294,11 @@ var init_libraries = __esm({
|
|
|
22008
22294
|
|
|
22009
22295
|
// src/cli/commands/testhub/entries.ts
|
|
22010
22296
|
async function readEntryFile(source, schema, hint) {
|
|
22011
|
-
const
|
|
22012
|
-
if (
|
|
22297
|
+
const path12 = source.file?.trim() ?? "";
|
|
22298
|
+
if (path12 === "") {
|
|
22013
22299
|
throw new UsageError("--file <path|-> is required", { hint });
|
|
22014
22300
|
}
|
|
22015
|
-
const document =
|
|
22301
|
+
const document = path12 === "-" ? await readJsonStdin() : parseJsonDocument(await readTextFile(path12, "--file"), `--file ${path12}`);
|
|
22016
22302
|
const list = unwrap2(document, schema.wrapperKey);
|
|
22017
22303
|
if (list.length === 0) {
|
|
22018
22304
|
throw new UsageError("--file contained no entries", {
|
|
@@ -24124,16 +24410,36 @@ init_errors();
|
|
|
24124
24410
|
init_config();
|
|
24125
24411
|
init_update_check();
|
|
24126
24412
|
init_update();
|
|
24127
|
-
init_version();
|
|
24128
24413
|
import { spawn } from "child_process";
|
|
24414
|
+
|
|
24415
|
+
// src/core/legacy-standalone.ts
|
|
24416
|
+
import { statSync as statSync4 } from "fs";
|
|
24417
|
+
import { homedir } from "os";
|
|
24418
|
+
import path11 from "path";
|
|
24419
|
+
function legacyStandalonePath(home = homedir()) {
|
|
24420
|
+
return path11.join(home, ".local", "share", "pingcode-cli");
|
|
24421
|
+
}
|
|
24422
|
+
function existingLegacyStandalone(home = homedir()) {
|
|
24423
|
+
const candidate = legacyStandalonePath(home);
|
|
24424
|
+
try {
|
|
24425
|
+
return statSync4(candidate).isDirectory() ? candidate : void 0;
|
|
24426
|
+
} catch {
|
|
24427
|
+
return void 0;
|
|
24428
|
+
}
|
|
24429
|
+
}
|
|
24430
|
+
|
|
24431
|
+
// src/bin/pingcode.ts
|
|
24432
|
+
init_version();
|
|
24129
24433
|
function notifyUpdateCheck(jsonMode) {
|
|
24130
24434
|
if (jsonMode) return;
|
|
24131
24435
|
if (process.env[ENV_NO_UPDATE_CHECK] === "1") return;
|
|
24132
24436
|
const dir = configDir();
|
|
24133
24437
|
const hint = readHint(dir);
|
|
24134
24438
|
if (hint !== void 0) {
|
|
24135
|
-
|
|
24136
|
-
|
|
24439
|
+
if (isNewerVersion(hint.version, VERSION)) {
|
|
24440
|
+
errLine(paint.yellow(`Update available: ${VERSION} \u2192 ${hint.version}`));
|
|
24441
|
+
errLine(paint.dim("Run: pingcode self-update"));
|
|
24442
|
+
}
|
|
24137
24443
|
try {
|
|
24138
24444
|
removeHint(dir);
|
|
24139
24445
|
} catch {
|
|
@@ -24155,9 +24461,18 @@ function detectJsonMode(program2, argv) {
|
|
|
24155
24461
|
}
|
|
24156
24462
|
return argv.includes("--json");
|
|
24157
24463
|
}
|
|
24464
|
+
function warnLegacyStandalone() {
|
|
24465
|
+
const legacy = existingLegacyStandalone();
|
|
24466
|
+
if (legacy !== void 0) {
|
|
24467
|
+
errLine(paint.yellow(
|
|
24468
|
+
`Deprecated standalone installation found at ${legacy}; it is ignored and can be deleted.`
|
|
24469
|
+
));
|
|
24470
|
+
}
|
|
24471
|
+
}
|
|
24158
24472
|
async function main(argv) {
|
|
24159
24473
|
const program2 = buildProgram();
|
|
24160
24474
|
const jsonMode = argv.includes("--json");
|
|
24475
|
+
if (argv.slice(2).includes("self-update")) warnLegacyStandalone();
|
|
24161
24476
|
notifyUpdateCheck(jsonMode);
|
|
24162
24477
|
try {
|
|
24163
24478
|
await program2.parseAsync(argv);
|