@valkyrianlabs/payload-markdown-docs 0.5.1 → 0.5.2

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.
@@ -33,6 +33,7 @@ const resolveSyncSource = async ({ manifest, options, payload })=>{
33
33
  slug: sourceId,
34
34
  collectionSlug: options.docsSetsCollectionSlug,
35
35
  docsGroupsCollectionSlug: options.docsGroupsCollectionSlug,
36
+ includeDrafts: true,
36
37
  payload
37
38
  }) : undefined;
38
39
  if (docsSet) {
@@ -119,6 +120,7 @@ const getRouteCollisionIssues = async ({ docsSet, manifest, options, payload, ro
119
120
  const existingDocsRouteCollisions = options.docsEnabled ? await findExistingDocsRouteCollisions({
120
121
  collectionSlug: options.docsCollectionSlug,
121
122
  docsSetId: docsSet?.id,
123
+ includeDrafts: options.docsEnableDrafts,
122
124
  payload,
123
125
  routes: desiredRoutes,
124
126
  sourceId: manifest.source.id
@@ -466,6 +468,7 @@ const createSyncEndpointHandler = (options)=>async (req)=>{
466
468
  const existingPayloadDocs = options.docsEnabled ? await findExistingPayloadDocsRecords({
467
469
  collectionSlug: options.docsCollectionSlug,
468
470
  docsSetId: sourceResolution.source.docsSet?.id,
471
+ draft: options.docsEnableDrafts,
469
472
  markdownFieldName: options.markdownFieldName,
470
473
  payload: req.payload,
471
474
  sourceId: validation.data.source.id
@@ -576,6 +579,7 @@ const createSyncEndpointHandler = (options)=>async (req)=>{
576
579
  docsSetId: sourceResolution.source.docsSet.id,
577
580
  now: options.getNow?.() ?? new Date(),
578
581
  payload: req.payload,
582
+ publish: validation.data.publish,
579
583
  syncRunId
580
584
  });
581
585
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/endpoints/sync.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload'\n\nimport type {\n ApplyDocsSyncPayloadOperations,\n DocsKeyPayloadOperations,\n DocsSetPayloadOperations,\n DocsTrustedPayloadOperations,\n ExistingDocsPayloadOperations,\n ExistingPayloadDocsRecord,\n ResolvedDocsSet,\n RouteCollisionPayloadOperations,\n SyncRunsPayloadOperations,\n} from '../payload/index.js'\nimport type { FetchJson, NoncePayloadOperations } from '../security/index.js'\nimport type {\n DocsDeleteBehavior,\n DocsManifest,\n DocsValidationIssue,\n PlannedDocChange,\n ValidatedDocsManifest,\n} from '../sync/index.js'\nimport type { PayloadMarkdownDocsAuthConfig } from '../types.js'\n\nimport {\n DEFAULT_MAX_BODY_BYTES,\n DEFAULT_MAX_SKEW_SECONDS,\n DEFAULT_NONCE_TTL_SECONDS,\n} from '../constants.js'\nimport {\n applyDocsSync,\n assertApplyDeleteBehaviorSupported,\n createSyncRunAudit,\n findConfiguredPagesRouteCollisions,\n findDocsKeyById,\n findDocsSetBySlug,\n findDocsSyncConflicts,\n findDuplicateDesiredRouteCollisions,\n findExistingDocsRouteCollisions,\n findExistingPayloadDocsRecords,\n findTrustedGitHubSources,\n getRecordId,\n isEd25519AuthEnabled,\n isGitHubOidcAuthEnabled,\n toExistingDocsRecord,\n updateDocsSetAfterSync,\n updateSyncRunAudit,\n} from '../payload/index.js'\nimport {\n assertNonceNotReplayed,\n buildCanonicalSigningString,\n extractSyncRequestHeaders,\n getCanonicalPathFromRequestUrl,\n storeAcceptedNonce,\n validateTimestampSkew,\n verifyBodySha256,\n verifyEd25519Signature,\n verifyGitHubOidcToken,\n} from '../security/index.js'\nimport { planDocsSync, validateDocsManifest } from '../sync/index.js'\n\nexport type DocsSyncEndpointErrorCode =\n | 'audit_unavailable'\n | 'auth_disabled'\n | 'body_hash_mismatch'\n | 'delete_behavior_not_implemented'\n | 'draft_behavior_not_available'\n | 'dry_run_required_not_implemented'\n | 'hard_delete_disabled'\n | 'invalid_body'\n | 'invalid_manifest'\n | 'invalid_method'\n | 'invalid_signature'\n | 'invalid_timestamp'\n | 'manual_edit_conflict'\n | 'missing_header'\n | 'nonce_replay'\n | 'oidc_expired'\n | 'oidc_invalid_audience'\n | 'oidc_invalid_issuer'\n | 'oidc_invalid_token'\n | 'oidc_jwks_unavailable'\n | 'oidc_missing_claim'\n | 'oidc_missing_jti'\n | 'oidc_not_yet_valid'\n | 'oidc_owner_not_allowed'\n | 'oidc_pull_request_not_allowed'\n | 'oidc_ref_not_allowed'\n | 'oidc_replay'\n | 'oidc_repository_not_allowed'\n | 'oidc_workflow_not_allowed'\n | 'publish_disabled'\n | 'publish_not_available'\n | 'replay_protection_unavailable'\n | 'route_collision'\n | 'source_not_allowed'\n | 'sync_apply_failed'\n | 'sync_mode_not_implemented'\n | 'sync_writes_disabled'\n | 'unknown_key'\n\nexport type CreateSyncEndpointOptions = {\n allowHardDelete?: boolean\n allowPublish?: boolean\n allowWrites?: boolean\n auth?: PayloadMarkdownDocsAuthConfig\n deleteBehavior?: DocsDeleteBehavior\n docsCollectionSlug: string\n docsEnabled: boolean\n docsEnableDrafts: boolean\n docsGroupsCollectionSlug: string\n docsKeysCollectionSlug: string\n docsKeysEnabled: boolean\n docsSetsCollectionSlug: string\n docsSetsEnabled: boolean\n docsTrustedCollectionSlug: string\n docsTrustedEnabled: boolean\n endpointPath: string\n getNow?: () => Date\n markdownFieldName: string\n maxBodyBytes?: number\n maxSkewSeconds?: number\n noncesCollectionSlug: string\n noncesEnabled: boolean\n nonceTtlSeconds?: number\n oidcFetchJson?: FetchJson\n requireDryRunBeforeApply?: boolean\n routing?: {\n pages?: {\n allowBridgePages: boolean\n bridgeField: string\n collection: string\n enabled: boolean\n routeField: string\n }\n }\n syncRunsCollectionSlug: string\n syncRunsEnabled: boolean\n}\n\ntype SyncErrorResponse = {\n conflicts?: {\n reason: string\n route?: string\n sourcePath: string\n }[]\n error: {\n code: DocsSyncEndpointErrorCode\n message: string\n }\n ok: false\n routeCollisions?: {\n reason: string\n route: string\n }[]\n}\n\ntype SerializedChange = {\n current?: {\n archived?: boolean\n route: string\n sourceHash?: string\n title?: string\n }\n desired?: {\n route: string\n sha256: string\n title: string\n }\n reason: string\n sourcePath: string\n}\n\ntype SyncSuccessResponse = {\n changes: {\n archive: SerializedChange[]\n create: SerializedChange[]\n delete: SerializedChange[]\n draft: SerializedChange[]\n unchanged: SerializedChange[]\n update: SerializedChange[]\n }\n deleteBehavior: DocsDeleteBehavior\n dryRun: boolean\n ok: true\n publishRequested: boolean\n summary: {\n archive: number\n create: number\n delete: number\n draft: number\n unchanged: number\n update: number\n warnings: number\n }\n syncRunId?: string\n warnings: DocsValidationIssue[]\n}\n\nconst jsonResponse = (body: SyncErrorResponse | SyncSuccessResponse, status = 200): Response =>\n Response.json(body, {\n status,\n })\n\nconst errorResponse = (\n code: DocsSyncEndpointErrorCode,\n message: string,\n status = 400,\n extras: Omit<SyncErrorResponse, 'error' | 'ok'> = {},\n): Response =>\n jsonResponse(\n {\n ...extras,\n error: {\n code,\n message,\n },\n ok: false,\n },\n status,\n )\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nconst parseManifestBody = (rawBody: string): DocsManifest | undefined => {\n try {\n const parsed = JSON.parse(rawBody) as unknown\n\n return isRecord(parsed) ? (parsed as DocsManifest) : undefined\n } catch {\n return undefined\n }\n}\n\ntype ResolvedSyncSource = {\n docsSet: ResolvedDocsSet\n routeBase: string\n sourceId: string\n}\n\nconst resolveSyncSource = async ({\n manifest,\n options,\n payload,\n}: {\n manifest: DocsManifest\n options: CreateSyncEndpointOptions\n payload: DocsSetPayloadOperations\n}): Promise<\n | {\n response: Response\n source?: never\n }\n | {\n response?: never\n source: ResolvedSyncSource\n }\n> => {\n const sourceId = manifest.source?.id\n\n if (!sourceId) {\n return {\n response: errorResponse(\n 'source_not_allowed',\n 'Manifest source.id is required and must match a docs set slug.',\n 400,\n ),\n }\n }\n\n const docsSet = options.docsSetsEnabled\n ? await findDocsSetBySlug({\n slug: sourceId,\n collectionSlug: options.docsSetsCollectionSlug,\n docsGroupsCollectionSlug: options.docsGroupsCollectionSlug,\n payload,\n })\n : undefined\n\n if (docsSet) {\n return {\n source: {\n docsSet,\n routeBase: docsSet.routeBase,\n sourceId,\n },\n }\n }\n\n return {\n response: errorResponse(\n 'source_not_allowed',\n `No docs set exists for source \"${sourceId}\". Create a docs set with slug \"${sourceId}\" in Payload Admin before syncing this source.`,\n 400,\n ),\n }\n}\n\nconst summarizePlan = (plan: ReturnType<typeof planDocsSync>) => ({\n archive: plan.archive.length,\n create: plan.create.length,\n delete: plan.delete.length,\n draft: plan.draft.length,\n unchanged: plan.unchanged.length,\n update: plan.update.length,\n warnings: plan.warnings.length,\n})\n\nconst serializeChange = (change: PlannedDocChange): SerializedChange => ({\n current: change.current\n ? {\n archived: change.current.archived,\n route: change.current.route,\n sourceHash: change.current.sourceHash,\n title: change.current.title,\n }\n : undefined,\n desired: change.desired\n ? {\n route: change.desired.route,\n sha256: change.desired.sha256,\n title: change.desired.title,\n }\n : undefined,\n reason: change.reason,\n sourcePath: change.sourcePath,\n})\n\nconst serializeChanges = (plan: ReturnType<typeof planDocsSync>) => ({\n archive: plan.archive.map(serializeChange),\n create: plan.create.map(serializeChange),\n delete: plan.delete.map(serializeChange),\n draft: plan.draft.map(serializeChange),\n unchanged: plan.unchanged.map(serializeChange),\n update: plan.update.map(serializeChange),\n})\n\nconst getTotalManifestBytes = (manifest: ValidatedDocsManifest): number =>\n manifest.files.reduce((total, file) => total + Buffer.byteLength(file.content, 'utf8'), 0)\n\nconst getPlannedConflictChanges = ({\n existing,\n plan,\n}: {\n existing: ExistingPayloadDocsRecord[]\n plan: ReturnType<typeof planDocsSync>\n}): PlannedDocChange[] => {\n const existingBySourcePath = new Map(existing.map((record) => [record.sourcePath, record]))\n const archivedUnchanged = plan.unchanged.filter((change) => {\n const current = existingBySourcePath.get(change.sourcePath)\n\n return current?.archived === true\n })\n\n return [...plan.update, ...plan.archive, ...plan.draft, ...plan.delete, ...archivedUnchanged]\n}\n\nconst getLifecyclePolicyError = ({\n deleteBehavior,\n manifest,\n options,\n}: {\n deleteBehavior: DocsDeleteBehavior\n manifest: ValidatedDocsManifest\n options: CreateSyncEndpointOptions\n}): Response | undefined => {\n if (manifest.publish && options.allowPublish !== true) {\n return errorResponse('publish_disabled', 'Publishing is disabled by server configuration.', 403)\n }\n\n if (manifest.publish && !options.docsEnableDrafts) {\n return errorResponse(\n 'publish_not_available',\n 'Publishing requires a draft-enabled dedicated docs collection.',\n 400,\n )\n }\n\n if (deleteBehavior === 'draft' && !options.docsEnableDrafts) {\n return errorResponse(\n 'draft_behavior_not_available',\n 'Draft delete behavior requires a draft-enabled dedicated docs collection.',\n 400,\n )\n }\n\n if (deleteBehavior === 'delete' && options.allowHardDelete !== true) {\n return errorResponse(\n 'hard_delete_disabled',\n 'Hard delete is disabled by server configuration.',\n 403,\n )\n }\n\n return undefined\n}\n\nconst getRouteCollisionIssues = async ({\n docsSet,\n manifest,\n options,\n payload,\n routeBase,\n}: {\n docsSet?: ResolvedDocsSet\n manifest: ValidatedDocsManifest\n options: CreateSyncEndpointOptions\n payload: RouteCollisionPayloadOperations\n routeBase: string\n}) => {\n const desiredRoutes = manifest.files.map((file) => file.route)\n const duplicateDesiredRouteCollisions = findDuplicateDesiredRouteCollisions(desiredRoutes)\n const existingDocsRouteCollisions = options.docsEnabled\n ? await findExistingDocsRouteCollisions({\n collectionSlug: options.docsCollectionSlug,\n docsSetId: docsSet?.id,\n payload,\n routes: desiredRoutes,\n sourceId: manifest.source.id,\n })\n : []\n const pageRouteCollisions =\n options.routing?.pages?.enabled === true\n ? await findConfiguredPagesRouteCollisions({\n allowBridgePages: options.routing.pages.allowBridgePages,\n bridgeField: options.routing.pages.bridgeField,\n collectionSlug: options.routing.pages.collection,\n docsSetRouteBase: routeBase,\n payload,\n routeField: options.routing.pages.routeField,\n })\n : []\n\n return [\n ...duplicateDesiredRouteCollisions,\n ...existingDocsRouteCollisions,\n ...pageRouteCollisions,\n ]\n}\n\ntype AuthenticatedSyncRequest = {\n actor?: string\n bodyHash: string\n branch?: string\n commit?: string\n expiresAt: Date\n keyId: string\n nonce: string\n repository?: string\n}\n\nconst getRequiredHeader = (headers: Headers, name: string): string | undefined => {\n const value = headers.get(name)\n\n return value && value.trim() !== '' ? value.trim() : undefined\n}\n\nconst getBearerToken = (headers: Headers): string | undefined => {\n const authorization = getRequiredHeader(headers, 'authorization')\n\n if (!authorization) {\n return undefined\n }\n\n const [scheme, token] = authorization.split(/\\s+/, 2)\n\n if (scheme?.toLowerCase() !== 'bearer' || !token) {\n return ''\n }\n\n return token\n}\n\nconst hasEd25519AuthHeaders = (headers: Headers): boolean =>\n getRequiredHeader(headers, 'x-vl-md-docs-key-id') !== undefined ||\n getRequiredHeader(headers, 'x-vl-md-docs-signature') !== undefined ||\n getRequiredHeader(headers, 'x-vl-md-docs-timestamp') !== undefined ||\n getRequiredHeader(headers, 'x-vl-md-docs-nonce') !== undefined\n\nconst assertReplayProtectionAvailable = (\n options: CreateSyncEndpointOptions,\n): Response | undefined =>\n options.noncesEnabled\n ? undefined\n : errorResponse(\n 'replay_protection_unavailable',\n 'Sync endpoint requires nonce replay protection.',\n 500,\n )\n\nconst authenticateEd25519Request = async ({\n now,\n options,\n rawBody,\n req,\n}: {\n now: Date\n options: CreateSyncEndpointOptions\n rawBody: string\n req: PayloadRequest\n}): Promise<\n | {\n identity: AuthenticatedSyncRequest\n response?: never\n }\n | {\n identity?: never\n response: Response\n }\n> => {\n const headersResult = extractSyncRequestHeaders(req.headers)\n\n if (!headersResult.ok) {\n return {\n response: errorResponse(\n 'missing_header',\n `Missing required sync header: ${headersResult.header}.`,\n 401,\n ),\n }\n }\n\n if (!options.docsKeysEnabled) {\n return {\n response: errorResponse(\n 'auth_disabled',\n 'Signed sync authentication requires the docs Keys collection.',\n 401,\n ),\n }\n }\n\n const keyConfig = await findDocsKeyById({\n collectionSlug: options.docsKeysCollectionSlug,\n keyId: headersResult.headers.keyId,\n payload: req.payload as unknown as DocsKeyPayloadOperations,\n })\n\n if (!keyConfig) {\n return {\n response: errorResponse('unknown_key', 'Unknown sync request key id.', 401),\n }\n }\n\n const bodyHash = verifyBodySha256({\n body: rawBody,\n expectedHash: headersResult.headers.bodySha256,\n })\n\n if (!bodyHash.ok) {\n return {\n response: errorResponse(\n 'body_hash_mismatch',\n 'Sync request body hash does not match the signed header.',\n 401,\n ),\n }\n }\n\n const timestampValidation = validateTimestampSkew({\n maxSkewSeconds: options.maxSkewSeconds ?? DEFAULT_MAX_SKEW_SECONDS,\n now,\n timestamp: headersResult.headers.timestamp,\n })\n\n if (!timestampValidation.ok) {\n return {\n response: errorResponse('invalid_timestamp', timestampValidation.message, 401),\n }\n }\n\n const replayUnavailable = assertReplayProtectionAvailable(options)\n\n if (replayUnavailable) {\n return {\n response: replayUnavailable,\n }\n }\n\n const nonceAvailable = await assertNonceNotReplayed({\n collectionSlug: options.noncesCollectionSlug,\n keyId: headersResult.headers.keyId,\n nonce: headersResult.headers.nonce,\n now,\n payload: req.payload as unknown as NoncePayloadOperations,\n })\n\n if (!nonceAvailable) {\n return {\n response: errorResponse('nonce_replay', 'Sync request nonce has already been used.', 409),\n }\n }\n\n const canonicalPath = getCanonicalPathFromRequestUrl({\n endpointPath: options.endpointPath,\n url: req.url,\n })\n const canonicalString = buildCanonicalSigningString({\n bodySha256: bodyHash.computedHash,\n method: 'POST',\n nonce: headersResult.headers.nonce,\n path: canonicalPath,\n timestamp: headersResult.headers.timestamp,\n })\n\n if (\n !verifyEd25519Signature({\n canonicalString,\n publicKey: keyConfig.publicKey,\n signature: headersResult.headers.signature,\n })\n ) {\n return {\n response: errorResponse('invalid_signature', 'Invalid sync request signature.', 401),\n }\n }\n\n const nonceTtlSeconds = options.nonceTtlSeconds ?? DEFAULT_NONCE_TTL_SECONDS\n\n return {\n identity: {\n bodyHash: bodyHash.computedHash,\n expiresAt: new Date(now.getTime() + nonceTtlSeconds * 1000),\n keyId: headersResult.headers.keyId,\n nonce: headersResult.headers.nonce,\n },\n }\n}\n\nconst authenticateGitHubOidcRequest = async ({\n docsSet,\n now,\n options,\n rawBody,\n req,\n}: {\n docsSet: ResolvedDocsSet\n now: Date\n options: CreateSyncEndpointOptions\n rawBody: string\n req: PayloadRequest\n}): Promise<\n | {\n identity: AuthenticatedSyncRequest\n response?: never\n }\n | {\n identity?: never\n response: Response\n }\n> => {\n const token = getBearerToken(req.headers)\n\n if (token === undefined) {\n return {\n response: errorResponse(\n 'missing_header',\n 'Missing required sync header: Authorization.',\n 401,\n ),\n }\n }\n\n if (token === '') {\n return {\n response: errorResponse(\n 'oidc_invalid_token',\n 'Authorization must be a Bearer GitHub OIDC token.',\n 401,\n ),\n }\n }\n\n const expectedHash = getRequiredHeader(req.headers, 'x-vl-md-docs-body-sha256')\n\n if (!expectedHash) {\n return {\n response: errorResponse(\n 'missing_header',\n 'Missing required sync header: X-VL-MD-DOCS-Body-SHA256.',\n 401,\n ),\n }\n }\n\n const bodyHash = verifyBodySha256({\n body: rawBody,\n expectedHash,\n })\n\n if (!bodyHash.ok) {\n return {\n response: errorResponse(\n 'body_hash_mismatch',\n 'Sync request body hash does not match the OIDC header.',\n 401,\n ),\n }\n }\n\n if (!options.docsTrustedEnabled) {\n return {\n response: errorResponse(\n 'auth_disabled',\n 'GitHub OIDC sync authentication requires the docs Trusted collection.',\n 401,\n ),\n }\n }\n\n const trustedSources = await findTrustedGitHubSources({\n collectionSlug: options.docsTrustedCollectionSlug,\n payload: req.payload as unknown as DocsTrustedPayloadOperations,\n })\n const allowedRef = docsSet.branch.startsWith('refs/')\n ? docsSet.branch\n : `refs/heads/${docsSet.branch}`\n\n const verified = await verifyGitHubOidcToken({\n config: {\n allowedRefs: [allowedRef],\n allowedWorkflowRefs: docsSet.advancedSecurity?.allowedWorkflowRefs,\n allowPullRequests: docsSet.allowPullRequests,\n audience: docsSet.slug,\n enforceWorkflowRefs: docsSet.advancedSecurity?.enabled === true,\n trustedSources,\n },\n fetchJson: options.oidcFetchJson,\n now,\n token,\n })\n\n if (!verified.ok) {\n return {\n response: errorResponse(\n verified.code,\n verified.message,\n verified.code === 'oidc_jwks_unavailable' ? 503 : 401,\n ),\n }\n }\n\n const replayUnavailable = assertReplayProtectionAvailable(options)\n\n if (replayUnavailable) {\n return {\n response: replayUnavailable,\n }\n }\n\n const nonceAvailable = await assertNonceNotReplayed({\n collectionSlug: options.noncesCollectionSlug,\n keyId: verified.token.keyId,\n nonce: verified.token.claims.jti,\n now,\n payload: req.payload as unknown as NoncePayloadOperations,\n })\n\n if (!nonceAvailable) {\n return {\n response: errorResponse('oidc_replay', 'GitHub OIDC token jti has already been used.', 409),\n }\n }\n\n return {\n identity: {\n actor: verified.token.claims.actor,\n bodyHash: bodyHash.computedHash,\n branch: verified.token.claims.ref,\n commit: verified.token.claims.sha,\n expiresAt: verified.token.expiresAt,\n keyId: verified.token.keyId,\n nonce: verified.token.claims.jti,\n repository: verified.token.claims.repository,\n },\n }\n}\n\nconst authenticateSyncRequest = async ({\n docsSet,\n now,\n options,\n rawBody,\n req,\n}: {\n docsSet: ResolvedDocsSet\n now: Date\n options: CreateSyncEndpointOptions\n rawBody: string\n req: PayloadRequest\n}): Promise<\n | {\n identity: AuthenticatedSyncRequest\n response?: never\n }\n | {\n identity?: never\n response: Response\n }\n> => {\n const ed25519Enabled = isEd25519AuthEnabled(options.auth)\n const githubOidcEnabled = isGitHubOidcAuthEnabled(options.auth)\n\n if (!ed25519Enabled && !githubOidcEnabled) {\n return {\n response: errorResponse(\n 'auth_disabled',\n 'Sync authentication is not configured for this endpoint.',\n 401,\n ),\n }\n }\n\n const bearerToken = getBearerToken(req.headers)\n\n if (bearerToken !== undefined) {\n if (!githubOidcEnabled) {\n return {\n response: errorResponse(\n 'auth_disabled',\n 'GitHub OIDC sync authentication is not configured for this endpoint.',\n 401,\n ),\n }\n }\n\n return authenticateGitHubOidcRequest({\n docsSet,\n now,\n options,\n rawBody,\n req,\n })\n }\n\n if (hasEd25519AuthHeaders(req.headers) || !githubOidcEnabled) {\n if (!ed25519Enabled) {\n return {\n response: errorResponse(\n 'auth_disabled',\n 'Signed sync authentication is not configured for this endpoint.',\n 401,\n ),\n }\n }\n\n return authenticateEd25519Request({\n now,\n options,\n rawBody,\n req,\n })\n }\n\n return authenticateGitHubOidcRequest({\n docsSet,\n now,\n options,\n rawBody,\n req,\n })\n}\n\nconst createSyncEndpointHandler =\n (options: CreateSyncEndpointOptions) =>\n async (req: PayloadRequest): Promise<Response> => {\n const startedAt = options.getNow?.() ?? new Date()\n\n if (req.method && req.method.toUpperCase() !== 'POST') {\n return errorResponse('invalid_method', 'Sync endpoint only accepts POST.', 405)\n }\n\n if (typeof req.text !== 'function') {\n return errorResponse(\n 'invalid_body',\n 'Sync endpoint requires access to the request body text.',\n 400,\n )\n }\n\n const rawBody = await req.text()\n const maxBodyBytes = options.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES\n\n if (Buffer.byteLength(rawBody, 'utf8') > maxBodyBytes) {\n return errorResponse('invalid_body', 'Sync request body is too large.', 413)\n }\n\n const manifest = parseManifestBody(rawBody)\n\n if (!manifest) {\n return errorResponse('invalid_body', 'Sync request body must be a JSON manifest.', 400)\n }\n\n const sourceResolution = await resolveSyncSource({\n manifest,\n options,\n payload: req.payload as unknown as DocsSetPayloadOperations,\n })\n\n if (sourceResolution.response) {\n return sourceResolution.response\n }\n\n const authentication = await authenticateSyncRequest({\n docsSet: sourceResolution.source.docsSet,\n now: startedAt,\n options,\n rawBody,\n req,\n })\n\n if (authentication.response) {\n return authentication.response\n }\n\n const validation = validateDocsManifest(manifest, {\n allowedSourceIds: [sourceResolution.source.sourceId],\n maxTotalBytes: maxBodyBytes,\n routeBase: sourceResolution.source.routeBase,\n })\n\n if (!validation.ok) {\n return jsonResponse(\n {\n error: {\n code: 'invalid_manifest',\n message: 'Sync manifest is invalid.',\n },\n ok: false,\n },\n 400,\n )\n }\n\n const effectiveDeleteBehavior = options.deleteBehavior ?? 'archive'\n const lifecyclePolicyError = getLifecyclePolicyError({\n deleteBehavior: effectiveDeleteBehavior,\n manifest: validation.data,\n options,\n })\n\n if (lifecyclePolicyError) {\n return lifecyclePolicyError\n }\n\n const routeCollisions = await getRouteCollisionIssues({\n docsSet: sourceResolution.source.docsSet,\n manifest: validation.data,\n options,\n payload: req.payload as unknown as RouteCollisionPayloadOperations,\n routeBase: sourceResolution.source.routeBase,\n })\n\n if (routeCollisions.length > 0) {\n return errorResponse(\n 'route_collision',\n 'One or more docs routes collide with an existing route reservation.',\n 409,\n {\n routeCollisions,\n },\n )\n }\n\n const isSyncMode = validation.data.mode === 'sync'\n\n if (isSyncMode && options.allowWrites !== true) {\n return errorResponse(\n 'sync_writes_disabled',\n 'Sync writes are disabled by server configuration.',\n 403,\n )\n }\n\n if (isSyncMode && options.requireDryRunBeforeApply === true) {\n return errorResponse(\n 'dry_run_required_not_implemented',\n 'Required dry-run proof before apply is not implemented yet.',\n 400,\n )\n }\n\n if (\n isSyncMode &&\n !assertApplyDeleteBehaviorSupported(effectiveDeleteBehavior, {\n allowHardDelete: options.allowHardDelete,\n docsEnableDrafts: options.docsEnableDrafts,\n })\n ) {\n return errorResponse(\n 'delete_behavior_not_implemented',\n 'Configured delete behavior cannot be applied.',\n 400,\n )\n }\n\n if (isSyncMode && !options.syncRunsEnabled) {\n return errorResponse(\n 'audit_unavailable',\n 'Applied sync requires the sync-run audit collection.',\n 500,\n )\n }\n\n const existingPayloadDocs = options.docsEnabled\n ? await findExistingPayloadDocsRecords({\n collectionSlug: options.docsCollectionSlug,\n docsSetId: sourceResolution.source.docsSet?.id,\n markdownFieldName: options.markdownFieldName,\n payload: req.payload as unknown as ExistingDocsPayloadOperations,\n sourceId: validation.data.source.id,\n })\n : []\n const existingDocs = existingPayloadDocs.map(toExistingDocsRecord)\n const plan = planDocsSync({\n deleteBehavior: effectiveDeleteBehavior,\n desired: validation.data,\n existing: existingDocs,\n })\n const summary = summarizePlan(plan)\n const warnings = [...validation.warnings, ...plan.warnings]\n if (isSyncMode) {\n const existingBySourcePath = new Map(\n existingPayloadDocs.map((record) => [record.sourcePath, record]),\n )\n const conflicts = findDocsSyncConflicts({\n existingBySourcePath,\n plannedChanges: getPlannedConflictChanges({\n existing: existingPayloadDocs,\n plan,\n }),\n })\n\n if (conflicts.length > 0) {\n return errorResponse(\n 'manual_edit_conflict',\n 'One or more docs were modified outside the docs sync workflow.',\n 409,\n {\n conflicts,\n },\n )\n }\n }\n\n await storeAcceptedNonce({\n bodyHash: authentication.identity.bodyHash,\n collectionSlug: options.noncesCollectionSlug,\n expiresAt: authentication.identity.expiresAt,\n keyId: authentication.identity.keyId,\n nonce: authentication.identity.nonce,\n payload: req.payload as unknown as NoncePayloadOperations,\n sourceId: validation.data.source.id,\n usedAt: startedAt,\n })\n\n let syncRunId: number | string | undefined\n\n if (options.syncRunsEnabled) {\n const syncRun = await createSyncRunAudit({\n actor: authentication.identity.actor,\n bodyHash: authentication.identity.bodyHash,\n branch: authentication.identity.branch ?? validation.data.source.branch,\n collectionSlug: options.syncRunsCollectionSlug,\n commit: authentication.identity.commit ?? validation.data.source.commit,\n completedAt: isSyncMode ? startedAt : (options.getNow?.() ?? new Date()),\n deleteBehavior: effectiveDeleteBehavior,\n errors: [],\n fileCount: validation.data.files.length,\n keyId: authentication.identity.keyId,\n mode: isSyncMode ? 'sync' : 'dry-run',\n payload: req.payload as unknown as SyncRunsPayloadOperations,\n publishRequested: validation.data.publish,\n repository: authentication.identity.repository ?? validation.data.source.repository,\n sourceId: validation.data.source.id,\n startedAt,\n status: isSyncMode ? 'pending' : 'success',\n summary,\n totalBytes: getTotalManifestBytes(validation.data),\n warnings,\n })\n\n syncRunId = getRecordId(syncRun)\n }\n\n if (isSyncMode) {\n if (!syncRunId) {\n return errorResponse(\n 'audit_unavailable',\n 'Applied sync could not create a sync-run audit record.',\n 500,\n )\n }\n\n try {\n const applyResult = await applyDocsSync({\n collectionSlug: options.docsCollectionSlug,\n deleteBehavior: effectiveDeleteBehavior,\n docsEnableDrafts: options.docsEnableDrafts,\n docsSetId: sourceResolution.source.docsSet?.id,\n existing: existingPayloadDocs,\n manifest: validation.data,\n markdownFieldName: options.markdownFieldName,\n now: options.getNow?.() ?? new Date(),\n payload: req.payload as unknown as ApplyDocsSyncPayloadOperations,\n plan,\n publish: validation.data.publish,\n syncRunId,\n })\n\n if (!applyResult.ok) {\n return errorResponse(\n 'manual_edit_conflict',\n 'One or more docs were modified outside the docs sync workflow.',\n 409,\n {\n conflicts: applyResult.conflicts,\n },\n )\n }\n\n await updateSyncRunAudit({\n collectionSlug: options.syncRunsCollectionSlug,\n completedAt: options.getNow?.() ?? new Date(),\n payload: req.payload as unknown as SyncRunsPayloadOperations,\n status: 'success',\n summary,\n syncRunId,\n warnings,\n })\n\n if (sourceResolution.source.docsSet) {\n await updateDocsSetAfterSync({\n aiExport: validation.data.aiExport,\n collectionSlug: options.docsSetsCollectionSlug,\n docsCount: validation.data.files.length,\n docsSetId: sourceResolution.source.docsSet.id,\n now: options.getNow?.() ?? new Date(),\n payload: req.payload as unknown as DocsSetPayloadOperations,\n syncRunId,\n })\n }\n } catch (error) {\n await updateSyncRunAudit({\n collectionSlug: options.syncRunsCollectionSlug,\n completedAt: options.getNow?.() ?? new Date(),\n errors: [\n {\n code: 'invalid_manifest',\n message: error instanceof Error ? error.message : 'Sync apply failed.',\n },\n ],\n payload: req.payload as unknown as SyncRunsPayloadOperations,\n status: 'failed',\n summary,\n syncRunId,\n warnings,\n })\n\n return errorResponse('sync_apply_failed', 'Sync apply failed.', 500)\n }\n }\n\n return jsonResponse({\n changes: serializeChanges(plan),\n deleteBehavior: effectiveDeleteBehavior,\n dryRun: !isSyncMode,\n ok: true,\n publishRequested: validation.data.publish,\n summary,\n syncRunId: syncRunId === undefined ? undefined : String(syncRunId),\n warnings,\n })\n }\n\nexport const createSyncEndpoint = (options: CreateSyncEndpointOptions): Endpoint => ({\n handler: createSyncEndpointHandler(options),\n method: 'post',\n path: options.endpointPath,\n})\n"],"names":["DEFAULT_MAX_BODY_BYTES","DEFAULT_MAX_SKEW_SECONDS","DEFAULT_NONCE_TTL_SECONDS","applyDocsSync","assertApplyDeleteBehaviorSupported","createSyncRunAudit","findConfiguredPagesRouteCollisions","findDocsKeyById","findDocsSetBySlug","findDocsSyncConflicts","findDuplicateDesiredRouteCollisions","findExistingDocsRouteCollisions","findExistingPayloadDocsRecords","findTrustedGitHubSources","getRecordId","isEd25519AuthEnabled","isGitHubOidcAuthEnabled","toExistingDocsRecord","updateDocsSetAfterSync","updateSyncRunAudit","assertNonceNotReplayed","buildCanonicalSigningString","extractSyncRequestHeaders","getCanonicalPathFromRequestUrl","storeAcceptedNonce","validateTimestampSkew","verifyBodySha256","verifyEd25519Signature","verifyGitHubOidcToken","planDocsSync","validateDocsManifest","jsonResponse","body","status","Response","json","errorResponse","code","message","extras","error","ok","isRecord","value","Array","isArray","parseManifestBody","rawBody","parsed","JSON","parse","undefined","resolveSyncSource","manifest","options","payload","sourceId","source","id","response","docsSet","docsSetsEnabled","slug","collectionSlug","docsSetsCollectionSlug","docsGroupsCollectionSlug","routeBase","summarizePlan","plan","archive","length","create","delete","draft","unchanged","update","warnings","serializeChange","change","current","archived","route","sourceHash","title","desired","sha256","reason","sourcePath","serializeChanges","map","getTotalManifestBytes","files","reduce","total","file","Buffer","byteLength","content","getPlannedConflictChanges","existing","existingBySourcePath","Map","record","archivedUnchanged","filter","get","getLifecyclePolicyError","deleteBehavior","publish","allowPublish","docsEnableDrafts","allowHardDelete","getRouteCollisionIssues","desiredRoutes","duplicateDesiredRouteCollisions","existingDocsRouteCollisions","docsEnabled","docsCollectionSlug","docsSetId","routes","pageRouteCollisions","routing","pages","enabled","allowBridgePages","bridgeField","collection","docsSetRouteBase","routeField","getRequiredHeader","headers","name","trim","getBearerToken","authorization","scheme","token","split","toLowerCase","hasEd25519AuthHeaders","assertReplayProtectionAvailable","noncesEnabled","authenticateEd25519Request","now","req","headersResult","header","docsKeysEnabled","keyConfig","docsKeysCollectionSlug","keyId","bodyHash","expectedHash","bodySha256","timestampValidation","maxSkewSeconds","timestamp","replayUnavailable","nonceAvailable","noncesCollectionSlug","nonce","canonicalPath","endpointPath","url","canonicalString","computedHash","method","path","publicKey","signature","nonceTtlSeconds","identity","expiresAt","Date","getTime","authenticateGitHubOidcRequest","docsTrustedEnabled","trustedSources","docsTrustedCollectionSlug","allowedRef","branch","startsWith","verified","config","allowedRefs","allowedWorkflowRefs","advancedSecurity","allowPullRequests","audience","enforceWorkflowRefs","fetchJson","oidcFetchJson","claims","jti","actor","ref","commit","sha","repository","authenticateSyncRequest","ed25519Enabled","auth","githubOidcEnabled","bearerToken","createSyncEndpointHandler","startedAt","getNow","toUpperCase","text","maxBodyBytes","sourceResolution","authentication","validation","allowedSourceIds","maxTotalBytes","effectiveDeleteBehavior","lifecyclePolicyError","data","routeCollisions","isSyncMode","mode","allowWrites","requireDryRunBeforeApply","syncRunsEnabled","existingPayloadDocs","markdownFieldName","existingDocs","summary","conflicts","plannedChanges","usedAt","syncRunId","syncRun","syncRunsCollectionSlug","completedAt","errors","fileCount","publishRequested","totalBytes","applyResult","aiExport","docsCount","Error","changes","dryRun","String","createSyncEndpoint","handler"],"mappings":"AAuBA,SACEA,sBAAsB,EACtBC,wBAAwB,EACxBC,yBAAyB,QACpB,kBAAiB;AACxB,SACEC,aAAa,EACbC,kCAAkC,EAClCC,kBAAkB,EAClBC,kCAAkC,EAClCC,eAAe,EACfC,iBAAiB,EACjBC,qBAAqB,EACrBC,mCAAmC,EACnCC,+BAA+B,EAC/BC,8BAA8B,EAC9BC,wBAAwB,EACxBC,WAAW,EACXC,oBAAoB,EACpBC,uBAAuB,EACvBC,oBAAoB,EACpBC,sBAAsB,EACtBC,kBAAkB,QACb,sBAAqB;AAC5B,SACEC,sBAAsB,EACtBC,2BAA2B,EAC3BC,yBAAyB,EACzBC,8BAA8B,EAC9BC,kBAAkB,EAClBC,qBAAqB,EACrBC,gBAAgB,EAChBC,sBAAsB,EACtBC,qBAAqB,QAChB,uBAAsB;AAC7B,SAASC,YAAY,EAAEC,oBAAoB,QAAQ,mBAAkB;AA4IrE,MAAMC,eAAe,CAACC,MAA+CC,SAAS,GAAG,GAC/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Aa;YAClBoN,SAAS3J,iBAAiBpB;YAC1BuC,gBAAgB4G;YAChB6B,QAAQ,CAACzB;YACTlL,IAAI;YACJoM,kBAAkBzB,WAAWK,IAAI,CAAC7G,OAAO;YACzCuH;YACAI,WAAWA,cAAcpL,YAAYA,YAAYkM,OAAOd;YACxD3J;QACF;IACF;AAEF,OAAO,MAAM0K,qBAAqB,CAAChM,UAAkD,CAAA;QACnFiM,SAAS3C,0BAA0BtJ;QACnCgH,QAAQ;QACRC,MAAMjH,QAAQ4G,YAAY;IAC5B,CAAA,EAAE"}
1
+ {"version":3,"sources":["../../src/endpoints/sync.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload'\n\nimport type {\n ApplyDocsSyncPayloadOperations,\n DocsKeyPayloadOperations,\n DocsSetPayloadOperations,\n DocsTrustedPayloadOperations,\n ExistingDocsPayloadOperations,\n ExistingPayloadDocsRecord,\n ResolvedDocsSet,\n RouteCollisionPayloadOperations,\n SyncRunsPayloadOperations,\n} from '../payload/index.js'\nimport type { FetchJson, NoncePayloadOperations } from '../security/index.js'\nimport type {\n DocsDeleteBehavior,\n DocsManifest,\n DocsValidationIssue,\n PlannedDocChange,\n ValidatedDocsManifest,\n} from '../sync/index.js'\nimport type { PayloadMarkdownDocsAuthConfig } from '../types.js'\n\nimport {\n DEFAULT_MAX_BODY_BYTES,\n DEFAULT_MAX_SKEW_SECONDS,\n DEFAULT_NONCE_TTL_SECONDS,\n} from '../constants.js'\nimport {\n applyDocsSync,\n assertApplyDeleteBehaviorSupported,\n createSyncRunAudit,\n findConfiguredPagesRouteCollisions,\n findDocsKeyById,\n findDocsSetBySlug,\n findDocsSyncConflicts,\n findDuplicateDesiredRouteCollisions,\n findExistingDocsRouteCollisions,\n findExistingPayloadDocsRecords,\n findTrustedGitHubSources,\n getRecordId,\n isEd25519AuthEnabled,\n isGitHubOidcAuthEnabled,\n toExistingDocsRecord,\n updateDocsSetAfterSync,\n updateSyncRunAudit,\n} from '../payload/index.js'\nimport {\n assertNonceNotReplayed,\n buildCanonicalSigningString,\n extractSyncRequestHeaders,\n getCanonicalPathFromRequestUrl,\n storeAcceptedNonce,\n validateTimestampSkew,\n verifyBodySha256,\n verifyEd25519Signature,\n verifyGitHubOidcToken,\n} from '../security/index.js'\nimport { planDocsSync, validateDocsManifest } from '../sync/index.js'\n\nexport type DocsSyncEndpointErrorCode =\n | 'audit_unavailable'\n | 'auth_disabled'\n | 'body_hash_mismatch'\n | 'delete_behavior_not_implemented'\n | 'draft_behavior_not_available'\n | 'dry_run_required_not_implemented'\n | 'hard_delete_disabled'\n | 'invalid_body'\n | 'invalid_manifest'\n | 'invalid_method'\n | 'invalid_signature'\n | 'invalid_timestamp'\n | 'manual_edit_conflict'\n | 'missing_header'\n | 'nonce_replay'\n | 'oidc_expired'\n | 'oidc_invalid_audience'\n | 'oidc_invalid_issuer'\n | 'oidc_invalid_token'\n | 'oidc_jwks_unavailable'\n | 'oidc_missing_claim'\n | 'oidc_missing_jti'\n | 'oidc_not_yet_valid'\n | 'oidc_owner_not_allowed'\n | 'oidc_pull_request_not_allowed'\n | 'oidc_ref_not_allowed'\n | 'oidc_replay'\n | 'oidc_repository_not_allowed'\n | 'oidc_workflow_not_allowed'\n | 'publish_disabled'\n | 'publish_not_available'\n | 'replay_protection_unavailable'\n | 'route_collision'\n | 'source_not_allowed'\n | 'sync_apply_failed'\n | 'sync_mode_not_implemented'\n | 'sync_writes_disabled'\n | 'unknown_key'\n\nexport type CreateSyncEndpointOptions = {\n allowHardDelete?: boolean\n allowPublish?: boolean\n allowWrites?: boolean\n auth?: PayloadMarkdownDocsAuthConfig\n deleteBehavior?: DocsDeleteBehavior\n docsCollectionSlug: string\n docsEnabled: boolean\n docsEnableDrafts: boolean\n docsGroupsCollectionSlug: string\n docsKeysCollectionSlug: string\n docsKeysEnabled: boolean\n docsSetsCollectionSlug: string\n docsSetsEnabled: boolean\n docsTrustedCollectionSlug: string\n docsTrustedEnabled: boolean\n endpointPath: string\n getNow?: () => Date\n markdownFieldName: string\n maxBodyBytes?: number\n maxSkewSeconds?: number\n noncesCollectionSlug: string\n noncesEnabled: boolean\n nonceTtlSeconds?: number\n oidcFetchJson?: FetchJson\n requireDryRunBeforeApply?: boolean\n routing?: {\n pages?: {\n allowBridgePages: boolean\n bridgeField: string\n collection: string\n enabled: boolean\n routeField: string\n }\n }\n syncRunsCollectionSlug: string\n syncRunsEnabled: boolean\n}\n\ntype SyncErrorResponse = {\n conflicts?: {\n reason: string\n route?: string\n sourcePath: string\n }[]\n error: {\n code: DocsSyncEndpointErrorCode\n message: string\n }\n ok: false\n routeCollisions?: {\n reason: string\n route: string\n }[]\n}\n\ntype SerializedChange = {\n current?: {\n archived?: boolean\n route: string\n sourceHash?: string\n title?: string\n }\n desired?: {\n route: string\n sha256: string\n title: string\n }\n reason: string\n sourcePath: string\n}\n\ntype SyncSuccessResponse = {\n changes: {\n archive: SerializedChange[]\n create: SerializedChange[]\n delete: SerializedChange[]\n draft: SerializedChange[]\n unchanged: SerializedChange[]\n update: SerializedChange[]\n }\n deleteBehavior: DocsDeleteBehavior\n dryRun: boolean\n ok: true\n publishRequested: boolean\n summary: {\n archive: number\n create: number\n delete: number\n draft: number\n unchanged: number\n update: number\n warnings: number\n }\n syncRunId?: string\n warnings: DocsValidationIssue[]\n}\n\nconst jsonResponse = (body: SyncErrorResponse | SyncSuccessResponse, status = 200): Response =>\n Response.json(body, {\n status,\n })\n\nconst errorResponse = (\n code: DocsSyncEndpointErrorCode,\n message: string,\n status = 400,\n extras: Omit<SyncErrorResponse, 'error' | 'ok'> = {},\n): Response =>\n jsonResponse(\n {\n ...extras,\n error: {\n code,\n message,\n },\n ok: false,\n },\n status,\n )\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nconst parseManifestBody = (rawBody: string): DocsManifest | undefined => {\n try {\n const parsed = JSON.parse(rawBody) as unknown\n\n return isRecord(parsed) ? (parsed as DocsManifest) : undefined\n } catch {\n return undefined\n }\n}\n\ntype ResolvedSyncSource = {\n docsSet: ResolvedDocsSet\n routeBase: string\n sourceId: string\n}\n\nconst resolveSyncSource = async ({\n manifest,\n options,\n payload,\n}: {\n manifest: DocsManifest\n options: CreateSyncEndpointOptions\n payload: DocsSetPayloadOperations\n}): Promise<\n | {\n response: Response\n source?: never\n }\n | {\n response?: never\n source: ResolvedSyncSource\n }\n> => {\n const sourceId = manifest.source?.id\n\n if (!sourceId) {\n return {\n response: errorResponse(\n 'source_not_allowed',\n 'Manifest source.id is required and must match a docs set slug.',\n 400,\n ),\n }\n }\n\n const docsSet = options.docsSetsEnabled\n ? await findDocsSetBySlug({\n slug: sourceId,\n collectionSlug: options.docsSetsCollectionSlug,\n docsGroupsCollectionSlug: options.docsGroupsCollectionSlug,\n includeDrafts: true,\n payload,\n })\n : undefined\n\n if (docsSet) {\n return {\n source: {\n docsSet,\n routeBase: docsSet.routeBase,\n sourceId,\n },\n }\n }\n\n return {\n response: errorResponse(\n 'source_not_allowed',\n `No docs set exists for source \"${sourceId}\". Create a docs set with slug \"${sourceId}\" in Payload Admin before syncing this source.`,\n 400,\n ),\n }\n}\n\nconst summarizePlan = (plan: ReturnType<typeof planDocsSync>) => ({\n archive: plan.archive.length,\n create: plan.create.length,\n delete: plan.delete.length,\n draft: plan.draft.length,\n unchanged: plan.unchanged.length,\n update: plan.update.length,\n warnings: plan.warnings.length,\n})\n\nconst serializeChange = (change: PlannedDocChange): SerializedChange => ({\n current: change.current\n ? {\n archived: change.current.archived,\n route: change.current.route,\n sourceHash: change.current.sourceHash,\n title: change.current.title,\n }\n : undefined,\n desired: change.desired\n ? {\n route: change.desired.route,\n sha256: change.desired.sha256,\n title: change.desired.title,\n }\n : undefined,\n reason: change.reason,\n sourcePath: change.sourcePath,\n})\n\nconst serializeChanges = (plan: ReturnType<typeof planDocsSync>) => ({\n archive: plan.archive.map(serializeChange),\n create: plan.create.map(serializeChange),\n delete: plan.delete.map(serializeChange),\n draft: plan.draft.map(serializeChange),\n unchanged: plan.unchanged.map(serializeChange),\n update: plan.update.map(serializeChange),\n})\n\nconst getTotalManifestBytes = (manifest: ValidatedDocsManifest): number =>\n manifest.files.reduce((total, file) => total + Buffer.byteLength(file.content, 'utf8'), 0)\n\nconst getPlannedConflictChanges = ({\n existing,\n plan,\n}: {\n existing: ExistingPayloadDocsRecord[]\n plan: ReturnType<typeof planDocsSync>\n}): PlannedDocChange[] => {\n const existingBySourcePath = new Map(existing.map((record) => [record.sourcePath, record]))\n const archivedUnchanged = plan.unchanged.filter((change) => {\n const current = existingBySourcePath.get(change.sourcePath)\n\n return current?.archived === true\n })\n\n return [...plan.update, ...plan.archive, ...plan.draft, ...plan.delete, ...archivedUnchanged]\n}\n\nconst getLifecyclePolicyError = ({\n deleteBehavior,\n manifest,\n options,\n}: {\n deleteBehavior: DocsDeleteBehavior\n manifest: ValidatedDocsManifest\n options: CreateSyncEndpointOptions\n}): Response | undefined => {\n if (manifest.publish && options.allowPublish !== true) {\n return errorResponse('publish_disabled', 'Publishing is disabled by server configuration.', 403)\n }\n\n if (manifest.publish && !options.docsEnableDrafts) {\n return errorResponse(\n 'publish_not_available',\n 'Publishing requires a draft-enabled dedicated docs collection.',\n 400,\n )\n }\n\n if (deleteBehavior === 'draft' && !options.docsEnableDrafts) {\n return errorResponse(\n 'draft_behavior_not_available',\n 'Draft delete behavior requires a draft-enabled dedicated docs collection.',\n 400,\n )\n }\n\n if (deleteBehavior === 'delete' && options.allowHardDelete !== true) {\n return errorResponse(\n 'hard_delete_disabled',\n 'Hard delete is disabled by server configuration.',\n 403,\n )\n }\n\n return undefined\n}\n\nconst getRouteCollisionIssues = async ({\n docsSet,\n manifest,\n options,\n payload,\n routeBase,\n}: {\n docsSet?: ResolvedDocsSet\n manifest: ValidatedDocsManifest\n options: CreateSyncEndpointOptions\n payload: RouteCollisionPayloadOperations\n routeBase: string\n}) => {\n const desiredRoutes = manifest.files.map((file) => file.route)\n const duplicateDesiredRouteCollisions = findDuplicateDesiredRouteCollisions(desiredRoutes)\n const existingDocsRouteCollisions = options.docsEnabled\n ? await findExistingDocsRouteCollisions({\n collectionSlug: options.docsCollectionSlug,\n docsSetId: docsSet?.id,\n includeDrafts: options.docsEnableDrafts,\n payload,\n routes: desiredRoutes,\n sourceId: manifest.source.id,\n })\n : []\n const pageRouteCollisions =\n options.routing?.pages?.enabled === true\n ? await findConfiguredPagesRouteCollisions({\n allowBridgePages: options.routing.pages.allowBridgePages,\n bridgeField: options.routing.pages.bridgeField,\n collectionSlug: options.routing.pages.collection,\n docsSetRouteBase: routeBase,\n payload,\n routeField: options.routing.pages.routeField,\n })\n : []\n\n return [\n ...duplicateDesiredRouteCollisions,\n ...existingDocsRouteCollisions,\n ...pageRouteCollisions,\n ]\n}\n\ntype AuthenticatedSyncRequest = {\n actor?: string\n bodyHash: string\n branch?: string\n commit?: string\n expiresAt: Date\n keyId: string\n nonce: string\n repository?: string\n}\n\nconst getRequiredHeader = (headers: Headers, name: string): string | undefined => {\n const value = headers.get(name)\n\n return value && value.trim() !== '' ? value.trim() : undefined\n}\n\nconst getBearerToken = (headers: Headers): string | undefined => {\n const authorization = getRequiredHeader(headers, 'authorization')\n\n if (!authorization) {\n return undefined\n }\n\n const [scheme, token] = authorization.split(/\\s+/, 2)\n\n if (scheme?.toLowerCase() !== 'bearer' || !token) {\n return ''\n }\n\n return token\n}\n\nconst hasEd25519AuthHeaders = (headers: Headers): boolean =>\n getRequiredHeader(headers, 'x-vl-md-docs-key-id') !== undefined ||\n getRequiredHeader(headers, 'x-vl-md-docs-signature') !== undefined ||\n getRequiredHeader(headers, 'x-vl-md-docs-timestamp') !== undefined ||\n getRequiredHeader(headers, 'x-vl-md-docs-nonce') !== undefined\n\nconst assertReplayProtectionAvailable = (\n options: CreateSyncEndpointOptions,\n): Response | undefined =>\n options.noncesEnabled\n ? undefined\n : errorResponse(\n 'replay_protection_unavailable',\n 'Sync endpoint requires nonce replay protection.',\n 500,\n )\n\nconst authenticateEd25519Request = async ({\n now,\n options,\n rawBody,\n req,\n}: {\n now: Date\n options: CreateSyncEndpointOptions\n rawBody: string\n req: PayloadRequest\n}): Promise<\n | {\n identity: AuthenticatedSyncRequest\n response?: never\n }\n | {\n identity?: never\n response: Response\n }\n> => {\n const headersResult = extractSyncRequestHeaders(req.headers)\n\n if (!headersResult.ok) {\n return {\n response: errorResponse(\n 'missing_header',\n `Missing required sync header: ${headersResult.header}.`,\n 401,\n ),\n }\n }\n\n if (!options.docsKeysEnabled) {\n return {\n response: errorResponse(\n 'auth_disabled',\n 'Signed sync authentication requires the docs Keys collection.',\n 401,\n ),\n }\n }\n\n const keyConfig = await findDocsKeyById({\n collectionSlug: options.docsKeysCollectionSlug,\n keyId: headersResult.headers.keyId,\n payload: req.payload as unknown as DocsKeyPayloadOperations,\n })\n\n if (!keyConfig) {\n return {\n response: errorResponse('unknown_key', 'Unknown sync request key id.', 401),\n }\n }\n\n const bodyHash = verifyBodySha256({\n body: rawBody,\n expectedHash: headersResult.headers.bodySha256,\n })\n\n if (!bodyHash.ok) {\n return {\n response: errorResponse(\n 'body_hash_mismatch',\n 'Sync request body hash does not match the signed header.',\n 401,\n ),\n }\n }\n\n const timestampValidation = validateTimestampSkew({\n maxSkewSeconds: options.maxSkewSeconds ?? DEFAULT_MAX_SKEW_SECONDS,\n now,\n timestamp: headersResult.headers.timestamp,\n })\n\n if (!timestampValidation.ok) {\n return {\n response: errorResponse('invalid_timestamp', timestampValidation.message, 401),\n }\n }\n\n const replayUnavailable = assertReplayProtectionAvailable(options)\n\n if (replayUnavailable) {\n return {\n response: replayUnavailable,\n }\n }\n\n const nonceAvailable = await assertNonceNotReplayed({\n collectionSlug: options.noncesCollectionSlug,\n keyId: headersResult.headers.keyId,\n nonce: headersResult.headers.nonce,\n now,\n payload: req.payload as unknown as NoncePayloadOperations,\n })\n\n if (!nonceAvailable) {\n return {\n response: errorResponse('nonce_replay', 'Sync request nonce has already been used.', 409),\n }\n }\n\n const canonicalPath = getCanonicalPathFromRequestUrl({\n endpointPath: options.endpointPath,\n url: req.url,\n })\n const canonicalString = buildCanonicalSigningString({\n bodySha256: bodyHash.computedHash,\n method: 'POST',\n nonce: headersResult.headers.nonce,\n path: canonicalPath,\n timestamp: headersResult.headers.timestamp,\n })\n\n if (\n !verifyEd25519Signature({\n canonicalString,\n publicKey: keyConfig.publicKey,\n signature: headersResult.headers.signature,\n })\n ) {\n return {\n response: errorResponse('invalid_signature', 'Invalid sync request signature.', 401),\n }\n }\n\n const nonceTtlSeconds = options.nonceTtlSeconds ?? DEFAULT_NONCE_TTL_SECONDS\n\n return {\n identity: {\n bodyHash: bodyHash.computedHash,\n expiresAt: new Date(now.getTime() + nonceTtlSeconds * 1000),\n keyId: headersResult.headers.keyId,\n nonce: headersResult.headers.nonce,\n },\n }\n}\n\nconst authenticateGitHubOidcRequest = async ({\n docsSet,\n now,\n options,\n rawBody,\n req,\n}: {\n docsSet: ResolvedDocsSet\n now: Date\n options: CreateSyncEndpointOptions\n rawBody: string\n req: PayloadRequest\n}): Promise<\n | {\n identity: AuthenticatedSyncRequest\n response?: never\n }\n | {\n identity?: never\n response: Response\n }\n> => {\n const token = getBearerToken(req.headers)\n\n if (token === undefined) {\n return {\n response: errorResponse(\n 'missing_header',\n 'Missing required sync header: Authorization.',\n 401,\n ),\n }\n }\n\n if (token === '') {\n return {\n response: errorResponse(\n 'oidc_invalid_token',\n 'Authorization must be a Bearer GitHub OIDC token.',\n 401,\n ),\n }\n }\n\n const expectedHash = getRequiredHeader(req.headers, 'x-vl-md-docs-body-sha256')\n\n if (!expectedHash) {\n return {\n response: errorResponse(\n 'missing_header',\n 'Missing required sync header: X-VL-MD-DOCS-Body-SHA256.',\n 401,\n ),\n }\n }\n\n const bodyHash = verifyBodySha256({\n body: rawBody,\n expectedHash,\n })\n\n if (!bodyHash.ok) {\n return {\n response: errorResponse(\n 'body_hash_mismatch',\n 'Sync request body hash does not match the OIDC header.',\n 401,\n ),\n }\n }\n\n if (!options.docsTrustedEnabled) {\n return {\n response: errorResponse(\n 'auth_disabled',\n 'GitHub OIDC sync authentication requires the docs Trusted collection.',\n 401,\n ),\n }\n }\n\n const trustedSources = await findTrustedGitHubSources({\n collectionSlug: options.docsTrustedCollectionSlug,\n payload: req.payload as unknown as DocsTrustedPayloadOperations,\n })\n const allowedRef = docsSet.branch.startsWith('refs/')\n ? docsSet.branch\n : `refs/heads/${docsSet.branch}`\n\n const verified = await verifyGitHubOidcToken({\n config: {\n allowedRefs: [allowedRef],\n allowedWorkflowRefs: docsSet.advancedSecurity?.allowedWorkflowRefs,\n allowPullRequests: docsSet.allowPullRequests,\n audience: docsSet.slug,\n enforceWorkflowRefs: docsSet.advancedSecurity?.enabled === true,\n trustedSources,\n },\n fetchJson: options.oidcFetchJson,\n now,\n token,\n })\n\n if (!verified.ok) {\n return {\n response: errorResponse(\n verified.code,\n verified.message,\n verified.code === 'oidc_jwks_unavailable' ? 503 : 401,\n ),\n }\n }\n\n const replayUnavailable = assertReplayProtectionAvailable(options)\n\n if (replayUnavailable) {\n return {\n response: replayUnavailable,\n }\n }\n\n const nonceAvailable = await assertNonceNotReplayed({\n collectionSlug: options.noncesCollectionSlug,\n keyId: verified.token.keyId,\n nonce: verified.token.claims.jti,\n now,\n payload: req.payload as unknown as NoncePayloadOperations,\n })\n\n if (!nonceAvailable) {\n return {\n response: errorResponse('oidc_replay', 'GitHub OIDC token jti has already been used.', 409),\n }\n }\n\n return {\n identity: {\n actor: verified.token.claims.actor,\n bodyHash: bodyHash.computedHash,\n branch: verified.token.claims.ref,\n commit: verified.token.claims.sha,\n expiresAt: verified.token.expiresAt,\n keyId: verified.token.keyId,\n nonce: verified.token.claims.jti,\n repository: verified.token.claims.repository,\n },\n }\n}\n\nconst authenticateSyncRequest = async ({\n docsSet,\n now,\n options,\n rawBody,\n req,\n}: {\n docsSet: ResolvedDocsSet\n now: Date\n options: CreateSyncEndpointOptions\n rawBody: string\n req: PayloadRequest\n}): Promise<\n | {\n identity: AuthenticatedSyncRequest\n response?: never\n }\n | {\n identity?: never\n response: Response\n }\n> => {\n const ed25519Enabled = isEd25519AuthEnabled(options.auth)\n const githubOidcEnabled = isGitHubOidcAuthEnabled(options.auth)\n\n if (!ed25519Enabled && !githubOidcEnabled) {\n return {\n response: errorResponse(\n 'auth_disabled',\n 'Sync authentication is not configured for this endpoint.',\n 401,\n ),\n }\n }\n\n const bearerToken = getBearerToken(req.headers)\n\n if (bearerToken !== undefined) {\n if (!githubOidcEnabled) {\n return {\n response: errorResponse(\n 'auth_disabled',\n 'GitHub OIDC sync authentication is not configured for this endpoint.',\n 401,\n ),\n }\n }\n\n return authenticateGitHubOidcRequest({\n docsSet,\n now,\n options,\n rawBody,\n req,\n })\n }\n\n if (hasEd25519AuthHeaders(req.headers) || !githubOidcEnabled) {\n if (!ed25519Enabled) {\n return {\n response: errorResponse(\n 'auth_disabled',\n 'Signed sync authentication is not configured for this endpoint.',\n 401,\n ),\n }\n }\n\n return authenticateEd25519Request({\n now,\n options,\n rawBody,\n req,\n })\n }\n\n return authenticateGitHubOidcRequest({\n docsSet,\n now,\n options,\n rawBody,\n req,\n })\n}\n\nconst createSyncEndpointHandler =\n (options: CreateSyncEndpointOptions) =>\n async (req: PayloadRequest): Promise<Response> => {\n const startedAt = options.getNow?.() ?? new Date()\n\n if (req.method && req.method.toUpperCase() !== 'POST') {\n return errorResponse('invalid_method', 'Sync endpoint only accepts POST.', 405)\n }\n\n if (typeof req.text !== 'function') {\n return errorResponse(\n 'invalid_body',\n 'Sync endpoint requires access to the request body text.',\n 400,\n )\n }\n\n const rawBody = await req.text()\n const maxBodyBytes = options.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES\n\n if (Buffer.byteLength(rawBody, 'utf8') > maxBodyBytes) {\n return errorResponse('invalid_body', 'Sync request body is too large.', 413)\n }\n\n const manifest = parseManifestBody(rawBody)\n\n if (!manifest) {\n return errorResponse('invalid_body', 'Sync request body must be a JSON manifest.', 400)\n }\n\n const sourceResolution = await resolveSyncSource({\n manifest,\n options,\n payload: req.payload as unknown as DocsSetPayloadOperations,\n })\n\n if (sourceResolution.response) {\n return sourceResolution.response\n }\n\n const authentication = await authenticateSyncRequest({\n docsSet: sourceResolution.source.docsSet,\n now: startedAt,\n options,\n rawBody,\n req,\n })\n\n if (authentication.response) {\n return authentication.response\n }\n\n const validation = validateDocsManifest(manifest, {\n allowedSourceIds: [sourceResolution.source.sourceId],\n maxTotalBytes: maxBodyBytes,\n routeBase: sourceResolution.source.routeBase,\n })\n\n if (!validation.ok) {\n return jsonResponse(\n {\n error: {\n code: 'invalid_manifest',\n message: 'Sync manifest is invalid.',\n },\n ok: false,\n },\n 400,\n )\n }\n\n const effectiveDeleteBehavior = options.deleteBehavior ?? 'archive'\n const lifecyclePolicyError = getLifecyclePolicyError({\n deleteBehavior: effectiveDeleteBehavior,\n manifest: validation.data,\n options,\n })\n\n if (lifecyclePolicyError) {\n return lifecyclePolicyError\n }\n\n const routeCollisions = await getRouteCollisionIssues({\n docsSet: sourceResolution.source.docsSet,\n manifest: validation.data,\n options,\n payload: req.payload as unknown as RouteCollisionPayloadOperations,\n routeBase: sourceResolution.source.routeBase,\n })\n\n if (routeCollisions.length > 0) {\n return errorResponse(\n 'route_collision',\n 'One or more docs routes collide with an existing route reservation.',\n 409,\n {\n routeCollisions,\n },\n )\n }\n\n const isSyncMode = validation.data.mode === 'sync'\n\n if (isSyncMode && options.allowWrites !== true) {\n return errorResponse(\n 'sync_writes_disabled',\n 'Sync writes are disabled by server configuration.',\n 403,\n )\n }\n\n if (isSyncMode && options.requireDryRunBeforeApply === true) {\n return errorResponse(\n 'dry_run_required_not_implemented',\n 'Required dry-run proof before apply is not implemented yet.',\n 400,\n )\n }\n\n if (\n isSyncMode &&\n !assertApplyDeleteBehaviorSupported(effectiveDeleteBehavior, {\n allowHardDelete: options.allowHardDelete,\n docsEnableDrafts: options.docsEnableDrafts,\n })\n ) {\n return errorResponse(\n 'delete_behavior_not_implemented',\n 'Configured delete behavior cannot be applied.',\n 400,\n )\n }\n\n if (isSyncMode && !options.syncRunsEnabled) {\n return errorResponse(\n 'audit_unavailable',\n 'Applied sync requires the sync-run audit collection.',\n 500,\n )\n }\n\n const existingPayloadDocs = options.docsEnabled\n ? await findExistingPayloadDocsRecords({\n collectionSlug: options.docsCollectionSlug,\n docsSetId: sourceResolution.source.docsSet?.id,\n draft: options.docsEnableDrafts,\n markdownFieldName: options.markdownFieldName,\n payload: req.payload as unknown as ExistingDocsPayloadOperations,\n sourceId: validation.data.source.id,\n })\n : []\n const existingDocs = existingPayloadDocs.map(toExistingDocsRecord)\n const plan = planDocsSync({\n deleteBehavior: effectiveDeleteBehavior,\n desired: validation.data,\n existing: existingDocs,\n })\n const summary = summarizePlan(plan)\n const warnings = [...validation.warnings, ...plan.warnings]\n if (isSyncMode) {\n const existingBySourcePath = new Map(\n existingPayloadDocs.map((record) => [record.sourcePath, record]),\n )\n const conflicts = findDocsSyncConflicts({\n existingBySourcePath,\n plannedChanges: getPlannedConflictChanges({\n existing: existingPayloadDocs,\n plan,\n }),\n })\n\n if (conflicts.length > 0) {\n return errorResponse(\n 'manual_edit_conflict',\n 'One or more docs were modified outside the docs sync workflow.',\n 409,\n {\n conflicts,\n },\n )\n }\n }\n\n await storeAcceptedNonce({\n bodyHash: authentication.identity.bodyHash,\n collectionSlug: options.noncesCollectionSlug,\n expiresAt: authentication.identity.expiresAt,\n keyId: authentication.identity.keyId,\n nonce: authentication.identity.nonce,\n payload: req.payload as unknown as NoncePayloadOperations,\n sourceId: validation.data.source.id,\n usedAt: startedAt,\n })\n\n let syncRunId: number | string | undefined\n\n if (options.syncRunsEnabled) {\n const syncRun = await createSyncRunAudit({\n actor: authentication.identity.actor,\n bodyHash: authentication.identity.bodyHash,\n branch: authentication.identity.branch ?? validation.data.source.branch,\n collectionSlug: options.syncRunsCollectionSlug,\n commit: authentication.identity.commit ?? validation.data.source.commit,\n completedAt: isSyncMode ? startedAt : (options.getNow?.() ?? new Date()),\n deleteBehavior: effectiveDeleteBehavior,\n errors: [],\n fileCount: validation.data.files.length,\n keyId: authentication.identity.keyId,\n mode: isSyncMode ? 'sync' : 'dry-run',\n payload: req.payload as unknown as SyncRunsPayloadOperations,\n publishRequested: validation.data.publish,\n repository: authentication.identity.repository ?? validation.data.source.repository,\n sourceId: validation.data.source.id,\n startedAt,\n status: isSyncMode ? 'pending' : 'success',\n summary,\n totalBytes: getTotalManifestBytes(validation.data),\n warnings,\n })\n\n syncRunId = getRecordId(syncRun)\n }\n\n if (isSyncMode) {\n if (!syncRunId) {\n return errorResponse(\n 'audit_unavailable',\n 'Applied sync could not create a sync-run audit record.',\n 500,\n )\n }\n\n try {\n const applyResult = await applyDocsSync({\n collectionSlug: options.docsCollectionSlug,\n deleteBehavior: effectiveDeleteBehavior,\n docsEnableDrafts: options.docsEnableDrafts,\n docsSetId: sourceResolution.source.docsSet?.id,\n existing: existingPayloadDocs,\n manifest: validation.data,\n markdownFieldName: options.markdownFieldName,\n now: options.getNow?.() ?? new Date(),\n payload: req.payload as unknown as ApplyDocsSyncPayloadOperations,\n plan,\n publish: validation.data.publish,\n syncRunId,\n })\n\n if (!applyResult.ok) {\n return errorResponse(\n 'manual_edit_conflict',\n 'One or more docs were modified outside the docs sync workflow.',\n 409,\n {\n conflicts: applyResult.conflicts,\n },\n )\n }\n\n await updateSyncRunAudit({\n collectionSlug: options.syncRunsCollectionSlug,\n completedAt: options.getNow?.() ?? new Date(),\n payload: req.payload as unknown as SyncRunsPayloadOperations,\n status: 'success',\n summary,\n syncRunId,\n warnings,\n })\n\n if (sourceResolution.source.docsSet) {\n await updateDocsSetAfterSync({\n aiExport: validation.data.aiExport,\n collectionSlug: options.docsSetsCollectionSlug,\n docsCount: validation.data.files.length,\n docsSetId: sourceResolution.source.docsSet.id,\n now: options.getNow?.() ?? new Date(),\n payload: req.payload as unknown as DocsSetPayloadOperations,\n publish: validation.data.publish,\n syncRunId,\n })\n }\n } catch (error) {\n await updateSyncRunAudit({\n collectionSlug: options.syncRunsCollectionSlug,\n completedAt: options.getNow?.() ?? new Date(),\n errors: [\n {\n code: 'invalid_manifest',\n message: error instanceof Error ? error.message : 'Sync apply failed.',\n },\n ],\n payload: req.payload as unknown as SyncRunsPayloadOperations,\n status: 'failed',\n summary,\n syncRunId,\n warnings,\n })\n\n return errorResponse('sync_apply_failed', 'Sync apply failed.', 500)\n }\n }\n\n return jsonResponse({\n changes: serializeChanges(plan),\n deleteBehavior: effectiveDeleteBehavior,\n dryRun: !isSyncMode,\n ok: true,\n publishRequested: validation.data.publish,\n summary,\n syncRunId: syncRunId === undefined ? undefined : String(syncRunId),\n warnings,\n })\n }\n\nexport const createSyncEndpoint = (options: CreateSyncEndpointOptions): Endpoint => ({\n handler: createSyncEndpointHandler(options),\n method: 'post',\n path: options.endpointPath,\n})\n"],"names":["DEFAULT_MAX_BODY_BYTES","DEFAULT_MAX_SKEW_SECONDS","DEFAULT_NONCE_TTL_SECONDS","applyDocsSync","assertApplyDeleteBehaviorSupported","createSyncRunAudit","findConfiguredPagesRouteCollisions","findDocsKeyById","findDocsSetBySlug","findDocsSyncConflicts","findDuplicateDesiredRouteCollisions","findExistingDocsRouteCollisions","findExistingPayloadDocsRecords","findTrustedGitHubSources","getRecordId","isEd25519AuthEnabled","isGitHubOidcAuthEnabled","toExistingDocsRecord","updateDocsSetAfterSync","updateSyncRunAudit","assertNonceNotReplayed","buildCanonicalSigningString","extractSyncRequestHeaders","getCanonicalPathFromRequestUrl","storeAcceptedNonce","validateTimestampSkew","verifyBodySha256","verifyEd25519Signature","verifyGitHubOidcToken","planDocsSync","validateDocsManifest","jsonResponse","body","status","Response","json","errorResponse","code","message","extras","error","ok","isRecord","value","Array","isArray","parseManifestBody","rawBody","parsed","JSON","parse","undefined","resolveSyncSource","manifest","options","payload","sourceId","source","id","response","docsSet","docsSetsEnabled","slug","collectionSlug","docsSetsCollectionSlug","docsGroupsCollectionSlug","includeDrafts","routeBase","summarizePlan","plan","archive","length","create","delete","draft","unchanged","update","warnings","serializeChange","change","current","archived","route","sourceHash","title","desired","sha256","reason","sourcePath","serializeChanges","map","getTotalManifestBytes","files","reduce","total","file","Buffer","byteLength","content","getPlannedConflictChanges","existing","existingBySourcePath","Map","record","archivedUnchanged","filter","get","getLifecyclePolicyError","deleteBehavior","publish","allowPublish","docsEnableDrafts","allowHardDelete","getRouteCollisionIssues","desiredRoutes","duplicateDesiredRouteCollisions","existingDocsRouteCollisions","docsEnabled","docsCollectionSlug","docsSetId","routes","pageRouteCollisions","routing","pages","enabled","allowBridgePages","bridgeField","collection","docsSetRouteBase","routeField","getRequiredHeader","headers","name","trim","getBearerToken","authorization","scheme","token","split","toLowerCase","hasEd25519AuthHeaders","assertReplayProtectionAvailable","noncesEnabled","authenticateEd25519Request","now","req","headersResult","header","docsKeysEnabled","keyConfig","docsKeysCollectionSlug","keyId","bodyHash","expectedHash","bodySha256","timestampValidation","maxSkewSeconds","timestamp","replayUnavailable","nonceAvailable","noncesCollectionSlug","nonce","canonicalPath","endpointPath","url","canonicalString","computedHash","method","path","publicKey","signature","nonceTtlSeconds","identity","expiresAt","Date","getTime","authenticateGitHubOidcRequest","docsTrustedEnabled","trustedSources","docsTrustedCollectionSlug","allowedRef","branch","startsWith","verified","config","allowedRefs","allowedWorkflowRefs","advancedSecurity","allowPullRequests","audience","enforceWorkflowRefs","fetchJson","oidcFetchJson","claims","jti","actor","ref","commit","sha","repository","authenticateSyncRequest","ed25519Enabled","auth","githubOidcEnabled","bearerToken","createSyncEndpointHandler","startedAt","getNow","toUpperCase","text","maxBodyBytes","sourceResolution","authentication","validation","allowedSourceIds","maxTotalBytes","effectiveDeleteBehavior","lifecyclePolicyError","data","routeCollisions","isSyncMode","mode","allowWrites","requireDryRunBeforeApply","syncRunsEnabled","existingPayloadDocs","markdownFieldName","existingDocs","summary","conflicts","plannedChanges","usedAt","syncRunId","syncRun","syncRunsCollectionSlug","completedAt","errors","fileCount","publishRequested","totalBytes","applyResult","aiExport","docsCount","Error","changes","dryRun","String","create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
  import { deriveDocsSetRouteBase, joinRouteSegments } from '../routing/index.js';
3
- import { getRelationshipId, isRecord, toResolvedDocsSet } from './records.js';
3
+ import { getRelationshipId, isRecord, isVisibleDocsSet, toResolvedDocsSet } from './records.js';
4
4
  const getGroupRoutePath = ({ groupId, groupsById, seen = new Set() })=>{
5
5
  if (!groupId || seen.has(groupId)) {
6
6
  return undefined;
@@ -25,6 +25,7 @@ export const getPayloadMarkdownDocsLinks = async ({ collections, overrideAccess
25
25
  payload.find({
26
26
  collection: docsSetsCollectionSlug,
27
27
  depth: 0,
28
+ draft: false,
28
29
  limit: 1000,
29
30
  overrideAccess
30
31
  }),
@@ -49,7 +50,9 @@ export const getPayloadMarkdownDocsLinks = async ({ collections, overrideAccess
49
50
  }));
50
51
  return docsSetsResult.docs.flatMap((doc)=>{
51
52
  const docsSet = toResolvedDocsSet(doc);
52
- if (!docsSet?.slug || !isRecord(doc)) {
53
+ if (!docsSet?.slug || !isRecord(doc) || !isVisibleDocsSet({
54
+ docsSet
55
+ })) {
53
56
  return [];
54
57
  }
55
58
  return [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/links.ts"],"sourcesContent":["import type {\n PayloadMarkdownDocsCollectionSlugs,\n PayloadMarkdownDocsReadPayload,\n} from './types.js'\n\nimport {\n DEFAULT_DOCS_GROUPS_COLLECTION_SLUG,\n DEFAULT_DOCS_SETS_COLLECTION_SLUG,\n} from '../constants.js'\nimport { deriveDocsSetRouteBase, joinRouteSegments } from '../routing/index.js'\nimport {\n getRelationshipId,\n isRecord,\n toResolvedDocsSet,\n} from './records.js'\n\nexport type PayloadMarkdownDocsLink = {\n label: string\n url: string\n}\n\nexport type GetPayloadMarkdownDocsLinksOptions = {\n collections?: Pick<PayloadMarkdownDocsCollectionSlugs, 'docsGroups' | 'docsSets'>\n overrideAccess?: boolean\n payload: PayloadMarkdownDocsReadPayload\n}\n\nconst getGroupRoutePath = ({\n groupId,\n groupsById,\n seen = new Set<string>(),\n}: {\n groupId?: string\n groupsById: Map<string, unknown>\n seen?: Set<string>\n}): string | undefined => {\n if (!groupId || seen.has(groupId)) {\n return undefined\n }\n\n const group = groupsById.get(groupId)\n\n if (!isRecord(group) || typeof group.slug !== 'string') {\n return undefined\n }\n\n return joinRouteSegments(\n getGroupRoutePath({\n groupId: getRelationshipId(group.parent),\n groupsById,\n seen: new Set([groupId, ...seen]),\n }),\n group.slug,\n )\n}\n\nexport const getPayloadMarkdownDocsLinks = async ({\n collections,\n overrideAccess = true,\n payload,\n}: GetPayloadMarkdownDocsLinksOptions): Promise<PayloadMarkdownDocsLink[]> => {\n const docsGroupsCollectionSlug =\n collections?.docsGroups ?? DEFAULT_DOCS_GROUPS_COLLECTION_SLUG\n const docsSetsCollectionSlug =\n collections?.docsSets ?? DEFAULT_DOCS_SETS_COLLECTION_SLUG\n const [docsSetsResult, docsGroupsResult] = await Promise.all([\n payload.find({\n collection: docsSetsCollectionSlug,\n depth: 0,\n limit: 1000,\n overrideAccess,\n }),\n payload.find({\n collection: docsGroupsCollectionSlug,\n depth: 0,\n limit: 1000,\n overrideAccess,\n }),\n ])\n const groupsById = new Map(\n docsGroupsResult.docs.flatMap((group) => {\n if (!isRecord(group)) {\n return []\n }\n\n const id = getRelationshipId(group)\n\n return id ? [[id, group]] : []\n }),\n )\n\n return docsSetsResult.docs\n .flatMap((doc) => {\n const docsSet = toResolvedDocsSet(doc)\n\n if (!docsSet?.slug || !isRecord(doc)) {\n return []\n }\n\n return [\n {\n label: docsSet.navTitle ?? docsSet.title,\n order: docsSet.order,\n url: deriveDocsSetRouteBase({\n docsSetSlug: docsSet.slug,\n groupRoutePath: getGroupRoutePath({\n groupId: getRelationshipId(doc.group),\n groupsById,\n }),\n }),\n },\n ]\n })\n .sort((first, second) => {\n if (first.order !== second.order) {\n return first.order - second.order\n }\n\n return first.label.localeCompare(second.label)\n })\n .map(({ label, url }) => ({\n label,\n url,\n }))\n}\n"],"names":["DEFAULT_DOCS_GROUPS_COLLECTION_SLUG","DEFAULT_DOCS_SETS_COLLECTION_SLUG","deriveDocsSetRouteBase","joinRouteSegments","getRelationshipId","isRecord","toResolvedDocsSet","getGroupRoutePath","groupId","groupsById","seen","Set","has","undefined","group","get","slug","parent","getPayloadMarkdownDocsLinks","collections","overrideAccess","payload","docsGroupsCollectionSlug","docsGroups","docsSetsCollectionSlug","docsSets","docsSetsResult","docsGroupsResult","Promise","all","find","collection","depth","limit","Map","docs","flatMap","id","doc","docsSet","label","navTitle","title","order","url","docsSetSlug","groupRoutePath","sort","first","second","localeCompare","map"],"mappings":"AAKA,SACEA,mCAAmC,EACnCC,iCAAiC,QAC5B,kBAAiB;AACxB,SAASC,sBAAsB,EAAEC,iBAAiB,QAAQ,sBAAqB;AAC/E,SACEC,iBAAiB,EACjBC,QAAQ,EACRC,iBAAiB,QACZ,eAAc;AAarB,MAAMC,oBAAoB,CAAC,EACzBC,OAAO,EACPC,UAAU,EACVC,OAAO,IAAIC,KAAa,EAKzB;IACC,IAAI,CAACH,WAAWE,KAAKE,GAAG,CAACJ,UAAU;QACjC,OAAOK;IACT;IAEA,MAAMC,QAAQL,WAAWM,GAAG,CAACP;IAE7B,IAAI,CAACH,SAASS,UAAU,OAAOA,MAAME,IAAI,KAAK,UAAU;QACtD,OAAOH;IACT;IAEA,OAAOV,kBACLI,kBAAkB;QAChBC,SAASJ,kBAAkBU,MAAMG,MAAM;QACvCR;QACAC,MAAM,IAAIC,IAAI;YAACH;eAAYE;SAAK;IAClC,IACAI,MAAME,IAAI;AAEd;AAEA,OAAO,MAAME,8BAA8B,OAAO,EAChDC,WAAW,EACXC,iBAAiB,IAAI,EACrBC,OAAO,EAC4B;IACnC,MAAMC,2BACJH,aAAaI,cAAcvB;IAC7B,MAAMwB,yBACJL,aAAaM,YAAYxB;IAC3B,MAAM,CAACyB,gBAAgBC,iBAAiB,GAAG,MAAMC,QAAQC,GAAG,CAAC;QAC3DR,QAAQS,IAAI,CAAC;YACXC,YAAYP;YACZQ,OAAO;YACPC,OAAO;YACPb;QACF;QACAC,QAAQS,IAAI,CAAC;YACXC,YAAYT;YACZU,OAAO;YACPC,OAAO;YACPb;QACF;KACD;IACD,MAAMX,aAAa,IAAIyB,IACrBP,iBAAiBQ,IAAI,CAACC,OAAO,CAAC,CAACtB;QAC7B,IAAI,CAACT,SAASS,QAAQ;YACpB,OAAO,EAAE;QACX;QAEA,MAAMuB,KAAKjC,kBAAkBU;QAE7B,OAAOuB,KAAK;YAAC;gBAACA;gBAAIvB;aAAM;SAAC,GAAG,EAAE;IAChC;IAGF,OAAOY,eAAeS,IAAI,CACvBC,OAAO,CAAC,CAACE;QACR,MAAMC,UAAUjC,kBAAkBgC;QAElC,IAAI,CAACC,SAASvB,QAAQ,CAACX,SAASiC,MAAM;YACpC,OAAO,EAAE;QACX;QAEA,OAAO;YACL;gBACEE,OAAOD,QAAQE,QAAQ,IAAIF,QAAQG,KAAK;gBACxCC,OAAOJ,QAAQI,KAAK;gBACpBC,KAAK1C,uBAAuB;oBAC1B2C,aAAaN,QAAQvB,IAAI;oBACzB8B,gBAAgBvC,kBAAkB;wBAChCC,SAASJ,kBAAkBkC,IAAIxB,KAAK;wBACpCL;oBACF;gBACF;YACF;SACD;IACH,GACCsC,IAAI,CAAC,CAACC,OAAOC;QACZ,IAAID,MAAML,KAAK,KAAKM,OAAON,KAAK,EAAE;YAChC,OAAOK,MAAML,KAAK,GAAGM,OAAON,KAAK;QACnC;QAEA,OAAOK,MAAMR,KAAK,CAACU,aAAa,CAACD,OAAOT,KAAK;IAC/C,GACCW,GAAG,CAAC,CAAC,EAAEX,KAAK,EAAEI,GAAG,EAAE,GAAM,CAAA;YACxBJ;YACAI;QACF,CAAA;AACJ,EAAC"}
1
+ {"version":3,"sources":["../../src/next/links.ts"],"sourcesContent":["import type { PayloadMarkdownDocsCollectionSlugs, PayloadMarkdownDocsReadPayload } from './types.js'\n\nimport {\n DEFAULT_DOCS_GROUPS_COLLECTION_SLUG,\n DEFAULT_DOCS_SETS_COLLECTION_SLUG,\n} from '../constants.js'\nimport { deriveDocsSetRouteBase, joinRouteSegments } from '../routing/index.js'\nimport { getRelationshipId, isRecord, isVisibleDocsSet, toResolvedDocsSet } from './records.js'\n\nexport type PayloadMarkdownDocsLink = {\n label: string\n url: string\n}\n\nexport type GetPayloadMarkdownDocsLinksOptions = {\n collections?: Pick<PayloadMarkdownDocsCollectionSlugs, 'docsGroups' | 'docsSets'>\n overrideAccess?: boolean\n payload: PayloadMarkdownDocsReadPayload\n}\n\nconst getGroupRoutePath = ({\n groupId,\n groupsById,\n seen = new Set<string>(),\n}: {\n groupId?: string\n groupsById: Map<string, unknown>\n seen?: Set<string>\n}): string | undefined => {\n if (!groupId || seen.has(groupId)) {\n return undefined\n }\n\n const group = groupsById.get(groupId)\n\n if (!isRecord(group) || typeof group.slug !== 'string') {\n return undefined\n }\n\n return joinRouteSegments(\n getGroupRoutePath({\n groupId: getRelationshipId(group.parent),\n groupsById,\n seen: new Set([groupId, ...seen]),\n }),\n group.slug,\n )\n}\n\nexport const getPayloadMarkdownDocsLinks = async ({\n collections,\n overrideAccess = true,\n payload,\n}: GetPayloadMarkdownDocsLinksOptions): Promise<PayloadMarkdownDocsLink[]> => {\n const docsGroupsCollectionSlug = collections?.docsGroups ?? DEFAULT_DOCS_GROUPS_COLLECTION_SLUG\n const docsSetsCollectionSlug = collections?.docsSets ?? DEFAULT_DOCS_SETS_COLLECTION_SLUG\n const [docsSetsResult, docsGroupsResult] = await Promise.all([\n payload.find({\n collection: docsSetsCollectionSlug,\n depth: 0,\n draft: false,\n limit: 1000,\n overrideAccess,\n }),\n payload.find({\n collection: docsGroupsCollectionSlug,\n depth: 0,\n limit: 1000,\n overrideAccess,\n }),\n ])\n const groupsById = new Map(\n docsGroupsResult.docs.flatMap((group) => {\n if (!isRecord(group)) {\n return []\n }\n\n const id = getRelationshipId(group)\n\n return id ? [[id, group]] : []\n }),\n )\n\n return docsSetsResult.docs\n .flatMap((doc) => {\n const docsSet = toResolvedDocsSet(doc)\n\n if (!docsSet?.slug || !isRecord(doc) || !isVisibleDocsSet({ docsSet })) {\n return []\n }\n\n return [\n {\n label: docsSet.navTitle ?? docsSet.title,\n order: docsSet.order,\n url: deriveDocsSetRouteBase({\n docsSetSlug: docsSet.slug,\n groupRoutePath: getGroupRoutePath({\n groupId: getRelationshipId(doc.group),\n groupsById,\n }),\n }),\n },\n ]\n })\n .sort((first, second) => {\n if (first.order !== second.order) {\n return first.order - second.order\n }\n\n return first.label.localeCompare(second.label)\n })\n .map(({ label, url }) => ({\n label,\n url,\n }))\n}\n"],"names":["DEFAULT_DOCS_GROUPS_COLLECTION_SLUG","DEFAULT_DOCS_SETS_COLLECTION_SLUG","deriveDocsSetRouteBase","joinRouteSegments","getRelationshipId","isRecord","isVisibleDocsSet","toResolvedDocsSet","getGroupRoutePath","groupId","groupsById","seen","Set","has","undefined","group","get","slug","parent","getPayloadMarkdownDocsLinks","collections","overrideAccess","payload","docsGroupsCollectionSlug","docsGroups","docsSetsCollectionSlug","docsSets","docsSetsResult","docsGroupsResult","Promise","all","find","collection","depth","draft","limit","Map","docs","flatMap","id","doc","docsSet","label","navTitle","title","order","url","docsSetSlug","groupRoutePath","sort","first","second","localeCompare","map"],"mappings":"AAEA,SACEA,mCAAmC,EACnCC,iCAAiC,QAC5B,kBAAiB;AACxB,SAASC,sBAAsB,EAAEC,iBAAiB,QAAQ,sBAAqB;AAC/E,SAASC,iBAAiB,EAAEC,QAAQ,EAAEC,gBAAgB,EAAEC,iBAAiB,QAAQ,eAAc;AAa/F,MAAMC,oBAAoB,CAAC,EACzBC,OAAO,EACPC,UAAU,EACVC,OAAO,IAAIC,KAAa,EAKzB;IACC,IAAI,CAACH,WAAWE,KAAKE,GAAG,CAACJ,UAAU;QACjC,OAAOK;IACT;IAEA,MAAMC,QAAQL,WAAWM,GAAG,CAACP;IAE7B,IAAI,CAACJ,SAASU,UAAU,OAAOA,MAAME,IAAI,KAAK,UAAU;QACtD,OAAOH;IACT;IAEA,OAAOX,kBACL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IAAI,CAAC,CAACC,OAAOC;QACZ,IAAID,MAAML,KAAK,KAAKM,OAAON,KAAK,EAAE;YAChC,OAAOK,MAAML,KAAK,GAAGM,OAAON,KAAK;QACnC;QAEA,OAAOK,MAAMR,KAAK,CAACU,aAAa,CAACD,OAAOT,KAAK;IAC/C,GACCW,GAAG,CAAC,CAAC,EAAEX,KAAK,EAAEI,GAAG,EAAE,GAAM,CAAA;YACxBJ;YACAI;QACF,CAAA;AACJ,EAAC"}
@@ -1,7 +1,7 @@
1
1
  import { DEFAULT_DOCS_COLLECTION_SLUG, DEFAULT_DOCS_GROUPS_COLLECTION_SLUG, DEFAULT_DOCS_SETS_COLLECTION_SLUG, DEFAULT_MARKDOWN_FIELD_NAME } from '../constants.js';
2
2
  import { deriveDocsSetRouteBase, joinRouteSegments, normalizeRoutePath } from '../routing/index.js';
3
3
  import { isExcludedFromAiExport } from '../sync/index.js';
4
- import { getRelationshipId, isRecord, isVisibleDocsRecord, toResolvedDocsGroup, toResolvedDocsRecord, toResolvedDocsSet } from './records.js';
4
+ import { getRelationshipId, isRecord, isVisibleDocsRecord, isVisibleDocsSet, toResolvedDocsGroup, toResolvedDocsRecord, toResolvedDocsSet } from './records.js';
5
5
  const resolveCollectionSlugs = (collections)=>({
6
6
  docs: collections?.docs ?? DEFAULT_DOCS_COLLECTION_SLUG,
7
7
  docsGroups: collections?.docsGroups ?? DEFAULT_DOCS_GROUPS_COLLECTION_SLUG,
@@ -75,11 +75,12 @@ const withComputedDocsSetRoute = ({ doc, docsSet, groupsById })=>{
75
75
  })
76
76
  };
77
77
  };
78
- const findDocsSetByRouteBase = async ({ collections, overrideAccess, payload, routeBase })=>{
78
+ const findDocsSetByRouteBase = async ({ collections, includeDrafts, overrideAccess, payload, routeBase })=>{
79
79
  const [result, groupsById] = await Promise.all([
80
80
  payload.find({
81
81
  collection: collections.docsSets,
82
82
  depth: 0,
83
+ draft: includeDrafts,
83
84
  limit: 1000,
84
85
  overrideAccess
85
86
  }),
@@ -93,13 +94,17 @@ const findDocsSetByRouteBase = async ({ collections, overrideAccess, payload, ro
93
94
  doc,
94
95
  docsSet: toResolvedDocsSet(doc),
95
96
  groupsById
96
- })).find((docsSet)=>docsSet?.routeBase === routeBase);
97
+ })).find((docsSet)=>docsSet?.routeBase === routeBase && isVisibleDocsSet({
98
+ docsSet,
99
+ includeDrafts
100
+ }));
97
101
  };
98
- const findDocsSetByAiExportOutput = async ({ collections, output, overrideAccess, payload })=>{
102
+ const findDocsSetByAiExportOutput = async ({ collections, includeDrafts, output, overrideAccess, payload })=>{
99
103
  const [result, groupsById] = await Promise.all([
100
104
  payload.find({
101
105
  collection: collections.docsSets,
102
106
  depth: 0,
107
+ draft: includeDrafts,
103
108
  limit: 1000,
104
109
  overrideAccess
105
110
  }),
@@ -113,21 +118,26 @@ const findDocsSetByAiExportOutput = async ({ collections, output, overrideAccess
113
118
  doc,
114
119
  docsSet: toResolvedDocsSet(doc),
115
120
  groupsById
116
- })).find((docsSet)=>docsSet?.aiExport?.output === output);
121
+ })).find((docsSet)=>docsSet?.aiExport?.output === output && isVisibleDocsSet({
122
+ docsSet,
123
+ includeDrafts
124
+ }));
117
125
  };
118
- const findDocsSetForMarkdownRoute = async ({ collections, overrideAccess, payload, route })=>{
126
+ const findDocsSetForMarkdownRoute = async ({ collections, includeDrafts, overrideAccess, payload, route })=>{
119
127
  const routeBase = stripMarkdownRouteSuffix(route);
120
128
  if (!routeBase) {
121
129
  return undefined;
122
130
  }
123
131
  const docsSet = await findDocsSetByRouteBase({
124
132
  collections,
133
+ includeDrafts,
125
134
  overrideAccess,
126
135
  payload,
127
136
  routeBase
128
137
  });
129
138
  return docsSet ?? findDocsSetByAiExportOutput({
130
139
  collections,
140
+ includeDrafts,
131
141
  output: route,
132
142
  overrideAccess,
133
143
  payload
@@ -137,6 +147,7 @@ const getDocsRecords = async ({ collections, docsSet, includeDrafts, markdownFie
137
147
  const result = await payload.find({
138
148
  collection: collections.docs,
139
149
  depth: 0,
150
+ draft: includeDrafts,
140
151
  limit: 1000,
141
152
  overrideAccess,
142
153
  where: {
@@ -251,6 +262,7 @@ overrideAccess = true, path, payload })=>{
251
262
  const collections = resolveCollectionSlugs(collectionOptions);
252
263
  const docsSet = await findDocsSetForMarkdownRoute({
253
264
  collections,
265
+ includeDrafts,
254
266
  overrideAccess,
255
267
  payload,
256
268
  route
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/markdown.ts"],"sourcesContent":["import type {\n DocsAiExportManifest,\n DocsValidationIssue,\n} from '../sync/index.js'\nimport type {\n PayloadMarkdownDocsCollectionSlugs,\n PayloadMarkdownDocsReadPayload,\n ResolvedPayloadMarkdownDocsRecord,\n ResolvedPayloadMarkdownDocsSet,\n ResolvePayloadMarkdownDocsRouteOptions,\n} from './types.js'\n\nimport {\n DEFAULT_DOCS_COLLECTION_SLUG,\n DEFAULT_DOCS_GROUPS_COLLECTION_SLUG,\n DEFAULT_DOCS_SETS_COLLECTION_SLUG,\n DEFAULT_MARKDOWN_FIELD_NAME,\n} from '../constants.js'\nimport {\n deriveDocsSetRouteBase,\n joinRouteSegments,\n normalizeRoutePath,\n} from '../routing/index.js'\nimport {\n isExcludedFromAiExport,\n} from '../sync/index.js'\nimport {\n getRelationshipId,\n isRecord,\n isVisibleDocsRecord,\n toResolvedDocsGroup,\n toResolvedDocsRecord,\n toResolvedDocsSet,\n} from './records.js'\n\nexport type ResolvedPayloadMarkdownDocsMarkdownRoute = {\n contentType: 'text/markdown; charset=utf-8'\n docsSet: ResolvedPayloadMarkdownDocsSet\n markdown: string\n output: string\n route: string\n type: 'markdown'\n warnings: DocsValidationIssue[]\n}\n\nexport type ResolvePayloadMarkdownDocsMarkdownRouteOptions =\n ResolvePayloadMarkdownDocsRouteOptions\n\ntype ResolvedCollectionSlugs = {\n docs: string\n docsGroups: string\n docsSets: string\n}\n\nconst resolveCollectionSlugs = (\n collections?: PayloadMarkdownDocsCollectionSlugs,\n): ResolvedCollectionSlugs => ({\n docs: collections?.docs ?? DEFAULT_DOCS_COLLECTION_SLUG,\n docsGroups: collections?.docsGroups ?? DEFAULT_DOCS_GROUPS_COLLECTION_SLUG,\n docsSets: collections?.docsSets ?? DEFAULT_DOCS_SETS_COLLECTION_SLUG,\n})\n\nconst getRoutePath = ({\n slug,\n path,\n}: Pick<ResolvePayloadMarkdownDocsRouteOptions, 'path' | 'slug'>): string => {\n if (path !== undefined) {\n return normalizeRoutePath(path)\n }\n\n if (Array.isArray(slug)) {\n return normalizeRoutePath(slug.length === 0 ? '/' : slug.join('/'))\n }\n\n if (typeof slug === 'string') {\n return normalizeRoutePath(slug)\n }\n\n return '/'\n}\n\nconst stripMarkdownRouteSuffix = (route: string): string | undefined =>\n route.toLowerCase().endsWith('.md') ? route.slice(0, -3) : undefined\n\nconst getGroupsById = async ({\n collections,\n overrideAccess,\n payload,\n}: {\n collections: ResolvedCollectionSlugs\n overrideAccess: boolean\n payload: PayloadMarkdownDocsReadPayload\n}): Promise<Map<string, unknown>> => {\n const result = await payload.find({\n collection: collections.docsGroups,\n depth: 0,\n limit: 1000,\n overrideAccess,\n })\n\n return new Map(\n result.docs.flatMap((doc) => {\n if (!isRecord(doc)) {\n return []\n }\n\n const id = getRelationshipId(doc)\n\n return id ? [[id, doc]] : []\n }),\n )\n}\n\nconst getGroupRoutePath = ({\n groupId,\n groupsById,\n seen = new Set<string>(),\n}: {\n groupId?: string\n groupsById: Map<string, unknown>\n seen?: Set<string>\n}): string | undefined => {\n if (!groupId || seen.has(groupId)) {\n return undefined\n }\n\n const group = groupsById.get(groupId)\n const resolvedGroup = toResolvedDocsGroup(group)\n\n if (!resolvedGroup?.slug) {\n return undefined\n }\n\n const parentRoutePath = isRecord(group)\n ? getGroupRoutePath({\n groupId: getRelationshipId(group.parent),\n groupsById,\n seen: new Set([groupId, ...seen]),\n })\n : undefined\n\n return joinRouteSegments(parentRoutePath, resolvedGroup.slug)\n}\n\nconst withComputedDocsSetRoute = ({\n doc,\n docsSet,\n groupsById,\n}: {\n doc: unknown\n docsSet?: ResolvedPayloadMarkdownDocsSet\n groupsById: Map<string, unknown>\n}): ResolvedPayloadMarkdownDocsSet | undefined => {\n if (!docsSet?.slug) {\n return docsSet\n }\n\n const groupRoutePath = isRecord(doc)\n ? getGroupRoutePath({\n groupId: getRelationshipId(doc.group),\n groupsById,\n })\n : undefined\n\n return {\n ...docsSet,\n routeBase: deriveDocsSetRouteBase({\n docsSetSlug: docsSet.slug,\n groupRoutePath,\n }),\n }\n}\n\nconst findDocsSetByRouteBase = async ({\n collections,\n overrideAccess,\n payload,\n routeBase,\n}: {\n collections: ResolvedCollectionSlugs\n overrideAccess: boolean\n payload: PayloadMarkdownDocsReadPayload\n routeBase: string\n}): Promise<ResolvedPayloadMarkdownDocsSet | undefined> => {\n const [result, groupsById] = await Promise.all([\n payload.find({\n collection: collections.docsSets,\n depth: 0,\n limit: 1000,\n overrideAccess,\n }),\n getGroupsById({\n collections,\n overrideAccess,\n payload,\n }),\n ])\n\n return result.docs\n .map((doc) =>\n withComputedDocsSetRoute({\n doc,\n docsSet: toResolvedDocsSet(doc),\n groupsById,\n }),\n )\n .find((docsSet) => docsSet?.routeBase === routeBase)\n}\n\nconst findDocsSetByAiExportOutput = async ({\n collections,\n output,\n overrideAccess,\n payload,\n}: {\n collections: ResolvedCollectionSlugs\n output: string\n overrideAccess: boolean\n payload: PayloadMarkdownDocsReadPayload\n}): Promise<ResolvedPayloadMarkdownDocsSet | undefined> => {\n const [result, groupsById] = await Promise.all([\n payload.find({\n collection: collections.docsSets,\n depth: 0,\n limit: 1000,\n overrideAccess,\n }),\n getGroupsById({\n collections,\n overrideAccess,\n payload,\n }),\n ])\n\n return result.docs\n .map((doc) =>\n withComputedDocsSetRoute({\n doc,\n docsSet: toResolvedDocsSet(doc),\n groupsById,\n }),\n )\n .find((docsSet) => docsSet?.aiExport?.output === output)\n}\n\nconst findDocsSetForMarkdownRoute = async ({\n collections,\n overrideAccess,\n payload,\n route,\n}: {\n collections: ResolvedCollectionSlugs\n overrideAccess: boolean\n payload: PayloadMarkdownDocsReadPayload\n route: string\n}): Promise<ResolvedPayloadMarkdownDocsSet | undefined> => {\n const routeBase = stripMarkdownRouteSuffix(route)\n\n if (!routeBase) {\n return undefined\n }\n\n const docsSet = await findDocsSetByRouteBase({\n collections,\n overrideAccess,\n payload,\n routeBase,\n })\n\n return (\n docsSet ??\n findDocsSetByAiExportOutput({\n collections,\n output: route,\n overrideAccess,\n payload,\n })\n )\n}\n\nconst getDocsRecords = async ({\n collections,\n docsSet,\n includeDrafts,\n markdownField,\n overrideAccess,\n payload,\n}: {\n collections: ResolvedCollectionSlugs\n docsSet: ResolvedPayloadMarkdownDocsSet\n includeDrafts: boolean\n markdownField: string\n overrideAccess: boolean\n payload: PayloadMarkdownDocsReadPayload\n}): Promise<ResolvedPayloadMarkdownDocsRecord[]> => {\n const result = await payload.find({\n collection: collections.docs,\n depth: 0,\n limit: 1000,\n overrideAccess,\n where: {\n docsSet: {\n equals: docsSet.id,\n },\n },\n })\n\n return result.docs\n .map((doc) =>\n toResolvedDocsRecord({\n doc,\n markdownField,\n }),\n )\n .filter(\n (record): record is ResolvedPayloadMarkdownDocsRecord =>\n record !== undefined &&\n isVisibleDocsRecord({\n includeDrafts,\n record,\n }),\n )\n}\n\nconst compareDocsRecords = (\n first: ResolvedPayloadMarkdownDocsRecord,\n second: ResolvedPayloadMarkdownDocsRecord,\n): number => {\n if (first.order !== second.order) {\n return first.order - second.order\n }\n\n const titleCompare = first.title.localeCompare(second.title)\n\n if (titleCompare !== 0) {\n return titleCompare\n }\n\n const pathCompare = first.sourcePath.localeCompare(second.sourcePath)\n\n return pathCompare !== 0 ? pathCompare : first.id.localeCompare(second.id)\n}\n\nconst getDefaultAiExportManifest = (\n docsSet: ResolvedPayloadMarkdownDocsSet,\n): DocsAiExportManifest => ({\n canonical: docsSet.routeBase,\n exclude: [],\n headingMode: 'normalize',\n order: [],\n orphans: 'append',\n output: `${docsSet.routeBase}.md`,\n sourcePath: 'fallback',\n title: docsSet.title,\n version: 1,\n})\n\nconst orderDocsRecords = ({\n manifest,\n records,\n}: {\n manifest: DocsAiExportManifest\n records: ResolvedPayloadMarkdownDocsRecord[]\n}): {\n ordered: ResolvedPayloadMarkdownDocsRecord[]\n warnings: DocsValidationIssue[]\n} => {\n const recordsBySourcePath = new Map(records.map((record) => [record.sourcePath, record]))\n const listedRecords: ResolvedPayloadMarkdownDocsRecord[] = []\n const listedSourcePaths = new Set<string>()\n const warnings: DocsValidationIssue[] = []\n\n for (const orderedPath of manifest.order) {\n listedSourcePaths.add(orderedPath)\n const record = recordsBySourcePath.get(orderedPath)\n\n if (!record) {\n warnings.push({\n code: 'missing_ai_export_order_path',\n message: `AI export manifest order path \"${orderedPath}\" does not exist in the generated docs records.`,\n path: manifest.sourcePath,\n })\n continue\n }\n\n listedRecords.push(record)\n }\n\n if (manifest.orphans === 'ignore') {\n return {\n ordered: listedRecords,\n warnings,\n }\n }\n\n const orphans = records\n .filter((record) => !listedSourcePaths.has(record.sourcePath))\n .sort(compareDocsRecords)\n\n return {\n ordered: [...listedRecords, ...orphans],\n warnings,\n }\n}\n\nconst shiftMarkdownHeadings = (markdown: string): string =>\n markdown.replace(/^(#{1,6})(\\s+)/gm, (match, hashes: string, whitespace: string) =>\n hashes.length >= 5 ? `${'#'.repeat(6)}${whitespace}` : `${hashes}##${whitespace}`,\n )\n\nconst sectionTitle = (record: ResolvedPayloadMarkdownDocsRecord): string =>\n record.title.trim() || record.sourcePath\n\nconst renderMarkdownExport = ({\n docsSet,\n manifest,\n records,\n}: {\n docsSet: ResolvedPayloadMarkdownDocsSet\n manifest: DocsAiExportManifest\n records: ResolvedPayloadMarkdownDocsRecord[]\n}): string => {\n const lines: string[] = []\n const title = manifest.title ?? docsSet.title\n const canonical = manifest.canonical ?? docsSet.routeBase\n const output = manifest.output ?? `${docsSet.routeBase}.md`\n\n lines.push(`# ${title}`)\n lines.push('')\n lines.push(`Canonical: ${canonical}`)\n lines.push(`Output: ${output}`)\n\n if (manifest.description) {\n lines.push('', manifest.description.trim())\n }\n\n if (manifest.preamble) {\n lines.push('', manifest.preamble.trim())\n }\n\n for (const record of records) {\n const content = record.content?.trim()\n\n if (!content) {\n continue\n }\n\n if (manifest.headingMode === 'preserve') {\n lines.push('', content)\n continue\n }\n\n lines.push('', `## ${sectionTitle(record)}`, '', shiftMarkdownHeadings(content))\n }\n\n return `${lines.join('\\n').replace(/\\n{4,}/g, '\\n\\n\\n').trimEnd()}\\n`\n}\n\nexport const resolvePayloadMarkdownDocsMarkdownRoute = async ({\n slug,\n collections: collectionOptions,\n includeDrafts = false,\n markdownField = DEFAULT_MARKDOWN_FIELD_NAME,\n // Route adapter reads plugin-owned generated docs collections server-side.\n // Access is overridden here, then public visibility and manifest exclusions are enforced.\n overrideAccess = true,\n path,\n payload,\n}: ResolvePayloadMarkdownDocsMarkdownRouteOptions): Promise<\n null | ResolvedPayloadMarkdownDocsMarkdownRoute\n> => {\n const route = getRoutePath({\n slug,\n path,\n })\n const collections = resolveCollectionSlugs(collectionOptions)\n const docsSet = await findDocsSetForMarkdownRoute({\n collections,\n overrideAccess,\n payload,\n route,\n })\n\n if (!docsSet) {\n return null\n }\n\n const manifest = docsSet.aiExport ?? getDefaultAiExportManifest(docsSet)\n const records = (\n await getDocsRecords({\n collections,\n docsSet,\n includeDrafts,\n markdownField,\n overrideAccess,\n payload,\n })\n ).filter(\n (record) =>\n !isExcludedFromAiExport({\n exclude: manifest.exclude,\n sourcePath: record.sourcePath,\n }),\n )\n const ordered = orderDocsRecords({\n manifest,\n records,\n })\n\n return {\n type: 'markdown',\n contentType: 'text/markdown; charset=utf-8',\n docsSet,\n markdown: renderMarkdownExport({\n docsSet,\n manifest,\n records: ordered.ordered,\n }),\n output: manifest.output ?? `${docsSet.routeBase}.md`,\n route,\n warnings: ordered.warnings,\n }\n}\n\nexport const createPayloadMarkdownDocsMarkdownResponse = async (\n options: ResolvePayloadMarkdownDocsMarkdownRouteOptions,\n): Promise<null | Response> => {\n const resolved = await resolvePayloadMarkdownDocsMarkdownRoute(options)\n\n if (!resolved) {\n return null\n }\n\n return new Response(resolved.markdown, {\n headers: {\n 'Content-Type': resolved.contentType,\n },\n status: 200,\n })\n}\n"],"names":["DEFAULT_DOCS_COLLECTION_SLUG","DEFAULT_DOCS_GROUPS_COLLECTION_SLUG","DEFAULT_DOCS_SETS_COLLECTION_SLUG","DEFAULT_MARKDOWN_FIELD_NAME","deriveDocsSetRouteBase","joinRouteSegments","normalizeRoutePath","isExcludedFromAiExport","getRelationshipId","isRecord","isVisibleDocsRecord","toResolvedDocsGroup","toResolvedDocsRecord","toResolvedDocsSet","resolveCollectionSlugs","collections","docs","docsGroups","docsSets","getRoutePath","slug","path","undefined","Array","isArray","length","join","stripMarkdownRouteSuffix","route","toLowerCase","endsWith","slice","getGroupsById","overrideAccess","payload","result","find","collection","depth","limit","Map","flatMap","doc","id","getGroupRoutePath","groupId","groupsById","seen","Set","has","group","get","resolvedGroup","parentRoutePath","parent","withComputedDocsSetRoute","docsSet","groupRoutePath","routeBase","docsSetSlug","findDocsSetByRouteBase","Promise","all","map","findDocsSetByAiExportOutput","output","aiExport","findDocsSetForMarkdownRoute","getDocsRecords","includeDrafts","markdownField","where","equals","filter","record","compareDocsRecords","first","second","order","titleCompare","title","localeCompare","pathCompare","sourcePath","getDefaultAiExportManifest","canonical","exclude","headingMode","orphans","version","orderDocsRecords","manifest","records","recordsBySourcePath","listedRecords","listedSourcePaths","warnings","orderedPath","add","push","code","message","ordered","sort","shiftMarkdownHeadings","markdown","replace","match","hashes","whitespace","repeat","sectionTitle","trim","renderMarkdownExport","lines","description","preamble","content","trimEnd","resolvePayloadMarkdownDocsMarkdownRoute","collectionOptions","type","contentType","createPayloadMarkdownDocsMarkdownResponse","options","resolved","Response","headers","status"],"mappings":"AAYA,SACEA,4BAA4B,EAC5BC,mCAAmC,EACnCC,iCAAiC,EACjCC,2BAA2B,QACtB,kBAAiB;AACxB,SACEC,sBAAsB,EACtBC,iB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QAC1B;QACArC,QAAQ0B,SAAS1B,MAAM,IAAI,GAAGT,QAAQE,SAAS,CAAC,GAAG,CAAC;QACpD9B;QACAoE,UAAUM,QAAQN,QAAQ;IAC5B;AACF,EAAC;AAED,OAAO,MAAM2B,4CAA4C,OACvDC;IAEA,MAAMC,WAAW,MAAMN,wCAAwCK;IAE/D,IAAI,CAACC,UAAU;QACb,OAAO;IACT;IAEA,OAAO,IAAIC,SAASD,SAASpB,QAAQ,EAAE;QACrCsB,SAAS;YACP,gBAAgBF,SAASH,WAAW;QACtC;QACAM,QAAQ;IACV;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/next/markdown.ts"],"sourcesContent":["import type { DocsAiExportManifest, DocsValidationIssue } from '../sync/index.js'\nimport type {\n PayloadMarkdownDocsCollectionSlugs,\n PayloadMarkdownDocsReadPayload,\n ResolvedPayloadMarkdownDocsRecord,\n ResolvedPayloadMarkdownDocsSet,\n ResolvePayloadMarkdownDocsRouteOptions,\n} from './types.js'\n\nimport {\n DEFAULT_DOCS_COLLECTION_SLUG,\n DEFAULT_DOCS_GROUPS_COLLECTION_SLUG,\n DEFAULT_DOCS_SETS_COLLECTION_SLUG,\n DEFAULT_MARKDOWN_FIELD_NAME,\n} from '../constants.js'\nimport { deriveDocsSetRouteBase, joinRouteSegments, normalizeRoutePath } from '../routing/index.js'\nimport { isExcludedFromAiExport } from '../sync/index.js'\nimport {\n getRelationshipId,\n isRecord,\n isVisibleDocsRecord,\n isVisibleDocsSet,\n toResolvedDocsGroup,\n toResolvedDocsRecord,\n toResolvedDocsSet,\n} from './records.js'\n\nexport type ResolvedPayloadMarkdownDocsMarkdownRoute = {\n contentType: 'text/markdown; charset=utf-8'\n docsSet: ResolvedPayloadMarkdownDocsSet\n markdown: string\n output: string\n route: string\n type: 'markdown'\n warnings: DocsValidationIssue[]\n}\n\nexport type ResolvePayloadMarkdownDocsMarkdownRouteOptions = ResolvePayloadMarkdownDocsRouteOptions\n\ntype ResolvedCollectionSlugs = {\n docs: string\n docsGroups: string\n docsSets: string\n}\n\nconst resolveCollectionSlugs = (\n collections?: PayloadMarkdownDocsCollectionSlugs,\n): ResolvedCollectionSlugs => ({\n docs: collections?.docs ?? DEFAULT_DOCS_COLLECTION_SLUG,\n docsGroups: collections?.docsGroups ?? DEFAULT_DOCS_GROUPS_COLLECTION_SLUG,\n docsSets: collections?.docsSets ?? DEFAULT_DOCS_SETS_COLLECTION_SLUG,\n})\n\nconst getRoutePath = ({\n slug,\n path,\n}: Pick<ResolvePayloadMarkdownDocsRouteOptions, 'path' | 'slug'>): string => {\n if (path !== undefined) {\n return normalizeRoutePath(path)\n }\n\n if (Array.isArray(slug)) {\n return normalizeRoutePath(slug.length === 0 ? '/' : slug.join('/'))\n }\n\n if (typeof slug === 'string') {\n return normalizeRoutePath(slug)\n }\n\n return '/'\n}\n\nconst stripMarkdownRouteSuffix = (route: string): string | undefined =>\n route.toLowerCase().endsWith('.md') ? route.slice(0, -3) : undefined\n\nconst getGroupsById = async ({\n collections,\n overrideAccess,\n payload,\n}: {\n collections: ResolvedCollectionSlugs\n overrideAccess: boolean\n payload: PayloadMarkdownDocsReadPayload\n}): Promise<Map<string, unknown>> => {\n const result = await payload.find({\n collection: collections.docsGroups,\n depth: 0,\n limit: 1000,\n overrideAccess,\n })\n\n return new Map(\n result.docs.flatMap((doc) => {\n if (!isRecord(doc)) {\n return []\n }\n\n const id = getRelationshipId(doc)\n\n return id ? [[id, doc]] : []\n }),\n )\n}\n\nconst getGroupRoutePath = ({\n groupId,\n groupsById,\n seen = new Set<string>(),\n}: {\n groupId?: string\n groupsById: Map<string, unknown>\n seen?: Set<string>\n}): string | undefined => {\n if (!groupId || seen.has(groupId)) {\n return undefined\n }\n\n const group = groupsById.get(groupId)\n const resolvedGroup = toResolvedDocsGroup(group)\n\n if (!resolvedGroup?.slug) {\n return undefined\n }\n\n const parentRoutePath = isRecord(group)\n ? getGroupRoutePath({\n groupId: getRelationshipId(group.parent),\n groupsById,\n seen: new Set([groupId, ...seen]),\n })\n : undefined\n\n return joinRouteSegments(parentRoutePath, resolvedGroup.slug)\n}\n\nconst withComputedDocsSetRoute = ({\n doc,\n docsSet,\n groupsById,\n}: {\n doc: unknown\n docsSet?: ResolvedPayloadMarkdownDocsSet\n groupsById: Map<string, unknown>\n}): ResolvedPayloadMarkdownDocsSet | undefined => {\n if (!docsSet?.slug) {\n return docsSet\n }\n\n const groupRoutePath = isRecord(doc)\n ? getGroupRoutePath({\n groupId: getRelationshipId(doc.group),\n groupsById,\n })\n : undefined\n\n return {\n ...docsSet,\n routeBase: deriveDocsSetRouteBase({\n docsSetSlug: docsSet.slug,\n groupRoutePath,\n }),\n }\n}\n\nconst findDocsSetByRouteBase = async ({\n collections,\n includeDrafts,\n overrideAccess,\n payload,\n routeBase,\n}: {\n collections: ResolvedCollectionSlugs\n includeDrafts: boolean\n overrideAccess: boolean\n payload: PayloadMarkdownDocsReadPayload\n routeBase: string\n}): Promise<ResolvedPayloadMarkdownDocsSet | undefined> => {\n const [result, groupsById] = await Promise.all([\n payload.find({\n collection: collections.docsSets,\n depth: 0,\n draft: includeDrafts,\n limit: 1000,\n overrideAccess,\n }),\n getGroupsById({\n collections,\n overrideAccess,\n payload,\n }),\n ])\n\n return result.docs\n .map((doc) =>\n withComputedDocsSetRoute({\n doc,\n docsSet: toResolvedDocsSet(doc),\n groupsById,\n }),\n )\n .find(\n (docsSet) => docsSet?.routeBase === routeBase && isVisibleDocsSet({ docsSet, includeDrafts }),\n )\n}\n\nconst findDocsSetByAiExportOutput = async ({\n collections,\n includeDrafts,\n output,\n overrideAccess,\n payload,\n}: {\n collections: ResolvedCollectionSlugs\n includeDrafts: boolean\n output: string\n overrideAccess: boolean\n payload: PayloadMarkdownDocsReadPayload\n}): Promise<ResolvedPayloadMarkdownDocsSet | undefined> => {\n const [result, groupsById] = await Promise.all([\n payload.find({\n collection: collections.docsSets,\n depth: 0,\n draft: includeDrafts,\n limit: 1000,\n overrideAccess,\n }),\n getGroupsById({\n collections,\n overrideAccess,\n payload,\n }),\n ])\n\n return result.docs\n .map((doc) =>\n withComputedDocsSetRoute({\n doc,\n docsSet: toResolvedDocsSet(doc),\n groupsById,\n }),\n )\n .find(\n (docsSet) =>\n docsSet?.aiExport?.output === output && isVisibleDocsSet({ docsSet, includeDrafts }),\n )\n}\n\nconst findDocsSetForMarkdownRoute = async ({\n collections,\n includeDrafts,\n overrideAccess,\n payload,\n route,\n}: {\n collections: ResolvedCollectionSlugs\n includeDrafts: boolean\n overrideAccess: boolean\n payload: PayloadMarkdownDocsReadPayload\n route: string\n}): Promise<ResolvedPayloadMarkdownDocsSet | undefined> => {\n const routeBase = stripMarkdownRouteSuffix(route)\n\n if (!routeBase) {\n return undefined\n }\n\n const docsSet = await findDocsSetByRouteBase({\n collections,\n includeDrafts,\n overrideAccess,\n payload,\n routeBase,\n })\n\n return (\n docsSet ??\n findDocsSetByAiExportOutput({\n collections,\n includeDrafts,\n output: route,\n overrideAccess,\n payload,\n })\n )\n}\n\nconst getDocsRecords = async ({\n collections,\n docsSet,\n includeDrafts,\n markdownField,\n overrideAccess,\n payload,\n}: {\n collections: ResolvedCollectionSlugs\n docsSet: ResolvedPayloadMarkdownDocsSet\n includeDrafts: boolean\n markdownField: string\n overrideAccess: boolean\n payload: PayloadMarkdownDocsReadPayload\n}): Promise<ResolvedPayloadMarkdownDocsRecord[]> => {\n const result = await payload.find({\n collection: collections.docs,\n depth: 0,\n draft: includeDrafts,\n limit: 1000,\n overrideAccess,\n where: {\n docsSet: {\n equals: docsSet.id,\n },\n },\n })\n\n return result.docs\n .map((doc) =>\n toResolvedDocsRecord({\n doc,\n markdownField,\n }),\n )\n .filter(\n (record): record is ResolvedPayloadMarkdownDocsRecord =>\n record !== undefined &&\n isVisibleDocsRecord({\n includeDrafts,\n record,\n }),\n )\n}\n\nconst compareDocsRecords = (\n first: ResolvedPayloadMarkdownDocsRecord,\n second: ResolvedPayloadMarkdownDocsRecord,\n): number => {\n if (first.order !== second.order) {\n return first.order - second.order\n }\n\n const titleCompare = first.title.localeCompare(second.title)\n\n if (titleCompare !== 0) {\n return titleCompare\n }\n\n const pathCompare = first.sourcePath.localeCompare(second.sourcePath)\n\n return pathCompare !== 0 ? pathCompare : first.id.localeCompare(second.id)\n}\n\nconst getDefaultAiExportManifest = (\n docsSet: ResolvedPayloadMarkdownDocsSet,\n): DocsAiExportManifest => ({\n canonical: docsSet.routeBase,\n exclude: [],\n headingMode: 'normalize',\n order: [],\n orphans: 'append',\n output: `${docsSet.routeBase}.md`,\n sourcePath: 'fallback',\n title: docsSet.title,\n version: 1,\n})\n\nconst orderDocsRecords = ({\n manifest,\n records,\n}: {\n manifest: DocsAiExportManifest\n records: ResolvedPayloadMarkdownDocsRecord[]\n}): {\n ordered: ResolvedPayloadMarkdownDocsRecord[]\n warnings: DocsValidationIssue[]\n} => {\n const recordsBySourcePath = new Map(records.map((record) => [record.sourcePath, record]))\n const listedRecords: ResolvedPayloadMarkdownDocsRecord[] = []\n const listedSourcePaths = new Set<string>()\n const warnings: DocsValidationIssue[] = []\n\n for (const orderedPath of manifest.order) {\n listedSourcePaths.add(orderedPath)\n const record = recordsBySourcePath.get(orderedPath)\n\n if (!record) {\n warnings.push({\n code: 'missing_ai_export_order_path',\n message: `AI export manifest order path \"${orderedPath}\" does not exist in the generated docs records.`,\n path: manifest.sourcePath,\n })\n continue\n }\n\n listedRecords.push(record)\n }\n\n if (manifest.orphans === 'ignore') {\n return {\n ordered: listedRecords,\n warnings,\n }\n }\n\n const orphans = records\n .filter((record) => !listedSourcePaths.has(record.sourcePath))\n .sort(compareDocsRecords)\n\n return {\n ordered: [...listedRecords, ...orphans],\n warnings,\n }\n}\n\nconst shiftMarkdownHeadings = (markdown: string): string =>\n markdown.replace(/^(#{1,6})(\\s+)/gm, (match, hashes: string, whitespace: string) =>\n hashes.length >= 5 ? `${'#'.repeat(6)}${whitespace}` : `${hashes}##${whitespace}`,\n )\n\nconst sectionTitle = (record: ResolvedPayloadMarkdownDocsRecord): string =>\n record.title.trim() || record.sourcePath\n\nconst renderMarkdownExport = ({\n docsSet,\n manifest,\n records,\n}: {\n docsSet: ResolvedPayloadMarkdownDocsSet\n manifest: DocsAiExportManifest\n records: ResolvedPayloadMarkdownDocsRecord[]\n}): string => {\n const lines: string[] = []\n const title = manifest.title ?? docsSet.title\n const canonical = manifest.canonical ?? docsSet.routeBase\n const output = manifest.output ?? `${docsSet.routeBase}.md`\n\n lines.push(`# ${title}`)\n lines.push('')\n lines.push(`Canonical: ${canonical}`)\n lines.push(`Output: ${output}`)\n\n if (manifest.description) {\n lines.push('', manifest.description.trim())\n }\n\n if (manifest.preamble) {\n lines.push('', manifest.preamble.trim())\n }\n\n for (const record of records) {\n const content = record.content?.trim()\n\n if (!content) {\n continue\n }\n\n if (manifest.headingMode === 'preserve') {\n lines.push('', content)\n continue\n }\n\n lines.push('', `## ${sectionTitle(record)}`, '', shiftMarkdownHeadings(content))\n }\n\n return `${lines\n .join('\\n')\n .replace(/\\n{4,}/g, '\\n\\n\\n')\n .trimEnd()}\\n`\n}\n\nexport const resolvePayloadMarkdownDocsMarkdownRoute = async ({\n slug,\n collections: collectionOptions,\n includeDrafts = false,\n markdownField = DEFAULT_MARKDOWN_FIELD_NAME,\n // Route adapter reads plugin-owned generated docs collections server-side.\n // Access is overridden here, then public visibility and manifest exclusions are enforced.\n overrideAccess = true,\n path,\n payload,\n}: ResolvePayloadMarkdownDocsMarkdownRouteOptions): Promise<null | ResolvedPayloadMarkdownDocsMarkdownRoute> => {\n const route = getRoutePath({\n slug,\n path,\n })\n const collections = resolveCollectionSlugs(collectionOptions)\n const docsSet = await findDocsSetForMarkdownRoute({\n collections,\n includeDrafts,\n overrideAccess,\n payload,\n route,\n })\n\n if (!docsSet) {\n return null\n }\n\n const manifest = docsSet.aiExport ?? getDefaultAiExportManifest(docsSet)\n const records = (\n await getDocsRecords({\n collections,\n docsSet,\n includeDrafts,\n markdownField,\n overrideAccess,\n payload,\n })\n ).filter(\n (record) =>\n !isExcludedFromAiExport({\n exclude: manifest.exclude,\n sourcePath: record.sourcePath,\n }),\n )\n const ordered = orderDocsRecords({\n manifest,\n records,\n })\n\n return {\n type: 'markdown',\n contentType: 'text/markdown; charset=utf-8',\n docsSet,\n markdown: renderMarkdownExport({\n docsSet,\n manifest,\n records: ordered.ordered,\n }),\n output: manifest.output ?? `${docsSet.routeBase}.md`,\n route,\n warnings: ordered.warnings,\n }\n}\n\nexport const createPayloadMarkdownDocsMarkdownResponse = async (\n options: ResolvePayloadMarkdownDocsMarkdownRouteOptions,\n): Promise<null | Response> => {\n const resolved = await resolvePayloadMarkdownDocsMarkdownRoute(options)\n\n if (!resolved) {\n return null\n }\n\n return new Response(resolved.markdown, {\n headers: {\n 'Content-Type': resolved.contentType,\n },\n status: 200,\n })\n}\n"],"names":["DEFAULT_DOCS_COLLECTION_SLUG","DEFAULT_DOCS_GROUPS_COLLECTION_SLUG","DEFAULT_DOCS_SETS_COLLECTION_SLUG","DEFAULT_MARKDOWN_FIELD_NAME","deriveDocsSetRouteBase","joinRouteSegments","normalizeRoutePath","isExcludedFromAiExport","getRelationshipId","isRecord","isVisibleDocsRecord","isVisibleDocsSet","toResolvedDocsGroup","toResolvedDocsRecord","toResolvedDocsSet","resolveCollectionSlugs","collections","docs","docsGroups","docsSets","getRoutePath","slug","path","undefined","Array","isArray","length","join","stripMarkdownRouteSuffix","route","toLowerCase","endsWith","slice","getGroupsById","overrideAccess","payload","result","find","collection","depth","limit","Map","flatMap","doc","id","getGroupRoutePath","groupId","groupsById","seen","Set","has","group","get","resolvedGroup","parentRoutePath","parent","withComputedDocsSetRoute","docsSet","groupRoutePath","routeBase","docsSetSlug","findDocsSetByRouteBase","includeDrafts","Promise","all","draft","map","findDocsSetByAiExportOutput","output","aiExport","findDocsSetForMarkdownRoute","getDocsRecords","markdownField","where","equals","filter","record","compareDocsRecords","first","second","order","titleCompare","title","localeCompare","pathCompare","sourcePath","getDefaultAiExportManifest","canonical","exclude","headingMode","orphans","version","orderDocsRecords","manifest","records","recordsBySourcePath","listedRecords","listedSourcePaths","warnings","orderedPath","add","push","code","message","ordered","sort","shiftMarkdownHeadings","markdown","replace","match","hashes","whitespace","repeat","sectionTitle","trim","renderMarkdownExport","lines","description","preamble","content","trimEnd","resolvePayloadMarkdownDocsMarkdownRoute","collectionOptions","type","contentType","createPayloadMarkdownDocsMarkdownResponse","options","resolved","Response","headers","status"],"mappings":"AASA,SACEA,4BAA4B,EAC5BC,mCAAmC,EACnCC,iCAAiC,EACjCC,2BAA2B,QACtB,kBAAiB;AACxB,SAASC,sBAAsB,EAAEC,iBAAiB,EAAEC,kBAAkB,QAAQ,sBAAqB;AACnG,SAASC,sBAAsB,QAAQ,mBAAkB;AACzD,SACEC,iBAAiB,EACjBC,QAAQ,EACRC,mBAAmB,EACnBC,gBAAgB,EAChBC,mBAAmB,EACnBC,oBAAoB,EACpBC,iBAAiB,QACZ,eAAc;AAoBrB,MAAMC,yBAAyB,CAC7BC,cAC6B,CAAA;QAC7BC,MAAMD,aAAaC,QAAQjB;QAC3BkB,YAAYF,aAAaE,cAAcjB;QACvCkB,UAAUH,aAAaG,YAAYjB;IACrC,CAAA;AAEA,MAAMkB,eAAe,CAAC,EACpBC,IAAI,EACJC,IAAI,EAC0D;IAC9D,IAAIA,SAASC,WAAW;QACtB,OAAOjB,mBAAmBgB;IAC5B;IAEA,IAAIE,MAAMC,OAAO,CAACJ,OAAO;QACvB,OAAOf,mBAAmBe,KAAKK,MAAM,KAAK,IAAI,MAAML,KAAKM,IAAI,CAAC;IAChE;IAEA,IAAI,OAAON,SAAS,UAAU;QAC5B,OAAOf,mBAAmBe;IAC5B;IAEA,OAAO;AACT;AAEA,MAAMO,2BAA2B,CAACC,QAChCA,MAAMC,WAAW,GAAGC,QAAQ,CAAC,SAASF,MAAMG,KAAK,CAAC,GAAG,CAAC,KAAKT;AAE7D,MAAMU,gBAAgB,OAAO,EAC3BjB,WAAW,EACXkB,cAAc,EACdC,OAAO,EAKR;IACC,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;IACA,MAAMN,cAAcD,uBAAuB2G;IAC3C,MAAMjE,UAAU,MAAMa,4BAA4B;QAChDtD;QACA8C;QACA5B;QACAC;QACAN;IACF;IAEA,IAAI,CAAC4B,SAAS;QACZ,OAAO;IACT;IAEA,MAAMoC,WAAWpC,QAAQY,QAAQ,IAAIiB,2BAA2B7B;IAChE,MAAMqC,UAAU,AACd,CAAA,MAAMvB,eAAe;QACnBvD;QACAyC;QACAK;QACAU;QACAtC;QACAC;IACF,EAAC,EACDwC,MAAM,CACN,CAACC,SACC,CAACrE,uBAAuB;YACtBiF,SAASK,SAASL,OAAO;YACzBH,YAAYT,OAAOS,UAAU;QAC/B;IAEJ,MAAMmB,UAAUZ,iBAAiB;QAC/BC;QACAC;IACF;IAEA,OAAO;QACL6B,MAAM;QACNC,aAAa;QACbnE;QACAkD,UAAUQ,qBAAqB;YAC7B1D;YACAoC;YACAC,SAASU,QAAQA,OAAO;QAC1B;QACApC,QAAQyB,SAASzB,MAAM,IAAI,GAAGX,QAAQE,SAAS,CAAC,GAAG,CAAC;QACpD9B;QACAqE,UAAUM,QAAQN,QAAQ;IAC5B;AACF,EAAC;AAED,OAAO,MAAM2B,4CAA4C,OACvDC;IAEA,MAAMC,WAAW,MAAMN,wCAAwCK;IAE/D,IAAI,CAACC,UAAU;QACb,OAAO;IACT;IAEA,OAAO,IAAIC,SAASD,SAASpB,QAAQ,EAAE;QACrCsB,SAAS;YACP,gBAAgBF,SAASH,WAAW;QACtC;QACAM,QAAQ;IACV;AACF,EAAC"}
@@ -83,6 +83,7 @@ const findDocsSetById = async ({ id, collections, includeDrafts, overrideAccess,
83
83
  payload.find({
84
84
  collection: collections.docsSets,
85
85
  depth: 0,
86
+ draft: includeDrafts,
86
87
  limit: 1,
87
88
  overrideAccess,
88
89
  where: {
@@ -112,6 +113,7 @@ const findDocsSetByRouteBase = async ({ collections, includeDrafts, overrideAcce
112
113
  payload.find({
113
114
  collection: collections.docsSets,
114
115
  depth: 0,
116
+ draft: includeDrafts,
115
117
  limit: 1000,
116
118
  overrideAccess
117
119
  }),
@@ -135,6 +137,7 @@ const findDocsSetByRoutePrefix = async ({ collections, includeDrafts, overrideAc
135
137
  payload.find({
136
138
  collection: collections.docsSets,
137
139
  depth: 0,
140
+ draft: includeDrafts,
138
141
  limit: 1000,
139
142
  overrideAccess
140
143
  }),
@@ -196,6 +199,7 @@ const findDocsRecordByRoute = async ({ collections, includeDrafts, markdownField
196
199
  const result = await payload.find({
197
200
  collection: collections.docs,
198
201
  depth: 1,
202
+ draft: includeDrafts,
199
203
  limit: 5,
200
204
  overrideAccess,
201
205
  where: {
@@ -269,6 +273,7 @@ const findGroupIndexRoute = async ({ collections, includeDrafts, overrideAccess,
269
273
  const docsSetsResult = await payload.find({
270
274
  collection: collections.docsSets,
271
275
  depth: 0,
276
+ draft: includeDrafts,
272
277
  limit: 1000,
273
278
  overrideAccess
274
279
  });