@apet97/clockify-cli-115 5.0.4 → 6.0.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.
- package/README.md +96 -26
- package/dist/client.js +18 -15
- package/dist/closed-pipe.js +3 -0
- package/dist/commands/api.js +182 -61
- package/dist/commands/approvals.js +9 -7
- package/dist/commands/auditlog.js +11 -8
- package/dist/commands/balanceAssignment.js +10 -8
- package/dist/commands/clients.js +16 -7
- package/dist/commands/doctor.js +42 -25
- package/dist/commands/entries.js +29 -14
- package/dist/commands/expenses.js +64 -22
- package/dist/commands/helpers.js +28 -7
- package/dist/commands/invoices.js +12 -16
- package/dist/commands/leaf-command.js +8 -0
- package/dist/commands/log.js +4 -2
- package/dist/commands/projects.js +18 -9
- package/dist/commands/reports.js +32 -14
- package/dist/commands/resolve-refs.js +30 -53
- package/dist/commands/scheduling.js +94 -40
- package/dist/commands/shared-report-body.js +205 -0
- package/dist/commands/sharedReports.js +19 -215
- package/dist/commands/start.js +6 -4
- package/dist/commands/status.js +55 -19
- package/dist/commands/stop.js +15 -17
- package/dist/commands/tags.js +6 -4
- package/dist/commands/tasks.js +18 -23
- package/dist/commands/timeoff.js +23 -16
- package/dist/commands/users.js +7 -5
- package/dist/commands/webhooks.js +14 -12
- package/dist/completions.js +290 -55
- package/dist/config.js +10 -6
- package/dist/duration.js +5 -4
- package/dist/error-codes.js +34 -6
- package/dist/failure.js +87 -0
- package/dist/flags.js +74 -0
- package/dist/generated/version.js +1 -1
- package/dist/index.js +41 -105
- package/dist/output.js +62 -28
- package/dist/write-outcome.js +84 -0
- package/package.json +3 -3
|
@@ -1,7 +1,27 @@
|
|
|
1
|
-
import { AlreadyReportedError, printRecords } from "../output.js";
|
|
1
|
+
import { AlreadyReportedError, printRecords, printWarning } from "../output.js";
|
|
2
2
|
import { printReceipt } from "../receipt.js";
|
|
3
|
+
import { dispatchedWrite, writeFailure } from "../write-outcome.js";
|
|
3
4
|
import { clampPageSize, parseFloatArg, parseIntArg, promoteDateBoundary, requireRfc3339Timestamp, resolveContext, } from "./helpers.js";
|
|
4
5
|
import { leafCommand } from "./leaf-command.js";
|
|
6
|
+
const PUBLISH_SCOPE_WARNING = "Publishing this window includes all other drafts for the same user.";
|
|
7
|
+
async function readPublication(client, window, id) {
|
|
8
|
+
try {
|
|
9
|
+
const rows = await client.scheduling.list(window);
|
|
10
|
+
const row = rows.find((item) => item.id === id);
|
|
11
|
+
return row && "published" in row && typeof row.published === "boolean"
|
|
12
|
+
? row.published
|
|
13
|
+
: undefined;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function identifiedAssignment(rows) {
|
|
20
|
+
const first = Array.isArray(rows) ? rows[0] : undefined;
|
|
21
|
+
if (first === null || typeof first !== "object" || !("id" in first))
|
|
22
|
+
return undefined;
|
|
23
|
+
return typeof first.id === "string" && first.id.trim() !== "" ? first : undefined;
|
|
24
|
+
}
|
|
5
25
|
export const registerSchedulingCommand = (program, services) => {
|
|
6
26
|
const scheduling = program
|
|
7
27
|
.command("scheduling")
|
|
@@ -16,11 +36,13 @@ export const registerSchedulingCommand = (program, services) => {
|
|
|
16
36
|
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
17
37
|
.option("--name <text>", "Filter by assignment name substring.")
|
|
18
38
|
.action(async function (opts) {
|
|
39
|
+
const start = promoteDateBoundary(opts.from, "from", "start");
|
|
40
|
+
const end = promoteDateBoundary(opts.to, "to", "end");
|
|
19
41
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
20
42
|
const req = {
|
|
21
43
|
workspaceId,
|
|
22
|
-
start
|
|
23
|
-
end
|
|
44
|
+
start,
|
|
45
|
+
end,
|
|
24
46
|
page: opts.page,
|
|
25
47
|
"page-size": clampPageSize(opts.limit, 200),
|
|
26
48
|
};
|
|
@@ -57,7 +79,7 @@ export const registerSchedulingCommand = (program, services) => {
|
|
|
57
79
|
.option("--note <text>", "Assignment note.")
|
|
58
80
|
.option("--billable", "Mark assignment as billable.", false)
|
|
59
81
|
.option("--include-non-working-days", "Include weekends/non-working days.", false)
|
|
60
|
-
.option("--publish", "Publish
|
|
82
|
+
.option("--publish", "Publish all drafts for this user in the start/end window, including other drafts.", false)
|
|
61
83
|
.action(async function (opts) {
|
|
62
84
|
const start = requireRfc3339Timestamp(opts.start, "start");
|
|
63
85
|
const end = requireRfc3339Timestamp(opts.end, "end");
|
|
@@ -78,11 +100,13 @@ export const registerSchedulingCommand = (program, services) => {
|
|
|
78
100
|
if (opts.includeNonWorkingDays)
|
|
79
101
|
body.includeNonWorkingDays = true;
|
|
80
102
|
const req = { workspaceId, body };
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
103
|
+
const created = identifiedAssignment(await dispatchedWrite(this, client.scheduling.createRecurring(req)));
|
|
104
|
+
if (created === undefined) {
|
|
105
|
+
throw new Error("Clockify accepted the request, but its response identifies no created assignment. " +
|
|
106
|
+
(opts.publish === true ? "Nothing was published. " : "") +
|
|
107
|
+
`Check the window with: clk115 scheduling list --from ${start} --to ${end} --json`);
|
|
108
|
+
}
|
|
109
|
+
let publication = { kind: "draft" };
|
|
86
110
|
if (opts.publish === true) {
|
|
87
111
|
const publishRequest = {
|
|
88
112
|
start,
|
|
@@ -90,58 +114,88 @@ export const registerSchedulingCommand = (program, services) => {
|
|
|
90
114
|
userFilter: { contains: "CONTAINS", ids: [opts.user] },
|
|
91
115
|
};
|
|
92
116
|
try {
|
|
93
|
-
await client.scheduling.publish({ workspaceId, body: publishRequest });
|
|
94
|
-
|
|
117
|
+
await dispatchedWrite(this, client.scheduling.publish({ workspaceId, body: publishRequest }));
|
|
118
|
+
publication = { kind: "published" };
|
|
95
119
|
}
|
|
96
120
|
catch (err) {
|
|
97
121
|
const detail = err instanceof Error ? err.message : String(err);
|
|
98
|
-
|
|
99
|
-
|
|
122
|
+
const { classifyWriteOutcome } = await import("clockify-sdk-ts-115/errors");
|
|
123
|
+
const published = classifyWriteOutcome(err) === "definitely-failed"
|
|
124
|
+
? false
|
|
125
|
+
: await readPublication(client, { workspaceId, start, end }, created.id);
|
|
126
|
+
if (published === undefined) {
|
|
127
|
+
publication = {
|
|
128
|
+
kind: "unknown",
|
|
129
|
+
cause: err,
|
|
130
|
+
warning: `Assignment created. Publication state is unknown after the publish error: ${detail}`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
else if (published) {
|
|
134
|
+
publication = { kind: "published" };
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
publication = {
|
|
138
|
+
kind: "publish_failed",
|
|
139
|
+
cause: err,
|
|
140
|
+
warning: `The assignment was created but publishing it failed: ${detail}. It remains an unpublished draft.`,
|
|
141
|
+
publishRequest,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
100
144
|
}
|
|
101
145
|
}
|
|
102
|
-
const
|
|
103
|
-
id: created.id
|
|
146
|
+
const baseData = {
|
|
147
|
+
id: created.id,
|
|
104
148
|
user: created.userId ?? "",
|
|
105
149
|
project: created.projectId ?? "",
|
|
106
150
|
hoursPerDay: created.hoursPerDay ?? 0,
|
|
107
151
|
start: created.start ?? created.period?.start ?? start,
|
|
108
152
|
end: created.end ?? created.period?.end ?? end,
|
|
109
|
-
published,
|
|
110
|
-
...(failedPublishRequest
|
|
111
|
-
? {
|
|
112
|
-
warningCode: "publish_failed",
|
|
113
|
-
publishRequest: failedPublishRequest,
|
|
114
|
-
}
|
|
115
|
-
: {}),
|
|
153
|
+
published: publication.kind === "unknown" ? "unknown" : publication.kind === "published",
|
|
116
154
|
};
|
|
117
|
-
const recoveryCommand =
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
155
|
+
const recoveryCommand = publication.kind === "unknown"
|
|
156
|
+
? `clk115 api GET /workspaces/{workspaceId}/scheduling/assignments/all -q start=${start} -q end=${end} --all`
|
|
157
|
+
: "clk115 api PUT /workspaces/{workspaceId}/scheduling/assignments/publish --body -";
|
|
158
|
+
const recoveryReason = publication.kind === "unknown"
|
|
159
|
+
? `Check assignment ${baseData.id} before retrying publication.`
|
|
160
|
+
: "Pipe the stored publishRequest JSON to stdin to publish the created draft.";
|
|
161
|
+
const needsRecovery = publication.kind === "publish_failed" || publication.kind === "unknown";
|
|
162
|
+
const warnings = [];
|
|
163
|
+
if ("warning" in publication)
|
|
164
|
+
warnings.push(`${publication.warning} ${PUBLISH_SCOPE_WARNING}`);
|
|
165
|
+
else if (publication.kind === "published")
|
|
166
|
+
warnings.push(PUBLISH_SCOPE_WARNING);
|
|
167
|
+
if (output.mode === "table") {
|
|
168
|
+
for (const warning of warnings)
|
|
169
|
+
printWarning(warning, output);
|
|
170
|
+
}
|
|
122
171
|
printReceipt({
|
|
123
172
|
ok: true,
|
|
124
173
|
action: "scheduling.create",
|
|
125
174
|
entity: "scheduling_assignment",
|
|
126
|
-
ids: { assignmentId:
|
|
127
|
-
data:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
175
|
+
ids: { assignmentId: baseData.id },
|
|
176
|
+
data: {
|
|
177
|
+
...baseData,
|
|
178
|
+
...(opts.publish && { publishScope: { userId: opts.user, start, end } }),
|
|
179
|
+
...("cause" in publication && {
|
|
180
|
+
...await writeFailure(this, publication.cause),
|
|
181
|
+
warningCode: publication.kind === "unknown" ? "publish_unknown" : "publish_failed",
|
|
182
|
+
recoveryCommand,
|
|
183
|
+
recovery: `Read back the assignment before repeating any write. ${recoveryReason}`,
|
|
184
|
+
}),
|
|
185
|
+
...(publication.kind === "publish_failed" && { publishRequest: publication.publishRequest }),
|
|
186
|
+
},
|
|
187
|
+
changed: { created: [{ type: "scheduling_assignment", id: baseData.id }] },
|
|
188
|
+
warnings,
|
|
189
|
+
next: needsRecovery
|
|
190
|
+
? [{ command: recoveryCommand, reason: recoveryReason }]
|
|
137
191
|
: [
|
|
138
192
|
{
|
|
139
|
-
command: `clk115 scheduling list --from ${
|
|
193
|
+
command: `clk115 scheduling list --from ${baseData.start} --to ${baseData.end} --json`,
|
|
140
194
|
reason: "Verify the assignment appears.",
|
|
141
195
|
},
|
|
142
196
|
],
|
|
143
197
|
}, output);
|
|
144
|
-
if (
|
|
198
|
+
if (needsRecovery) {
|
|
145
199
|
throw new AlreadyReportedError();
|
|
146
200
|
}
|
|
147
201
|
});
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { UsageError } from "../failure.js";
|
|
3
|
+
import { SHARED_REPORT_FILTER_EXPORT_TYPES, SHARED_REPORT_TYPES, SUMMARY_GROUPS, } from "./sharedReports.js";
|
|
4
|
+
const nonEmptyStringSchema = z
|
|
5
|
+
.string()
|
|
6
|
+
.refine((value) => value.trim() !== "", "must be a non-empty string.");
|
|
7
|
+
const dateStringSchema = nonEmptyStringSchema.refine((value) => !Number.isNaN(Date.parse(value)), "must be a valid date string.");
|
|
8
|
+
const upperCaseString = (value) => typeof value === "string" ? value.toUpperCase() : value;
|
|
9
|
+
const sharedReportTypeSchema = z.preprocess(upperCaseString, z.enum(SHARED_REPORT_TYPES));
|
|
10
|
+
const sharedReportExportTypeSchema = z.preprocess(upperCaseString, z.enum(SHARED_REPORT_FILTER_EXPORT_TYPES));
|
|
11
|
+
const openObjectSchema = z.record(z.string(), z.unknown());
|
|
12
|
+
const INT_MESSAGE = { error: "provide a whole integer" };
|
|
13
|
+
const sharedUsersFilterSchema = z
|
|
14
|
+
.object({
|
|
15
|
+
contains: z.enum(["CONTAINS", "DOES_NOT_CONTAIN", "CONTAINS_ONLY"]).optional(),
|
|
16
|
+
ids: z.array(z.string()).optional(),
|
|
17
|
+
status: z.enum(["ALL", "ACTIVE", "INACTIVE"]).optional(),
|
|
18
|
+
})
|
|
19
|
+
.strict();
|
|
20
|
+
const sharedAttendanceFilterSchema = z
|
|
21
|
+
.object({
|
|
22
|
+
page: z.number().int(INT_MESSAGE).optional(),
|
|
23
|
+
pageSize: z.number().int(INT_MESSAGE).optional(),
|
|
24
|
+
users: sharedUsersFilterSchema.optional(),
|
|
25
|
+
})
|
|
26
|
+
.strict();
|
|
27
|
+
const sharedDetailedFilterSchema = z
|
|
28
|
+
.object({
|
|
29
|
+
auditFilter: openObjectSchema.optional(),
|
|
30
|
+
options: openObjectSchema.optional(),
|
|
31
|
+
page: z.number().int(INT_MESSAGE).optional(),
|
|
32
|
+
pageSize: z.number().int(INT_MESSAGE).optional(),
|
|
33
|
+
sortColumn: nonEmptyStringSchema.optional(),
|
|
34
|
+
sortOrder: z.enum(["ASCENDING", "DESCENDING"]).optional(),
|
|
35
|
+
})
|
|
36
|
+
.strict();
|
|
37
|
+
const sharedSummaryFilterSchema = z
|
|
38
|
+
.object({
|
|
39
|
+
groups: z
|
|
40
|
+
.array(z.enum(SUMMARY_GROUPS))
|
|
41
|
+
.min(1, { error: `provide 1-3 of: ${SUMMARY_GROUPS.join(", ")}` })
|
|
42
|
+
.max(3, { error: `provide at most 3 of: ${SUMMARY_GROUPS.join(", ")}` }),
|
|
43
|
+
sortColumn: nonEmptyStringSchema.optional(),
|
|
44
|
+
})
|
|
45
|
+
.strict();
|
|
46
|
+
const sharedWeeklyFilterSchema = z
|
|
47
|
+
.object({
|
|
48
|
+
group: z.enum(["PROJECT", "USER"]),
|
|
49
|
+
subgroup: z.literal("TIME"),
|
|
50
|
+
})
|
|
51
|
+
.strict();
|
|
52
|
+
const sharedReportFilterSchema = z
|
|
53
|
+
.object({
|
|
54
|
+
attendanceFilter: sharedAttendanceFilterSchema.optional(),
|
|
55
|
+
dateRangeEnd: dateStringSchema,
|
|
56
|
+
dateRangeStart: dateStringSchema,
|
|
57
|
+
detailedFilter: sharedDetailedFilterSchema.optional(),
|
|
58
|
+
exportType: sharedReportExportTypeSchema,
|
|
59
|
+
summaryFilter: sharedSummaryFilterSchema.optional(),
|
|
60
|
+
weeklyFilter: sharedWeeklyFilterSchema.optional(),
|
|
61
|
+
})
|
|
62
|
+
.strict();
|
|
63
|
+
const sharedReportBodySchema = z
|
|
64
|
+
.object({
|
|
65
|
+
filter: sharedReportFilterSchema,
|
|
66
|
+
isPublic: z.boolean().optional(),
|
|
67
|
+
name: nonEmptyStringSchema,
|
|
68
|
+
type: sharedReportTypeSchema,
|
|
69
|
+
})
|
|
70
|
+
.strict();
|
|
71
|
+
function toSharedUsersFilter(value) {
|
|
72
|
+
return {
|
|
73
|
+
...(value.contains !== undefined ? { contains: value.contains } : {}),
|
|
74
|
+
...(value.ids !== undefined ? { ids: value.ids } : {}),
|
|
75
|
+
...(value.status !== undefined ? { status: value.status } : {}),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function toSharedReportFilter(value) {
|
|
79
|
+
return {
|
|
80
|
+
dateRangeEnd: value.dateRangeEnd,
|
|
81
|
+
dateRangeStart: value.dateRangeStart,
|
|
82
|
+
exportType: value.exportType,
|
|
83
|
+
...(value.attendanceFilter !== undefined
|
|
84
|
+
? {
|
|
85
|
+
attendanceFilter: {
|
|
86
|
+
...(value.attendanceFilter.page !== undefined
|
|
87
|
+
? { page: value.attendanceFilter.page }
|
|
88
|
+
: {}),
|
|
89
|
+
...(value.attendanceFilter.pageSize !== undefined
|
|
90
|
+
? { pageSize: value.attendanceFilter.pageSize }
|
|
91
|
+
: {}),
|
|
92
|
+
...(value.attendanceFilter.users !== undefined
|
|
93
|
+
? { users: toSharedUsersFilter(value.attendanceFilter.users) }
|
|
94
|
+
: {}),
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
: {}),
|
|
98
|
+
...(value.detailedFilter !== undefined
|
|
99
|
+
? {
|
|
100
|
+
detailedFilter: {
|
|
101
|
+
...(value.detailedFilter.auditFilter !== undefined
|
|
102
|
+
? { auditFilter: value.detailedFilter.auditFilter }
|
|
103
|
+
: {}),
|
|
104
|
+
...(value.detailedFilter.options !== undefined
|
|
105
|
+
? { options: value.detailedFilter.options }
|
|
106
|
+
: {}),
|
|
107
|
+
...(value.detailedFilter.page !== undefined
|
|
108
|
+
? { page: value.detailedFilter.page }
|
|
109
|
+
: {}),
|
|
110
|
+
...(value.detailedFilter.pageSize !== undefined
|
|
111
|
+
? { pageSize: value.detailedFilter.pageSize }
|
|
112
|
+
: {}),
|
|
113
|
+
...(value.detailedFilter.sortColumn !== undefined
|
|
114
|
+
? { sortColumn: value.detailedFilter.sortColumn }
|
|
115
|
+
: {}),
|
|
116
|
+
...(value.detailedFilter.sortOrder !== undefined
|
|
117
|
+
? { sortOrder: value.detailedFilter.sortOrder }
|
|
118
|
+
: {}),
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
: {}),
|
|
122
|
+
...(value.summaryFilter !== undefined
|
|
123
|
+
? {
|
|
124
|
+
summaryFilter: {
|
|
125
|
+
groups: value.summaryFilter.groups,
|
|
126
|
+
...(value.summaryFilter.sortColumn !== undefined
|
|
127
|
+
? { sortColumn: value.summaryFilter.sortColumn }
|
|
128
|
+
: {}),
|
|
129
|
+
},
|
|
130
|
+
}
|
|
131
|
+
: {}),
|
|
132
|
+
...(value.weeklyFilter !== undefined
|
|
133
|
+
? {
|
|
134
|
+
weeklyFilter: {
|
|
135
|
+
group: value.weeklyFilter.group,
|
|
136
|
+
subgroup: value.weeklyFilter.subgroup,
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
: {}),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function toSharedReportBody(value) {
|
|
143
|
+
return {
|
|
144
|
+
filter: toSharedReportFilter(value.filter),
|
|
145
|
+
name: value.name,
|
|
146
|
+
type: value.type,
|
|
147
|
+
...(value.isPublic !== undefined ? { isPublic: value.isPublic } : {}),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function parseFilterJson(raw) {
|
|
151
|
+
if (typeof raw !== "string") {
|
|
152
|
+
throw new UsageError("--filter must be a JSON object.");
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
return JSON.parse(raw);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
throw new UsageError(`--filter must be a JSON object, e.g. '{"dateRangeStart":"…","dateRangeEnd":"…"}'`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function schemaIssueLabel(issue, operation) {
|
|
162
|
+
const [root, ...path] = issue.path;
|
|
163
|
+
if (root === "filter") {
|
|
164
|
+
return path.length > 0 ? `--filter ${path.join(".")}` : "--filter";
|
|
165
|
+
}
|
|
166
|
+
if (root === "name")
|
|
167
|
+
return "--name";
|
|
168
|
+
if (root === "type")
|
|
169
|
+
return "--type";
|
|
170
|
+
return operation;
|
|
171
|
+
}
|
|
172
|
+
function sharedReportValidationError(error, operation, rawType) {
|
|
173
|
+
const invalidTypeIssue = error.issues.find((issue) => issue.path[0] === "type" && issue.code === "invalid_value");
|
|
174
|
+
if (invalidTypeIssue !== undefined) {
|
|
175
|
+
return new UsageError(`Unknown --type "${String(rawType)}". Provide one of: ${SHARED_REPORT_TYPES.join(", ")}.`);
|
|
176
|
+
}
|
|
177
|
+
const issue = error.issues[0];
|
|
178
|
+
if (issue === undefined)
|
|
179
|
+
return new UsageError(`${operation}: invalid request.`);
|
|
180
|
+
if (issue.path.length === 1 &&
|
|
181
|
+
issue.path[0] === "filter" &&
|
|
182
|
+
issue.code === "invalid_type" &&
|
|
183
|
+
issue.expected === "object") {
|
|
184
|
+
return new UsageError("--filter must be a JSON object.");
|
|
185
|
+
}
|
|
186
|
+
const label = schemaIssueLabel(issue, operation);
|
|
187
|
+
if (issue.code === "unrecognized_keys") {
|
|
188
|
+
const fieldKind = issue.path[0] === "filter" ? "filter field(s)" : "field(s)";
|
|
189
|
+
return new UsageError(`${label} has unknown ${fieldKind}: ${issue.keys.join(", ")}.`);
|
|
190
|
+
}
|
|
191
|
+
return new UsageError(`${label}: ${issue.message}`);
|
|
192
|
+
}
|
|
193
|
+
export function parseSharedReportBody(opts, operation) {
|
|
194
|
+
const candidate = {
|
|
195
|
+
name: opts.name,
|
|
196
|
+
type: opts.type,
|
|
197
|
+
filter: parseFilterJson(opts.filter),
|
|
198
|
+
...(opts.public !== undefined ? { isPublic: opts.public } : {}),
|
|
199
|
+
};
|
|
200
|
+
const result = sharedReportBodySchema.safeParse(candidate);
|
|
201
|
+
if (!result.success) {
|
|
202
|
+
throw sharedReportValidationError(result.error, operation, opts.type);
|
|
203
|
+
}
|
|
204
|
+
return toSharedReportBody(result.data);
|
|
205
|
+
}
|