@tearleads/client-sdk 0.1.69 → 0.1.72

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 (102) hide show
  1. package/data/shared/userTiming.js +42 -0
  2. package/data/shared/userTiming.js.map +1 -0
  3. package/data/sqlite/sqlExec.js +27 -3
  4. package/data/sqlite/sqlExec.js.map +1 -1
  5. package/data/sync/coordinatorLaneRun.js +29 -6
  6. package/data/sync/coordinatorLaneRun.js.map +1 -1
  7. package/data/sync/coordinatorState.d.ts +3 -1
  8. package/data/sync/coordinatorState.js +1 -0
  9. package/data/sync/coordinatorState.js.map +1 -1
  10. package/data/sync/syncTelemetry.d.ts +15 -0
  11. package/data/sync/syncTelemetry.js +10 -0
  12. package/data/sync/syncTelemetry.js.map +1 -1
  13. package/data/sync/uploadLane.js +20 -3
  14. package/data/sync/uploadLane.js.map +1 -1
  15. package/internal/api-client/ApiClient.d.ts +73 -3
  16. package/internal/api-client/apiRequestMetrics.d.ts +18 -4
  17. package/internal/api-client/apiRequestMetrics.js +55 -5
  18. package/internal/api-client/apiRequestMetrics.js.map +1 -1
  19. package/internal/api-client/durationSampleWindow.d.ts +26 -0
  20. package/internal/api-client/durationSampleWindow.js +42 -0
  21. package/internal/api-client/durationSampleWindow.js.map +1 -0
  22. package/internal/api-client/measureApiRequest.js +9 -4
  23. package/internal/api-client/measureApiRequest.js.map +1 -1
  24. package/internal/api-client/serverTiming.d.ts +12 -0
  25. package/internal/api-client/serverTiming.js +49 -0
  26. package/internal/api-client/serverTiming.js.map +1 -0
  27. package/internal/validators/documentCreateSeedRefinements.js +9 -0
  28. package/internal/validators/documentCreateSeedRefinements.js.map +1 -0
  29. package/internal/validators/operation/auth.d.ts +120 -0
  30. package/internal/validators/operation/containerMutations.d.ts +355 -0
  31. package/internal/validators/operation/containerMutations.js +7 -1
  32. package/internal/validators/operation/containerMutations.js.map +1 -1
  33. package/internal/validators/operation/documentMutations.d.ts +356 -0
  34. package/internal/validators/operation/documentMutations.js +6 -1
  35. package/internal/validators/operation/documentMutations.js.map +1 -1
  36. package/internal/validators/operation/documentSync.d.ts +9 -9
  37. package/internal/validators/operation/organizations.d.ts +120 -0
  38. package/internal/validators/request/containerMetadata.d.ts +313 -0
  39. package/internal/validators/request/containerMetadata.js +20 -3
  40. package/internal/validators/request/containerMetadata.js.map +1 -1
  41. package/internal/validators/request/document.d.ts +571 -0
  42. package/internal/validators/request/document.js +19 -1
  43. package/internal/validators/request/document.js.map +1 -1
  44. package/internal/validators/request/documentCreateSeed.js +35 -0
  45. package/internal/validators/request/documentCreateSeed.js.map +1 -0
  46. package/internal/validators/request/organizationProvisioning.js +9 -22
  47. package/internal/validators/request/organizationProvisioning.js.map +1 -1
  48. package/internal/validators/response/containerMetadata.d.ts +20 -0
  49. package/internal/validators/response/documentMutation.d.ts +43 -0
  50. package/internal/validators/response/documentMutation.js +12 -1
  51. package/internal/validators/response/documentMutation.js.map +1 -1
  52. package/internal/validators/response/documentSyncSchema.d.ts +13 -9
  53. package/internal/validators/response/documentSyncSchema.js +23 -18
  54. package/internal/validators/response/documentSyncSchema.js.map +1 -1
  55. package/internal/validators/response/index.d.ts +1 -1
  56. package/internal/validators/response/index.js.map +1 -1
  57. package/internal/validators/response/organizationProvisioning.d.ts +350 -0
  58. package/internal/validators/response/registration.d.ts +120 -0
  59. package/package.json +1 -1
  60. package/stores/container-contents/containerState/containerStatePersistence.js +2 -0
  61. package/stores/container-contents/containerState/containerStatePersistence.js.map +1 -1
  62. package/stores/container-contents/remoteEvents/remoteEventSync.js +1 -1
  63. package/stores/container-contents/remoteEvents/remoteEventSync.js.map +1 -1
  64. package/stores/container-contents/state.js +2 -0
  65. package/stores/container-contents/state.js.map +1 -1
  66. package/stores/container-contents/syncAgent/syncAgentTypes.d.ts +5 -0
  67. package/stores/container-contents/syncAgent/syncAgentTypes.js.map +1 -1
  68. package/stores/documents/documentStore/sync/createdDocumentPersistence.js +71 -0
  69. package/stores/documents/documentStore/sync/createdDocumentPersistence.js.map +1 -0
  70. package/stores/documents/documentStore/sync/index.js +13 -2
  71. package/stores/documents/documentStore/sync/index.js.map +1 -1
  72. package/stores/documents/documentStore/sync/syncRemoteSignals.js +21 -3
  73. package/stores/documents/documentStore/sync/syncRemoteSignals.js.map +1 -1
  74. package/stores/documents/documentStore/sync/syncSeededCreate.js +50 -0
  75. package/stores/documents/documentStore/sync/syncSeededCreate.js.map +1 -0
  76. package/stores/documents/documentStore/sync/syncShared.js +16 -8
  77. package/stores/documents/documentStore/sync/syncShared.js.map +1 -1
  78. package/workflows/container-contents/container-state/create/createIntentSeed.js +60 -0
  79. package/workflows/container-contents/container-state/create/createIntentSeed.js.map +1 -0
  80. package/workflows/container-contents/container-state/create/createIntentSync.js +18 -19
  81. package/workflows/container-contents/container-state/create/createIntentSync.js.map +1 -1
  82. package/workflows/container-contents/container-state/create/createWithMetadata.js +43 -6
  83. package/workflows/container-contents/container-state/create/createWithMetadata.js.map +1 -1
  84. package/workflows/container-contents/container-state/create/createWithMetadataPlan.js +5 -1
  85. package/workflows/container-contents/container-state/create/createWithMetadataPlan.js.map +1 -1
  86. package/workflows/container-contents/container-state/remote.js +15 -0
  87. package/workflows/container-contents/container-state/remote.js.map +1 -1
  88. package/workflows/container-contents/container-state/types.js.map +1 -1
  89. package/workflows/container-contents/metadata/metadataEvents.d.ts +7 -1
  90. package/workflows/container-contents/metadata/metadataEvents.js +8 -2
  91. package/workflows/container-contents/metadata/metadataEvents.js.map +1 -1
  92. package/workflows/container-contents/remoteHydration/types.d.ts +3 -0
  93. package/workflows/container-contents/remoteHydration/types.js.map +1 -1
  94. package/workflows/documents/create/index.d.ts +7 -0
  95. package/workflows/documents/create/index.js +40 -2
  96. package/workflows/documents/create/index.js.map +1 -1
  97. package/workflows/documents/index.d.ts +1 -0
  98. package/workflows/documents/index.js +1 -0
  99. package/workflows/documents/index.js.map +1 -1
  100. package/workflows/documents/sync/initialSync.d.ts +39 -0
  101. package/workflows/documents/sync/initialSync.js +39 -6
  102. package/workflows/documents/sync/initialSync.js.map +1 -1
@@ -0,0 +1,35 @@
1
+ import { MAX_DOCUMENT_SYNC_REQUEST_BYTES } from "../util/documentSyncLimits.js";
2
+ const TEXT_ENCODER = new TextEncoder();
3
+ /**
4
+ * A seed is the one update a document is born with, committed in its create
5
+ * transaction: exactly one outgoing update and no container rekeys.
6
+ */
7
+ export function refineSingleUpdateSeed(seed, context, issue) {
8
+ if (!Array.isArray(seed?.outgoingUpdates)) {
9
+ return;
10
+ }
11
+ if (seed.outgoingUpdates.length !== 1 ||
12
+ (seed.containerRekeys?.length ?? 0) !== 0) {
13
+ context.addIssue({
14
+ code: "custom",
15
+ message: issue.message,
16
+ path: [issue.path],
17
+ });
18
+ }
19
+ }
20
+ /**
21
+ * A create seed stands in for the document's first sync, so it is held to the
22
+ * sync request limit the create route's larger ingress ceiling would not apply.
23
+ */
24
+ export function refineSeedWithinSyncRequestLimit(seed, context, path) {
25
+ if (seed !== undefined &&
26
+ TEXT_ENCODER.encode(JSON.stringify(seed)).byteLength >
27
+ MAX_DOCUMENT_SYNC_REQUEST_BYTES) {
28
+ context.addIssue({
29
+ code: "custom",
30
+ message: `create seed exceeds ${MAX_DOCUMENT_SYNC_REQUEST_BYTES} serialized bytes`,
31
+ path: [path],
32
+ });
33
+ }
34
+ }
35
+ //# sourceMappingURL=documentCreateSeed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentCreateSeed.js","sourceRoot":"","sources":["documentCreateSeed.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAAE,MAAM,4BAA4B,CAAC;AAG7E,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,IAAqC,EACrC,OAAwB,EACxB,KAA0D;IAE1D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE,CAAC;QAC1C,OAAO;IACT,CAAC;IACD,IACE,IAAI,CAAC,eAAe,CAAC,MAAM,KAAK,CAAC;QACjC,CAAC,IAAI,CAAC,eAAe,EAAE,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,EACzC,CAAC;QACD,OAAO,CAAC,QAAQ,CAAC;YACf,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;SACnB,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAC9C,IAAqC,EACrC,OAAwB,EACxB,IAAY;IAEZ,IACE,IAAI,KAAK,SAAS;QAClB,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU;YAClD,+BAA+B,EACjC,CAAC;QACD,OAAO,CAAC,QAAQ,CAAC;YACf,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,uBAAuB,+BAA+B,mBAAmB;YAClF,IAAI,EAAE,CAAC,IAAI,CAAC;SACb,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type { z } from \"zod\";\nimport { MAX_DOCUMENT_SYNC_REQUEST_BYTES } from \"../util/documentSyncLimits\";\nimport type { DocumentSyncRequest } from \"./documentSyncSchema\";\n\nconst TEXT_ENCODER = new TextEncoder();\n\n/**\n * A seed is the one update a document is born with, committed in its create\n * transaction: exactly one outgoing update and no container rekeys.\n */\nexport function refineSingleUpdateSeed(\n seed: DocumentSyncRequest | undefined,\n context: z.RefinementCtx,\n issue: { readonly message: string; readonly path: string },\n): void {\n if (!Array.isArray(seed?.outgoingUpdates)) {\n return;\n }\n if (\n seed.outgoingUpdates.length !== 1 ||\n (seed.containerRekeys?.length ?? 0) !== 0\n ) {\n context.addIssue({\n code: \"custom\",\n message: issue.message,\n path: [issue.path],\n });\n }\n}\n\n/**\n * A create seed stands in for the document's first sync, so it is held to the\n * sync request limit the create route's larger ingress ceiling would not apply.\n */\nexport function refineSeedWithinSyncRequestLimit(\n seed: DocumentSyncRequest | undefined,\n context: z.RefinementCtx,\n path: string,\n): void {\n if (\n seed !== undefined &&\n TEXT_ENCODER.encode(JSON.stringify(seed)).byteLength >\n MAX_DOCUMENT_SYNC_REQUEST_BYTES\n ) {\n context.addIssue({\n code: \"custom\",\n message: `create seed exceeds ${MAX_DOCUMENT_SYNC_REQUEST_BYTES} serialized bytes`,\n path: [path],\n });\n }\n}\n"]}
@@ -6,6 +6,7 @@ import { OrganizationReplacementAuthorizationSchema } from "../util/organization
6
6
  import { ContainerMutationRequestSchema } from "./container.js";
7
7
  import { containerCreateWithMetadataDocumentRequestShape } from "./containerMetadata.js";
8
8
  import { DocumentSyncRequestSchema, documentCreateRequestShape, } from "./document.js";
9
+ import { refineSingleUpdateSeed } from "./documentCreateSeed.js";
9
10
  import { CreateOrganizationGroupRequestSchema } from "./organization.js";
10
11
  import { OrganizationPrincipalPolicyRequestSchema } from "./principal.js";
11
12
  /**
@@ -26,30 +27,16 @@ const provisionedDocumentRequestShape = {
26
27
  initialSync: DocumentSyncRequestSchema,
27
28
  };
28
29
  export const ProvisionedDocumentRequestSchema = registerJsonSchemaRuntimeRefinements(loosePlainObject(provisionedDocumentRequestShape).superRefine((value, context) => {
29
- if (!Array.isArray(value.initialSync?.outgoingUpdates)) {
30
- return;
31
- }
32
- if (value.initialSync.outgoingUpdates.length !== 1 ||
33
- (value.initialSync.containerRekeys?.length ?? 0) !== 0) {
34
- context.addIssue({
35
- code: "custom",
36
- message: "provisioned document seed requires one update and no container rekeys",
37
- path: ["initialSync"],
38
- });
39
- }
30
+ refineSingleUpdateSeed(value.initialSync, context, {
31
+ message: "provisioned document seed requires one update and no container rekeys",
32
+ path: "initialSync",
33
+ });
40
34
  }), [organizationProvisioningDocumentSeedRefinement]);
41
35
  export const ProvisionedSystemContainerRequestSchema = registerJsonSchemaRuntimeRefinements(loosePlainObject(provisionedSystemContainerRequestShape).superRefine((value, context) => {
42
- if (!Array.isArray(value.initialMetadataSync?.outgoingUpdates)) {
43
- return;
44
- }
45
- if (value.initialMetadataSync.outgoingUpdates.length !== 1 ||
46
- (value.initialMetadataSync.containerRekeys?.length ?? 0) !== 0) {
47
- context.addIssue({
48
- code: "custom",
49
- message: "provisioned system-container metadata seed requires one update and no container rekeys",
50
- path: ["initialMetadataSync"],
51
- });
52
- }
36
+ refineSingleUpdateSeed(value.initialMetadataSync, context, {
37
+ message: "provisioned system-container metadata seed requires one update and no container rekeys",
38
+ path: "initialMetadataSync",
39
+ });
53
40
  }), [organizationProvisioningContainerSeedRefinement]);
54
41
  export function isProvisionedDocumentRequest(value) {
55
42
  return ProvisionedDocumentRequestSchema.safeParse(value).success;
@@ -1 +1 @@
1
- {"version":3,"file":"organizationProvisioning.js","sourceRoot":"","sources":["organizationProvisioning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,oCAAoC,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,+CAA+C,EAC/C,8CAA8C,GAC/C,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,0CAA0C,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,+CAA+C,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EACL,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oCAAoC,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,wCAAwC,EAAE,MAAM,aAAa,CAAC;AAEvE;;;;GAIG;AACH,MAAM,sCAAsC,GAAG;IAC7C,GAAG,+CAA+C;IAClD,mBAAmB,EAAE,yBAAyB;CAC/C,CAAC;AAEF;;;GAG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CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE;IACrD;;;;;OAKG;IACH,mBAAmB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC3C;;;;OAIG;IACH,sBAAsB,EAAE,kBAAkB,CAAC,QAAQ,EAAE;CACtD,CAAC,CAAC;AAMH,MAAM,UAAU,2BAA2B,CACzC,KAAc;IAEd,OAAO,+BAA+B,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAClE,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport {\n organizationProvisioningContainerSeedRefinement,\n organizationProvisioningDocumentSeedRefinement,\n} from \"../organizationProvisioningRefinements\";\nimport { arraySchema, loosePlainObject, uuidV4StringSchema } from \"../schema\";\nimport { OrganizationReplacementAuthorizationSchema } from \"../util/organizationReplacement\";\nimport { ContainerMutationRequestSchema } from \"./container\";\nimport { containerCreateWithMetadataDocumentRequestShape } from \"./containerMetadata\";\nimport {\n DocumentSyncRequestSchema,\n documentCreateRequestShape,\n} from \"./document\";\nimport { CreateOrganizationGroupRequestSchema } from \"./organization\";\nimport { OrganizationPrincipalPolicyRequestSchema } from \"./principal\";\n\n/**\n * A built-in or app-owned system container whose encrypted initial metadata\n * body is committed in the same transaction as the organization and document\n * shell.\n */\nconst provisionedSystemContainerRequestShape = {\n ...containerCreateWithMetadataDocumentRequestShape,\n initialMetadataSync: DocumentSyncRequestSchema,\n};\n\n/**\n * A document whose encrypted initial body is committed with its manifest in the\n * organization-provisioning transaction.\n */\nconst provisionedDocumentRequestShape = {\n ...documentCreateRequestShape,\n initialSync: DocumentSyncRequestSchema,\n};\n\nexport const ProvisionedDocumentRequestSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject(provisionedDocumentRequestShape).superRefine(\n (value, context) => {\n if (!Array.isArray(value.initialSync?.outgoingUpdates)) {\n return;\n }\n if (\n value.initialSync.outgoingUpdates.length !== 1 ||\n (value.initialSync.containerRekeys?.length ?? 0) !== 0\n ) {\n context.addIssue({\n code: \"custom\",\n message:\n \"provisioned document seed requires one update and no container rekeys\",\n path: [\"initialSync\"],\n });\n }\n },\n ),\n [organizationProvisioningDocumentSeedRefinement],\n );\n\nexport type ProvisionedDocumentRequest = z.infer<\n typeof ProvisionedDocumentRequestSchema\n>;\n\nexport const ProvisionedSystemContainerRequestSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject(provisionedSystemContainerRequestShape).superRefine(\n (value, context) => {\n if (!Array.isArray(value.initialMetadataSync?.outgoingUpdates)) {\n return;\n }\n if (\n value.initialMetadataSync.outgoingUpdates.length !== 1 ||\n (value.initialMetadataSync.containerRekeys?.length ?? 0) !== 0\n ) {\n context.addIssue({\n code: \"custom\",\n message:\n \"provisioned system-container metadata seed requires one update and no container rekeys\",\n path: [\"initialMetadataSync\"],\n });\n }\n },\n ),\n [organizationProvisioningContainerSeedRefinement],\n );\n\nexport type ProvisionedSystemContainerRequest = z.infer<\n typeof ProvisionedSystemContainerRequestSchema\n>;\n\nexport function isProvisionedDocumentRequest(\n value: unknown,\n): value is ProvisionedDocumentRequest {\n return ProvisionedDocumentRequestSchema.safeParse(value).success;\n}\n\nexport function isProvisionedSystemContainerRequest(\n value: unknown,\n): value is ProvisionedSystemContainerRequest {\n return ProvisionedSystemContainerRequestSchema.safeParse(value).success;\n}\n\n/**\n * The client-signed artifacts required to bootstrap a fresh organization: the\n * organization + admin/member group policies, the signed root container and its\n * metadata document, the organization metadata root, and the optional\n * roster/organization profile documents.\n *\n * This is the shared shape between user registration (which bootstraps the\n * user's personal organization) and creating an additional organization for an\n * existing user. Registration additionally carries the new user's public key\n * material (see {@link RegistrationRequest}); creating an additional\n * organization reuses the caller's existing keys, so it needs only this base.\n */\nexport const organizationProvisioningRequestShape = {\n initialAdminGroup: CreateOrganizationGroupRequestSchema,\n initialMemberGroup: CreateOrganizationGroupRequestSchema,\n initialOrganizationMetadataContainer: ProvisionedSystemContainerRequestSchema,\n initialOrganizationPolicy: OrganizationPrincipalPolicyRequestSchema,\n initialOrganizationProfileDocument:\n ProvisionedDocumentRequestSchema.optional(),\n initialRootContainer: ContainerMutationRequestSchema,\n initialRootMetadataDocument: ProvisionedDocumentRequestSchema,\n initialRosterProfileContainer:\n ProvisionedSystemContainerRequestSchema.optional(),\n initialRosterProfileDocument: ProvisionedDocumentRequestSchema.optional(),\n initialSystemContainers: arraySchema(\n ProvisionedSystemContainerRequestSchema,\n ).optional(),\n organizationId: uuidV4StringSchema,\n rootContainerId: uuidV4StringSchema,\n userId: uuidV4StringSchema,\n} satisfies z.ZodRawShape;\n\nexport const OrganizationProvisioningRequestSchema = loosePlainObject(\n organizationProvisioningRequestShape,\n);\n\nexport type OrganizationProvisioningRequest = z.infer<\n typeof OrganizationProvisioningRequestSchema\n>;\n\nexport function isOrganizationProvisioningRequest(\n value: unknown,\n): value is OrganizationProvisioningRequest {\n return OrganizationProvisioningRequestSchema.safeParse(value).success;\n}\n\n/**\n * Request to create an additional organization for the authenticated user. The\n * caller re-signs the same provisioning artifacts as registration, but with\n * their existing identity keys, so the request is exactly an\n * {@link OrganizationProvisioningRequest} where `userId` is the caller.\n */\nexport const CreateOrganizationRequestSchema = loosePlainObject({\n ...organizationProvisioningRequestShape,\n replacementAuthorization:\n OrganizationReplacementAuthorizationSchema.optional(),\n /**\n * Marks this fresh organization as the durable destination for one native\n * subscription restore. The server records and later verifies this intent;\n * ordinary existing organizations cannot be used as restore destinations.\n */\n nativeSubscriptionRestore: z.literal(true).optional(),\n /**\n * Completes a previously provisioned personal-organization replacement\n * after the client has committed its local remote-state reset. The server\n * rechecks replacement ownership and sync eligibility before moving the\n * user's default-organization pointer.\n */\n finalizeReplacement: z.boolean().optional(),\n /**\n * Purged personal organization this fresh organization replaces. The server\n * accepts this only after the old organization's purge is complete. The\n * default pointer moves only on a later `finalizeReplacement` replay.\n */\n replacesOrganizationId: uuidV4StringSchema.optional(),\n});\n\nexport type CreateOrganizationRequest = z.infer<\n typeof CreateOrganizationRequestSchema\n>;\n\nexport function isCreateOrganizationRequest(\n value: unknown,\n): value is CreateOrganizationRequest {\n return CreateOrganizationRequestSchema.safeParse(value).success;\n}\n"]}
1
+ {"version":3,"file":"organizationProvisioning.js","sourceRoot":"","sources":["organizationProvisioning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,oCAAoC,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,+CAA+C,EAC/C,8CAA8C,GAC/C,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,0CAA0C,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,+CAA+C,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EACL,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,oCAAoC,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,wCAAwC,EAAE,MAAM,aAAa,CAAC;AAEvE;;;;GAIG;AACH,MAAM,sCAAsC,GAAG;IAC7C,GAAG,+CAA+C;IAClD,mBAAmB,EAAE,yBAAyB;CAC/C,CAAC;AAEF;;;GAGG;AACH,MAAM,+BAA+B,GAAG;IACtC,GAAG,0BAA0B;IAC7B,WAAW,EAAE,yBAAyB;CACvC,CAAC;AAEF,MAAM,CAAC,MAAM,gCAAgC,GAC3C,oCAAoC,CAClC,gBAAgB,CAAC,+BAA+B,CAAC,CAAC,WAAW,CAC3D,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACjB,sBAAsB,CAAC,KAAK,C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BAAkB;CACH,CAAC;AAE1B,MAAM,CAAC,MAAM,qCAAqC,GAAG,gBAAgB,CACnE,oCAAoC,CACrC,CAAC;AAMF,MAAM,UAAU,iCAAiC,CAC/C,KAAc;IAEd,OAAO,qCAAqC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACxE,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,gBAAgB,CAAC;IAC9D,GAAG,oCAAoC;IACvC,wBAAwB,EACtB,0CAA0C,CAAC,QAAQ,EAAE;IACvD;;;;OAIG;IACH,yBAAyB,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE;IACrD;;;;;OAKG;IACH,mBAAmB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC3C;;;;OAIG;IACH,sBAAsB,EAAE,kBAAkB,CAAC,QAAQ,EAAE;CACtD,CAAC,CAAC;AAMH,MAAM,UAAU,2BAA2B,CACzC,KAAc;IAEd,OAAO,+BAA+B,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAClE,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport {\n organizationProvisioningContainerSeedRefinement,\n organizationProvisioningDocumentSeedRefinement,\n} from \"../organizationProvisioningRefinements\";\nimport { arraySchema, loosePlainObject, uuidV4StringSchema } from \"../schema\";\nimport { OrganizationReplacementAuthorizationSchema } from \"../util/organizationReplacement\";\nimport { ContainerMutationRequestSchema } from \"./container\";\nimport { containerCreateWithMetadataDocumentRequestShape } from \"./containerMetadata\";\nimport {\n DocumentSyncRequestSchema,\n documentCreateRequestShape,\n} from \"./document\";\nimport { refineSingleUpdateSeed } from \"./documentCreateSeed\";\nimport { CreateOrganizationGroupRequestSchema } from \"./organization\";\nimport { OrganizationPrincipalPolicyRequestSchema } from \"./principal\";\n\n/**\n * A built-in or app-owned system container whose encrypted initial metadata\n * body is committed in the same transaction as the organization and document\n * shell.\n */\nconst provisionedSystemContainerRequestShape = {\n ...containerCreateWithMetadataDocumentRequestShape,\n initialMetadataSync: DocumentSyncRequestSchema,\n};\n\n/**\n * A document whose encrypted initial body is committed with its manifest in the\n * organization-provisioning transaction.\n */\nconst provisionedDocumentRequestShape = {\n ...documentCreateRequestShape,\n initialSync: DocumentSyncRequestSchema,\n};\n\nexport const ProvisionedDocumentRequestSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject(provisionedDocumentRequestShape).superRefine(\n (value, context) => {\n refineSingleUpdateSeed(value.initialSync, context, {\n message:\n \"provisioned document seed requires one update and no container rekeys\",\n path: \"initialSync\",\n });\n },\n ),\n [organizationProvisioningDocumentSeedRefinement],\n );\n\nexport type ProvisionedDocumentRequest = z.infer<\n typeof ProvisionedDocumentRequestSchema\n>;\n\nexport const ProvisionedSystemContainerRequestSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject(provisionedSystemContainerRequestShape).superRefine(\n (value, context) => {\n refineSingleUpdateSeed(value.initialMetadataSync, context, {\n message:\n \"provisioned system-container metadata seed requires one update and no container rekeys\",\n path: \"initialMetadataSync\",\n });\n },\n ),\n [organizationProvisioningContainerSeedRefinement],\n );\n\nexport type ProvisionedSystemContainerRequest = z.infer<\n typeof ProvisionedSystemContainerRequestSchema\n>;\n\nexport function isProvisionedDocumentRequest(\n value: unknown,\n): value is ProvisionedDocumentRequest {\n return ProvisionedDocumentRequestSchema.safeParse(value).success;\n}\n\nexport function isProvisionedSystemContainerRequest(\n value: unknown,\n): value is ProvisionedSystemContainerRequest {\n return ProvisionedSystemContainerRequestSchema.safeParse(value).success;\n}\n\n/**\n * The client-signed artifacts required to bootstrap a fresh organization: the\n * organization + admin/member group policies, the signed root container and its\n * metadata document, the organization metadata root, and the optional\n * roster/organization profile documents.\n *\n * This is the shared shape between user registration (which bootstraps the\n * user's personal organization) and creating an additional organization for an\n * existing user. Registration additionally carries the new user's public key\n * material (see {@link RegistrationRequest}); creating an additional\n * organization reuses the caller's existing keys, so it needs only this base.\n */\nexport const organizationProvisioningRequestShape = {\n initialAdminGroup: CreateOrganizationGroupRequestSchema,\n initialMemberGroup: CreateOrganizationGroupRequestSchema,\n initialOrganizationMetadataContainer: ProvisionedSystemContainerRequestSchema,\n initialOrganizationPolicy: OrganizationPrincipalPolicyRequestSchema,\n initialOrganizationProfileDocument:\n ProvisionedDocumentRequestSchema.optional(),\n initialRootContainer: ContainerMutationRequestSchema,\n initialRootMetadataDocument: ProvisionedDocumentRequestSchema,\n initialRosterProfileContainer:\n ProvisionedSystemContainerRequestSchema.optional(),\n initialRosterProfileDocument: ProvisionedDocumentRequestSchema.optional(),\n initialSystemContainers: arraySchema(\n ProvisionedSystemContainerRequestSchema,\n ).optional(),\n organizationId: uuidV4StringSchema,\n rootContainerId: uuidV4StringSchema,\n userId: uuidV4StringSchema,\n} satisfies z.ZodRawShape;\n\nexport const OrganizationProvisioningRequestSchema = loosePlainObject(\n organizationProvisioningRequestShape,\n);\n\nexport type OrganizationProvisioningRequest = z.infer<\n typeof OrganizationProvisioningRequestSchema\n>;\n\nexport function isOrganizationProvisioningRequest(\n value: unknown,\n): value is OrganizationProvisioningRequest {\n return OrganizationProvisioningRequestSchema.safeParse(value).success;\n}\n\n/**\n * Request to create an additional organization for the authenticated user. The\n * caller re-signs the same provisioning artifacts as registration, but with\n * their existing identity keys, so the request is exactly an\n * {@link OrganizationProvisioningRequest} where `userId` is the caller.\n */\nexport const CreateOrganizationRequestSchema = loosePlainObject({\n ...organizationProvisioningRequestShape,\n replacementAuthorization:\n OrganizationReplacementAuthorizationSchema.optional(),\n /**\n * Marks this fresh organization as the durable destination for one native\n * subscription restore. The server records and later verifies this intent;\n * ordinary existing organizations cannot be used as restore destinations.\n */\n nativeSubscriptionRestore: z.literal(true).optional(),\n /**\n * Completes a previously provisioned personal-organization replacement\n * after the client has committed its local remote-state reset. The server\n * rechecks replacement ownership and sync eligibility before moving the\n * user's default-organization pointer.\n */\n finalizeReplacement: z.boolean().optional(),\n /**\n * Purged personal organization this fresh organization replaces. The server\n * accepts this only after the old organization's purge is complete. The\n * default pointer moves only on a later `finalizeReplacement` replay.\n */\n replacesOrganizationId: uuidV4StringSchema.optional(),\n});\n\nexport type CreateOrganizationRequest = z.infer<\n typeof CreateOrganizationRequestSchema\n>;\n\nexport function isCreateOrganizationRequest(\n value: unknown,\n): value is CreateOrganizationRequest {\n return CreateOrganizationRequestSchema.safeParse(value).success;\n}\n"]}
@@ -95,6 +95,11 @@ export declare const ContainerCreateWithMetadataDocumentResponseSchema: z.ZodTyp
95
95
  targets: Record<string, unknown>[];
96
96
  };
97
97
  id: string;
98
+ initialSync?: {
99
+ commitLsn: string | null;
100
+ commitLsnMode: "tracked" | "untracked";
101
+ acceptedOutgoingUpdateIds: string[];
102
+ } | undefined;
98
103
  };
99
104
  }, {
100
105
  container: {
@@ -192,6 +197,11 @@ export declare const ContainerCreateWithMetadataDocumentResponseSchema: z.ZodTyp
192
197
  targets: Record<string, unknown>[];
193
198
  };
194
199
  id: string;
200
+ initialSync?: {
201
+ commitLsn: string | null;
202
+ commitLsnMode: "tracked" | "untracked";
203
+ acceptedOutgoingUpdateIds: string[];
204
+ } | undefined;
195
205
  };
196
206
  }, z.core.$ZodTypeInternals<{
197
207
  container: {
@@ -289,6 +299,11 @@ export declare const ContainerCreateWithMetadataDocumentResponseSchema: z.ZodTyp
289
299
  targets: Record<string, unknown>[];
290
300
  };
291
301
  id: string;
302
+ initialSync?: {
303
+ commitLsn: string | null;
304
+ commitLsnMode: "tracked" | "untracked";
305
+ acceptedOutgoingUpdateIds: string[];
306
+ } | undefined;
292
307
  };
293
308
  }, {
294
309
  container: {
@@ -386,6 +401,11 @@ export declare const ContainerCreateWithMetadataDocumentResponseSchema: z.ZodTyp
386
401
  targets: Record<string, unknown>[];
387
402
  };
388
403
  id: string;
404
+ initialSync?: {
405
+ commitLsn: string | null;
406
+ commitLsnMode: "tracked" | "untracked";
407
+ acceptedOutgoingUpdateIds: string[];
408
+ } | undefined;
389
409
  };
390
410
  }>>;
391
411
  export type ContainerCreateWithMetadataDocumentResponse = z.infer<typeof ContainerCreateWithMetadataDocumentResponseSchema>;
@@ -1,6 +1,29 @@
1
1
  import { z } from "zod";
2
2
  import { type DocumentContentKeyBundleResponse, type DocumentKekTargetsResponse, type DocumentSyncResponse } from "./documentSyncSchema.js";
3
3
  export { type DocumentContentKeyBundleResponse, DocumentContentKeyBundleResponseSchema, type DocumentContentKeyTargetEnvelopeResponse, DocumentContentKeyTargetEnvelopeResponseSchema, type DocumentKekTargetsResponse, DocumentKekTargetsResponseSchema, type DocumentSyncPullPageResponse, DocumentSyncPullPageResponseSchema, type DocumentSyncResponse, DocumentSyncResponseSchema, type DocumentSyncUpdateResponse, DocumentSyncUpdateResponseSchema, } from "./documentSyncSchema.js";
4
+ /**
5
+ * What the create transaction committed of a seed: the accepted update id and
6
+ * the commit position a following sync reads from, as a sync response reports
7
+ * them.
8
+ */
9
+ export declare const DocumentCreateSeedResponseSchema: z.ZodType<{
10
+ commitLsn: string | null;
11
+ commitLsnMode: "tracked" | "untracked";
12
+ acceptedOutgoingUpdateIds: string[];
13
+ }, {
14
+ commitLsn: string | null;
15
+ commitLsnMode: "tracked" | "untracked";
16
+ acceptedOutgoingUpdateIds: string[];
17
+ }, z.core.$ZodTypeInternals<{
18
+ commitLsn: string | null;
19
+ commitLsnMode: "tracked" | "untracked";
20
+ acceptedOutgoingUpdateIds: string[];
21
+ }, {
22
+ commitLsn: string | null;
23
+ commitLsnMode: "tracked" | "untracked";
24
+ acceptedOutgoingUpdateIds: string[];
25
+ }>>;
26
+ export type DocumentCreateSeedResponse = z.infer<typeof DocumentCreateSeedResponseSchema>;
4
27
  export declare const DocumentCreateResponseSchema: z.ZodType<{
5
28
  accessManifest: {
6
29
  event: {
@@ -36,6 +59,11 @@ export declare const DocumentCreateResponseSchema: z.ZodType<{
36
59
  targets: Record<string, unknown>[];
37
60
  };
38
61
  id: string;
62
+ initialSync?: {
63
+ commitLsn: string | null;
64
+ commitLsnMode: "tracked" | "untracked";
65
+ acceptedOutgoingUpdateIds: string[];
66
+ } | undefined;
39
67
  }, {
40
68
  accessManifest: {
41
69
  event: {
@@ -71,6 +99,11 @@ export declare const DocumentCreateResponseSchema: z.ZodType<{
71
99
  targets: Record<string, unknown>[];
72
100
  };
73
101
  id: string;
102
+ initialSync?: {
103
+ commitLsn: string | null;
104
+ commitLsnMode: "tracked" | "untracked";
105
+ acceptedOutgoingUpdateIds: string[];
106
+ } | undefined;
74
107
  }, z.core.$ZodTypeInternals<{
75
108
  accessManifest: {
76
109
  event: {
@@ -106,6 +139,11 @@ export declare const DocumentCreateResponseSchema: z.ZodType<{
106
139
  targets: Record<string, unknown>[];
107
140
  };
108
141
  id: string;
142
+ initialSync?: {
143
+ commitLsn: string | null;
144
+ commitLsnMode: "tracked" | "untracked";
145
+ acceptedOutgoingUpdateIds: string[];
146
+ } | undefined;
109
147
  }, {
110
148
  accessManifest: {
111
149
  event: {
@@ -141,6 +179,11 @@ export declare const DocumentCreateResponseSchema: z.ZodType<{
141
179
  targets: Record<string, unknown>[];
142
180
  };
143
181
  id: string;
182
+ initialSync?: {
183
+ commitLsn: string | null;
184
+ commitLsnMode: "tracked" | "untracked";
185
+ acceptedOutgoingUpdateIds: string[];
186
+ } | undefined;
144
187
  }>>;
145
188
  export type DocumentCreateResponse = z.infer<typeof DocumentCreateResponseSchema>;
146
189
  export declare const DocumentLinkSetMutationResponseSchema: z.ZodType<{
@@ -4,16 +4,27 @@ import { arraySchema, loosePlainObject, nonEmptyArraySchema, nonEmptyStringSchem
4
4
  import { AccessEventBundleWireResponseSchema, AccessManifestBundleWireResponseSchema, } from "../util/index.js";
5
5
  import { writerProjectionManifestBundlesRefinement } from "../writerProjectionRefinements.js";
6
6
  import { ContainerKeyingPathResponseSchema, ContainerKeyingPathWireResponseSchema, } from "./container.js";
7
- import { DocumentContentKeyBundleResponseSchema, DocumentKekTargetsResponseSchema, DocumentSyncResponseSchema, } from "./documentSyncSchema.js";
7
+ import { commitLsnResponseShape, DocumentContentKeyBundleResponseSchema, DocumentKekTargetsResponseSchema, DocumentSyncResponseSchema, } from "./documentSyncSchema.js";
8
8
  import { containerKeyingPathReferences, ManifestBundlesSchema, ManifestHashReferenceSchema, OmittedManifestBundlesSchema, refineManifestBundleReferences, } from "./manifestBundleReferences.js";
9
9
  import { ProjectionPolicyEvidenceResponseSchema } from "./projectionPolicyEvidence.js";
10
10
  export { DocumentContentKeyBundleResponseSchema, DocumentContentKeyTargetEnvelopeResponseSchema, DocumentKekTargetsResponseSchema, DocumentSyncPullPageResponseSchema, DocumentSyncResponseSchema, DocumentSyncUpdateResponseSchema, } from "./documentSyncSchema.js";
11
+ /**
12
+ * What the create transaction committed of a seed: the accepted update id and
13
+ * the commit position a following sync reads from, as a sync response reports
14
+ * them.
15
+ */
16
+ export const DocumentCreateSeedResponseSchema = loosePlainObject({
17
+ acceptedOutgoingUpdateIds: arraySchema(nonEmptyStringSchema, 1),
18
+ ...commitLsnResponseShape,
19
+ });
11
20
  export const DocumentCreateResponseSchema = loosePlainObject({
12
21
  accessManifest: AccessManifestBundleWireResponseSchema,
13
22
  contentKeyBundle: DocumentContentKeyBundleResponseSchema,
14
23
  createdAt: z.string(),
15
24
  documentKekTargets: DocumentKekTargetsResponseSchema,
16
25
  id: z.string(),
26
+ /** Present exactly when the request carried a seed. */
27
+ initialSync: DocumentCreateSeedResponseSchema.optional(),
17
28
  });
18
29
  export const DocumentLinkSetMutationResponseSchema = loosePlainObject({
19
30
  accessManifest: AccessManifestBundleWireResponseSchema,
@@ -1 +1 @@
1
- {"version":3,"file":"documentMutation.js","sourceRoot":"","sources":["documentMutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,oCAAoC,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,WAAW,EACX,gBAA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B,CACpC,KAAc;IAEd,OAAO,0BAA0B,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,kCAAkC,CAChD,KAAc;IAEd,OAAO,sCAAsC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,sCAAsC,CACpD,KAAc;IAEd,OAAO,0CAA0C,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC7E,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport {\n arraySchema,\n loosePlainObject,\n nonEmptyArraySchema,\n nonEmptyStringSchema,\n} from \"../schema\";\nimport {\n AccessEventBundleWireResponseSchema,\n AccessManifestBundleWireResponseSchema,\n} from \"../util\";\nimport { writerProjectionManifestBundlesRefinement } from \"../writerProjectionRefinements\";\nimport {\n ContainerKeyingPathResponseSchema,\n ContainerKeyingPathWireResponseSchema,\n} from \"./container\";\nimport {\n type DocumentContentKeyBundleResponse,\n DocumentContentKeyBundleResponseSchema,\n type DocumentKekTargetsResponse,\n DocumentKekTargetsResponseSchema,\n type DocumentSyncResponse,\n DocumentSyncResponseSchema,\n} from \"./documentSyncSchema\";\nimport {\n containerKeyingPathReferences,\n ManifestBundlesSchema,\n ManifestHashReferenceSchema,\n OmittedManifestBundlesSchema,\n refineManifestBundleReferences,\n} from \"./manifestBundleReferences\";\nimport { ProjectionPolicyEvidenceResponseSchema } from \"./projectionPolicyEvidence\";\n\nexport {\n type DocumentContentKeyBundleResponse,\n DocumentContentKeyBundleResponseSchema,\n type DocumentContentKeyTargetEnvelopeResponse,\n DocumentContentKeyTargetEnvelopeResponseSchema,\n type DocumentKekTargetsResponse,\n DocumentKekTargetsResponseSchema,\n type DocumentSyncPullPageResponse,\n DocumentSyncPullPageResponseSchema,\n type DocumentSyncResponse,\n DocumentSyncResponseSchema,\n type DocumentSyncUpdateResponse,\n DocumentSyncUpdateResponseSchema,\n} from \"./documentSyncSchema\";\n\nexport const DocumentCreateResponseSchema = loosePlainObject({\n accessManifest: AccessManifestBundleWireResponseSchema,\n contentKeyBundle: DocumentContentKeyBundleResponseSchema,\n createdAt: z.string(),\n documentKekTargets: DocumentKekTargetsResponseSchema,\n id: z.string(),\n});\n\nexport type DocumentCreateResponse = z.infer<\n typeof DocumentCreateResponseSchema\n>;\n\nexport const DocumentLinkSetMutationResponseSchema = loosePlainObject({\n accessManifest: AccessManifestBundleWireResponseSchema,\n contentKeyBundle: DocumentContentKeyBundleResponseSchema,\n documentKekTargets: DocumentKekTargetsResponseSchema,\n id: z.string(),\n});\n\nexport type DocumentLinkSetMutationResponse = z.infer<\n typeof DocumentLinkSetMutationResponseSchema\n>;\n\nconst documentPurgeProofShape = {\n authorizingContainerPath: nonEmptyArraySchema(\n AccessManifestBundleWireResponseSchema,\n ),\n documentContainerManifestHistory: arraySchema(\n AccessManifestBundleWireResponseSchema,\n ),\n documentId: nonEmptyStringSchema,\n documentManifest: AccessManifestBundleWireResponseSchema,\n documentManifestContainerPaths: arraySchema(\n arraySchema(AccessManifestBundleWireResponseSchema),\n ),\n documentManifestPredecessors: arraySchema(\n AccessManifestBundleWireResponseSchema,\n ),\n purgeEvent: AccessEventBundleWireResponseSchema,\n purgedAt: nonEmptyStringSchema,\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n} as const;\n\nexport const DocumentPurgeProofResponseSchema = loosePlainObject(\n documentPurgeProofShape,\n);\n\nexport type DocumentPurgeProofResponse = z.infer<\n typeof DocumentPurgeProofResponseSchema\n>;\n\nexport const DocumentPurgeResponseSchema = loosePlainObject({\n ...documentPurgeProofShape,\n reclaimedBlobStorageKeys: arraySchema(z.string()),\n});\n\nexport type DocumentPurgeResponse = z.infer<typeof DocumentPurgeResponseSchema>;\n\nexport const DocumentWriterProjectionResponseSchema = loosePlainObject({\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n authorizingContainerPaths: nonEmptyArraySchema(\n ContainerKeyingPathResponseSchema,\n ),\n contentKeyBundle: DocumentContentKeyBundleResponseSchema,\n /** Present only when the stored content-key bundle targets stale KEKs. */\n contentKeyBundleStale: z.literal(true).optional(),\n documentContainerManifestHistory: arraySchema(\n AccessManifestBundleWireResponseSchema,\n ),\n documentId: z.string(),\n documentKekTargets: DocumentKekTargetsResponseSchema,\n documentManifest: AccessManifestBundleWireResponseSchema,\n documentManifestContainerPaths: arraySchema(\n arraySchema(AccessManifestBundleWireResponseSchema),\n ),\n documentManifestHistory: arraySchema(AccessManifestBundleWireResponseSchema),\n});\n\nexport type DocumentWriterProjectionResponse = z.infer<\n typeof DocumentWriterProjectionResponseSchema\n>;\n\nfunction documentWriterProjectionReferences(projection: {\n readonly authorizingContainerPaths: unknown;\n readonly documentContainerManifestHistory: unknown;\n readonly documentManifest: unknown;\n readonly documentManifestContainerPaths: unknown;\n readonly documentManifestHistory: unknown;\n}): unknown[] {\n const listed = (value: unknown): unknown[] =>\n Array.isArray(value) ? value : [];\n return [\n projection.documentManifest,\n ...listed(projection.documentManifestHistory),\n ...listed(projection.documentContainerManifestHistory),\n ...listed(projection.documentManifestContainerPaths).flatMap(listed),\n ...listed(projection.authorizingContainerPaths).flatMap(\n containerKeyingPathReferences,\n ),\n ];\n}\n\n/** The served shape; see ContainerWriterProjectionWireResponseSchema. */\nexport const DocumentWriterProjectionWireResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n bundles: ManifestBundlesSchema,\n omittedBundles: OmittedManifestBundlesSchema,\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n authorizingContainerPaths: nonEmptyArraySchema(\n ContainerKeyingPathWireResponseSchema,\n ),\n contentKeyBundle: DocumentContentKeyBundleResponseSchema,\n /** Present only when the stored content-key bundle targets stale KEKs. */\n contentKeyBundleStale: z.literal(true).optional(),\n documentContainerManifestHistory: arraySchema(\n ManifestHashReferenceSchema,\n ),\n documentId: z.string(),\n documentKekTargets: DocumentKekTargetsResponseSchema,\n documentManifest: ManifestHashReferenceSchema,\n documentManifestContainerPaths: arraySchema(\n arraySchema(ManifestHashReferenceSchema),\n ),\n documentManifestHistory: arraySchema(ManifestHashReferenceSchema),\n }).superRefine((projection, context) =>\n refineManifestBundleReferences(\n projection,\n documentWriterProjectionReferences(projection),\n context,\n ),\n ),\n [writerProjectionManifestBundlesRefinement],\n );\n\nexport type DocumentWriterProjectionWireResponse = z.infer<\n typeof DocumentWriterProjectionWireResponseSchema\n>;\n\n/**\n * Derives the KEK-target summary that corresponds to a content-key bundle,\n * preserving the bundle's served target order. Both the API (for stale-bundle\n * read-only sync responses) and clients (for plans built against a stale\n * bundle) must derive this identically so response/plan state comparisons\n * hold byte-for-byte.\n */\nexport function documentKekTargetsFromContentKeyBundle(\n bundle: DocumentContentKeyBundleResponse,\n): DocumentKekTargetsResponse {\n const targets = bundle.targets.map((target) => ({\n containerId: target.containerId,\n containerManifestHash: target.containerManifestHash,\n containerKeyEpochId: target.containerKeyEpochId,\n containerKeyEpoch: target.containerKeyEpoch,\n }));\n\n return {\n documentId: bundle.documentId,\n documentKeyTargetHash: bundle.targetHash,\n linkSetManifestHash: bundle.linkSetManifestHash,\n linkedContainerKeyEpochIds: targets.map(\n (target) => target.containerKeyEpochId,\n ),\n linkedContainerManifestHashes: targets.map(\n (target) => target.containerManifestHash,\n ),\n targets,\n };\n}\n\nexport function isDocumentKekTargetsResponse(\n value: unknown,\n): value is DocumentKekTargetsResponse {\n return DocumentKekTargetsResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentContentKeyBundleResponse(\n value: unknown,\n): value is DocumentContentKeyBundleResponse {\n return DocumentContentKeyBundleResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentCreateResponse(\n value: unknown,\n): value is DocumentCreateResponse {\n return DocumentCreateResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentLinkSetMutationResponse(\n value: unknown,\n): value is DocumentLinkSetMutationResponse {\n return DocumentLinkSetMutationResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentPurgeResponse(\n value: unknown,\n): value is DocumentPurgeResponse {\n return DocumentPurgeResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentPurgeProofResponse(\n value: unknown,\n): value is DocumentPurgeProofResponse {\n return DocumentPurgeProofResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentSyncResponse(\n value: unknown,\n): value is DocumentSyncResponse {\n return DocumentSyncResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentWriterProjectionResponse(\n value: unknown,\n): value is DocumentWriterProjectionResponse {\n return DocumentWriterProjectionResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentWriterProjectionWireResponse(\n value: unknown,\n): value is DocumentWriterProjectionWireResponse {\n return DocumentWriterProjectionWireResponseSchema.safeParse(value).success;\n}\n"]}
1
+ {"version":3,"file":"documentMutation.js","sourceRoot":"","sources":["documentMutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,oCAAoC,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,mCAAmC,EACnC,sCAAsC,GACvC,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,yCAAyC,EAAE,MAAM,gCAAgC,CAAC;AAC3F,OAAO,EACL,iCAAiC,EACjC,qCAAqC,GACtC,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EAEtB,sCAAsC,EAEtC,gCAAgC,EAEhC,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,EACrB,2BAA2B,EAC3B,4BAA4B,EAC5B,8BAA8B,GAC/B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,sCAAsC,EAAE,MAAM,4BAA4B,CAAC;AAEpF,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,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC7E,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport {\n arraySchema,\n loosePlainObject,\n nonEmptyArraySchema,\n nonEmptyStringSchema,\n} from \"../schema\";\nimport {\n AccessEventBundleWireResponseSchema,\n AccessManifestBundleWireResponseSchema,\n} from \"../util\";\nimport { writerProjectionManifestBundlesRefinement } from \"../writerProjectionRefinements\";\nimport {\n ContainerKeyingPathResponseSchema,\n ContainerKeyingPathWireResponseSchema,\n} from \"./container\";\nimport {\n commitLsnResponseShape,\n type DocumentContentKeyBundleResponse,\n DocumentContentKeyBundleResponseSchema,\n type DocumentKekTargetsResponse,\n DocumentKekTargetsResponseSchema,\n type DocumentSyncResponse,\n DocumentSyncResponseSchema,\n} from \"./documentSyncSchema\";\nimport {\n containerKeyingPathReferences,\n ManifestBundlesSchema,\n ManifestHashReferenceSchema,\n OmittedManifestBundlesSchema,\n refineManifestBundleReferences,\n} from \"./manifestBundleReferences\";\nimport { ProjectionPolicyEvidenceResponseSchema } from \"./projectionPolicyEvidence\";\n\nexport {\n type DocumentContentKeyBundleResponse,\n DocumentContentKeyBundleResponseSchema,\n type DocumentContentKeyTargetEnvelopeResponse,\n DocumentContentKeyTargetEnvelopeResponseSchema,\n type DocumentKekTargetsResponse,\n DocumentKekTargetsResponseSchema,\n type DocumentSyncPullPageResponse,\n DocumentSyncPullPageResponseSchema,\n type DocumentSyncResponse,\n DocumentSyncResponseSchema,\n type DocumentSyncUpdateResponse,\n DocumentSyncUpdateResponseSchema,\n} from \"./documentSyncSchema\";\n\n/**\n * What the create transaction committed of a seed: the accepted update id and\n * the commit position a following sync reads from, as a sync response reports\n * them.\n */\nexport const DocumentCreateSeedResponseSchema = loosePlainObject({\n acceptedOutgoingUpdateIds: arraySchema(nonEmptyStringSchema, 1),\n ...commitLsnResponseShape,\n});\n\nexport type DocumentCreateSeedResponse = z.infer<\n typeof DocumentCreateSeedResponseSchema\n>;\n\nexport const DocumentCreateResponseSchema = loosePlainObject({\n accessManifest: AccessManifestBundleWireResponseSchema,\n contentKeyBundle: DocumentContentKeyBundleResponseSchema,\n createdAt: z.string(),\n documentKekTargets: DocumentKekTargetsResponseSchema,\n id: z.string(),\n /** Present exactly when the request carried a seed. */\n initialSync: DocumentCreateSeedResponseSchema.optional(),\n});\n\nexport type DocumentCreateResponse = z.infer<\n typeof DocumentCreateResponseSchema\n>;\n\nexport const DocumentLinkSetMutationResponseSchema = loosePlainObject({\n accessManifest: AccessManifestBundleWireResponseSchema,\n contentKeyBundle: DocumentContentKeyBundleResponseSchema,\n documentKekTargets: DocumentKekTargetsResponseSchema,\n id: z.string(),\n});\n\nexport type DocumentLinkSetMutationResponse = z.infer<\n typeof DocumentLinkSetMutationResponseSchema\n>;\n\nconst documentPurgeProofShape = {\n authorizingContainerPath: nonEmptyArraySchema(\n AccessManifestBundleWireResponseSchema,\n ),\n documentContainerManifestHistory: arraySchema(\n AccessManifestBundleWireResponseSchema,\n ),\n documentId: nonEmptyStringSchema,\n documentManifest: AccessManifestBundleWireResponseSchema,\n documentManifestContainerPaths: arraySchema(\n arraySchema(AccessManifestBundleWireResponseSchema),\n ),\n documentManifestPredecessors: arraySchema(\n AccessManifestBundleWireResponseSchema,\n ),\n purgeEvent: AccessEventBundleWireResponseSchema,\n purgedAt: nonEmptyStringSchema,\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n} as const;\n\nexport const DocumentPurgeProofResponseSchema = loosePlainObject(\n documentPurgeProofShape,\n);\n\nexport type DocumentPurgeProofResponse = z.infer<\n typeof DocumentPurgeProofResponseSchema\n>;\n\nexport const DocumentPurgeResponseSchema = loosePlainObject({\n ...documentPurgeProofShape,\n reclaimedBlobStorageKeys: arraySchema(z.string()),\n});\n\nexport type DocumentPurgeResponse = z.infer<typeof DocumentPurgeResponseSchema>;\n\nexport const DocumentWriterProjectionResponseSchema = loosePlainObject({\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n authorizingContainerPaths: nonEmptyArraySchema(\n ContainerKeyingPathResponseSchema,\n ),\n contentKeyBundle: DocumentContentKeyBundleResponseSchema,\n /** Present only when the stored content-key bundle targets stale KEKs. */\n contentKeyBundleStale: z.literal(true).optional(),\n documentContainerManifestHistory: arraySchema(\n AccessManifestBundleWireResponseSchema,\n ),\n documentId: z.string(),\n documentKekTargets: DocumentKekTargetsResponseSchema,\n documentManifest: AccessManifestBundleWireResponseSchema,\n documentManifestContainerPaths: arraySchema(\n arraySchema(AccessManifestBundleWireResponseSchema),\n ),\n documentManifestHistory: arraySchema(AccessManifestBundleWireResponseSchema),\n});\n\nexport type DocumentWriterProjectionResponse = z.infer<\n typeof DocumentWriterProjectionResponseSchema\n>;\n\nfunction documentWriterProjectionReferences(projection: {\n readonly authorizingContainerPaths: unknown;\n readonly documentContainerManifestHistory: unknown;\n readonly documentManifest: unknown;\n readonly documentManifestContainerPaths: unknown;\n readonly documentManifestHistory: unknown;\n}): unknown[] {\n const listed = (value: unknown): unknown[] =>\n Array.isArray(value) ? value : [];\n return [\n projection.documentManifest,\n ...listed(projection.documentManifestHistory),\n ...listed(projection.documentContainerManifestHistory),\n ...listed(projection.documentManifestContainerPaths).flatMap(listed),\n ...listed(projection.authorizingContainerPaths).flatMap(\n containerKeyingPathReferences,\n ),\n ];\n}\n\n/** The served shape; see ContainerWriterProjectionWireResponseSchema. */\nexport const DocumentWriterProjectionWireResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n bundles: ManifestBundlesSchema,\n omittedBundles: OmittedManifestBundlesSchema,\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n authorizingContainerPaths: nonEmptyArraySchema(\n ContainerKeyingPathWireResponseSchema,\n ),\n contentKeyBundle: DocumentContentKeyBundleResponseSchema,\n /** Present only when the stored content-key bundle targets stale KEKs. */\n contentKeyBundleStale: z.literal(true).optional(),\n documentContainerManifestHistory: arraySchema(\n ManifestHashReferenceSchema,\n ),\n documentId: z.string(),\n documentKekTargets: DocumentKekTargetsResponseSchema,\n documentManifest: ManifestHashReferenceSchema,\n documentManifestContainerPaths: arraySchema(\n arraySchema(ManifestHashReferenceSchema),\n ),\n documentManifestHistory: arraySchema(ManifestHashReferenceSchema),\n }).superRefine((projection, context) =>\n refineManifestBundleReferences(\n projection,\n documentWriterProjectionReferences(projection),\n context,\n ),\n ),\n [writerProjectionManifestBundlesRefinement],\n );\n\nexport type DocumentWriterProjectionWireResponse = z.infer<\n typeof DocumentWriterProjectionWireResponseSchema\n>;\n\n/**\n * Derives the KEK-target summary that corresponds to a content-key bundle,\n * preserving the bundle's served target order. Both the API (for stale-bundle\n * read-only sync responses) and clients (for plans built against a stale\n * bundle) must derive this identically so response/plan state comparisons\n * hold byte-for-byte.\n */\nexport function documentKekTargetsFromContentKeyBundle(\n bundle: DocumentContentKeyBundleResponse,\n): DocumentKekTargetsResponse {\n const targets = bundle.targets.map((target) => ({\n containerId: target.containerId,\n containerManifestHash: target.containerManifestHash,\n containerKeyEpochId: target.containerKeyEpochId,\n containerKeyEpoch: target.containerKeyEpoch,\n }));\n\n return {\n documentId: bundle.documentId,\n documentKeyTargetHash: bundle.targetHash,\n linkSetManifestHash: bundle.linkSetManifestHash,\n linkedContainerKeyEpochIds: targets.map(\n (target) => target.containerKeyEpochId,\n ),\n linkedContainerManifestHashes: targets.map(\n (target) => target.containerManifestHash,\n ),\n targets,\n };\n}\n\nexport function isDocumentKekTargetsResponse(\n value: unknown,\n): value is DocumentKekTargetsResponse {\n return DocumentKekTargetsResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentContentKeyBundleResponse(\n value: unknown,\n): value is DocumentContentKeyBundleResponse {\n return DocumentContentKeyBundleResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentCreateResponse(\n value: unknown,\n): value is DocumentCreateResponse {\n return DocumentCreateResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentLinkSetMutationResponse(\n value: unknown,\n): value is DocumentLinkSetMutationResponse {\n return DocumentLinkSetMutationResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentPurgeResponse(\n value: unknown,\n): value is DocumentPurgeResponse {\n return DocumentPurgeResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentPurgeProofResponse(\n value: unknown,\n): value is DocumentPurgeProofResponse {\n return DocumentPurgeProofResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentSyncResponse(\n value: unknown,\n): value is DocumentSyncResponse {\n return DocumentSyncResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentWriterProjectionResponse(\n value: unknown,\n): value is DocumentWriterProjectionResponse {\n return DocumentWriterProjectionResponseSchema.safeParse(value).success;\n}\n\nexport function isDocumentWriterProjectionWireResponse(\n value: unknown,\n): value is DocumentWriterProjectionWireResponse {\n return DocumentWriterProjectionWireResponseSchema.safeParse(value).success;\n}\n"]}
@@ -209,10 +209,11 @@ export declare const DocumentSyncPullPageResponseSchema: z.ZodType<{
209
209
  nextCursor: string | null;
210
210
  }>>;
211
211
  export type DocumentSyncPullPageResponse = z.infer<typeof DocumentSyncPullPageResponseSchema>;
212
+ export declare const commitLsnResponseShape: {
213
+ commitLsn: z.ZodNullable<z.ZodString>;
214
+ commitLsnMode: z.ZodUnion<readonly [z.ZodLiteral<"tracked">, z.ZodLiteral<"untracked">]>;
215
+ };
212
216
  export declare const DocumentSyncResponseSchema: z.ZodType<{
213
- acceptedOutgoingUpdateIds: string[];
214
- commitLsn: string | null;
215
- commitLsnMode: "tracked" | "untracked";
216
217
  contentKeyBundle: {
217
218
  contentKeyEpoch: number;
218
219
  documentId: string;
@@ -275,10 +276,10 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
275
276
  checkpointPayloadKind?: "full_history_snapshot" | undefined;
276
277
  sourceVersionVector?: string | undefined;
277
278
  }[];
278
- }, {
279
- acceptedOutgoingUpdateIds: string[];
280
279
  commitLsn: string | null;
281
280
  commitLsnMode: "tracked" | "untracked";
281
+ acceptedOutgoingUpdateIds: string[];
282
+ }, {
282
283
  contentKeyBundle: {
283
284
  contentKeyEpoch: number;
284
285
  documentId: string;
@@ -341,10 +342,10 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
341
342
  checkpointPayloadKind?: "full_history_snapshot" | undefined;
342
343
  sourceVersionVector?: string | undefined;
343
344
  }[];
344
- }, z.core.$ZodTypeInternals<{
345
- acceptedOutgoingUpdateIds: string[];
346
345
  commitLsn: string | null;
347
346
  commitLsnMode: "tracked" | "untracked";
347
+ acceptedOutgoingUpdateIds: string[];
348
+ }, z.core.$ZodTypeInternals<{
348
349
  contentKeyBundle: {
349
350
  contentKeyEpoch: number;
350
351
  documentId: string;
@@ -407,10 +408,10 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
407
408
  checkpointPayloadKind?: "full_history_snapshot" | undefined;
408
409
  sourceVersionVector?: string | undefined;
409
410
  }[];
410
- }, {
411
- acceptedOutgoingUpdateIds: string[];
412
411
  commitLsn: string | null;
413
412
  commitLsnMode: "tracked" | "untracked";
413
+ acceptedOutgoingUpdateIds: string[];
414
+ }, {
414
415
  contentKeyBundle: {
415
416
  contentKeyEpoch: number;
416
417
  documentId: string;
@@ -473,5 +474,8 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
473
474
  checkpointPayloadKind?: "full_history_snapshot" | undefined;
474
475
  sourceVersionVector?: string | undefined;
475
476
  }[];
477
+ commitLsn: string | null;
478
+ commitLsnMode: "tracked" | "untracked";
479
+ acceptedOutgoingUpdateIds: string[];
476
480
  }>>;
477
481
  export type DocumentSyncResponse = z.infer<typeof DocumentSyncResponseSchema>;
@@ -96,10 +96,30 @@ function addHistoricalContentKeyBundleIssues(response, context) {
96
96
  seenEpochs.add(contentKeyEpoch);
97
97
  });
98
98
  }
99
- export const DocumentSyncResponseSchema = registerJsonSchemaRuntimeRefinements(loosePlainObject({
100
- acceptedOutgoingUpdateIds: arraySchema(z.string(), MAX_DOCUMENT_SYNC_OUTGOING_UPDATES),
99
+ export const commitLsnResponseShape = {
101
100
  commitLsn: z.string().nullable(),
102
101
  commitLsnMode: z.union([z.literal("tracked"), z.literal("untracked")]),
102
+ };
103
+ /** The 0/0 sentinel and the untracked mode imply each other. */
104
+ function addCommitLsnIssues(response, context) {
105
+ if (response.commitLsnMode === "untracked" && response.commitLsn !== "0/0") {
106
+ context.addIssue({
107
+ code: "custom",
108
+ message: "untracked commit LSN must use the 0/0 sentinel",
109
+ path: ["commitLsn"],
110
+ });
111
+ }
112
+ if (response.commitLsn === "0/0" && response.commitLsnMode !== "untracked") {
113
+ context.addIssue({
114
+ code: "custom",
115
+ message: "0/0 commit LSN must be declared untracked",
116
+ path: ["commitLsnMode"],
117
+ });
118
+ }
119
+ }
120
+ export const DocumentSyncResponseSchema = registerJsonSchemaRuntimeRefinements(loosePlainObject({
121
+ acceptedOutgoingUpdateIds: arraySchema(z.string(), MAX_DOCUMENT_SYNC_OUTGOING_UPDATES),
122
+ ...commitLsnResponseShape,
103
123
  contentKeyBundle: DocumentContentKeyBundleResponseSchema,
104
124
  contentKeyBundles: arraySchema(DocumentContentKeyBundleResponseSchema),
105
125
  documentId: z.string(),
@@ -115,22 +135,7 @@ export const DocumentSyncResponseSchema = registerJsonSchemaRuntimeRefinements(l
115
135
  path: ["pullPage", "nextCursor"],
116
136
  });
117
137
  }
118
- if (response.commitLsnMode === "untracked" &&
119
- response.commitLsn !== "0/0") {
120
- context.addIssue({
121
- code: "custom",
122
- message: "untracked commit LSN must use the 0/0 sentinel",
123
- path: ["commitLsn"],
124
- });
125
- }
126
- if (response.commitLsn === "0/0" &&
127
- response.commitLsnMode !== "untracked") {
128
- context.addIssue({
129
- code: "custom",
130
- message: "0/0 commit LSN must be declared untracked",
131
- path: ["commitLsnMode"],
132
- });
133
- }
138
+ addCommitLsnIssues(response, context);
134
139
  addHistoricalContentKeyBundleIssues(response, context);
135
140
  }), [
136
141
  documentSyncResponseCommitLsnModeRefinement,
@@ -1 +1 @@
1
- {"version":3,"file":"docum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AAQ,CAAC,SAAS,KAAK,KAAK,EAC5B,CAAC;QACD,OAAO,CAAC,QAAQ,CAAC;YACf,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,gDAAgD;YACzD,IAAI,EAAE,CAAC,WAAW,CAAC;SACpB,CAAC,CAAC;IACL,CAAC;IACD,IACE,QAAQ,CAAC,SAAS,KAAK,KAAK;QAC5B,QAAQ,CAAC,aAAa,KAAK,WAAW,EACtC,CAAC;QACD,OAAO,CAAC,QAAQ,CAAC;YACf,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,2CAA2C;YACpD,IAAI,EAAE,CAAC,eAAe,CAAC;SACxB,CAAC,CAAC;IACL,CAAC;IACD,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 current epoch's bundle travels only as `contentKeyBundle`, so the array\n * holds the distinct older epochs that served updates cite. Field issues do not\n * stop this object refinement, so it judges only epochs that parsed.\n */\nfunction addHistoricalContentKeyBundleIssues(\n response: {\n readonly contentKeyBundle: unknown;\n readonly contentKeyBundles: unknown;\n },\n context: z.RefinementCtx,\n): void {\n const currentEpoch = contentKeyEpochOf(response.contentKeyBundle);\n if (currentEpoch === null || !Array.isArray(response.contentKeyBundles)) {\n return;\n }\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 (contentKeyEpoch >= currentEpoch || seenEpochs.has(contentKeyEpoch)) {\n context.addIssue({\n code: \"custom\",\n message:\n \"content-key bundles must be distinct epochs older than contentKeyBundle\",\n path: [\"contentKeyBundles\", index, \"contentKeyEpoch\"],\n });\n }\n seenEpochs.add(contentKeyEpoch);\n });\n}\n\nexport const DocumentSyncResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n acceptedOutgoingUpdateIds: arraySchema(\n z.string(),\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n ),\n commitLsn: z.string().nullable(),\n commitLsnMode: z.union([z.literal(\"tracked\"), z.literal(\"untracked\")]),\n contentKeyBundle: DocumentContentKeyBundleResponseSchema,\n contentKeyBundles: arraySchema(DocumentContentKeyBundleResponseSchema),\n documentId: z.string(),\n documentKekTargets: DocumentKekTargetsResponseSchema,\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 if (\n response.commitLsnMode === \"untracked\" &&\n response.commitLsn !== \"0/0\"\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"untracked commit LSN must use the 0/0 sentinel\",\n path: [\"commitLsn\"],\n });\n }\n if (\n response.commitLsn === \"0/0\" &&\n response.commitLsnMode !== \"untracked\"\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"0/0 commit LSN must be declared untracked\",\n path: [\"commitLsnMode\"],\n });\n }\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":["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,EAC3C,+CAA+C,EAC/C,+CAA+C,EAC/C,sCAAsC,EACtC,sCAAsC,GACvC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oCAAoC,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,WAAW,EACX,2BAA2B,EAC3B,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,kCAAkC,EAClC,oCAAoC,EACpC,uCAAuC,GACxC,MAAM,4BAA4B,CAAC;AAEpC,MAAM,CAAC,MAAM,8CAA8C,GAAG,gBAAgB,CAAC;IAC7E,WAAW,EAAE,oBAAoB;IACjC,iBAAiB,EAAE,qBAAqB;IACxC,mBAAmB,EAAE,oBAAoB;IACzC,qBAAqB,EAAE,oBAAoB;IAC3C,UAAU,EAAE,oBAAoB;IAChC,gBAAgB,EAAE,iBAAiB;CACpC,CAAC,CAAC;AAMH,MAAM,sCAAsC,GAAG,gBAAgB,CAAC;IAC9D,WAAW,EAAE,oBAAoB;IACjC,iBAAiB,EAAE,qBAAqB;IACxC,mBAAmB,EAAE,oBAAoB;IACzC,qBAAqB,EAAE,oBAAoB;CAC5C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gCAAgC,GAAG,gBAAg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,MAAM,0BAA0B,GAAG,oCAAoC,CAC5E,gBAAgB,CAAC;IACf,yBAAyB,EAAE,WAAW,CACpC,CAAC,CAAC,MAAM,EAAE,EACV,kCAAkC,CACnC;IACD,GAAG,sBAAsB;IACzB,gBAAgB,EAAE,sCAAsC;IACxD,iBAAiB,EAAE,WAAW,CAAC,sCAAsC,CAAC;IACtE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,kBAAkB,EAAE,gCAAgC;IACpD,QAAQ,EAAE,kCAAkC;IAC5C,OAAO,EAAE,WAAW,CAClB,gCAAgC,EAChC,uCAAuC,CACxC;CACF,CAAC,CAAC,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 ),\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 current epoch's bundle travels only as `contentKeyBundle`, so the array\n * holds the distinct older epochs that served updates cite. Field issues do not\n * stop this object refinement, so it judges only epochs that parsed.\n */\nfunction addHistoricalContentKeyBundleIssues(\n response: {\n readonly contentKeyBundle: unknown;\n readonly contentKeyBundles: unknown;\n },\n context: z.RefinementCtx,\n): void {\n const currentEpoch = contentKeyEpochOf(response.contentKeyBundle);\n if (currentEpoch === null || !Array.isArray(response.contentKeyBundles)) {\n return;\n }\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 (contentKeyEpoch >= currentEpoch || seenEpochs.has(contentKeyEpoch)) {\n context.addIssue({\n code: \"custom\",\n message:\n \"content-key bundles must be distinct epochs older than contentKeyBundle\",\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 contentKeyBundle: DocumentContentKeyBundleResponseSchema,\n contentKeyBundles: arraySchema(DocumentContentKeyBundleResponseSchema),\n documentId: z.string(),\n documentKekTargets: DocumentKekTargetsResponseSchema,\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"]}
@@ -12,7 +12,7 @@ export { CONTAINER_NOT_FOUND_ERROR_CODE, type ContainerNotFoundErrorResponse, Co
12
12
  export { isListContainerParentLanesResponse, type ListContainerParentLanesResponse, ListContainerParentLanesResponseSchema, } from "./containerParentLanes.js";
13
13
  export { CONTAINER_UNAVAILABLE_ERROR_CODE, type ContainerUnavailableErrorCode, } from "./containerUnavailableError.js";
14
14
  export { type ContainerDocumentSummary, ContainerDocumentSummaryResponseSchema, type ContainerDocumentSyncTombstone, ContainerDocumentSyncTombstoneResponseSchema, type DocumentEditAttributionRangeResponse, DocumentEditAttributionRangeResponseSchema, type DocumentEditAttributionResponse, DocumentEditAttributionResponseSchema, type DocumentEditAttributionSegmentResponse, DocumentEditAttributionSegmentResponseSchema, isDocumentEditAttributionResponse, isListDocumentEditAttributionRangesResponse, type ListContainerDocumentsResponse, ListContainerDocumentsResponseSchema, type ListDocumentEditAttributionRangesResponse, ListDocumentEditAttributionRangesResponseSchema, } from "./document.js";
15
- export { type DocumentContentKeyBundleResponse, DocumentContentKeyBundleResponseSchema, type DocumentContentKeyTargetEnvelopeResponse, DocumentContentKeyTargetEnvelopeResponseSchema, type DocumentCreateResponse, DocumentCreateResponseSchema, type DocumentKekTargetsResponse, DocumentKekTargetsResponseSchema, type DocumentLinkSetMutationResponse, DocumentLinkSetMutationResponseSchema, type DocumentPurgeProofResponse, DocumentPurgeProofResponseSchema, type DocumentPurgeResponse, DocumentPurgeResponseSchema, type DocumentSyncPullPageResponse, DocumentSyncPullPageResponseSchema, type DocumentSyncResponse, DocumentSyncResponseSchema, type DocumentSyncUpdateResponse, DocumentSyncUpdateResponseSchema, type DocumentWriterProjectionResponse, DocumentWriterProjectionResponseSchema, type DocumentWriterProjectionWireResponse, DocumentWriterProjectionWireResponseSchema, documentKekTargetsFromContentKeyBundle, isDocumentContentKeyBundleResponse, isDocumentCreateResponse, isDocumentKekTargetsResponse, isDocumentLinkSetMutationResponse, isDocumentPurgeProofResponse, isDocumentPurgeResponse, isDocumentSyncResponse, isDocumentWriterProjectionResponse, isDocumentWriterProjectionWireResponse, } from "./documentMutation.js";
15
+ export { type DocumentContentKeyBundleResponse, DocumentContentKeyBundleResponseSchema, type DocumentContentKeyTargetEnvelopeResponse, DocumentContentKeyTargetEnvelopeResponseSchema, type DocumentCreateResponse, DocumentCreateResponseSchema, type DocumentCreateSeedResponse, type DocumentKekTargetsResponse, DocumentKekTargetsResponseSchema, type DocumentLinkSetMutationResponse, DocumentLinkSetMutationResponseSchema, type DocumentPurgeProofResponse, DocumentPurgeProofResponseSchema, type DocumentPurgeResponse, DocumentPurgeResponseSchema, type DocumentSyncPullPageResponse, DocumentSyncPullPageResponseSchema, type DocumentSyncResponse, DocumentSyncResponseSchema, type DocumentSyncUpdateResponse, DocumentSyncUpdateResponseSchema, type DocumentWriterProjectionResponse, DocumentWriterProjectionResponseSchema, type DocumentWriterProjectionWireResponse, DocumentWriterProjectionWireResponseSchema, documentKekTargetsFromContentKeyBundle, isDocumentContentKeyBundleResponse, isDocumentCreateResponse, isDocumentKekTargetsResponse, isDocumentLinkSetMutationResponse, isDocumentPurgeProofResponse, isDocumentPurgeResponse, isDocumentSyncResponse, isDocumentWriterProjectionResponse, isDocumentWriterProjectionWireResponse, } from "./documentMutation.js";
16
16
  export { DOCUMENT_MUTATION_ERROR_CODES, DocumentMutationBehaviorErrorCodeSchema, type DocumentMutationErrorCode, DocumentMutationErrorCodeSchema, type DocumentMutationFailureResponse, DocumentMutationFailureResponseSchema, } from "./documentMutationError.js";
17
17
  export { DOCUMENT_NOT_FOUND_ERROR_CODE, DOCUMENT_PROJECTION_ERROR_CODES, DOCUMENT_SYNC_ERROR_CODES, type DocumentNotFoundErrorCode, type DocumentNotFoundErrorResponse, DocumentNotFoundErrorResponseSchema, type DocumentProjectionErrorCode, DocumentProjectionErrorCodeSchema, type DocumentSyncErrorCode, DocumentSyncErrorCodeSchema, type DocumentSyncErrorResponse, DocumentSyncErrorResponseSchema, type DocumentSyncStateStaleErrorResponse, DocumentSyncStateStaleErrorResponseSchema, type DocumentWriterProjectionErrorResponse, DocumentWriterProjectionErrorResponseSchema, isDocumentSyncErrorCode, isDocumentSyncErrorResponse, isDocumentSyncStateStaleErrorResponse, } from "./documentSyncError.js";
18
18
  export { type ErrorResponse, ErrorResponseSchema, isErrorResponse, } from "./error.js";