-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Expand file tree
/
Copy pathwork-product.ts
More file actions
102 lines (90 loc) · 3.23 KB
/
Copy pathwork-product.ts
File metadata and controls
102 lines (90 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { z } from "zod";
import { workspaceFileRefSchema } from "./workspace-file-resource.js";
function attachmentContentPath(attachmentId: string): string {
return `/api/attachments/${attachmentId}/content`;
}
export const issueWorkProductTypeSchema = z.enum([
"preview_url",
"runtime_service",
"pull_request",
"branch",
"commit",
"artifact",
"document",
]);
export const issueWorkProductStatusSchema = z.enum([
"active",
"ready_for_review",
"approved",
"changes_requested",
"merged",
"closed",
"failed",
"archived",
"draft",
]);
export const issueWorkProductReviewStateSchema = z.enum([
"none",
"needs_board_review",
"approved",
"changes_requested",
]);
export const attachmentArtifactWorkProductMetadataSchema = z.object({
attachmentId: z.string().uuid(),
contentType: z.string().min(1),
byteSize: z.number().int().nonnegative(),
contentPath: z.string().min(1),
openPath: z.string().min(1),
downloadPath: z.string().min(1),
originalFilename: z.string().optional().nullable(),
}).superRefine((value, ctx) => {
const contentPath = attachmentContentPath(value.attachmentId);
if (value.contentPath !== contentPath) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["contentPath"],
message: "contentPath must point to the same-origin attachment content route",
});
}
if (value.openPath !== contentPath) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["openPath"],
message: "openPath must point to the same-origin attachment content route",
});
}
if (value.downloadPath !== `${contentPath}?download=1`) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["downloadPath"],
message: "downloadPath must point to the same-origin attachment download route",
});
}
});
export type AttachmentArtifactWorkProductMetadata = z.infer<typeof attachmentArtifactWorkProductMetadataSchema>;
export const issueWorkProductMetadataSchema = z
.object({
resourceRef: workspaceFileRefSchema.optional().nullable(),
})
.passthrough();
export type IssueWorkProductMetadata = z.infer<typeof issueWorkProductMetadataSchema>;
export const createIssueWorkProductSchema = z.object({
projectId: z.string().uuid().optional().nullable(),
executionWorkspaceId: z.string().uuid().optional().nullable(),
runtimeServiceId: z.string().uuid().optional().nullable(),
type: issueWorkProductTypeSchema,
provider: z.string().min(1),
externalId: z.string().optional().nullable(),
title: z.string().min(1),
url: z.string().url().optional().nullable(),
status: issueWorkProductStatusSchema.default("active"),
reviewState: issueWorkProductReviewStateSchema.optional().default("none"),
isPrimary: z.boolean().optional().default(false),
healthStatus: z.enum(["unknown", "healthy", "unhealthy"]).optional().default("unknown"),
summary: z.string().optional().nullable(),
metadata: issueWorkProductMetadataSchema.optional().nullable(),
createdByRunId: z.string().uuid().optional().nullable(),
});
export type CreateIssueWorkProduct = z.infer<typeof createIssueWorkProductSchema>;
export const updateIssueWorkProductSchema = createIssueWorkProductSchema.partial();
export type UpdateIssueWorkProduct = z.infer<typeof updateIssueWorkProductSchema>;