was-teaching-server 0.9.1

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 (295) hide show
  1. package/CHANGELOG.md +1432 -0
  2. package/LICENSE +661 -0
  3. package/README.md +305 -0
  4. package/common/css/materialize.1.0.0.min.css +13 -0
  5. package/dist/auth-header-hooks.d.ts +84 -0
  6. package/dist/auth-header-hooks.d.ts.map +1 -0
  7. package/dist/auth-header-hooks.js +136 -0
  8. package/dist/auth-header-hooks.js.map +1 -0
  9. package/dist/authorize.d.ts +45 -0
  10. package/dist/authorize.d.ts.map +1 -0
  11. package/dist/authorize.js +76 -0
  12. package/dist/authorize.js.map +1 -0
  13. package/dist/backends/filesystem.d.ts +1179 -0
  14. package/dist/backends/filesystem.d.ts.map +1 -0
  15. package/dist/backends/filesystem.js +2727 -0
  16. package/dist/backends/filesystem.js.map +1 -0
  17. package/dist/backends/postgres.d.ts +833 -0
  18. package/dist/backends/postgres.d.ts.map +1 -0
  19. package/dist/backends/postgres.js +2164 -0
  20. package/dist/backends/postgres.js.map +1 -0
  21. package/dist/backends/postgresSchema.d.ts +36 -0
  22. package/dist/backends/postgresSchema.d.ts.map +1 -0
  23. package/dist/backends/postgresSchema.js +203 -0
  24. package/dist/backends/postgresSchema.js.map +1 -0
  25. package/dist/config.default.d.ts +360 -0
  26. package/dist/config.default.d.ts.map +1 -0
  27. package/dist/config.default.js +493 -0
  28. package/dist/config.default.js.map +1 -0
  29. package/dist/corsProxy.d.ts +45 -0
  30. package/dist/corsProxy.d.ts.map +1 -0
  31. package/dist/corsProxy.js +278 -0
  32. package/dist/corsProxy.js.map +1 -0
  33. package/dist/digest.d.ts +45 -0
  34. package/dist/digest.d.ts.map +1 -0
  35. package/dist/digest.js +174 -0
  36. package/dist/digest.js.map +1 -0
  37. package/dist/errors.d.ts +654 -0
  38. package/dist/errors.d.ts.map +1 -0
  39. package/dist/errors.js +960 -0
  40. package/dist/errors.js.map +1 -0
  41. package/dist/index.d.ts +22 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +21 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/lib/atomicFile.d.ts +61 -0
  46. package/dist/lib/atomicFile.d.ts.map +1 -0
  47. package/dist/lib/atomicFile.js +150 -0
  48. package/dist/lib/atomicFile.js.map +1 -0
  49. package/dist/lib/backendRegistry.d.ts +59 -0
  50. package/dist/lib/backendRegistry.d.ts.map +1 -0
  51. package/dist/lib/backendRegistry.js +92 -0
  52. package/dist/lib/backendRegistry.js.map +1 -0
  53. package/dist/lib/backendUsage.d.ts +28 -0
  54. package/dist/lib/backendUsage.d.ts.map +1 -0
  55. package/dist/lib/backendUsage.js +55 -0
  56. package/dist/lib/backendUsage.js.map +1 -0
  57. package/dist/lib/backends.d.ts +142 -0
  58. package/dist/lib/backends.d.ts.map +1 -0
  59. package/dist/lib/backends.js +272 -0
  60. package/dist/lib/backends.js.map +1 -0
  61. package/dist/lib/blindedIndex.d.ts +156 -0
  62. package/dist/lib/blindedIndex.d.ts.map +1 -0
  63. package/dist/lib/blindedIndex.js +338 -0
  64. package/dist/lib/blindedIndex.js.map +1 -0
  65. package/dist/lib/collectionDescription.d.ts +33 -0
  66. package/dist/lib/collectionDescription.d.ts.map +1 -0
  67. package/dist/lib/collectionDescription.js +21 -0
  68. package/dist/lib/collectionDescription.js.map +1 -0
  69. package/dist/lib/cursor.d.ts +18 -0
  70. package/dist/lib/cursor.d.ts.map +1 -0
  71. package/dist/lib/cursor.js +50 -0
  72. package/dist/lib/cursor.js.map +1 -0
  73. package/dist/lib/edvEnvelope.d.ts +50 -0
  74. package/dist/lib/edvEnvelope.d.ts.map +1 -0
  75. package/dist/lib/edvEnvelope.js +106 -0
  76. package/dist/lib/edvEnvelope.js.map +1 -0
  77. package/dist/lib/encryption.d.ts +192 -0
  78. package/dist/lib/encryption.d.ts.map +1 -0
  79. package/dist/lib/encryption.js +383 -0
  80. package/dist/lib/encryption.js.map +1 -0
  81. package/dist/lib/etag.d.ts +33 -0
  82. package/dist/lib/etag.d.ts.map +1 -0
  83. package/dist/lib/etag.js +36 -0
  84. package/dist/lib/etag.js.map +1 -0
  85. package/dist/lib/exportManifest.d.ts +29 -0
  86. package/dist/lib/exportManifest.d.ts.map +1 -0
  87. package/dist/lib/exportManifest.js +77 -0
  88. package/dist/lib/exportManifest.js.map +1 -0
  89. package/dist/lib/importTar.d.ts +81 -0
  90. package/dist/lib/importTar.d.ts.map +1 -0
  91. package/dist/lib/importTar.js +301 -0
  92. package/dist/lib/importTar.js.map +1 -0
  93. package/dist/lib/isJson.d.ts +16 -0
  94. package/dist/lib/isJson.d.ts.map +1 -0
  95. package/dist/lib/isJson.js +17 -0
  96. package/dist/lib/isJson.js.map +1 -0
  97. package/dist/lib/keyEpoch.d.ts +38 -0
  98. package/dist/lib/keyEpoch.d.ts.map +1 -0
  99. package/dist/lib/keyEpoch.js +75 -0
  100. package/dist/lib/keyEpoch.js.map +1 -0
  101. package/dist/lib/keyedMutex.d.ts +28 -0
  102. package/dist/lib/keyedMutex.d.ts.map +1 -0
  103. package/dist/lib/keyedMutex.js +45 -0
  104. package/dist/lib/keyedMutex.js.map +1 -0
  105. package/dist/lib/kmsModule.d.ts +62 -0
  106. package/dist/lib/kmsModule.d.ts.map +1 -0
  107. package/dist/lib/kmsModule.js +327 -0
  108. package/dist/lib/kmsModule.js.map +1 -0
  109. package/dist/lib/kmsRecordCipher.d.ts +82 -0
  110. package/dist/lib/kmsRecordCipher.d.ts.map +1 -0
  111. package/dist/lib/kmsRecordCipher.js +226 -0
  112. package/dist/lib/kmsRecordCipher.js.map +1 -0
  113. package/dist/lib/pagination.d.ts +19 -0
  114. package/dist/lib/pagination.d.ts.map +1 -0
  115. package/dist/lib/pagination.js +21 -0
  116. package/dist/lib/pagination.js.map +1 -0
  117. package/dist/lib/paths.d.ts +273 -0
  118. package/dist/lib/paths.d.ts.map +1 -0
  119. package/dist/lib/paths.js +270 -0
  120. package/dist/lib/paths.js.map +1 -0
  121. package/dist/lib/preconditions.d.ts +65 -0
  122. package/dist/lib/preconditions.d.ts.map +1 -0
  123. package/dist/lib/preconditions.js +112 -0
  124. package/dist/lib/preconditions.js.map +1 -0
  125. package/dist/lib/resourceFileName.d.ts +41 -0
  126. package/dist/lib/resourceFileName.d.ts.map +1 -0
  127. package/dist/lib/resourceFileName.js +58 -0
  128. package/dist/lib/resourceFileName.js.map +1 -0
  129. package/dist/lib/revocations.d.ts +49 -0
  130. package/dist/lib/revocations.d.ts.map +1 -0
  131. package/dist/lib/revocations.js +86 -0
  132. package/dist/lib/revocations.js.map +1 -0
  133. package/dist/lib/validateDid.d.ts +19 -0
  134. package/dist/lib/validateDid.d.ts.map +1 -0
  135. package/dist/lib/validateDid.js +35 -0
  136. package/dist/lib/validateDid.js.map +1 -0
  137. package/dist/lib/validateId.d.ts +66 -0
  138. package/dist/lib/validateId.d.ts.map +1 -0
  139. package/dist/lib/validateId.js +126 -0
  140. package/dist/lib/validateId.js.map +1 -0
  141. package/dist/plugin.d.ts +115 -0
  142. package/dist/plugin.d.ts.map +1 -0
  143. package/dist/plugin.js +134 -0
  144. package/dist/plugin.js.map +1 -0
  145. package/dist/policy.d.ts +78 -0
  146. package/dist/policy.d.ts.map +1 -0
  147. package/dist/policy.js +115 -0
  148. package/dist/policy.js.map +1 -0
  149. package/dist/provisioning.d.ts +38 -0
  150. package/dist/provisioning.d.ts.map +1 -0
  151. package/dist/provisioning.js +72 -0
  152. package/dist/provisioning.js.map +1 -0
  153. package/dist/requests/BackendRequest.d.ts +61 -0
  154. package/dist/requests/BackendRequest.d.ts.map +1 -0
  155. package/dist/requests/BackendRequest.js +152 -0
  156. package/dist/requests/BackendRequest.js.map +1 -0
  157. package/dist/requests/CollectionRequest.d.ts +234 -0
  158. package/dist/requests/CollectionRequest.d.ts.map +1 -0
  159. package/dist/requests/CollectionRequest.js +705 -0
  160. package/dist/requests/CollectionRequest.js.map +1 -0
  161. package/dist/requests/KeyRequest.d.ts +115 -0
  162. package/dist/requests/KeyRequest.d.ts.map +1 -0
  163. package/dist/requests/KeyRequest.js +468 -0
  164. package/dist/requests/KeyRequest.js.map +1 -0
  165. package/dist/requests/KeystoreRequest.d.ts +99 -0
  166. package/dist/requests/KeystoreRequest.d.ts.map +1 -0
  167. package/dist/requests/KeystoreRequest.js +247 -0
  168. package/dist/requests/KeystoreRequest.js.map +1 -0
  169. package/dist/requests/PolicyRequest.d.ts +53 -0
  170. package/dist/requests/PolicyRequest.d.ts.map +1 -0
  171. package/dist/requests/PolicyRequest.js +124 -0
  172. package/dist/requests/PolicyRequest.js.map +1 -0
  173. package/dist/requests/ResourceRequest.d.ts +134 -0
  174. package/dist/requests/ResourceRequest.d.ts.map +1 -0
  175. package/dist/requests/ResourceRequest.js +548 -0
  176. package/dist/requests/ResourceRequest.js.map +1 -0
  177. package/dist/requests/RevocationRequest.d.ts +67 -0
  178. package/dist/requests/RevocationRequest.d.ts.map +1 -0
  179. package/dist/requests/RevocationRequest.js +187 -0
  180. package/dist/requests/RevocationRequest.js.map +1 -0
  181. package/dist/requests/SpaceRequest.d.ts +204 -0
  182. package/dist/requests/SpaceRequest.d.ts.map +1 -0
  183. package/dist/requests/SpaceRequest.js +520 -0
  184. package/dist/requests/SpaceRequest.js.map +1 -0
  185. package/dist/requests/SpacesRepositoryRequest.d.ts +50 -0
  186. package/dist/requests/SpacesRepositoryRequest.d.ts.map +1 -0
  187. package/dist/requests/SpacesRepositoryRequest.js +159 -0
  188. package/dist/requests/SpacesRepositoryRequest.js.map +1 -0
  189. package/dist/requests/collectionContext.d.ts +21 -0
  190. package/dist/requests/collectionContext.d.ts.map +1 -0
  191. package/dist/requests/collectionContext.js +30 -0
  192. package/dist/requests/collectionContext.js.map +1 -0
  193. package/dist/requests/controllerConsent.d.ts +58 -0
  194. package/dist/requests/controllerConsent.d.ts.map +1 -0
  195. package/dist/requests/controllerConsent.js +73 -0
  196. package/dist/requests/controllerConsent.js.map +1 -0
  197. package/dist/requests/keystoreContext.d.ts +68 -0
  198. package/dist/requests/keystoreContext.d.ts.map +1 -0
  199. package/dist/requests/keystoreContext.js +87 -0
  200. package/dist/requests/keystoreContext.js.map +1 -0
  201. package/dist/requests/resourceInput.d.ts +19 -0
  202. package/dist/requests/resourceInput.d.ts.map +1 -0
  203. package/dist/requests/resourceInput.js +102 -0
  204. package/dist/requests/resourceInput.js.map +1 -0
  205. package/dist/requests/spaceContext.d.ts +127 -0
  206. package/dist/requests/spaceContext.d.ts.map +1 -0
  207. package/dist/requests/spaceContext.js +201 -0
  208. package/dist/requests/spaceContext.js.map +1 -0
  209. package/dist/routes.d.ts +55 -0
  210. package/dist/routes.d.ts.map +1 -0
  211. package/dist/routes.js +306 -0
  212. package/dist/routes.js.map +1 -0
  213. package/dist/server.d.ts +20 -0
  214. package/dist/server.d.ts.map +1 -0
  215. package/dist/server.js +60 -0
  216. package/dist/server.js.map +1 -0
  217. package/dist/start.d.ts +7 -0
  218. package/dist/start.d.ts.map +1 -0
  219. package/dist/start.js +61 -0
  220. package/dist/start.js.map +1 -0
  221. package/dist/storage.d.ts +29 -0
  222. package/dist/storage.d.ts.map +1 -0
  223. package/dist/storage.js +47 -0
  224. package/dist/storage.js.map +1 -0
  225. package/dist/types.d.ts +915 -0
  226. package/dist/types.d.ts.map +1 -0
  227. package/dist/types.js +2 -0
  228. package/dist/types.js.map +1 -0
  229. package/dist/views/home.hbs +9 -0
  230. package/dist/views/templates/main.hbs +12 -0
  231. package/dist/zcap.d.ts +267 -0
  232. package/dist/zcap.d.ts.map +1 -0
  233. package/dist/zcap.js +478 -0
  234. package/dist/zcap.js.map +1 -0
  235. package/package.json +109 -0
  236. package/src/auth-header-hooks.ts +163 -0
  237. package/src/authorize.ts +117 -0
  238. package/src/backends/filesystem.ts +3626 -0
  239. package/src/backends/postgres.ts +3073 -0
  240. package/src/backends/postgresSchema.ts +231 -0
  241. package/src/config.default.ts +657 -0
  242. package/src/corsProxy.ts +326 -0
  243. package/src/declarations.d.ts +28 -0
  244. package/src/digest.ts +223 -0
  245. package/src/errors.ts +1122 -0
  246. package/src/index.ts +21 -0
  247. package/src/lib/atomicFile.ts +176 -0
  248. package/src/lib/backendRegistry.ts +139 -0
  249. package/src/lib/backendUsage.ts +79 -0
  250. package/src/lib/backends.ts +351 -0
  251. package/src/lib/blindedIndex.ts +466 -0
  252. package/src/lib/collectionDescription.ts +43 -0
  253. package/src/lib/cursor.ts +52 -0
  254. package/src/lib/edvEnvelope.ts +120 -0
  255. package/src/lib/encryption.ts +472 -0
  256. package/src/lib/etag.ts +40 -0
  257. package/src/lib/exportManifest.ts +115 -0
  258. package/src/lib/importTar.ts +381 -0
  259. package/src/lib/isJson.ts +18 -0
  260. package/src/lib/keyEpoch.ts +89 -0
  261. package/src/lib/keyedMutex.ts +45 -0
  262. package/src/lib/kmsModule.ts +451 -0
  263. package/src/lib/kmsRecordCipher.ts +292 -0
  264. package/src/lib/pagination.ts +22 -0
  265. package/src/lib/paths.ts +382 -0
  266. package/src/lib/preconditions.ts +145 -0
  267. package/src/lib/resourceFileName.ts +69 -0
  268. package/src/lib/revocations.ts +116 -0
  269. package/src/lib/validateDid.ts +41 -0
  270. package/src/lib/validateId.ts +148 -0
  271. package/src/plugin.ts +288 -0
  272. package/src/policy.ts +176 -0
  273. package/src/provisioning.ts +98 -0
  274. package/src/requests/BackendRequest.ts +219 -0
  275. package/src/requests/CollectionRequest.ts +899 -0
  276. package/src/requests/KeyRequest.ts +617 -0
  277. package/src/requests/KeystoreRequest.ts +325 -0
  278. package/src/requests/PolicyRequest.ts +169 -0
  279. package/src/requests/ResourceRequest.ts +649 -0
  280. package/src/requests/RevocationRequest.ts +267 -0
  281. package/src/requests/SpaceRequest.ts +686 -0
  282. package/src/requests/SpacesRepositoryRequest.ts +194 -0
  283. package/src/requests/collectionContext.ts +41 -0
  284. package/src/requests/controllerConsent.ts +108 -0
  285. package/src/requests/keystoreContext.ts +124 -0
  286. package/src/requests/resourceInput.ts +118 -0
  287. package/src/requests/spaceContext.ts +311 -0
  288. package/src/routes.ts +420 -0
  289. package/src/server.ts +69 -0
  290. package/src/start.ts +71 -0
  291. package/src/storage.ts +60 -0
  292. package/src/types.ts +1016 -0
  293. package/src/views/home.hbs +9 -0
  294. package/src/views/templates/main.hbs +12 -0
  295. package/src/zcap.ts +657 -0
@@ -0,0 +1,360 @@
1
+ import type { KmsRecordKekRegistry } from './types.js';
2
+ /** Server version, read from package.json at startup. */
3
+ export declare const SERVER_VERSION: string;
4
+ /**
5
+ * Space Description cache (see src/requests/spaceContext.ts). The description is
6
+ * read on every authorized handler, so it is memoized per storage backend.
7
+ * Writes invalidate the entry explicitly; the short TTL is a backstop that also
8
+ * bounds staleness when several server processes share one storage backend (so
9
+ * one process's cache cannot serve another process's write indefinitely).
10
+ */
11
+ export declare const SPACE_DESCRIPTION_CACHE_TTL = 5000;
12
+ /** Max number of Space Descriptions held per backend cache (LRU-bounded). */
13
+ export declare const SPACE_DESCRIPTION_CACHE_MAX = 1000;
14
+ /**
15
+ * Max number of resolved external-backend adapters held per provider-registry
16
+ * cache (see src/lib/backendRegistry.ts), LRU-bounded. One adapter instance is
17
+ * memoized per selected `{spaceId}/{backendId}` and reused across requests;
18
+ * record changes bust the entry explicitly (no TTL backstop is needed because
19
+ * the provider registry itself is fixed for an instance's lifetime).
20
+ */
21
+ export declare const RESOLVED_BACKEND_CACHE_MAX = 1000;
22
+ /**
23
+ * Linkset relation URI for the access-control `policy` auxiliary resource
24
+ * (RFC9264 linkset discovery; see src/policy.ts and the linkset handlers).
25
+ */
26
+ export declare const POLICY_LINK_RELATION = "https://wallet.storage/spec#policy";
27
+ /**
28
+ * Linkset relation URI for a Collection's selected `backend` auxiliary resource
29
+ * (RFC9264 linkset discovery; advertised at `/space/{id}/{cid}/backend`).
30
+ */
31
+ export declare const BACKEND_LINK_RELATION = "https://wallet.storage/spec#backend";
32
+ /**
33
+ * Linkset relation URI for a Collection's `quota` report auxiliary resource
34
+ * (RFC9264 linkset discovery; advertised at `/space/{id}/{cid}/quota`).
35
+ */
36
+ export declare const QUOTA_LINK_RELATION = "https://wallet.storage/spec#quota";
37
+ /**
38
+ * Linkset relation URI for a Space's `backends-available` auxiliary resource
39
+ * (RFC9264 linkset discovery; advertised at `/space/{id}/backends`).
40
+ */
41
+ export declare const BACKENDS_AVAILABLE_LINK_RELATION = "https://wallet.storage/spec#backends-available";
42
+ /**
43
+ * Linkset relation URI for a Space's `quotas` report auxiliary resource
44
+ * (RFC9264 linkset discovery; advertised at `/space/{id}/quotas`).
45
+ */
46
+ export declare const QUOTAS_LINK_RELATION = "https://wallet.storage/spec#quotas";
47
+ /**
48
+ * Fraction of a backend's configured capacity at or above which its quota
49
+ * report `state` becomes `near-limit` (spec "Quotas"). Below this it is `ok`;
50
+ * at or above full capacity it is `over-quota`. Only applies when a finite
51
+ * capacity is configured (an unlimited backend is always `ok`).
52
+ */
53
+ export declare const QUOTA_NEAR_LIMIT_FRACTION = 0.9;
54
+ /**
55
+ * Write-path quota usage cache TTL (see
56
+ * `FileSystemBackend._assertSpaceHeadroom`). The quota pre-flight measures a
57
+ * Space's on-disk usage with `du`, which walks the whole Space tree -- too
58
+ * costly to repeat on every resource write. The measured total is cached per
59
+ * Space for this long, with each accepted write's incoming bytes added to the
60
+ * cached figure; deletes invalidate the entry. The TTL bounds the drift of
61
+ * that optimistic accounting (overwrites that replaced rather than added
62
+ * bytes, streamed bodies of undeclared size) -- the quota is a documented
63
+ * soft limit, and the TTL bounds the re-measurement window.
64
+ */
65
+ export declare const QUOTA_USAGE_CACHE_TTL = 5000;
66
+ /**
67
+ * The single in-process KMS module this server hard-wires.
68
+ * A keystore created without one gets this alias, and it is immutable thereafter.
69
+ */
70
+ export declare const DEFAULT_KMS_MODULE = "local-v1";
71
+ /**
72
+ * Max keystore configs returned by `GET /kms/keystores?controller=...` (the
73
+ * webkms protocol's list cap).
74
+ */
75
+ export declare const KEYSTORE_LIST_LIMIT = 100;
76
+ /**
77
+ * Max key descriptions returned per page by
78
+ * `GET /kms/keystores/:keystoreId/keys` (the List Keys fork extension). A
79
+ * further page is signalled by the response's `next` cursor URL; realistic
80
+ * keystores hold a handful of keys, so one page is the steady state.
81
+ */
82
+ export declare const KEY_LIST_LIMIT = 100;
83
+ /**
84
+ * Max capability delegation chain length accepted on `/kms` invocations, the
85
+ * root capability included (webkms-switch's `maxChainLength` default). A
86
+ * per-key `maxCapabilityChainLength` (1-10, set at generate time) may narrow
87
+ * this further for key operations; it can never widen it.
88
+ */
89
+ export declare const KMS_MAX_CHAIN_LENGTH = 10;
90
+ /**
91
+ * Max time-to-live of a delegated capability accepted on `/kms` invocations,
92
+ * measured `expires` minus the delegation proof's `created`, in milliseconds
93
+ * (90 days -- webkms-switch's `maxDelegationTtl` default). One unified bound
94
+ * for every `/kms` route family:
95
+ * revocation plus the mandatory `expires` is the real control.
96
+ */
97
+ export declare const KMS_MAX_DELEGATION_TTL: number;
98
+ /** TCP port the server listens on when `PORT` is unset. */
99
+ export declare const DEFAULT_PORT = 3002;
100
+ /**
101
+ * The default per-upload byte cap applied by BOTH backends when
102
+ * `MAX_UPLOAD_BYTES` is unset (a default-on limit, 64 MiB). Every blob write
103
+ * buffers through process memory on at least one path (the Postgres single
104
+ * `bytea`, multipart's in-memory `toBuffer()`), so "no cap" would be a footgun.
105
+ * Opt out explicitly with `MAX_UPLOAD_BYTES=unlimited`, which the backends
106
+ * accept only where an unbounded upload is actually safe (the filesystem
107
+ * streaming path; the Postgres backend rejects it at construction).
108
+ */
109
+ export declare const DEFAULT_MAX_UPLOAD_BYTES: number;
110
+ /**
111
+ * Default cap on the number of Spaces a single controller may create, applied
112
+ * by BOTH backends when `MAX_SPACES_PER_CONTROLLER` is unset (a default-on
113
+ * count quota). Chosen far above any teaching or conformance workload while
114
+ * still bounding runaway creation by one controller. Opt out with
115
+ * `MAX_SPACES_PER_CONTROLLER=unlimited`.
116
+ */
117
+ export declare const DEFAULT_MAX_SPACES_PER_CONTROLLER = 100;
118
+ /**
119
+ * Default cap on the number of Collections a single Space may hold, applied by
120
+ * BOTH backends when `MAX_COLLECTIONS_PER_SPACE` is unset (a default-on count
121
+ * quota). Opt out with `MAX_COLLECTIONS_PER_SPACE=unlimited`.
122
+ */
123
+ export declare const DEFAULT_MAX_COLLECTIONS_PER_SPACE = 100;
124
+ /**
125
+ * Default cap on the number of live Resources a single Space may hold across
126
+ * all its Collections, applied by BOTH backends when `MAX_RESOURCES_PER_SPACE`
127
+ * is unset (a default-on count quota). A tombstone (soft-deleted Resource) does
128
+ * not count against it. Opt out with `MAX_RESOURCES_PER_SPACE=unlimited`.
129
+ */
130
+ export declare const DEFAULT_MAX_RESOURCES_PER_SPACE = 10000;
131
+ /**
132
+ * The validated env-derived server configuration returned by
133
+ * {@link loadConfigFromEnv} and consumed by `start.ts`.
134
+ */
135
+ export interface EnvConfig {
136
+ /** The server base URL (`SERVER_URL`); required, validated. */
137
+ serverUrl: string;
138
+ /** TCP port to listen on (`PORT`); defaults to {@link DEFAULT_PORT}. */
139
+ port: number;
140
+ /** Postgres connection string (`DATABASE_URL`); unset selects the filesystem backend. */
141
+ databaseUrl?: string;
142
+ /**
143
+ * Per-Space storage quota in bytes (`STORAGE_LIMIT_PER_SPACE`). `undefined`
144
+ * means unset -- unlimited, but `start.ts` warns to prompt an explicit
145
+ * choice; `Infinity` means `unlimited` was set explicitly (no warning).
146
+ */
147
+ storageLimitPerSpace?: number;
148
+ /**
149
+ * Per-upload size cap in bytes (`MAX_UPLOAD_BYTES`). `undefined` means unset
150
+ * -- the backends apply the {@link DEFAULT_MAX_UPLOAD_BYTES} default;
151
+ * `Infinity` means `unlimited` was set explicitly (no per-upload cap).
152
+ */
153
+ maxUploadBytes?: number;
154
+ /**
155
+ * Max Spaces a single controller may create (`MAX_SPACES_PER_CONTROLLER`).
156
+ * `undefined` means unset -- the backends apply the
157
+ * {@link DEFAULT_MAX_SPACES_PER_CONTROLLER} default; `Infinity` means
158
+ * `unlimited` was set explicitly (no cap).
159
+ */
160
+ maxSpacesPerController?: number;
161
+ /**
162
+ * Max Collections a single Space may hold (`MAX_COLLECTIONS_PER_SPACE`).
163
+ * `undefined` means unset -- the backends apply the
164
+ * {@link DEFAULT_MAX_COLLECTIONS_PER_SPACE} default; `Infinity` means
165
+ * `unlimited` was set explicitly (no cap).
166
+ */
167
+ maxCollectionsPerSpace?: number;
168
+ /**
169
+ * Max live Resources a single Space may hold across all its Collections
170
+ * (`MAX_RESOURCES_PER_SPACE`). `undefined` means unset -- the backends apply
171
+ * the {@link DEFAULT_MAX_RESOURCES_PER_SPACE} default; `Infinity` means
172
+ * `unlimited` was set explicitly (no cap).
173
+ */
174
+ maxResourcesPerSpace?: number;
175
+ /** Backend registration allowlist (`WAS_ENABLED_BACKENDS`); unset = permissive. */
176
+ enabledBackendProviders?: string[];
177
+ /**
178
+ * At-rest KMS key-record encryption registry (`KMS_RECORD_KEK` /
179
+ * `KMS_RECORD_KEKS` / `KMS_RECORD_CURRENT_KEK`); unset = plaintext.
180
+ */
181
+ kmsRecordKek?: KmsRecordKekRegistry;
182
+ /** Shared-secret provisioning gate (`WAS_ONBOARDING_TOKEN`); unset = open provisioning. */
183
+ onboardingToken?: string;
184
+ }
185
+ /**
186
+ * Reads and validates the server's whole env config surface in one place
187
+ * (fail-fast startup): a missing `SERVER_URL` or any malformed value throws
188
+ * with the offending variable named, before the server starts listening --
189
+ * instead of silently breaking ZCap matching at request time.
190
+ * @param [env] {NodeJS.ProcessEnv} defaults to `process.env`
191
+ * @returns {EnvConfig}
192
+ */
193
+ export declare function loadConfigFromEnv(env?: NodeJS.ProcessEnv): EnvConfig;
194
+ /**
195
+ * Validates a server base URL (the `serverUrl` option / `SERVER_URL` env
196
+ * value): it must be an absolute `http:`/`https:` URL with no path, query, or
197
+ * fragment. ZCap `invocationTarget` URLs and `Location` headers are built by
198
+ * resolving absolute paths against this base (`new URL(path, serverUrl)`),
199
+ * which silently drops any base path -- so a sub-path deployment would break
200
+ * every delegated invocation. Rejected at startup instead (fail-fast).
201
+ * @param serverUrl {string} the candidate base URL
202
+ * @returns {void} throws on an invalid value
203
+ */
204
+ export declare function assertValidServerUrl(serverUrl: string): void;
205
+ /**
206
+ * Parses the `SERVER_URL` env value: the server's base URL, used to build and
207
+ * match ZCap `invocationTarget` URLs (host and port must match the client's
208
+ * exactly). Required -- unset would silently break all ZCap matching, so
209
+ * startup fails instead. The value is trimmed but otherwise preserved
210
+ * byte-for-byte (never normalized), since capability targets compare as exact
211
+ * strings. Validated by {@link assertValidServerUrl}.
212
+ * @param raw {string|undefined} the raw env value
213
+ * @returns {string} the trimmed, validated base URL
214
+ */
215
+ export declare function parseServerUrl(raw: string | undefined): string;
216
+ /**
217
+ * Parses the `PORT` env value into the TCP port to listen on. An unset or
218
+ * empty value returns {@link DEFAULT_PORT}.
219
+ * @param raw {string|undefined} the raw env value
220
+ * @returns {number} the port
221
+ */
222
+ export declare function parsePort(raw: string | undefined): number;
223
+ /**
224
+ * Parses the `DATABASE_URL` env value: a Postgres connection string that,
225
+ * when set, selects the PostgreSQL storage backend (unset keeps the default
226
+ * filesystem backend). The string's shape is left to the `pg` driver, which
227
+ * accepts several connection-string forms; an unset or empty value returns
228
+ * `undefined`.
229
+ * @param raw {string|undefined} the raw env value
230
+ * @returns {string|undefined} the trimmed connection string, or `undefined`
231
+ */
232
+ export declare function parseDatabaseUrl(raw: string | undefined): string | undefined;
233
+ /**
234
+ * Parses the at-rest key-record encryption env surface into a
235
+ * {@link KmsRecordKekRegistry} (the optional hardening increment). Each KEK is a
236
+ * single AES-256 key-encryption key in base58btc Multikey form
237
+ * (`secretKeyMultibase`, header `0xa2 0x01`), whose id is derived from its
238
+ * material (`deriveKekId`) and stored per record -- so registering a second KEK
239
+ * for rotation is a config change, not a schema migration. Three env variables
240
+ * feed it:
241
+ *
242
+ * - `KMS_RECORD_KEK` -- a single KEK (the teaching default alias);
243
+ * - `KMS_RECORD_KEKS` -- a comma-separated list of KEKs, each registered by its
244
+ * derived id; the FIRST entry is the current KEK by default, so a rotation is
245
+ * "prepend the new KEK, keep the old one behind it". Surrounding whitespace is
246
+ * trimmed and empty entries ignored; a duplicate entry (same derived id twice)
247
+ * throws;
248
+ * - `KMS_RECORD_CURRENT_KEK` -- optionally overrides which registered KEK wraps
249
+ * NEW records: a `urn:kek:sha256:<hex>` id, a multibase KEK value (its id
250
+ * derived), or the literal `none` (case-insensitive) which sets
251
+ * `currentKekId: null` -- the decrypt-only posture (old records still read, new
252
+ * records are written plaintext). It must name a registered KEK.
253
+ *
254
+ * All three unset/empty returns `undefined`, meaning encryption is disabled --
255
+ * key records are written plaintext (the default, honest about the teaching
256
+ * server's threat model). Setting both `KMS_RECORD_KEK` and `KMS_RECORD_KEKS` is
257
+ * ambiguous and throws; setting `KMS_RECORD_CURRENT_KEK` with no KEK configured
258
+ * throws. A malformed value throws (fails startup), naming the offending
259
+ * variable (and, for a list entry, its 1-based position) but never echoing the
260
+ * secret.
261
+ * @param options {object}
262
+ * @param [options.kek] {string} the `KMS_RECORD_KEK` value
263
+ * @param [options.keks] {string} the `KMS_RECORD_KEKS` value
264
+ * @param [options.currentKek] {string} the `KMS_RECORD_CURRENT_KEK` value
265
+ * @returns {KmsRecordKekRegistry|undefined} the registry, or `undefined` when
266
+ * no KEK is configured
267
+ */
268
+ export declare function parseKmsRecordKekRegistry({ kek, keks, currentKek }: {
269
+ kek?: string;
270
+ keks?: string;
271
+ currentKek?: string;
272
+ }): KmsRecordKekRegistry | undefined;
273
+ /**
274
+ * Parses the `STORAGE_LIMIT_PER_SPACE` env value into a per-Space capacity in
275
+ * bytes (spec "Quotas"). Accepts a plain non-negative integer number of bytes,
276
+ * or the literal `unlimited` (case-insensitive, trimmed) which returns
277
+ * `Infinity` -- an explicitly acknowledged unlimited quota (no startup
278
+ * warning). An unset or empty value returns `undefined`, meaning no limit is
279
+ * configured (still unlimited, but `start.ts` warns to prompt an explicit
280
+ * choice). A malformed value throws.
281
+ * @param raw {string|undefined} the raw env value
282
+ * @returns {number|undefined} capacity in bytes, `Infinity` for `unlimited`,
283
+ * or `undefined` when unset
284
+ */
285
+ export declare function parseStorageLimit(raw: string | undefined): number | undefined;
286
+ /**
287
+ * Parses the `MAX_UPLOAD_BYTES` env value into a per-upload size cap in bytes
288
+ * (spec "Quotas", the backend's `maxUploadBytes` constraint). Accepts a plain
289
+ * non-negative integer number of bytes, or the literal `unlimited`
290
+ * (case-insensitive, trimmed) which returns `Infinity` -- explicitly no cap.
291
+ * An unset or empty value returns `undefined`, meaning not configured: the
292
+ * backends apply the {@link DEFAULT_MAX_UPLOAD_BYTES} default (a default-on
293
+ * limit). A single upload exceeding the cap is rejected with
294
+ * `payload-too-large` (413), while smaller uploads still succeed. A malformed
295
+ * value throws.
296
+ * @param raw {string|undefined} the raw env value
297
+ * @returns {number|undefined} the per-upload cap in bytes, `Infinity` for
298
+ * `unlimited`, or `undefined` when unset
299
+ */
300
+ export declare function parseMaxUploadBytes(raw: string | undefined): number | undefined;
301
+ /**
302
+ * Parses one of the count-quota env values (`MAX_SPACES_PER_CONTROLLER`,
303
+ * `MAX_COLLECTIONS_PER_SPACE`, `MAX_RESOURCES_PER_SPACE`) into a maximum count.
304
+ * Accepts a plain non-negative integer, or the literal `unlimited`
305
+ * (case-insensitive, trimmed) which returns `Infinity` -- explicitly no cap. An
306
+ * unset or empty value returns `undefined`, meaning not configured: the backends
307
+ * apply the matching default-on limit ({@link DEFAULT_MAX_SPACES_PER_CONTROLLER}
308
+ * and friends). A malformed value throws, naming the variable and the
309
+ * `unlimited` escape hatch.
310
+ * @param raw {string|undefined} the raw env value
311
+ * @param name {string} the env variable name, for the error message
312
+ * @returns {number|undefined} the max count, `Infinity` for `unlimited`, or
313
+ * `undefined` when unset
314
+ */
315
+ export declare function parseCountLimit(raw: string | undefined, name: string): number | undefined;
316
+ /**
317
+ * Normalizes a count-quota constructor option to the internal instance field
318
+ * both backends store: an unset option (`undefined`) applies the default-on
319
+ * `fallback` limit; a non-finite option (`Infinity`, from an explicit
320
+ * `unlimited`) becomes `undefined` (no cap); a finite value passes through.
321
+ * Shared so the two backends cannot drift on the mapping (the same posture as
322
+ * the `maxUploadBytes` normalization each backend already applies), letting each
323
+ * count guard keep its plain `!== undefined` test.
324
+ * @param value {number|undefined} the constructor option
325
+ * @param fallback {number} the default-on limit applied when unset
326
+ * @returns {number|undefined} the internal limit, or `undefined` for no cap
327
+ */
328
+ export declare function normalizeCountLimit(value: number | undefined, fallback: number): number | undefined;
329
+ /**
330
+ * Parses the `WAS_ENABLED_BACKENDS` env value into the server-wide registration
331
+ * allowlist: the backend `provider` names a client may register (spec
332
+ * "Backends"). A comma-separated list (e.g. `gdrive,s3`); surrounding whitespace
333
+ * and empty entries are ignored. An unset or empty value returns `undefined`,
334
+ * meaning no allowlist is configured -- any provider may be registered (the
335
+ * permissive default, preserving prior behavior). When set, a registration whose
336
+ * `provider` is not listed is rejected with `unsupported-backend` (409).
337
+ * @param raw {string|undefined} the raw env value
338
+ * @returns {string[]|undefined} the allowed provider names, or `undefined`
339
+ */
340
+ export declare function parseEnabledBackends(raw: string | undefined): string[] | undefined;
341
+ /**
342
+ * Parses the `WAS_ONBOARDING_TOKEN` env value into the shared-secret onboarding
343
+ * token gating the two open provisioning endpoints (`POST /spaces/`,
344
+ * `POST /kms/keystores`). An unset or empty/whitespace-only value returns
345
+ * `undefined`, meaning the feature is off -- provisioning is authorized by
346
+ * proving control of the body's controller DID (the teaching default). When
347
+ * set, those two endpoints instead require an `Authorization: Bearer <token>`
348
+ * header matching this value, which then substitutes for zcap verification.
349
+ * @param raw {string|undefined} the raw env value
350
+ * @returns {string|undefined} the trimmed token, or `undefined` when unset
351
+ */
352
+ export declare function parseOnboardingToken(raw: string | undefined): string | undefined;
353
+ export declare const SPEC_URL = "https://digitalcredentials.github.io/wallet-attached-storage-spec/";
354
+ export declare const UBC_MANIFEST_URL = "https://codeberg.org/fediverse/fep/src/branch/main/fep/6fcd/fep-6fcd.md#manifest-file";
355
+ export declare const SPACE_URL = "https://digitalcredentials.github.io/wallet-attached-storage-spec/#spaces";
356
+ export declare const COLLECTION_URL = "https://digitalcredentials.github.io/wallet-attached-storage-spec/#collection-data-model";
357
+ export declare const RESOURCE_URL = "https://digitalcredentials.github.io/wallet-attached-storage-spec/#resource-data-model";
358
+ export declare const POLICY_URL = "https://digitalcredentials.github.io/wallet-attached-storage-spec/#policy";
359
+ export declare const META_URL = "https://digitalcredentials.github.io/wallet-attached-storage-spec/#resource-metadata-data-model";
360
+ //# sourceMappingURL=config.default.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.default.d.ts","sourceRoot":"","sources":["../src/config.default.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAA;AAMjE,yDAAyD;AACzD,eAAO,MAAM,cAAc,EAEd,MAAM,CAAA;AAEnB;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,OAAQ,CAAA;AAChD,6EAA6E;AAC7E,eAAO,MAAM,2BAA2B,OAAQ,CAAA;AAEhD;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,OAAQ,CAAA;AAE/C;;;GAGG;AACH,eAAO,MAAM,oBAAoB,uCAAuC,CAAA;AAExE;;;GAGG;AACH,eAAO,MAAM,qBAAqB,wCAAwC,CAAA;AAE1E;;;GAGG;AACH,eAAO,MAAM,mBAAmB,sCAAsC,CAAA;AAEtE;;;GAGG;AACH,eAAO,MAAM,gCAAgC,mDACK,CAAA;AAElD;;;GAGG;AACH,eAAO,MAAM,oBAAoB,uCAAuC,CAAA;AAExE;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,MAAM,CAAA;AAE5C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,OAAQ,CAAA;AAE1C;;;GAGG;AACH,eAAO,MAAM,kBAAkB,aAAa,CAAA;AAE5C;;;GAGG;AACH,eAAO,MAAM,mBAAmB,MAAM,CAAA;AAEtC;;;;;GAKG;AACH,eAAO,MAAM,cAAc,MAAM,CAAA;AA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