@pmate/cli 0.21.18 → 0.21.19
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/dist/index.d.ts +17 -0
- package/dist/index.js +174 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -349,6 +349,23 @@ type RoleCommandArgs = {
|
|
|
349
349
|
json: boolean;
|
|
350
350
|
};
|
|
351
351
|
type AccountCommandArgs = {
|
|
352
|
+
type: Command.Account;
|
|
353
|
+
action: "list";
|
|
354
|
+
page?: number;
|
|
355
|
+
pageSize?: number;
|
|
356
|
+
mobile?: string;
|
|
357
|
+
nickName?: string;
|
|
358
|
+
baseUrl?: string;
|
|
359
|
+
json: boolean;
|
|
360
|
+
} | {
|
|
361
|
+
type: Command.Account;
|
|
362
|
+
action: "app-users";
|
|
363
|
+
app: string;
|
|
364
|
+
page?: number;
|
|
365
|
+
pageSize?: number;
|
|
366
|
+
baseUrl?: string;
|
|
367
|
+
json: boolean;
|
|
368
|
+
} | {
|
|
352
369
|
type: Command.Account;
|
|
353
370
|
action: "view";
|
|
354
371
|
account?: string;
|
package/dist/index.js
CHANGED
|
@@ -19221,6 +19221,28 @@ var AccountCommandHandler = class {
|
|
|
19221
19221
|
async handle(args) {
|
|
19222
19222
|
const token = this.readToken();
|
|
19223
19223
|
switch (args.action) {
|
|
19224
|
+
case "list": {
|
|
19225
|
+
const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
|
|
19226
|
+
const result = await this.request(
|
|
19227
|
+
baseUrl,
|
|
19228
|
+
token,
|
|
19229
|
+
"GET",
|
|
19230
|
+
`/accounts?${this.buildAccountListQuery(args)}`
|
|
19231
|
+
);
|
|
19232
|
+
this.renderAccountList(result, args.json);
|
|
19233
|
+
return;
|
|
19234
|
+
}
|
|
19235
|
+
case "app-users": {
|
|
19236
|
+
const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
|
|
19237
|
+
const result = await this.request(
|
|
19238
|
+
baseUrl,
|
|
19239
|
+
token,
|
|
19240
|
+
"GET",
|
|
19241
|
+
`/accounts/app-users/${encodeURIComponent(args.app)}?${this.buildPagedQuery(args)}`
|
|
19242
|
+
);
|
|
19243
|
+
this.renderAccountAppUsers(result, args.json);
|
|
19244
|
+
return;
|
|
19245
|
+
}
|
|
19224
19246
|
case "view": {
|
|
19225
19247
|
const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
|
|
19226
19248
|
const result = await this.request(
|
|
@@ -19362,6 +19384,20 @@ var AccountCommandHandler = class {
|
|
|
19362
19384
|
if (args.nickName) params.set("nickName", args.nickName);
|
|
19363
19385
|
return params.toString();
|
|
19364
19386
|
}
|
|
19387
|
+
buildAccountListQuery(args) {
|
|
19388
|
+
const params = new URLSearchParams();
|
|
19389
|
+
if (args.page) params.set("page", String(args.page));
|
|
19390
|
+
if (args.pageSize) params.set("pageSize", String(args.pageSize));
|
|
19391
|
+
if (args.mobile) params.set("mobile", args.mobile);
|
|
19392
|
+
if (args.nickName) params.set("nickName", args.nickName);
|
|
19393
|
+
return params.toString();
|
|
19394
|
+
}
|
|
19395
|
+
buildPagedQuery(args) {
|
|
19396
|
+
const params = new URLSearchParams();
|
|
19397
|
+
if (args.page) params.set("page", String(args.page));
|
|
19398
|
+
if (args.pageSize) params.set("pageSize", String(args.pageSize));
|
|
19399
|
+
return params.toString();
|
|
19400
|
+
}
|
|
19365
19401
|
buildRoleBindingsQuery(args) {
|
|
19366
19402
|
const params = new URLSearchParams();
|
|
19367
19403
|
params.set("account", args.account);
|
|
@@ -19440,6 +19476,44 @@ var AccountCommandHandler = class {
|
|
|
19440
19476
|
});
|
|
19441
19477
|
}
|
|
19442
19478
|
}
|
|
19479
|
+
renderAccountList(result, asJson) {
|
|
19480
|
+
if (asJson) {
|
|
19481
|
+
ui.plain(JSON.stringify(result, null, 2));
|
|
19482
|
+
return;
|
|
19483
|
+
}
|
|
19484
|
+
this.renderAccountView(result.items, false);
|
|
19485
|
+
if (result.items.length > 0) {
|
|
19486
|
+
ui.info(`page ${result.page}`, {
|
|
19487
|
+
pageSize: result.pageSize,
|
|
19488
|
+
totalPages: result.totalPages,
|
|
19489
|
+
hasNext: result.hasNext
|
|
19490
|
+
});
|
|
19491
|
+
}
|
|
19492
|
+
}
|
|
19493
|
+
renderAccountAppUsers(result, asJson) {
|
|
19494
|
+
if (asJson) {
|
|
19495
|
+
ui.plain(JSON.stringify(result, null, 2));
|
|
19496
|
+
return;
|
|
19497
|
+
}
|
|
19498
|
+
if (result.items.length === 0) {
|
|
19499
|
+
ui.warn("No app users found.");
|
|
19500
|
+
return;
|
|
19501
|
+
}
|
|
19502
|
+
for (const item of result.items) {
|
|
19503
|
+
ui.info(item.account.id, {
|
|
19504
|
+
mobile: item.account.mobile,
|
|
19505
|
+
nickNames: item.nickNames,
|
|
19506
|
+
roles: item.roles.map((role) => `${role.namespace}/${role.role}`),
|
|
19507
|
+
sources: item.sources
|
|
19508
|
+
});
|
|
19509
|
+
}
|
|
19510
|
+
ui.info(`page ${result.page}`, {
|
|
19511
|
+
pageSize: result.pageSize,
|
|
19512
|
+
total: result.total,
|
|
19513
|
+
totalPages: result.totalPages,
|
|
19514
|
+
hasNext: result.hasNext
|
|
19515
|
+
});
|
|
19516
|
+
}
|
|
19443
19517
|
renderJson(value, asJson) {
|
|
19444
19518
|
if (!asJson) {
|
|
19445
19519
|
return;
|
|
@@ -21514,7 +21588,93 @@ function parseAccountArgs(tokens) {
|
|
|
21514
21588
|
const rest = [...tokens];
|
|
21515
21589
|
const action = rest.shift();
|
|
21516
21590
|
if (!action) {
|
|
21517
|
-
throw new Error("Missing account action. Use: account view|role");
|
|
21591
|
+
throw new Error("Missing account action. Use: account list|view|app-users|role");
|
|
21592
|
+
}
|
|
21593
|
+
if (action === "list") {
|
|
21594
|
+
let mobile;
|
|
21595
|
+
let nickName;
|
|
21596
|
+
let page;
|
|
21597
|
+
let pageSize;
|
|
21598
|
+
let baseUrl2;
|
|
21599
|
+
let json2 = false;
|
|
21600
|
+
while (rest.length > 0) {
|
|
21601
|
+
const token = rest.shift();
|
|
21602
|
+
switch (token) {
|
|
21603
|
+
case "--mobile":
|
|
21604
|
+
mobile = requireValue8(rest, token);
|
|
21605
|
+
break;
|
|
21606
|
+
case "--nickname":
|
|
21607
|
+
case "--nickName":
|
|
21608
|
+
nickName = requireValue8(rest, token);
|
|
21609
|
+
break;
|
|
21610
|
+
case "--page":
|
|
21611
|
+
page = parsePositiveInt(requireValue8(rest, token), token);
|
|
21612
|
+
break;
|
|
21613
|
+
case "--page-size":
|
|
21614
|
+
pageSize = parsePositiveInt(requireValue8(rest, token), token);
|
|
21615
|
+
break;
|
|
21616
|
+
case "--base-url":
|
|
21617
|
+
baseUrl2 = requireValue8(rest, token);
|
|
21618
|
+
break;
|
|
21619
|
+
case "--json":
|
|
21620
|
+
json2 = true;
|
|
21621
|
+
break;
|
|
21622
|
+
default:
|
|
21623
|
+
throw new Error(`Unknown account list option: ${token}`);
|
|
21624
|
+
}
|
|
21625
|
+
}
|
|
21626
|
+
if (mobile && nickName) {
|
|
21627
|
+
throw new Error(
|
|
21628
|
+
"Usage: account list [--page <n>] [--page-size <n>] [--mobile <mobile> | --nickname <nickname>] [--base-url <url>] [--json]"
|
|
21629
|
+
);
|
|
21630
|
+
}
|
|
21631
|
+
return {
|
|
21632
|
+
type: "account" /* Account */,
|
|
21633
|
+
action: "list",
|
|
21634
|
+
page,
|
|
21635
|
+
pageSize,
|
|
21636
|
+
mobile,
|
|
21637
|
+
nickName,
|
|
21638
|
+
baseUrl: baseUrl2,
|
|
21639
|
+
json: json2
|
|
21640
|
+
};
|
|
21641
|
+
}
|
|
21642
|
+
if (action === "app-users") {
|
|
21643
|
+
const app = parseNamespacedRef(requireValue8(rest, "app-users"), {
|
|
21644
|
+
entityLabel: "app ref"
|
|
21645
|
+
}).fullId;
|
|
21646
|
+
let page;
|
|
21647
|
+
let pageSize;
|
|
21648
|
+
let baseUrl2;
|
|
21649
|
+
let json2 = false;
|
|
21650
|
+
while (rest.length > 0) {
|
|
21651
|
+
const token = rest.shift();
|
|
21652
|
+
switch (token) {
|
|
21653
|
+
case "--page":
|
|
21654
|
+
page = parsePositiveInt(requireValue8(rest, token), token);
|
|
21655
|
+
break;
|
|
21656
|
+
case "--page-size":
|
|
21657
|
+
pageSize = parsePositiveInt(requireValue8(rest, token), token);
|
|
21658
|
+
break;
|
|
21659
|
+
case "--base-url":
|
|
21660
|
+
baseUrl2 = requireValue8(rest, token);
|
|
21661
|
+
break;
|
|
21662
|
+
case "--json":
|
|
21663
|
+
json2 = true;
|
|
21664
|
+
break;
|
|
21665
|
+
default:
|
|
21666
|
+
throw new Error(`Unknown account app-users option: ${token}`);
|
|
21667
|
+
}
|
|
21668
|
+
}
|
|
21669
|
+
return {
|
|
21670
|
+
type: "account" /* Account */,
|
|
21671
|
+
action: "app-users",
|
|
21672
|
+
app,
|
|
21673
|
+
page,
|
|
21674
|
+
pageSize,
|
|
21675
|
+
baseUrl: baseUrl2,
|
|
21676
|
+
json: json2
|
|
21677
|
+
};
|
|
21518
21678
|
}
|
|
21519
21679
|
if (action === "view") {
|
|
21520
21680
|
let account2;
|
|
@@ -21737,6 +21897,13 @@ function requireValue8(tokens, optionName) {
|
|
|
21737
21897
|
}
|
|
21738
21898
|
return value;
|
|
21739
21899
|
}
|
|
21900
|
+
function parsePositiveInt(value, optionName) {
|
|
21901
|
+
const parsed = Number(value);
|
|
21902
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
21903
|
+
throw new Error(`${optionName} must be a positive integer`);
|
|
21904
|
+
}
|
|
21905
|
+
return parsed;
|
|
21906
|
+
}
|
|
21740
21907
|
|
|
21741
21908
|
// src/orgCommandParser.ts
|
|
21742
21909
|
init_namespacedRef();
|
|
@@ -22265,7 +22432,9 @@ var HELP_TEXT = [
|
|
|
22265
22432
|
` ${import_chalk4.default.gray(" definition create <role> [--display-name <name>] [--description <text>] [--base-url <url>] [--json]")}`,
|
|
22266
22433
|
` ${import_chalk4.default.gray(" default base URL: https://auth-api-v2.pmate.chat")}`,
|
|
22267
22434
|
` ${import_chalk4.default.cyan("account")} View accounts and manage account role bindings`,
|
|
22435
|
+
` ${import_chalk4.default.gray(" list [--page <n>] [--page-size <n>] [--mobile <mobile> | --nickname <nickname>] [--base-url <url>] [--json]")}`,
|
|
22268
22436
|
` ${import_chalk4.default.gray(" view (--account <id> | --mobile <mobile> | --nickname <nickname>) [--base-url <url>] [--json]")}`,
|
|
22437
|
+
` ${import_chalk4.default.gray(" app-users <ns:app> [--page <n>] [--page-size <n>] [--base-url <url>] [--json]")}`,
|
|
22269
22438
|
` ${import_chalk4.default.gray(" role list --account <id> [--namespace <ns>] [--base-url <url>] [--json]")}`,
|
|
22270
22439
|
` ${import_chalk4.default.gray(" role add --account <id> --namespace <ns> --role <role> [--base-url <url>] [--json]")}`,
|
|
22271
22440
|
` ${import_chalk4.default.gray(" role remove --account <id> --namespace <ns> --role <role> [--base-url <url>] [--json]")}`,
|
|
@@ -23913,7 +24082,7 @@ function parseRandomArgs(tokens) {
|
|
|
23913
24082
|
mode = "easy";
|
|
23914
24083
|
break;
|
|
23915
24084
|
case "--length":
|
|
23916
|
-
length =
|
|
24085
|
+
length = parsePositiveInt2(requireValue12(rest, token), token);
|
|
23917
24086
|
seenLength = true;
|
|
23918
24087
|
break;
|
|
23919
24088
|
case "--charset": {
|
|
@@ -23928,10 +24097,10 @@ function parseRandomArgs(tokens) {
|
|
|
23928
24097
|
break;
|
|
23929
24098
|
}
|
|
23930
24099
|
case "--count":
|
|
23931
|
-
count =
|
|
24100
|
+
count = parsePositiveInt2(requireValue12(rest, token), token);
|
|
23932
24101
|
break;
|
|
23933
24102
|
case "--words":
|
|
23934
|
-
words =
|
|
24103
|
+
words = parsePositiveInt2(requireValue12(rest, token), token);
|
|
23935
24104
|
seenWords = true;
|
|
23936
24105
|
break;
|
|
23937
24106
|
case "--digits":
|
|
@@ -23980,7 +24149,7 @@ function requireValue12(tokens, optionName) {
|
|
|
23980
24149
|
function decodeEscapedNewlines(value) {
|
|
23981
24150
|
return value.replace(/(?<!\\)\\r\\n/g, "\n").replace(/(?<!\\)\\n/g, "\n").replace(/(?<!\\)\\r/g, "\n");
|
|
23982
24151
|
}
|
|
23983
|
-
function
|
|
24152
|
+
function parsePositiveInt2(value, optionName) {
|
|
23984
24153
|
const parsed = Number.parseInt(value, 10);
|
|
23985
24154
|
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
23986
24155
|
throw new Error(`Invalid ${optionName} value: ${value}`);
|