@apet97/clockify-cli-115 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,65 @@
1
+ import { entityId } from "clockify-sdk-ts-115/operation-receipt";
2
+ import { printReceipt } from "../receipt.js";
3
+ import { resolveContext } from "./helpers.js";
4
+ import { resolveProjectId, resolveTaskId, resolveTagIds } from "./resolve-refs.js";
5
+ export const registerStartCommand = (program, services) => {
6
+ program
7
+ .command("start")
8
+ .description("Start a running time entry. Resolves project/task/tag names to IDs automatically.")
9
+ .argument("[description]", "Description for the time entry.")
10
+ .option("-p, --project <name>", "Project name or ID.")
11
+ .option("-t, --task <name>", "Task name or ID.")
12
+ .option("--tag <name...>", "Tag name(s) or ID(s). Repeat the flag for multiple tags.")
13
+ .option("--billable", "Mark the entry as billable.", false)
14
+ .action(async function (description, opts) {
15
+ const { client, workspaceId, output } = await resolveContext(this, services);
16
+ const user = await client.users.getCurrentUser();
17
+ const userId = entityId(user);
18
+ if (!userId) {
19
+ throw new Error("could not determine user ID from getCurrentUser response");
20
+ }
21
+ const projectId = opts.project
22
+ ? await resolveProjectId(client, workspaceId, opts.project)
23
+ : undefined;
24
+ if (opts.task && !projectId) {
25
+ throw new Error("--task requires --project: a task can only be resolved within a project.");
26
+ }
27
+ const taskId = opts.task && projectId
28
+ ? await resolveTaskId(client, workspaceId, projectId, opts.task)
29
+ : undefined;
30
+ const tagIds = opts.tag
31
+ ? await resolveTagIds(client, workspaceId, opts.tag)
32
+ : undefined;
33
+ const body = {
34
+ start: new Date().toISOString(),
35
+ };
36
+ if (description)
37
+ body.description = description;
38
+ if (projectId)
39
+ body.projectId = projectId;
40
+ if (taskId)
41
+ body.taskId = taskId;
42
+ if (tagIds && tagIds.length > 0)
43
+ body.tagIds = tagIds;
44
+ if (opts.billable)
45
+ body.billable = true;
46
+ const req = { workspaceId, body };
47
+ const created = await client.timeEntries.create(req);
48
+ const entry = created;
49
+ const data = {
50
+ id: entry.id ?? "",
51
+ description: entry.description ?? "",
52
+ projectId: entry.projectId ?? "",
53
+ startedAt: entry.timeInterval?.start ?? body.start,
54
+ };
55
+ printReceipt({
56
+ ok: true,
57
+ action: "timer.start",
58
+ entity: "time_entry",
59
+ ids: { entryId: data.id },
60
+ data,
61
+ changed: { created: [{ type: "time_entry", id: data.id }] },
62
+ next: [{ command: "clk115 stop --json", reason: "Stop this running timer." }],
63
+ }, output);
64
+ });
65
+ };
@@ -0,0 +1,66 @@
1
+ import { entityId } from "clockify-sdk-ts-115/operation-receipt";
2
+ import { formatIsoDuration } from "../duration.js";
3
+ import { printObject } from "../output.js";
4
+ import { resolveBaseContext } from "./helpers.js";
5
+ export const registerStatusCommand = (program, services) => {
6
+ program
7
+ .command("status")
8
+ .description("Show the configured workspace, current user, and running timer.")
9
+ .action(async function () {
10
+ const { client, config, output } = await resolveBaseContext(this, services);
11
+ const user = await client.users.getCurrentUser();
12
+ if (!config.workspaceId) {
13
+ const workspaces = (await client.workspaces.list());
14
+ printObject({
15
+ userId: entityId(user) ?? "",
16
+ email: user.email ?? "",
17
+ workspaceId: "(not set)",
18
+ availableWorkspaces: workspaces.map((w) => ({ id: w.id ?? "", name: w.name ?? "" })),
19
+ hint: "Set CLOCKIFY_WORKSPACE_ID (or pass --workspace, or add workspaceId to ~/.clockifyrc.json) to one of the ids above.",
20
+ }, output);
21
+ return;
22
+ }
23
+ const workspaceId = config.workspaceId;
24
+ const inProgressResp = await client.timeEntries.listInProgress({ workspaceId });
25
+ const entries = normaliseEntries(inProgressResp);
26
+ const running = entries.find((entry) => isOwn(entry, user)) ?? null;
27
+ printObject({
28
+ workspaceId,
29
+ userId: entityId(user) ?? "",
30
+ email: user.email ?? "",
31
+ name: user.name ?? "",
32
+ runningEntry: running
33
+ ? {
34
+ id: entityId(running),
35
+ description: running.description ?? "",
36
+ projectId: running.projectId ?? "",
37
+ startedAt: extractStart(running),
38
+ elapsed: formatIsoDuration(extractIsoDuration(running)),
39
+ }
40
+ : "(no timer running)",
41
+ }, output);
42
+ });
43
+ };
44
+ function normaliseEntries(resp) {
45
+ if (Array.isArray(resp))
46
+ return resp;
47
+ if (resp && typeof resp === "object") {
48
+ const candidate = resp.timeEntries ?? resp.data;
49
+ if (Array.isArray(candidate))
50
+ return candidate;
51
+ }
52
+ return [];
53
+ }
54
+ function isOwn(entry, user) {
55
+ const entryUserId = entry.userId;
56
+ const userId = entityId(user);
57
+ return entryUserId !== undefined && userId !== undefined && entryUserId === userId;
58
+ }
59
+ function extractStart(entry) {
60
+ const interval = entry.timeInterval;
61
+ return interval?.start ?? "";
62
+ }
63
+ function extractIsoDuration(entry) {
64
+ const interval = entry.timeInterval;
65
+ return interval?.duration ?? null;
66
+ }
@@ -0,0 +1,41 @@
1
+ import { entityId } from "clockify-sdk-ts-115/operation-receipt";
2
+ import { printSuccess } from "../output.js";
3
+ import { printReceipt } from "../receipt.js";
4
+ import { resolveContext } from "./helpers.js";
5
+ export const registerStopCommand = (program, services) => {
6
+ program
7
+ .command("stop")
8
+ .description("Stop the running timer for the current user.")
9
+ .action(async function () {
10
+ const { client, workspaceId, output } = await resolveContext(this, services);
11
+ const user = await client.users.getCurrentUser();
12
+ const userId = entityId(user);
13
+ if (!userId) {
14
+ throw new Error("could not determine user ID from getCurrentUser response");
15
+ }
16
+ const inProgress = (await client.timeEntries.listInProgress({ workspaceId }));
17
+ const running = inProgress.find((entry) => entry.userId === userId && entry.id);
18
+ if (!running) {
19
+ printSuccess("no timer was running", output);
20
+ return;
21
+ }
22
+ const end = new Date().toISOString();
23
+ const stopped = await client.timeEntries.updateForUser({ workspaceId, userId, end });
24
+ const entry = stopped;
25
+ const data = {
26
+ ...entry,
27
+ id: entry.id ?? "",
28
+ description: entry.description ?? "",
29
+ duration: entry.timeInterval?.duration ?? "",
30
+ };
31
+ printReceipt({
32
+ ok: true,
33
+ action: "timer.stop",
34
+ entity: "time_entry",
35
+ ids: { entryId: data.id },
36
+ data,
37
+ changed: { updated: [{ type: "time_entry", id: data.id }] },
38
+ next: [{ command: "clk115 entries list --json", reason: "Review the stopped entry." }],
39
+ }, output);
40
+ });
41
+ };
@@ -0,0 +1,109 @@
1
+ import { printObject, printRecords } from "../output.js";
2
+ import { printReceipt } from "../receipt.js";
3
+ import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
4
+ export const registerTagsCommand = (program, services) => {
5
+ const tags = program.command("tags").description("Manage tags.");
6
+ tags.command("list")
7
+ .description("List tags in the workspace.")
8
+ .option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
9
+ .option("--page <n>", "Page number.", parseIntArg, 1)
10
+ .option("--name <text>", "Filter by tag name substring.")
11
+ .option("--archived", "Include archived tags.", false)
12
+ .action(async function (opts) {
13
+ const { client, workspaceId, output } = await resolveContext(this, services);
14
+ const req = {
15
+ workspaceId,
16
+ page: opts.page,
17
+ "page-size": clampPageSize(opts.limit, 200),
18
+ };
19
+ if (opts.name)
20
+ req.name = opts.name;
21
+ if (opts.archived)
22
+ req.archived = true;
23
+ const items = await client.tags.list(req);
24
+ const rows = items.map((raw) => {
25
+ const t = raw;
26
+ return {
27
+ id: t.id ?? "",
28
+ name: t.name ?? "",
29
+ archived: t.archived === true,
30
+ };
31
+ });
32
+ printRecords(rows, output);
33
+ });
34
+ tags.command("create")
35
+ .argument("<name>", "Tag name.")
36
+ .description("Create a tag in the workspace.")
37
+ .action(async function (name) {
38
+ const { client, workspaceId, output } = await resolveContext(this, services);
39
+ const req = { workspaceId, body: { name } };
40
+ const created = (await client.tags.create(req));
41
+ const data = { id: created.id ?? "", name: created.name ?? "" };
42
+ printReceipt({
43
+ ok: true,
44
+ action: "tags.create",
45
+ entity: "tag",
46
+ ids: { tagId: data.id },
47
+ data,
48
+ changed: { created: [{ type: "tag", id: data.id, name: data.name }] },
49
+ next: [
50
+ { command: "clk115 tags list --json", reason: "Verify the tag appears." },
51
+ ],
52
+ }, output);
53
+ });
54
+ tags.command("get")
55
+ .argument("<id>", "Tag ID.")
56
+ .description("Get one tag by ID.")
57
+ .action(async function (id) {
58
+ const { client, workspaceId, output } = await resolveContext(this, services);
59
+ const tag = await client.tags.get({ workspaceId, tagId: id });
60
+ printObject(tag, output);
61
+ });
62
+ tags.command("update")
63
+ .argument("<id>", "Tag ID.")
64
+ .option("--name <text>", "New tag name.")
65
+ .option("--archived", "Archive the tag.")
66
+ .option("--no-archived", "Unarchive the tag.")
67
+ .description("Update a tag by ID.")
68
+ .action(async function (id, opts) {
69
+ const { client, workspaceId, output } = await resolveContext(this, services);
70
+ const body = {};
71
+ if (opts.name)
72
+ body.name = opts.name;
73
+ if (opts.archived !== undefined)
74
+ body.archived = opts.archived;
75
+ const req = { workspaceId, tagId: id, body };
76
+ const updated = (await client.tags.update(req));
77
+ const data = { id: updated.id ?? id, name: updated.name ?? "" };
78
+ printReceipt({
79
+ ok: true,
80
+ action: "tags.update",
81
+ entity: "tag",
82
+ ids: { tagId: data.id },
83
+ data,
84
+ changed: { updated: [{ type: "tag", id: data.id, name: data.name }] },
85
+ next: [{ command: "clk115 tags list --json", reason: "Verify the update." }],
86
+ }, output);
87
+ });
88
+ tags.command("delete")
89
+ .argument("<id>", "Tag ID.")
90
+ .description("Delete a tag by ID.")
91
+ .action(async function (id) {
92
+ const { client, workspaceId, output } = await resolveContext(this, services);
93
+ await client.tags.delete({ workspaceId, tagId: id });
94
+ printReceipt({
95
+ ok: true,
96
+ action: "tags.delete",
97
+ entity: "tag",
98
+ ids: { tagId: id },
99
+ data: { id, deleted: true, message: `deleted tag ${id}` },
100
+ changed: { deleted: [{ type: "tag", id }] },
101
+ next: [
102
+ {
103
+ command: "clk115 tags list --json",
104
+ reason: "Verify the tag no longer appears.",
105
+ },
106
+ ],
107
+ }, output);
108
+ });
109
+ };
@@ -0,0 +1,163 @@
1
+ import { wireBody } from "clockify-sdk-ts-115/requests";
2
+ import { printObject, printRecords } from "../output.js";
3
+ import { printReceipt } from "../receipt.js";
4
+ import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
5
+ export const registerTasksCommand = (program, services) => {
6
+ const tasks = program.command("tasks").description("Manage tasks.");
7
+ tasks
8
+ .command("list")
9
+ .argument("<projectId>", "Project ID.")
10
+ .description("List tasks for a project.")
11
+ .option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
12
+ .option("--page <n>", "Page number.", parseIntArg, 1)
13
+ .option("--name <text>", "Filter by task name substring.")
14
+ .action(async function (projectId, opts) {
15
+ const { client, workspaceId, output } = await resolveContext(this, services);
16
+ const req = {
17
+ workspaceId,
18
+ projectId,
19
+ page: opts.page,
20
+ "page-size": clampPageSize(opts.limit, 200),
21
+ };
22
+ if (opts.name)
23
+ req.name = opts.name;
24
+ const items = await client.tasks.list(req);
25
+ const rows = items.map((raw) => {
26
+ const t = raw;
27
+ return {
28
+ id: t.id ?? "",
29
+ name: t.name ?? "",
30
+ status: t.status ?? "",
31
+ billable: t.billable === true,
32
+ };
33
+ });
34
+ printRecords(rows, output);
35
+ });
36
+ tasks
37
+ .command("create")
38
+ .argument("<projectId>", "Project ID.")
39
+ .argument("<name>", "Task name.")
40
+ .option("--billable", "Mark as billable.")
41
+ .option("--estimate <iso>", "ISO-8601 duration estimate (e.g. PT8H).")
42
+ .option("--assignee <id...>", "Assignee user ID(s).")
43
+ .description("Create a task under a project.")
44
+ .action(async function (projectId, name, opts) {
45
+ const { client, workspaceId, output } = await resolveContext(this, services);
46
+ const body = { name };
47
+ if (opts.billable !== undefined)
48
+ body.billable = opts.billable;
49
+ if (opts.estimate)
50
+ body.estimate = opts.estimate;
51
+ if (Array.isArray(opts.assignee) && opts.assignee.length > 0)
52
+ body.assigneeIds = opts.assignee;
53
+ const req = wireBody({
54
+ workspaceId,
55
+ projectId,
56
+ body,
57
+ });
58
+ const created = (await client.tasks.create(req));
59
+ const data = { id: created.id ?? "", name: created.name ?? name };
60
+ printReceipt({
61
+ ok: true,
62
+ action: "tasks.create",
63
+ entity: "task",
64
+ ids: { projectId, taskId: data.id },
65
+ data,
66
+ changed: { created: [{ type: "task", id: data.id, name: data.name }] },
67
+ next: [
68
+ {
69
+ command: `clk115 tasks list ${projectId} --json`,
70
+ reason: "Verify the task appears.",
71
+ },
72
+ ],
73
+ }, output);
74
+ });
75
+ tasks
76
+ .command("get")
77
+ .argument("<projectId>", "Project ID.")
78
+ .argument("<id>", "Task ID.")
79
+ .description("Get one task by project ID and task ID.")
80
+ .action(async function (projectId, id) {
81
+ const { client, workspaceId, output } = await resolveContext(this, services);
82
+ const task = await client.tasks.get({ workspaceId, projectId, taskId: id });
83
+ printObject(task, output);
84
+ });
85
+ tasks
86
+ .command("update")
87
+ .argument("<projectId>", "Project ID.")
88
+ .argument("<id>", "Task ID.")
89
+ .option("--name <text>", "New task name.")
90
+ .option("--status <status>", "ACTIVE or DONE.")
91
+ .option("--estimate <iso>", "ISO-8601 duration estimate (e.g. PT8H).")
92
+ .option("--billable", "Mark as billable.")
93
+ .option("--no-billable", "Mark as non-billable.")
94
+ .option("--assignee <id...>", "Assignee user ID(s).")
95
+ .description("Update a task by project ID and task ID.")
96
+ .action(async function (projectId, id, opts) {
97
+ const { client, workspaceId, output } = await resolveContext(this, services);
98
+ const body = {};
99
+ if (opts.name)
100
+ body.name = opts.name;
101
+ if (opts.status)
102
+ body.status = String(opts.status).toUpperCase();
103
+ if (opts.estimate)
104
+ body.estimate = opts.estimate;
105
+ if (opts.billable !== undefined)
106
+ body.billable = opts.billable;
107
+ if (Array.isArray(opts.assignee) && opts.assignee.length > 0)
108
+ body.assigneeIds = opts.assignee;
109
+ const req = wireBody({
110
+ workspaceId,
111
+ projectId,
112
+ taskId: id,
113
+ body,
114
+ });
115
+ const updated = (await client.tasks.update(req));
116
+ const data = { id: updated.id ?? id, name: updated.name ?? "" };
117
+ printReceipt({
118
+ ok: true,
119
+ action: "tasks.update",
120
+ entity: "task",
121
+ ids: { projectId, taskId: data.id },
122
+ data,
123
+ changed: { updated: [{ type: "task", id: data.id, name: data.name }] },
124
+ next: [
125
+ {
126
+ command: `clk115 tasks get ${projectId} ${data.id} --json`,
127
+ reason: "Verify the update.",
128
+ },
129
+ ],
130
+ }, output);
131
+ });
132
+ tasks
133
+ .command("delete")
134
+ .argument("<projectId>", "Project ID.")
135
+ .argument("<id>", "Task ID.")
136
+ .description("Delete a task by project ID and task ID (marks DONE first; an active task cannot be deleted).")
137
+ .action(async function (projectId, id) {
138
+ const { client, workspaceId, output } = await resolveContext(this, services);
139
+ const current = (await client.tasks.get({ workspaceId, projectId, taskId: id }));
140
+ await client.tasks.update(wireBody({
141
+ workspaceId,
142
+ projectId,
143
+ taskId: id,
144
+ name: String(current.name ?? ""),
145
+ status: "DONE",
146
+ }));
147
+ await client.tasks.delete({ workspaceId, projectId, taskId: id });
148
+ printReceipt({
149
+ ok: true,
150
+ action: "tasks.delete",
151
+ entity: "task",
152
+ ids: { projectId, taskId: id },
153
+ data: { id, deleted: true, message: `deleted task ${id}` },
154
+ changed: { deleted: [{ type: "task", id }] },
155
+ next: [
156
+ {
157
+ command: `clk115 tasks list ${projectId} --json`,
158
+ reason: "Verify the task no longer appears.",
159
+ },
160
+ ],
161
+ }, output);
162
+ });
163
+ };
@@ -0,0 +1,102 @@
1
+ import { wireBody } from "clockify-sdk-ts-115/requests";
2
+ import { printRecords } from "../output.js";
3
+ import { printReceipt } from "../receipt.js";
4
+ import { clampPageSize, parseIntArg, resolveContext, splitList } from "./helpers.js";
5
+ export const registerTimeOffCommand = (program, services) => {
6
+ const timeoff = program.command("timeoff").description("Time-off requests.");
7
+ timeoff
8
+ .command("list")
9
+ .description("List time-off requests in the workspace.")
10
+ .option("--page <n>", "Page number.", parseIntArg, 1)
11
+ .option("--limit <n>", "Items per page (default 50, max 200).", parseIntArg, 50)
12
+ .option("--start <date>", "Window start (YYYY-MM-DD or RFC3339).")
13
+ .option("--end <date>", "Window end (YYYY-MM-DD or RFC3339).")
14
+ .option("--status <statuses>", "Comma-separated statuses (APPROVED, PENDING, REJECTED, WITHDRAWN).")
15
+ .option("--user <ids>", "Comma-separated user IDs to scope the search.")
16
+ .action(async function (opts) {
17
+ const { client, workspaceId, output } = await resolveContext(this, services);
18
+ const req = {
19
+ workspaceId,
20
+ page: opts.page,
21
+ pageSize: clampPageSize(opts.limit, 200),
22
+ };
23
+ if (opts.start)
24
+ req.start = opts.start;
25
+ if (opts.end)
26
+ req.end = opts.end;
27
+ if (opts.status)
28
+ req.statuses = splitList(opts.status);
29
+ if (opts.user)
30
+ req.users = splitList(opts.user);
31
+ const items = (await client.timeOff.list(wireBody(req)));
32
+ const rows = items.map((raw) => {
33
+ const r = raw;
34
+ const statusValue = typeof r.status === "object" && r.status !== null
35
+ ? (r.status.statusType ?? "")
36
+ : typeof r.status === "string"
37
+ ? r.status
38
+ : "";
39
+ return {
40
+ id: r.id ?? "",
41
+ user: r.userId ?? "",
42
+ policy: r.policyId ?? "",
43
+ status: statusValue,
44
+ start: r.timeOffPeriod?.period?.start ?? "",
45
+ end: r.timeOffPeriod?.period?.end ?? "",
46
+ note: r.note ?? "",
47
+ };
48
+ });
49
+ printRecords(rows, output);
50
+ });
51
+ timeoff
52
+ .command("submit")
53
+ .description("Submit a time-off request against a policy.")
54
+ .requiredOption("--policy <id>", "Time-off policy ID.")
55
+ .requiredOption("--start <date>", "Period start (date-only YYYY-MM-DD for DAYS-unit policies, RFC3339 for HOURS-unit).")
56
+ .option("--end <date>", "Period end (RFC3339); HOURS-unit policies need it, DAYS-unit use --days. Provide --end or --days.")
57
+ .option("--days <n>", "Days requested; DAYS-unit policies need it. Provide --end or --days.", parseIntArg)
58
+ .option("--note <text>", "Optional request note.")
59
+ .option("--half-day", "Mark as a half-day request.", false)
60
+ .option("--half-day-period <period>", "Half-day period (FIRST_HALF, SECOND_HALF, NOT_DEFINED).")
61
+ .action(async function (opts) {
62
+ if (opts.end === undefined && !Number.isFinite(opts.days)) {
63
+ throw new Error("provide --end (date-range / HOURS-unit policies) or --days (DAYS-unit policies)");
64
+ }
65
+ const { client, workspaceId, output } = await resolveContext(this, services);
66
+ const period = { start: opts.start };
67
+ if (opts.end !== undefined)
68
+ period.end = opts.end;
69
+ if (Number.isFinite(opts.days))
70
+ period.days = opts.days;
71
+ const body = {
72
+ note: opts.note ?? "",
73
+ timeOffPeriod: {
74
+ isHalfDay: opts.halfDay === true,
75
+ halfDayPeriod: opts.halfDayPeriod ?? "NOT_DEFINED",
76
+ period,
77
+ },
78
+ };
79
+ const req = {
80
+ workspaceId,
81
+ policyId: opts.policy,
82
+ body,
83
+ };
84
+ const created = (await client.timeOff.submit(req));
85
+ const data = {
86
+ id: created.id ?? "",
87
+ user: created.userId ?? "",
88
+ status: created.status?.statusType ?? "",
89
+ };
90
+ printReceipt({
91
+ ok: true,
92
+ action: "timeoff.submit",
93
+ entity: "time_off_request",
94
+ ids: { timeOffRequestId: data.id },
95
+ data,
96
+ changed: { created: [{ type: "time_off_request", id: data.id }] },
97
+ next: [
98
+ { command: "clk115 timeoff list --json", reason: "Review request status." },
99
+ ],
100
+ }, output);
101
+ });
102
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,116 @@
1
+ import { printObject, printRecords } from "../output.js";
2
+ import { printReceipt } from "../receipt.js";
3
+ import { clampPageSize, parseIntArg, resolveBaseContext, resolveContext } from "./helpers.js";
4
+ export const registerUsersCommand = (program, services) => {
5
+ const users = program.command("users").description("Inspect workspace users.");
6
+ users
7
+ .command("me")
8
+ .description("Show the current authenticated user (the API-key owner).")
9
+ .action(async function () {
10
+ const { client, output } = await resolveBaseContext(this, services);
11
+ const me = await client.users.getCurrentUser();
12
+ printObject(me, output);
13
+ });
14
+ users
15
+ .command("list")
16
+ .description("List members of the workspace.")
17
+ .option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
18
+ .option("--page <n>", "Page number.", parseIntArg, 1)
19
+ .option("--name <text>", "Filter by name/email substring.")
20
+ .action(async function (opts) {
21
+ const { client, workspaceId, output } = await resolveContext(this, services);
22
+ const req = {
23
+ workspaceId,
24
+ page: opts.page,
25
+ "page-size": clampPageSize(opts.limit, 200),
26
+ "include-roles": false,
27
+ };
28
+ if (opts.name)
29
+ req.name = opts.name;
30
+ const items = await client.users.list(req);
31
+ const rows = items.map((raw) => {
32
+ const u = raw;
33
+ return {
34
+ id: u.id ?? "",
35
+ name: u.name ?? "",
36
+ email: u.email ?? "",
37
+ status: u.status ?? "",
38
+ };
39
+ });
40
+ printRecords(rows, output);
41
+ });
42
+ users
43
+ .command("invite")
44
+ .argument("<email>", "Email address of the user to invite.")
45
+ .option("--no-send-email", "Do not send the invitation email.")
46
+ .description("Invite (add) a user to the workspace by email.")
47
+ .action(async function (email, opts) {
48
+ const { client, workspaceId, output } = await resolveContext(this, services);
49
+ const sendEmail = opts.sendEmail !== false;
50
+ const workspace = (await client.workspaces.addUser({
51
+ workspaceId,
52
+ "send-email": sendEmail ? "true" : "false",
53
+ email,
54
+ }));
55
+ printReceipt({
56
+ ok: true,
57
+ action: "users.invite",
58
+ entity: "workspace_member",
59
+ ids: { workspaceId },
60
+ data: { email, sendEmail, message: `invited ${email}` },
61
+ changed: {
62
+ created: [
63
+ { type: "workspace_member", id: workspace.id ?? "", name: email },
64
+ ],
65
+ },
66
+ next: [
67
+ {
68
+ command: "clk115 users list --json",
69
+ reason: "Verify the member appears.",
70
+ },
71
+ ],
72
+ }, output);
73
+ });
74
+ users
75
+ .command("update-profile")
76
+ .argument("<userId>", "User ID whose member profile to update.")
77
+ .option("--name <text>", "Display name.")
78
+ .option("--image-url <url>", "Profile image URL.")
79
+ .option("--remove-image", "Remove the profile image.")
80
+ .option("--week-start <day>", "Week start day, e.g. MONDAY.")
81
+ .option("--work-capacity <iso>", "Daily work capacity, ISO-8601 duration (e.g. PT8H).")
82
+ .option("--working-days <days...>", "Working day enums, e.g. MONDAY TUESDAY.")
83
+ .description("Update one user's member profile (name, image, week start, work capacity, working days).")
84
+ .action(async function (userId, opts) {
85
+ const { client, workspaceId, output } = await resolveContext(this, services);
86
+ const body = {};
87
+ if (opts.name !== undefined)
88
+ body.name = opts.name;
89
+ if (opts.imageUrl !== undefined)
90
+ body.imageUrl = opts.imageUrl;
91
+ if (opts.removeImage)
92
+ body.removeProfileImage = true;
93
+ if (opts.weekStart !== undefined)
94
+ body.weekStart = opts.weekStart;
95
+ if (opts.workCapacity !== undefined)
96
+ body.workCapacity = opts.workCapacity;
97
+ if (Array.isArray(opts.workingDays) && opts.workingDays.length > 0)
98
+ body.workingDays = opts.workingDays;
99
+ const updated = (await client.memberProfiles.update({ workspaceId, userId, body }));
100
+ printReceipt({
101
+ ok: true,
102
+ action: "users.update-profile",
103
+ entity: "member_profile",
104
+ ids: { workspaceId, userId },
105
+ data: {
106
+ id: updated.id ?? userId,
107
+ userId,
108
+ message: `updated profile for ${userId}`,
109
+ },
110
+ changed: { updated: [{ type: "member_profile", id: userId }] },
111
+ next: [
112
+ { command: "clk115 users list --json", reason: "Verify the member list." },
113
+ ],
114
+ }, output);
115
+ });
116
+ };