openlinear 0.1.3

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,113 @@
1
+ import { z } from 'zod';
2
+
3
+ export const ErrorCategory = z.enum([
4
+ 'AUTH',
5
+ 'RATE_LIMIT',
6
+ 'MERGE_CONFLICT',
7
+ 'TIMEOUT',
8
+ 'UNKNOWN'
9
+ ]);
10
+
11
+ export const ExecutionStatus = z.enum([
12
+ 'pending',
13
+ 'running',
14
+ 'completed',
15
+ 'failed',
16
+ 'cancelled'
17
+ ]);
18
+
19
+ export const ExecutionMetadataSyncSchema = z.object({
20
+ taskId: z.string(),
21
+ runId: z.string(),
22
+ status: ExecutionStatus,
23
+ startedAt: z.string().datetime().optional(),
24
+ completedAt: z.string().datetime().optional(),
25
+ durationMs: z.number().int().min(0).optional(),
26
+ progress: z.number().int().min(0).max(100).optional(),
27
+ branch: z.string().optional(),
28
+ commitSha: z.string().optional(),
29
+ prUrl: z.string().url().optional(),
30
+ prNumber: z.number().int().positive().optional(),
31
+ outcome: z.string().max(500).optional(),
32
+ errorCategory: ErrorCategory.optional(),
33
+ filesChanged: z.number().int().min(0).optional(),
34
+ toolsExecuted: z.number().int().min(0).optional(),
35
+ }).strict();
36
+
37
+ export type ExecutionMetadataSync = z.infer<typeof ExecutionMetadataSyncSchema>;
38
+
39
+ export function validateExecutionMetadataSync(payload: unknown): ExecutionMetadataSync {
40
+ return ExecutionMetadataSyncSchema.parse(payload);
41
+ }
42
+
43
+ export function safeValidateExecutionMetadataSync(payload: unknown):
44
+ | { success: true; data: ExecutionMetadataSync }
45
+ | { success: false; error: z.ZodError } {
46
+ const result = ExecutionMetadataSyncSchema.safeParse(payload);
47
+
48
+ if (result.success) {
49
+ return { success: true, data: result.data };
50
+ } else {
51
+ return { success: false, error: result.error };
52
+ }
53
+ }
54
+
55
+ export function checkExecutionMetadataSync(payload: unknown): {
56
+ valid: boolean;
57
+ issues?: string[];
58
+ } {
59
+ const result = ExecutionMetadataSyncSchema.safeParse(payload);
60
+
61
+ if (result.success) {
62
+ return { valid: true };
63
+ } else {
64
+ return {
65
+ valid: false,
66
+ issues: result.error.errors.map(e =>
67
+ `${e.path.join('.')}: ${e.message}`
68
+ )
69
+ };
70
+ }
71
+ }
72
+
73
+ export const FORBIDDEN_SYNC_FIELDS = [
74
+ 'prompt',
75
+ 'logs',
76
+ 'toolLogs',
77
+ 'executionLogs',
78
+ 'repoPath',
79
+ 'accessToken',
80
+ 'apiKey',
81
+ 'passwordHash',
82
+ 'jwt',
83
+ 'client',
84
+ 'timeoutId',
85
+ 'rawOutput',
86
+ 'diff',
87
+ 'fileContents',
88
+ 'env',
89
+ 'environment',
90
+ 'processEnv',
91
+ ] as const;
92
+
93
+ export function isForbiddenField(field: string): boolean {
94
+ return FORBIDDEN_SYNC_FIELDS.includes(field as any);
95
+ }
96
+
97
+ export function sanitizePayload(payload: Record<string, any>): {
98
+ sanitized: Record<string, any>;
99
+ removed: string[];
100
+ } {
101
+ const sanitized: Record<string, any> = {};
102
+ const removed: string[] = [];
103
+
104
+ for (const [key, value] of Object.entries(payload)) {
105
+ if (isForbiddenField(key)) {
106
+ removed.push(key);
107
+ } else {
108
+ sanitized[key] = value;
109
+ }
110
+ }
111
+
112
+ return { sanitized, removed };
113
+ }