Files
PaperClipAI/packages/shared/src/validators/company-portability.ts
T
3abe9e2134 build(deps): bump zod from 3.25.76 to 4.4.3 (#11719)
Bumps [zod](https://github.com/colinhacks/zod) from 3.25.76 to 4.4.3.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/colinhacks/zod/releases">zod's
releases</a>.</em></p>
<blockquote>
<h2>v4.4.3</h2>
<h2>Commits:</h2>
<ul>
<li>4c2fa95ce3f3390fbc522324e406b4e9e89b88f9 docs: use Zernio primary
wordmark for gold sponsor logo</li>
<li>2aeec83eb135e3a83756e973ef44845fc5a455d2 docs: prune lapsed gold
sponsors and rebalance logo sizing</li>
<li>7391be88ac1ee5cd02057f5ccc012a1f5df4efd0 docs: prune lapsed
silver/bronze sponsors and add active ones</li>
<li>2c703322a21b4e2b12f33f49ea8430c451a68b4f docs: normalize bronze
sponsor logos to github avatar pattern</li>
<li>9195250cab0e7950efe39c3926d6c203b4b0a170 docs: remove Mintlify from
bronze sponsors (churned)</li>
<li>b8dffe9e62f17e6571e6249d05cc5102b54d94e4 docs: remove Numeric and
Speakeasy (2+ missed monthly cycles)</li>
<li>1cab69383fcdeae2a366d5e2a2fc4d8fc765d168 fix(v4): restore catch
handling for absent object keys (<a
href="https://redirect.github.com/colinhacks/zod/issues/5937">#5937</a>)
(<a
href="https://redirect.github.com/colinhacks/zod/issues/5939">#5939</a>)</li>
<li>c2be4f819064eed62c7c350a2d399b5faecd15f8 fix(v4): generalize
optin/fallback to transform; restore preprocess on absent keys (<a
href="https://redirect.github.com/colinhacks/zod/issues/5941">#5941</a>)</li>
<li>f3c9ec03ba7a28ae72d25cc295f38674bee0f559 4.4.3</li>
<li>1fb56a5c18c27102dbc92260a4007c7732a0ccca docs: document release
procedure in AGENTS.md</li>
</ul>
<h2>v4.4.2</h2>
<h2>Commits:</h2>
<ul>
<li>0c62df0ea19fd05abdf90473e9eef7eea530fab2 Clean up docs navigation
and stale labels (<a
href="https://redirect.github.com/colinhacks/zod/issues/5901">#5901</a>)</li>
<li>20cc794895cc8604fe0c87d83a5d1c3f89fad0ac chore: add security policy
and refresh tooling deps</li>
<li>6fbe07b0177efdd1bf1c0b05160e70d7a0702337 fix(docs): heading anchor
links now include the hash so it doesnt scoll all the way up, follows
navbar logic (<a
href="https://redirect.github.com/colinhacks/zod/issues/5791">#5791</a>)</li>
<li>4bbed1b1c73eca4ce9e59b1189ed236aa6c8b5bd Tighten discriminated union
option typing</li>
<li>bbac3e567e7fccfaaf7cdc97f1ce30c295e2c908 Update PR guidance for
agents</li>
<li>cf0dc942a32805c292fff59ade20a7ace980735a Merge remote-tracking
branch 'origin/main' into fix-discriminated-union-key-constraint</li>
<li>292c894a5fd2aa42e527900b83d8d7a3009a709c docs: add Zernio gold
sponsor</li>
<li>1fc9f311c28dcf80d0bb5a36b177086cbc3d8eca docs: document codec
inversion</li>
<li>1373c85da9aeff704a9762d27bc58699618aefb7 docs: remove AI disclosure
guidance</li>
<li>e20d02b473c08e3a4e557bc610b1b5fac079b649 chore: ignore triage
notes</li>
<li>e58ea4d91b1dfe8194b73508203213cbc7e9c936 docs: test Zod Mini tab
code heights</li>
<li>905761a5d127e8d5dd2ebb3bc88c75cb0b8149ff docs: document preprocess
input type narrowing</li>
<li>bf64bac850d4dee2b7dde7e64909d5d796d32043 chore: tighten test
guidance in AGENTS.md</li>
<li>8ec4e73f4c4693b6361ad591be40fb41eb8a9f95 chore: update play.ts
scratch</li>
<li>02c2baf7d0d615872fa4528a8020603b71211702 Make z.preprocess defer
optionality to inner schema (<a
href="https://redirect.github.com/colinhacks/zod/issues/5929">#5929</a>)</li>
<li>88015df8e25c44fb5385eb3ef28935119cd5edea fix(docs): drop deprecated
<code>baseUrl</code> from tsconfig</li>
<li>c59d4474e3b4cad1b323462186cf607178ce8267 4.4.2</li>
</ul>
<h2>v4.4.1</h2>
<h2>Commits:</h2>
<ul>
<li>481f7be4238c83ed58183f921b2646f340a91c6a ci: gate release publishing
on full test workflow</li>
<li>95ccab423aec720b2523c3a64cdc7e3204537cc7 test(v3): restore optional
undefined expectations</li>
<li>cede2c63739a5823d6aa5093d291e9a111da943d fix(v4): reject tuple holes
before required defaults (<a
href="https://redirect.github.com/colinhacks/zod/issues/5900">#5900</a>)</li>
<li>edd0bf0f5ada4a8dc581c259407d7bbad0a71ea7 release: 4.4.1</li>
<li>180d83d1dbe6a59260710cc8637a3dea2281ee56 docs: remove Jazz featured
sponsor</li>
</ul>
<h2>v4.4.0</h2>
<h2>4.4.0</h2>
<p>This is a minor release with a wide set of correctness and soundness
fixes. Some fixes intentionally make Zod stricter, so code that depended
on previously accepted invalid or ambiguous inputs may need small
updates.</p>
<h2>Potentially breaking bug fixes</h2>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/colinhacks/zod/commit/1fb56a5c18c27102dbc92260a4007c7732a0ccca"><code>1fb56a5</code></a>
docs: document release procedure in AGENTS.md</li>
<li><a
href="https://github.com/colinhacks/zod/commit/f3c9ec03ba7a28ae72d25cc295f38674bee0f559"><code>f3c9ec0</code></a>
4.4.3</li>
<li><a
href="https://github.com/colinhacks/zod/commit/c2be4f819064eed62c7c350a2d399b5faecd15f8"><code>c2be4f8</code></a>
fix(v4): generalize optin/fallback to transform; restore preprocess on
absent...</li>
<li><a
href="https://github.com/colinhacks/zod/commit/1cab69383fcdeae2a366d5e2a2fc4d8fc765d168"><code>1cab693</code></a>
fix(v4): restore catch handling for absent object keys (<a
href="https://redirect.github.com/colinhacks/zod/issues/5937">#5937</a>)
(<a
href="https://redirect.github.com/colinhacks/zod/issues/5939">#5939</a>)</li>
<li><a
href="https://github.com/colinhacks/zod/commit/b8dffe9e62f17e6571e6249d05cc5102b54d94e4"><code>b8dffe9</code></a>
docs: remove Numeric and Speakeasy (2+ missed monthly cycles)</li>
<li><a
href="https://github.com/colinhacks/zod/commit/9195250cab0e7950efe39c3926d6c203b4b0a170"><code>9195250</code></a>
docs: remove Mintlify from bronze sponsors (churned)</li>
<li><a
href="https://github.com/colinhacks/zod/commit/2c703322a21b4e2b12f33f49ea8430c451a68b4f"><code>2c70332</code></a>
docs: normalize bronze sponsor logos to github avatar pattern</li>
<li><a
href="https://github.com/colinhacks/zod/commit/7391be88ac1ee5cd02057f5ccc012a1f5df4efd0"><code>7391be8</code></a>
docs: prune lapsed silver/bronze sponsors and add active ones</li>
<li><a
href="https://github.com/colinhacks/zod/commit/2aeec83eb135e3a83756e973ef44845fc5a455d2"><code>2aeec83</code></a>
docs: prune lapsed gold sponsors and rebalance logo sizing</li>
<li><a
href="https://github.com/colinhacks/zod/commit/4c2fa95ce3f3390fbc522324e406b4e9e89b88f9"><code>4c2fa95</code></a>
docs: use Zernio primary wordmark for gold sponsor logo</li>
<li>Additional commits viewable in <a
href="https://github.com/colinhacks/zod/compare/v3.25.76...v4.4.3">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~GitHub%20Actions">GitHub Actions</a>, a new
releaser for zod since your current version.</p>
</details>
<br />

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Priya Raman <priya@paperclip.ing>
Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-08-21 00:04:14 -07:00

335 lines
12 KiB
TypeScript

import { z } from "zod";
import { PERMISSION_KEYS } from "../constants.js";
import { MAX_COMPANY_ATTACHMENT_MAX_BYTES } from "../constants.js";
import {
issueCommentAuthorTypeSchema,
issueCommentMetadataSchema,
issueCommentPresentationSchema,
} from "./issue.js";
import { routineVariableSchema } from "./routine.js";
export const portabilityIncludeSchema = z
.object({
company: z.boolean().optional(),
agents: z.boolean().optional(),
projects: z.boolean().optional(),
issues: z.boolean().optional(),
skills: z.boolean().optional(),
})
.partial();
export const portabilityEnvInputSchema = z.object({
key: z.string().min(1),
description: z.string().nullable(),
agentSlug: z.string().min(1).nullable(),
projectSlug: z.string().min(1).nullable(),
kind: z.enum(["secret", "plain"]),
requirement: z.enum(["required", "optional"]),
defaultValue: z.string().nullable(),
portability: z.enum(["portable", "system_dependent"]),
});
export const portabilityFileEntrySchema = z.union([
z.string(),
z.object({
encoding: z.literal("base64"),
data: z.string(),
contentType: z.string().min(1).optional().nullable(),
}),
]);
export const portabilityCompanyManifestEntrySchema = z.object({
path: z.string().min(1),
name: z.string().min(1),
description: z.string().nullable(),
brandColor: z.string().nullable(),
logoPath: z.string().nullable(),
attachmentMaxBytes: z.number().int().min(1).max(MAX_COMPANY_ATTACHMENT_MAX_BYTES).nullable().default(null),
requireBoardApprovalForNewAgents: z.boolean(),
feedbackDataSharingEnabled: z.boolean().default(false),
feedbackDataSharingConsentAt: z.string().datetime().nullable().default(null),
feedbackDataSharingConsentByUserId: z.string().nullable().default(null),
feedbackDataSharingTermsVersion: z.string().nullable().default(null),
});
export const portabilitySidebarOrderSchema = z.object({
agents: z.array(z.string().min(1)).default([]),
projects: z.array(z.string().min(1)).default([]),
});
export const portabilityLabelManifestEntrySchema = z.object({
name: z.string().min(1),
color: z.string().min(1),
});
export const portabilityBlobManifestEntrySchema = z.object({
sha256: z.string().min(1),
byteSize: z.number().int().nonnegative(),
contentType: z.string().min(1),
});
export const portabilityAgentManifestEntrySchema = z.object({
slug: z.string().min(1),
name: z.string().min(1),
path: z.string().min(1),
skills: z.array(z.string().min(1)).default([]),
role: z.string().min(1),
title: z.string().nullable(),
icon: z.string().nullable(),
capabilities: z.string().nullable(),
reportsToSlug: z.string().min(1).nullable(),
adapterType: z.string().min(1),
adapterConfig: z.record(z.string(), z.unknown()),
runtimeConfig: z.record(z.string(), z.unknown()),
permissions: z.record(z.string(), z.unknown()),
permissionGrants: z.array(z.object({
permissionKey: z.enum(PERMISSION_KEYS),
scope: z.record(z.string(), z.unknown()).nullable().default(null),
})).default([]),
budgetMonthlyCents: z.number().int().nonnegative(),
metadata: z.record(z.string(), z.unknown()).nullable(),
});
export const portabilitySkillManifestEntrySchema = z.object({
key: z.string().min(1),
slug: z.string().min(1),
name: z.string().min(1),
path: z.string().min(1),
description: z.string().nullable(),
sourceType: z.string().min(1),
sourceLocator: z.string().nullable(),
sourceRef: z.string().nullable(),
trustLevel: z.string().nullable(),
compatibility: z.string().nullable(),
metadata: z.record(z.string(), z.unknown()).nullable(),
fileInventory: z.array(z.object({
path: z.string().min(1),
kind: z.string().min(1),
})).default([]),
});
export const portabilityProjectManifestEntrySchema = z.object({
slug: z.string().min(1),
name: z.string().min(1),
path: z.string().min(1),
description: z.string().nullable(),
ownerAgentSlug: z.string().min(1).nullable(),
leadAgentSlug: z.string().min(1).nullable(),
targetDate: z.string().nullable(),
color: z.string().nullable(),
status: z.string().nullable(),
executionWorkspacePolicy: z.record(z.string(), z.unknown()).nullable(),
workspaces: z.array(z.object({
key: z.string().min(1),
name: z.string().min(1),
sourceType: z.string().nullable(),
repoUrl: z.string().nullable(),
repoRef: z.string().nullable(),
defaultRef: z.string().nullable(),
visibility: z.string().nullable(),
setupCommand: z.string().nullable(),
cleanupCommand: z.string().nullable(),
metadata: z.record(z.string(), z.unknown()).nullable(),
isPrimary: z.boolean(),
})).default([]),
metadata: z.record(z.string(), z.unknown()).nullable(),
});
export const portabilityIssueRoutineTriggerManifestEntrySchema = z.object({
kind: z.string().min(1),
label: z.string().nullable(),
enabled: z.boolean(),
cronExpression: z.string().nullable(),
timezone: z.string().nullable(),
signingMode: z.string().nullable(),
replayWindowSec: z.number().int().nullable(),
});
export const portabilityIssueRoutineManifestEntrySchema = z.object({
concurrencyPolicy: z.string().nullable(),
catchUpPolicy: z.string().nullable(),
variables: z.array(routineVariableSchema).nullable().optional(),
triggers: z.array(portabilityIssueRoutineTriggerManifestEntrySchema).default([]),
});
export const portabilityIssueCommentManifestEntrySchema = z.object({
body: z.string().min(1),
authorType: issueCommentAuthorTypeSchema,
authorAgentSlug: z.string().min(1).nullable(),
authorUserId: z.string().nullable(),
presentation: issueCommentPresentationSchema.nullable(),
metadata: issueCommentMetadataSchema.nullable(),
createdAt: z.string().datetime().nullable(),
});
export const portabilityIssueDocumentManifestEntrySchema = z.object({
key: z.string().min(1),
title: z.string().nullable(),
format: z.string().min(1),
path: z.string().min(1),
});
export const portabilityIssueWorkProductManifestEntrySchema = z.object({
type: z.string().min(1),
provider: z.string().min(1),
externalId: z.string().nullable(),
title: z.string().min(1),
url: z.string().nullable(),
status: z.string().min(1),
reviewState: z.string().min(1),
isPrimary: z.boolean().default(false),
healthStatus: z.string().min(1),
summary: z.string().nullable(),
metadata: z.record(z.string(), z.unknown()).nullable(),
});
export const portabilityIssueMonitorManifestEntrySchema = z.object({
notes: z.string().nullable(),
scheduledBy: z.string().nullable(),
hadSchedule: z.boolean().default(false),
});
export const portabilityIssueAttachmentManifestEntrySchema = z.object({
sha256: z.string().min(1),
contentType: z.string().min(1),
originalFilename: z.string().nullable(),
byteSize: z.number().int().nonnegative(),
commentIndex: z.number().int().nonnegative().nullable().default(null),
});
export const portabilityIssueManifestEntrySchema = z.object({
slug: z.string().min(1),
identifier: z.string().min(1).nullable(),
title: z.string().min(1),
path: z.string().min(1),
projectSlug: z.string().min(1).nullable(),
projectWorkspaceKey: z.string().min(1).nullable(),
assigneeAgentSlug: z.string().min(1).nullable(),
description: z.string().nullable(),
recurring: z.boolean().default(false),
routine: portabilityIssueRoutineManifestEntrySchema.nullable(),
legacyRecurrence: z.record(z.string(), z.unknown()).nullable(),
status: z.string().nullable(),
priority: z.string().nullable(),
labelIds: z.array(z.string().min(1)).default([]),
labelNames: z.array(z.string().min(1)).default([]),
billingCode: z.string().nullable(),
executionWorkspaceSettings: z.record(z.string(), z.unknown()).nullable(),
assigneeAdapterOverrides: z.record(z.string(), z.unknown()).nullable(),
comments: z.array(portabilityIssueCommentManifestEntrySchema).default([]),
blockedBy: z.array(z.string().min(1)).default([]),
documents: z.array(portabilityIssueDocumentManifestEntrySchema).default([]),
workProducts: z.array(portabilityIssueWorkProductManifestEntrySchema).default([]),
monitor: portabilityIssueMonitorManifestEntrySchema.nullable().default(null),
attachments: z.array(portabilityIssueAttachmentManifestEntrySchema).default([]),
parentSlug: z.string().min(1).nullable().optional(),
createdAt: z.string().datetime().nullable().optional(),
updatedAt: z.string().datetime().nullable().optional(),
startedAt: z.string().datetime().nullable().optional(),
completedAt: z.string().datetime().nullable().optional(),
cancelledAt: z.string().datetime().nullable().optional(),
metadata: z.record(z.string(), z.unknown()).nullable(),
});
export const portabilityManifestSchema = z.object({
schemaVersion: z.number().int().positive(),
generatedAt: z.string().datetime(),
source: z
.object({
companyId: z.string().guid(),
companyName: z.string().min(1),
})
.nullable(),
includes: z.object({
company: z.boolean(),
agents: z.boolean(),
projects: z.boolean(),
issues: z.boolean(),
skills: z.boolean(),
}),
company: portabilityCompanyManifestEntrySchema.nullable(),
sidebar: portabilitySidebarOrderSchema.nullable(),
labels: z.array(portabilityLabelManifestEntrySchema).default([]),
blobs: z.array(portabilityBlobManifestEntrySchema).default([]),
agents: z.array(portabilityAgentManifestEntrySchema),
skills: z.array(portabilitySkillManifestEntrySchema).default([]),
projects: z.array(portabilityProjectManifestEntrySchema).default([]),
issues: z.array(portabilityIssueManifestEntrySchema).default([]),
envInputs: z.array(portabilityEnvInputSchema).default([]),
});
export const portabilitySourceSchema = z.discriminatedUnion("type", [
z.object({
type: z.literal("inline"),
rootPath: z.string().min(1).optional().nullable(),
files: z.record(z.string(), portabilityFileEntrySchema),
// Self-describing completeness count. The client sets this to
// `Object.keys(files).length`; the import path rejects the payload when the
// received file set is smaller, so a truncated or re-framed body fails
// closed instead of importing a fragment. Optional for backwards
// compatibility with callers that predate the check.
expectedFileCount: z.number().int().nonnegative().optional(),
}),
z.object({
type: z.literal("github"),
url: z.string().url(),
}),
]);
export const portabilityTargetSchema = z.discriminatedUnion("mode", [
z.object({
mode: z.literal("new_company"),
newCompanyName: z.string().min(1).optional().nullable(),
}),
z.object({
mode: z.literal("existing_company"),
companyId: z.string().guid(),
}),
]);
export const portabilityAgentSelectionSchema = z.union([
z.literal("all"),
z.array(z.string().min(1)),
]);
export const portabilityCollisionStrategySchema = z.enum(["rename", "skip", "replace"]);
export const companyPortabilityExportSchema = z.object({
include: portabilityIncludeSchema.optional(),
agents: z.array(z.string().min(1)).optional(),
skills: z.array(z.string().min(1)).optional(),
projects: z.array(z.string().min(1)).optional(),
issues: z.array(z.string().min(1)).optional(),
projectIssues: z.array(z.string().min(1)).optional(),
selectedFiles: z.array(z.string().min(1)).optional(),
expandReferencedSkills: z.boolean().optional(),
sidebarOrder: portabilitySidebarOrderSchema.partial().optional(),
});
export type CompanyPortabilityExport = z.infer<typeof companyPortabilityExportSchema>;
export const companyPortabilityPreviewSchema = z.object({
source: portabilitySourceSchema,
include: portabilityIncludeSchema.optional(),
target: portabilityTargetSchema,
agents: portabilityAgentSelectionSchema.optional(),
collisionStrategy: portabilityCollisionStrategySchema.optional(),
nameOverrides: z.record(z.string().min(1), z.string().min(1)).optional(),
selectedFiles: z.array(z.string().min(1)).optional(),
});
export type CompanyPortabilityPreview = z.infer<typeof companyPortabilityPreviewSchema>;
export const portabilityAdapterOverrideSchema = z.object({
adapterType: z.string().min(1),
adapterConfig: z.record(z.string(), z.unknown()).optional(),
});
export const companyPortabilityImportSchema = companyPortabilityPreviewSchema.extend({
adapterOverrides: z.record(z.string().min(1), portabilityAdapterOverrideSchema).optional(),
secretValues: z.record(z.string().min(1), z.string()).optional(),
pauseAutomations: z.boolean().optional(),
});
export type CompanyPortabilityImport = z.infer<typeof companyPortabilityImportSchema>;