@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.
- package/data/documents/shared/sync/syncResponseAuthorization.js +12 -1
- package/data/documents/shared/sync/syncResponseAuthorization.js.map +1 -1
- package/data/documents/shared/sync/syncResponses.js +2 -2
- package/data/documents/shared/sync/syncResponses.js.map +1 -1
- package/data/keyingProjectionVerification/checkpoints/checkpointContext.js +12 -3
- package/data/keyingProjectionVerification/checkpoints/checkpointContext.js.map +1 -1
- package/data/keyingProjectionVerification/checkpoints/verifiedBundleBytes.js +73 -8
- package/data/keyingProjectionVerification/checkpoints/verifiedBundleBytes.js.map +1 -1
- package/data/keyingProjectionVerification/container/containerAncestorCitations.js +20 -4
- package/data/keyingProjectionVerification/container/containerAncestorCitations.js.map +1 -1
- package/data/keyingProjectionVerification/container/containerManifestVerification.js +43 -32
- package/data/keyingProjectionVerification/container/containerManifestVerification.js.map +1 -1
- package/data/keyingProjectionVerification/container/containerSignedParentReference.js +129 -0
- package/data/keyingProjectionVerification/container/containerSignedParentReference.js.map +1 -0
- package/data/keyingProjectionVerification/document/documentManifestVerification.js +28 -7
- package/data/keyingProjectionVerification/document/documentManifestVerification.js.map +1 -1
- package/data/persistence/verifiedCitations/bundleCitationRows.js.map +1 -1
- package/data/persistence/verifiedCitations/citationCollection.js +2 -2
- package/data/persistence/verifiedCitations/citationCollection.js.map +1 -1
- package/data/persistence/verifiedManifestBundlePersistence.d.ts +3 -2
- package/data/persistence/verifiedManifestBundlePersistence.js +1 -1
- package/data/persistence/verifiedManifestBundlePersistence.js.map +1 -1
- package/internal/api-client/ApiClient.d.ts +7 -7
- package/internal/api-client/client/apiClientContext.d.ts +1 -1
- package/internal/api-client/client/blobs.d.ts +1 -1
- package/internal/api-client/client/documents.d.ts +6 -6
- package/internal/api-client/verifiedManifestCitations.d.ts +4 -3
- package/internal/api-client/verifiedManifestCitations.js +3 -3
- package/internal/api-client/verifiedManifestCitations.js.map +1 -1
- package/internal/validators/operation/attachments.d.ts +2 -2
- package/internal/validators/operation/documentSync.d.ts +24 -24
- package/internal/validators/operation/writerProjections.d.ts +8 -8
- package/internal/validators/response/blob.d.ts +6 -6
- package/internal/validators/response/blob.js +12 -2
- package/internal/validators/response/blob.js.map +1 -1
- package/internal/validators/response/container.d.ts +4 -4
- package/internal/validators/response/documentMutation.d.ts +4 -4
- package/internal/validators/response/documentSyncSchema.d.ts +48 -48
- package/internal/validators/response/documentSyncSchema.js +1 -1
- package/internal/validators/response/documentSyncSchema.js.map +1 -1
- package/internal/validators/response/manifestBundleReferences.js +4 -3
- package/internal/validators/response/manifestBundleReferences.js.map +1 -1
- package/internal/validators/response/writerProjectionWire.d.ts +4 -4
- package/internal/validators/response/writerProjectionWire.js +8 -5
- package/internal/validators/response/writerProjectionWire.js.map +1 -1
- package/internal/validators/util/index.d.ts +1 -0
- package/internal/validators/util/index.js +1 -0
- package/internal/validators/util/index.js.map +1 -1
- package/internal/validators/util/servedManifestBundle.d.ts +71 -0
- package/internal/validators/util/servedManifestBundle.js +100 -0
- package/internal/validators/util/servedManifestBundle.js.map +1 -0
- package/package.json +1 -1
- package/workflows/blobs/hydration/decrypt.js +17 -1
- package/workflows/blobs/hydration/decrypt.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"citationCollection.js","sourceRoot":"","sources":["citationCollection.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,
|
|
1
|
+
{"version":3,"file":"citationCollection.js","sourceRoot":"","sources":["citationCollection.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EACL,wCAAwC,GAEzC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE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AsB,EACtB,OAA+B,EAC/B,MAA8B,EAC9B,KAAa;IAEb,MAAM,SAAS,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,gBAAgB,CACtC,EAAE,EACF,cAAc,EACd,OAAO,EACP,MAAM,EACN,SAAS,CAAC,SAAS,CACpB;QACC,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,kBAAkB,CAAC,CAAC;IACrD,MAAM,cAAc,CAAC,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAC7D,MAAM,aAAa,CAAC,EAAE,EAAE,cAAc,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAC1D,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC;AAC9E,CAAC","sourcesContent":["import type {\n HeldProjectionCitation,\n WriterProjectionTarget,\n} from \"@tearleads/api-client\";\nimport { toFingerprint } from \"@tearleads/crypto\";\nimport {\n isServedAccessManifestBundleWireResponse,\n type ServedAccessManifestBundleWireResponse,\n} from \"@tearleads/validators/util\";\nimport { and, asc, desc, eq, ne, notInArray } from \"drizzle-orm\";\nimport { verifiedAccessManifestBundles as bundles } from \"../../sqlite/schema/verifiedManifestBundleSchema\";\nimport type { ClientSQLiteDatabase } from \"../../sqlite/sqlitePersistenceRuntime\";\nimport {\n batchedObjectRows,\n objectRows,\n type StoredBundleRow,\n storedColumns,\n} from \"./bundleCitationRows\";\nimport type { CitedObject } from \"./citationScope\";\nimport { KEK_LEVEL_OBJECT_KIND, readStoredKekLevel } from \"./kekLevelCitations\";\nimport { lineageKekLevels } from \"./levelCitationRows\";\n\nasync function readStoredBundle(\n row: StoredBundleRow,\n): Promise<ServedAccessManifestBundleWireResponse | null> {\n if (\n (await toFingerprint(new TextEncoder().encode(row.bundleJson))) !==\n row.bundleDigest\n )\n return null;\n try {\n const bundle: unknown = JSON.parse(row.bundleJson);\n return isServedAccessManifestBundleWireResponse(bundle) &&\n bundle.manifestHash === row.manifestHash\n ? bundle\n : null;\n } catch {\n return null;\n }\n}\n\nfunction recentRows(\n db: ClientSQLiteDatabase,\n organizationId: string,\n limit: number,\n excluded: readonly string[] = [],\n offset = 0,\n) {\n return db\n .select(storedColumns)\n .from(bundles)\n .where(\n and(\n eq(bundles.organizationId, organizationId),\n ne(bundles.objectKind, KEK_LEVEL_OBJECT_KIND),\n excluded.length > 0\n ? notInArray(bundles.manifestHash, [...excluded])\n : undefined,\n ),\n )\n .orderBy(desc(bundles.verifiedAt), asc(bundles.manifestHash))\n .limit(limit)\n .offset(offset);\n}\n\nfunction citationCollector(limit: number) {\n const cited = new Map<string, HeldProjectionCitation>();\n const damaged: string[] = [];\n return {\n cited,\n damaged,\n remaining: () => limit - cited.size,\n async collect(\n rows: readonly StoredBundleRow[],\n read: (\n row: StoredBundleRow,\n ) => Promise<HeldProjectionCitation | null> = readStoredBundle,\n ) {\n for (const row of rows) {\n if (cited.size >= limit || cited.has(row.manifestHash)) continue;\n const citation = await read(row);\n if (citation) cited.set(row.manifestHash, citation);\n else damaged.push(row.manifestHash);\n }\n },\n };\n}\n\ntype CitationCollector = ReturnType<typeof citationCollector>;\n\nasync function collectObjects(\n db: ClientSQLiteDatabase,\n organizationId: string,\n objects: readonly CitedObject[],\n collector: CitationCollector,\n) {\n if (collector.remaining() === 0) return;\n const rows =\n objects.length > 2\n ? await batchedObjectRows(\n db,\n organizationId,\n objects,\n collector.remaining(),\n readStoredBundle,\n )\n : null;\n if (rows) await collector.collect(rows);\n else\n for (const object of objects)\n if (collector.remaining() > 0)\n await collector.collect(\n await objectRows(db, organizationId, object, collector.remaining()),\n );\n}\n\nasync function collectRecent(\n db: ClientSQLiteDatabase,\n organizationId: string,\n collector: CitationCollector,\n limit: number,\n) {\n if (collector.remaining() === 0) return;\n const window = limit + collector.cited.size;\n const damageCount = collector.damaged.length;\n await collector.collect(\n await recentRows(db, organizationId, collector.remaining(), [\n ...collector.cited.keys(),\n ]),\n );\n // Damage can free quota. Replay the original recent window in bounded\n // pages; a healthy read never loads duplicate JSON.\n if (collector.damaged.length > damageCount)\n for (\n let offset = 0;\n offset < window && collector.remaining() > 0;\n offset += limit\n )\n await collector.collect(\n await recentRows(\n db,\n organizationId,\n Math.min(limit, window - offset),\n [],\n offset,\n ),\n );\n}\n\n/**\n * Healthy reads load at most the hint quota in JSON across all phases. Damage\n * may require more reads to preserve the old fallback, each bounded by that\n * quota; only accepted citations are retained. None are verifier trust input.\n */\nexport async function collectVerifiedManifestCitations(\n db: ClientSQLiteDatabase,\n organizationId: string,\n objects: readonly CitedObject[],\n target: WriterProjectionTarget,\n limit: number,\n) {\n const collector = citationCollector(limit);\n for await (const row of lineageKekLevels(\n db,\n organizationId,\n objects,\n target,\n collector.remaining,\n ))\n await collector.collect([row], readStoredKekLevel);\n await collectObjects(db, organizationId, objects, collector);\n await collectRecent(db, organizationId, collector, limit);\n return { cited: [...collector.cited.values()], damaged: collector.damaged };\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HeldProjectionCitation, VerifiedManifestCitations, WriterProjectionTarget } from "../../internal/api-client/index.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type ServedAccessManifestBundleWireResponse } from "../../internal/validators/util/index.js";
|
|
3
3
|
import { verifiedAccessManifestBundles as bundles } from "../sqlite/schema/verifiedManifestBundleSchema.js";
|
|
4
4
|
import { type ClientSQLiteTransactionScope } from "../sqlite/sqlitePersistenceRuntime.js";
|
|
5
5
|
import { type ExecSql } from "../sqlite/sqlSchema.js";
|
|
@@ -10,7 +10,8 @@ import { type VerifiedKekLevel } from "./verifiedCitations/kekLevelCitations.js"
|
|
|
10
10
|
*/
|
|
11
11
|
export declare const MAX_VERIFIED_MANIFEST_BUNDLES = 1024;
|
|
12
12
|
interface VerifiedBundle {
|
|
13
|
-
|
|
13
|
+
/** The served bytes; the decoded state is rebuilt from them on refill. */
|
|
14
|
+
readonly bundle: ServedAccessManifestBundleWireResponse;
|
|
14
15
|
readonly checkpoint: {
|
|
15
16
|
readonly objectKind: string;
|
|
16
17
|
readonly organizationId: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toFingerprint } from "../../internal/crypto/index.js";
|
|
2
|
-
import { KNOWN_MANIFEST_HINT_LIMIT } from "../../internal/validators/util/index.js";
|
|
2
|
+
import { KNOWN_MANIFEST_HINT_LIMIT, } from "../../internal/validators/util/index.js";
|
|
3
3
|
import { and, asc, eq, inArray, notInArray, sql } from "drizzle-orm";
|
|
4
4
|
import { containerTables, localIntentTables } from "../sqlite/schema/index.js";
|
|
5
5
|
import { documentContainerProjectionTables, documentProjectionTables, } from "../sqlite/schema/documentProjectionSchema.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifiedManifestBundlePersistence.js","sourceRoot":"","sources":["verifiedManifestBundlePersistence.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EACL,iCAAiC,EACjC,wBAAwB,GACzB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,6BAA6B,IAAI,OAAO,EACxC,4BAA4B,GAC7B,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAEL,iCAAiC,GAClC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CA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AAO,CAAC;aAC7C,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YAC5B,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;gBAChD,MAAM,MAAM;qBACT,MAAM,CAAC,OAAO,CAAC;qBACf,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;qBAC3C,GAAG,EAAE,CAAC;QACb,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC5B,OAAO,KAAK,CAAC;AACf,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,+BAA+B,CAC7C,cAAoC;IAEpC,OAAO;QACL,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YACrB,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;YACjC,OAAO,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACvE,CAAC;KACF,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,4CAA4C,CAChE,EAAgC,EAChC,cAAsB;IAEtB,MAAM,EAAE;SACL,MAAM,CAAC,OAAO,CAAC;SACf,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;SACjD,GAAG,EAAE,CAAC;AACX,CAAC","sourcesContent":["import type {\n HeldProjectionCitation,\n VerifiedManifestCitations,\n WriterProjectionTarget,\n} from \"@tearleads/api-client\";\nimport { toFingerprint } from \"@tearleads/crypto\";\nimport type { AccessManifestBundleWireResponse } from \"@tearleads/validators/response\";\nimport { KNOWN_MANIFEST_HINT_LIMIT } from \"@tearleads/validators/util\";\nimport { and, asc, eq, inArray, notInArray, sql } from \"drizzle-orm\";\nimport { containerTables, localIntentTables } from \"../sqlite/schema\";\nimport {\n documentContainerProjectionTables,\n documentProjectionTables,\n} from \"../sqlite/schema/documentProjectionSchema\";\nimport {\n verifiedAccessManifestBundles as bundles,\n verifiedManifestBundleTables,\n} from \"../sqlite/schema/verifiedManifestBundleSchema\";\nimport { sqliteInsertBatchSize } from \"../sqlite/sqliteBindBudget\";\nimport {\n type ClientSQLiteTransactionScope,\n getClientSQLitePersistenceRuntime,\n} from \"../sqlite/sqlitePersistenceRuntime\";\nimport { excludedValue } from \"../sqlite/sqliteUpsert\";\nimport { type ExecSql, ensureSqlTables } from \"../sqlite/sqlSchema\";\nimport { collectVerifiedManifestCitations } from \"./verifiedCitations/citationCollection\";\nimport {\n citedObjects,\n targetOrganization,\n} from \"./verifiedCitations/citationScope\";\nimport {\n KEK_LEVEL_OBJECT_KIND,\n kekLevelRow,\n type VerifiedKekLevel,\n} from \"./verifiedCitations/kekLevelCitations\";\n\n/**\n * Bounds local bytes (a bundle is ~10–20 KB). Evicting the least recently\n * verified rows only makes a later read carry those bundles again.\n */\nexport const MAX_VERIFIED_MANIFEST_BUNDLES = 1024;\nconst STATEMENT_BATCH = 200;\n\ninterface VerifiedBundle {\n readonly bundle: AccessManifestBundleWireResponse;\n readonly checkpoint: {\n readonly objectKind: string;\n readonly organizationId: string;\n readonly objectId: string;\n readonly epoch: number;\n };\n}\n\n/** Bytes a projection verification accepted: a bundle or a KEK level. */\nexport type VerifiedManifestBundle = VerifiedBundle | VerifiedKekLevel;\n\nfunction sha256Hex(text: string): Promise<string> {\n return toFingerprint(new TextEncoder().encode(text));\n}\n\nconst BUNDLE_WRITE_BATCH_SIZE = sqliteInsertBatchSize(bundles);\n\nfunction slices<T>(values: readonly T[], size: number): T[][] {\n const result: T[][] = [];\n for (let index = 0; index < values.length; index += size)\n result.push(values.slice(index, index + size));\n return result;\n}\n\nfunction batches<T>(values: readonly T[]): T[][] {\n return slices(values, STATEMENT_BATCH);\n}\n\nasync function pruneInTransaction(\n tx: ClientSQLiteTransactionScope,\n): Promise<void> {\n const [row] = await tx.select({ count: sql<number>`count(*)` }).from(bundles);\n const excess = (row?.count ?? 0) - MAX_VERIFIED_MANIFEST_BUNDLES;\n if (excess <= 0) return;\n const evicted = await tx\n .select({ manifestHash: bundles.manifestHash })\n .from(bundles)\n .orderBy(asc(bundles.verifiedAt), asc(bundles.manifestHash))\n .limit(excess);\n for (const batch of batches(evicted.map((entry) => entry.manifestHash)))\n await tx.delete(bundles).where(inArray(bundles.manifestHash, batch)).run();\n}\n\n/** A verified bundle's exact JSON and that JSON's digest. */\nexport type VerifiedManifestBundleRow = Omit<\n typeof bundles.$inferInsert,\n \"verifiedAt\"\n>;\n\n/**\n * Prepares rows for bundles and KEK levels that just passed projection\n * verification. The digests are computed here, before the checkpoint\n * transaction that writes them begins.\n */\nexport async function verifiedManifestBundleRows(\n entries: readonly VerifiedManifestBundle[],\n): Promise<VerifiedManifestBundleRow[]> {\n const bundleEntries: VerifiedBundle[] = [];\n const levelEntries: VerifiedKekLevel[] = [];\n for (const entry of entries)\n if (\"kekLevel\" in entry) levelEntries.push(entry);\n else bundleEntries.push(entry);\n // One level per container: its newest epoch, the last one seen on a tie.\n const levelRows = new Map<string, VerifiedManifestBundleRow>();\n for (const level of levelEntries) {\n const row = await kekLevelRow(level);\n const held = row && levelRows.get(row.objectId);\n if (row && (!held || held.epoch <= row.epoch))\n levelRows.set(row.objectId, row);\n }\n return [...(await bundleRows(bundleEntries)), ...levelRows.values()];\n}\n\nfunction bundleRows(\n entries: readonly VerifiedBundle[],\n): Promise<VerifiedManifestBundleRow[]> {\n const unique = new Map(\n entries.map((entry) => [entry.bundle.manifestHash, entry]),\n );\n return Promise.all(\n [...unique.values()].map(async ({ bundle, checkpoint }) => {\n const bundleJson = JSON.stringify(bundle);\n return {\n manifestHash: bundle.manifestHash,\n organizationId: checkpoint.organizationId,\n objectKind: checkpoint.objectKind,\n objectId: checkpoint.objectId,\n epoch: checkpoint.epoch,\n bundleJson,\n bundleDigest: await sha256Hex(bundleJson),\n };\n }),\n );\n}\n\n/**\n * Records verified bundles inside the transaction that finalizes their\n * projection's checkpoints, so they commit or roll back with it and no cache\n * work outlives the verification. Freshly verified bytes replace any stored\n * copy.\n */\nexport async function writeVerifiedManifestBundlesInTransaction(\n tx: ClientSQLiteTransactionScope,\n rows: readonly VerifiedManifestBundleRow[],\n verifiedAt: string,\n): Promise<void> {\n if (rows.length === 0) return;\n const stored = await touchStoredDigests(\n tx,\n rows.map((row) => row.manifestHash),\n verifiedAt,\n );\n // A repeated hash keeps its last changed row, as sequential upserts would.\n const changed = new Map(\n rows\n .filter((row) => stored.get(row.manifestHash) !== row.bundleDigest)\n .map((row) => [row.manifestHash, { ...row, verifiedAt }]),\n );\n for (const batch of slices([...changed.values()], BUNDLE_WRITE_BATCH_SIZE))\n await tx\n .insert(bundles)\n .values(batch)\n .onConflictDoUpdate({\n target: bundles.manifestHash,\n set: {\n organizationId: excludedValue(bundles.organizationId),\n objectKind: excludedValue(bundles.objectKind),\n objectId: excludedValue(bundles.objectId),\n epoch: excludedValue(bundles.epoch),\n bundleJson: excludedValue(bundles.bundleJson),\n bundleDigest: excludedValue(bundles.bundleDigest),\n verifiedAt: excludedValue(bundles.verifiedAt),\n },\n })\n .run();\n // All incremental SDK level writes pass here. Both checkpoint callers\n // prepare them with verifiedManifestBundleRows (one level per container),\n // then write and drop siblings in the same serialized transaction. Thus an\n // unchanged level already removed its siblings; eviction/reset only delete.\n // Restored caches must preserve that invariant too: this fast path does not\n // repair externally injected stale siblings.\n await dropSupersededKekLevels(tx, [...changed.values()]);\n // Replacing or touching existing rows cannot grow the bounded cache.\n if (rows.some((row) => !stored.has(row.manifestHash))) {\n await pruneInTransaction(tx);\n }\n}\n\n/**\n * A container keeps only its latest verified level: the API serves its\n * current level, so an older one can never be cited usefully again.\n */\nasync function dropSupersededKekLevels(\n tx: ClientSQLiteTransactionScope,\n rows: readonly VerifiedManifestBundleRow[],\n): Promise<void> {\n const levels = rows.filter((row) => row.objectKind === KEK_LEVEL_OBJECT_KIND);\n for (const batch of batches(levels))\n await tx\n .delete(bundles)\n .where(\n and(\n eq(bundles.objectKind, KEK_LEVEL_OBJECT_KIND),\n inArray(\n bundles.objectId,\n batch.map((row) => row.objectId),\n ),\n notInArray(\n bundles.manifestHash,\n batch.map((row) => row.manifestHash),\n ),\n ),\n )\n .run();\n}\n\nasync function touchStoredDigests(\n tx: ClientSQLiteTransactionScope,\n manifestHashes: readonly string[],\n verifiedAt: string,\n): Promise<Map<string, string>> {\n const digests = new Map<string, string>();\n for (const batch of batches(manifestHashes)) {\n const rows = await tx\n .update(bundles)\n .set({ verifiedAt })\n .where(inArray(bundles.manifestHash, batch))\n .returning({\n bundleDigest: bundles.bundleDigest,\n manifestHash: bundles.manifestHash,\n });\n for (const row of rows) digests.set(row.manifestHash, row.bundleDigest);\n }\n return digests;\n}\n\n/**\n * The latest verified KEK level of each container the target's projection\n * walks (supplemented by organization-recency levels for a pending move,\n * or when the lineage has no stored level); then verified bundles of those\n * objects, newest epochs first; then\n * the most recently verified bundles of its organization, since a\n * just-verified parent is the likeliest part of a new child's projection.\n * Citations never leave the target's organization: an object whose\n * organization the device cannot place cites nothing. Damaged rows are\n * dropped.\n */\nexport async function loadVerifiedManifestCitations(\n execSql: ExecSql,\n target: WriterProjectionTarget,\n requestedLimit = KNOWN_MANIFEST_HINT_LIMIT,\n): Promise<HeldProjectionCitation[]> {\n const limit = Math.min(KNOWN_MANIFEST_HINT_LIMIT, Math.floor(requestedLimit));\n if (!(limit > 0)) return [];\n await ensureSqlTables(execSql, [\n ...verifiedManifestBundleTables,\n ...containerTables,\n ...documentContainerProjectionTables,\n ...documentProjectionTables,\n ...localIntentTables,\n ]);\n const { db } = getClientSQLitePersistenceRuntime(execSql);\n const objects = await citedObjects(db, target);\n const organizationId = await targetOrganization(db, target, objects);\n if (organizationId === null) return [];\n const { cited, damaged } = await collectVerifiedManifestCitations(\n db,\n organizationId,\n objects,\n target,\n limit,\n );\n if (damaged.length > 0)\n await getClientSQLitePersistenceRuntime(execSql)\n .runMutation(async (handle) => {\n for (const batch of batches([...new Set(damaged)]))\n await handle\n .delete(bundles)\n .where(inArray(bundles.manifestHash, batch))\n .run();\n })\n .catch(() => undefined);\n return cited;\n}\n\n/** Cites from whichever database the signed-in identity currently uses. */\nexport function createVerifiedManifestCitations(\n resolveExecSql: () => ExecSql | null,\n): VerifiedManifestCitations {\n return {\n cite: async (target) => {\n const execSql = resolveExecSql();\n return execSql ? loadVerifiedManifestCitations(execSql, target) : [];\n },\n };\n}\n\n/** Drops an organization's verified bundles when a remote reset forgets it. */\nexport async function deleteVerifiedManifestBundlesForOrganization(\n tx: ClientSQLiteTransactionScope,\n organizationId: string,\n): Promise<void> {\n await tx\n .delete(bundles)\n .where(eq(bundles.organizationId, organizationId))\n .run();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"verifiedManifestBundlePersistence.js","sourceRoot":"","sources":["verifiedManifestBundlePersistence.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EACL,yBAAyB,GAE1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EACL,iCAAiC,EACjC,wBAAwB,GACzB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,6BAA6B,IAAI,OAAO,EACxC,4BAA4B,GAC7B,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAEL,iCAAiC,GAClC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAgB,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACpE,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YAC5B,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;gBAChD,MAAM,MAAM;qBACT,MAAM,CAAC,OAAO,CAAC;qBACf,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;qBAC3C,GAAG,EAAE,CAAC;QACb,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC5B,OAAO,KAAK,CAAC;AACf,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,+BAA+B,CAC7C,cAAoC;IAEpC,OAAO;QACL,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YACrB,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;YACjC,OAAO,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACvE,CAAC;KACF,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,4CAA4C,CAChE,EAAgC,EAChC,cAAsB;IAEtB,MAAM,EAAE;SACL,MAAM,CAAC,OAAO,CAAC;SACf,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;SACjD,GAAG,EAAE,CAAC;AACX,CAAC","sourcesContent":["import type {\n HeldProjectionCitation,\n VerifiedManifestCitations,\n WriterProjectionTarget,\n} from \"@tearleads/api-client\";\nimport { toFingerprint } from \"@tearleads/crypto\";\nimport {\n KNOWN_MANIFEST_HINT_LIMIT,\n type ServedAccessManifestBundleWireResponse,\n} from \"@tearleads/validators/util\";\nimport { and, asc, eq, inArray, notInArray, sql } from \"drizzle-orm\";\nimport { containerTables, localIntentTables } from \"../sqlite/schema\";\nimport {\n documentContainerProjectionTables,\n documentProjectionTables,\n} from \"../sqlite/schema/documentProjectionSchema\";\nimport {\n verifiedAccessManifestBundles as bundles,\n verifiedManifestBundleTables,\n} from \"../sqlite/schema/verifiedManifestBundleSchema\";\nimport { sqliteInsertBatchSize } from \"../sqlite/sqliteBindBudget\";\nimport {\n type ClientSQLiteTransactionScope,\n getClientSQLitePersistenceRuntime,\n} from \"../sqlite/sqlitePersistenceRuntime\";\nimport { excludedValue } from \"../sqlite/sqliteUpsert\";\nimport { type ExecSql, ensureSqlTables } from \"../sqlite/sqlSchema\";\nimport { collectVerifiedManifestCitations } from \"./verifiedCitations/citationCollection\";\nimport {\n citedObjects,\n targetOrganization,\n} from \"./verifiedCitations/citationScope\";\nimport {\n KEK_LEVEL_OBJECT_KIND,\n kekLevelRow,\n type VerifiedKekLevel,\n} from \"./verifiedCitations/kekLevelCitations\";\n\n/**\n * Bounds local bytes (a bundle is ~10–20 KB). Evicting the least recently\n * verified rows only makes a later read carry those bundles again.\n */\nexport const MAX_VERIFIED_MANIFEST_BUNDLES = 1024;\nconst STATEMENT_BATCH = 200;\n\ninterface VerifiedBundle {\n /** The served bytes; the decoded state is rebuilt from them on refill. */\n readonly bundle: ServedAccessManifestBundleWireResponse;\n readonly checkpoint: {\n readonly objectKind: string;\n readonly organizationId: string;\n readonly objectId: string;\n readonly epoch: number;\n };\n}\n\n/** Bytes a projection verification accepted: a bundle or a KEK level. */\nexport type VerifiedManifestBundle = VerifiedBundle | VerifiedKekLevel;\n\nfunction sha256Hex(text: string): Promise<string> {\n return toFingerprint(new TextEncoder().encode(text));\n}\n\nconst BUNDLE_WRITE_BATCH_SIZE = sqliteInsertBatchSize(bundles);\n\nfunction slices<T>(values: readonly T[], size: number): T[][] {\n const result: T[][] = [];\n for (let index = 0; index < values.length; index += size)\n result.push(values.slice(index, index + size));\n return result;\n}\n\nfunction batches<T>(values: readonly T[]): T[][] {\n return slices(values, STATEMENT_BATCH);\n}\n\nasync function pruneInTransaction(\n tx: ClientSQLiteTransactionScope,\n): Promise<void> {\n const [row] = await tx.select({ count: sql<number>`count(*)` }).from(bundles);\n const excess = (row?.count ?? 0) - MAX_VERIFIED_MANIFEST_BUNDLES;\n if (excess <= 0) return;\n const evicted = await tx\n .select({ manifestHash: bundles.manifestHash })\n .from(bundles)\n .orderBy(asc(bundles.verifiedAt), asc(bundles.manifestHash))\n .limit(excess);\n for (const batch of batches(evicted.map((entry) => entry.manifestHash)))\n await tx.delete(bundles).where(inArray(bundles.manifestHash, batch)).run();\n}\n\n/** A verified bundle's exact JSON and that JSON's digest. */\nexport type VerifiedManifestBundleRow = Omit<\n typeof bundles.$inferInsert,\n \"verifiedAt\"\n>;\n\n/**\n * Prepares rows for bundles and KEK levels that just passed projection\n * verification. The digests are computed here, before the checkpoint\n * transaction that writes them begins.\n */\nexport async function verifiedManifestBundleRows(\n entries: readonly VerifiedManifestBundle[],\n): Promise<VerifiedManifestBundleRow[]> {\n const bundleEntries: VerifiedBundle[] = [];\n const levelEntries: VerifiedKekLevel[] = [];\n for (const entry of entries)\n if (\"kekLevel\" in entry) levelEntries.push(entry);\n else bundleEntries.push(entry);\n // One level per container: its newest epoch, the last one seen on a tie.\n const levelRows = new Map<string, VerifiedManifestBundleRow>();\n for (const level of levelEntries) {\n const row = await kekLevelRow(level);\n const held = row && levelRows.get(row.objectId);\n if (row && (!held || held.epoch <= row.epoch))\n levelRows.set(row.objectId, row);\n }\n return [...(await bundleRows(bundleEntries)), ...levelRows.values()];\n}\n\nfunction bundleRows(\n entries: readonly VerifiedBundle[],\n): Promise<VerifiedManifestBundleRow[]> {\n const unique = new Map(\n entries.map((entry) => [entry.bundle.manifestHash, entry]),\n );\n return Promise.all(\n [...unique.values()].map(async ({ bundle, checkpoint }) => {\n const bundleJson = JSON.stringify(bundle);\n return {\n manifestHash: bundle.manifestHash,\n organizationId: checkpoint.organizationId,\n objectKind: checkpoint.objectKind,\n objectId: checkpoint.objectId,\n epoch: checkpoint.epoch,\n bundleJson,\n bundleDigest: await sha256Hex(bundleJson),\n };\n }),\n );\n}\n\n/**\n * Records verified bundles inside the transaction that finalizes their\n * projection's checkpoints, so they commit or roll back with it and no cache\n * work outlives the verification. Freshly verified bytes replace any stored\n * copy.\n */\nexport async function writeVerifiedManifestBundlesInTransaction(\n tx: ClientSQLiteTransactionScope,\n rows: readonly VerifiedManifestBundleRow[],\n verifiedAt: string,\n): Promise<void> {\n if (rows.length === 0) return;\n const stored = await touchStoredDigests(\n tx,\n rows.map((row) => row.manifestHash),\n verifiedAt,\n );\n // A repeated hash keeps its last changed row, as sequential upserts would.\n const changed = new Map(\n rows\n .filter((row) => stored.get(row.manifestHash) !== row.bundleDigest)\n .map((row) => [row.manifestHash, { ...row, verifiedAt }]),\n );\n for (const batch of slices([...changed.values()], BUNDLE_WRITE_BATCH_SIZE))\n await tx\n .insert(bundles)\n .values(batch)\n .onConflictDoUpdate({\n target: bundles.manifestHash,\n set: {\n organizationId: excludedValue(bundles.organizationId),\n objectKind: excludedValue(bundles.objectKind),\n objectId: excludedValue(bundles.objectId),\n epoch: excludedValue(bundles.epoch),\n bundleJson: excludedValue(bundles.bundleJson),\n bundleDigest: excludedValue(bundles.bundleDigest),\n verifiedAt: excludedValue(bundles.verifiedAt),\n },\n })\n .run();\n // All incremental SDK level writes pass here. Both checkpoint callers\n // prepare them with verifiedManifestBundleRows (one level per container),\n // then write and drop siblings in the same serialized transaction. Thus an\n // unchanged level already removed its siblings; eviction/reset only delete.\n // Restored caches must preserve that invariant too: this fast path does not\n // repair externally injected stale siblings.\n await dropSupersededKekLevels(tx, [...changed.values()]);\n // Replacing or touching existing rows cannot grow the bounded cache.\n if (rows.some((row) => !stored.has(row.manifestHash))) {\n await pruneInTransaction(tx);\n }\n}\n\n/**\n * A container keeps only its latest verified level: the API serves its\n * current level, so an older one can never be cited usefully again.\n */\nasync function dropSupersededKekLevels(\n tx: ClientSQLiteTransactionScope,\n rows: readonly VerifiedManifestBundleRow[],\n): Promise<void> {\n const levels = rows.filter((row) => row.objectKind === KEK_LEVEL_OBJECT_KIND);\n for (const batch of batches(levels))\n await tx\n .delete(bundles)\n .where(\n and(\n eq(bundles.objectKind, KEK_LEVEL_OBJECT_KIND),\n inArray(\n bundles.objectId,\n batch.map((row) => row.objectId),\n ),\n notInArray(\n bundles.manifestHash,\n batch.map((row) => row.manifestHash),\n ),\n ),\n )\n .run();\n}\n\nasync function touchStoredDigests(\n tx: ClientSQLiteTransactionScope,\n manifestHashes: readonly string[],\n verifiedAt: string,\n): Promise<Map<string, string>> {\n const digests = new Map<string, string>();\n for (const batch of batches(manifestHashes)) {\n const rows = await tx\n .update(bundles)\n .set({ verifiedAt })\n .where(inArray(bundles.manifestHash, batch))\n .returning({\n bundleDigest: bundles.bundleDigest,\n manifestHash: bundles.manifestHash,\n });\n for (const row of rows) digests.set(row.manifestHash, row.bundleDigest);\n }\n return digests;\n}\n\n/**\n * The latest verified KEK level of each container the target's projection\n * walks (supplemented by organization-recency levels for a pending move,\n * or when the lineage has no stored level); then verified bundles of those\n * objects, newest epochs first; then\n * the most recently verified bundles of its organization, since a\n * just-verified parent is the likeliest part of a new child's projection.\n * Citations never leave the target's organization: an object whose\n * organization the device cannot place cites nothing. Damaged rows are\n * dropped.\n */\nexport async function loadVerifiedManifestCitations(\n execSql: ExecSql,\n target: WriterProjectionTarget,\n requestedLimit = KNOWN_MANIFEST_HINT_LIMIT,\n): Promise<HeldProjectionCitation[]> {\n const limit = Math.min(KNOWN_MANIFEST_HINT_LIMIT, Math.floor(requestedLimit));\n if (!(limit > 0)) return [];\n await ensureSqlTables(execSql, [\n ...verifiedManifestBundleTables,\n ...containerTables,\n ...documentContainerProjectionTables,\n ...documentProjectionTables,\n ...localIntentTables,\n ]);\n const { db } = getClientSQLitePersistenceRuntime(execSql);\n const objects = await citedObjects(db, target);\n const organizationId = await targetOrganization(db, target, objects);\n if (organizationId === null) return [];\n const { cited, damaged } = await collectVerifiedManifestCitations(\n db,\n organizationId,\n objects,\n target,\n limit,\n );\n if (damaged.length > 0)\n await getClientSQLitePersistenceRuntime(execSql)\n .runMutation(async (handle) => {\n for (const batch of batches([...new Set(damaged)]))\n await handle\n .delete(bundles)\n .where(inArray(bundles.manifestHash, batch))\n .run();\n })\n .catch(() => undefined);\n return cited;\n}\n\n/** Cites from whichever database the signed-in identity currently uses. */\nexport function createVerifiedManifestCitations(\n resolveExecSql: () => ExecSql | null,\n): VerifiedManifestCitations {\n return {\n cite: async (target) => {\n const execSql = resolveExecSql();\n return execSql ? loadVerifiedManifestCitations(execSql, target) : [];\n },\n };\n}\n\n/** Drops an organization's verified bundles when a remote reset forgets it. */\nexport async function deleteVerifiedManifestBundlesForOrganization(\n tx: ClientSQLiteTransactionScope,\n organizationId: string,\n): Promise<void> {\n await tx\n .delete(bundles)\n .where(eq(bundles.organizationId, organizationId))\n .run();\n}\n"]}
|
|
@@ -2789,12 +2789,6 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
2789
2789
|
};
|
|
2790
2790
|
updates: {
|
|
2791
2791
|
accessEpoch: number;
|
|
2792
|
-
authorizationTargets: {
|
|
2793
|
-
containerId: string;
|
|
2794
|
-
containerKeyEpoch: number;
|
|
2795
|
-
containerKeyEpochId: string;
|
|
2796
|
-
containerManifestHash: string;
|
|
2797
|
-
}[];
|
|
2798
2792
|
authorFingerprint: string;
|
|
2799
2793
|
createdAt: string;
|
|
2800
2794
|
documentId: string;
|
|
@@ -2804,6 +2798,12 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
2804
2798
|
partialStartVersionVector: string;
|
|
2805
2799
|
plaintextHash: string;
|
|
2806
2800
|
writeHeader: Record<string, unknown>;
|
|
2801
|
+
authorizationTargets?: {
|
|
2802
|
+
containerId: string;
|
|
2803
|
+
containerKeyEpoch: number;
|
|
2804
|
+
containerKeyEpochId: string;
|
|
2805
|
+
containerManifestHash: string;
|
|
2806
|
+
}[] | undefined;
|
|
2807
2807
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
2808
2808
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
2809
2809
|
sourceVersionVector?: string | undefined;
|
|
@@ -2934,7 +2934,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
2934
2934
|
linkedContainerKeyEpochIds: string[];
|
|
2935
2935
|
linkedContainerManifestHashes: string[];
|
|
2936
2936
|
organizationId: string;
|
|
2937
|
-
targets
|
|
2937
|
+
targets?: Record<string, unknown>[] | undefined;
|
|
2938
2938
|
};
|
|
2939
2939
|
writeHeader: Record<string, unknown>;
|
|
2940
2940
|
}[] | null>;
|
|
@@ -637,7 +637,7 @@ export declare class ApiClientContext {
|
|
|
637
637
|
linkedContainerKeyEpochIds: string[];
|
|
638
638
|
linkedContainerManifestHashes: string[];
|
|
639
639
|
organizationId: string;
|
|
640
|
-
targets
|
|
640
|
+
targets?: Record<string, unknown>[] | undefined;
|
|
641
641
|
};
|
|
642
642
|
writeHeader: Record<string, unknown>;
|
|
643
643
|
}[] | null>>;
|
|
@@ -144,7 +144,7 @@ export declare class BlobArea {
|
|
|
144
144
|
linkedContainerKeyEpochIds: string[];
|
|
145
145
|
linkedContainerManifestHashes: string[];
|
|
146
146
|
organizationId: string;
|
|
147
|
-
targets
|
|
147
|
+
targets?: Record<string, unknown>[] | undefined;
|
|
148
148
|
};
|
|
149
149
|
writeHeader: Record<string, unknown>;
|
|
150
150
|
}[] | null>;
|
|
@@ -315,12 +315,6 @@ export declare class DocumentArea {
|
|
|
315
315
|
};
|
|
316
316
|
updates: {
|
|
317
317
|
accessEpoch: number;
|
|
318
|
-
authorizationTargets: {
|
|
319
|
-
containerId: string;
|
|
320
|
-
containerKeyEpoch: number;
|
|
321
|
-
containerKeyEpochId: string;
|
|
322
|
-
containerManifestHash: string;
|
|
323
|
-
}[];
|
|
324
318
|
authorFingerprint: string;
|
|
325
319
|
createdAt: string;
|
|
326
320
|
documentId: string;
|
|
@@ -330,6 +324,12 @@ export declare class DocumentArea {
|
|
|
330
324
|
partialStartVersionVector: string;
|
|
331
325
|
plaintextHash: string;
|
|
332
326
|
writeHeader: Record<string, unknown>;
|
|
327
|
+
authorizationTargets?: {
|
|
328
|
+
containerId: string;
|
|
329
|
+
containerKeyEpoch: number;
|
|
330
|
+
containerKeyEpochId: string;
|
|
331
|
+
containerManifestHash: string;
|
|
332
|
+
}[] | undefined;
|
|
333
333
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
334
334
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
335
335
|
sourceVersionVector?: string | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ContainerKekWireLevel } from "../validators/response/index.js";
|
|
2
|
+
import { type ServedAccessManifestBundleWireResponse } from "../validators/util/index.js";
|
|
2
3
|
/** Citation only saves bytes: a source slower than this sends the read uncited. */
|
|
3
4
|
export declare const MANIFEST_CITATION_DEADLINE_MS = 250;
|
|
4
5
|
/**
|
|
@@ -15,7 +16,7 @@ export interface WriterProjectionTarget {
|
|
|
15
16
|
readonly listing?: WriterProjectionListing | undefined;
|
|
16
17
|
}
|
|
17
18
|
/** A held access-manifest bundle or a held container KEK level. */
|
|
18
|
-
export type HeldProjectionCitation =
|
|
19
|
+
export type HeldProjectionCitation = ServedAccessManifestBundleWireResponse | ContainerKekWireLevel;
|
|
19
20
|
/**
|
|
20
21
|
* Verified access-manifest bundles and container KEK levels a device durably
|
|
21
22
|
* holds that a writer projection of `target` may cite, most useful first.
|
|
@@ -28,7 +29,7 @@ export interface VerifiedManifestCitations {
|
|
|
28
29
|
}
|
|
29
30
|
/** The exact bytes one request cites: bundles by hash, levels by digest. */
|
|
30
31
|
export interface HeldProjectionCitations {
|
|
31
|
-
readonly bundles: Map<string,
|
|
32
|
+
readonly bundles: Map<string, ServedAccessManifestBundleWireResponse>;
|
|
32
33
|
readonly kekLevels: Map<string, ContainerKekWireLevel>;
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { computeContainerKekLevelDigest } from "../crypto/index.js";
|
|
2
|
-
import {
|
|
3
|
-
import { isSha256HexString, KNOWN_MANIFEST_HINT_LIMIT, } from "../validators/util/index.js";
|
|
2
|
+
import { isContainerKekWireLevel, } from "../validators/response/index.js";
|
|
3
|
+
import { isServedAccessManifestBundleWireResponse, isSha256HexString, KNOWN_MANIFEST_HINT_LIMIT, } from "../validators/util/index.js";
|
|
4
4
|
/** Citation only saves bytes: a source slower than this sends the read uncited. */
|
|
5
5
|
export const MANIFEST_CITATION_DEADLINE_MS = 250;
|
|
6
6
|
function noCitations() {
|
|
@@ -48,7 +48,7 @@ async function prepareHeldCitations(entries) {
|
|
|
48
48
|
try {
|
|
49
49
|
if (isContainerKekWireLevel(entry))
|
|
50
50
|
levels.push(structuredClone(entry));
|
|
51
|
-
else if (
|
|
51
|
+
else if (isServedAccessManifestBundleWireResponse(entry) &&
|
|
52
52
|
isSha256HexString(entry.manifestHash) &&
|
|
53
53
|
!held.bundles.has(entry.manifestHash))
|
|
54
54
|
held.bundles.set(entry.manifestHash, structuredClone(entry));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifiedManifestCitations.js","sourceRoot":"","sources":["verifiedManifestCitations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,
|
|
1
|
+
{"version":3,"file":"verifiedManifestCitations.js","sourceRoot":"","sources":["verifiedManifestCitations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAEL,uBAAuB,GACxB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,wCAAwC,EACxC,iBAAiB,EACjB,yBAAyB,GAE1B,MAAM,4BAA4B,CAAC;AAEpC,mFAAmF;AACnF,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAyCjD,SAAS,WAAW;IAClB,OAAO,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;AAC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AC,KAAK,CAAC;gBAAE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;iBACnE,IACH,wCAAwC,CAAC,KAAK,CAAC;gBAC/C,iBAAiB,CAAC,KAAK,CAAC,YAAY,CAAC;gBACrC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC;gBAErC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;QACjE,CAAC;QAAC,MAAM,CAAC;YACP,4DAA4D;QAC9D,CAAC;IACH,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC,CAAC;IAC9E,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAC9B,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC;YACvC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,MAAwC,EACxC,MAA8B,EAC9B,MAAgC;IAEhC,IAAI,CAAC,MAAM;QAAE,OAAO,WAAW,EAAE,CAAC;IAClC,OAAO,eAAe,CACpB,KAAK,IAAI,EAAE,CAAC,oBAAoB,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAC3D,MAAM,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { computeContainerKekLevelDigest } from \"@tearleads/crypto\";\nimport {\n type ContainerKekWireLevel,\n isContainerKekWireLevel,\n} from \"@tearleads/validators/response\";\nimport {\n isServedAccessManifestBundleWireResponse,\n isSha256HexString,\n KNOWN_MANIFEST_HINT_LIMIT,\n type ServedAccessManifestBundleWireResponse,\n} from \"@tearleads/validators/util\";\n\n/** Citation only saves bytes: a source slower than this sends the read uncited. */\nexport const MANIFEST_CITATION_DEADLINE_MS = 250;\n\n/**\n * Where a listing placed a container the device has not stored yet. Only\n * which held bytes a read cites depends on it, never what the read accepts.\n */\nexport interface WriterProjectionListing {\n readonly organizationId: string;\n readonly parentId: string | null;\n}\n\nexport interface WriterProjectionTarget {\n readonly kind: \"container\" | \"document\";\n readonly id: string;\n readonly listing?: WriterProjectionListing | undefined;\n}\n\n/** A held access-manifest bundle or a held container KEK level. */\nexport type HeldProjectionCitation =\n | ServedAccessManifestBundleWireResponse\n | ContainerKekWireLevel;\n\n/**\n * Verified access-manifest bundles and container KEK levels a device durably\n * holds that a writer projection of `target` may cite, most useful first.\n * This is never trust input: the exact cited bytes only fill the response's\n * omitted positions, and the caller verifies the rebuilt projection exactly\n * as a full one.\n */\nexport interface VerifiedManifestCitations {\n cite(\n target: WriterProjectionTarget,\n ): Promise<readonly HeldProjectionCitation[]>;\n}\n\n/** The exact bytes one request cites: bundles by hash, levels by digest. */\nexport interface HeldProjectionCitations {\n readonly bundles: Map<string, ServedAccessManifestBundleWireResponse>;\n readonly kekLevels: Map<string, ContainerKekWireLevel>;\n}\n\nfunction noCitations(): HeldProjectionCitations {\n return { bundles: new Map(), kekLevels: new Map() };\n}\n\n/**\n * The prepared citations, or none once the deadline passes, the caller\n * aborts, or the source or preparation throws or rejects. A late answer is\n * discarded: it can never reach a request that was already sent.\n */\nfunction boundedCitation(\n prepare: () => Promise<HeldProjectionCitations>,\n signal: AbortSignal | undefined,\n): Promise<HeldProjectionCitations> {\n return new Promise((resolve) => {\n let settled = false;\n const finish = (held: HeldProjectionCitations) => {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n signal?.removeEventListener(\"abort\", abandon);\n resolve(held);\n };\n const abandon = () => finish(noCitations());\n const timer = setTimeout(abandon, MANIFEST_CITATION_DEADLINE_MS);\n if (signal?.aborted) return abandon();\n signal?.addEventListener(\"abort\", abandon, { once: true });\n try {\n prepare().then(finish, abandon);\n } catch {\n abandon();\n }\n });\n}\n\n/**\n * Copies the source's answer and keys each KEK level by the digest\n * recomputed from its own bytes, never by a digest the source names.\n */\nasync function prepareHeldCitations(\n entries: readonly unknown[],\n): Promise<HeldProjectionCitations> {\n const held = noCitations();\n const levels: ContainerKekWireLevel[] = [];\n for (const entry of entries) {\n if (held.bundles.size + levels.length >= KNOWN_MANIFEST_HINT_LIMIT) break;\n try {\n if (isContainerKekWireLevel(entry)) levels.push(structuredClone(entry));\n else if (\n isServedAccessManifestBundleWireResponse(entry) &&\n isSha256HexString(entry.manifestHash) &&\n !held.bundles.has(entry.manifestHash)\n )\n held.bundles.set(entry.manifestHash, structuredClone(entry));\n } catch {\n // An uncloneable entry is skipped; its bytes simply travel.\n }\n }\n const digests = await Promise.all(levels.map(computeContainerKekLevelDigest));\n levels.forEach((level, index) => {\n const digest = digests[index];\n if (digest && !held.kekLevels.has(digest))\n held.kekLevels.set(digest, level);\n });\n return held;\n}\n\n/**\n * The bytes one request cites, copied so a later eviction or mutation of the\n * source cannot change what fills its omissions. Citing only saves bytes, so\n * it never blocks or fails a read: a slow, failing, or abandoned source or\n * preparation yields no hints, within one deadline.\n */\nexport async function heldManifestCitations(\n source: VerifiedManifestCitations | null,\n target: WriterProjectionTarget,\n signal?: AbortSignal | undefined,\n): Promise<HeldProjectionCitations> {\n if (!source) return noCitations();\n return boundedCitation(\n async () => prepareHeldCitations(await source.cite(target)),\n signal,\n );\n}\n"]}
|
|
@@ -1401,7 +1401,7 @@ export declare const listDocumentAttachmentsOperation: Omit<{
|
|
|
1401
1401
|
linkedContainerKeyEpochIds: string[];
|
|
1402
1402
|
linkedContainerManifestHashes: string[];
|
|
1403
1403
|
organizationId: string;
|
|
1404
|
-
targets
|
|
1404
|
+
targets?: Record<string, unknown>[] | undefined;
|
|
1405
1405
|
};
|
|
1406
1406
|
writeHeader: Record<string, unknown>;
|
|
1407
1407
|
}[], {
|
|
@@ -1450,7 +1450,7 @@ export declare const listDocumentAttachmentsOperation: Omit<{
|
|
|
1450
1450
|
linkedContainerKeyEpochIds: string[];
|
|
1451
1451
|
linkedContainerManifestHashes: string[];
|
|
1452
1452
|
organizationId: string;
|
|
1453
|
-
targets
|
|
1453
|
+
targets?: Record<string, unknown>[] | undefined;
|
|
1454
1454
|
};
|
|
1455
1455
|
writeHeader: Record<string, unknown>;
|
|
1456
1456
|
}[]>;
|
|
@@ -464,12 +464,6 @@ export declare const documentSyncOperation: Omit<{
|
|
|
464
464
|
};
|
|
465
465
|
updates: {
|
|
466
466
|
accessEpoch: number;
|
|
467
|
-
authorizationTargets: {
|
|
468
|
-
containerId: string;
|
|
469
|
-
containerKeyEpoch: number;
|
|
470
|
-
containerKeyEpochId: string;
|
|
471
|
-
containerManifestHash: string;
|
|
472
|
-
}[];
|
|
473
467
|
authorFingerprint: string;
|
|
474
468
|
createdAt: string;
|
|
475
469
|
documentId: string;
|
|
@@ -479,6 +473,12 @@ export declare const documentSyncOperation: Omit<{
|
|
|
479
473
|
partialStartVersionVector: string;
|
|
480
474
|
plaintextHash: string;
|
|
481
475
|
writeHeader: Record<string, unknown>;
|
|
476
|
+
authorizationTargets?: {
|
|
477
|
+
containerId: string;
|
|
478
|
+
containerKeyEpoch: number;
|
|
479
|
+
containerKeyEpochId: string;
|
|
480
|
+
containerManifestHash: string;
|
|
481
|
+
}[] | undefined;
|
|
482
482
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
483
483
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
484
484
|
sourceVersionVector?: string | undefined;
|
|
@@ -508,12 +508,6 @@ export declare const documentSyncOperation: Omit<{
|
|
|
508
508
|
};
|
|
509
509
|
updates: {
|
|
510
510
|
accessEpoch: number;
|
|
511
|
-
authorizationTargets: {
|
|
512
|
-
containerId: string;
|
|
513
|
-
containerKeyEpoch: number;
|
|
514
|
-
containerKeyEpochId: string;
|
|
515
|
-
containerManifestHash: string;
|
|
516
|
-
}[];
|
|
517
511
|
authorFingerprint: string;
|
|
518
512
|
createdAt: string;
|
|
519
513
|
documentId: string;
|
|
@@ -523,6 +517,12 @@ export declare const documentSyncOperation: Omit<{
|
|
|
523
517
|
partialStartVersionVector: string;
|
|
524
518
|
plaintextHash: string;
|
|
525
519
|
writeHeader: Record<string, unknown>;
|
|
520
|
+
authorizationTargets?: {
|
|
521
|
+
containerId: string;
|
|
522
|
+
containerKeyEpoch: number;
|
|
523
|
+
containerKeyEpochId: string;
|
|
524
|
+
containerManifestHash: string;
|
|
525
|
+
}[] | undefined;
|
|
526
526
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
527
527
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
528
528
|
sourceVersionVector?: string | undefined;
|
|
@@ -552,12 +552,6 @@ export declare const documentSyncOperation: Omit<{
|
|
|
552
552
|
};
|
|
553
553
|
updates: {
|
|
554
554
|
accessEpoch: number;
|
|
555
|
-
authorizationTargets: {
|
|
556
|
-
containerId: string;
|
|
557
|
-
containerKeyEpoch: number;
|
|
558
|
-
containerKeyEpochId: string;
|
|
559
|
-
containerManifestHash: string;
|
|
560
|
-
}[];
|
|
561
555
|
authorFingerprint: string;
|
|
562
556
|
createdAt: string;
|
|
563
557
|
documentId: string;
|
|
@@ -567,6 +561,12 @@ export declare const documentSyncOperation: Omit<{
|
|
|
567
561
|
partialStartVersionVector: string;
|
|
568
562
|
plaintextHash: string;
|
|
569
563
|
writeHeader: Record<string, unknown>;
|
|
564
|
+
authorizationTargets?: {
|
|
565
|
+
containerId: string;
|
|
566
|
+
containerKeyEpoch: number;
|
|
567
|
+
containerKeyEpochId: string;
|
|
568
|
+
containerManifestHash: string;
|
|
569
|
+
}[] | undefined;
|
|
570
570
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
571
571
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
572
572
|
sourceVersionVector?: string | undefined;
|
|
@@ -596,12 +596,6 @@ export declare const documentSyncOperation: Omit<{
|
|
|
596
596
|
};
|
|
597
597
|
updates: {
|
|
598
598
|
accessEpoch: number;
|
|
599
|
-
authorizationTargets: {
|
|
600
|
-
containerId: string;
|
|
601
|
-
containerKeyEpoch: number;
|
|
602
|
-
containerKeyEpochId: string;
|
|
603
|
-
containerManifestHash: string;
|
|
604
|
-
}[];
|
|
605
599
|
authorFingerprint: string;
|
|
606
600
|
createdAt: string;
|
|
607
601
|
documentId: string;
|
|
@@ -611,6 +605,12 @@ export declare const documentSyncOperation: Omit<{
|
|
|
611
605
|
partialStartVersionVector: string;
|
|
612
606
|
plaintextHash: string;
|
|
613
607
|
writeHeader: Record<string, unknown>;
|
|
608
|
+
authorizationTargets?: {
|
|
609
|
+
containerId: string;
|
|
610
|
+
containerKeyEpoch: number;
|
|
611
|
+
containerKeyEpochId: string;
|
|
612
|
+
containerManifestHash: string;
|
|
613
|
+
}[] | undefined;
|
|
614
614
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
615
615
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
616
616
|
sourceVersionVector?: string | undefined;
|
|
@@ -161,7 +161,7 @@ export declare const getContainerWriterProjectionOperation: Omit<{
|
|
|
161
161
|
};
|
|
162
162
|
manifest: Record<string, unknown>;
|
|
163
163
|
manifestHash: string;
|
|
164
|
-
state:
|
|
164
|
+
state: import("../util/index.js").ServedManifestState;
|
|
165
165
|
}>;
|
|
166
166
|
omittedBundles: string[];
|
|
167
167
|
}, {
|
|
@@ -243,7 +243,7 @@ export declare const getContainerWriterProjectionOperation: Omit<{
|
|
|
243
243
|
};
|
|
244
244
|
manifest: Record<string, unknown>;
|
|
245
245
|
manifestHash: string;
|
|
246
|
-
state:
|
|
246
|
+
state: import("../util/index.js").ServedManifestState;
|
|
247
247
|
}>;
|
|
248
248
|
omittedBundles: string[];
|
|
249
249
|
}, z.core.$ZodTypeInternals<{
|
|
@@ -325,7 +325,7 @@ export declare const getContainerWriterProjectionOperation: Omit<{
|
|
|
325
325
|
};
|
|
326
326
|
manifest: Record<string, unknown>;
|
|
327
327
|
manifestHash: string;
|
|
328
|
-
state:
|
|
328
|
+
state: import("../util/index.js").ServedManifestState;
|
|
329
329
|
}>;
|
|
330
330
|
omittedBundles: string[];
|
|
331
331
|
}, {
|
|
@@ -407,7 +407,7 @@ export declare const getContainerWriterProjectionOperation: Omit<{
|
|
|
407
407
|
};
|
|
408
408
|
manifest: Record<string, unknown>;
|
|
409
409
|
manifestHash: string;
|
|
410
|
-
state:
|
|
410
|
+
state: import("../util/index.js").ServedManifestState;
|
|
411
411
|
}>;
|
|
412
412
|
omittedBundles: string[];
|
|
413
413
|
}>>;
|
|
@@ -568,7 +568,7 @@ export declare const getDocumentWriterProjectionOperation: Omit<{
|
|
|
568
568
|
};
|
|
569
569
|
manifest: Record<string, unknown>;
|
|
570
570
|
manifestHash: string;
|
|
571
|
-
state:
|
|
571
|
+
state: import("../util/index.js").ServedManifestState;
|
|
572
572
|
}>;
|
|
573
573
|
omittedBundles: string[];
|
|
574
574
|
policyEvidence: {
|
|
@@ -680,7 +680,7 @@ export declare const getDocumentWriterProjectionOperation: Omit<{
|
|
|
680
680
|
};
|
|
681
681
|
manifest: Record<string, unknown>;
|
|
682
682
|
manifestHash: string;
|
|
683
|
-
state:
|
|
683
|
+
state: import("../util/index.js").ServedManifestState;
|
|
684
684
|
}>;
|
|
685
685
|
omittedBundles: string[];
|
|
686
686
|
policyEvidence: {
|
|
@@ -792,7 +792,7 @@ export declare const getDocumentWriterProjectionOperation: Omit<{
|
|
|
792
792
|
};
|
|
793
793
|
manifest: Record<string, unknown>;
|
|
794
794
|
manifestHash: string;
|
|
795
|
-
state:
|
|
795
|
+
state: import("../util/index.js").ServedManifestState;
|
|
796
796
|
}>;
|
|
797
797
|
omittedBundles: string[];
|
|
798
798
|
policyEvidence: {
|
|
@@ -904,7 +904,7 @@ export declare const getDocumentWriterProjectionOperation: Omit<{
|
|
|
904
904
|
};
|
|
905
905
|
manifest: Record<string, unknown>;
|
|
906
906
|
manifestHash: string;
|
|
907
|
-
state:
|
|
907
|
+
state: import("../util/index.js").ServedManifestState;
|
|
908
908
|
}>;
|
|
909
909
|
omittedBundles: string[];
|
|
910
910
|
policyEvidence: {
|
|
@@ -387,7 +387,7 @@ export declare const BlobAttachmentSummarySchema: z.ZodType<{
|
|
|
387
387
|
linkedContainerKeyEpochIds: string[];
|
|
388
388
|
linkedContainerManifestHashes: string[];
|
|
389
389
|
organizationId: string;
|
|
390
|
-
targets
|
|
390
|
+
targets?: Record<string, unknown>[] | undefined;
|
|
391
391
|
};
|
|
392
392
|
writeHeader: Record<string, unknown>;
|
|
393
393
|
}, {
|
|
@@ -436,7 +436,7 @@ export declare const BlobAttachmentSummarySchema: z.ZodType<{
|
|
|
436
436
|
linkedContainerKeyEpochIds: string[];
|
|
437
437
|
linkedContainerManifestHashes: string[];
|
|
438
438
|
organizationId: string;
|
|
439
|
-
targets
|
|
439
|
+
targets?: Record<string, unknown>[] | undefined;
|
|
440
440
|
};
|
|
441
441
|
writeHeader: Record<string, unknown>;
|
|
442
442
|
}, z.core.$ZodTypeInternals<{
|
|
@@ -485,7 +485,7 @@ export declare const BlobAttachmentSummarySchema: z.ZodType<{
|
|
|
485
485
|
linkedContainerKeyEpochIds: string[];
|
|
486
486
|
linkedContainerManifestHashes: string[];
|
|
487
487
|
organizationId: string;
|
|
488
|
-
targets
|
|
488
|
+
targets?: Record<string, unknown>[] | undefined;
|
|
489
489
|
};
|
|
490
490
|
writeHeader: Record<string, unknown>;
|
|
491
491
|
}, {
|
|
@@ -534,7 +534,7 @@ export declare const BlobAttachmentSummarySchema: z.ZodType<{
|
|
|
534
534
|
linkedContainerKeyEpochIds: string[];
|
|
535
535
|
linkedContainerManifestHashes: string[];
|
|
536
536
|
organizationId: string;
|
|
537
|
-
targets
|
|
537
|
+
targets?: Record<string, unknown>[] | undefined;
|
|
538
538
|
};
|
|
539
539
|
writeHeader: Record<string, unknown>;
|
|
540
540
|
}>>;
|
|
@@ -585,7 +585,7 @@ export declare const ListDocumentAttachmentsResponseSchema: z.ZodCustom<{
|
|
|
585
585
|
linkedContainerKeyEpochIds: string[];
|
|
586
586
|
linkedContainerManifestHashes: string[];
|
|
587
587
|
organizationId: string;
|
|
588
|
-
targets
|
|
588
|
+
targets?: Record<string, unknown>[] | undefined;
|
|
589
589
|
};
|
|
590
590
|
writeHeader: Record<string, unknown>;
|
|
591
591
|
}[], {
|
|
@@ -634,7 +634,7 @@ export declare const ListDocumentAttachmentsResponseSchema: z.ZodCustom<{
|
|
|
634
634
|
linkedContainerKeyEpochIds: string[];
|
|
635
635
|
linkedContainerManifestHashes: string[];
|
|
636
636
|
organizationId: string;
|
|
637
|
-
targets
|
|
637
|
+
targets?: Record<string, unknown>[] | undefined;
|
|
638
638
|
};
|
|
639
639
|
writeHeader: Record<string, unknown>;
|
|
640
640
|
}[]>;
|
|
@@ -50,7 +50,7 @@ export const BlobContentKeyBundleResponseSchema = loosePlainObject({
|
|
|
50
50
|
targetHash: z.string(),
|
|
51
51
|
targets: arraySchema(BlobContentKeyTargetEnvelopeResponseSchema),
|
|
52
52
|
});
|
|
53
|
-
|
|
53
|
+
const blobKekTargetsShape = {
|
|
54
54
|
activeBindingIds: arraySchema(z.string()),
|
|
55
55
|
blobAccessManifestHash: z.string(),
|
|
56
56
|
blobId: z.string(),
|
|
@@ -60,6 +60,16 @@ export const BlobKekTargetsResponseSchema = loosePlainObject({
|
|
|
60
60
|
linkedContainerManifestHashes: arraySchema(z.string()),
|
|
61
61
|
organizationId: z.string(),
|
|
62
62
|
targets: arraySchema(plainObjectSchema),
|
|
63
|
+
};
|
|
64
|
+
export const BlobKekTargetsResponseSchema = loosePlainObject(blobKekTargetsShape);
|
|
65
|
+
/**
|
|
66
|
+
* The target set a blob's write was authorized against. `targets` is omitted
|
|
67
|
+
* when `blobKeyTargetHash` equals the listing's current `blobKekTargets`
|
|
68
|
+
* hash: the reader refills it from that set and re-hashes it.
|
|
69
|
+
*/
|
|
70
|
+
const BlobWriteAuthorizationResponseSchema = loosePlainObject({
|
|
71
|
+
...blobKekTargetsShape,
|
|
72
|
+
targets: arraySchema(plainObjectSchema).optional(),
|
|
63
73
|
});
|
|
64
74
|
export const BlobAttachmentSummarySchema = loosePlainObject({
|
|
65
75
|
bindingEvent: AccessEventBundleWireResponseSchema,
|
|
@@ -70,7 +80,7 @@ export const BlobAttachmentSummarySchema = loosePlainObject({
|
|
|
70
80
|
documentManifestHash: z.string(),
|
|
71
81
|
previousBindingId: z.string().nullable(),
|
|
72
82
|
slotId: z.string(),
|
|
73
|
-
writeAuthorization:
|
|
83
|
+
writeAuthorization: BlobWriteAuthorizationResponseSchema,
|
|
74
84
|
writeHeader: plainObjectSchema,
|
|
75
85
|
});
|
|
76
86
|
export const ListDocumentAttachmentsResponseSchema = arraySchema(BlobAttachmentSummarySchema);
|