Skip to main content
import { validateExecutionMetadataSync } from 'openlinear/types';

Enums

ExecutionStatus

type ExecutionStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';

ErrorCategory

type ErrorCategory = 'AUTH' | 'RATE_LIMIT' | 'MERGE_CONFLICT' | 'TIMEOUT' | 'UNKNOWN';

ExecutionMetadataSync

The full sync payload shape:
FieldTypeRequiredDescription
version'1.0'NoSchema version
taskIdstringYesTask UUID
runIdstringYesExecution run UUID
statusExecutionStatusYesCurrent status
startedAtstringNoISO 8601 datetime
completedAtstringNoISO 8601 datetime
durationMsnumberNoNon-negative integer
branchstringNoGit branch name
commitShastringNoGit commit hash
prUrlstringNoValid URL to PR
prNumbernumberNoPositive integer
outcomestringNoMax 500 chars summary
errorCategoryErrorCategoryNoError classification

Validation Functions

validateExecutionMetadataSync(payload)

Parses and returns the payload as ExecutionMetadataSync. Throws ZodError on failure.
import { validateExecutionMetadataSync } from 'openlinear/types';

const metadata = validateExecutionMetadataSync({
  taskId: 'tsk_123',
  runId: 'run_456',
  status: 'completed',
  durationMs: 45000,
  branch: 'feature/add-login',
  prUrl: 'https://github.com/org/repo/pull/42',
  prNumber: 42,
});

safeValidateExecutionMetadataSync(payload)

Returns a discriminated union — never throws.
import { safeValidateExecutionMetadataSync } from 'openlinear/types';

const result = safeValidateExecutionMetadataSync(payload);
if (result.success) {
  console.log('Valid:', result.data);
} else {
  console.error('Invalid:', result.error.errors);
}

checkExecutionMetadataSync(payload)

Returns { valid: boolean; issues?: string[] } for human-readable validation.
import { checkExecutionMetadataSync } from 'openlinear/types';

const { valid, issues } = checkExecutionMetadataSync(payload);
if (!valid) {
  issues?.forEach(issue => console.warn(issue));
}

validateExecutionMetadataMiddleware()

Express middleware factory. Validates req.body and sets req.validatedMetadata.
import express from 'express';
import { validateExecutionMetadataMiddleware } from 'openlinear/types';

const app = express();
app.use(express.json());

app.post('/sync', validateExecutionMetadataMiddleware(), (req, res) => {
  res.json({ received: req.validatedMetadata.taskId });
});
Error response (400):
{
  "error": "Invalid sync payload",
  "code": "VALIDATION_ERROR",
  "details": [{"field": "prUrl", "message": "Invalid url"}]
}