@vielzeug/archive 0.0.0-stage → 26.10.7

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 (118) hide show
  1. package/README.md +81 -2
  2. package/dist/_crypto.cjs +2 -0
  3. package/dist/_crypto.cjs.map +1 -0
  4. package/dist/_crypto.d.ts +7 -0
  5. package/dist/_crypto.d.ts.map +1 -0
  6. package/dist/_crypto.js +2 -0
  7. package/dist/_crypto.js.map +1 -0
  8. package/dist/_json.cjs +2 -0
  9. package/dist/_json.cjs.map +1 -0
  10. package/dist/_json.d.ts +4 -0
  11. package/dist/_json.d.ts.map +1 -0
  12. package/dist/_json.js +2 -0
  13. package/dist/_json.js.map +1 -0
  14. package/dist/auth/config.cjs +2 -0
  15. package/dist/auth/config.cjs.map +1 -0
  16. package/dist/auth/config.d.ts +88 -0
  17. package/dist/auth/config.d.ts.map +1 -0
  18. package/dist/auth/config.js +2 -0
  19. package/dist/auth/config.js.map +1 -0
  20. package/dist/auth/errors.cjs +2 -0
  21. package/dist/auth/errors.cjs.map +1 -0
  22. package/dist/auth/errors.d.ts +10 -0
  23. package/dist/auth/errors.d.ts.map +1 -0
  24. package/dist/auth/errors.js +2 -0
  25. package/dist/auth/errors.js.map +1 -0
  26. package/dist/auth/store.cjs +19 -0
  27. package/dist/auth/store.cjs.map +1 -0
  28. package/dist/auth/store.d.ts +45 -0
  29. package/dist/auth/store.d.ts.map +1 -0
  30. package/dist/auth/store.js +19 -0
  31. package/dist/auth/store.js.map +1 -0
  32. package/dist/auth/worker.cjs +16 -0
  33. package/dist/auth/worker.cjs.map +1 -0
  34. package/dist/auth/worker.d.ts +47 -0
  35. package/dist/auth/worker.d.ts.map +1 -0
  36. package/dist/auth/worker.js +16 -0
  37. package/dist/auth/worker.js.map +1 -0
  38. package/dist/auth.cjs +1 -0
  39. package/dist/auth.d.ts +5 -0
  40. package/dist/auth.d.ts.map +1 -0
  41. package/dist/auth.js +1 -0
  42. package/dist/collection.cjs +2 -0
  43. package/dist/collection.cjs.map +1 -0
  44. package/dist/collection.d.ts +139 -0
  45. package/dist/collection.d.ts.map +1 -0
  46. package/dist/collection.js +2 -0
  47. package/dist/collection.js.map +1 -0
  48. package/dist/contract.cjs +2 -0
  49. package/dist/contract.cjs.map +1 -0
  50. package/dist/contract.d.ts +228 -0
  51. package/dist/contract.d.ts.map +1 -0
  52. package/dist/contract.js +2 -0
  53. package/dist/contract.js.map +1 -0
  54. package/dist/errors.cjs +2 -0
  55. package/dist/errors.cjs.map +1 -0
  56. package/dist/errors.d.ts +12 -0
  57. package/dist/errors.d.ts.map +1 -0
  58. package/dist/errors.js +2 -0
  59. package/dist/errors.js.map +1 -0
  60. package/dist/index.cjs +1 -0
  61. package/dist/index.d.ts +4 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +1 -0
  64. package/dist/worker/_pagination.cjs +2 -0
  65. package/dist/worker/_pagination.cjs.map +1 -0
  66. package/dist/worker/_pagination.d.ts +31 -0
  67. package/dist/worker/_pagination.d.ts.map +1 -0
  68. package/dist/worker/_pagination.js +2 -0
  69. package/dist/worker/_pagination.js.map +1 -0
  70. package/dist/worker/_service.cjs +2 -0
  71. package/dist/worker/_service.cjs.map +1 -0
  72. package/dist/worker/_service.d.ts +5 -0
  73. package/dist/worker/_service.d.ts.map +1 -0
  74. package/dist/worker/_service.js +2 -0
  75. package/dist/worker/_service.js.map +1 -0
  76. package/dist/worker/auth.cjs +2 -0
  77. package/dist/worker/auth.cjs.map +1 -0
  78. package/dist/worker/auth.d.ts +34 -0
  79. package/dist/worker/auth.d.ts.map +1 -0
  80. package/dist/worker/auth.js +2 -0
  81. package/dist/worker/auth.js.map +1 -0
  82. package/dist/worker/env.cjs +2 -0
  83. package/dist/worker/env.cjs.map +1 -0
  84. package/dist/worker/env.d.ts +73 -0
  85. package/dist/worker/env.d.ts.map +1 -0
  86. package/dist/worker/env.js +2 -0
  87. package/dist/worker/env.js.map +1 -0
  88. package/dist/worker/http.cjs +2 -0
  89. package/dist/worker/http.cjs.map +1 -0
  90. package/dist/worker/http.d.ts +66 -0
  91. package/dist/worker/http.d.ts.map +1 -0
  92. package/dist/worker/http.js +2 -0
  93. package/dist/worker/http.js.map +1 -0
  94. package/dist/worker/publications.cjs +2 -0
  95. package/dist/worker/publications.cjs.map +1 -0
  96. package/dist/worker/publications.d.ts +60 -0
  97. package/dist/worker/publications.d.ts.map +1 -0
  98. package/dist/worker/publications.js +2 -0
  99. package/dist/worker/publications.js.map +1 -0
  100. package/dist/worker/sql.cjs +60 -0
  101. package/dist/worker/sql.cjs.map +1 -0
  102. package/dist/worker/sql.d.ts +87 -0
  103. package/dist/worker/sql.d.ts.map +1 -0
  104. package/dist/worker/sql.js +60 -0
  105. package/dist/worker/sql.js.map +1 -0
  106. package/dist/worker/worker.cjs +2 -0
  107. package/dist/worker/worker.cjs.map +1 -0
  108. package/dist/worker/worker.d.ts +72 -0
  109. package/dist/worker/worker.d.ts.map +1 -0
  110. package/dist/worker/worker.js +2 -0
  111. package/dist/worker/worker.js.map +1 -0
  112. package/dist/worker.cjs +1 -0
  113. package/dist/worker.d.ts +4 -0
  114. package/dist/worker.d.ts.map +1 -0
  115. package/dist/worker.js +1 -0
  116. package/migrations/0001_community_archive.sql +173 -0
  117. package/migrations/auth/0001_auth.sql +65 -0
  118. package/package.json +72 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.js","names":[],"sources":["../src/collection.ts"],"sourcesContent":["import { type Schema, s } from '@vielzeug/spell';\nimport { sha256Hex } from './_crypto';\nimport { canonicalObjectJson } from './_json';\nimport {\n ARCHIVE_COLLECTION_NAME_PATTERN,\n ARCHIVE_CONTRACT_VERSION,\n ARCHIVE_LIMITS,\n type ArchivePage,\n archiveAuthorSchema,\n hex64Schema,\n isoTimestampSchema,\n isWellFormedText,\n uuidSchema,\n} from './contract';\nimport { ArchiveDefinitionError, ArchiveDerivationError, type ArchiveDerivationStage } from './errors';\n\n/**\n * Stored payloads are canonical by construction: `derive` validates, normalizes and\n * byte-pins every payload before it is stored, and the package's schema policy is\n * to reset/reseed databases when canonicalization semantics change. The emitted\n * entry schemas therefore embed the plain payload schema — re-parsing a stored\n * payload re-runs its (write-time-stable, hence idempotent) schema, never a\n * parallel re-canonicalization.\n */\n\n/**\n * The one seam between a deployment's content and the archive core. A collection\n * declares its payload schema and derives its list dimensions; the core owns\n * everything else — parsing, canonical serialization, the content hash, the emitted\n * envelope schemas, and every storage bound. Collections never hash, never size,\n * and never hand-write the envelope.\n */\n\n/** What `index` derives from one validated payload: the list dimensions plus the FTS title. */\nexport interface ArchiveIndexing<F extends string = string, T extends string = string> {\n /** One scalar-filter value from the declared vocabulary, or null for \"no filter\". */\n filter: F | null;\n /** Tag values from the declared vocabulary; duplicates collapse in first-seen order. */\n tags: readonly T[];\n /** The searchable title; the core trims and bounds it. */\n title: string;\n}\n\n/** The definition a deployment writes; `defineArchiveCollection` derives the rest. */\nexport interface ArchiveCollectionDefinition<\n P extends object,\n C extends number,\n F extends string = never,\n T extends string = never,\n> {\n /**\n * Normalizes a parsed payload to its storage form — fixed key order, sorted\n * order-insensitive lists — so equivalent content hashes identically. Omit when\n * the payload is already canonical; a result that leaves the payload schema is\n * a derivation fault at derive time, never stored. Must be idempotent.\n */\n canonicalize?(payload: P): P;\n /** The collection's payload-format version; stored and re-emitted with every entry. */\n contentVersion: C;\n /** Valid scalar-filter values; a query param outside the vocabulary is 400. */\n filters?: readonly F[];\n /** Derives the list dimensions and the searchable title from the canonical payload. */\n index(payload: P): ArchiveIndexing<NoInfer<F>, NoInfer<T>>;\n /** The URL + storage dimension this collection owns: lowercase `[a-z0-9-]`, at most 32 chars. */\n name: string;\n /** The strict payload schema: the whole content contract, parsed before anything derives. */\n payloadSchema: Schema<P, unknown>;\n /** Valid tag values. */\n tags?: readonly T[];\n}\n\n/** Everything the archive stores and re-identifies by, derived once per publish and update. */\nexport interface ArchiveDerivation {\n /** The stored bytes: the canonical payload, serialized with fixed key order. */\n canonicalJson: string;\n /** SHA-256 hex over `{contentVersion, payload}`: identical content hashes identically. */\n contentHash: string;\n /** The collection's declared payload-format version. */\n contentVersion: number;\n filter: string | null;\n tags: readonly string[];\n title: string;\n}\n\n/** The envelope fields every emitted entry carries; the payload stays the collection's. */\nexport interface ArchiveEntry<P = unknown, C extends number = number> {\n author: { id: string; name: string };\n contentHash: string;\n /** The collection's payload-format version, literal-pinned by the definition. */\n contentVersion: C;\n id: string;\n likeCount: number;\n payload: P;\n publishedAt: string;\n revision: number;\n /** The archive wire-contract version, pinned by the core. */\n schemaVersion: typeof ARCHIVE_CONTRACT_VERSION;\n updatedAt: string;\n}\n\n/** The private owner view: the emitted entry plus the create retry key and moderation state. */\nexport interface ArchiveOwnedEntry<P = unknown, C extends number = number> extends ArchiveEntry<P, C> {\n /** The create retry key; public routes never emit it. */\n clientKey: string;\n /** True while an operator has removed the entry from public view (still owned, frozen for edits). */\n hidden: boolean;\n}\n\n/**\n * The wire schemas one collection shares with its client: every request and response\n * envelope for this collection's routes, composed from the payload schema, so the\n * client and the Worker parse the same bytes with the same rules.\n */\nexport interface ArchiveContract<P = unknown, C extends number = number> {\n /** The public entry emitted by list, detail and publish/update responses. */\n entry: Schema<ArchiveEntry<P, C>>;\n /** The own-publications response: `{ entries: ArchiveOwnedEntry[] }`. */\n ownedEntries: Schema<{ entries: ArchiveOwnedEntry<P, C>[] }>;\n /** The private owner entry — the public entry plus the create retry key. */\n ownedEntry: Schema<ArchiveOwnedEntry<P, C>>;\n /** One list page: entries plus the forward/backward cursors around it. */\n page: Schema<ArchivePage<ArchiveEntry<P, C>>>;\n /** The publish request: `{ clientKey, payload }`. */\n publishInput: Schema<{ clientKey: string; payload: P }, unknown>;\n /** The update request: `{ expectedRevision, payload }`. */\n updateInput: Schema<{ expectedRevision: number; payload: P }, unknown>;\n}\n\n/** One registered collection: the derived runtime seam the Worker consumes. */\nexport interface ArchiveCollection<P extends object = object, C extends number = number> {\n readonly contentVersion: C;\n /** The collection's wire schemas, shared with its client. */\n readonly contract: ArchiveContract<P, C>;\n /**\n * Validates an untrusted payload and derives everything the archive stores.\n * Null rejects invalid content: JSON/schema failures, title/tag bounds or the\n * canonical payload byte ceiling. Routes answer 422 `invalid-payload` for null.\n * Callback failures and deployment invariant violations throw ArchiveDerivationError.\n */\n readonly derive: (raw: unknown) => Promise<ArchiveDerivation | null>;\n readonly filters: readonly string[];\n readonly name: string;\n readonly tags: readonly string[];\n}\n\n/** The envelope shape shared by the public and owned compositions. */\nconst envelopeShape = <P, C extends number>(payload: Schema<P>, contentVersion: C) =>\n ({\n author: archiveAuthorSchema,\n contentHash: hex64Schema,\n contentVersion: s.literal(contentVersion),\n id: uuidSchema,\n likeCount: s.number().int().min(0).max(Number.MAX_SAFE_INTEGER),\n payload,\n publishedAt: isoTimestampSchema,\n revision: s.number().int().min(1).max(Number.MAX_SAFE_INTEGER),\n schemaVersion: s.literal(ARCHIVE_CONTRACT_VERSION),\n updatedAt: isoTimestampSchema,\n }) as const;\n\n/**\n * Builds one collection from its definition. Malformed definitions fail here, at\n * registration time — never mid-request: the name must be a routable `[a-z0-9-]`\n * segment, the content version a positive integer, and every declared filter and\n * tag value well-formed text of `1..vocabChars` chars — the bound cursors and the\n * meta route both rely on it. The core derives everything else per payload:\n * parsing, canonical serialization, hashing over the collection's versioned\n * envelope, the emitted-entry schemas, and every storage bound.\n */\nexport function defineArchiveCollection<\n P extends object,\n const C extends number,\n const F extends string = never,\n const T extends string = never,\n>(definition: ArchiveCollectionDefinition<P, C, F, T>): ArchiveCollection<P, C> {\n const { canonicalize, contentVersion, index, name, payloadSchema } = definition;\n if (\n typeof index !== 'function' ||\n !payloadSchema ||\n typeof payloadSchema.safeParse !== 'function' ||\n (canonicalize !== undefined && typeof canonicalize !== 'function')\n ) {\n throw new ArchiveDefinitionError(\n 'Collection requires a payload schema and synchronous indexing/canonicalization functions.',\n );\n }\n if (\n (definition.filters !== undefined && !Array.isArray(definition.filters)) ||\n (definition.tags !== undefined && !Array.isArray(definition.tags))\n ) {\n throw new ArchiveDefinitionError('Collection vocabularies must be arrays.');\n }\n const filters = Object.freeze([...(definition.filters ?? [])]);\n const tags = Object.freeze([...(definition.tags ?? [])]);\n if (typeof name !== 'string' || !ARCHIVE_COLLECTION_NAME_PATTERN.test(name)) {\n throw new ArchiveDefinitionError(`Archive collection name must match [a-z0-9-]{1,32}: ${JSON.stringify(name)}`);\n }\n if (!Number.isSafeInteger(contentVersion) || contentVersion < 1) {\n throw new ArchiveDefinitionError(`Archive collection ${name}: contentVersion must be a safe integer >= 1.`);\n }\n const validateVocabulary = (kind: 'filters' | 'tags', values: readonly string[]): void => {\n for (const value of values) {\n if (\n typeof value !== 'string' ||\n value.length === 0 ||\n value.length > ARCHIVE_LIMITS.vocabChars ||\n !isWellFormedText(value)\n ) {\n throw new ArchiveDefinitionError(\n `Archive collection ${name}: every ${kind} value must be well-formed text of 1..${ARCHIVE_LIMITS.vocabChars} chars.`,\n );\n }\n }\n };\n validateVocabulary('filters', filters);\n validateVocabulary('tags', tags);\n const filterValues = new Set<string>(filters);\n const tagValues = new Set<string>(tags);\n\n const derive = async (raw: unknown): Promise<ArchiveDerivation | null> => {\n let stage: ArchiveDerivationStage = 'schema';\n try {\n if (canonicalObjectJson(raw) === null) return null;\n const parsed = payloadSchema.safeParse(raw);\n if (!parsed.success) return null;\n const parsedJson = canonicalObjectJson(parsed.data, true, raw);\n if (parsedJson === null)\n throw new ArchiveDerivationError(stage, 'Payload schema produced invalid or lossy JSON.');\n stage = 'canonicalize';\n const canonical = canonicalize === undefined ? parsed.data : canonicalize(parsed.data);\n // A canonicalize step that leaves the payload schema is a collection bug, not data to store.\n const normalizedJson = canonicalObjectJson(canonical, true, JSON.parse(parsedJson));\n if (normalizedJson === null) throw new ArchiveDerivationError(stage, 'Canonicalization produced invalid JSON.');\n stage = 'schema';\n const revalidated = payloadSchema.safeParse(JSON.parse(normalizedJson));\n if (!revalidated.success)\n throw new ArchiveDerivationError(\n canonicalize === undefined ? 'schema' : 'canonicalize',\n 'Canonical payload is outside the payload schema.',\n { cause: revalidated.error },\n );\n const canonicalJson = canonicalObjectJson(revalidated.data, true, JSON.parse(normalizedJson));\n if (canonicalJson === null || canonicalJson !== normalizedJson)\n throw new ArchiveDerivationError(stage, 'Payload schema is not stable on canonical JSON.');\n if (canonicalize !== undefined) {\n const repeatedPayload = payloadSchema.parse(JSON.parse(canonicalJson));\n stage = 'canonicalize';\n const repeated = canonicalize(repeatedPayload);\n if (canonicalObjectJson(repeated, true) !== canonicalJson)\n throw new ArchiveDerivationError(stage, 'Canonicalization is not idempotent.');\n }\n\n stage = 'index';\n const { filter, tags: rawTags, title: rawTitle } = index(revalidated.data);\n // Indexing may read the final parsed value, but must not change the stored content.\n if (canonicalObjectJson(revalidated.data, true) !== canonicalJson)\n throw new ArchiveDerivationError(stage, 'Indexing mutated the canonical payload.');\n if (typeof rawTitle !== 'string' || !Array.isArray(rawTags))\n throw new ArchiveDerivationError(stage, 'Indexing must return a string title and a tags array.');\n const title = rawTitle.trim();\n if (title.length === 0 || title.length > ARCHIVE_LIMITS.titleChars || !isWellFormedText(title)) return null;\n if (filter !== null && (typeof filter !== 'string' || !isWellFormedText(filter)))\n throw new ArchiveDerivationError(stage, 'Indexing returned an invalid filter.');\n const uniqueTags: string[] = [];\n for (const tag of rawTags) {\n if (typeof tag !== 'string' || !isWellFormedText(tag))\n throw new ArchiveDerivationError(stage, 'Indexing returned an invalid tag.');\n if (!uniqueTags.includes(tag)) uniqueTags.push(tag);\n }\n // A derivation outside the declared vocabulary would store a row no list query\n // can reach — the query route 400s the very value the collection derived.\n if ((filter !== null && !filterValues.has(filter)) || uniqueTags.some((tag) => !tagValues.has(tag)))\n throw new ArchiveDerivationError(stage, 'Indexing returned a value outside the declared vocabularies.');\n if (uniqueTags.length > ARCHIVE_LIMITS.tagsPerEntry) return null;\n\n if (new TextEncoder().encode(canonicalJson).byteLength > ARCHIVE_LIMITS.payloadBytes) return null;\n stage = 'hash';\n const contentHash = await sha256Hex(`{\"contentVersion\":${contentVersion},\"payload\":${canonicalJson}}`);\n return { canonicalJson, contentHash, contentVersion, filter, tags: uniqueTags, title };\n } catch (cause) {\n if (cause instanceof ArchiveDerivationError) throw cause;\n throw new ArchiveDerivationError(stage, 'Collection content derivation failed.', { cause });\n }\n };\n\n // The cast pins the envelope's payload member to the collection's output type:\n // `payloadSchema` is `Schema<P, unknown>` (input unknown), and inference through\n // the generic shape helper would widen the member to `unknown`.\n const entrySchema: Schema<ArchiveEntry<P, C>> = s.object(envelopeShape(payloadSchema as Schema<P>, contentVersion));\n const ownedEntrySchema: Schema<ArchiveOwnedEntry<P, C>> = s.object({\n ...envelopeShape(payloadSchema as Schema<P>, contentVersion),\n clientKey: uuidSchema,\n hidden: s.boolean(),\n });\n const contract: ArchiveContract<P, C> = {\n entry: entrySchema,\n ownedEntries: s.object({ entries: s.array(ownedEntrySchema) }),\n ownedEntry: ownedEntrySchema,\n page: s.object({\n cursor: s.string().nullable(),\n entries: s.array(entrySchema),\n }),\n publishInput: s.object({ clientKey: uuidSchema, payload: payloadSchema }),\n updateInput: s.object({\n expectedRevision: s.number().int().min(1).max(Number.MAX_SAFE_INTEGER),\n payload: payloadSchema,\n }),\n };\n\n return Object.freeze({ contentVersion, contract: Object.freeze(contract), derive, filters, name, tags });\n}\n"],"mappings":"2YAkJA,IAAM,eAAsC,EAAoB,KAC7D,CACC,OAAQ,EACR,YAAa,EACb,eAAgB,EAAE,QAAQ,CAAc,EACxC,GAAI,EACJ,UAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAA2B,EAC9D,UACA,YAAa,EACb,SAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAA2B,EAC7D,cAAe,EAAE,QAAA,CAAgC,EACjD,UAAW,CACb,GAWF,SAAgB,wBAKd,EAA8E,CAC9E,GAAM,CAAE,eAAc,iBAA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C,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAA2B,EACrE,QAAS,CACX,CAAC,CACH,EAEA,OAAO,OAAO,OAAO,CAAE,iBAAgB,SAAU,OAAO,OAAO,CAAQ,EAAG,OAAQ,UAAS,OAAM,MAAK,CAAC,CACzG"}
@@ -0,0 +1,2 @@
1
+ let e=require("@vielzeug/spell");var t=`archive_session`,n=`/api/v1`,r=2592e3,i=900,sessionCookieValue=(e,r)=>`${t}=${e}; HttpOnly; SameSite=Strict; Path=${n}; Max-Age=${r.maxAgeSeconds}${r.secure?`; Secure`:``}`,a=`x-archive-publisher`,o=`X-Archive-Account`,s=`x-archive-request`,c=1,l=1,u=1,d=`archive-operator`,f=/^[a-z0-9-]{1,32}$/,p=e.s.string().uuid(),m=e.s.string().isoDateTime(),h=e.s.string().regex(/^[0-9a-f]{64}$/),g=/[\p{Cs}\p{Cc}]/u,isWellFormedText=e=>!g.test(e),textString=()=>e.s.string().check(isWellFormedText),_=textString().trim().max(24),v=e.s.object({id:p,name:_}),y=e.s.object({id:p,name:_,operator:e.s.boolean()}).nullable(),b=e.s.object({createdAt:m,email:e.s.string().email(),id:p,lastSignInAt:m.nullable()}),x=e.s.object({ids:e.s.array(p)}),S=e.s.object({cursor:e.s.string().nullable(),ids:e.s.array(p)}),C=e.s.object({id:p,likeCount:e.s.number().int().min(0).max(2**53-1),liked:e.s.boolean()}),w=Object.freeze({aliasChars:24,cursorChars:1024,idempotencyRetentionMs:1728e5,likeStateIds:50,maxPageSize:50,maxPublications:50,pageSize:10,payloadBytes:8192,publicCacheSeconds:30,reportReasonChars:256,requestBytes:12288,searchChars:64,searchTerms:6,tagsPerEntry:16,titleChars:128,vocabChars:64}),T=e.s.object({aliasChars:e.s.number().int().min(1),cursorChars:e.s.number().int().min(1),idempotencyRetentionMs:e.s.number().int().min(1),likeStateIds:e.s.number().int().min(1),maxPageSize:e.s.number().int().min(1),maxPublications:e.s.number().int().min(1),pageSize:e.s.number().int().min(1),payloadBytes:e.s.number().int().min(1),publicCacheSeconds:e.s.number().int().min(0),reportReasonChars:e.s.number().int().min(1),requestBytes:e.s.number().int().min(1),searchChars:e.s.number().int().min(1),searchTerms:e.s.number().int().min(1),tagsPerEntry:e.s.number().int().min(1),titleChars:e.s.number().int().min(1),vocabChars:e.s.number().int().min(1)}),E=e.s.object({dbSchemaVersion:e.s.number().int().min(0).nullable(),features:e.s.object({likes:e.s.boolean(),publishing:e.s.boolean()}),limits:T,reason:e.s.enum([`database-unavailable`,`schema-mismatch`]).nullable(),schemaVersion:e.s.literal(1),status:e.s.enum([`ok`,`degraded`])}),D=e.s.object({dbSchemaVersion:e.s.number().int().min(0).nullable(),reason:e.s.enum([`configuration-unavailable`,`database-unavailable`,`schema-mismatch`]).nullable(),schemaVersion:e.s.literal(1),status:e.s.enum([`ok`,`degraded`])}),O=[`account-changed`,`auth-unavailable`,`bad-request`,`conflict`,`forbidden`,`gone`,`internal`,`invalid-payload`,`likes-disabled`,`method-not-allowed`,`not-found`,`publisher-changed`,`publishing-disabled`,`quota`,`rate-limited`,`record-unavailable`,`timeout`,`too-large`,`unauthenticated`,`unavailable`,`unsupported-media`],k=e.s.object({error:e.s.object({code:e.s.enum(O),message:e.s.string().min(1).max(256),requestId:p}).strict()}).strict(),A=e.s.object({ok:e.s.literal(!0)}).strict(),j=e.s.object({filters:e.s.array(e.s.string().min(1).max(w.vocabChars)),name:e.s.string().regex(f),tags:e.s.array(e.s.string().min(1).max(w.vocabChars))}),M=e.s.object({cursor:e.s.string().nullable(),reports:e.s.array(e.s.object({createdAt:m,entryId:p,entryTitle:e.s.string().min(1).max(w.titleChars),id:p,reason:e.s.string().min(1).max(w.reportReasonChars),reporter:v,resolvedAt:m.nullable()}))}),N=e.s.object({cursor:e.s.string().nullable(),reports:e.s.array(e.s.object({collection:e.s.string().regex(f),createdAt:m,entryId:p,id:p,reason:e.s.string().min(1).max(w.reportReasonChars),resolvedAt:m.nullable()}))}),P=[`hide`,`unhide`,`remove`,`erase-publisher`],F=e.s.object({actions:e.s.array(e.s.object({action:e.s.enum(P),collection:e.s.string().regex(f).nullable(),createdAt:m,id:p,operatorId:p,targetId:p})),cursor:e.s.string().nullable()}),I=e.s.enum([`liked`,`recent`]);exports.ACCOUNT_HEADER=o,exports.ARCHIVE_COLLECTION_NAME_PATTERN=f,exports.ARCHIVE_CONTRACT_VERSION=c,exports.ARCHIVE_ERROR_CODES=O,exports.ARCHIVE_LIMITS=w,exports.ARCHIVE_MODERATION_ACTIONS=P,exports.ARCHIVE_OPERATOR_ROLE=d,exports.ARCHIVE_SCHEMA_VERSION=l,exports.AUTH_SCHEMA_VERSION=u,exports.ILL_FORMED_TEXT=g,exports.OPERATOR_SESSION_MAX_AGE_SECONDS=i,exports.PUBLISHER_HEADER=a,exports.REQUEST_MARKER_HEADER=s,exports.SESSION_COOKIE_NAME=t,exports.SESSION_COOKIE_PATH=n,exports.SESSION_MAX_AGE_SECONDS=r,exports.archiveAccountSchema=b,exports.archiveAliasSchema=_,exports.archiveAuthHealthSchema=D,exports.archiveAuthorSchema=v,exports.archiveCollectionMetaSchema=j,exports.archiveErrorResponseSchema=k,exports.archiveHealthSchema=E,exports.archiveIdentitySchema=y,exports.archiveLikeStateSchema=C,exports.archiveLikedIdsSchema=x,exports.archiveLikesPageSchema=S,exports.archiveLimitsSchema=T,exports.archiveModerationLogSchema=F,exports.archiveOkSchema=A,exports.archiveOwnReportsSchema=N,exports.archiveReportsSchema=M,exports.archiveSortSchema=I,exports.hex64Schema=h,exports.isWellFormedText=isWellFormedText,exports.isoTimestampSchema=m,exports.sessionCookieValue=sessionCookieValue,exports.uuidSchema=p;
2
+ //# sourceMappingURL=contract.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.cjs","names":[],"sources":["../src/contract.ts"],"sourcesContent":["import { type InferOutput, type Schema, s } from '@vielzeug/spell';\n\n/** Shared naming: one place so the client, Worker and issuer cannot drift. */\nexport const SESSION_COOKIE_NAME = 'archive_session';\nexport const SESSION_COOKIE_PATH = '/api/v1';\n/**\n * The maximum age a session JWT may carry, and the cookie Max-Age an issuer sets:\n * a long-lived signed-in state. The Worker rejects older tokens at this bound.\n */\nexport const SESSION_MAX_AGE_SECONDS = 30 * 24 * 60 * 60;\nexport const OPERATOR_SESSION_MAX_AGE_SECONDS = 15 * 60;\n\n/**\n * The full Set-Cookie value for the session cookie: name, token and the security\n * attributes every issuer and the Worker must agree on — HttpOnly, SameSite=Strict,\n * the contract Path, Max-Age, and Secure in production. Issuers mint with the\n * session's max age; the Worker and issuers clear with `maxAgeSeconds: 0`. Never\n * hand-compose the attributes: the cookie's CSRF and theft posture is contract,\n * not per-issuer choice.\n */\nexport const sessionCookieValue = (token: string, options: { maxAgeSeconds: number; secure: boolean }): string =>\n `${SESSION_COOKIE_NAME}=${token}; HttpOnly; SameSite=Strict; Path=${SESSION_COOKIE_PATH}; Max-Age=${options.maxAgeSeconds}${options.secure ? '; Secure' : ''}`;\n\nexport const PUBLISHER_HEADER = 'x-archive-publisher';\n/** Pins account erasure to the issuer account shown when confirmation began. */\nexport const ACCOUNT_HEADER = 'X-Archive-Account';\nexport const REQUEST_MARKER_HEADER = 'x-archive-request';\n/** The wire-contract version advertised by health and stamped on every entry envelope. */\nexport const ARCHIVE_CONTRACT_VERSION = 1;\n/**\n * The storage schema version: the `archive_schema_meta` stamp the package's migration\n * writes and the Worker reads back through health. A mismatch answers `degraded`\n * instead of `ok` — a stale database is the most likely deployment fault.\n */\nexport const ARCHIVE_SCHEMA_VERSION = 1;\n/** Canonical issuer database initialization stamp. */\nexport const AUTH_SCHEMA_VERSION = 1;\n/** The `roles` claim value a session JWT carries for operator authority (moderation). */\nexport const ARCHIVE_OPERATOR_ROLE = 'archive-operator';\n/** The routable collection-name rule: lowercase `[a-z0-9-]`, at most 32 chars. */\nexport const ARCHIVE_COLLECTION_NAME_PATTERN = /^[a-z0-9-]{1,32}$/;\n\n// Exported schemas carry explicit public `Schema<Output>` annotations: the concrete\n// spell schema classes are not part of spell's public export surface, so inferred\n// types would not be portable across package declaration files.\nexport const uuidSchema: Schema<string> = s.string().uuid();\nexport const isoTimestampSchema: Schema<string> = s.string().isoDateTime();\nexport const hex64Schema: Schema<string> = s.string().regex(/^[0-9a-f]{64}$/);\n/** Well-formed user text: no lone UTF-16 surrogates, no C0/C1/DEL control characters. */\nexport const ILL_FORMED_TEXT = /[\\p{Cs}\\p{Cc}]/u;\nexport const isWellFormedText = (value: string): boolean => !ILL_FORMED_TEXT.test(value);\nconst textString = () => s.string().check(isWellFormedText);\n/** The one alias rule, shared by identity mutations and every emitted DTO. */\nexport const archiveAliasSchema: Schema<string> = textString().trim().max(24);\n\nexport const archiveAuthorSchema: Schema<{ id: string; name: string }> = s.object({\n id: uuidSchema,\n name: archiveAliasSchema,\n});\nexport const archiveIdentitySchema: Schema<{ id: string; name: string; operator: boolean } | null> = s\n .object({ id: uuidSchema, name: archiveAliasSchema, operator: s.boolean() })\n .nullable();\nexport type ArchiveIdentity = InferOutput<typeof archiveIdentitySchema>;\n/** The issuer account metadata export; its id is the session subject, not a publisher id. */\nexport const archiveAccountSchema: Schema<{\n createdAt: string;\n email: string;\n id: string;\n lastSignInAt: string | null;\n}> = s.object({\n createdAt: isoTimestampSchema,\n email: s.string().email(),\n id: uuidSchema,\n lastSignInAt: isoTimestampSchema.nullable(),\n});\nexport type ArchiveAccount = InferOutput<typeof archiveAccountSchema>;\nexport const archiveLikedIdsSchema: Schema<{ ids: string[] }> = s.object({ ids: s.array(uuidSchema) });\nexport const archiveLikesPageSchema: Schema<{ cursor: string | null; ids: string[] }> = s.object({\n cursor: s.string().nullable(),\n ids: s.array(uuidSchema),\n});\nexport type ArchiveLikesPage = InferOutput<typeof archiveLikesPageSchema>;\nexport const archiveLikeStateSchema: Schema<{ id: string; likeCount: number; liked: boolean }> = s.object({\n id: uuidSchema,\n likeCount: s.number().int().min(0).max(Number.MAX_SAFE_INTEGER),\n liked: s.boolean(),\n});\n\n/** Application bounds shared by handlers, the health route, and clients. */\nexport const ARCHIVE_LIMITS = Object.freeze({\n aliasChars: 24,\n cursorChars: 1024,\n idempotencyRetentionMs: 48 * 60 * 60 * 1000,\n likeStateIds: 50,\n maxPageSize: 50,\n maxPublications: 50,\n pageSize: 10,\n payloadBytes: 8192,\n publicCacheSeconds: 30,\n /** One free-text moderation reason: trimmed, non-empty, at most this many chars. */\n reportReasonChars: 256,\n requestBytes: 12 * 1024,\n searchChars: 64,\n searchTerms: 6,\n tagsPerEntry: 16,\n titleChars: 128,\n /** One declared filter or tag value: well-formed, non-empty, at most this many chars. */\n vocabChars: 64,\n});\nexport const archiveLimitsSchema: Schema<{\n aliasChars: number;\n cursorChars: number;\n idempotencyRetentionMs: number;\n likeStateIds: number;\n maxPageSize: number;\n maxPublications: number;\n pageSize: number;\n payloadBytes: number;\n publicCacheSeconds: number;\n reportReasonChars: number;\n requestBytes: number;\n searchChars: number;\n searchTerms: number;\n tagsPerEntry: number;\n titleChars: number;\n vocabChars: number;\n}> = s.object({\n aliasChars: s.number().int().min(1),\n cursorChars: s.number().int().min(1),\n idempotencyRetentionMs: s.number().int().min(1),\n likeStateIds: s.number().int().min(1),\n maxPageSize: s.number().int().min(1),\n maxPublications: s.number().int().min(1),\n pageSize: s.number().int().min(1),\n payloadBytes: s.number().int().min(1),\n publicCacheSeconds: s.number().int().min(0),\n reportReasonChars: s.number().int().min(1),\n requestBytes: s.number().int().min(1),\n searchChars: s.number().int().min(1),\n searchTerms: s.number().int().min(1),\n tagsPerEntry: s.number().int().min(1),\n titleChars: s.number().int().min(1),\n vocabChars: s.number().int().min(1),\n});\nexport const archiveHealthSchema: Schema<{\n /** The storage schema stamp (`archive_schema_meta`) the database actually carries. */\n dbSchemaVersion: number | null;\n features: { likes: boolean; publishing: boolean };\n limits: InferOutput<typeof archiveLimitsSchema>;\n schemaVersion: 1;\n /** 'degraded' when the database's storage schema does not match the Worker's. */\n status: 'ok' | 'degraded';\n reason: 'database-unavailable' | 'schema-mismatch' | null;\n}> = s.object({\n dbSchemaVersion: s.number().int().min(0).nullable(),\n features: s.object({ likes: s.boolean(), publishing: s.boolean() }),\n limits: archiveLimitsSchema,\n reason: s.enum(['database-unavailable', 'schema-mismatch'] as const).nullable(),\n schemaVersion: s.literal(ARCHIVE_CONTRACT_VERSION),\n status: s.enum(['ok', 'degraded'] as const),\n});\nexport type ArchiveHealth = InferOutput<typeof archiveHealthSchema>;\n\nexport const archiveAuthHealthSchema: Schema<{\n dbSchemaVersion: number | null;\n schemaVersion: 1;\n status: 'ok' | 'degraded';\n reason: 'configuration-unavailable' | 'database-unavailable' | 'schema-mismatch' | null;\n}> = s.object({\n dbSchemaVersion: s.number().int().min(0).nullable(),\n reason: s.enum(['configuration-unavailable', 'database-unavailable', 'schema-mismatch'] as const).nullable(),\n schemaVersion: s.literal(AUTH_SCHEMA_VERSION),\n status: s.enum(['ok', 'degraded'] as const),\n});\nexport type AuthHealth = InferOutput<typeof archiveAuthHealthSchema>;\n\n/** The Worker's full error-code vocabulary — the contract both sides test against. */\nexport const ARCHIVE_ERROR_CODES = [\n 'account-changed',\n 'auth-unavailable',\n 'bad-request',\n 'conflict',\n 'forbidden',\n 'gone',\n 'internal',\n 'invalid-payload',\n 'likes-disabled',\n 'method-not-allowed',\n 'not-found',\n 'publisher-changed',\n 'publishing-disabled',\n 'quota',\n 'rate-limited',\n 'record-unavailable',\n 'timeout',\n 'too-large',\n 'unauthenticated',\n 'unavailable',\n 'unsupported-media',\n] as const;\nexport type ArchiveErrorCode = (typeof ARCHIVE_ERROR_CODES)[number];\n\n/**\n * The error envelope every route answers failures with: `{ error: { code, message,\n * requestId } }`. Clients validate against this one schema — an envelope carrying an\n * unknown code or malformed fields is not an archive error at all.\n */\nexport const archiveErrorResponseSchema: Schema<{\n error: { code: ArchiveErrorCode; message: string; requestId: string };\n}> = s\n .object({\n error: s\n .object({\n code: s.enum(ARCHIVE_ERROR_CODES),\n message: s.string().min(1).max(256),\n requestId: uuidSchema,\n })\n .strict(),\n })\n .strict();\nexport type ArchiveErrorResponse = InferOutput<typeof archiveErrorResponseSchema>;\n\n/** The sign-out acknowledgement: the only non-collection response body, shared by both sides. */\nexport const archiveOkSchema: Schema<{ ok: true }> = s.object({ ok: s.literal(true) }).strict();\n\n/** One collection's public self-description: its name and declared query vocabularies. */\nexport const archiveCollectionMetaSchema: Schema<{\n filters: string[];\n name: string;\n tags: string[];\n}> = s.object({\n filters: s.array(s.string().min(1).max(ARCHIVE_LIMITS.vocabChars)),\n name: s.string().regex(ARCHIVE_COLLECTION_NAME_PATTERN),\n tags: s.array(s.string().min(1).max(ARCHIVE_LIMITS.vocabChars)),\n});\nexport type ArchiveCollectionMeta = InferOutput<typeof archiveCollectionMetaSchema>;\n\n/** One reader report an operator reviews: what was reported, why, and by whom. */\nexport const archiveReportsSchema: Schema<{\n cursor: string | null;\n reports: {\n id: string;\n createdAt: string;\n entryId: string;\n entryTitle: string;\n reason: string;\n reporter: { id: string; name: string };\n resolvedAt: string | null;\n }[];\n}> = s.object({\n cursor: s.string().nullable(),\n reports: s.array(\n s.object({\n createdAt: isoTimestampSchema,\n entryId: uuidSchema,\n entryTitle: s.string().min(1).max(ARCHIVE_LIMITS.titleChars),\n id: uuidSchema,\n reason: s.string().min(1).max(ARCHIVE_LIMITS.reportReasonChars),\n reporter: archiveAuthorSchema,\n resolvedAt: isoTimestampSchema.nullable(),\n }),\n ),\n});\nexport type ArchiveReports = InferOutput<typeof archiveReportsSchema>;\nexport const archiveOwnReportsSchema: Schema<{\n cursor: string | null;\n reports: {\n collection: string;\n createdAt: string;\n entryId: string;\n id: string;\n reason: string;\n resolvedAt: string | null;\n }[];\n}> = s.object({\n cursor: s.string().nullable(),\n reports: s.array(\n s.object({\n collection: s.string().regex(ARCHIVE_COLLECTION_NAME_PATTERN),\n createdAt: isoTimestampSchema,\n entryId: uuidSchema,\n id: uuidSchema,\n reason: s.string().min(1).max(ARCHIVE_LIMITS.reportReasonChars),\n resolvedAt: isoTimestampSchema.nullable(),\n }),\n ),\n});\nexport type ArchiveOwnReports = InferOutput<typeof archiveOwnReportsSchema>;\n\n/** The moderation actions an operator can take; the audit log's whole vocabulary. */\nexport const ARCHIVE_MODERATION_ACTIONS = ['hide', 'unhide', 'remove', 'erase-publisher'] as const;\nexport type ArchiveModerationAction = (typeof ARCHIVE_MODERATION_ACTIONS)[number];\n\n/**\n * The operator accountability log: one row per effective moderation action, newest\n * first. Operator and target travel as opaque ids only — no names (they change), no\n * content — so the log stays honest after renames and survives the erasures it records.\n */\nexport const archiveModerationLogSchema: Schema<{\n cursor: string | null;\n actions: {\n id: string;\n action: ArchiveModerationAction;\n collection: string | null;\n createdAt: string;\n operatorId: string;\n targetId: string;\n }[];\n}> = s.object({\n actions: s.array(\n s.object({\n action: s.enum(ARCHIVE_MODERATION_ACTIONS),\n collection: s.string().regex(ARCHIVE_COLLECTION_NAME_PATTERN).nullable(),\n createdAt: isoTimestampSchema,\n id: uuidSchema,\n operatorId: uuidSchema,\n targetId: uuidSchema,\n }),\n ),\n cursor: s.string().nullable(),\n});\nexport type ArchiveModerationLog = InferOutput<typeof archiveModerationLogSchema>;\n\n/** How the online list ranks entries: explicit modes only, no vague composites. */\nexport type ArchiveSort = 'liked' | 'recent';\nexport const archiveSortSchema: Schema<ArchiveSort> = s.enum(['liked', 'recent'] as const);\n\n/**\n * One page of archive entries. Every list in the package pages forward-only: the\n * cursor walks toward the oldest entry and is null after the last page.\n */\nexport interface ArchivePage<T> {\n /** Cursor for the next page; null after the last. */\n cursor: string | null;\n entries: readonly T[];\n}\n"],"mappings":"iCAGA,IAAa,EAAsB,kBACtB,EAAsB,UAKtB,EAA0B,OAC1B,EAAmC,IAUnC,oBAAsB,EAAe,IAChD,GAAG,EAAoB,GAAG,EAAM,oCAAoC,EAAoB,YAAY,EAAQ,gBAAgB,EAAQ,OAAS,WAAa,KAE/I,EAAmB,sBAEnB,EAAiB,oBACjB,EAAwB,oBAExB,EAA2B,EAM3B,EAAyB,EAEzB,EAAsB,EAEtB,E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O,CACP,OAAQ,EAAA,EAAE,KAAK,CAA0B,EACzC,WAAY,EAAA,EAAE,OAAO,CAAC,CAAC,MAAM,CAA+B,CAAC,CAAC,SAAS,EACvE,UAAW,EACX,GAAI,EACJ,WAAY,EACZ,SAAU,CACZ,CAAC,CACH,EACA,OAAQ,EAAA,EAAE,OAAO,CAAC,CAAC,SAAS,CAC9B,CAAC,EAKY,EAAyC,EAAA,EAAE,KAAK,CAAC,QAAS,QAAQ,CAAU"}
@@ -0,0 +1,228 @@
1
+ import { type InferOutput, type Schema } from '@vielzeug/spell';
2
+ /** Shared naming: one place so the client, Worker and issuer cannot drift. */
3
+ export declare const SESSION_COOKIE_NAME = "archive_session";
4
+ export declare const SESSION_COOKIE_PATH = "/api/v1";
5
+ /**
6
+ * The maximum age a session JWT may carry, and the cookie Max-Age an issuer sets:
7
+ * a long-lived signed-in state. The Worker rejects older tokens at this bound.
8
+ */
9
+ export declare const SESSION_MAX_AGE_SECONDS: number;
10
+ export declare const OPERATOR_SESSION_MAX_AGE_SECONDS: number;
11
+ /**
12
+ * The full Set-Cookie value for the session cookie: name, token and the security
13
+ * attributes every issuer and the Worker must agree on — HttpOnly, SameSite=Strict,
14
+ * the contract Path, Max-Age, and Secure in production. Issuers mint with the
15
+ * session's max age; the Worker and issuers clear with `maxAgeSeconds: 0`. Never
16
+ * hand-compose the attributes: the cookie's CSRF and theft posture is contract,
17
+ * not per-issuer choice.
18
+ */
19
+ export declare const sessionCookieValue: (token: string, options: {
20
+ maxAgeSeconds: number;
21
+ secure: boolean;
22
+ }) => string;
23
+ export declare const PUBLISHER_HEADER = "x-archive-publisher";
24
+ /** Pins account erasure to the issuer account shown when confirmation began. */
25
+ export declare const ACCOUNT_HEADER = "X-Archive-Account";
26
+ export declare const REQUEST_MARKER_HEADER = "x-archive-request";
27
+ /** The wire-contract version advertised by health and stamped on every entry envelope. */
28
+ export declare const ARCHIVE_CONTRACT_VERSION = 1;
29
+ /**
30
+ * The storage schema version: the `archive_schema_meta` stamp the package's migration
31
+ * writes and the Worker reads back through health. A mismatch answers `degraded`
32
+ * instead of `ok` — a stale database is the most likely deployment fault.
33
+ */
34
+ export declare const ARCHIVE_SCHEMA_VERSION = 1;
35
+ /** Canonical issuer database initialization stamp. */
36
+ export declare const AUTH_SCHEMA_VERSION = 1;
37
+ /** The `roles` claim value a session JWT carries for operator authority (moderation). */
38
+ export declare const ARCHIVE_OPERATOR_ROLE = "archive-operator";
39
+ /** The routable collection-name rule: lowercase `[a-z0-9-]`, at most 32 chars. */
40
+ export declare const ARCHIVE_COLLECTION_NAME_PATTERN: RegExp;
41
+ export declare const uuidSchema: Schema<string>;
42
+ export declare const isoTimestampSchema: Schema<string>;
43
+ export declare const hex64Schema: Schema<string>;
44
+ /** Well-formed user text: no lone UTF-16 surrogates, no C0/C1/DEL control characters. */
45
+ export declare const ILL_FORMED_TEXT: RegExp;
46
+ export declare const isWellFormedText: (value: string) => boolean;
47
+ /** The one alias rule, shared by identity mutations and every emitted DTO. */
48
+ export declare const archiveAliasSchema: Schema<string>;
49
+ export declare const archiveAuthorSchema: Schema<{
50
+ id: string;
51
+ name: string;
52
+ }>;
53
+ export declare const archiveIdentitySchema: Schema<{
54
+ id: string;
55
+ name: string;
56
+ operator: boolean;
57
+ } | null>;
58
+ export type ArchiveIdentity = InferOutput<typeof archiveIdentitySchema>;
59
+ /** The issuer account metadata export; its id is the session subject, not a publisher id. */
60
+ export declare const archiveAccountSchema: Schema<{
61
+ createdAt: string;
62
+ email: string;
63
+ id: string;
64
+ lastSignInAt: string | null;
65
+ }>;
66
+ export type ArchiveAccount = InferOutput<typeof archiveAccountSchema>;
67
+ export declare const archiveLikedIdsSchema: Schema<{
68
+ ids: string[];
69
+ }>;
70
+ export declare const archiveLikesPageSchema: Schema<{
71
+ cursor: string | null;
72
+ ids: string[];
73
+ }>;
74
+ export type ArchiveLikesPage = InferOutput<typeof archiveLikesPageSchema>;
75
+ export declare const archiveLikeStateSchema: Schema<{
76
+ id: string;
77
+ likeCount: number;
78
+ liked: boolean;
79
+ }>;
80
+ /** Application bounds shared by handlers, the health route, and clients. */
81
+ export declare const ARCHIVE_LIMITS: Readonly<{
82
+ aliasChars: 24;
83
+ cursorChars: 1024;
84
+ idempotencyRetentionMs: number;
85
+ likeStateIds: 50;
86
+ maxPageSize: 50;
87
+ maxPublications: 50;
88
+ pageSize: 10;
89
+ payloadBytes: 8192;
90
+ publicCacheSeconds: 30;
91
+ /** One free-text moderation reason: trimmed, non-empty, at most this many chars. */
92
+ reportReasonChars: 256;
93
+ requestBytes: number;
94
+ searchChars: 64;
95
+ searchTerms: 6;
96
+ tagsPerEntry: 16;
97
+ titleChars: 128;
98
+ /** One declared filter or tag value: well-formed, non-empty, at most this many chars. */
99
+ vocabChars: 64;
100
+ }>;
101
+ export declare const archiveLimitsSchema: Schema<{
102
+ aliasChars: number;
103
+ cursorChars: number;
104
+ idempotencyRetentionMs: number;
105
+ likeStateIds: number;
106
+ maxPageSize: number;
107
+ maxPublications: number;
108
+ pageSize: number;
109
+ payloadBytes: number;
110
+ publicCacheSeconds: number;
111
+ reportReasonChars: number;
112
+ requestBytes: number;
113
+ searchChars: number;
114
+ searchTerms: number;
115
+ tagsPerEntry: number;
116
+ titleChars: number;
117
+ vocabChars: number;
118
+ }>;
119
+ export declare const archiveHealthSchema: Schema<{
120
+ /** The storage schema stamp (`archive_schema_meta`) the database actually carries. */
121
+ dbSchemaVersion: number | null;
122
+ features: {
123
+ likes: boolean;
124
+ publishing: boolean;
125
+ };
126
+ limits: InferOutput<typeof archiveLimitsSchema>;
127
+ schemaVersion: 1;
128
+ /** 'degraded' when the database's storage schema does not match the Worker's. */
129
+ status: 'ok' | 'degraded';
130
+ reason: 'database-unavailable' | 'schema-mismatch' | null;
131
+ }>;
132
+ export type ArchiveHealth = InferOutput<typeof archiveHealthSchema>;
133
+ export declare const archiveAuthHealthSchema: Schema<{
134
+ dbSchemaVersion: number | null;
135
+ schemaVersion: 1;
136
+ status: 'ok' | 'degraded';
137
+ reason: 'configuration-unavailable' | 'database-unavailable' | 'schema-mismatch' | null;
138
+ }>;
139
+ export type AuthHealth = InferOutput<typeof archiveAuthHealthSchema>;
140
+ /** The Worker's full error-code vocabulary — the contract both sides test against. */
141
+ export declare const ARCHIVE_ERROR_CODES: readonly ["account-changed", "auth-unavailable", "bad-request", "conflict", "forbidden", "gone", "internal", "invalid-payload", "likes-disabled", "method-not-allowed", "not-found", "publisher-changed", "publishing-disabled", "quota", "rate-limited", "record-unavailable", "timeout", "too-large", "unauthenticated", "unavailable", "unsupported-media"];
142
+ export type ArchiveErrorCode = (typeof ARCHIVE_ERROR_CODES)[number];
143
+ /**
144
+ * The error envelope every route answers failures with: `{ error: { code, message,
145
+ * requestId } }`. Clients validate against this one schema — an envelope carrying an
146
+ * unknown code or malformed fields is not an archive error at all.
147
+ */
148
+ export declare const archiveErrorResponseSchema: Schema<{
149
+ error: {
150
+ code: ArchiveErrorCode;
151
+ message: string;
152
+ requestId: string;
153
+ };
154
+ }>;
155
+ export type ArchiveErrorResponse = InferOutput<typeof archiveErrorResponseSchema>;
156
+ /** The sign-out acknowledgement: the only non-collection response body, shared by both sides. */
157
+ export declare const archiveOkSchema: Schema<{
158
+ ok: true;
159
+ }>;
160
+ /** One collection's public self-description: its name and declared query vocabularies. */
161
+ export declare const archiveCollectionMetaSchema: Schema<{
162
+ filters: string[];
163
+ name: string;
164
+ tags: string[];
165
+ }>;
166
+ export type ArchiveCollectionMeta = InferOutput<typeof archiveCollectionMetaSchema>;
167
+ /** One reader report an operator reviews: what was reported, why, and by whom. */
168
+ export declare const archiveReportsSchema: Schema<{
169
+ cursor: string | null;
170
+ reports: {
171
+ id: string;
172
+ createdAt: string;
173
+ entryId: string;
174
+ entryTitle: string;
175
+ reason: string;
176
+ reporter: {
177
+ id: string;
178
+ name: string;
179
+ };
180
+ resolvedAt: string | null;
181
+ }[];
182
+ }>;
183
+ export type ArchiveReports = InferOutput<typeof archiveReportsSchema>;
184
+ export declare const archiveOwnReportsSchema: Schema<{
185
+ cursor: string | null;
186
+ reports: {
187
+ collection: string;
188
+ createdAt: string;
189
+ entryId: string;
190
+ id: string;
191
+ reason: string;
192
+ resolvedAt: string | null;
193
+ }[];
194
+ }>;
195
+ export type ArchiveOwnReports = InferOutput<typeof archiveOwnReportsSchema>;
196
+ /** The moderation actions an operator can take; the audit log's whole vocabulary. */
197
+ export declare const ARCHIVE_MODERATION_ACTIONS: readonly ["hide", "unhide", "remove", "erase-publisher"];
198
+ export type ArchiveModerationAction = (typeof ARCHIVE_MODERATION_ACTIONS)[number];
199
+ /**
200
+ * The operator accountability log: one row per effective moderation action, newest
201
+ * first. Operator and target travel as opaque ids only — no names (they change), no
202
+ * content — so the log stays honest after renames and survives the erasures it records.
203
+ */
204
+ export declare const archiveModerationLogSchema: Schema<{
205
+ cursor: string | null;
206
+ actions: {
207
+ id: string;
208
+ action: ArchiveModerationAction;
209
+ collection: string | null;
210
+ createdAt: string;
211
+ operatorId: string;
212
+ targetId: string;
213
+ }[];
214
+ }>;
215
+ export type ArchiveModerationLog = InferOutput<typeof archiveModerationLogSchema>;
216
+ /** How the online list ranks entries: explicit modes only, no vague composites. */
217
+ export type ArchiveSort = 'liked' | 'recent';
218
+ export declare const archiveSortSchema: Schema<ArchiveSort>;
219
+ /**
220
+ * One page of archive entries. Every list in the package pages forward-only: the
221
+ * cursor walks toward the oldest entry and is null after the last page.
222
+ */
223
+ export interface ArchivePage<T> {
224
+ /** Cursor for the next page; null after the last. */
225
+ cursor: string | null;
226
+ entries: readonly T[];
227
+ }
228
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,MAAM,EAAK,MAAM,iBAAiB,CAAC;AAEnE,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AACrD,eAAO,MAAM,mBAAm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0 +1,2 @@
1
+ import{s as e}from"@vielzeug/spell";var t=`archive_session`,n=`/api/v1`,r=2592e3,i=900,sessionCookieValue=(e,r)=>`${t}=${e}; HttpOnly; SameSite=Strict; Path=${n}; Max-Age=${r.maxAgeSeconds}${r.secure?`; Secure`:``}`,a=`x-archive-publisher`,o=`X-Archive-Account`,s=`x-archive-request`,c=1,l=1,u=1,d=`archive-operator`,f=/^[a-z0-9-]{1,32}$/,p=e.string().uuid(),m=e.string().isoDateTime(),h=e.string().regex(/^[0-9a-f]{64}$/),g=/[\p{Cs}\p{Cc}]/u,isWellFormedText=e=>!g.test(e),textString=()=>e.string().check(isWellFormedText),_=textString().trim().max(24),v=e.object({id:p,name:_}),y=e.object({id:p,name:_,operator:e.boolean()}).nullable(),b=e.object({createdAt:m,email:e.string().email(),id:p,lastSignInAt:m.nullable()}),x=e.object({ids:e.array(p)}),S=e.object({cursor:e.string().nullable(),ids:e.array(p)}),C=e.object({id:p,likeCount:e.number().int().min(0).max(2**53-1),liked:e.boolean()}),w=Object.freeze({aliasChars:24,cursorChars:1024,idempotencyRetentionMs:1728e5,likeStateIds:50,maxPageSize:50,maxPublications:50,pageSize:10,payloadBytes:8192,publicCacheSeconds:30,reportReasonChars:256,requestBytes:12288,searchChars:64,searchTerms:6,tagsPerEntry:16,titleChars:128,vocabChars:64}),T=e.object({aliasChars:e.number().int().min(1),cursorChars:e.number().int().min(1),idempotencyRetentionMs:e.number().int().min(1),likeStateIds:e.number().int().min(1),maxPageSize:e.number().int().min(1),maxPublications:e.number().int().min(1),pageSize:e.number().int().min(1),payloadBytes:e.number().int().min(1),publicCacheSeconds:e.number().int().min(0),reportReasonChars:e.number().int().min(1),requestBytes:e.number().int().min(1),searchChars:e.number().int().min(1),searchTerms:e.number().int().min(1),tagsPerEntry:e.number().int().min(1),titleChars:e.number().int().min(1),vocabChars:e.number().int().min(1)}),E=e.object({dbSchemaVersion:e.number().int().min(0).nullable(),features:e.object({likes:e.boolean(),publishing:e.boolean()}),limits:T,reason:e.enum([`database-unavailable`,`schema-mismatch`]).nullable(),schemaVersion:e.literal(1),status:e.enum([`ok`,`degraded`])}),D=e.object({dbSchemaVersion:e.number().int().min(0).nullable(),reason:e.enum([`configuration-unavailable`,`database-unavailable`,`schema-mismatch`]).nullable(),schemaVersion:e.literal(1),status:e.enum([`ok`,`degraded`])}),O=[`account-changed`,`auth-unavailable`,`bad-request`,`conflict`,`forbidden`,`gone`,`internal`,`invalid-payload`,`likes-disabled`,`method-not-allowed`,`not-found`,`publisher-changed`,`publishing-disabled`,`quota`,`rate-limited`,`record-unavailable`,`timeout`,`too-large`,`unauthenticated`,`unavailable`,`unsupported-media`],k=e.object({error:e.object({code:e.enum(O),message:e.string().min(1).max(256),requestId:p}).strict()}).strict(),A=e.object({ok:e.literal(!0)}).strict(),j=e.object({filters:e.array(e.string().min(1).max(w.vocabChars)),name:e.string().regex(f),tags:e.array(e.string().min(1).max(w.vocabChars))}),M=e.object({cursor:e.string().nullable(),reports:e.array(e.object({createdAt:m,entryId:p,entryTitle:e.string().min(1).max(w.titleChars),id:p,reason:e.string().min(1).max(w.reportReasonChars),reporter:v,resolvedAt:m.nullable()}))}),N=e.object({cursor:e.string().nullable(),reports:e.array(e.object({collection:e.string().regex(f),createdAt:m,entryId:p,id:p,reason:e.string().min(1).max(w.reportReasonChars),resolvedAt:m.nullable()}))}),P=[`hide`,`unhide`,`remove`,`erase-publisher`],F=e.object({actions:e.array(e.object({action:e.enum(P),collection:e.string().regex(f).nullable(),createdAt:m,id:p,operatorId:p,targetId:p})),cursor:e.string().nullable()}),I=e.enum([`liked`,`recent`]);export{o as ACCOUNT_HEADER,f as ARCHIVE_COLLECTION_NAME_PATTERN,c as ARCHIVE_CONTRACT_VERSION,O as ARCHIVE_ERROR_CODES,w as ARCHIVE_LIMITS,P as ARCHIVE_MODERATION_ACTIONS,d as ARCHIVE_OPERATOR_ROLE,l as ARCHIVE_SCHEMA_VERSION,u as AUTH_SCHEMA_VERSION,g as ILL_FORMED_TEXT,i as OPERATOR_SESSION_MAX_AGE_SECONDS,a as PUBLISHER_HEADER,s as REQUEST_MARKER_HEADER,t as SESSION_COOKIE_NAME,n as SESSION_COOKIE_PATH,r as SESSION_MAX_AGE_SECONDS,b as archiveAccountSchema,_ as archiveAliasSchema,D as archiveAuthHealthSchema,v as archiveAuthorSchema,j as archiveCollectionMetaSchema,k as archiveErrorResponseSchema,E as archiveHealthSchema,y as archiveIdentitySchema,C as archiveLikeStateSchema,x as archiveLikedIdsSchema,S as archiveLikesPageSchema,T as archiveLimitsSchema,F as archiveModerationLogSchema,A as archiveOkSchema,N as archiveOwnReportsSchema,M as archiveReportsSchema,I as archiveSortSchema,h as hex64Schema,isWellFormedText,m as isoTimestampSchema,sessionCookieValue,p as uuidSchema};
2
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","names":[],"sources":["../src/contract.ts"],"sourcesContent":["import { type InferOutput, type Schema, s } from '@vielzeug/spell';\n\n/** Shared naming: one place so the client, Worker and issuer cannot drift. */\nexport const SESSION_COOKIE_NAME = 'archive_session';\nexport const SESSION_COOKIE_PATH = '/api/v1';\n/**\n * The maximum age a session JWT may carry, and the cookie Max-Age an issuer sets:\n * a long-lived signed-in state. The Worker rejects older tokens at this bound.\n */\nexport const SESSION_MAX_AGE_SECONDS = 30 * 24 * 60 * 60;\nexport const OPERATOR_SESSION_MAX_AGE_SECONDS = 15 * 60;\n\n/**\n * The full Set-Cookie value for the session cookie: name, token and the security\n * attributes every issuer and the Worker must agree on — HttpOnly, SameSite=Strict,\n * the contract Path, Max-Age, and Secure in production. Issuers mint with the\n * session's max age; the Worker and issuers clear with `maxAgeSeconds: 0`. Never\n * hand-compose the attributes: the cookie's CSRF and theft posture is contract,\n * not per-issuer choice.\n */\nexport const sessionCookieValue = (token: string, options: { maxAgeSeconds: number; secure: boolean }): string =>\n `${SESSION_COOKIE_NAME}=${token}; HttpOnly; SameSite=Strict; Path=${SESSION_COOKIE_PATH}; Max-Age=${options.maxAgeSeconds}${options.secure ? '; Secure' : ''}`;\n\nexport const PUBLISHER_HEADER = 'x-archive-publisher';\n/** Pins account erasure to the issuer account shown when confirmation began. */\nexport const ACCOUNT_HEADER = 'X-Archive-Account';\nexport const REQUEST_MARKER_HEADER = 'x-archive-request';\n/** The wire-contract version advertised by health and stamped on every entry envelope. */\nexport const ARCHIVE_CONTRACT_VERSION = 1;\n/**\n * The storage schema version: the `archive_schema_meta` stamp the package's migration\n * writes and the Worker reads back through health. A mismatch answers `degraded`\n * instead of `ok` — a stale database is the most likely deployment fault.\n */\nexport const ARCHIVE_SCHEMA_VERSION = 1;\n/** Canonical issuer database initialization stamp. */\nexport const AUTH_SCHEMA_VERSION = 1;\n/** The `roles` claim value a session JWT carries for operator authority (moderation). */\nexport const ARCHIVE_OPERATOR_ROLE = 'archive-operator';\n/** The routable collection-name rule: lowercase `[a-z0-9-]`, at most 32 chars. */\nexport const ARCHIVE_COLLECTION_NAME_PATTERN = /^[a-z0-9-]{1,32}$/;\n\n// Exported schemas carry explicit public `Schema<Output>` annotations: the concrete\n// spell schema classes are not part of spell's public export surface, so inferred\n// types would not be portable across package declaration files.\nexport const uuidSchema: Schema<string> = s.string().uuid();\nexport const isoTimestampSchema: Schema<string> = s.string().isoDateTime();\nexport const hex64Schema: Schema<string> = s.string().regex(/^[0-9a-f]{64}$/);\n/** Well-formed user text: no lone UTF-16 surrogates, no C0/C1/DEL control characters. */\nexport const ILL_FORMED_TEXT = /[\\p{Cs}\\p{Cc}]/u;\nexport const isWellFormedText = (value: string): boolean => !ILL_FORMED_TEXT.test(value);\nconst textString = () => s.string().check(isWellFormedText);\n/** The one alias rule, shared by identity mutations and every emitted DTO. */\nexport const archiveAliasSchema: Schema<string> = textString().trim().max(24);\n\nexport const archiveAuthorSchema: Schema<{ id: string; name: string }> = s.object({\n id: uuidSchema,\n name: archiveAliasSchema,\n});\nexport const archiveIdentitySchema: Schema<{ id: string; name: string; operator: boolean } | null> = s\n .object({ id: uuidSchema, name: archiveAliasSchema, operator: s.boolean() })\n .nullable();\nexport type ArchiveIdentity = InferOutput<typeof archiveIdentitySchema>;\n/** The issuer account metadata export; its id is the session subject, not a publisher id. */\nexport const archiveAccountSchema: Schema<{\n createdAt: string;\n email: string;\n id: string;\n lastSignInAt: string | null;\n}> = s.object({\n createdAt: isoTimestampSchema,\n email: s.string().email(),\n id: uuidSchema,\n lastSignInAt: isoTimestampSchema.nullable(),\n});\nexport type ArchiveAccount = InferOutput<typeof archiveAccountSchema>;\nexport const archiveLikedIdsSchema: Schema<{ ids: string[] }> = s.object({ ids: s.array(uuidSchema) });\nexport const archiveLikesPageSchema: Schema<{ cursor: string | null; ids: string[] }> = s.object({\n cursor: s.string().nullable(),\n ids: s.array(uuidSchema),\n});\nexport type ArchiveLikesPage = InferOutput<typeof archiveLikesPageSchema>;\nexport const archiveLikeStateSchema: Schema<{ id: string; likeCount: number; liked: boolean }> = s.object({\n id: uuidSchema,\n likeCount: s.number().int().min(0).max(Number.MAX_SAFE_INTEGER),\n liked: s.boolean(),\n});\n\n/** Application bounds shared by handlers, the health route, and clients. */\nexport const ARCHIVE_LIMITS = Object.freeze({\n aliasChars: 24,\n cursorChars: 1024,\n idempotencyRetentionMs: 48 * 60 * 60 * 1000,\n likeStateIds: 50,\n maxPageSize: 50,\n maxPublications: 50,\n pageSize: 10,\n payloadBytes: 8192,\n publicCacheSeconds: 30,\n /** One free-text moderation reason: trimmed, non-empty, at most this many chars. */\n reportReasonChars: 256,\n requestBytes: 12 * 1024,\n searchChars: 64,\n searchTerms: 6,\n tagsPerEntry: 16,\n titleChars: 128,\n /** One declared filter or tag value: well-formed, non-empty, at most this many chars. */\n vocabChars: 64,\n});\nexport const archiveLimitsSchema: Schema<{\n aliasChars: number;\n cursorChars: number;\n idempotencyRetentionMs: number;\n likeStateIds: number;\n maxPageSize: number;\n maxPublications: number;\n pageSize: number;\n payloadBytes: number;\n publicCacheSeconds: number;\n reportReasonChars: number;\n requestBytes: number;\n searchChars: number;\n searchTerms: number;\n tagsPerEntry: number;\n titleChars: number;\n vocabChars: number;\n}> = s.object({\n aliasChars: s.number().int().min(1),\n cursorChars: s.number().int().min(1),\n idempotencyRetentionMs: s.number().int().min(1),\n likeStateIds: s.number().int().min(1),\n maxPageSize: s.number().int().min(1),\n maxPublications: s.number().int().min(1),\n pageSize: s.number().int().min(1),\n payloadBytes: s.number().int().min(1),\n publicCacheSeconds: s.number().int().min(0),\n reportReasonChars: s.number().int().min(1),\n requestBytes: s.number().int().min(1),\n searchChars: s.number().int().min(1),\n searchTerms: s.number().int().min(1),\n tagsPerEntry: s.number().int().min(1),\n titleChars: s.number().int().min(1),\n vocabChars: s.number().int().min(1),\n});\nexport const archiveHealthSchema: Schema<{\n /** The storage schema stamp (`archive_schema_meta`) the database actually carries. */\n dbSchemaVersion: number | null;\n features: { likes: boolean; publishing: boolean };\n limits: InferOutput<typeof archiveLimitsSchema>;\n schemaVersion: 1;\n /** 'degraded' when the database's storage schema does not match the Worker's. */\n status: 'ok' | 'degraded';\n reason: 'database-unavailable' | 'schema-mismatch' | null;\n}> = s.object({\n dbSchemaVersion: s.number().int().min(0).nullable(),\n features: s.object({ likes: s.boolean(), publishing: s.boolean() }),\n limits: archiveLimitsSchema,\n reason: s.enum(['database-unavailable', 'schema-mismatch'] as const).nullable(),\n schemaVersion: s.literal(ARCHIVE_CONTRACT_VERSION),\n status: s.enum(['ok', 'degraded'] as const),\n});\nexport type ArchiveHealth = InferOutput<typeof archiveHealthSchema>;\n\nexport const archiveAuthHealthSchema: Schema<{\n dbSchemaVersion: number | null;\n schemaVersion: 1;\n status: 'ok' | 'degraded';\n reason: 'configuration-unavailable' | 'database-unavailable' | 'schema-mismatch' | null;\n}> = s.object({\n dbSchemaVersion: s.number().int().min(0).nullable(),\n reason: s.enum(['configuration-unavailable', 'database-unavailable', 'schema-mismatch'] as const).nullable(),\n schemaVersion: s.literal(AUTH_SCHEMA_VERSION),\n status: s.enum(['ok', 'degraded'] as const),\n});\nexport type AuthHealth = InferOutput<typeof archiveAuthHealthSchema>;\n\n/** The Worker's full error-code vocabulary — the contract both sides test against. */\nexport const ARCHIVE_ERROR_CODES = [\n 'account-changed',\n 'auth-unavailable',\n 'bad-request',\n 'conflict',\n 'forbidden',\n 'gone',\n 'internal',\n 'invalid-payload',\n 'likes-disabled',\n 'method-not-allowed',\n 'not-found',\n 'publisher-changed',\n 'publishing-disabled',\n 'quota',\n 'rate-limited',\n 'record-unavailable',\n 'timeout',\n 'too-large',\n 'unauthenticated',\n 'unavailable',\n 'unsupported-media',\n] as const;\nexport type ArchiveErrorCode = (typeof ARCHIVE_ERROR_CODES)[number];\n\n/**\n * The error envelope every route answers failures with: `{ error: { code, message,\n * requestId } }`. Clients validate against this one schema — an envelope carrying an\n * unknown code or malformed fields is not an archive error at all.\n */\nexport const archiveErrorResponseSchema: Schema<{\n error: { code: ArchiveErrorCode; message: string; requestId: string };\n}> = s\n .object({\n error: s\n .object({\n code: s.enum(ARCHIVE_ERROR_CODES),\n message: s.string().min(1).max(256),\n requestId: uuidSchema,\n })\n .strict(),\n })\n .strict();\nexport type ArchiveErrorResponse = InferOutput<typeof archiveErrorResponseSchema>;\n\n/** The sign-out acknowledgement: the only non-collection response body, shared by both sides. */\nexport const archiveOkSchema: Schema<{ ok: true }> = s.object({ ok: s.literal(true) }).strict();\n\n/** One collection's public self-description: its name and declared query vocabularies. */\nexport const archiveCollectionMetaSchema: Schema<{\n filters: string[];\n name: string;\n tags: string[];\n}> = s.object({\n filters: s.array(s.string().min(1).max(ARCHIVE_LIMITS.vocabChars)),\n name: s.string().regex(ARCHIVE_COLLECTION_NAME_PATTERN),\n tags: s.array(s.string().min(1).max(ARCHIVE_LIMITS.vocabChars)),\n});\nexport type ArchiveCollectionMeta = InferOutput<typeof archiveCollectionMetaSchema>;\n\n/** One reader report an operator reviews: what was reported, why, and by whom. */\nexport const archiveReportsSchema: Schema<{\n cursor: string | null;\n reports: {\n id: string;\n createdAt: string;\n entryId: string;\n entryTitle: string;\n reason: string;\n reporter: { id: string; name: string };\n resolvedAt: string | null;\n }[];\n}> = s.object({\n cursor: s.string().nullable(),\n reports: s.array(\n s.object({\n createdAt: isoTimestampSchema,\n entryId: uuidSchema,\n entryTitle: s.string().min(1).max(ARCHIVE_LIMITS.titleChars),\n id: uuidSchema,\n reason: s.string().min(1).max(ARCHIVE_LIMITS.reportReasonChars),\n reporter: archiveAuthorSchema,\n resolvedAt: isoTimestampSchema.nullable(),\n }),\n ),\n});\nexport type ArchiveReports = InferOutput<typeof archiveReportsSchema>;\nexport const archiveOwnReportsSchema: Schema<{\n cursor: string | null;\n reports: {\n collection: string;\n createdAt: string;\n entryId: string;\n id: string;\n reason: string;\n resolvedAt: string | null;\n }[];\n}> = s.object({\n cursor: s.string().nullable(),\n reports: s.array(\n s.object({\n collection: s.string().regex(ARCHIVE_COLLECTION_NAME_PATTERN),\n createdAt: isoTimestampSchema,\n entryId: uuidSchema,\n id: uuidSchema,\n reason: s.string().min(1).max(ARCHIVE_LIMITS.reportReasonChars),\n resolvedAt: isoTimestampSchema.nullable(),\n }),\n ),\n});\nexport type ArchiveOwnReports = InferOutput<typeof archiveOwnReportsSchema>;\n\n/** The moderation actions an operator can take; the audit log's whole vocabulary. */\nexport const ARCHIVE_MODERATION_ACTIONS = ['hide', 'unhide', 'remove', 'erase-publisher'] as const;\nexport type ArchiveModerationAction = (typeof ARCHIVE_MODERATION_ACTIONS)[number];\n\n/**\n * The operator accountability log: one row per effective moderation action, newest\n * first. Operator and target travel as opaque ids only — no names (they change), no\n * content — so the log stays honest after renames and survives the erasures it records.\n */\nexport const archiveModerationLogSchema: Schema<{\n cursor: string | null;\n actions: {\n id: string;\n action: ArchiveModerationAction;\n collection: string | null;\n createdAt: string;\n operatorId: string;\n targetId: string;\n }[];\n}> = s.object({\n actions: s.array(\n s.object({\n action: s.enum(ARCHIVE_MODERATION_ACTIONS),\n collection: s.string().regex(ARCHIVE_COLLECTION_NAME_PATTERN).nullable(),\n createdAt: isoTimestampSchema,\n id: uuidSchema,\n operatorId: uuidSchema,\n targetId: uuidSchema,\n }),\n ),\n cursor: s.string().nullable(),\n});\nexport type ArchiveModerationLog = InferOutput<typeof archiveModerationLogSchema>;\n\n/** How the online list ranks entries: explicit modes only, no vague composites. */\nexport type ArchiveSort = 'liked' | 'recent';\nexport const archiveSortSchema: Schema<ArchiveSort> = s.enum(['liked', 'recent'] as const);\n\n/**\n * One page of archive entries. Every list in the package pages forward-only: the\n * cursor walks toward the oldest entry and is null after the last page.\n */\nexport interface ArchivePage<T> {\n /** Cursor for the next page; null after the last. */\n cursor: string | null;\n entries: readonly T[];\n}\n"],"mappings":"oCAGA,IAAa,EAAsB,kBACtB,EAAsB,UAKtB,EAA0B,OAC1B,EAAmC,IAUnC,oBAAsB,EAAe,IAChD,GAAG,EAAoB,GAAG,EAAM,oCAAoC,EAAoB,YAAY,EAAQ,gBAAgB,EAAQ,OAAS,WAAa,KAE/I,EAAmB,sBAEnB,EAAiB,oBACjB,EAAwB,oBAExB,EAA2B,EAM3B,EAAyB,EAEzB,EAAsB,EAEtB,EAAwB,mBAExB,EAAkC,oBAKlC,EAA6B,EAAE,OAAO,CAAC,CAAC,KAAK,EAC7C,EAAqC,EAAE,OAAO,CAAC,CAAC,YAAY,EAC5D,EAA8B,EAAE,OAAO,CAAC,CAAC,MAAM,gBAAgB,EAE/D,EAAkB,kBAClB,iBAAoB,GAA2B,CAAC,EAAgB,KAAK,CAAK,EACjF,eAAmB,EAAE,OAAO,CAAC,CAAC,MAAM,gBAAgB,EAE7C,EAAqC,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAE/D,EAA4D,EAAE,OAAO,CAChF,GAAI,EACJ,KAAM,CACR,CAAC,EACY,EAAwF,EAClG,OAAO,CAAE,GAAI,EAAY,KAAM,EAAoB,SAAU,EAAE,QAAQ,CAAE,CAAC,CAAC,CAC3E,SAAS,EAGC,EAKR,EAAE,OAAO,CACZ,U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AAI,EACJ,OAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAe,iBAAiB,EAC9D,WAAY,EAAmB,SAAS,CAC1C,CAAC,CACH,CACF,CAAC,EAIY,EAA6B,CAAC,OAAQ,SAAU,SAAU,iBAAiB,EAQ3E,EAUR,EAAE,OAAO,CACZ,QAAS,EAAE,MACT,EAAE,OAAO,CACP,OAAQ,EAAE,KAAK,CAA0B,EACzC,WAAY,EAAE,OAAO,CAAC,CAAC,MAAM,CAA+B,CAAC,CAAC,SAAS,EACvE,UAAW,EACX,GAAI,EACJ,WAAY,EACZ,SAAU,CACZ,CAAC,CACH,EACA,OAAQ,EAAE,OAAO,CAAC,CAAC,SAAS,CAC9B,CAAC,EAKY,EAAyC,EAAE,KAAK,CAAC,QAAS,QAAQ,CAAU"}
@@ -0,0 +1,2 @@
1
+ var ArchiveError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},ArchiveDefinitionError=class extends ArchiveError{},ArchiveDerivationError=class extends ArchiveError{stage;constructor(e,t,n){super(t,n),this.stage=e}};exports.ArchiveDefinitionError=ArchiveDefinitionError,exports.ArchiveDerivationError=ArchiveDerivationError,exports.ArchiveError=ArchiveError;
2
+ //# sourceMappingURL=errors.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export class ArchiveError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ArchiveDefinitionError extends ArchiveError {}\n\nexport type ArchiveDerivationStage = 'canonicalize' | 'hash' | 'index' | 'schema';\n\n/** A collection callback or core runtime fault, not invalid submitted content. */\nexport class ArchiveDerivationError extends ArchiveError {\n readonly stage: ArchiveDerivationStage;\n\n constructor(stage: ArchiveDerivationStage, message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.stage = stage;\n }\n}\n"],"mappings":"AAAA,IAAa,aAAb,cAAkC,KAAM,CACtC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAEa,uBAAb,cAA4C,YAAa,CAAC,EAK7C,uBAAb,cAA4C,YAAa,CACvD,MAEA,YAAY,EAA+B,EAAiB,EAAqB,CAC/E,MAAM,EAAS,CAAI,EACnB,KAAK,MAAQ,CACf,CACF"}
@@ -0,0 +1,12 @@
1
+ export declare class ArchiveError extends Error {
2
+ constructor(message: string, opts?: ErrorOptions);
3
+ }
4
+ export declare class ArchiveDefinitionError extends ArchiveError {
5
+ }
6
+ export type ArchiveDerivationStage = 'canonicalize' | 'hash' | 'index' | 'schema';
7
+ /** A collection callback or core runtime fault, not invalid submitted content. */
8
+ export declare class ArchiveDerivationError extends ArchiveError {
9
+ readonly stage: ArchiveDerivationStage;
10
+ constructor(stage: ArchiveDerivationStage, message: string, opts?: ErrorOptions);
11
+ }
12
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,qBAAa,sBAAuB,SAAQ,YAAY;CAAG;AAE3D,MAAM,MAAM,sBAAsB,GAAG,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAElF,kFAAkF;AAClF,qBAAa,sBAAuB,SAAQ,YAAY;IACtD,QAAQ,CAAC,KAAK,EAAE,sBAAsB,CAAC;gBAE3B,KAAK,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAIhF"}
package/dist/errors.js ADDED
@@ -0,0 +1,2 @@
1
+ var ArchiveError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},ArchiveDefinitionError=class extends ArchiveError{},ArchiveDerivationError=class extends ArchiveError{stage;constructor(e,t,n){super(t,n),this.stage=e}};export{ArchiveDefinitionError,ArchiveDerivationError,ArchiveError};
2
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export class ArchiveError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ArchiveDefinitionError extends ArchiveError {}\n\nexport type ArchiveDerivationStage = 'canonicalize' | 'hash' | 'index' | 'schema';\n\n/** A collection callback or core runtime fault, not invalid submitted content. */\nexport class ArchiveDerivationError extends ArchiveError {\n readonly stage: ArchiveDerivationStage;\n\n constructor(stage: ArchiveDerivationStage, message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.stage = stage;\n }\n}\n"],"mappings":"AAAA,IAAa,aAAb,cAAkC,KAAM,CACtC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAEa,uBAAb,cAA4C,YAAa,CAAC,EAK7C,uBAAb,cAA4C,YAAa,CACvD,MAEA,YAAY,EAA+B,EAAiB,EAAqB,CAC/E,MAAM,EAAS,CAAI,EACnB,KAAK,MAAQ,CACf,CACF"}
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./contract.cjs"),t=require("./errors.cjs"),n=require("./collection.cjs");exports.ACCOUNT_HEADER=e.ACCOUNT_HEADER,exports.ARCHIVE_COLLECTION_NAME_PATTERN=e.ARCHIVE_COLLECTION_NAME_PATTERN,exports.ARCHIVE_CONTRACT_VERSION=e.ARCHIVE_CONTRACT_VERSION,exports.ARCHIVE_ERROR_CODES=e.ARCHIVE_ERROR_CODES,exports.ARCHIVE_LIMITS=e.ARCHIVE_LIMITS,exports.ARCHIVE_MODERATION_ACTIONS=e.ARCHIVE_MODERATION_ACTIONS,exports.ARCHIVE_OPERATOR_ROLE=e.ARCHIVE_OPERATOR_ROLE,exports.ARCHIVE_SCHEMA_VERSION=e.ARCHIVE_SCHEMA_VERSION,exports.AUTH_SCHEMA_VERSION=e.AUTH_SCHEMA_VERSION,exports.ArchiveDefinitionError=t.ArchiveDefinitionError,exports.ArchiveDerivationError=t.ArchiveDerivationError,exports.ArchiveError=t.ArchiveError,exports.ILL_FORMED_TEXT=e.ILL_FORMED_TEXT,exports.OPERATOR_SESSION_MAX_AGE_SECONDS=e.OPERATOR_SESSION_MAX_AGE_SECONDS,exports.PUBLISHER_HEADER=e.PUBLISHER_HEADER,exports.REQUEST_MARKER_HEADER=e.REQUEST_MARKER_HEADER,exports.SESSION_COOKIE_NAME=e.SESSION_COOKIE_NAME,exports.SESSION_COOKIE_PATH=e.SESSION_COOKIE_PATH,exports.SESSION_MAX_AGE_SECONDS=e.SESSION_MAX_AGE_SECONDS,exports.archiveAccountSchema=e.archiveAccountSchema,exports.archiveAliasSchema=e.archiveAliasSchema,exports.archiveAuthHealthSchema=e.archiveAuthHealthSchema,exports.archiveAuthorSchema=e.archiveAuthorSchema,exports.archiveCollectionMetaSchema=e.archiveCollectionMetaSchema,exports.archiveErrorResponseSchema=e.archiveErrorResponseSchema,exports.archiveHealthSchema=e.archiveHealthSchema,exports.archiveIdentitySchema=e.archiveIdentitySchema,exports.archiveLikeStateSchema=e.archiveLikeStateSchema,exports.archiveLikedIdsSchema=e.archiveLikedIdsSchema,exports.archiveLikesPageSchema=e.archiveLikesPageSchema,exports.archiveLimitsSchema=e.archiveLimitsSchema,exports.archiveModerationLogSchema=e.archiveModerationLogSchema,exports.archiveOkSchema=e.archiveOkSchema,exports.archiveOwnReportsSchema=e.archiveOwnReportsSchema,exports.archiveReportsSchema=e.archiveReportsSchema,exports.archiveSortSchema=e.archiveSortSchema,exports.defineArchiveCollection=n.defineArchiveCollection,exports.hex64Schema=e.hex64Schema,exports.isWellFormedText=e.isWellFormedText,exports.isoTimestampSchema=e.isoTimestampSchema,exports.sessionCookieValue=e.sessionCookieValue,exports.uuidSchema=e.uuidSchema;
@@ -0,0 +1,4 @@
1
+ export * from './collection';
2
+ export * from './contract';
3
+ export * from './errors';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{ACCOUNT_HEADER as e,ARCHIVE_COLLECTION_NAME_PATTERN as t,ARCHIVE_CONTRACT_VERSION as n,ARCHIVE_ERROR_CODES as r,ARCHIVE_LIMITS as i,ARCHIVE_MODERATION_ACTIONS as a,ARCHIVE_OPERATOR_ROLE as o,ARCHIVE_SCHEMA_VERSION as s,AUTH_SCHEMA_VERSION as c,ILL_FORMED_TEXT as l,OPERATOR_SESSION_MAX_AGE_SECONDS as u,PUBLISHER_HEADER as d,REQUEST_MARKER_HEADER as f,SESSION_COOKIE_NAME as p,SESSION_COOKIE_PATH as m,SESSION_MAX_AGE_SECONDS as h,archiveAccountSchema as g,archiveAliasSchema as _,archiveAuthHealthSchema as v,archiveAuthorSchema as y,archiveCollectionMetaSchema as b,archiveErrorResponseSchema as x,archiveHealthSchema as S,archiveIdentitySchema as C,archiveLikeStateSchema as w,archiveLikedIdsSchema as T,archiveLikesPageSchema as E,archiveLimitsSchema as D,archiveModerationLogSchema as O,archiveOkSchema as k,archiveOwnReportsSchema as A,archiveReportsSchema as j,archiveSortSchema as M,hex64Schema as N,isWellFormedText as P,isoTimestampSchema as F,sessionCookieValue as I,uuidSchema as L}from"./contract.js";import{ArchiveDefinitionError as R,ArchiveDerivationError as z,ArchiveError as B}from"./errors.js";import{defineArchiveCollection as V}from"./collection.js";export{e as ACCOUNT_HEADER,t as ARCHIVE_COLLECTION_NAME_PATTERN,n as ARCHIVE_CONTRACT_VERSION,r as ARCHIVE_ERROR_CODES,i as ARCHIVE_LIMITS,a as ARCHIVE_MODERATION_ACTIONS,o as ARCHIVE_OPERATOR_ROLE,s as ARCHIVE_SCHEMA_VERSION,c as AUTH_SCHEMA_VERSION,R as ArchiveDefinitionError,z as ArchiveDerivationError,B as ArchiveError,l as ILL_FORMED_TEXT,u as OPERATOR_SESSION_MAX_AGE_SECONDS,d as PUBLISHER_HEADER,f as REQUEST_MARKER_HEADER,p as SESSION_COOKIE_NAME,m as SESSION_COOKIE_PATH,h as SESSION_MAX_AGE_SECONDS,g as archiveAccountSchema,_ as archiveAliasSchema,v as archiveAuthHealthSchema,y as archiveAuthorSchema,b as archiveCollectionMetaSchema,x as archiveErrorResponseSchema,S as archiveHealthSchema,C as archiveIdentitySchema,w as archiveLikeStateSchema,T as archiveLikedIdsSchema,E as archiveLikesPageSchema,D as archiveLimitsSchema,O as archiveModerationLogSchema,k as archiveOkSchema,A as archiveOwnReportsSchema,j as archiveReportsSchema,M as archiveSortSchema,V as defineArchiveCollection,N as hex64Schema,P as isWellFormedText,F as isoTimestampSchema,I as sessionCookieValue,L as uuidSchema};
@@ -0,0 +1,2 @@
1
+ const e=require("../contract.cjs"),t=require("./http.cjs");let n=require("@vielzeug/spell");var encodeCursorValue=e=>{let t=new TextEncoder().encode(JSON.stringify(e));return btoa(Array.from(t,e=>String.fromCharCode(e)).join(``)).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replaceAll(`=`,``)};function decodeCursorValue(n,r){if(n.length>e.ARCHIVE_LIMITS.cursorChars||!/^[A-Za-z0-9_-]+$/.test(n))throw t.badRequest();let i;try{let e=n.replaceAll(`-`,`+`).replaceAll(`_`,`/`),t=Uint8Array.from(atob(e+`=`.repeat((4-e.length%4)%4)),e=>e.charCodeAt(0));i=JSON.parse(new TextDecoder(`utf-8`,{fatal:!0}).decode(t))}catch{throw t.badRequest()}let a=r.safeParse(i);if(!a.success||encodeCursorValue(i)!==n)throw t.badRequest();return a.data}var r=n.s.object({context:n.s.string(),createdAt:e.isoTimestampSchema,id:e.uuidSchema,likeCount:n.s.number().int().min(0).max(2**53-1).optional()});function forwardPageParams(n,i){let a=n.get(`limit`),o=a===null?e.ARCHIVE_LIMITS.pageSize:Number(a);if(!Number.isInteger(o)||o<1||o>e.ARCHIVE_LIMITS.maxPageSize)throw t.badRequest();let s=n.get(`cursor`),c=s===null?null:decodeCursorValue(s,r);if(c!==null&&c.context!==i)throw t.badRequest();return{cursor:c,limit:o}}function forwardPage(e,n,r=[]){let i=t.queryParams(new URL(e.url),[`cursor`,`limit`,...r]);return{...forwardPageParams(i,n),params:i}}var nextCursor=(e,t)=>encodeCursorValue({...e,context:t});exports.decodeCursorValue=decodeCursorValue,exports.encodeCursorValue=encodeCursorValue,exports.forwardPage=forwardPage,exports.forwardPageParams=forwardPageParams,exports.nextCursor=nextCursor;
2
+ //# sourceMappingURL=_pagination.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_pagination.cjs","names":[],"sources":["../../src/worker/_pagination.ts"],"sourcesContent":["import { type Schema, s } from '@vielzeug/spell';\nimport { ARCHIVE_LIMITS, isoTimestampSchema, uuidSchema } from '../contract';\nimport { badRequest, queryParams } from './http';\n\n/**\n * The package's one pagination idiom: forward-only keyset pages. A cursor is an\n * opaque envelope of `{ context, createdAt, id, likeCount }` — `createdAt`/`id`\n * are the sort boundary (a timestamp and the row id), `likeCount` is the optional\n * extra sort field (the boundary count of the liked-sorted entry list), and\n * `context` names the query the cursor was minted for, so a cursor replayed under\n * a different query is a 400, never a silently wrong page.\n */\nexport const encodeCursorValue = (value: unknown): string => {\n const bytes = new TextEncoder().encode(JSON.stringify(value));\n return btoa(Array.from(bytes, (byte) => String.fromCharCode(byte)).join(''))\n .replaceAll('+', '-')\n .replaceAll('/', '_')\n .replaceAll('=', '');\n};\n\nexport function decodeCursorValue<T>(raw: string, schema: Schema<T>): T {\n if (raw.length > ARCHIVE_LIMITS.cursorChars || !/^[A-Za-z0-9_-]+$/.test(raw)) throw badRequest();\n let value: unknown;\n try {\n const base64 = raw.replaceAll('-', '+').replaceAll('_', '/');\n const bytes = Uint8Array.from(atob(base64 + '='.repeat((4 - (base64.length % 4)) % 4)), (char) =>\n char.charCodeAt(0),\n );\n value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));\n } catch {\n throw badRequest();\n }\n const parsed = schema.safeParse(value);\n if (!parsed.success || encodeCursorValue(value) !== raw) throw badRequest();\n return parsed.data;\n}\n\n/** One keyset boundary: timestamp, row id, and the liked sort's boundary count. */\nexport interface ForwardCursor {\n context: string;\n createdAt: string;\n id: string;\n likeCount?: number;\n}\n\nconst forwardCursorSchema: Schema<ForwardCursor> = s.object({\n context: s.string(),\n createdAt: isoTimestampSchema,\n id: uuidSchema,\n // Only the liked-sorted entry list carries a boundary count; every other list\n // omits the key entirely.\n likeCount: s.number().int().min(0).max(Number.MAX_SAFE_INTEGER).optional(),\n});\n\n/** Parses `limit` and the forward cursor from an already allow-listed parameter set. */\nexport function forwardPageParams(params: URLSearchParams, context: string) {\n const rawLimit = params.get('limit');\n const limit = rawLimit === null ? ARCHIVE_LIMITS.pageSize : Number(rawLimit);\n if (!Number.isInteger(limit) || limit < 1 || limit > ARCHIVE_LIMITS.maxPageSize) throw badRequest();\n const raw = params.get('cursor');\n const cursor = raw === null ? null : decodeCursorValue(raw, forwardCursorSchema);\n if (cursor !== null && cursor.context !== context) throw badRequest();\n return { cursor, limit };\n}\n\n/** Allow-lists the query, then parses `limit` and the forward cursor. */\nexport function forwardPage(request: Request, context: string, extra: readonly string[] = []) {\n const params = queryParams(new URL(request.url), ['cursor', 'limit', ...extra]);\n return { ...forwardPageParams(params, context), params };\n}\n\nexport const n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SAAgB,kBAAkB,EAAyB,EAAiB,CAC1E,IAAM,EAAW,EAAO,IAAI,OAAO,EAC7B,EAAQ,IAAa,KAAO,EAAA,eAAe,SAAW,OAAO,CAAQ,EAC3E,GAAI,CAAC,OAAO,UAAU,CAAK,GAAK,EAAQ,GAAK,EAAQ,EAAA,eAAe,YAAa,MAAM,EAAA,WAAW,EAClG,IAAM,EAAM,EAAO,IAAI,QAAQ,EACzB,EAAS,IAAQ,KAAO,KAAO,kBAAkB,EAAK,CAAmB,EAC/E,GAAI,IAAW,MAAQ,EAAO,UAAY,EAAS,MAAM,EAAA,WAAW,EACpE,MAAO,CAAE,SAAQ,OAAM,CACzB,CAGA,SAAgB,YAAY,EAAkB,EAAiB,EAA2B,CAAC,EAAG,CAC5F,IAAM,EAAS,EAAA,YAAY,IAAI,IAAI,EAAQ,GAAG,EAAG,CAAC,SAAU,QAAS,GAAG,CAAK,CAAC,EAC9E,MAAO,CAAE,GAAG,kBAAkB,EAAQ,CAAO,EAAG,QAAO,CACzD,CAEA,IAAa,YAAc,EAAwC,IACjE,kBAAkB,CAAE,GAAG,EAAQ,SAAQ,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { type Schema } from '@vielzeug/spell';
2
+ /**
3
+ * The package's one pagination idiom: forward-only keyset pages. A cursor is an
4
+ * opaque envelope of `{ context, createdAt, id, likeCount }` — `createdAt`/`id`
5
+ * are the sort boundary (a timestamp and the row id), `likeCount` is the optional
6
+ * extra sort field (the boundary count of the liked-sorted entry list), and
7
+ * `context` names the query the cursor was minted for, so a cursor replayed under
8
+ * a different query is a 400, never a silently wrong page.
9
+ */
10
+ export declare const encodeCursorValue: (value: unknown) => string;
11
+ export declare function decodeCursorValue<T>(raw: string, schema: Schema<T>): T;
12
+ /** One keyset boundary: timestamp, row id, and the liked sort's boundary count. */
13
+ export interface ForwardCursor {
14
+ context: string;
15
+ createdAt: string;
16
+ id: string;
17
+ likeCount?: number;
18
+ }
19
+ /** Parses `limit` and the forward cursor from an already allow-listed parameter set. */
20
+ export declare function forwardPageParams(params: URLSearchParams, context: string): {
21
+ cursor: ForwardCursor | null;
22
+ limit: number;
23
+ };
24
+ /** Allow-lists the query, then parses `limit` and the forward cursor. */
25
+ export declare function forwardPage(request: Request, context: string, extra?: readonly string[]): {
26
+ params: URLSearchParams;
27
+ cursor: ForwardCursor | null;
28
+ limit: number;
29
+ };
30
+ export declare const nextCursor: (cursor: Omit<ForwardCursor, "context">, context: string) => string;
31
+ //# sourceMappingURL=_pagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_pagination.d.ts","sourceRoot":"","sources":["../../src/worker/_pagination.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAK,MAAM,iBAAiB,CAAC;AAIjD;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,OAAO,KAAG,MAMlD,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAetE;AAED,mFAAmF;AACnF,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAWD,wFAAwF;AACxF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;;;EAQzE;AAED,yEAAyE;AACzE,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,SAAS,MAAM,EAAO;;;;EAG3F;AAED,eAAO,MAAM,UAAU,GAAI,QAAQ,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,EAAE,SAAS,MAAM,KAAG,MAC1C,CAAC"}
@@ -0,0 +1,2 @@
1
+ import{ARCHIVE_LIMITS as e,isoTimestampSchema as t,uuidSchema as n}from"../contract.js";import{badRequest as r,queryParams as i}from"./http.js";import{s as a}from"@vielzeug/spell";var encodeCursorValue=e=>{let t=new TextEncoder().encode(JSON.stringify(e));return btoa(Array.from(t,e=>String.fromCharCode(e)).join(``)).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replaceAll(`=`,``)};function decodeCursorValue(t,n){if(t.length>e.cursorChars||!/^[A-Za-z0-9_-]+$/.test(t))throw r();let i;try{let e=t.replaceAll(`-`,`+`).replaceAll(`_`,`/`),n=Uint8Array.from(atob(e+`=`.repeat((4-e.length%4)%4)),e=>e.charCodeAt(0));i=JSON.parse(new TextDecoder(`utf-8`,{fatal:!0}).decode(n))}catch{throw r()}let a=n.safeParse(i);if(!a.success||encodeCursorValue(i)!==t)throw r();return a.data}var o=a.object({context:a.string(),createdAt:t,id:n,likeCount:a.number().int().min(0).max(2**53-1).optional()});function forwardPageParams(t,n){let i=t.get(`limit`),a=i===null?e.pageSize:Number(i);if(!Number.isInteger(a)||a<1||a>e.maxPageSize)throw r();let s=t.get(`cursor`),c=s===null?null:decodeCursorValue(s,o);if(c!==null&&c.context!==n)throw r();return{cursor:c,limit:a}}function forwardPage(e,t,n=[]){let r=i(new URL(e.url),[`cursor`,`limit`,...n]);return{...forwardPageParams(r,t),params:r}}var nextCursor=(e,t)=>encodeCursorValue({...e,context:t});export{decodeCursorValue,encodeCursorValue,forwardPage,forwardPageParams,nextCursor};
2
+ //# sourceMappingURL=_pagination.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_pagination.js","names":[],"sources":["../../src/worker/_pagination.ts"],"sourcesContent":["import { type Schema, s } from '@vielzeug/spell';\nimport { ARCHIVE_LIMITS, isoTimestampSchema, uuidSchema } from '../contract';\nimport { badRequest, queryParams } from './http';\n\n/**\n * The package's one pagination idiom: forward-only keyset pages. A cursor is an\n * opaque envelope of `{ context, createdAt, id, likeCount }` — `createdAt`/`id`\n * are the sort boundary (a timestamp and the row id), `likeCount` is the optional\n * extra sort field (the boundary count of the liked-sorted entry list), and\n * `context` names the query the cursor was minted for, so a cursor replayed under\n * a different query is a 400, never a silently wrong page.\n */\nexport const encodeCursorValue = (value: unknown): string => {\n const bytes = new TextEncoder().encode(JSON.stringify(value));\n return btoa(Array.from(bytes, (byte) => String.fromCharCode(byte)).join(''))\n .replaceAll('+', '-')\n .replaceAll('/', '_')\n .replaceAll('=', '');\n};\n\nexport function decodeCursorValue<T>(raw: string, schema: Schema<T>): T {\n if (raw.length > ARCHIVE_LIMITS.cursorChars || !/^[A-Za-z0-9_-]+$/.test(raw)) throw badRequest();\n let value: unknown;\n try {\n const base64 = raw.replaceAll('-', '+').replaceAll('_', '/');\n const bytes = Uint8Array.from(atob(base64 + '='.repeat((4 - (base64.length % 4)) % 4)), (char) =>\n char.charCodeAt(0),\n );\n value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));\n } catch {\n throw badRequest();\n }\n const parsed = schema.safeParse(value);\n if (!parsed.success || encodeCursorValue(value) !== raw) throw badRequest();\n return parsed.data;\n}\n\n/** One keyset boundary: timestamp, row id, and the liked sort's boundary count. */\nexport interface ForwardCursor {\n context: string;\n createdAt: string;\n id: string;\n likeCount?: number;\n}\n\nconst forwardCursorSchema: Schema<ForwardCursor> = s.object({\n context: s.string(),\n createdAt: isoTimestampSchema,\n id: uuidSchema,\n // Only the liked-sorted entry list carries a boundary count; every other list\n // omits the key entirely.\n likeCount: s.number().int().min(0).max(Number.MAX_SAFE_INTEGER).optional(),\n});\n\n/** Parses `limit` and the forward cursor from an already allow-listed parameter set. */\nexport function forwardPageParams(params: URLSearchParams, context: string) {\n const rawLimit = params.get('limit');\n const limit = rawLimit === null ? ARCHIVE_LIMITS.pageSize : Number(rawLimit);\n if (!Number.isInteger(limit) || limit < 1 || limit > ARCHIVE_LIMITS.maxPageSize) throw badRequest();\n const raw = params.get('cursor');\n const cursor = raw === null ? null : decodeCursorValue(raw, forwardCursorSchema);\n if (cursor !== null && cursor.context !== context) throw badRequest();\n return { cursor, limit };\n}\n\n/** Allow-lists the query, then parses `limit` and the forward cursor. */\nexport function forwardPage(request: Request, context: string, extra: readonly string[] = []) {\n const params = queryParams(new URL(request.url), ['cursor', 'limit', ...extra]);\n return { ...forwardPageParams(params, context), params };\n}\n\nexport const nextCursor = (cursor: Omit<ForwardCursor, 'context'>, context: string): string =>\n encodeCursorValue({ ...cursor, context });\n"],"mappings":"oLAYA,IAAa,kBAAqB,GAA2B,CAC3D,IAAM,EAAQ,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK,UAAU,CAAK,CAAC,EAC5D,OAAO,KAAK,MAAM,KAAK,EAAQ,GAAS,OAAO,aAAa,CAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CACzE,WAAW,IAAK,GAAG,CAAC,CACpB,WAAW,IAAK,GAAG,CAAC,CACpB,WAAW,IAAK,EAAE,CACvB,EAEA,SAAgB,kBAAqB,EAAa,EAAsB,CACtE,GAAI,EAAI,OAAS,EAAe,aAAe,CAAC,mBAAmB,KAAK,CAAG,EAAG,MAAM,EAAW,EAC/F,IAAI,EACJ,GAAI,CACF,IAAM,EAAS,EAAI,WAAW,IAAK,GAAG,CAAC,CAAC,WAAW,IAAK,GAAG,EACrD,EAAQ,WAAW,KAAK,KAAK,EAAS,IAAI,QAAQ,EAAK,EAAO,OAAS,GAAM,CAAC,CAAC,EAAI,GACvF,EAAK,WAAW,CAAC,CACnB,EACA,EAAQ,KAAK,MAAM,IAAI,YAAY,QAAS,CAAE,MAAO,EAAK,CAAC,CAAC,CAAC,OAAO,CAAK,CAAC,CAC5E,MAAQ,CACN,MAAM,EAAW,CACnB,CACA,IAAM,EAAS,EAAO,UAAU,CAAK,EACrC,GAAI,CAAC,EAAO,SAAW,kBAAkB,CAAK,IAAM,EAAK,MAAM,EAAW,EAC1E,OAAO,EAAO,IAChB,CAUA,IAAM,EAA6C,EAAE,OAAO,CAC1D,QAAS,EAAE,OAAO,EAClB,UAAW,EACX,GAAI,EAGJ,UAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAA2B,CAAC,CAAC,SAAS,CAC3E,CAAC,EAGD,SAAgB,kBAAkB,EAAyB,EAAiB,CAC1E,IAAM,EAAW,EAAO,IAAI,OAAO,EAC7B,EAAQ,IAAa,KAAO,EAAe,SAAW,OAAO,CAAQ,EAC3E,GAAI,CAAC,OAAO,UAAU,CAAK,GAAK,EAAQ,GAAK,EAAQ,EAAe,YAAa,MAAM,EAAW,EAClG,IAAM,EAAM,EAAO,IAAI,QAAQ,EACzB,EAAS,IAAQ,KAAO,KAAO,kBAAkB,EAAK,CAAmB,EAC/E,GAAI,IAAW,MAAQ,EAAO,UAAY,EAAS,MAAM,EAAW,EACpE,MAAO,CAAE,SAAQ,OAAM,CACzB,CAGA,SAAgB,YAAY,EAAkB,EAAiB,EAA2B,CAAC,EAAG,CAC5F,IAAM,EAAS,EAAY,IAAI,IAAI,EAAQ,GAAG,EAAG,CAAC,SAAU,QAAS,GAAG,CAAK,CAAC,EAC9E,MAAO,CAAE,GAAG,kBAAkB,EAAQ,CAAO,EAAG,QAAO,CACzD,CAEA,IAAa,YAAc,EAAwC,IACjE,kBAAkB,CAAE,GAAG,EAAQ,SAAQ,CAAC"}
@@ -0,0 +1,2 @@
1
+ async function serviceRequest(e,t,n){let r=new AbortController,i;try{return await Promise.race([e.fetch(new Request(t,{signal:r.signal})).then(n),new Promise((e,t)=>{i=setTimeout(()=>{r.abort(),t(Error(`Service request timed out.`))},5e3)})])}finally{i!==void 0&&clearTimeout(i)}}exports.serviceRequest=serviceRequest;
2
+ //# sourceMappingURL=_service.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_service.cjs","names":[],"sources":["../../src/worker/_service.ts"],"sourcesContent":["/** Bound the complete service exchange, including response-body decoding. */\nexport async function serviceRequest<T>(\n binding: { fetch(request: Request): Promise<Response> },\n request: Request,\n consume: (response: Response) => Promise<T>,\n): Promise<T> {\n const controller = new AbortController();\n let timer: ReturnType<typeof setTimeout> | undefined;\n try {\n return await Promise.race([\n binding.fetch(new Request(request, { signal: controller.signal })).then(consume),\n new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => {\n controller.abort();\n reject(new Error('Service request timed out.'));\n }, 5000);\n }),\n ]);\n } finally {\n if (timer !== undefined) clearTimeout(timer);\n }\n}\n"],"mappings":"AACA,eAAsB,eACpB,EACA,EACA,EACY,CACZ,IAAM,EAAa,IAAI,gBACnB,EACJ,GAAI,CACF,OAAO,MAAM,QAAQ,KAAK,CACxB,EAAQ,MAAM,IAAI,QAAQ,EAAS,CAAE,OAAQ,EAAW,MAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAO,EAC/E,IAAI,SAAgB,EAAU,IAAW,CACvC,EAAQ,eAAiB,CACvB,EAAW,MAAM,EACjB,EAAW,MAAM,4BAA4B,CAAC,CAChD,EAAG,GAAI,CACT,CAAC,CACH,CAAC,CACH,QAAU,CACJ,IAAU,IAAA,IAAW,aAAa,CAAK,CAC7C,CACF"}
@@ -0,0 +1,5 @@
1
+ /** Bound the complete service exchange, including response-body decoding. */
2
+ export declare function serviceRequest<T>(binding: {
3
+ fetch(request: Request): Promise<Response>;
4
+ }, request: Request, consume: (response: Response) => Promise<T>): Promise<T>;
5
+ //# sourceMappingURL=_service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_service.d.ts","sourceRoot":"","sources":["../../src/worker/_service.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wBAAsB,cAAc,CAAC,CAAC,EACpC,OAAO,EAAE;IAAE,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAAE,EACvD,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,GAC1C,OAAO,CAAC,CAAC,CAAC,CAgBZ"}
@@ -0,0 +1,2 @@
1
+ async function serviceRequest(e,t,n){let r=new AbortController,i;try{return await Promise.race([e.fetch(new Request(t,{signal:r.signal})).then(n),new Promise((e,t)=>{i=setTimeout(()=>{r.abort(),t(Error(`Service request timed out.`))},5e3)})])}finally{i!==void 0&&clearTimeout(i)}}export{serviceRequest};
2
+ //# sourceMappingURL=_service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_service.js","names":[],"sources":["../../src/worker/_service.ts"],"sourcesContent":["/** Bound the complete service exchange, including response-body decoding. */\nexport async function serviceRequest<T>(\n binding: { fetch(request: Request): Promise<Response> },\n request: Request,\n consume: (response: Response) => Promise<T>,\n): Promise<T> {\n const controller = new AbortController();\n let timer: ReturnType<typeof setTimeout> | undefined;\n try {\n return await Promise.race([\n binding.fetch(new Request(request, { signal: controller.signal })).then(consume),\n new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => {\n controller.abort();\n reject(new Error('Service request timed out.'));\n }, 5000);\n }),\n ]);\n } finally {\n if (timer !== undefined) clearTimeout(timer);\n }\n}\n"],"mappings":"AACA,eAAsB,eACpB,EACA,EACA,EACY,CACZ,IAAM,EAAa,IAAI,gBACnB,EACJ,GAAI,CACF,OAAO,MAAM,QAAQ,KAAK,CACxB,EAAQ,MAAM,IAAI,QAAQ,EAAS,CAAE,OAAQ,EAAW,MAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAO,EAC/E,IAAI,SAAgB,EAAU,IAAW,CACvC,EAAQ,eAAiB,CACvB,EAAW,MAAM,EACjB,EAAW,MAAM,4BAA4B,CAAC,CAChD,EAAG,GAAI,CACT,CAAC,CACH,CAAC,CACH,QAAU,CACJ,IAAU,IAAA,IAAW,aAAa,CAAK,CAC7C,CACF"}
@@ -0,0 +1,2 @@
1
+ const e=require("../contract.cjs"),t=require("./_service.cjs"),n=require("./http.cjs"),r=require("./sql.cjs");let i=require("jose");var a=e.SESSION_MAX_AGE_SECONDS,o=256,authUnavailable=()=>new n.ApiError(503,`auth-unavailable`,`Sign-in is currently unavailable.`);async function verifySession(s,c,l,u=!1){let d=n.sessionToken(s);if(d===null)return null;let f;try{f=(await(0,i.jwtVerify)(d,c.jwks,{algorithms:[`RS256`],audience:c.audience,clockTolerance:5,issuer:c.issuer,maxTokenAge:a,requiredClaims:[`sub`,`iss`,`aud`,`iat`,`exp`,`sessionVersion`]})).payload}catch(e){throw e instanceof i.errors.JWKSTimeout||e instanceof i.errors.JWKSInvalid||e instanceof i.errors.JWKSMultipleMatchingKeys?authUnavailable():e instanceof i.errors.JOSEError?n.unauthenticated():authUnavailable()}let p=f.sub,m=f.iss,h=f.iat,g=f.roles;if(!Number.isSafeInteger(f.sessionVersion)||f.sessionVersion<0)throw n.unauthenticated();let _=Array.isArray(g)&&g.includes(`archive-operator`);if(typeof p!=`string`||p.length===0||p.length>o||!e.isWellFormedText(p)||typeof m!=`string`||typeof h==`number`&&h*1e3>Date.now()+5e3||_&&(typeof h!=`number`||typeof f.exp!=`number`||f.exp-h>900||Date.now()/1e3-h>905))throw n.unauthenticated();if(!(u&&await l.DB.prepare(r.SQL.revokedSubject).bind(m,p,Date.now()).first()!==null))try{await t.serviceRequest(l.AUTH_ISSUER_SERVICE,new Request(new URL(`/api/v1/auth/session`,c.issuer),{headers:{cookie:`archive_session=${d}`},redirect:`manual`}),async t=>{let r=await t.json();if(t.status===200&&e.archiveOkSchema.safeParse(r).success)return;let i=e.archiveErrorResponseSchema.safeParse(r);throw t.status===401&&i.success&&i.data.error.code===`unauthenticated`?n.unauthenticated():authUnavailable()})}catch(e){throw e instanceof n.ApiError&&e.status===401?e:authUnavailable()}if(!u&&await l.DB.prepare(r.SQL.revokedSubject).bind(m,p,Date.now()).first()!==null)throw n.unauthenticated();let v=await l.DB.prepare(r.SQL.publisher).bind(m,p).first();return{operator:_,publisher:v===null?null:{displayName:v.display_name,id:v.id},subject:{issuer:m,subject:p}}}function requireSession(e){if(e===null)throw n.unauthenticated();return e}exports.requireSession=requireSession,exports.verifySession=verifySession;
2
+ //# sourceMappingURL=auth.cjs.map