lansenger-cli 1.0.0 → 1.0.2

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.
@@ -2,26 +2,33 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.registerConfigCommands = registerConfigCommands;
4
4
  const utils_1 = require("../utils");
5
+ const VALID_KEYS = ["app_id", "app_secret", "api_gateway_url", "passport_url", "encoding_key", "callback_token"];
5
6
  function registerConfigCommands(program) {
6
7
  const cmd = program.command("config").description("Manage CLI configuration and credentials");
7
8
  cmd
8
9
  .command("set")
9
10
  .description("Set credentials (app_id, app_secret, api_gateway_url, passport_url, encoding_key, callback_token)")
10
- .requiredOption("--app-id <appId>", "App ID")
11
- .requiredOption("--app-secret <appSecret>", "App Secret")
12
- .option("--api-gateway-url <url>", "API Gateway URL")
13
- .option("--passport-url <url>", "Passport URL")
14
- .option("--encoding-key <key>", "Encoding AES key")
15
- .option("--callback-token <token>", "Callback verification token")
16
- .action(async (opts) => {
11
+ .argument("<key>", `Config key: ${VALID_KEYS.join(", ")}`)
12
+ .argument("<value>", "Config value")
13
+ .option("-P, --profile <profile>", "Profile name (overrides global --profile)")
14
+ .action((key, value, opts) => {
15
+ if (!VALID_KEYS.includes(key)) {
16
+ console.error(`Error: Invalid key '${key}'. Valid keys: ${VALID_KEYS.join(", ")}`);
17
+ process.exit(1);
18
+ }
19
+ const p = opts.profile || utils_1.activeProfile;
17
20
  const store = (0, utils_1.getStore)();
18
- store.saveCredentials(opts.appId, opts.appSecret, opts.apiGatewayUrl || "", opts.passportUrl || "", opts.encodingKey || "", opts.callbackToken || "");
19
- (0, utils_1.outputResult)({ success: true, message: "Credentials saved", profile: store.currentProfile });
21
+ const creds = store.loadCredentials();
22
+ creds[key] = value;
23
+ store.saveCredentials(creds.app_id || "", creds.app_secret || "", creds.api_gateway_url || "", creds.passport_url || "", creds.encoding_key || "", creds.callback_token || "");
24
+ (0, utils_1.outputResult)({ success: true, message: `Set ${key} = ${value}`, profile: p });
20
25
  });
21
26
  cmd
22
27
  .command("show")
23
28
  .description("Show current configuration")
24
- .action(async () => {
29
+ .option("-P, --profile <profile>", "Profile name (overrides global --profile)")
30
+ .action((opts) => {
31
+ const p = opts.profile || utils_1.activeProfile;
25
32
  const store = (0, utils_1.getStore)();
26
33
  const creds = store.loadCredentials();
27
34
  const masked = {
@@ -31,7 +38,7 @@ function registerConfigCommands(program) {
31
38
  passport_url: creds.passport_url,
32
39
  encoding_key: creds.encoding_key ? "(set)" : "(not set)",
33
40
  callback_token: creds.callback_token ? "(set)" : "(not set)",
34
- profile: store.currentProfile,
41
+ profile: p,
35
42
  has_full_config: store.hasFullConfig(),
36
43
  };
37
44
  (0, utils_1.outputResult)(masked);
@@ -39,15 +46,24 @@ function registerConfigCommands(program) {
39
46
  cmd
40
47
  .command("clear")
41
48
  .description("Clear stored credentials for current profile")
42
- .action(async () => {
49
+ .option("-P, --profile <profile>", "Profile name (overrides global --profile)")
50
+ .option("--all", "Delete entire state file (all profiles)", false)
51
+ .action((opts) => {
52
+ if (opts.all) {
53
+ const store = (0, utils_1.getStore)();
54
+ store.clear();
55
+ (0, utils_1.outputResult)({ success: true, message: "Cleared entire state file (all profiles)." });
56
+ return;
57
+ }
58
+ const p = opts.profile || utils_1.activeProfile;
43
59
  const store = (0, utils_1.getStore)();
44
60
  store.clearProfile();
45
- (0, utils_1.outputResult)({ success: true, message: "Credentials cleared for profile: " + store.currentProfile });
61
+ (0, utils_1.outputResult)({ success: true, message: `Cleared profile '${p}'.` });
46
62
  });
47
63
  cmd
48
64
  .command("list-profiles")
49
65
  .description("List all stored credential profiles")
50
- .action(async () => {
66
+ .action(() => {
51
67
  const store = (0, utils_1.getStore)();
52
68
  const profiles = store.listProfiles();
53
69
  const active = store.getActiveProfile();
@@ -3,42 +3,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.registerDepartmentCommands = registerDepartmentCommands;
4
4
  const utils_1 = require("../utils");
5
5
  function registerDepartmentCommands(program) {
6
- const cmd = program.command("department").description("Query department/organization structure");
6
+ const cmd = program.command("department").description("Query department information");
7
7
  cmd
8
8
  .command("detail")
9
9
  .description("Fetch department detail")
10
- .requiredOption("--dept-id <deptId>", "Department ID")
11
- .option("--user-token <token>", "User token")
12
- .action(async (opts) => {
10
+ .argument("<departmentId>", "Department ID")
11
+ .option("--user-token <token>", "User token", "")
12
+ .option("--tag-id <tagId>", "Tag ID", "")
13
+ .action(async (departmentId, opts) => {
13
14
  const client = (0, utils_1.getClient)();
14
- const result = await client.fetchDepartmentDetail(opts.deptId, { user_token: opts.userToken || undefined });
15
+ const result = await client.fetchDepartmentDetail(departmentId, {
16
+ user_token: opts.userToken || undefined,
17
+ tag_id: opts.tagId || undefined,
18
+ });
15
19
  (0, utils_1.checkError)(result);
16
20
  (0, utils_1.outputResult)(result);
17
21
  });
18
22
  cmd
19
23
  .command("children")
20
24
  .description("Fetch child departments")
21
- .requiredOption("--dept-id <deptId>", "Department ID")
22
- .option("--user-token <token>", "User token")
23
- .action(async (opts) => {
25
+ .argument("<departmentId>", "Department ID")
26
+ .option("--user-token <token>", "User token", "")
27
+ .action(async (departmentId, opts) => {
24
28
  const client = (0, utils_1.getClient)();
25
- const result = await client.fetchDepartmentChildren(opts.deptId, { user_token: opts.userToken || undefined });
29
+ const result = await client.fetchDepartmentChildren(departmentId, { user_token: opts.userToken || undefined });
26
30
  (0, utils_1.checkError)(result);
27
31
  (0, utils_1.outputResult)(result);
28
32
  });
29
33
  cmd
30
34
  .command("staffs")
31
35
  .description("Fetch staff members of a department")
32
- .requiredOption("--dept-id <deptId>", "Department ID")
33
- .option("--page <page>", "Page number", "1")
34
- .option("--size <size>", "Page size", "50")
35
- .option("--user-token <token>", "User token")
36
- .action(async (opts) => {
36
+ .argument("<departmentId>", "Department ID")
37
+ .option("--user-token <token>", "User token", "")
38
+ .option("-p, --page <page>", "Page number", "1")
39
+ .option("-s, --size <size>", "Page size", "100")
40
+ .action(async (departmentId, opts) => {
37
41
  const client = (0, utils_1.getClient)();
38
- const result = await client.fetchDepartmentStaffs(opts.deptId, {
42
+ const result = await client.fetchDepartmentStaffs(departmentId, {
43
+ user_token: opts.userToken || undefined,
39
44
  page: parseInt(opts.page),
40
45
  page_size: parseInt(opts.size),
41
- user_token: opts.userToken || undefined,
42
46
  });
43
47
  (0, utils_1.checkError)(result);
44
48
  (0, utils_1.outputResult)(result);
@@ -7,16 +7,23 @@ function registerGroupCommands(program) {
7
7
  cmd
8
8
  .command("create")
9
9
  .description("Create a new group")
10
- .requiredOption("--name <name>", "Group name")
11
- .requiredOption("--org-id <orgId>", "Organization ID")
12
- .option("--staff-id-list <ids>", "Comma-separated initial member staff IDs")
13
- .option("--owner-id <ownerId>", "Group owner ID")
14
- .action(async (opts) => {
10
+ .argument("<name>", "Group name")
11
+ .argument("<orgId>", "Organization ID")
12
+ .option("--owner <ownerId>", "Owner staff ID", "")
13
+ .option("-d, --desc <desc>", "Group description", "")
14
+ .option("--avatar <avatarId>", "Avatar ID", "")
15
+ .option("--staff <ids...>", "Staff IDs to add, space-separated")
16
+ .option("--dept <ids...>", "Department IDs to add, space-separated")
17
+ .option("--user-token <token>", "User token", "")
18
+ .action(async (name, orgId, opts) => {
15
19
  const client = (0, utils_1.getClient)();
16
- const staffIdList = opts.staffIdList ? (0, utils_1.commaList)(opts.staffIdList) : undefined;
17
- const result = await client.createGroup(opts.name, opts.orgId, {
18
- staff_id_list: staffIdList,
19
- owner_id: opts.ownerId || undefined,
20
+ const result = await client.createGroup(name, orgId, {
21
+ owner_id: opts.owner || undefined,
22
+ description: opts.desc || undefined,
23
+ avatar_id: opts.avatar || undefined,
24
+ staff_id_list: opts.staff || undefined,
25
+ department_id_list: opts.dept || undefined,
26
+ user_token: opts.userToken || undefined,
20
27
  });
21
28
  (0, utils_1.checkError)(result);
22
29
  (0, utils_1.outputResult)(result);
@@ -24,44 +31,56 @@ function registerGroupCommands(program) {
24
31
  cmd
25
32
  .command("info")
26
33
  .description("Fetch group info")
27
- .requiredOption("--group-id <groupId>", "Group ID")
28
- .option("--user-token <token>", "User token")
29
- .action(async (opts) => {
34
+ .argument("<groupId>", "Group ID")
35
+ .option("--user-token <token>", "User token", "")
36
+ .action(async (groupId, opts) => {
30
37
  const client = (0, utils_1.getClient)();
31
- const result = await client.fetchGroupInfo(opts.groupId, { user_token: opts.userToken || undefined });
38
+ const result = await client.fetchGroupInfo(groupId, { user_token: opts.userToken || undefined });
32
39
  (0, utils_1.checkError)(result);
33
40
  (0, utils_1.outputResult)(result);
34
41
  });
35
42
  cmd
36
43
  .command("members")
37
44
  .description("Fetch group members")
38
- .requiredOption("--group-id <groupId>", "Group ID")
39
- .option("--user-token <token>", "User token")
40
- .action(async (opts) => {
45
+ .argument("<groupId>", "Group ID")
46
+ .option("--user-token <token>", "User token", "")
47
+ .option("-p, --page <page>", "Page offset", "0")
48
+ .option("-s, --size <size>", "Page size", "100")
49
+ .action(async (groupId, opts) => {
41
50
  const client = (0, utils_1.getClient)();
42
- const result = await client.fetchGroupMembers(opts.groupId, { user_token: opts.userToken || undefined });
51
+ const result = await client.fetchGroupMembers(groupId, {
52
+ user_token: opts.userToken || undefined,
53
+ page_offset: parseInt(opts.page),
54
+ page_size: parseInt(opts.size),
55
+ });
43
56
  (0, utils_1.checkError)(result);
44
57
  (0, utils_1.outputResult)(result);
45
58
  });
46
59
  cmd
47
60
  .command("list")
48
61
  .description("List all groups")
49
- .option("--user-token <token>", "User token")
62
+ .option("--user-token <token>", "User token", "")
63
+ .option("-p, --page <page>", "Page offset", "0")
64
+ .option("-s, --size <size>", "Page size", "100")
50
65
  .action(async (opts) => {
51
66
  const client = (0, utils_1.getClient)();
52
- const result = await client.fetchGroupList({ user_token: opts.userToken || undefined });
67
+ const result = await client.fetchGroupList({
68
+ user_token: opts.userToken || undefined,
69
+ page_offset: parseInt(opts.page),
70
+ page_size: parseInt(opts.size),
71
+ });
53
72
  (0, utils_1.checkError)(result);
54
73
  (0, utils_1.outputResult)(result);
55
74
  });
56
75
  cmd
57
76
  .command("check")
58
77
  .description("Check if a user is in a group")
59
- .requiredOption("--group-id <groupId>", "Group ID")
60
- .option("--staff-id <staffId>", "Staff ID to check")
61
- .option("--user-token <token>", "User token")
62
- .action(async (opts) => {
78
+ .argument("<groupId>", "Group ID")
79
+ .option("--user-token <token>", "User token", "")
80
+ .option("--staff-id <staffId>", "Staff ID to check", "")
81
+ .action(async (groupId, opts) => {
63
82
  const client = (0, utils_1.getClient)();
64
- const result = await client.checkIsInGroup(opts.groupId, {
83
+ const result = await client.checkIsInGroup(groupId, {
65
84
  staff_id: opts.staffId || undefined,
66
85
  user_token: opts.userToken || undefined,
67
86
  });
@@ -71,13 +90,17 @@ function registerGroupCommands(program) {
71
90
  cmd
72
91
  .command("update")
73
92
  .description("Update group info")
74
- .requiredOption("--group-id <groupId>", "Group ID")
75
- .option("--name <name>", "New group name")
76
- .option("--user-token <token>", "User token")
77
- .action(async (opts) => {
93
+ .argument("<groupId>", "Group ID")
94
+ .option("--name <name>", "New group name", "")
95
+ .option("--desc <desc>", "New description", "")
96
+ .option("--owner <ownerId>", "New owner ID", "")
97
+ .option("--user-token <token>", "User token", "")
98
+ .action(async (groupId, opts) => {
78
99
  const client = (0, utils_1.getClient)();
79
- const result = await client.updateGroupInfo(opts.groupId, {
100
+ const result = await client.updateGroupInfo(groupId, {
80
101
  name: opts.name || undefined,
102
+ description: opts.desc || undefined,
103
+ owner_id: opts.owner || undefined,
81
104
  user_token: opts.userToken || undefined,
82
105
  });
83
106
  (0, utils_1.checkError)(result);
@@ -86,17 +109,17 @@ function registerGroupCommands(program) {
86
109
  cmd
87
110
  .command("update-members")
88
111
  .description("Add or remove group members")
89
- .requiredOption("--group-id <groupId>", "Group ID")
90
- .option("--add <ids>", "Comma-separated staff IDs to add")
91
- .option("--del <ids>", "Comma-separated staff IDs to remove")
92
- .option("--user-token <token>", "User token")
93
- .action(async (opts) => {
112
+ .argument("<groupId>", "Group ID")
113
+ .option("--add <ids...>", "Staff IDs to add, space-separated")
114
+ .option("--remove <ids...>", "Staff IDs to remove, space-separated")
115
+ .option("--add-dept <ids...>", "Department IDs to add, space-separated")
116
+ .option("--user-token <token>", "User token", "")
117
+ .action(async (groupId, opts) => {
94
118
  const client = (0, utils_1.getClient)();
95
- const addUserList = opts.add ? (0, utils_1.commaList)(opts.add) : undefined;
96
- const delUserList = opts.del ? (0, utils_1.commaList)(opts.del) : undefined;
97
- const result = await client.updateGroupMembers(opts.groupId, {
98
- add_user_list: addUserList,
99
- del_user_list: delUserList,
119
+ const result = await client.updateGroupMembers(groupId, {
120
+ add_user_list: opts.add || undefined,
121
+ del_user_list: opts.remove || undefined,
122
+ add_department_id_list: opts.addDept || undefined,
100
123
  user_token: opts.userToken || undefined,
101
124
  });
102
125
  (0, utils_1.checkError)(result);
@@ -105,11 +128,11 @@ function registerGroupCommands(program) {
105
128
  cmd
106
129
  .command("dismiss")
107
130
  .description("Dismiss/delete a group")
108
- .requiredOption("--group-id <groupId>", "Group ID")
109
- .option("--user-token <token>", "User token")
110
- .action(async (opts) => {
131
+ .argument("<groupId>", "Group ID to dismiss/delete")
132
+ .option("--user-token <token>", "User token", "")
133
+ .action(async (groupId, opts) => {
111
134
  const client = (0, utils_1.getClient)();
112
- const result = await client.dismissGroup(opts.groupId, { user_token: opts.userToken || undefined });
135
+ const result = await client.dismissGroup(groupId, { user_token: opts.userToken || undefined });
113
136
  (0, utils_1.checkError)(result);
114
137
  (0, utils_1.outputResult)(result);
115
138
  });
@@ -3,16 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.registerMediaCommands = registerMediaCommands;
4
4
  const utils_1 = require("../utils");
5
5
  function registerMediaCommands(program) {
6
- const cmd = program.command("media").description("Upload, download, and manage media files");
6
+ const cmd = program.command("media").description("Upload and download media files");
7
7
  cmd
8
8
  .command("upload")
9
9
  .description("Upload a media file")
10
- .requiredOption("--file-path <path>", "File path to upload")
11
- .option("--media-type <type>", "Media type (1=video,2=image,3=file)")
12
- .action(async (opts) => {
10
+ .argument("<filePath>", "Local file path to upload")
11
+ .option("-t, --media-type <type>", "1=video, 2=image, 3=file (4.5.1 core service)", "3")
12
+ .option("--user-token <token>", "User token (optional for 4.5.1)", "")
13
+ .action(async (filePath, opts) => {
13
14
  const client = (0, utils_1.getClient)();
14
- const result = await client.uploadMediaFile(opts.filePath, {
15
- media_type: opts.mediaType ? parseInt(opts.mediaType) : undefined,
15
+ const result = await client.uploadMediaFile(filePath, {
16
+ media_type: parseInt(opts.mediaType),
17
+ user_token: opts.userToken || undefined,
18
+ });
19
+ (0, utils_1.checkError)(result);
20
+ (0, utils_1.outputResult)(result);
21
+ });
22
+ cmd
23
+ .command("upload-app")
24
+ .description("Upload media for app/bot usage (4.5.4 API)")
25
+ .argument("<filePath>", "Local file path to upload")
26
+ .option("-t, --media-type <type>", "file, video, image, audio (4.5.4 app/bot)", "file")
27
+ .option("--width <width>", "Width for video/image", "0")
28
+ .option("--height <height>", "Height for video/image", "0")
29
+ .option("--duration <duration>", "Duration in seconds for video/audio", "0")
30
+ .action(async (filePath, opts) => {
31
+ const client = (0, utils_1.getClient)();
32
+ const result = await client.uploadAppMediaFile(filePath, {
33
+ media_type: opts.mediaType,
34
+ width: parseInt(opts.width) || undefined,
35
+ height: parseInt(opts.height) || undefined,
36
+ duration: parseInt(opts.duration) || undefined,
16
37
  });
17
38
  (0, utils_1.checkError)(result);
18
39
  (0, utils_1.outputResult)(result);
@@ -20,10 +41,10 @@ function registerMediaCommands(program) {
20
41
  cmd
21
42
  .command("download")
22
43
  .description("Download a media file (to stdout as binary)")
23
- .requiredOption("--media-id <mediaId>", "Media ID")
24
- .action(async (opts) => {
44
+ .argument("<mediaId>", "Media ID to download")
45
+ .action(async (mediaId) => {
25
46
  const client = (0, utils_1.getClient)();
26
- const result = await client.downloadMediaFile(opts.mediaId);
47
+ const result = await client.downloadMediaFile(mediaId);
27
48
  (0, utils_1.checkError)(result);
28
49
  if (result.success && result.data) {
29
50
  process.stdout.write(result.data);
@@ -35,23 +56,25 @@ function registerMediaCommands(program) {
35
56
  cmd
36
57
  .command("download-to-file")
37
58
  .description("Download a media file to a local file")
38
- .requiredOption("--media-id <mediaId>", "Media ID")
39
- .option("--target-path <path>", "Target file path")
40
- .action(async (opts) => {
59
+ .argument("<mediaId>", "Media ID to download")
60
+ .option("-o, --output <path>", "Target file path", "")
61
+ .option("--media-type <type>", "file, image, or video", "file")
62
+ .action(async (mediaId, opts) => {
41
63
  const client = (0, utils_1.getClient)();
42
- const savedPath = await client.downloadMediaToFile(opts.mediaId, {
43
- target_path: opts.targetPath || undefined,
64
+ const savedPath = await client.downloadMediaToFile(mediaId, {
65
+ target_path: opts.output || undefined,
66
+ media_type: opts.mediaType,
44
67
  });
45
68
  (0, utils_1.outputResult)({ success: true, path: savedPath });
46
69
  });
47
70
  cmd
48
71
  .command("path")
49
72
  .description("Fetch media path info")
50
- .requiredOption("--media-id <mediaId>", "Media ID")
51
- .option("--user-token <token>", "User token")
52
- .action(async (opts) => {
73
+ .argument("<mediaId>", "Media ID to get path for")
74
+ .option("--user-token <token>", "User token", "")
75
+ .action(async (mediaId, opts) => {
53
76
  const client = (0, utils_1.getClient)();
54
- const result = await client.fetchMediaPathInfo(opts.mediaId, { user_token: opts.userToken || undefined });
77
+ const result = await client.fetchMediaPathInfo(mediaId, { user_token: opts.userToken || undefined });
55
78
  (0, utils_1.checkError)(result);
56
79
  (0, utils_1.outputResult)(result);
57
80
  });