@tearleads/client-sdk 0.1.240 → 0.1.242

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.
Files changed (54) hide show
  1. package/data/documents/shared/sync/syncResponseAuthorization.js +12 -1
  2. package/data/documents/shared/sync/syncResponseAuthorization.js.map +1 -1
  3. package/data/documents/shared/sync/syncResponses.js +2 -2
  4. package/data/documents/shared/sync/syncResponses.js.map +1 -1
  5. package/data/keyingProjectionVerification/checkpoints/checkpointContext.js +12 -3
  6. package/data/keyingProjectionVerification/checkpoints/checkpointContext.js.map +1 -1
  7. package/data/keyingProjectionVerification/checkpoints/verifiedBundleBytes.js +73 -8
  8. package/data/keyingProjectionVerification/checkpoints/verifiedBundleBytes.js.map +1 -1
  9. package/data/keyingProjectionVerification/container/containerAncestorCitations.js +20 -4
  10. package/data/keyingProjectionVerification/container/containerAncestorCitations.js.map +1 -1
  11. package/data/keyingProjectionVerification/container/containerManifestVerification.js +43 -32
  12. package/data/keyingProjectionVerification/container/containerManifestVerification.js.map +1 -1
  13. package/data/keyingProjectionVerification/container/containerSignedParentReference.js +129 -0
  14. package/data/keyingProjectionVerification/container/containerSignedParentReference.js.map +1 -0
  15. package/data/keyingProjectionVerification/document/documentManifestVerification.js +28 -7
  16. package/data/keyingProjectionVerification/document/documentManifestVerification.js.map +1 -1
  17. package/data/persistence/verifiedCitations/bundleCitationRows.js.map +1 -1
  18. package/data/persistence/verifiedCitations/citationCollection.js +2 -2
  19. package/data/persistence/verifiedCitations/citationCollection.js.map +1 -1
  20. package/data/persistence/verifiedManifestBundlePersistence.d.ts +3 -2
  21. package/data/persistence/verifiedManifestBundlePersistence.js +1 -1
  22. package/data/persistence/verifiedManifestBundlePersistence.js.map +1 -1
  23. package/internal/api-client/ApiClient.d.ts +7 -7
  24. package/internal/api-client/client/apiClientContext.d.ts +1 -1
  25. package/internal/api-client/client/blobs.d.ts +1 -1
  26. package/internal/api-client/client/documents.d.ts +6 -6
  27. package/internal/api-client/verifiedManifestCitations.d.ts +4 -3
  28. package/internal/api-client/verifiedManifestCitations.js +3 -3
  29. package/internal/api-client/verifiedManifestCitations.js.map +1 -1
  30. package/internal/validators/operation/attachments.d.ts +2 -2
  31. package/internal/validators/operation/documentSync.d.ts +24 -24
  32. package/internal/validators/operation/writerProjections.d.ts +8 -8
  33. package/internal/validators/response/blob.d.ts +6 -6
  34. package/internal/validators/response/blob.js +12 -2
  35. package/internal/validators/response/blob.js.map +1 -1
  36. package/internal/validators/response/container.d.ts +4 -4
  37. package/internal/validators/response/documentMutation.d.ts +4 -4
  38. package/internal/validators/response/documentSyncSchema.d.ts +48 -48
  39. package/internal/validators/response/documentSyncSchema.js +1 -1
  40. package/internal/validators/response/documentSyncSchema.js.map +1 -1
  41. package/internal/validators/response/manifestBundleReferences.js +4 -3
  42. package/internal/validators/response/manifestBundleReferences.js.map +1 -1
  43. package/internal/validators/response/writerProjectionWire.d.ts +4 -4
  44. package/internal/validators/response/writerProjectionWire.js +8 -5
  45. package/internal/validators/response/writerProjectionWire.js.map +1 -1
  46. package/internal/validators/util/index.d.ts +1 -0
  47. package/internal/validators/util/index.js +1 -0
  48. package/internal/validators/util/index.js.map +1 -1
  49. package/internal/validators/util/servedManifestBundle.d.ts +71 -0
  50. package/internal/validators/util/servedManifestBundle.js +100 -0
  51. package/internal/validators/util/servedManifestBundle.js.map +1 -0
  52. package/package.json +1 -1
  53. package/workflows/blobs/hydration/decrypt.js +17 -1
  54. package/workflows/blobs/hydration/decrypt.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"blob.js","sourceRoot":"","sources":["blob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,mCAAmC,EAAE,MAAM,SAAS,CAAC;AAC9D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;AACxE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,KAAc;IAEd,OAAO,qCAAqC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,KAAc;IAEd,OAAO,gCAAgC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC5C,KAAc;IAEd,OAAO,kCAAkC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACrE,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n arraySchema,\n loosePlainObject,\n nonEmptyStringSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n} from \"../schema\";\nimport { AccessEventBundleWireResponseSchema } from \"../util\";\nimport { MultipartBlobPartUploadSchema } from \"../util/blobTransferSchemas\";\nimport { DocumentCreateSeedResponseSchema } from \"./documentMutation\";\n\nexport const MultipartBlobStagePartSchema = loosePlainObject({\n byteLength: positiveIntegerSchema,\n etag: nonEmptyStringSchema,\n partNumber: positiveIntegerSchema,\n});\n\nexport type MultipartBlobStagePart = z.infer<\n typeof MultipartBlobStagePartSchema\n>;\n\nexport const InitiateMultipartBlobStageResponseSchema = loosePlainObject({\n organizationId: nonEmptyStringSchema,\n byteLength: positiveIntegerSchema,\n expiresAt: z.string(),\n // One upload source per requested first part, in request order.\n partUploads: arraySchema(MultipartBlobPartUploadSchema),\n sha256: nonEmptyStringSchema,\n stageId: z.string(),\n uploadedParts: arraySchema(MultipartBlobStagePartSchema),\n uploadId: z.string(),\n});\n\nexport type InitiateMultipartBlobStageResponse = z.infer<\n typeof InitiateMultipartBlobStageResponseSchema\n>;\n\nexport const MultipartBlobStageStatusResponseSchema = loosePlainObject({\n organizationId: nonEmptyStringSchema,\n byteLength: positiveIntegerSchema,\n completed: z.boolean(),\n expiresAt: z.string(),\n sha256: nonEmptyStringSchema,\n stageId: z.string(),\n uploadedParts: arraySchema(MultipartBlobStagePartSchema),\n uploadId: z.string(),\n});\n\nexport type MultipartBlobStageStatusResponse = z.infer<\n typeof MultipartBlobStageStatusResponseSchema\n>;\n\nexport const UploadMultipartBlobPartResponseSchema = loosePlainObject({\n part: MultipartBlobStagePartSchema,\n stageId: z.string(),\n uploadId: z.string(),\n});\n\nexport type UploadMultipartBlobPartResponse = z.infer<\n typeof UploadMultipartBlobPartResponseSchema\n>;\n\nexport const BlobContentKeyTargetEnvelopeResponseSchema = loosePlainObject({\n bindingId: z.string(),\n containerId: z.string(),\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: z.string(),\n containerManifestHash: z.string(),\n documentId: z.string(),\n wrappedKey: z.string(),\n wrappingMetadata: plainObjectSchema,\n});\n\nexport type BlobContentKeyTargetEnvelopeResponse = z.infer<\n typeof BlobContentKeyTargetEnvelopeResponseSchema\n>;\n\nexport const BlobContentKeyBundleResponseSchema = loosePlainObject({\n blobId: z.string(),\n contentKeyEpoch: positiveIntegerSchema,\n targetHash: z.string(),\n targets: arraySchema(BlobContentKeyTargetEnvelopeResponseSchema),\n});\n\nexport type BlobContentKeyBundleResponse = z.infer<\n typeof BlobContentKeyBundleResponseSchema\n>;\n\nexport const BlobKekTargetsResponseSchema = loosePlainObject({\n activeBindingIds: arraySchema(z.string()),\n blobAccessManifestHash: z.string(),\n blobId: z.string(),\n blobKeyTargetHash: z.string(),\n documentManifestHashes: arraySchema(z.string()),\n linkedContainerKeyEpochIds: arraySchema(z.string()),\n linkedContainerManifestHashes: arraySchema(z.string()),\n organizationId: z.string(),\n targets: arraySchema(plainObjectSchema),\n});\n\nexport type BlobKekTargetsResponse = z.infer<\n typeof BlobKekTargetsResponseSchema\n>;\n\nexport const BlobAttachmentSummarySchema = loosePlainObject({\n bindingEvent: AccessEventBundleWireResponseSchema,\n bindingId: z.string(),\n blobId: z.string(),\n blobKekTargets: BlobKekTargetsResponseSchema,\n contentKeyBundle: BlobContentKeyBundleResponseSchema,\n documentManifestHash: z.string(),\n previousBindingId: z.string().nullable(),\n slotId: z.string(),\n writeAuthorization: BlobKekTargetsResponseSchema,\n writeHeader: plainObjectSchema,\n});\n\nexport type BlobAttachmentSummary = z.infer<typeof BlobAttachmentSummarySchema>;\n\nexport const ListDocumentAttachmentsResponseSchema = arraySchema(\n BlobAttachmentSummarySchema,\n);\n\nexport type ListDocumentAttachmentsResponse = z.infer<\n typeof ListDocumentAttachmentsResponseSchema\n>;\n\n/**\n * A bind acknowledges by hash: the signed binding event's hash, the stored\n * content-key epoch, the verified write header's hash, and the hashes of the\n * server-resolved KEK target set and blob access manifest. It never echoes the\n * signed event, the content-key wraps, the write header, the KEK targets, or\n * the write authorization (which a staged upload's bind stores as exactly the\n * targets it wrapped to); the client compares each with what it signed.\n */\nexport const BlobAttachmentBindResponseSchema = loosePlainObject({\n bindingId: z.string(),\n blobAccessManifestHash: nonEmptyStringSchema,\n blobId: z.string(),\n blobKeyTargetHash: nonEmptyStringSchema,\n contentKeyEpoch: positiveIntegerSchema,\n documentId: z.string(),\n documentManifestHash: z.string(),\n eventHash: nonEmptyStringSchema,\n previousBindingId: z.string().nullable(),\n slotId: z.string(),\n writeHeaderHash: z.string(),\n /** Present exactly when the request carried `documentSync`. */\n documentSync: DocumentCreateSeedResponseSchema.optional(),\n});\n\nexport type BlobAttachmentBindResponse = z.infer<\n typeof BlobAttachmentBindResponseSchema\n>;\n\nfunction sortedUniqueStrings(values: readonly string[]): string[] {\n return [...new Set(values)].sort((left, right) =>\n left < right ? -1 : left > right ? 1 : 0,\n );\n}\n\n/**\n * The listing entry a staged upload's bind committed, rebuilt from the\n * request it acknowledged: the bind stores exactly the signed event,\n * content-key bundle, and write header the request carried, and a staged\n * blob is new, so this binding is its only one and its KEK targets and write\n * authorization are exactly the targets the bundle wraps to. Callers must\n * first have matched the acknowledgement's hashes against that request.\n */\nexport function blobAttachmentSummaryFromStagedBind(\n request: {\n readonly body: unknown;\n readonly contentKeyBundle: {\n readonly targetHash: string;\n readonly targets: readonly BlobContentKeyTargetEnvelopeResponse[];\n };\n readonly event: Record<string, unknown>;\n readonly stagedBlob: { readonly writeHeader: Record<string, unknown> };\n },\n response: BlobAttachmentBindResponse,\n): BlobAttachmentSummary {\n const { organizationId } = request.event;\n if (typeof organizationId !== \"string\") {\n throw new Error(\"Attachment bind event organization id is invalid\");\n }\n const targets = request.contentKeyBundle.targets.map((target) => ({\n bindingId: target.bindingId,\n containerId: target.containerId,\n containerKeyEpoch: target.containerKeyEpoch,\n containerKeyEpochId: target.containerKeyEpochId,\n containerManifestHash: target.containerManifestHash,\n documentId: target.documentId,\n }));\n const blobKekTargets: BlobKekTargetsResponse = {\n activeBindingIds: [response.bindingId],\n blobAccessManifestHash: response.blobAccessManifestHash,\n blobId: response.blobId,\n blobKeyTargetHash: response.blobKeyTargetHash,\n documentManifestHashes: [response.documentManifestHash],\n linkedContainerKeyEpochIds: sortedUniqueStrings(\n targets.map((target) => target.containerKeyEpochId),\n ),\n linkedContainerManifestHashes: sortedUniqueStrings(\n targets.map((target) => target.containerManifestHash),\n ),\n organizationId,\n targets,\n };\n return {\n bindingEvent: {\n body: request.body,\n event: request.event,\n eventHash: response.eventHash,\n },\n bindingId: response.bindingId,\n blobId: response.blobId,\n blobKekTargets,\n contentKeyBundle: {\n blobId: response.blobId,\n contentKeyEpoch: response.contentKeyEpoch,\n targetHash: request.contentKeyBundle.targetHash,\n targets: [...request.contentKeyBundle.targets],\n },\n documentManifestHash: response.documentManifestHash,\n previousBindingId: response.previousBindingId,\n slotId: response.slotId,\n writeAuthorization: blobKekTargets,\n writeHeader: request.stagedBlob.writeHeader,\n };\n}\n\nexport const BlobAttachmentDetachResponseSchema = loosePlainObject({\n bindingId: z.string(),\n blobId: z.string(),\n documentId: z.string(),\n slotId: z.string(),\n});\n\nexport type BlobAttachmentDetachResponse = z.infer<\n typeof BlobAttachmentDetachResponseSchema\n>;\n\nexport function isInitiateMultipartBlobStageResponse(\n value: unknown,\n): value is InitiateMultipartBlobStageResponse {\n return InitiateMultipartBlobStageResponseSchema.safeParse(value).success;\n}\n\nexport function isMultipartBlobStageStatusResponse(\n value: unknown,\n): value is MultipartBlobStageStatusResponse {\n return MultipartBlobStageStatusResponseSchema.safeParse(value).success;\n}\n\nexport function isUploadMultipartBlobPartResponse(\n value: unknown,\n): value is UploadMultipartBlobPartResponse {\n return UploadMultipartBlobPartResponseSchema.safeParse(value).success;\n}\n\nexport function isListDocumentAttachmentsResponse(\n value: unknown,\n): value is ListDocumentAttachmentsResponse {\n return ListDocumentAttachmentsResponseSchema.safeParse(value).success;\n}\n\nexport function isBlobAttachmentBindResponse(\n value: unknown,\n): value is BlobAttachmentBindResponse {\n return BlobAttachmentBindResponseSchema.safeParse(value).success;\n}\n\nexport function isBlobAttachmentDetachResponse(\n value: unknown,\n): value is BlobAttachmentDetachResponse {\n return BlobAttachmentDetachResponseSchema.safeParse(value).success;\n}\n"]}
1
+ {"version":3,"file":"blob.js","sourceRoot":"","sources":["blob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,mCAAmC,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,6BAA6B,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AAEtE,MAAM,CAAC,MAAM,4BAA4B,GAAG,gBAAgB,CAAC;IAC3D,UAAU,EAAE,qBAAqB;IACjC,IAAI,EAAE,oBAAoB;IAC1B,UAAU,EAAE,qBAAqB;CAClC,CAAC,CAAC;AAMH,MAAM,CAAC,MAAM,wCAAwC,GAAG,gBAAgB,CAAC;IACvE,cAAc,EAAE,oBAAoB;IACpC,UAAU,EAAE,qBAAqB;IACjC,SAAS,EAAE,CAAC,CAAC,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CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC5C,KAAc;IAEd,OAAO,kCAAkC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACrE,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n arraySchema,\n loosePlainObject,\n nonEmptyStringSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n} from \"../schema\";\nimport { AccessEventBundleWireResponseSchema } from \"../util\";\nimport { MultipartBlobPartUploadSchema } from \"../util/blobTransferSchemas\";\nimport { DocumentCreateSeedResponseSchema } from \"./documentMutation\";\n\nexport const MultipartBlobStagePartSchema = loosePlainObject({\n byteLength: positiveIntegerSchema,\n etag: nonEmptyStringSchema,\n partNumber: positiveIntegerSchema,\n});\n\nexport type MultipartBlobStagePart = z.infer<\n typeof MultipartBlobStagePartSchema\n>;\n\nexport const InitiateMultipartBlobStageResponseSchema = loosePlainObject({\n organizationId: nonEmptyStringSchema,\n byteLength: positiveIntegerSchema,\n expiresAt: z.string(),\n // One upload source per requested first part, in request order.\n partUploads: arraySchema(MultipartBlobPartUploadSchema),\n sha256: nonEmptyStringSchema,\n stageId: z.string(),\n uploadedParts: arraySchema(MultipartBlobStagePartSchema),\n uploadId: z.string(),\n});\n\nexport type InitiateMultipartBlobStageResponse = z.infer<\n typeof InitiateMultipartBlobStageResponseSchema\n>;\n\nexport const MultipartBlobStageStatusResponseSchema = loosePlainObject({\n organizationId: nonEmptyStringSchema,\n byteLength: positiveIntegerSchema,\n completed: z.boolean(),\n expiresAt: z.string(),\n sha256: nonEmptyStringSchema,\n stageId: z.string(),\n uploadedParts: arraySchema(MultipartBlobStagePartSchema),\n uploadId: z.string(),\n});\n\nexport type MultipartBlobStageStatusResponse = z.infer<\n typeof MultipartBlobStageStatusResponseSchema\n>;\n\nexport const UploadMultipartBlobPartResponseSchema = loosePlainObject({\n part: MultipartBlobStagePartSchema,\n stageId: z.string(),\n uploadId: z.string(),\n});\n\nexport type UploadMultipartBlobPartResponse = z.infer<\n typeof UploadMultipartBlobPartResponseSchema\n>;\n\nexport const BlobContentKeyTargetEnvelopeResponseSchema = loosePlainObject({\n bindingId: z.string(),\n containerId: z.string(),\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: z.string(),\n containerManifestHash: z.string(),\n documentId: z.string(),\n wrappedKey: z.string(),\n wrappingMetadata: plainObjectSchema,\n});\n\nexport type BlobContentKeyTargetEnvelopeResponse = z.infer<\n typeof BlobContentKeyTargetEnvelopeResponseSchema\n>;\n\nexport const BlobContentKeyBundleResponseSchema = loosePlainObject({\n blobId: z.string(),\n contentKeyEpoch: positiveIntegerSchema,\n targetHash: z.string(),\n targets: arraySchema(BlobContentKeyTargetEnvelopeResponseSchema),\n});\n\nexport type BlobContentKeyBundleResponse = z.infer<\n typeof BlobContentKeyBundleResponseSchema\n>;\n\nconst blobKekTargetsShape = {\n activeBindingIds: arraySchema(z.string()),\n blobAccessManifestHash: z.string(),\n blobId: z.string(),\n blobKeyTargetHash: z.string(),\n documentManifestHashes: arraySchema(z.string()),\n linkedContainerKeyEpochIds: arraySchema(z.string()),\n linkedContainerManifestHashes: arraySchema(z.string()),\n organizationId: z.string(),\n targets: arraySchema(plainObjectSchema),\n};\n\nexport const BlobKekTargetsResponseSchema =\n loosePlainObject(blobKekTargetsShape);\n\nexport type BlobKekTargetsResponse = z.infer<\n typeof BlobKekTargetsResponseSchema\n>;\n\n/**\n * The target set a blob's write was authorized against. `targets` is omitted\n * when `blobKeyTargetHash` equals the listing's current `blobKekTargets`\n * hash: the reader refills it from that set and re-hashes it.\n */\nconst BlobWriteAuthorizationResponseSchema = loosePlainObject({\n ...blobKekTargetsShape,\n targets: arraySchema(plainObjectSchema).optional(),\n});\n\nexport const BlobAttachmentSummarySchema = loosePlainObject({\n bindingEvent: AccessEventBundleWireResponseSchema,\n bindingId: z.string(),\n blobId: z.string(),\n blobKekTargets: BlobKekTargetsResponseSchema,\n contentKeyBundle: BlobContentKeyBundleResponseSchema,\n documentManifestHash: z.string(),\n previousBindingId: z.string().nullable(),\n slotId: z.string(),\n writeAuthorization: BlobWriteAuthorizationResponseSchema,\n writeHeader: plainObjectSchema,\n});\n\nexport type BlobAttachmentSummary = z.infer<typeof BlobAttachmentSummarySchema>;\n\nexport const ListDocumentAttachmentsResponseSchema = arraySchema(\n BlobAttachmentSummarySchema,\n);\n\nexport type ListDocumentAttachmentsResponse = z.infer<\n typeof ListDocumentAttachmentsResponseSchema\n>;\n\n/**\n * A bind acknowledges by hash: the signed binding event's hash, the stored\n * content-key epoch, the verified write header's hash, and the hashes of the\n * server-resolved KEK target set and blob access manifest. It never echoes the\n * signed event, the content-key wraps, the write header, the KEK targets, or\n * the write authorization (which a staged upload's bind stores as exactly the\n * targets it wrapped to); the client compares each with what it signed.\n */\nexport const BlobAttachmentBindResponseSchema = loosePlainObject({\n bindingId: z.string(),\n blobAccessManifestHash: nonEmptyStringSchema,\n blobId: z.string(),\n blobKeyTargetHash: nonEmptyStringSchema,\n contentKeyEpoch: positiveIntegerSchema,\n documentId: z.string(),\n documentManifestHash: z.string(),\n eventHash: nonEmptyStringSchema,\n previousBindingId: z.string().nullable(),\n slotId: z.string(),\n writeHeaderHash: z.string(),\n /** Present exactly when the request carried `documentSync`. */\n documentSync: DocumentCreateSeedResponseSchema.optional(),\n});\n\nexport type BlobAttachmentBindResponse = z.infer<\n typeof BlobAttachmentBindResponseSchema\n>;\n\nfunction sortedUniqueStrings(values: readonly string[]): string[] {\n return [...new Set(values)].sort((left, right) =>\n left < right ? -1 : left > right ? 1 : 0,\n );\n}\n\n/**\n * The listing entry a staged upload's bind committed, rebuilt from the\n * request it acknowledged: the bind stores exactly the signed event,\n * content-key bundle, and write header the request carried, and a staged\n * blob is new, so this binding is its only one and its KEK targets and write\n * authorization are exactly the targets the bundle wraps to. Callers must\n * first have matched the acknowledgement's hashes against that request.\n */\nexport function blobAttachmentSummaryFromStagedBind(\n request: {\n readonly body: unknown;\n readonly contentKeyBundle: {\n readonly targetHash: string;\n readonly targets: readonly BlobContentKeyTargetEnvelopeResponse[];\n };\n readonly event: Record<string, unknown>;\n readonly stagedBlob: { readonly writeHeader: Record<string, unknown> };\n },\n response: BlobAttachmentBindResponse,\n): BlobAttachmentSummary {\n const { organizationId } = request.event;\n if (typeof organizationId !== \"string\") {\n throw new Error(\"Attachment bind event organization id is invalid\");\n }\n const targets = request.contentKeyBundle.targets.map((target) => ({\n bindingId: target.bindingId,\n containerId: target.containerId,\n containerKeyEpoch: target.containerKeyEpoch,\n containerKeyEpochId: target.containerKeyEpochId,\n containerManifestHash: target.containerManifestHash,\n documentId: target.documentId,\n }));\n const blobKekTargets: BlobKekTargetsResponse = {\n activeBindingIds: [response.bindingId],\n blobAccessManifestHash: response.blobAccessManifestHash,\n blobId: response.blobId,\n blobKeyTargetHash: response.blobKeyTargetHash,\n documentManifestHashes: [response.documentManifestHash],\n linkedContainerKeyEpochIds: sortedUniqueStrings(\n targets.map((target) => target.containerKeyEpochId),\n ),\n linkedContainerManifestHashes: sortedUniqueStrings(\n targets.map((target) => target.containerManifestHash),\n ),\n organizationId,\n targets,\n };\n return {\n bindingEvent: {\n body: request.body,\n event: request.event,\n eventHash: response.eventHash,\n },\n bindingId: response.bindingId,\n blobId: response.blobId,\n blobKekTargets,\n contentKeyBundle: {\n blobId: response.blobId,\n contentKeyEpoch: response.contentKeyEpoch,\n targetHash: request.contentKeyBundle.targetHash,\n targets: [...request.contentKeyBundle.targets],\n },\n documentManifestHash: response.documentManifestHash,\n previousBindingId: response.previousBindingId,\n slotId: response.slotId,\n writeAuthorization: blobKekTargets,\n writeHeader: request.stagedBlob.writeHeader,\n };\n}\n\nexport const BlobAttachmentDetachResponseSchema = loosePlainObject({\n bindingId: z.string(),\n blobId: z.string(),\n documentId: z.string(),\n slotId: z.string(),\n});\n\nexport type BlobAttachmentDetachResponse = z.infer<\n typeof BlobAttachmentDetachResponseSchema\n>;\n\nexport function isInitiateMultipartBlobStageResponse(\n value: unknown,\n): value is InitiateMultipartBlobStageResponse {\n return InitiateMultipartBlobStageResponseSchema.safeParse(value).success;\n}\n\nexport function isMultipartBlobStageStatusResponse(\n value: unknown,\n): value is MultipartBlobStageStatusResponse {\n return MultipartBlobStageStatusResponseSchema.safeParse(value).success;\n}\n\nexport function isUploadMultipartBlobPartResponse(\n value: unknown,\n): value is UploadMultipartBlobPartResponse {\n return UploadMultipartBlobPartResponseSchema.safeParse(value).success;\n}\n\nexport function isListDocumentAttachmentsResponse(\n value: unknown,\n): value is ListDocumentAttachmentsResponse {\n return ListDocumentAttachmentsResponseSchema.safeParse(value).success;\n}\n\nexport function isBlobAttachmentBindResponse(\n value: unknown,\n): value is BlobAttachmentBindResponse {\n return BlobAttachmentBindResponseSchema.safeParse(value).success;\n}\n\nexport function isBlobAttachmentDetachResponse(\n value: unknown,\n): value is BlobAttachmentDetachResponse {\n return BlobAttachmentDetachResponseSchema.safeParse(value).success;\n}\n"]}
@@ -1445,7 +1445,7 @@ export declare const ContainerWriterProjectionWireResponseSchema: z.ZodType<{
1445
1445
  };
1446
1446
  manifest: Record<string, unknown>;
1447
1447
  manifestHash: string;
1448
- state: Record<string, unknown>;
1448
+ state: import("../util/index.js").ServedManifestState;
1449
1449
  }>;
1450
1450
  omittedBundles: string[];
1451
1451
  }, {
@@ -1527,7 +1527,7 @@ export declare const ContainerWriterProjectionWireResponseSchema: z.ZodType<{
1527
1527
  };
1528
1528
  manifest: Record<string, unknown>;
1529
1529
  manifestHash: string;
1530
- state: Record<string, unknown>;
1530
+ state: import("../util/index.js").ServedManifestState;
1531
1531
  }>;
1532
1532
  omittedBundles: string[];
1533
1533
  }, z.core.$ZodTypeInternals<{
@@ -1609,7 +1609,7 @@ export declare const ContainerWriterProjectionWireResponseSchema: z.ZodType<{
1609
1609
  };
1610
1610
  manifest: Record<string, unknown>;
1611
1611
  manifestHash: string;
1612
- state: Record<string, unknown>;
1612
+ state: import("../util/index.js").ServedManifestState;
1613
1613
  }>;
1614
1614
  omittedBundles: string[];
1615
1615
  }, {
@@ -1691,7 +1691,7 @@ export declare const ContainerWriterProjectionWireResponseSchema: z.ZodType<{
1691
1691
  };
1692
1692
  manifest: Record<string, unknown>;
1693
1693
  manifestHash: string;
1694
- state: Record<string, unknown>;
1694
+ state: import("../util/index.js").ServedManifestState;
1695
1695
  }>;
1696
1696
  omittedBundles: string[];
1697
1697
  }>>;
@@ -1536,7 +1536,7 @@ export declare const DocumentWriterProjectionWireResponseSchema: z.ZodType<{
1536
1536
  };
1537
1537
  manifest: Record<string, unknown>;
1538
1538
  manifestHash: string;
1539
- state: Record<string, unknown>;
1539
+ state: import("../util/index.js").ServedManifestState;
1540
1540
  }>;
1541
1541
  omittedBundles: string[];
1542
1542
  policyEvidence: {
@@ -1648,7 +1648,7 @@ export declare const DocumentWriterProjectionWireResponseSchema: z.ZodType<{
1648
1648
  };
1649
1649
  manifest: Record<string, unknown>;
1650
1650
  manifestHash: string;
1651
- state: Record<string, unknown>;
1651
+ state: import("../util/index.js").ServedManifestState;
1652
1652
  }>;
1653
1653
  omittedBundles: string[];
1654
1654
  policyEvidence: {
@@ -1760,7 +1760,7 @@ export declare const DocumentWriterProjectionWireResponseSchema: z.ZodType<{
1760
1760
  };
1761
1761
  manifest: Record<string, unknown>;
1762
1762
  manifestHash: string;
1763
- state: Record<string, unknown>;
1763
+ state: import("../util/index.js").ServedManifestState;
1764
1764
  }>;
1765
1765
  omittedBundles: string[];
1766
1766
  policyEvidence: {
@@ -1872,7 +1872,7 @@ export declare const DocumentWriterProjectionWireResponseSchema: z.ZodType<{
1872
1872
  };
1873
1873
  manifest: Record<string, unknown>;
1874
1874
  manifestHash: string;
1875
- state: Record<string, unknown>;
1875
+ state: import("../util/index.js").ServedManifestState;
1876
1876
  }>;
1877
1877
  omittedBundles: string[];
1878
1878
  policyEvidence: {
@@ -115,12 +115,6 @@ export declare const DocumentContentKeyBundleResponseSchema: z.ZodType<{
115
115
  export type DocumentContentKeyBundleResponse = z.infer<typeof DocumentContentKeyBundleResponseSchema>;
116
116
  export declare const DocumentSyncUpdateResponseSchema: z.ZodType<{
117
117
  accessEpoch: number;
118
- authorizationTargets: {
119
- containerId: string;
120
- containerKeyEpoch: number;
121
- containerKeyEpochId: string;
122
- containerManifestHash: string;
123
- }[];
124
118
  authorFingerprint: string;
125
119
  createdAt: string;
126
120
  documentId: string;
@@ -130,17 +124,17 @@ export declare const DocumentSyncUpdateResponseSchema: z.ZodType<{
130
124
  partialStartVersionVector: string;
131
125
  plaintextHash: string;
132
126
  writeHeader: Record<string, unknown>;
127
+ authorizationTargets?: {
128
+ containerId: string;
129
+ containerKeyEpoch: number;
130
+ containerKeyEpochId: string;
131
+ containerManifestHash: string;
132
+ }[] | undefined;
133
133
  checkpointKind?: "rotate_baseline" | undefined;
134
134
  checkpointPayloadKind?: "full_history_snapshot" | undefined;
135
135
  sourceVersionVector?: string | undefined;
136
136
  }, {
137
137
  accessEpoch: number;
138
- authorizationTargets: {
139
- containerId: string;
140
- containerKeyEpoch: number;
141
- containerKeyEpochId: string;
142
- containerManifestHash: string;
143
- }[];
144
138
  authorFingerprint: string;
145
139
  createdAt: string;
146
140
  documentId: string;
@@ -150,17 +144,17 @@ export declare const DocumentSyncUpdateResponseSchema: z.ZodType<{
150
144
  partialStartVersionVector: string;
151
145
  plaintextHash: string;
152
146
  writeHeader: Record<string, unknown>;
147
+ authorizationTargets?: {
148
+ containerId: string;
149
+ containerKeyEpoch: number;
150
+ containerKeyEpochId: string;
151
+ containerManifestHash: string;
152
+ }[] | undefined;
153
153
  checkpointKind?: "rotate_baseline" | undefined;
154
154
  checkpointPayloadKind?: "full_history_snapshot" | undefined;
155
155
  sourceVersionVector?: string | undefined;
156
156
  }, z.core.$ZodTypeInternals<{
157
157
  accessEpoch: number;
158
- authorizationTargets: {
159
- containerId: string;
160
- containerKeyEpoch: number;
161
- containerKeyEpochId: string;
162
- containerManifestHash: string;
163
- }[];
164
158
  authorFingerprint: string;
165
159
  createdAt: string;
166
160
  documentId: string;
@@ -170,17 +164,17 @@ export declare const DocumentSyncUpdateResponseSchema: z.ZodType<{
170
164
  partialStartVersionVector: string;
171
165
  plaintextHash: string;
172
166
  writeHeader: Record<string, unknown>;
167
+ authorizationTargets?: {
168
+ containerId: string;
169
+ containerKeyEpoch: number;
170
+ containerKeyEpochId: string;
171
+ containerManifestHash: string;
172
+ }[] | undefined;
173
173
  checkpointKind?: "rotate_baseline" | undefined;
174
174
  checkpointPayloadKind?: "full_history_snapshot" | undefined;
175
175
  sourceVersionVector?: string | undefined;
176
176
  }, {
177
177
  accessEpoch: number;
178
- authorizationTargets: {
179
- containerId: string;
180
- containerKeyEpoch: number;
181
- containerKeyEpochId: string;
182
- containerManifestHash: string;
183
- }[];
184
178
  authorFingerprint: string;
185
179
  createdAt: string;
186
180
  documentId: string;
@@ -190,6 +184,12 @@ export declare const DocumentSyncUpdateResponseSchema: z.ZodType<{
190
184
  partialStartVersionVector: string;
191
185
  plaintextHash: string;
192
186
  writeHeader: Record<string, unknown>;
187
+ authorizationTargets?: {
188
+ containerId: string;
189
+ containerKeyEpoch: number;
190
+ containerKeyEpochId: string;
191
+ containerManifestHash: string;
192
+ }[] | undefined;
193
193
  checkpointKind?: "rotate_baseline" | undefined;
194
194
  checkpointPayloadKind?: "full_history_snapshot" | undefined;
195
195
  sourceVersionVector?: string | undefined;
@@ -235,12 +235,6 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
235
235
  };
236
236
  updates: {
237
237
  accessEpoch: number;
238
- authorizationTargets: {
239
- containerId: string;
240
- containerKeyEpoch: number;
241
- containerKeyEpochId: string;
242
- containerManifestHash: string;
243
- }[];
244
238
  authorFingerprint: string;
245
239
  createdAt: string;
246
240
  documentId: string;
@@ -250,6 +244,12 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
250
244
  partialStartVersionVector: string;
251
245
  plaintextHash: string;
252
246
  writeHeader: Record<string, unknown>;
247
+ authorizationTargets?: {
248
+ containerId: string;
249
+ containerKeyEpoch: number;
250
+ containerKeyEpochId: string;
251
+ containerManifestHash: string;
252
+ }[] | undefined;
253
253
  checkpointKind?: "rotate_baseline" | undefined;
254
254
  checkpointPayloadKind?: "full_history_snapshot" | undefined;
255
255
  sourceVersionVector?: string | undefined;
@@ -279,12 +279,6 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
279
279
  };
280
280
  updates: {
281
281
  accessEpoch: number;
282
- authorizationTargets: {
283
- containerId: string;
284
- containerKeyEpoch: number;
285
- containerKeyEpochId: string;
286
- containerManifestHash: string;
287
- }[];
288
282
  authorFingerprint: string;
289
283
  createdAt: string;
290
284
  documentId: string;
@@ -294,6 +288,12 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
294
288
  partialStartVersionVector: string;
295
289
  plaintextHash: string;
296
290
  writeHeader: Record<string, unknown>;
291
+ authorizationTargets?: {
292
+ containerId: string;
293
+ containerKeyEpoch: number;
294
+ containerKeyEpochId: string;
295
+ containerManifestHash: string;
296
+ }[] | undefined;
297
297
  checkpointKind?: "rotate_baseline" | undefined;
298
298
  checkpointPayloadKind?: "full_history_snapshot" | undefined;
299
299
  sourceVersionVector?: string | undefined;
@@ -323,12 +323,6 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
323
323
  };
324
324
  updates: {
325
325
  accessEpoch: number;
326
- authorizationTargets: {
327
- containerId: string;
328
- containerKeyEpoch: number;
329
- containerKeyEpochId: string;
330
- containerManifestHash: string;
331
- }[];
332
326
  authorFingerprint: string;
333
327
  createdAt: string;
334
328
  documentId: string;
@@ -338,6 +332,12 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
338
332
  partialStartVersionVector: string;
339
333
  plaintextHash: string;
340
334
  writeHeader: Record<string, unknown>;
335
+ authorizationTargets?: {
336
+ containerId: string;
337
+ containerKeyEpoch: number;
338
+ containerKeyEpochId: string;
339
+ containerManifestHash: string;
340
+ }[] | undefined;
341
341
  checkpointKind?: "rotate_baseline" | undefined;
342
342
  checkpointPayloadKind?: "full_history_snapshot" | undefined;
343
343
  sourceVersionVector?: string | undefined;
@@ -367,12 +367,6 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
367
367
  };
368
368
  updates: {
369
369
  accessEpoch: number;
370
- authorizationTargets: {
371
- containerId: string;
372
- containerKeyEpoch: number;
373
- containerKeyEpochId: string;
374
- containerManifestHash: string;
375
- }[];
376
370
  authorFingerprint: string;
377
371
  createdAt: string;
378
372
  documentId: string;
@@ -382,6 +376,12 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
382
376
  partialStartVersionVector: string;
383
377
  plaintextHash: string;
384
378
  writeHeader: Record<string, unknown>;
379
+ authorizationTargets?: {
380
+ containerId: string;
381
+ containerKeyEpoch: number;
382
+ containerKeyEpochId: string;
383
+ containerManifestHash: string;
384
+ }[] | undefined;
385
385
  checkpointKind?: "rotate_baseline" | undefined;
386
386
  checkpointPayloadKind?: "full_history_snapshot" | undefined;
387
387
  sourceVersionVector?: string | undefined;
@@ -35,7 +35,7 @@ export const DocumentContentKeyBundleResponseSchema = loosePlainObject({
35
35
  });
36
36
  export const DocumentSyncUpdateResponseSchema = registerJsonSchemaRuntimeRefinements(loosePlainObject({
37
37
  accessEpoch: positiveIntegerSchema,
38
- authorizationTargets: nonEmptyArraySchema(DocumentContentKeyTargetResponseSchema),
38
+ authorizationTargets: nonEmptyArraySchema(DocumentContentKeyTargetResponseSchema).optional(),
39
39
  authorFingerprint: z.string(),
40
40
  checkpointKind: z
41
41
  .literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND)
@@ -1 +1 @@
1
- {"version":3,"file":"documentSyncSchema.js","sourceRoot":"","sources":["documentSyncSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,oCAAoC,EACpC,gDAAgD,EAChD,sCAAsC,EACtC,8CAA8C,GAC/C,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,2CAA2C,EAC3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C,QAAQ,CAAC;YACf,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,+CAA+C;YACxD,IAAI,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC;SACjC,CAAC,CAAC;IACL,CAAC;IACD,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtC,mCAAmC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC,CAAC,EACF;IACE,2CAA2C;IAC3C,+CAA+C;IAC/C,sCAAsC;IACtC,+CAA+C;CAChD,CACF,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n classifyDocumentSyncCheckpointFields,\n DOCUMENT_SYNC_CHECKPOINT_FIELD_SET_ISSUE_MESSAGE,\n DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND,\n DOCUMENT_SYNC_ROTATION_CHECKPOINT_PAYLOAD_KIND,\n} from \"../documentSyncCheckpoint\";\nimport {\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n documentSyncResponseHistoricalBundlesRefinement,\n documentSyncResponsePullPageRefinement,\n documentSyncResponseRotationRefinement,\n} from \"../documentSyncRefinements\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport {\n arraySchema,\n boundedNonEmptyStringSchema,\n loosePlainObject,\n nonEmptyArraySchema,\n nonEmptyStringSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n} from \"../schema\";\nimport {\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n} from \"../util/documentSyncLimits\";\n\nexport const DocumentContentKeyTargetEnvelopeResponseSchema = loosePlainObject({\n containerId: nonEmptyStringSchema,\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHash: nonEmptyStringSchema,\n wrappedKey: nonEmptyStringSchema,\n wrappingMetadata: plainObjectSchema,\n});\n\nexport type DocumentContentKeyTargetEnvelopeResponse = z.infer<\n typeof DocumentContentKeyTargetEnvelopeResponseSchema\n>;\n\nconst DocumentContentKeyTargetResponseSchema = loosePlainObject({\n containerId: nonEmptyStringSchema,\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHash: nonEmptyStringSchema,\n});\n\nexport const DocumentKekTargetsResponseSchema = loosePlainObject({\n documentId: z.string(),\n documentKeyTargetHash: nonEmptyStringSchema,\n linkedContainerKeyEpochIds: nonEmptyArraySchema(nonEmptyStringSchema),\n linkedContainerManifestHashes: nonEmptyArraySchema(nonEmptyStringSchema),\n linkSetManifestHash: nonEmptyStringSchema,\n targets: nonEmptyArraySchema(plainObjectSchema),\n});\n\nexport type DocumentKekTargetsResponse = z.infer<\n typeof DocumentKekTargetsResponseSchema\n>;\n\nexport const DocumentContentKeyBundleResponseSchema = loosePlainObject({\n contentKeyEpoch: positiveIntegerSchema,\n documentId: z.string(),\n linkSetManifestHash: nonEmptyStringSchema,\n targetHash: nonEmptyStringSchema,\n targets: nonEmptyArraySchema(DocumentContentKeyTargetEnvelopeResponseSchema),\n});\n\nexport type DocumentContentKeyBundleResponse = z.infer<\n typeof DocumentContentKeyBundleResponseSchema\n>;\n\nexport const DocumentSyncUpdateResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n accessEpoch: positiveIntegerSchema,\n authorizationTargets: nonEmptyArraySchema(\n DocumentContentKeyTargetResponseSchema,\n ),\n authorFingerprint: z.string(),\n checkpointKind: z\n .literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND)\n .optional(),\n checkpointPayloadKind: z\n .literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_PAYLOAD_KIND)\n .optional(),\n createdAt: z.string(),\n documentId: z.string(),\n encryptedData: z.string(),\n id: z.string(),\n partialEndVersionVector: z.string(),\n partialStartVersionVector: z.string(),\n plaintextHash: nonEmptyStringSchema,\n sourceVersionVector: z.string().min(1).optional(),\n writeHeader: plainObjectSchema,\n }).superRefine((update, context) => {\n if (classifyDocumentSyncCheckpointFields(update) === \"invalid\") {\n context.addIssue({\n code: \"custom\",\n message: DOCUMENT_SYNC_CHECKPOINT_FIELD_SET_ISSUE_MESSAGE,\n });\n }\n }),\n [documentSyncResponseRotationRefinement],\n );\n\nexport type DocumentSyncUpdateResponse = z.infer<\n typeof DocumentSyncUpdateResponseSchema\n>;\n\nexport const DocumentSyncPullPageResponseSchema = loosePlainObject({\n hasMore: z.boolean(),\n nextCursor: boundedNonEmptyStringSchema(\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n ).nullable(),\n});\n\nexport type DocumentSyncPullPageResponse = z.infer<\n typeof DocumentSyncPullPageResponseSchema\n>;\n\nfunction contentKeyEpochOf(bundle: unknown): number | null {\n if (typeof bundle !== \"object\" || bundle === null) return null;\n const contentKeyEpoch: unknown = Reflect.get(bundle, \"contentKeyEpoch\");\n return typeof contentKeyEpoch === \"number\" ? contentKeyEpoch : null;\n}\n\n/**\n * The client already holds the current epoch's bundle, so the array holds the\n * distinct older epochs that served updates cite; the client rejects any epoch\n * not older than the one it planned against. Field issues do not stop this\n * object refinement, so it judges only epochs that parsed.\n */\nfunction addHistoricalContentKeyBundleIssues(\n response: { readonly contentKeyBundles: unknown },\n context: z.RefinementCtx,\n): void {\n if (!Array.isArray(response.contentKeyBundles)) return;\n const seenEpochs = new Set<number>();\n // forEach skips holes exactly as arraySchema's item validation does.\n response.contentKeyBundles.forEach((bundle: unknown, index: number) => {\n const contentKeyEpoch = contentKeyEpochOf(bundle);\n if (contentKeyEpoch === null) return;\n if (seenEpochs.has(contentKeyEpoch)) {\n context.addIssue({\n code: \"custom\",\n message: \"content-key bundles must be distinct epochs\",\n path: [\"contentKeyBundles\", index, \"contentKeyEpoch\"],\n });\n }\n seenEpochs.add(contentKeyEpoch);\n });\n}\n\nexport const commitLsnResponseShape = {\n commitLsn: z.string().nullable(),\n commitLsnMode: z.union([z.literal(\"tracked\"), z.literal(\"untracked\")]),\n};\n\n/** The 0/0 sentinel and the untracked mode imply each other. */\nfunction addCommitLsnIssues(\n response: {\n readonly commitLsn: string | null;\n readonly commitLsnMode: \"tracked\" | \"untracked\";\n },\n context: z.RefinementCtx,\n): void {\n if (response.commitLsnMode === \"untracked\" && response.commitLsn !== \"0/0\") {\n context.addIssue({\n code: \"custom\",\n message: \"untracked commit LSN must use the 0/0 sentinel\",\n path: [\"commitLsn\"],\n });\n }\n if (response.commitLsn === \"0/0\" && response.commitLsnMode !== \"untracked\") {\n context.addIssue({\n code: \"custom\",\n message: \"0/0 commit LSN must be declared untracked\",\n path: [\"commitLsnMode\"],\n });\n }\n}\n\nexport const DocumentSyncResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n acceptedOutgoingUpdateIds: arraySchema(\n z.string(),\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n ),\n ...commitLsnResponseShape,\n contentKeyBundles: arraySchema(DocumentContentKeyBundleResponseSchema),\n documentId: z.string(),\n pullPage: DocumentSyncPullPageResponseSchema,\n updates: arraySchema(\n DocumentSyncUpdateResponseSchema,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n ),\n }).superRefine((response, context) => {\n if (\n response.pullPage !== undefined &&\n response.pullPage.hasMore !== (response.pullPage.nextCursor !== null)\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"pull page continuation does not match hasMore\",\n path: [\"pullPage\", \"nextCursor\"],\n });\n }\n addCommitLsnIssues(response, context);\n addHistoricalContentKeyBundleIssues(response, context);\n }),\n [\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n documentSyncResponsePullPageRefinement,\n documentSyncResponseHistoricalBundlesRefinement,\n ],\n);\n\nexport type DocumentSyncResponse = z.infer<typeof DocumentSyncResponseSchema>;\n"]}
1
+ {"version":3,"file":"documentSyncSchema.js","sourceRoot":"","sources":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AC,WAAW,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE;IACnC,IACE,QAAQ,CAAC,QAAQ,KAAK,SAAS;QAC/B,QAAQ,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,KAAK,IAAI,CAAC,EACrE,CAAC;QACD,OAAO,CAAC,QAAQ,CAAC;YACf,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,+CAA+C;YACxD,IAAI,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC;SACjC,CAAC,CAAC;IACL,CAAC;IACD,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtC,mCAAmC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC,CAAC,EACF;IACE,2CAA2C;IAC3C,+CAA+C;IAC/C,sCAAsC;IACtC,+CAA+C;CAChD,CACF,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n classifyDocumentSyncCheckpointFields,\n DOCUMENT_SYNC_CHECKPOINT_FIELD_SET_ISSUE_MESSAGE,\n DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND,\n DOCUMENT_SYNC_ROTATION_CHECKPOINT_PAYLOAD_KIND,\n} from \"../documentSyncCheckpoint\";\nimport {\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n documentSyncResponseHistoricalBundlesRefinement,\n documentSyncResponsePullPageRefinement,\n documentSyncResponseRotationRefinement,\n} from \"../documentSyncRefinements\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport {\n arraySchema,\n boundedNonEmptyStringSchema,\n loosePlainObject,\n nonEmptyArraySchema,\n nonEmptyStringSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n} from \"../schema\";\nimport {\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n} from \"../util/documentSyncLimits\";\n\nexport const DocumentContentKeyTargetEnvelopeResponseSchema = loosePlainObject({\n containerId: nonEmptyStringSchema,\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHash: nonEmptyStringSchema,\n wrappedKey: nonEmptyStringSchema,\n wrappingMetadata: plainObjectSchema,\n});\n\nexport type DocumentContentKeyTargetEnvelopeResponse = z.infer<\n typeof DocumentContentKeyTargetEnvelopeResponseSchema\n>;\n\nconst DocumentContentKeyTargetResponseSchema = loosePlainObject({\n containerId: nonEmptyStringSchema,\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHash: nonEmptyStringSchema,\n});\n\nexport const DocumentKekTargetsResponseSchema = loosePlainObject({\n documentId: z.string(),\n documentKeyTargetHash: nonEmptyStringSchema,\n linkedContainerKeyEpochIds: nonEmptyArraySchema(nonEmptyStringSchema),\n linkedContainerManifestHashes: nonEmptyArraySchema(nonEmptyStringSchema),\n linkSetManifestHash: nonEmptyStringSchema,\n targets: nonEmptyArraySchema(plainObjectSchema),\n});\n\nexport type DocumentKekTargetsResponse = z.infer<\n typeof DocumentKekTargetsResponseSchema\n>;\n\nexport const DocumentContentKeyBundleResponseSchema = loosePlainObject({\n contentKeyEpoch: positiveIntegerSchema,\n documentId: z.string(),\n linkSetManifestHash: nonEmptyStringSchema,\n targetHash: nonEmptyStringSchema,\n targets: nonEmptyArraySchema(DocumentContentKeyTargetEnvelopeResponseSchema),\n});\n\nexport type DocumentContentKeyBundleResponse = z.infer<\n typeof DocumentContentKeyBundleResponseSchema\n>;\n\nexport const DocumentSyncUpdateResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n accessEpoch: positiveIntegerSchema,\n authorizationTargets: nonEmptyArraySchema(\n DocumentContentKeyTargetResponseSchema,\n ).optional(),\n authorFingerprint: z.string(),\n checkpointKind: z\n .literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND)\n .optional(),\n checkpointPayloadKind: z\n .literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_PAYLOAD_KIND)\n .optional(),\n createdAt: z.string(),\n documentId: z.string(),\n encryptedData: z.string(),\n id: z.string(),\n partialEndVersionVector: z.string(),\n partialStartVersionVector: z.string(),\n plaintextHash: nonEmptyStringSchema,\n sourceVersionVector: z.string().min(1).optional(),\n writeHeader: plainObjectSchema,\n }).superRefine((update, context) => {\n if (classifyDocumentSyncCheckpointFields(update) === \"invalid\") {\n context.addIssue({\n code: \"custom\",\n message: DOCUMENT_SYNC_CHECKPOINT_FIELD_SET_ISSUE_MESSAGE,\n });\n }\n }),\n [documentSyncResponseRotationRefinement],\n );\n\nexport type DocumentSyncUpdateResponse = z.infer<\n typeof DocumentSyncUpdateResponseSchema\n>;\n\nexport const DocumentSyncPullPageResponseSchema = loosePlainObject({\n hasMore: z.boolean(),\n nextCursor: boundedNonEmptyStringSchema(\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n ).nullable(),\n});\n\nexport type DocumentSyncPullPageResponse = z.infer<\n typeof DocumentSyncPullPageResponseSchema\n>;\n\nfunction contentKeyEpochOf(bundle: unknown): number | null {\n if (typeof bundle !== \"object\" || bundle === null) return null;\n const contentKeyEpoch: unknown = Reflect.get(bundle, \"contentKeyEpoch\");\n return typeof contentKeyEpoch === \"number\" ? contentKeyEpoch : null;\n}\n\n/**\n * The client already holds the current epoch's bundle, so the array holds the\n * distinct older epochs that served updates cite; the client rejects any epoch\n * not older than the one it planned against. Field issues do not stop this\n * object refinement, so it judges only epochs that parsed.\n */\nfunction addHistoricalContentKeyBundleIssues(\n response: { readonly contentKeyBundles: unknown },\n context: z.RefinementCtx,\n): void {\n if (!Array.isArray(response.contentKeyBundles)) return;\n const seenEpochs = new Set<number>();\n // forEach skips holes exactly as arraySchema's item validation does.\n response.contentKeyBundles.forEach((bundle: unknown, index: number) => {\n const contentKeyEpoch = contentKeyEpochOf(bundle);\n if (contentKeyEpoch === null) return;\n if (seenEpochs.has(contentKeyEpoch)) {\n context.addIssue({\n code: \"custom\",\n message: \"content-key bundles must be distinct epochs\",\n path: [\"contentKeyBundles\", index, \"contentKeyEpoch\"],\n });\n }\n seenEpochs.add(contentKeyEpoch);\n });\n}\n\nexport const commitLsnResponseShape = {\n commitLsn: z.string().nullable(),\n commitLsnMode: z.union([z.literal(\"tracked\"), z.literal(\"untracked\")]),\n};\n\n/** The 0/0 sentinel and the untracked mode imply each other. */\nfunction addCommitLsnIssues(\n response: {\n readonly commitLsn: string | null;\n readonly commitLsnMode: \"tracked\" | \"untracked\";\n },\n context: z.RefinementCtx,\n): void {\n if (response.commitLsnMode === \"untracked\" && response.commitLsn !== \"0/0\") {\n context.addIssue({\n code: \"custom\",\n message: \"untracked commit LSN must use the 0/0 sentinel\",\n path: [\"commitLsn\"],\n });\n }\n if (response.commitLsn === \"0/0\" && response.commitLsnMode !== \"untracked\") {\n context.addIssue({\n code: \"custom\",\n message: \"0/0 commit LSN must be declared untracked\",\n path: [\"commitLsnMode\"],\n });\n }\n}\n\nexport const DocumentSyncResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n acceptedOutgoingUpdateIds: arraySchema(\n z.string(),\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n ),\n ...commitLsnResponseShape,\n contentKeyBundles: arraySchema(DocumentContentKeyBundleResponseSchema),\n documentId: z.string(),\n pullPage: DocumentSyncPullPageResponseSchema,\n updates: arraySchema(\n DocumentSyncUpdateResponseSchema,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n ),\n }).superRefine((response, context) => {\n if (\n response.pullPage !== undefined &&\n response.pullPage.hasMore !== (response.pullPage.nextCursor !== null)\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"pull page continuation does not match hasMore\",\n path: [\"pullPage\", \"nextCursor\"],\n });\n }\n addCommitLsnIssues(response, context);\n addHistoricalContentKeyBundleIssues(response, context);\n }),\n [\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n documentSyncResponsePullPageRefinement,\n documentSyncResponseHistoricalBundlesRefinement,\n ],\n);\n\nexport type DocumentSyncResponse = z.infer<typeof DocumentSyncResponseSchema>;\n"]}
@@ -1,13 +1,14 @@
1
1
  import { isPlainObject } from "../isPlainObject.js";
2
2
  import { arraySchema, nonEmptyStringSchema, plainRecordSchema, } from "../schema.js";
3
- import { AccessManifestBundleWireResponseSchema } from "../util/index.js";
3
+ import { ServedAccessManifestBundleWireResponseSchema } from "../util/index.js";
4
4
  /**
5
5
  * A writer projection names each access manifest by hash. The bundle for a
6
6
  * hash travels once, in `bundles`, however many lists cite it, or not at all
7
- * when the request cited it as already held (`omittedBundles`).
7
+ * when the request cited it as already held (`omittedBundles`). A served
8
+ * bundle omits the derived state, which the client rebuilds as it decodes.
8
9
  */
9
10
  export const ManifestHashReferenceSchema = nonEmptyStringSchema;
10
- export const ManifestBundlesSchema = plainRecordSchema(AccessManifestBundleWireResponseSchema);
11
+ export const ManifestBundlesSchema = plainRecordSchema(ServedAccessManifestBundleWireResponseSchema);
11
12
  export const OmittedManifestBundlesSchema = arraySchema(ManifestHashReferenceSchema);
12
13
  function listed(value) {
13
14
  return Array.isArray(value) ? value : [];
@@ -1 +1 @@
1
- {"version":3,"file":"manifestBundleReferences.js","sourceRoot":"","sources":["manifestBundleReferences.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,sCAAsC,EAAE,MAAM,SAAS,CAAC;AAEjE;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,oBAAoB,CAAC;AAEhE,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CACpD,sCAAsC,CACvC,CAAC;AAEF,MAAM,CA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C,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CACtE,CAAC;IACF,MAAM,OAAO,GAAG,wBAAwB,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC;IACzE,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACnE,CAAC;AACH,CAAC","sourcesContent":["import type { z } from \"zod\";\nimport { isPlainObject } from \"../isPlainObject\";\nimport {\n arraySchema,\n nonEmptyStringSchema,\n plainRecordSchema,\n} from \"../schema\";\nimport { AccessManifestBundleWireResponseSchema } from \"../util\";\n\n/**\n * A writer projection names each access manifest by hash. The bundle for a\n * hash travels once, in `bundles`, however many lists cite it, or not at all\n * when the request cited it as already held (`omittedBundles`).\n */\nexport const ManifestHashReferenceSchema = nonEmptyStringSchema;\n\nexport const ManifestBundlesSchema = plainRecordSchema(\n AccessManifestBundleWireResponseSchema,\n);\n\nexport const OmittedManifestBundlesSchema = arraySchema(\n ManifestHashReferenceSchema,\n);\n\nfunction listed(value: unknown): unknown[] {\n return Array.isArray(value) ? value : [];\n}\n\n/** Hashes cited by one container keying path: its path and every KEK history. */\nexport function containerKeyingPathReferences(path: unknown): unknown[] {\n if (!isPlainObject(path)) {\n return [];\n }\n const { containerKeks, path: manifests } = path;\n return [\n ...listed(manifests),\n ...listed(containerKeks).flatMap((kek) => {\n if (!isPlainObject(kek)) {\n return [];\n }\n const { containerManifestHistory } = kek;\n return listed(containerManifestHistory);\n }),\n ];\n}\n\nfunction firstBundleInconsistency(\n bundles: Record<string, unknown>,\n omitted: readonly unknown[],\n cited: ReadonlySet<string>,\n): string | null {\n const omittedHashes = new Set<unknown>(omitted);\n if (omittedHashes.size !== omitted.length) {\n return \"omittedBundles repeats a manifest hash\";\n }\n for (const hash of omitted) {\n if (typeof hash !== \"string\" || !cited.has(hash)) {\n return `omitted bundle ${String(hash)} is not cited`;\n }\n if (Object.hasOwn(bundles, hash)) {\n return `omitted bundle ${hash} is also served`;\n }\n }\n for (const hash of cited) {\n if (!Object.hasOwn(bundles, hash) && !omittedHashes.has(hash)) {\n return `manifest ${hash} is cited without a bundle`;\n }\n }\n return firstServedBundleInconsistency(bundles, cited);\n}\n\nfunction firstServedBundleInconsistency(\n bundles: Record<string, unknown>,\n cited: ReadonlySet<string>,\n): string | null {\n for (const [hash, bundle] of Object.entries(bundles)) {\n if (\n !isPlainObject(bundle) ||\n Reflect.get(bundle, \"manifestHash\") !== hash\n ) {\n return `bundle key ${hash} does not match its manifestHash`;\n }\n if (!cited.has(hash)) {\n return `bundle ${hash} is not cited`;\n }\n }\n return null;\n}\n\n/**\n * Fails closed on the first inconsistency: a cited hash neither served nor\n * declared omitted, a bundle stored under a key other than its own\n * manifestHash, a served or omitted bundle no list cites, or a hash both\n * served and omitted. Whether an omission was requested is the client's\n * check. Refinements may run after field errors, so inputs are unknown.\n */\nexport function refineManifestBundleReferences(\n projection: { readonly bundles: unknown; readonly omittedBundles: unknown },\n references: readonly unknown[],\n context: z.RefinementCtx,\n): void {\n const { bundles, omittedBundles } = projection;\n if (!isPlainObject(bundles) || !Array.isArray(omittedBundles)) {\n return;\n }\n const cited = new Set(\n references.filter((hash): hash is string => typeof hash === \"string\"),\n );\n const message = firstBundleInconsistency(bundles, omittedBundles, cited);\n if (message !== null) {\n context.addIssue({ code: \"custom\", message, path: [\"bundles\"] });\n }\n}\n"]}
1
+ {"version":3,"file":"manifestBundleReferences.js","sourceRoot":"","sources":["manifestBundleReferences.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,4CAA4C,EAAE,MAAM,SAAS,CAAC;AAE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AO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QAC9D,OAAO;IACT,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CACtE,CAAC;IACF,MAAM,OAAO,GAAG,wBAAwB,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC;IACzE,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACnE,CAAC;AACH,CAAC","sourcesContent":["import type { z } from \"zod\";\nimport { isPlainObject } from \"../isPlainObject\";\nimport {\n arraySchema,\n nonEmptyStringSchema,\n plainRecordSchema,\n} from \"../schema\";\nimport { ServedAccessManifestBundleWireResponseSchema } from \"../util\";\n\n/**\n * A writer projection names each access manifest by hash. The bundle for a\n * hash travels once, in `bundles`, however many lists cite it, or not at all\n * when the request cited it as already held (`omittedBundles`). A served\n * bundle omits the derived state, which the client rebuilds as it decodes.\n */\nexport const ManifestHashReferenceSchema = nonEmptyStringSchema;\n\nexport const ManifestBundlesSchema = plainRecordSchema(\n ServedAccessManifestBundleWireResponseSchema,\n);\n\nexport const OmittedManifestBundlesSchema = arraySchema(\n ManifestHashReferenceSchema,\n);\n\nfunction listed(value: unknown): unknown[] {\n return Array.isArray(value) ? value : [];\n}\n\n/** Hashes cited by one container keying path: its path and every KEK history. */\nexport function containerKeyingPathReferences(path: unknown): unknown[] {\n if (!isPlainObject(path)) {\n return [];\n }\n const { containerKeks, path: manifests } = path;\n return [\n ...listed(manifests),\n ...listed(containerKeks).flatMap((kek) => {\n if (!isPlainObject(kek)) {\n return [];\n }\n const { containerManifestHistory } = kek;\n return listed(containerManifestHistory);\n }),\n ];\n}\n\nfunction firstBundleInconsistency(\n bundles: Record<string, unknown>,\n omitted: readonly unknown[],\n cited: ReadonlySet<string>,\n): string | null {\n const omittedHashes = new Set<unknown>(omitted);\n if (omittedHashes.size !== omitted.length) {\n return \"omittedBundles repeats a manifest hash\";\n }\n for (const hash of omitted) {\n if (typeof hash !== \"string\" || !cited.has(hash)) {\n return `omitted bundle ${String(hash)} is not cited`;\n }\n if (Object.hasOwn(bundles, hash)) {\n return `omitted bundle ${hash} is also served`;\n }\n }\n for (const hash of cited) {\n if (!Object.hasOwn(bundles, hash) && !omittedHashes.has(hash)) {\n return `manifest ${hash} is cited without a bundle`;\n }\n }\n return firstServedBundleInconsistency(bundles, cited);\n}\n\nfunction firstServedBundleInconsistency(\n bundles: Record<string, unknown>,\n cited: ReadonlySet<string>,\n): string | null {\n for (const [hash, bundle] of Object.entries(bundles)) {\n if (\n !isPlainObject(bundle) ||\n Reflect.get(bundle, \"manifestHash\") !== hash\n ) {\n return `bundle key ${hash} does not match its manifestHash`;\n }\n if (!cited.has(hash)) {\n return `bundle ${hash} is not cited`;\n }\n }\n return null;\n}\n\n/**\n * Fails closed on the first inconsistency: a cited hash neither served nor\n * declared omitted, a bundle stored under a key other than its own\n * manifestHash, a served or omitted bundle no list cites, or a hash both\n * served and omitted. Whether an omission was requested is the client's\n * check. Refinements may run after field errors, so inputs are unknown.\n */\nexport function refineManifestBundleReferences(\n projection: { readonly bundles: unknown; readonly omittedBundles: unknown },\n references: readonly unknown[],\n context: z.RefinementCtx,\n): void {\n const { bundles, omittedBundles } = projection;\n if (!isPlainObject(bundles) || !Array.isArray(omittedBundles)) {\n return;\n }\n const cited = new Set(\n references.filter((hash): hash is string => typeof hash === \"string\"),\n );\n const message = firstBundleInconsistency(bundles, omittedBundles, cited);\n if (message !== null) {\n context.addIssue({ code: \"custom\", message, path: [\"bundles\"] });\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
- import type { AccessManifestBundleWireResponse } from "../util/index.js";
1
+ import { type ServedAccessManifestBundleWireResponse } from "../util/index.js";
2
2
  import { type ContainerKekResponse, type ContainerKekWireLevel, type ContainerWriterProjectionResponse, type ContainerWriterProjectionWireResponse } from "./container.js";
3
3
  import { type DocumentWriterProjectionResponse, type DocumentWriterProjectionWireResponse } from "./documentMutation.js";
4
- type Bundle = AccessManifestBundleWireResponse;
4
+ type ServedBundle = ServedAccessManifestBundleWireResponse;
5
5
  type HeldLevels = ReadonlyMap<string, ContainerKekWireLevel>;
6
6
  /** A KEK level's wire form: its manifest history cited by hash. */
7
7
  export declare function containerKekWireLevel(kek: ContainerKekResponse): ContainerKekWireLevel;
@@ -24,7 +24,7 @@ export declare function encodeDocumentWriterProjection(projection: DocumentWrite
24
24
  * `heldLevels` (KEK levels by digest) cannot fill; the caller treats either
25
25
  * as a shape failure.
26
26
  */
27
- export declare function decodeContainerWriterProjection(value: unknown, held?: ReadonlyMap<string, Bundle>, heldLevels?: HeldLevels): ContainerWriterProjectionResponse | null;
27
+ export declare function decodeContainerWriterProjection(value: unknown, held?: ReadonlyMap<string, ServedBundle>, heldLevels?: HeldLevels): ContainerWriterProjectionResponse | null;
28
28
  /** See {@link decodeContainerWriterProjection}. */
29
- export declare function decodeDocumentWriterProjection(value: unknown, held?: ReadonlyMap<string, Bundle>, heldLevels?: HeldLevels): DocumentWriterProjectionResponse | null;
29
+ export declare function decodeDocumentWriterProjection(value: unknown, held?: ReadonlyMap<string, ServedBundle>, heldLevels?: HeldLevels): DocumentWriterProjectionResponse | null;
30
30
  export {};
@@ -1,10 +1,12 @@
1
+ import { completeServedAccessManifestBundle, toServedAccessManifestBundle, } from "../util/index.js";
1
2
  import { ContainerWriterProjectionWireResponseSchema, isCitedContainerKekLevel, } from "./container.js";
2
3
  import { DocumentWriterProjectionWireResponseSchema, } from "./documentMutation.js";
3
4
  /**
4
5
  * Collects each distinct manifest once. Every slot a server fills for one
5
6
  * hash comes from the same stored row, and the client verifies the bundle it
6
7
  * receives wherever that hash is cited, so the first occurrence stands. A
7
- * hash the request declared known is cited but not served.
8
+ * hash the request declared known is cited but not served. A served bundle's
9
+ * state leaves out what its own signed bytes name; decoding fills it back.
8
10
  */
9
11
  function bundleCitations(known) {
10
12
  const byHash = new Map();
@@ -15,7 +17,7 @@ function bundleCitations(known) {
15
17
  if (known.has(hash))
16
18
  omitted.add(hash);
17
19
  else if (!byHash.has(hash))
18
- byHash.set(hash, bundle);
20
+ byHash.set(hash, toServedAccessManifestBundle(bundle));
19
21
  return hash;
20
22
  },
21
23
  // fromEntries defines own data properties, even for a "__proto__" key.
@@ -83,16 +85,17 @@ export function encodeDocumentWriterProjection(projection, known = new Set(), he
83
85
  /**
84
86
  * Served bundles plus the exact held bytes for each omitted hash. An omission
85
87
  * the caller cannot fill from `held` (which carries only what its request
86
- * cited) makes the response unusable. Each cited position receives its own
88
+ * cited) makes the response unusable. Each bundle's state gets back the
89
+ * fields its own signed bytes name. Each cited position receives its own
87
90
  * copy, as when every slot carried its own JSON.
88
91
  */
89
92
  function bundleResolver(bundles, omittedBundles, held) {
90
- const byHash = new Map(Object.entries(bundles));
93
+ const byHash = new Map(Object.entries(bundles).map(([hash, bundle]) => [hash, completeServedAccessManifestBundle(bundle)]));
91
94
  for (const hash of omittedBundles) {
92
95
  const bundle = held.get(hash);
93
96
  if (bundle?.manifestHash !== hash)
94
97
  return null;
95
- byHash.set(hash, bundle);
98
+ byHash.set(hash, completeServedAccessManifestBundle(bundle));
96
99
  }
97
100
  return (hash) => {
98
101
  const bundle = byHash.get(hash);
@@ -1 +1 @@
1
- {"version":3,"file":"writerProjectionWire.js","sourceRoot":"","sources":["writerProjectionWire.ts"],"names":[],"mappings":"AACA,OAAO,EAOL,2CAA2C,EAC3C,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAGL,0CAA0C,GAC3C,MAAM,oBAAoB,CAAC;AAK5B;;;;;GAKG;AACH,SAAS,eAAe,CAAC,KAA0B;IACjD,MAAM,MAAM,GAAG,IAAI,GAA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AC1C,CAAC;IACD,MAAM,CAAC,SAAS,EAAE,GAAG,UAAU,CAAC,GAAG,yBAAyB,CAAC;IAC7D,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAC5B,OAAO;QACL,GAAG,UAAU;QACb,yBAAyB,EAAE,CAAC,SAAS,EAAE,GAAG,UAAU,CAAC;QACrD,gCAAgC,EAC9B,UAAU,CAAC,gCAAgC,CAAC,GAAG,CAAC,OAAO,CAAC;QAC1D,gBAAgB,EAAE,OAAO,CAAC,UAAU,CAAC,gBAAgB,CAAC;QACtD,8BAA8B,EAC5B,UAAU,CAAC,8BAA8B,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACrD,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAClB;QACH,uBAAuB,EAAE,UAAU,CAAC,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAC;KACzE,CAAC;AACJ,CAAC","sourcesContent":["import type { AccessManifestBundleWireResponse } from \"../util\";\nimport {\n type ContainerKekResponse,\n type ContainerKekWireLevel,\n type ContainerKeyingPathResponse,\n type ContainerKeyingPathWireResponse,\n type ContainerWriterProjectionResponse,\n type ContainerWriterProjectionWireResponse,\n ContainerWriterProjectionWireResponseSchema,\n isCitedContainerKekLevel,\n} from \"./container\";\nimport {\n type DocumentWriterProjectionResponse,\n type DocumentWriterProjectionWireResponse,\n DocumentWriterProjectionWireResponseSchema,\n} from \"./documentMutation\";\n\ntype Bundle = AccessManifestBundleWireResponse;\ntype HeldLevels = ReadonlyMap<string, ContainerKekWireLevel>;\n\n/**\n * Collects each distinct manifest once. Every slot a server fills for one\n * hash comes from the same stored row, and the client verifies the bundle it\n * receives wherever that hash is cited, so the first occurrence stands. A\n * hash the request declared known is cited but not served.\n */\nfunction bundleCitations(known: ReadonlySet<string>) {\n const byHash = new Map<string, Bundle>();\n const omitted = new Set<string>();\n return {\n cite(bundle: Bundle): string {\n const hash = bundle.manifestHash;\n if (known.has(hash)) omitted.add(hash);\n else if (!byHash.has(hash)) byHash.set(hash, bundle);\n return hash;\n },\n // fromEntries defines own data properties, even for a \"__proto__\" key.\n bundles: (): Record<string, Bundle> => Object.fromEntries(byHash),\n omitted: (): string[] => [...omitted],\n };\n}\n\n/** A KEK level's wire form: its manifest history cited by hash. */\nexport function containerKekWireLevel(\n kek: ContainerKekResponse,\n): ContainerKekWireLevel {\n return {\n ...kek,\n containerManifestHistory: kek.containerManifestHistory.map(\n (bundle) => bundle.manifestHash,\n ),\n };\n}\n\n/**\n * The digest a request declared for a KEK level it holds, or null when the\n * level travels in full. The caller derives it from the level's own served\n * bytes, so a level is omitted only when the held copy is exactly these.\n */\nexport type HeldKekLevelDigest = (kek: ContainerKekResponse) => string | null;\n\nfunction encodeKeyingPath(\n path: ContainerKeyingPathResponse,\n cite: (bundle: Bundle) => string,\n heldLevel: HeldKekLevelDigest,\n): ContainerKeyingPathWireResponse {\n return {\n ...path,\n path: path.path.map(cite),\n containerKeks: path.containerKeks.map((kek) => {\n const level = {\n ...kek,\n containerManifestHistory: kek.containerManifestHistory.map(cite),\n };\n const levelDigest = heldLevel(kek);\n return levelDigest === null\n ? level\n : {\n levelDigest,\n containerManifestHistory: level.containerManifestHistory,\n };\n }),\n };\n}\n\nconst noHeldLevels: HeldKekLevelDigest = () => null;\n\n/**\n * Call only after authorization and stored-evidence verification. `known`\n * holds the request's manifest hints; only hashes this projection cites are\n * omitted. `heldLevel` names each KEK level the request holds exactly.\n */\nexport function encodeContainerWriterProjection(\n projection: ContainerWriterProjectionResponse,\n known: ReadonlySet<string> = new Set(),\n heldLevel: HeldKekLevelDigest = noHeldLevels,\n): ContainerWriterProjectionWireResponse {\n const citations = bundleCitations(known);\n const encoded = encodeKeyingPath(projection, citations.cite, heldLevel);\n return {\n ...projection,\n ...encoded,\n bundles: citations.bundles(),\n omittedBundles: citations.omitted(),\n };\n}\n\n/** See {@link encodeContainerWriterProjection}. */\nexport function encodeDocumentWriterProjection(\n projection: DocumentWriterProjectionResponse,\n known: ReadonlySet<string> = new Set(),\n heldLevel: HeldKekLevelDigest = noHeldLevels,\n): DocumentWriterProjectionWireResponse {\n const { cite, bundles, omitted } = bundleCitations(known);\n const authorizingContainerPaths = projection.authorizingContainerPaths.map(\n (path) => encodeKeyingPath(path, cite, heldLevel),\n );\n return {\n ...projection,\n authorizingContainerPaths,\n documentContainerManifestHistory:\n projection.documentContainerManifestHistory.map(cite),\n documentManifest: cite(projection.documentManifest),\n documentManifestContainerPaths:\n projection.documentManifestContainerPaths.map((path) => path.map(cite)),\n documentManifestHistory: projection.documentManifestHistory.map(cite),\n bundles: bundles(),\n omittedBundles: omitted(),\n };\n}\n\n/**\n * Served bundles plus the exact held bytes for each omitted hash. An omission\n * the caller cannot fill from `held` (which carries only what its request\n * cited) makes the response unusable. Each cited position receives its own\n * copy, as when every slot carried its own JSON.\n */\nfunction bundleResolver(\n bundles: Record<string, Bundle>,\n omittedBundles: readonly string[],\n held: ReadonlyMap<string, Bundle>,\n): ((hash: string) => Bundle) | null {\n const byHash = new Map(Object.entries(bundles));\n for (const hash of omittedBundles) {\n const bundle = held.get(hash);\n if (bundle?.manifestHash !== hash) return null;\n byHash.set(hash, bundle);\n }\n return (hash: string): Bundle => {\n const bundle = byHash.get(hash);\n if (!bundle) {\n throw new Error(`manifest ${hash} is cited without a bundle`);\n }\n return structuredClone(bundle);\n };\n}\n\nfunction sameHashes(left: readonly string[], right: readonly string[]) {\n return (\n left.length === right.length &&\n left.every((hash, index) => hash === right[index])\n );\n}\n\n/**\n * Each cited KEK level becomes its own copy of the exact held level this\n * request declared under that digest. A digest the request did not cite, or\n * a held level whose manifest citations differ from the stub's, makes the\n * path unusable: the caller refetches in full.\n */\nfunction fillKekLevels(\n path: ContainerKeyingPathWireResponse,\n heldLevels: HeldLevels,\n): ContainerKekWireLevel[] | null {\n const levels: ContainerKekWireLevel[] = [];\n for (const kek of path.containerKeks) {\n if (!isCitedContainerKekLevel(kek)) {\n levels.push(kek);\n continue;\n }\n const held = heldLevels.get(kek.levelDigest);\n if (\n !held ||\n !sameHashes(held.containerManifestHistory, kek.containerManifestHistory)\n )\n return null;\n levels.push(structuredClone(held));\n }\n return levels;\n}\n\nfunction decodeKeyingPath(\n path: ContainerKeyingPathWireResponse,\n resolve: (hash: string) => Bundle,\n heldLevels: HeldLevels,\n): ContainerKeyingPathResponse | null {\n const levels = fillKekLevels(path, heldLevels);\n if (!levels) return null;\n return {\n ...path,\n path: path.path.map(resolve),\n containerKeks: levels.map((kek) => ({\n ...kek,\n containerManifestHistory: kek.containerManifestHistory.map(resolve),\n })),\n };\n}\n\n/**\n * Null for any wire inconsistency or an omission `held` (bundles) or\n * `heldLevels` (KEK levels by digest) cannot fill; the caller treats either\n * as a shape failure.\n */\nexport function decodeContainerWriterProjection(\n value: unknown,\n held: ReadonlyMap<string, Bundle> = new Map(),\n heldLevels: HeldLevels = new Map(),\n): ContainerWriterProjectionResponse | null {\n const parsed = ContainerWriterProjectionWireResponseSchema.safeParse(value);\n if (!parsed.success) {\n return null;\n }\n const { bundles, omittedBundles, ...projection } = parsed.data;\n const resolve = bundleResolver(bundles, omittedBundles, held);\n const path = resolve\n ? decodeKeyingPath(projection, resolve, heldLevels)\n : null;\n return path ? { ...projection, ...path } : null;\n}\n\n/** See {@link decodeContainerWriterProjection}. */\nexport function decodeDocumentWriterProjection(\n value: unknown,\n held: ReadonlyMap<string, Bundle> = new Map(),\n heldLevels: HeldLevels = new Map(),\n): DocumentWriterProjectionResponse | null {\n const parsed = DocumentWriterProjectionWireResponseSchema.safeParse(value);\n if (!parsed.success) {\n return null;\n }\n const { bundles, omittedBundles, ...projection } = parsed.data;\n const resolve = bundleResolver(bundles, omittedBundles, held);\n if (!resolve) {\n return null;\n }\n const authorizingContainerPaths: ContainerKeyingPathResponse[] = [];\n for (const path of projection.authorizingContainerPaths) {\n const decoded = decodeKeyingPath(path, resolve, heldLevels);\n if (!decoded) return null;\n authorizingContainerPaths.push(decoded);\n }\n const [firstPath, ...otherPaths] = authorizingContainerPaths;\n if (!firstPath) return null;\n return {\n ...projection,\n authorizingContainerPaths: [firstPath, ...otherPaths],\n documentContainerManifestHistory:\n projection.documentContainerManifestHistory.map(resolve),\n documentManifest: resolve(projection.documentManifest),\n documentManifestContainerPaths:\n projection.documentManifestContainerPaths.map((path) =>\n path.map(resolve),\n ),\n documentManifestHistory: projection.documentManifestHistory.map(resolve),\n };\n}\n"]}
1
+ {"version":3,"file":"writerProjectionWire.js","sourceRoot":"","sources":["writerProjectionWire.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kCAAkC,EAElC,4BAA4B,GAC7B,MAAM,SAAS,CAAC;AACjB,OAAO,EAOL,2CAA2C,EAC3C,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAGL,0CAA0C,GAC3C,MAAM,oBAAoB,CAAC;AAM5B;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,KAA0B;IACjD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC/C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,OAAO;QACL,IAAI,CAAC,MAAc;YACjB,MAAM,IAAI,GAAG,MAAM,CAAC,YAAY,CAAC;YACjC,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;iBAClC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;gBACxB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,4BAA4B,CAAC,MAAM,CAAC,CAAC,CAAC;YACzD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,uEAAuE;QACvE,OAAO,EAAE,GAAiC,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC;QACvE,OAAO,EAAE,GAAa,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC;KACtC,CAAC;AACJ,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,qBAAqB,CACnC,GAA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C,CAClB;QACH,uBAAuB,EAAE,UAAU,CAAC,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAC;KACzE,CAAC;AACJ,CAAC","sourcesContent":["import {\n type AccessManifestBundleWireResponse,\n completeServedAccessManifestBundle,\n type ServedAccessManifestBundleWireResponse,\n toServedAccessManifestBundle,\n} from \"../util\";\nimport {\n type ContainerKekResponse,\n type ContainerKekWireLevel,\n type ContainerKeyingPathResponse,\n type ContainerKeyingPathWireResponse,\n type ContainerWriterProjectionResponse,\n type ContainerWriterProjectionWireResponse,\n ContainerWriterProjectionWireResponseSchema,\n isCitedContainerKekLevel,\n} from \"./container\";\nimport {\n type DocumentWriterProjectionResponse,\n type DocumentWriterProjectionWireResponse,\n DocumentWriterProjectionWireResponseSchema,\n} from \"./documentMutation\";\n\ntype Bundle = AccessManifestBundleWireResponse;\ntype ServedBundle = ServedAccessManifestBundleWireResponse;\ntype HeldLevels = ReadonlyMap<string, ContainerKekWireLevel>;\n\n/**\n * Collects each distinct manifest once. Every slot a server fills for one\n * hash comes from the same stored row, and the client verifies the bundle it\n * receives wherever that hash is cited, so the first occurrence stands. A\n * hash the request declared known is cited but not served. A served bundle's\n * state leaves out what its own signed bytes name; decoding fills it back.\n */\nfunction bundleCitations(known: ReadonlySet<string>) {\n const byHash = new Map<string, ServedBundle>();\n const omitted = new Set<string>();\n return {\n cite(bundle: Bundle): string {\n const hash = bundle.manifestHash;\n if (known.has(hash)) omitted.add(hash);\n else if (!byHash.has(hash))\n byHash.set(hash, toServedAccessManifestBundle(bundle));\n return hash;\n },\n // fromEntries defines own data properties, even for a \"__proto__\" key.\n bundles: (): Record<string, ServedBundle> => Object.fromEntries(byHash),\n omitted: (): string[] => [...omitted],\n };\n}\n\n/** A KEK level's wire form: its manifest history cited by hash. */\nexport function containerKekWireLevel(\n kek: ContainerKekResponse,\n): ContainerKekWireLevel {\n return {\n ...kek,\n containerManifestHistory: kek.containerManifestHistory.map(\n (bundle) => bundle.manifestHash,\n ),\n };\n}\n\n/**\n * The digest a request declared for a KEK level it holds, or null when the\n * level travels in full. The caller derives it from the level's own served\n * bytes, so a level is omitted only when the held copy is exactly these.\n */\nexport type HeldKekLevelDigest = (kek: ContainerKekResponse) => string | null;\n\nfunction encodeKeyingPath(\n path: ContainerKeyingPathResponse,\n cite: (bundle: Bundle) => string,\n heldLevel: HeldKekLevelDigest,\n): ContainerKeyingPathWireResponse {\n return {\n ...path,\n path: path.path.map(cite),\n containerKeks: path.containerKeks.map((kek) => {\n const level = {\n ...kek,\n containerManifestHistory: kek.containerManifestHistory.map(cite),\n };\n const levelDigest = heldLevel(kek);\n return levelDigest === null\n ? level\n : {\n levelDigest,\n containerManifestHistory: level.containerManifestHistory,\n };\n }),\n };\n}\n\nconst noHeldLevels: HeldKekLevelDigest = () => null;\n\n/**\n * Call only after authorization and stored-evidence verification. `known`\n * holds the request's manifest hints; only hashes this projection cites are\n * omitted. `heldLevel` names each KEK level the request holds exactly.\n */\nexport function encodeContainerWriterProjection(\n projection: ContainerWriterProjectionResponse,\n known: ReadonlySet<string> = new Set(),\n heldLevel: HeldKekLevelDigest = noHeldLevels,\n): ContainerWriterProjectionWireResponse {\n const citations = bundleCitations(known);\n const encoded = encodeKeyingPath(projection, citations.cite, heldLevel);\n return {\n ...projection,\n ...encoded,\n bundles: citations.bundles(),\n omittedBundles: citations.omitted(),\n };\n}\n\n/** See {@link encodeContainerWriterProjection}. */\nexport function encodeDocumentWriterProjection(\n projection: DocumentWriterProjectionResponse,\n known: ReadonlySet<string> = new Set(),\n heldLevel: HeldKekLevelDigest = noHeldLevels,\n): DocumentWriterProjectionWireResponse {\n const { cite, bundles, omitted } = bundleCitations(known);\n const authorizingContainerPaths = projection.authorizingContainerPaths.map(\n (path) => encodeKeyingPath(path, cite, heldLevel),\n );\n return {\n ...projection,\n authorizingContainerPaths,\n documentContainerManifestHistory:\n projection.documentContainerManifestHistory.map(cite),\n documentManifest: cite(projection.documentManifest),\n documentManifestContainerPaths:\n projection.documentManifestContainerPaths.map((path) => path.map(cite)),\n documentManifestHistory: projection.documentManifestHistory.map(cite),\n bundles: bundles(),\n omittedBundles: omitted(),\n };\n}\n\n/**\n * Served bundles plus the exact held bytes for each omitted hash. An omission\n * the caller cannot fill from `held` (which carries only what its request\n * cited) makes the response unusable. Each bundle's state gets back the\n * fields its own signed bytes name. Each cited position receives its own\n * copy, as when every slot carried its own JSON.\n */\nfunction bundleResolver(\n bundles: Record<string, ServedBundle>,\n omittedBundles: readonly string[],\n held: ReadonlyMap<string, ServedBundle>,\n): ((hash: string) => Bundle) | null {\n const byHash = new Map(\n Object.entries(bundles).map(\n ([hash, bundle]) =>\n [hash, completeServedAccessManifestBundle(bundle)] as const,\n ),\n );\n for (const hash of omittedBundles) {\n const bundle = held.get(hash);\n if (bundle?.manifestHash !== hash) return null;\n byHash.set(hash, completeServedAccessManifestBundle(bundle));\n }\n return (hash: string): Bundle => {\n const bundle = byHash.get(hash);\n if (!bundle) {\n throw new Error(`manifest ${hash} is cited without a bundle`);\n }\n return structuredClone(bundle);\n };\n}\n\nfunction sameHashes(left: readonly string[], right: readonly string[]) {\n return (\n left.length === right.length &&\n left.every((hash, index) => hash === right[index])\n );\n}\n\n/**\n * Each cited KEK level becomes its own copy of the exact held level this\n * request declared under that digest. A digest the request did not cite, or\n * a held level whose manifest citations differ from the stub's, makes the\n * path unusable: the caller refetches in full.\n */\nfunction fillKekLevels(\n path: ContainerKeyingPathWireResponse,\n heldLevels: HeldLevels,\n): ContainerKekWireLevel[] | null {\n const levels: ContainerKekWireLevel[] = [];\n for (const kek of path.containerKeks) {\n if (!isCitedContainerKekLevel(kek)) {\n levels.push(kek);\n continue;\n }\n const held = heldLevels.get(kek.levelDigest);\n if (\n !held ||\n !sameHashes(held.containerManifestHistory, kek.containerManifestHistory)\n )\n return null;\n levels.push(structuredClone(held));\n }\n return levels;\n}\n\nfunction decodeKeyingPath(\n path: ContainerKeyingPathWireResponse,\n resolve: (hash: string) => Bundle,\n heldLevels: HeldLevels,\n): ContainerKeyingPathResponse | null {\n const levels = fillKekLevels(path, heldLevels);\n if (!levels) return null;\n return {\n ...path,\n path: path.path.map(resolve),\n containerKeks: levels.map((kek) => ({\n ...kek,\n containerManifestHistory: kek.containerManifestHistory.map(resolve),\n })),\n };\n}\n\n/**\n * Null for any wire inconsistency or an omission `held` (bundles) or\n * `heldLevels` (KEK levels by digest) cannot fill; the caller treats either\n * as a shape failure.\n */\nexport function decodeContainerWriterProjection(\n value: unknown,\n held: ReadonlyMap<string, ServedBundle> = new Map(),\n heldLevels: HeldLevels = new Map(),\n): ContainerWriterProjectionResponse | null {\n const parsed = ContainerWriterProjectionWireResponseSchema.safeParse(value);\n if (!parsed.success) {\n return null;\n }\n const { bundles, omittedBundles, ...projection } = parsed.data;\n const resolve = bundleResolver(bundles, omittedBundles, held);\n const path = resolve\n ? decodeKeyingPath(projection, resolve, heldLevels)\n : null;\n return path ? { ...projection, ...path } : null;\n}\n\n/** See {@link decodeContainerWriterProjection}. */\nexport function decodeDocumentWriterProjection(\n value: unknown,\n held: ReadonlyMap<string, ServedBundle> = new Map(),\n heldLevels: HeldLevels = new Map(),\n): DocumentWriterProjectionResponse | null {\n const parsed = DocumentWriterProjectionWireResponseSchema.safeParse(value);\n if (!parsed.success) {\n return null;\n }\n const { bundles, omittedBundles, ...projection } = parsed.data;\n const resolve = bundleResolver(bundles, omittedBundles, held);\n if (!resolve) {\n return null;\n }\n const authorizingContainerPaths: ContainerKeyingPathResponse[] = [];\n for (const path of projection.authorizingContainerPaths) {\n const decoded = decodeKeyingPath(path, resolve, heldLevels);\n if (!decoded) return null;\n authorizingContainerPaths.push(decoded);\n }\n const [firstPath, ...otherPaths] = authorizingContainerPaths;\n if (!firstPath) return null;\n return {\n ...projection,\n authorizingContainerPaths: [firstPath, ...otherPaths],\n documentContainerManifestHistory:\n projection.documentContainerManifestHistory.map(resolve),\n documentManifest: resolve(projection.documentManifest),\n documentManifestContainerPaths:\n projection.documentManifestContainerPaths.map((path) =>\n path.map(resolve),\n ),\n documentManifestHistory: projection.documentManifestHistory.map(resolve),\n };\n}\n"]}
@@ -11,6 +11,7 @@ export { isOrganizationReplacementAuthorization, type OrganizationReplacementAut
11
11
  export { PRINCIPAL_POLICY_HISTORY_PAGE_LIMIT, PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT, } from "./principalHistoryWire.js";
12
12
  export { hasArrayProperty, hasBooleanProperty, hasNonEmptyStringProperty, hasNullableNumberProperty, hasNullableStringProperty, hasNumberProperty, hasObjectProperty, hasOptionalStringProperty, hasPositiveIntegerProperty, hasPropertyValue, hasStringProperty, isNonEmptyStringArray, isOptionalRecordArray, isOptionalRecordArrayArray, isRecordArray, isRecordArrayArray, isStringArray, } from "./properties.js";
13
13
  export { AUTH_CHALLENGE_HEX_LENGTH, base64Length, canonicalBase64Pattern, isAuthChallengeHexString, isCanonicalBase64OfLength, isSha256HexString, ML_DSA87_PUBLIC_KEY_BYTES, ML_DSA87_SIGNATURE_BYTES, ML_KEM1024_PUBLIC_KEY_BYTES, SHA256_HEX_LENGTH, } from "./protocol.js";
14
+ export { completeServedAccessManifestBundle, isServedAccessManifestBundleWireResponse, type ServedAccessManifestBundleWireResponse, ServedAccessManifestBundleWireResponseSchema, type ServedManifestState, toServedAccessManifestBundle, } from "./servedManifestBundle.js";
14
15
  export { CANONICAL_SIGNED_AT_PATTERN, isCanonicalSignedAt, MAX_SIGNED_AT_YEAR, MIN_SIGNED_AT_YEAR, SIGNED_AT_CONTRACT, } from "./signedAt.js";
15
16
  export { isUuidV4String } from "./uuid.js";
16
17
  export { isWalLsnString, parseWalLsn } from "./walLsn.js";