@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,158 @@
1
+ import { archiveThenDeleteProject } from "clockify-sdk-ts-115/ensure";
2
+ import { printObject, printRecords } from "../output.js";
3
+ import { printReceipt } from "../receipt.js";
4
+ import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
5
+ export const registerProjectsCommand = (program, services) => {
6
+ const projects = program.command("projects").description("Manage projects.");
7
+ projects
8
+ .command("list")
9
+ .description("List projects in the workspace.")
10
+ .option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
11
+ .option("--page <n>", "Page number.", parseIntArg, 1)
12
+ .option("--name <text>", "Filter by project name substring.")
13
+ .option("--archived", "Include archived projects.", false)
14
+ .option("--client <id>", "Filter by client ID.")
15
+ .action(async function (opts) {
16
+ const { client, workspaceId, output } = await resolveContext(this, services);
17
+ const req = {
18
+ workspaceId,
19
+ page: opts.page,
20
+ "page-size": clampPageSize(opts.limit, 200),
21
+ };
22
+ if (opts.name)
23
+ req.name = opts.name;
24
+ if (opts.archived)
25
+ req.archived = true;
26
+ if (opts.client)
27
+ req.clients = [opts.client];
28
+ const items = await client.projects.list(req);
29
+ const rows = items.map((raw) => {
30
+ const p = raw;
31
+ return {
32
+ id: p.id ?? "",
33
+ name: p.name ?? "",
34
+ clientId: p.clientId ?? "",
35
+ color: p.color ?? "",
36
+ archived: p.archived === true,
37
+ billable: p.billable === true,
38
+ };
39
+ });
40
+ printRecords(rows, output);
41
+ });
42
+ projects
43
+ .command("create")
44
+ .argument("<name>", "Project name.")
45
+ .option("--client <id>", "Client ID.")
46
+ .option("--color <hex>", "Hex color (e.g. #4caf50).")
47
+ .option("--billable", "Mark as billable.", false)
48
+ .description("Create a project in the workspace.")
49
+ .action(async function (name, opts) {
50
+ const { client, workspaceId, output } = await resolveContext(this, services);
51
+ const req = {
52
+ workspaceId,
53
+ body: {
54
+ name,
55
+ ...(opts.client ? { clientId: opts.client } : {}),
56
+ ...(opts.color ? { color: opts.color } : {}),
57
+ ...(opts.billable ? { billable: true } : {}),
58
+ },
59
+ };
60
+ const created = (await client.projects.create(req));
61
+ const data = {
62
+ id: created.id ?? "",
63
+ name: created.name ?? "",
64
+ clientId: created.clientId ?? "",
65
+ color: created.color ?? "",
66
+ };
67
+ printReceipt({
68
+ ok: true,
69
+ action: "projects.create",
70
+ entity: "project",
71
+ ids: { projectId: data.id },
72
+ data,
73
+ changed: { created: [{ type: "project", id: data.id, name: data.name }] },
74
+ next: [
75
+ {
76
+ command: `clk115 tasks list ${data.id} --json`,
77
+ reason: "Review tasks for this project.",
78
+ },
79
+ ],
80
+ }, output);
81
+ });
82
+ projects
83
+ .command("get")
84
+ .argument("<id>", "Project ID.")
85
+ .description("Get one project by ID.")
86
+ .action(async function (id) {
87
+ const { client, workspaceId, output } = await resolveContext(this, services);
88
+ const project = await client.projects.get({ workspaceId, projectId: id });
89
+ printObject(project, output);
90
+ });
91
+ projects
92
+ .command("update")
93
+ .argument("<id>", "Project ID.")
94
+ .option("--name <text>", "New project name.")
95
+ .option("--client <id>", "Client ID.")
96
+ .option("--color <hex>", "Hex color (e.g. #4caf50).")
97
+ .option("--note <text>", "Project note.")
98
+ .option("--billable", "Mark as billable.")
99
+ .option("--no-billable", "Mark as non-billable.")
100
+ .option("--archived", "Archive the project.")
101
+ .option("--no-archived", "Unarchive the project.")
102
+ .description("Update a project by ID.")
103
+ .action(async function (id, opts) {
104
+ const { client, workspaceId, output } = await resolveContext(this, services);
105
+ const body = {};
106
+ if (opts.name)
107
+ body.name = opts.name;
108
+ if (opts.client)
109
+ body.clientId = opts.client;
110
+ if (opts.color)
111
+ body.color = opts.color;
112
+ if (opts.note !== undefined)
113
+ body.note = opts.note;
114
+ if (opts.billable !== undefined)
115
+ body.billable = opts.billable;
116
+ if (opts.archived !== undefined)
117
+ body.archived = opts.archived;
118
+ const req = { workspaceId, projectId: id, body };
119
+ const updated = (await client.projects.update(req));
120
+ const data = { id: updated.id ?? id, name: updated.name ?? "" };
121
+ printReceipt({
122
+ ok: true,
123
+ action: "projects.update",
124
+ entity: "project",
125
+ ids: { projectId: data.id },
126
+ data,
127
+ changed: { updated: [{ type: "project", id: data.id, name: data.name }] },
128
+ next: [
129
+ {
130
+ command: `clk115 projects get ${data.id} --json`,
131
+ reason: "Verify the update.",
132
+ },
133
+ ],
134
+ }, output);
135
+ });
136
+ projects
137
+ .command("delete")
138
+ .argument("<id>", "Project ID.")
139
+ .description("Delete a project by ID (archives first; an active project cannot be deleted).")
140
+ .action(async function (id) {
141
+ const { client, workspaceId, output } = await resolveContext(this, services);
142
+ await archiveThenDeleteProject({ workspaceId, id, resource: client.projects });
143
+ printReceipt({
144
+ ok: true,
145
+ action: "projects.delete",
146
+ entity: "project",
147
+ ids: { projectId: id },
148
+ data: { id, deleted: true, message: `deleted project ${id}` },
149
+ changed: { deleted: [{ type: "project", id }] },
150
+ next: [
151
+ {
152
+ command: "clk115 projects list --json",
153
+ reason: "Verify the project no longer appears.",
154
+ },
155
+ ],
156
+ }, output);
157
+ });
158
+ };
@@ -0,0 +1,134 @@
1
+ import { REPORT_PERIODS, resolveInstant, resolvePeriod, } from "clockify-sdk-ts-115/dates";
2
+ import { detailedFilter, summaryFilter, weeklyFilter } from "clockify-sdk-ts-115/reports";
3
+ import { printObject } from "../output.js";
4
+ import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
5
+ import { resolveClientId, resolveProjectId } from "./resolve-refs.js";
6
+ function resolveRange(opts) {
7
+ const now = new Date();
8
+ const periodInput = (opts.period ?? "this_month")
9
+ .trim()
10
+ .toLowerCase()
11
+ .replace(/[\s-]+/g, "_");
12
+ if (!REPORT_PERIODS.includes(periodInput)) {
13
+ throw new Error(`Unknown --period "${opts.period}". Use one of: ${REPORT_PERIODS.join(", ")}.`);
14
+ }
15
+ const range = resolvePeriod(now, periodInput);
16
+ let { dateRangeStart, dateRangeEnd } = range;
17
+ if (opts.from) {
18
+ const start = resolveInstant(now, opts.from, "start");
19
+ if (!start)
20
+ throw new Error(`--from "${opts.from}" is not a valid date, ISO timestamp, or period.`);
21
+ dateRangeStart = start;
22
+ }
23
+ if (opts.to) {
24
+ const end = resolveInstant(now, opts.to, "end");
25
+ if (!end)
26
+ throw new Error(`--to "${opts.to}" is not a valid date, ISO timestamp, or period.`);
27
+ dateRangeEnd = end;
28
+ }
29
+ return { dateRangeStart, dateRangeEnd };
30
+ }
31
+ function idFilter(ids) {
32
+ return { ids, contains: "CONTAINS" };
33
+ }
34
+ const PERIOD_HELP = `Named period: ${REPORT_PERIODS.join(", ")} (default this_month).`;
35
+ export const registerReportsCommand = (program, services) => {
36
+ const reports = program.command("reports").description("Run Clockify reports (read-only).");
37
+ reports
38
+ .command("summary")
39
+ .description("Summary report totals over a date range, grouped per --groups.")
40
+ .option("--period <p>", PERIOD_HELP)
41
+ .option("--from <date>", "Range start (YYYY-MM-DD, ISO, or a period); overrides --period.")
42
+ .option("--to <date>", "Range end (YYYY-MM-DD, ISO, or a period); overrides --period.")
43
+ .option("--groups <list>", "Comma-separated summary groups (e.g. PROJECT,TASK,CLIENT).", "PROJECT")
44
+ .option("--billable", "Only billable time.", false)
45
+ .option("--project <name|id...>", "Scope to one or more project names or ids.")
46
+ .option("--client <name|id...>", "Scope to one or more client names or ids.")
47
+ .action(async function (opts) {
48
+ const { client, workspaceId, output } = await resolveContext(this, services);
49
+ const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
50
+ const groups = String(opts.groups)
51
+ .split(",")
52
+ .map((g) => g.trim().toUpperCase())
53
+ .filter(Boolean);
54
+ const req = {
55
+ workspaceId,
56
+ dateRangeStart,
57
+ dateRangeEnd,
58
+ summaryFilter: summaryFilter(groups),
59
+ };
60
+ if (opts.billable)
61
+ req.billable = true;
62
+ if (Array.isArray(opts.project) && opts.project.length > 0) {
63
+ const ids = await Promise.all(opts.project.map((p) => resolveProjectId(client, workspaceId, p)));
64
+ req.projects = idFilter(ids);
65
+ }
66
+ if (Array.isArray(opts.client) && opts.client.length > 0) {
67
+ const ids = await Promise.all(opts.client.map((c) => resolveClientId(client, workspaceId, c)));
68
+ req.clients = idFilter(ids);
69
+ }
70
+ const data = await client.reports.summary(req);
71
+ printObject(data, output);
72
+ });
73
+ reports
74
+ .command("detailed")
75
+ .description("Detailed report listing individual time entries over a date range.")
76
+ .option("--period <p>", PERIOD_HELP)
77
+ .option("--from <date>", "Range start; overrides --period.")
78
+ .option("--to <date>", "Range end; overrides --period.")
79
+ .option("--page <n>", "Page number.", parseIntArg, 1)
80
+ .option("--page-size <n>", "Entries per page (max 1000).", parseIntArg, 50)
81
+ .action(async function (opts) {
82
+ const { client, workspaceId, output } = await resolveContext(this, services);
83
+ const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
84
+ const req = {
85
+ workspaceId,
86
+ dateRangeStart,
87
+ dateRangeEnd,
88
+ detailedFilter: detailedFilter({
89
+ page: opts.page,
90
+ pageSize: clampPageSize(opts.pageSize, 1000),
91
+ }),
92
+ };
93
+ const data = await client.reports.detailed(req);
94
+ printObject(data, output);
95
+ });
96
+ reports
97
+ .command("weekly")
98
+ .description("Weekly report aggregating tracked time per week over a date range.")
99
+ .option("--period <p>", PERIOD_HELP)
100
+ .option("--from <date>", "Range start; overrides --period.")
101
+ .option("--to <date>", "Range end; overrides --period.")
102
+ .option("--group <group>", "Top grouping: USER or PROJECT.", "USER")
103
+ .option("--subgroup <subgroup>", "Subgrouping (TIME).", "TIME")
104
+ .action(async function (opts) {
105
+ const { client, workspaceId, output } = await resolveContext(this, services);
106
+ const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
107
+ const req = {
108
+ workspaceId,
109
+ dateRangeStart,
110
+ dateRangeEnd,
111
+ weeklyFilter: weeklyFilter(String(opts.group).toUpperCase(), String(opts.subgroup).toUpperCase()),
112
+ };
113
+ const data = await client.reports.weekly(req);
114
+ printObject(data, output);
115
+ });
116
+ reports
117
+ .command("attendance")
118
+ .description("Attendance report of clock-in/out activity over a date range.")
119
+ .option("--period <p>", PERIOD_HELP)
120
+ .option("--from <date>", "Range start; overrides --period.")
121
+ .option("--to <date>", "Range end; overrides --period.")
122
+ .action(async function (opts) {
123
+ const { client, workspaceId, output } = await resolveContext(this, services);
124
+ const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
125
+ const req = {
126
+ workspaceId,
127
+ dateRangeStart,
128
+ dateRangeEnd,
129
+ attendanceFilter: {},
130
+ };
131
+ const data = await client.reports.attendance(req);
132
+ printObject(data, output);
133
+ });
134
+ };
@@ -0,0 +1,79 @@
1
+ import { iterAll } from "clockify-sdk-ts-115/iter";
2
+ import { looksLikeClockifyId, matchByName } from "clockify-sdk-ts-115/resolve";
3
+ function asNamed(rows) {
4
+ return rows.map((r) => {
5
+ const row = r;
6
+ return {
7
+ id: String(row.id ?? ""),
8
+ name: String(row.name ?? ""),
9
+ ...(row.archived !== undefined ? { archived: row.archived } : {}),
10
+ };
11
+ });
12
+ }
13
+ function pickIdByName(rows, ref, noun) {
14
+ const match = matchByName(asNamed(rows), ref);
15
+ if (match.kind === "many") {
16
+ throw new Error(`multiple ${noun}s named ${JSON.stringify(ref)}; pass the 24-character id instead`);
17
+ }
18
+ if (match.kind === "none") {
19
+ throw new Error(`${noun} ${JSON.stringify(ref)} not found in workspace`);
20
+ }
21
+ return match.entity.id;
22
+ }
23
+ async function collectPaged(fetcher, baseRequest) {
24
+ const rows = [];
25
+ for await (const row of iterAll(fetcher, baseRequest, { pageSize: 200, maxPages: 1000 })) {
26
+ rows.push(row);
27
+ }
28
+ return rows;
29
+ }
30
+ export async function resolveProjectId(client, workspaceId, ref) {
31
+ if (looksLikeClockifyId(ref))
32
+ return ref;
33
+ const list = await collectPaged(client.projects.list.bind(client.projects), {
34
+ workspaceId,
35
+ name: ref,
36
+ });
37
+ return pickIdByName(list, ref, "project");
38
+ }
39
+ export async function resolveClientId(client, workspaceId, ref) {
40
+ if (looksLikeClockifyId(ref))
41
+ return ref;
42
+ const list = await collectPaged(client.clients.list.bind(client.clients), {
43
+ workspaceId,
44
+ name: ref,
45
+ });
46
+ return pickIdByName(list, ref, "client");
47
+ }
48
+ export async function resolveTaskId(client, workspaceId, projectId, ref) {
49
+ if (looksLikeClockifyId(ref))
50
+ return ref;
51
+ const list = await collectPaged(client.tasks.list.bind(client.tasks), {
52
+ workspaceId,
53
+ projectId,
54
+ name: ref,
55
+ });
56
+ const match = matchByName(asNamed(list), ref);
57
+ if (match.kind === "many") {
58
+ throw new Error(`multiple tasks named ${JSON.stringify(ref)} on project ${projectId}; pass the 24-character id`);
59
+ }
60
+ if (match.kind === "none") {
61
+ throw new Error(`task ${JSON.stringify(ref)} not found on project ${projectId}`);
62
+ }
63
+ return match.entity.id;
64
+ }
65
+ export async function resolveTagIds(client, workspaceId, refs) {
66
+ const ids = [];
67
+ for (const ref of refs) {
68
+ if (looksLikeClockifyId(ref)) {
69
+ ids.push(ref);
70
+ continue;
71
+ }
72
+ const list = await collectPaged(client.tags.list.bind(client.tags), {
73
+ workspaceId,
74
+ name: ref,
75
+ });
76
+ ids.push(pickIdByName(list, ref, "tag"));
77
+ }
78
+ return ids;
79
+ }
@@ -0,0 +1,109 @@
1
+ import { printRecords } from "../output.js";
2
+ import { printReceipt } from "../receipt.js";
3
+ import { clampPageSize, parseFloatArg, parseIntArg, promoteDateBoundary, resolveContext, } from "./helpers.js";
4
+ export const registerSchedulingCommand = (program, services) => {
5
+ const scheduling = program
6
+ .command("scheduling")
7
+ .description("Capacity scheduling assignments.");
8
+ scheduling
9
+ .command("list")
10
+ .description("List scheduling assignments over a date range. --from/--to are required (the endpoint 400s without them).")
11
+ .requiredOption("--from <date>", "Range start (YYYY-MM-DD or RFC3339). Required.")
12
+ .requiredOption("--to <date>", "Range end (YYYY-MM-DD or RFC3339). Required.")
13
+ .option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
14
+ .option("--page <n>", "Page number.", parseIntArg, 1)
15
+ .option("--name <text>", "Filter by assignment name substring.")
16
+ .action(async function (opts) {
17
+ const { client, workspaceId, output } = await resolveContext(this, services);
18
+ const req = {
19
+ workspaceId,
20
+ start: promoteDateBoundary(opts.from, "from", "start"),
21
+ end: promoteDateBoundary(opts.to, "to", "end"),
22
+ page: opts.page,
23
+ "page-size": clampPageSize(opts.limit, 200),
24
+ };
25
+ if (opts.name)
26
+ req.name = opts.name;
27
+ const items = await client.scheduling.list(req);
28
+ const rows = items.map((raw) => {
29
+ const a = raw;
30
+ return {
31
+ id: a.id ?? "",
32
+ user: a.userId ?? "",
33
+ project: a.projectId ?? "",
34
+ task: a.taskId ?? "",
35
+ hoursPerDay: a.hoursPerDay ?? 0,
36
+ start: a.period?.start ?? "",
37
+ end: a.period?.end ?? "",
38
+ billable: a.billable === true,
39
+ note: a.note ?? "",
40
+ };
41
+ });
42
+ printRecords(rows, output);
43
+ });
44
+ scheduling
45
+ .command("create")
46
+ .description("Create a scheduling assignment (defaults to draft; pass --publish to publish).")
47
+ .requiredOption("--user <id>", "User ID to assign.")
48
+ .requiredOption("--project <id>", "Project ID.")
49
+ .requiredOption("--start <date>", "Period start (YYYY-MM-DD or RFC3339).")
50
+ .requiredOption("--end <date>", "Period end (YYYY-MM-DD or RFC3339).")
51
+ .requiredOption("--hours-per-day <n>", "Daily hour load (e.g. 6).", parseFloatArg)
52
+ .option("--task <id>", "Task ID.")
53
+ .option("--note <text>", "Assignment note.")
54
+ .option("--billable", "Mark assignment as billable.", false)
55
+ .option("--include-non-working-days", "Include weekends/non-working days.", false)
56
+ .option("--publish", "Publish immediately (default is draft).", false)
57
+ .action(async function (opts) {
58
+ const { client, workspaceId, output } = await resolveContext(this, services);
59
+ const body = {
60
+ userId: opts.user,
61
+ projectId: opts.project,
62
+ hoursPerDay: opts.hoursPerDay,
63
+ start: opts.start,
64
+ end: opts.end,
65
+ };
66
+ if (opts.task)
67
+ body.taskId = opts.task;
68
+ if (opts.note)
69
+ body.note = opts.note;
70
+ if (opts.billable)
71
+ body.billable = true;
72
+ if (opts.includeNonWorkingDays)
73
+ body.includeNonWorkingDays = true;
74
+ const req = { workspaceId, body };
75
+ const createdList = (await client.scheduling.createRecurring(req));
76
+ const created = createdList?.[0] ?? {};
77
+ if (opts.publish === true) {
78
+ await client.scheduling.publish({
79
+ workspaceId,
80
+ start: opts.start,
81
+ end: opts.end,
82
+ userFilter: { contains: "CONTAINS", ids: [opts.user] },
83
+ });
84
+ }
85
+ const data = {
86
+ id: created.id ?? "",
87
+ user: created.userId ?? "",
88
+ project: created.projectId ?? "",
89
+ hoursPerDay: created.hoursPerDay ?? 0,
90
+ start: created.start ?? created.period?.start ?? opts.start ?? "",
91
+ end: created.end ?? created.period?.end ?? opts.end ?? "",
92
+ published: opts.publish === true,
93
+ };
94
+ printReceipt({
95
+ ok: true,
96
+ action: "scheduling.create",
97
+ entity: "scheduling_assignment",
98
+ ids: { assignmentId: data.id },
99
+ data,
100
+ changed: { created: [{ type: "scheduling_assignment", id: data.id }] },
101
+ next: [
102
+ {
103
+ command: "clk115 scheduling list --json",
104
+ reason: "Verify the assignment appears.",
105
+ },
106
+ ],
107
+ }, output);
108
+ });
109
+ };
@@ -0,0 +1,174 @@
1
+ import { wireBody } from "clockify-sdk-ts-115/requests";
2
+ import { printObject } from "../output.js";
3
+ import { printReceipt } from "../receipt.js";
4
+ import { resolveContext } from "./helpers.js";
5
+ async function readReportBody(response) {
6
+ const text = new TextDecoder().decode(await response.arrayBuffer());
7
+ if (!text)
8
+ return { body: "" };
9
+ try {
10
+ const parsed = JSON.parse(text);
11
+ if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
12
+ return parsed;
13
+ }
14
+ return { body: parsed };
15
+ }
16
+ catch {
17
+ return { body: text };
18
+ }
19
+ }
20
+ const SHARED_REPORT_TYPES = [
21
+ "SUMMARY",
22
+ "DETAILED",
23
+ "WEEKLY",
24
+ "EXPENSE_DETAILED",
25
+ "INVOICE_TIME",
26
+ "ATTENDANCE_DETAILED",
27
+ "ATTENDANCE_SUMMARY",
28
+ "ASSIGNMENT_LIST",
29
+ "ASSIGNMENT_SCHEDULE",
30
+ "APPROVAL_DETAILED",
31
+ "APPROVAL_SUMMARY",
32
+ "BALANCE_LIST",
33
+ "TIMEOFF_DETAILED",
34
+ "EXPENSE_SUMMARY",
35
+ ];
36
+ function parseFilter(raw) {
37
+ try {
38
+ const parsed = JSON.parse(raw);
39
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
40
+ throw new Error("not an object");
41
+ }
42
+ return parsed;
43
+ }
44
+ catch {
45
+ throw new Error(`--filter must be a JSON object, e.g. '{"dateRangeStart":"…","dateRangeEnd":"…"}'`);
46
+ }
47
+ }
48
+ function requireType(raw) {
49
+ const type = String(raw).toUpperCase();
50
+ if (!SHARED_REPORT_TYPES.includes(type)) {
51
+ throw new Error(`Unknown --type "${raw}". Use one of: ${SHARED_REPORT_TYPES.join(", ")}.`);
52
+ }
53
+ return type;
54
+ }
55
+ export const registerSharedReportsCommand = (program, services) => {
56
+ const shared = program
57
+ .command("shared-reports")
58
+ .description("Manage shared (public-link) reports.");
59
+ shared
60
+ .command("list")
61
+ .description("List the workspace's shared (public-link) reports.")
62
+ .action(async function () {
63
+ const { client, workspaceId, output } = await resolveContext(this, services);
64
+ const result = await client.sharedReports.list({ workspaceId });
65
+ printObject(result, output);
66
+ });
67
+ shared
68
+ .command("view")
69
+ .argument("<id>", "Shared-report ID.")
70
+ .option("--export-type <type>", "Export type: JSON_V1, JSON, CSV, XLSX, or PDF (default JSON_V1).")
71
+ .description("View a shared report's rendered data by ID (reports host; not workspace-scoped).")
72
+ .action(async function (id, opts) {
73
+ const { client, output } = await resolveContext(this, services);
74
+ const exportType = (opts.exportType ? String(opts.exportType).toUpperCase() : "JSON_V1");
75
+ const response = await client.sharedReports.view({
76
+ sharedReportId: id,
77
+ exportType,
78
+ });
79
+ printObject(await readReportBody(response), output);
80
+ });
81
+ shared
82
+ .command("create")
83
+ .requiredOption("--name <text>", "Shared-report name.")
84
+ .requiredOption("--type <type>", `Report type: ${SHARED_REPORT_TYPES.join(", ")}.`)
85
+ .requiredOption("--filter <json>", "Report filter object as a JSON string.")
86
+ .option("--public", "Make the report publicly accessible.")
87
+ .description("Create a shared (public-link) report.")
88
+ .action(async function (opts) {
89
+ const { client, workspaceId, output } = await resolveContext(this, services);
90
+ const body = {
91
+ name: opts.name,
92
+ type: requireType(opts.type),
93
+ filter: parseFilter(opts.filter),
94
+ };
95
+ if (opts.public)
96
+ body.isPublic = true;
97
+ const created = (await client.sharedReports.create(wireBody({ workspaceId, body })));
98
+ const data = { id: created.id ?? "", name: created.name ?? opts.name };
99
+ printReceipt({
100
+ ok: true,
101
+ action: "shared-reports.create",
102
+ entity: "shared_report",
103
+ ids: { sharedReportId: data.id },
104
+ data,
105
+ changed: { created: [{ type: "shared_report", id: data.id, name: data.name }] },
106
+ next: [
107
+ {
108
+ command: "clk115 shared-reports list --json",
109
+ reason: "Verify the report appears.",
110
+ },
111
+ ],
112
+ }, output);
113
+ });
114
+ shared
115
+ .command("update")
116
+ .argument("<id>", "Shared-report ID.")
117
+ .requiredOption("--name <text>", "Shared-report name.")
118
+ .requiredOption("--type <type>", `Report type: ${SHARED_REPORT_TYPES.join(", ")}.`)
119
+ .requiredOption("--filter <json>", "Report filter object as a JSON string (full replace).")
120
+ .option("--public", "Make the report publicly accessible.")
121
+ .description("Replace a shared report by ID (full replace of name, type, and filter).")
122
+ .action(async function (id, opts) {
123
+ const { client, workspaceId, output } = await resolveContext(this, services);
124
+ const body = {
125
+ name: opts.name,
126
+ type: requireType(opts.type),
127
+ filter: parseFilter(opts.filter),
128
+ };
129
+ if (opts.public)
130
+ body.isPublic = true;
131
+ const updated = (await client.sharedReports.update(wireBody({
132
+ workspaceId,
133
+ sharedReportId: id,
134
+ body,
135
+ })));
136
+ const data = { id: updated.id ?? id, name: updated.name ?? opts.name };
137
+ printReceipt({
138
+ ok: true,
139
+ action: "shared-reports.update",
140
+ entity: "shared_report",
141
+ ids: { sharedReportId: data.id },
142
+ data,
143
+ changed: { updated: [{ type: "shared_report", id: data.id, name: data.name }] },
144
+ next: [
145
+ {
146
+ command: "clk115 shared-reports list --json",
147
+ reason: "Verify the update.",
148
+ },
149
+ ],
150
+ }, output);
151
+ });
152
+ shared
153
+ .command("delete")
154
+ .argument("<id>", "Shared-report ID.")
155
+ .description("Delete a shared report by ID.")
156
+ .action(async function (id) {
157
+ const { client, workspaceId, output } = await resolveContext(this, services);
158
+ await client.sharedReports.delete({ workspaceId, sharedReportId: id });
159
+ printReceipt({
160
+ ok: true,
161
+ action: "shared-reports.delete",
162
+ entity: "shared_report",
163
+ ids: { sharedReportId: id },
164
+ data: { id, deleted: true, message: `deleted shared report ${id}` },
165
+ changed: { deleted: [{ type: "shared_report", id }] },
166
+ next: [
167
+ {
168
+ command: "clk115 shared-reports list --json",
169
+ reason: "Verify the report no longer appears.",
170
+ },
171
+ ],
172
+ }, output);
173
+ });
174
+ };