@jwilleke/ngdpbase-types 0.0.0 → 5.19.0

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 (304) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +16 -2
  3. package/lib/packages/ngdpbase-types/index.d.ts +32 -0
  4. package/lib/packages/ngdpbase-types/testing.d.ts +43 -0
  5. package/lib/packages/ngdpbase-types/testing.js +53 -0
  6. package/lib/src/cache/CacheDependencies.d.ts +50 -0
  7. package/lib/src/cache/CacheDependencies.js +50 -0
  8. package/lib/src/cache/ICacheAdapter.d.ts +86 -0
  9. package/lib/src/cache/RegionCache.d.ts +171 -0
  10. package/lib/src/context/ActorContext.d.ts +48 -0
  11. package/lib/src/context/ActorContext.js +33 -0
  12. package/lib/src/context/ApiContext.d.ts +194 -0
  13. package/lib/src/context/ApiContext.js +273 -0
  14. package/lib/src/context/BaseContext.d.ts +110 -0
  15. package/lib/src/context/BaseContext.js +143 -0
  16. package/lib/src/context/JobContext.d.ts +153 -0
  17. package/lib/src/context/JobContext.js +144 -0
  18. package/lib/src/context/WikiContext.d.ts +404 -0
  19. package/lib/src/context/bootActions.d.ts +64 -0
  20. package/lib/src/context/bootActions.js +111 -0
  21. package/lib/src/converters/HtmlConverter.d.ts +70 -0
  22. package/lib/src/converters/IContentConverter.d.ts +94 -0
  23. package/lib/src/converters/JSPWikiConverter.d.ts +117 -0
  24. package/lib/src/converters/conversionWarning.d.ts +15 -0
  25. package/lib/src/converters/ncm/bridge.d.ts +22 -0
  26. package/lib/src/converters/ncm/existing.d.ts +23 -0
  27. package/lib/src/converters/ncm/fix/blocks.d.ts +89 -0
  28. package/lib/src/converters/ncm/fix/bulletMarkers.d.ts +21 -0
  29. package/lib/src/converters/ncm/fix/index.d.ts +36 -0
  30. package/lib/src/converters/ncm/fix/jspwikiBullets.d.ts +20 -0
  31. package/lib/src/converters/ncm/fix/jspwikiCodeMarkers.d.ts +38 -0
  32. package/lib/src/converters/ncm/fix/jspwikiHeadings.d.ts +25 -0
  33. package/lib/src/converters/ncm/fix/jspwikiIndent.d.ts +24 -0
  34. package/lib/src/converters/ncm/fix/jspwikiInsert.d.ts +21 -0
  35. package/lib/src/converters/ncm/fix/jspwikiItalic.d.ts +29 -0
  36. package/lib/src/converters/ncm/fix/jspwikiLinkLeftovers.d.ts +27 -0
  37. package/lib/src/converters/ncm/fix/moreInformationFooter.d.ts +25 -0
  38. package/lib/src/converters/ncm/fix/styleClosers.d.ts +25 -0
  39. package/lib/src/converters/ncm/fix/tightenLists.d.ts +30 -0
  40. package/lib/src/converters/ncm/fix/types.d.ts +33 -0
  41. package/lib/src/converters/ncm/footnotes.d.ts +39 -0
  42. package/lib/src/converters/ncm/images.d.ts +49 -0
  43. package/lib/src/converters/ncm/index.d.ts +20 -0
  44. package/lib/src/converters/ncm/links.d.ts +21 -0
  45. package/lib/src/converters/ncm/normalize.d.ts +39 -0
  46. package/lib/src/converters/ncm/placeholder.d.ts +25 -0
  47. package/lib/src/converters/ncm/tables.d.ts +36 -0
  48. package/lib/src/converters/ncm/types.d.ts +42 -0
  49. package/lib/src/http/egressPolicy.d.ts +52 -0
  50. package/lib/src/http/guardedFetch.d.ts +89 -0
  51. package/lib/src/http/guardedFetch.js +113 -0
  52. package/lib/src/http/guardedLookup.d.ts +48 -0
  53. package/lib/src/http/guardedLookup.js +73 -0
  54. package/lib/src/http/ssrf.d.ts +83 -0
  55. package/lib/src/http/ssrf.js +311 -0
  56. package/lib/src/mail/MailProvider.d.ts +36 -0
  57. package/lib/src/mail/NodemailerMailProvider.d.ts +26 -0
  58. package/lib/src/managers/AddonsManager.d.ts +691 -0
  59. package/lib/src/managers/AgentTokenManager.d.ts +269 -0
  60. package/lib/src/managers/AssetManager.d.ts +116 -0
  61. package/lib/src/managers/AttachmentManager.d.ts +1032 -0
  62. package/lib/src/managers/AuthManager.d.ts +1257 -0
  63. package/lib/src/managers/BackgroundJobManager.d.ts +434 -0
  64. package/lib/src/managers/BaseManager.d.ts +427 -0
  65. package/lib/src/managers/BaseManager.js +415 -0
  66. package/lib/src/managers/CacheManager.d.ts +159 -0
  67. package/lib/src/managers/CatalogManager.d.ts +235 -0
  68. package/lib/src/managers/CommentManager.d.ts +75 -0
  69. package/lib/src/managers/ConfigurationManager.d.ts +747 -0
  70. package/lib/src/managers/DatabaseManager.d.ts +188 -0
  71. package/lib/src/managers/DatabaseManager.js +590 -0
  72. package/lib/src/managers/EmailManager.d.ts +47 -0
  73. package/lib/src/managers/ExportManager.d.ts +129 -0
  74. package/lib/src/managers/ExportManager.js +420 -0
  75. package/lib/src/managers/FootnoteManager.d.ts +118 -0
  76. package/lib/src/managers/MediaManager.d.ts +279 -0
  77. package/lib/src/managers/MetricsManager.d.ts +89 -0
  78. package/lib/src/managers/NotificationManager.d.ts +165 -0
  79. package/lib/src/managers/OidcManager.d.ts +210 -0
  80. package/lib/src/managers/OrganizationManager.d.ts +107 -0
  81. package/lib/src/managers/PageManager.d.ts +1645 -0
  82. package/lib/src/managers/PersonManager.d.ts +48 -0
  83. package/lib/src/managers/PluginManager.d.ts +179 -0
  84. package/lib/src/managers/PluginManager.js +393 -0
  85. package/lib/src/managers/PolicyEvaluator.d.ts +213 -0
  86. package/lib/src/managers/RenderingManager.d.ts +358 -0
  87. package/lib/src/managers/RoleManager.d.ts +134 -0
  88. package/lib/src/managers/SearchManager.d.ts +402 -0
  89. package/lib/src/managers/ShareManager.d.ts +251 -0
  90. package/lib/src/managers/TemplateManager.d.ts +176 -0
  91. package/lib/src/managers/ThemeManager.d.ts +56 -0
  92. package/lib/src/managers/UserManager.d.ts +480 -0
  93. package/lib/src/managers/ValidationManager.d.ts +426 -0
  94. package/lib/src/managers/VariableManager.d.ts +145 -0
  95. package/lib/src/middleware/csrf.d.ts +3 -0
  96. package/lib/src/parsers/LinkParser.d.ts +457 -0
  97. package/lib/src/parsers/MarkupParser.d.ts +769 -0
  98. package/lib/src/parsers/context/ParseContext.d.ts +314 -0
  99. package/lib/src/parsers/data/emoji-map.d.ts +18 -0
  100. package/lib/src/parsers/dom/DOMBuilder.d.ts +210 -0
  101. package/lib/src/parsers/dom/DOMParser.d.ts +252 -0
  102. package/lib/src/parsers/dom/Tokenizer.d.ts +358 -0
  103. package/lib/src/parsers/dom/WikiDocument.d.ts +272 -0
  104. package/lib/src/parsers/dom/handlers/DOMLinkHandler.d.ts +260 -0
  105. package/lib/src/parsers/dom/handlers/DOMPluginHandler.d.ts +212 -0
  106. package/lib/src/parsers/dom/handlers/DOMVariableHandler.d.ts +171 -0
  107. package/lib/src/parsers/filters/BaseFilter.d.ts +269 -0
  108. package/lib/src/parsers/filters/FilterChain.d.ts +320 -0
  109. package/lib/src/parsers/handlers/BaseSyntaxHandler.d.ts +331 -0
  110. package/lib/src/parsers/handlers/HandlerRegistry.d.ts +225 -0
  111. package/lib/src/parsers/handlers/JSPWikiPreprocessor.d.ts +89 -0
  112. package/lib/src/parsers/handlers/LinkParserHandler.d.ts +80 -0
  113. package/lib/src/parsers/handlers/PluginSyntaxHandler.d.ts +78 -0
  114. package/lib/src/parsers/handlers/WikiFormHandler.d.ts +149 -0
  115. package/lib/src/parsers/handlers/WikiTagHandler.d.ts +125 -0
  116. package/lib/src/parsers/jspwikiTableRow.d.ts +39 -0
  117. package/lib/src/parsers/styleBlockSyntax.d.ts +14 -0
  118. package/lib/src/plugins/types.d.ts +79 -0
  119. package/lib/src/providers/AgentTokenAuthProvider.d.ts +40 -0
  120. package/lib/src/providers/AuthentikBearerAuthProvider.d.ts +75 -0
  121. package/lib/src/providers/BaseAttachmentProvider.d.ts +197 -0
  122. package/lib/src/providers/BaseAuthProvider.d.ts +220 -0
  123. package/lib/src/providers/BaseCacheProvider.d.ts +140 -0
  124. package/lib/src/providers/BaseCredentialsProvider.d.ts +84 -0
  125. package/lib/src/providers/BaseDatabaseProvider.d.ts +22 -0
  126. package/lib/src/providers/BaseDatabaseProvider.js +12 -0
  127. package/lib/src/providers/BaseLoggingProvider.d.ts +68 -0
  128. package/lib/src/providers/BaseLoggingProvider.js +37 -0
  129. package/lib/src/providers/BaseMediaProvider.d.ts +308 -0
  130. package/lib/src/providers/BasePageProvider.d.ts +337 -0
  131. package/lib/src/providers/BaseProvider.d.ts +98 -0
  132. package/lib/src/providers/BaseProvider.js +74 -0
  133. package/lib/src/providers/BaseSearchProvider.d.ts +362 -0
  134. package/lib/src/providers/BasicAttachmentProvider.d.ts +599 -0
  135. package/lib/src/providers/CloudflareAccessAuthProvider.d.ts +72 -0
  136. package/lib/src/providers/FileCredentialsProvider.d.ts +33 -0
  137. package/lib/src/providers/FileJobStateProvider.d.ts +58 -0
  138. package/lib/src/providers/FileLoggingProvider.d.ts +43 -0
  139. package/lib/src/providers/FileLoggingProvider.js +120 -0
  140. package/lib/src/providers/FileOidcAdapter.d.ts +25 -0
  141. package/lib/src/providers/FileSystemMediaProvider.d.ts +403 -0
  142. package/lib/src/providers/LunrSearchProvider.d.ts +280 -0
  143. package/lib/src/providers/MagicLinkAuthProvider.d.ts +125 -0
  144. package/lib/src/providers/NullCacheProvider.d.ts +72 -0
  145. package/lib/src/providers/OidcAuthProvider.d.ts +180 -0
  146. package/lib/src/providers/OidcBearerAuthProvider.d.ts +30 -0
  147. package/lib/src/providers/PasskeyAuthProvider.d.ts +58 -0
  148. package/lib/src/providers/PasswordAuthProvider.d.ts +20 -0
  149. package/lib/src/providers/SqliteDatabaseProvider.d.ts +55 -0
  150. package/lib/src/providers/SqliteDatabaseProvider.js +90 -0
  151. package/lib/src/providers/SqliteJobStateProvider.d.ts +41 -0
  152. package/lib/src/providers/databaseMigrations.d.ts +8 -0
  153. package/lib/src/providers/databaseMigrations.js +47 -0
  154. package/lib/src/providers/jobState.d.ts +99 -0
  155. package/lib/src/providers/lunrQueryToMiniSearch.d.ts +32 -0
  156. package/lib/src/providers/mediaFilenameDate.d.ts +22 -0
  157. package/lib/src/providers/sqliteBackup.d.ts +128 -0
  158. package/lib/src/providers/sqliteBackup.js +365 -0
  159. package/lib/src/providers/sqliteLocation.d.ts +17 -0
  160. package/lib/src/providers/sqliteLocation.js +55 -0
  161. package/lib/src/providers/sqliteMigrations.d.ts +48 -0
  162. package/lib/src/providers/sqliteMigrations.js +72 -0
  163. package/lib/src/rendering/githubAlerts.d.ts +22 -0
  164. package/lib/src/rendering/htmlPolicy.d.ts +76 -0
  165. package/lib/src/rendering/markdownConverter.d.ts +73 -0
  166. package/lib/src/security/PolicyDecisionPoint.d.ts +245 -0
  167. package/lib/src/security/PolicyInformationPoint.d.ts +448 -0
  168. package/lib/src/security/pageActions.d.ts +40 -0
  169. package/lib/src/security/permissions.generated.d.ts +78 -0
  170. package/lib/src/types/Asset.d.ts +414 -0
  171. package/lib/src/types/Catalog.d.ts +61 -0
  172. package/lib/src/types/Comment.d.ts +11 -0
  173. package/lib/src/types/Config.d.ts +388 -0
  174. package/lib/src/types/Organization.d.ts +78 -0
  175. package/lib/src/types/OrganizationProvider.d.ts +38 -0
  176. package/lib/src/types/Page.d.ts +220 -0
  177. package/lib/src/types/Person.d.ts +56 -0
  178. package/lib/src/types/PersonProvider.d.ts +25 -0
  179. package/lib/src/types/Policy.d.ts +139 -0
  180. package/lib/src/types/Policy.js +17 -0
  181. package/lib/src/types/Provider.d.ts +810 -0
  182. package/lib/src/types/Role.d.ts +84 -0
  183. package/lib/src/types/RoleProvider.d.ts +35 -0
  184. package/lib/src/types/Schema.d.ts +425 -0
  185. package/lib/src/types/Share.d.ts +172 -0
  186. package/lib/src/types/Share.js +81 -0
  187. package/lib/src/types/User.d.ts +304 -0
  188. package/lib/src/types/Version.d.ts +189 -0
  189. package/lib/src/types/WikiEngine.d.ts +128 -0
  190. package/lib/src/types/express.d.ts +120 -0
  191. package/lib/src/types/express.js +1 -0
  192. package/lib/src/types/guards.d.ts +78 -0
  193. package/lib/src/types/heic-decode.d.ts +16 -0
  194. package/lib/src/types/index.d.ts +19 -0
  195. package/lib/src/types/linkedom.d.ts +77 -0
  196. package/lib/src/types/markdown-it-plugins.d.ts +21 -0
  197. package/lib/src/utils/DeltaStorage.d.ts +118 -0
  198. package/lib/src/utils/LocaleUtils.d.ts +105 -0
  199. package/lib/src/utils/LocaleUtils.js +294 -0
  200. package/lib/src/utils/PageNameMatcher.d.ts +98 -0
  201. package/lib/src/utils/PathPreflight.d.ts +38 -0
  202. package/lib/src/utils/PathPreflight.js +50 -0
  203. package/lib/src/utils/SectionUtils.d.ts +40 -0
  204. package/lib/src/utils/addonConfigLayer.d.ts +144 -0
  205. package/lib/src/utils/addonConfigLayer.js +382 -0
  206. package/lib/src/utils/addonDatabaseRules.d.ts +25 -0
  207. package/lib/src/utils/addonDatabaseRules.js +57 -0
  208. package/lib/src/utils/addonHost.d.ts +51 -0
  209. package/lib/src/utils/addonHost.js +72 -0
  210. package/lib/src/utils/addonInstaller.d.ts +109 -0
  211. package/lib/src/utils/addonLock.d.ts +37 -0
  212. package/lib/src/utils/addonLock.js +48 -0
  213. package/lib/src/utils/addonPageSync.d.ts +45 -0
  214. package/lib/src/utils/addonProvenance.d.ts +48 -0
  215. package/lib/src/utils/addonTarball.d.ts +41 -0
  216. package/lib/src/utils/addonsPathResolver.d.ts +76 -0
  217. package/lib/src/utils/addonsPathResolver.js +129 -0
  218. package/lib/src/utils/assetMetadataTags.d.ts +66 -0
  219. package/lib/src/utils/atomicWrite.d.ts +28 -0
  220. package/lib/src/utils/auditConfigChange.d.ts +57 -0
  221. package/lib/src/utils/auditEventNames.d.ts +50 -0
  222. package/lib/src/utils/auditEventNames.generated.d.ts +169 -0
  223. package/lib/src/utils/auditEventNames.generated.js +174 -0
  224. package/lib/src/utils/auditEventNames.js +49 -0
  225. package/lib/src/utils/auditEvents.d.ts +265 -0
  226. package/lib/src/utils/auditEvents.js +309 -0
  227. package/lib/src/utils/auditRegistry.d.ts +102 -0
  228. package/lib/src/utils/auditRegistry.js +168 -0
  229. package/lib/src/utils/bip39English.d.ts +2 -0
  230. package/lib/src/utils/configEnvKeys.d.ts +68 -0
  231. package/lib/src/utils/configFiles.d.ts +74 -0
  232. package/lib/src/utils/configFiles.js +150 -0
  233. package/lib/src/utils/delegation.d.ts +48 -0
  234. package/lib/src/utils/deriveUsername.d.ts +21 -0
  235. package/lib/src/utils/explainMediaPath.d.ts +123 -0
  236. package/lib/src/utils/formerTitles.d.ts +69 -0
  237. package/lib/src/utils/frontmatterAccess.d.ts +54 -0
  238. package/lib/src/utils/headlessAdminPassword.d.ts +55 -0
  239. package/lib/src/utils/imageTransform.d.ts +52 -0
  240. package/lib/src/utils/instanceEnvSecret.d.ts +51 -0
  241. package/lib/src/utils/jobSlots.d.ts +43 -0
  242. package/lib/src/utils/keywordNormalizer.d.ts +127 -0
  243. package/lib/src/utils/logger.d.ts +70 -0
  244. package/lib/src/utils/logger.js +106 -0
  245. package/lib/src/utils/magicLinkDeviceState.d.ts +95 -0
  246. package/lib/src/utils/managerUtils.d.ts +40 -0
  247. package/lib/src/utils/migrateLegacyPrivateAttachments.d.ts +15 -0
  248. package/lib/src/utils/orgFilename.d.ts +22 -0
  249. package/lib/src/utils/pageFeature.d.ts +27 -0
  250. package/lib/src/utils/pageFrontmatter.d.ts +21 -0
  251. package/lib/src/utils/pageNotes.d.ts +150 -0
  252. package/lib/src/utils/pageTitleRule.d.ts +37 -0
  253. package/lib/src/utils/pageToArticle.d.ts +59 -0
  254. package/lib/src/utils/pageUrl.d.ts +18 -0
  255. package/lib/src/utils/passwordChange.d.ts +12 -0
  256. package/lib/src/utils/passwordHash.d.ts +60 -0
  257. package/lib/src/utils/permissionCatalog.d.ts +52 -0
  258. package/lib/src/utils/pluginFormatters.d.ts +452 -0
  259. package/lib/src/utils/pluginFormatters.js +714 -0
  260. package/lib/src/utils/privateLinkRewrite.d.ts +42 -0
  261. package/lib/src/utils/privateStoreAccess.d.ts +57 -0
  262. package/lib/src/utils/privateStoreAccess.js +65 -0
  263. package/lib/src/utils/privateStoreCatalogs.d.ts +40 -0
  264. package/lib/src/utils/privateStoreCrypto.d.ts +127 -0
  265. package/lib/src/utils/privateStoreDoor.d.ts +181 -0
  266. package/lib/src/utils/privateStoreExport.d.ts +72 -0
  267. package/lib/src/utils/privateStoreFiles.d.ts +120 -0
  268. package/lib/src/utils/privateStoreMeta.d.ts +64 -0
  269. package/lib/src/utils/privateStoreMigrations.d.ts +37 -0
  270. package/lib/src/utils/privateStorePath.d.ts +259 -0
  271. package/lib/src/utils/privateStorePath.js +436 -0
  272. package/lib/src/utils/privateStoreTakeout.d.ts +76 -0
  273. package/lib/src/utils/privateStoreUnlock.d.ts +175 -0
  274. package/lib/src/utils/proxyClaim.d.ts +59 -0
  275. package/lib/src/utils/proxyClaim.js +30 -0
  276. package/lib/src/utils/redactPrivateNames.d.ts +21 -0
  277. package/lib/src/utils/redactPrivateNames.js +89 -0
  278. package/lib/src/utils/redactSecrets.d.ts +58 -0
  279. package/lib/src/utils/redactSecrets.js +171 -0
  280. package/lib/src/utils/renameLinkRewrite.d.ts +112 -0
  281. package/lib/src/utils/roleGrants.d.ts +35 -0
  282. package/lib/src/utils/safeRedirect.d.ts +32 -0
  283. package/lib/src/utils/schedule.d.ts +54 -0
  284. package/lib/src/utils/secretFileMode.d.ts +17 -0
  285. package/lib/src/utils/seededShippedPages.d.ts +45 -0
  286. package/lib/src/utils/sensitiveValues.d.ts +59 -0
  287. package/lib/src/utils/sensitiveValues.js +106 -0
  288. package/lib/src/utils/sessionEnd.d.ts +12 -0
  289. package/lib/src/utils/sessionGeneration.d.ts +24 -0
  290. package/lib/src/utils/sessionIdle.d.ts +41 -0
  291. package/lib/src/utils/sessionLimits.d.ts +68 -0
  292. package/lib/src/utils/shareLockbox.d.ts +64 -0
  293. package/lib/src/utils/sigstoreTrustedRoot.d.ts +33 -0
  294. package/lib/src/utils/sniffMime.d.ts +21 -0
  295. package/lib/src/utils/storeSearchIndex.d.ts +75 -0
  296. package/lib/src/utils/subjectMayDo.d.ts +21 -0
  297. package/lib/src/utils/systemCategoryRules.d.ts +30 -0
  298. package/lib/src/utils/systemCategoryRules.js +41 -0
  299. package/lib/src/utils/userCreateError.d.ts +62 -0
  300. package/lib/src/utils/username.d.ts +53 -0
  301. package/lib/src/utils/vaultUrlRewrite.d.ts +27 -0
  302. package/lib/src/utils/version.d.ts +84 -0
  303. package/lib/src/utils/videoFrame.d.ts +21 -0
  304. package/package.json +54 -3
@@ -0,0 +1,269 @@
1
+ /**
2
+ * AgentTokenManager — user-delegated agent API tokens (#946).
3
+ *
4
+ * A user mints a short-lived bearer credential for themselves and hands it to
5
+ * an agent. The token is a *delegation of the owner's own authority*: it can
6
+ * never do anything its owner could not already do.
7
+ *
8
+ * Design decisions (recorded on #946):
9
+ * - **Opaque, not JWT.** A 24-hour credential must be revocable before it
10
+ * expires; a self-signed JWT cannot be withdrawn.
11
+ * - **SHA-256, not bcrypt.** The token is 256 bits of uniform randomness, so
12
+ * there is no dictionary to attack and no work factor is warranted. bcrypt
13
+ * would only add per-request latency on an endpoint agents hammer.
14
+ * (Password hashing is a different problem — low-entropy human input.)
15
+ * - **Persisted, not in-memory.** MagicLinkAuthProvider's in-memory map suits
16
+ * its 15-minute TTL; at 24 hours a restart would silently invalidate every
17
+ * live token mid-run.
18
+ * - **Roles are never stored on the token.** Only `owner` is kept, and
19
+ * permissions resolve live from the user record at request time — so
20
+ * demoting or disabling a user immediately weakens every token they hold.
21
+ * - **Scopes only narrow.** Effective permission is owner ∩ scopes, enforced
22
+ * live by PolicyInformationPoint and UserManager against `viaToken.scopes`.
23
+ *
24
+ * Store: `<FAST_STORAGE>/tokens/agent-tokens.json`, a map keyed by token id,
25
+ * matching the map-not-array convention of `users.json`.
26
+ *
27
+ * ## Correctness rules this file is built around (#1108)
28
+ *
29
+ * A review of the original implementation found seven defects, all of which
30
+ * came back to three rules that were implied but never stated. They are stated
31
+ * here because each was violated by code that read as though it respected them:
32
+ *
33
+ * 1. **The read path does no disk IO.** `verify()` runs on every agent
34
+ * request. The original stamped `lastUsedAt` and persisted synchronously —
35
+ * and `persist()` took a timestamped backup copy first, so authenticating
36
+ * wrote an unbounded pile of hash-bearing files into the token directory.
37
+ * `lastUsedAt` is now buffered in memory and flushed by the maintenance
38
+ * timer; backups are taken only on structural change, and are bounded.
39
+ * 2. **An unreadable date means expired, everywhere.** `Date.parse` returns
40
+ * `NaN` for a malformed value, and `NaN <= now` and `NaN > now` are *both*
41
+ * false — so `verify()` read a broken `expiresAt` as "not expired" while
42
+ * `isLive()` read the same value as "not live". The result was a token that
43
+ * authenticated forever and appeared in no listing, not even an admin's.
44
+ * Every expiry comparison now goes through `expiryOf()`, which collapses
45
+ * unparseable to `-Infinity`: unreadable fails closed.
46
+ * 3. **Nothing hands out a live reference to a stored record.** `verify()`
47
+ * returned the record straight out of the Map — hash included — and
48
+ * AgentTokenAuthProvider put its `scopes` array into `req.userContext`,
49
+ * where the ACL layer treats it as the permission ceiling. Anything
50
+ * downstream holding that array was editing the store. Every exit from this
51
+ * class is now a copy via `toPublic()`.
52
+ *
53
+ * ## Extraction note
54
+ *
55
+ * The two namespace-bound values live in `CONFIG_PREFIX` and `TOKEN_PREFIX`
56
+ * below. When this class moves into the shared framework package, those are the
57
+ * parameters a derivative supplies — nothing else in the file names the host.
58
+ */
59
+ import BaseManager, { type ManagerStats } from './BaseManager.js';
60
+ import type { BackupData } from './BaseManager.js';
61
+ import type { WikiEngine } from '../types/WikiEngine.js';
62
+ import type { PermissionSubject } from './UserManager.js';
63
+ export { MINT_PERMISSION } from '../utils/delegation.js';
64
+ export interface AgentTokenRecord {
65
+ id: string;
66
+ owner: string;
67
+ name: string;
68
+ /** `sha256:<hex>` — never the cleartext */
69
+ hash: string;
70
+ /** Leading characters, kept for display in listings */
71
+ prefix: string;
72
+ scopes: string[];
73
+ createdAt: string;
74
+ expiresAt: string;
75
+ lastUsedAt: string | null;
76
+ revokedAt: string | null;
77
+ revokedBy: string | null;
78
+ /**
79
+ * #1762 slice 6: the person who minted it while acting for `owner` under a
80
+ * proxy grant. Absent when the owner minted it themselves.
81
+ */
82
+ approvedBy?: string;
83
+ /** The proxy grant it was minted under. Ending that grant ends this token; it works only while the grant is in force. */
84
+ proxyGrantId?: string;
85
+ }
86
+ /** A record safe to return over the API — no hash. */
87
+ export type AgentTokenPublic = Omit<AgentTokenRecord, 'hash'>;
88
+ export interface MintResult {
89
+ /** Cleartext token — returned once, never persisted. */
90
+ token: string;
91
+ record: AgentTokenPublic;
92
+ }
93
+ declare class AgentTokenManager extends BaseManager {
94
+ private storePath;
95
+ private tokens;
96
+ /**
97
+ * Records that failed validation on load, kept verbatim and written back.
98
+ *
99
+ * They are deliberately NOT in `tokens`, so they authenticate nothing and
100
+ * appear in no listing. But dropping them would rewrite the store without
101
+ * them on the next save — destroying the only evidence that something
102
+ * corrupted the file. Fail closed, keep the evidence, stay up.
103
+ */
104
+ private quarantined;
105
+ /** Ids whose `lastUsedAt` has moved in memory but not yet on disk. */
106
+ private dirtyLastUsed;
107
+ /**
108
+ * Serialises saves. `writeFileAtomic` guarantees no *partial* file, and says
109
+ * so in its own header — it is explicitly not a lock, and two concurrent
110
+ * writers still race for last-writer-wins. This is the queue the page index
111
+ * uses for the same reason.
112
+ */
113
+ private writeQueue;
114
+ private tokenConfig;
115
+ constructor(engine: WikiEngine);
116
+ initialize(): Promise<void>;
117
+ /**
118
+ * Flush buffered `lastUsedAt` stamps and purge dead records, every
119
+ * `sweep-interval-seconds` — a maintenance job on the scheduler (#1721).
120
+ *
121
+ * Purging used to happen only in `initialize()`, so a server up for months
122
+ * never applied its own retention policy again — the config promised a
123
+ * 30-day window that was only ever honoured at boot.
124
+ */
125
+ private startMaintenance;
126
+ private load;
127
+ /**
128
+ * Persist the store atomically, serialised behind the write queue.
129
+ *
130
+ * Quarantined records are written back untouched so a save never destroys
131
+ * evidence of corruption.
132
+ */
133
+ private persist;
134
+ /**
135
+ * Write out buffered `lastUsedAt` stamps, if any.
136
+ *
137
+ * Public so a caller — a test, or a shutdown path — can make the in-memory
138
+ * stamp durable on demand without waiting for the maintenance tick.
139
+ */
140
+ flushLastUsed(): Promise<number>;
141
+ /**
142
+ * Mint a token for `owner`.
143
+ * @throws Error with a caller-safe message on validation failure.
144
+ */
145
+ /**
146
+ * The audit sink, or null when no AuditManager is registered (#1111).
147
+ *
148
+ * Fire-and-forget with a caught error at the call site: the credential is the
149
+ * product and the log is a record of it, so losing the log is bad but
150
+ * refusing to mint because the log failed is worse.
151
+ */
152
+ private auditSink;
153
+ /**
154
+ * Mint a token for `subject`, the owner acting through a session (#1178).
155
+ *
156
+ * Takes the subject rather than a username because minting asks a policy
157
+ * question: does the owner hold every scope the token would carry? A scope
158
+ * the owner lacks is inert at use time (effective permission is owner ∩
159
+ * scopes), so refusing it here is honesty rather than security — a token
160
+ * that silently cannot do the thing it names is a support ticket. The
161
+ * refusal names the missing scopes so the caller can act on it.
162
+ *
163
+ * #1762 slice 6: a subject acting for the owner under a proxy grant mints
164
+ * the owner's token. The same `permits` question then asks the proxy
165
+ * ceiling, so every scope must be in the grant, held by the owner and held
166
+ * by the person acting. The token records that person (`approvedBy`) and the
167
+ * grant (`proxyGrantId`); it works only while that grant is in force.
168
+ */
169
+ mint(subject: PermissionSubject, name: string, scopes: string[], ttlHours?: number, now?: number): Promise<MintResult>;
170
+ /**
171
+ * Verify a presented cleartext token.
172
+ * Returns a COPY of the record when valid, else null. Buffers `lastUsedAt`.
173
+ *
174
+ * No disk IO: see rule 1 in the file header. The stamp lands in memory and is
175
+ * flushed by the maintenance tick, so a token used a thousand times a minute
176
+ * costs one write, not a thousand writes and a thousand backup files.
177
+ */
178
+ verify(token: string, now?: number): Promise<AgentTokenPublic | null>;
179
+ /** Live (not expired, not revoked) tokens for an owner. */
180
+ listForOwner(owner: string, now?: number): AgentTokenPublic[];
181
+ /** Every live token, for admin oversight (#946 open question 1). */
182
+ /**
183
+ * #1006: how many live tokens exist. Never which, and never their values.
184
+ *
185
+ * This manager is the reason the contract is counts-only rather than the
186
+ * `getAll()` originally asked for: it holds bearer credentials, and a
187
+ * generic enumeration on the base class would hand them to the first
188
+ * generic caller. `listAll()` returns `AgentTokenPublic`, which already
189
+ * excludes the secret — this reports its LENGTH and not its contents.
190
+ */
191
+ getManagerStats(): Promise<ManagerStats>;
192
+ listAll(now?: number): AgentTokenPublic[];
193
+ getById(id: string): AgentTokenPublic | null;
194
+ /**
195
+ * A token minted under a proxy grant works only while that grant is in
196
+ * force (#1762 slice 6): ended, past its end date, or proxy access turned
197
+ * off, and the token stops. Asked of AuthManager, which owns the grants; no
198
+ * answer is a refusal. A token its owner minted is not affected.
199
+ */
200
+ private approvalInForce;
201
+ /**
202
+ * Revoke a token. Effective immediately — verify() reads the in-memory store
203
+ * per request, so there is no cache to wait out. `ctx` is who revoked it:
204
+ * under a proxy grant (#1762 slice 6) the record names the represented
205
+ * person and the person acting, and `revokedBy` is the person acting.
206
+ */
207
+ revoke(id: string, ctx: PermissionSubject, now?: number): Promise<boolean>;
208
+ /**
209
+ * Extend one of the caller's own live tokens (#1734): move its expiry later
210
+ * by `hours` (the maximum when omitted), never beyond now + `max-ttl-hours`.
211
+ * The token string and its scopes do not change, so the agent holding it
212
+ * keeps working without a new hand-over.
213
+ *
214
+ * - Only the token's owner extends it. An admin does not extend someone
215
+ * else's token: like minting, a token's lifetime traces to the person who
216
+ * chose to delegate. Returns null for a token that is not the caller's, so
217
+ * the route answers it as one that does not exist.
218
+ * - The owner must hold `token-extend`, asked of the PDP with the subject the
219
+ * request carries, so step-up applies and a delegated credential is refused.
220
+ * - An expired or revoked token is not extended: mint a new one.
221
+ *
222
+ * Recorded before the expiry moves, like mint and revoke: `token-extend` is
223
+ * declared on-failure: refuse, so a lifetime change that cannot be audited
224
+ * does not happen.
225
+ *
226
+ * @returns The updated record, or null when the caller has no such token
227
+ * @throws Error with a caller-safe message when the extension is refused
228
+ */
229
+ extend(id: string, subject: PermissionSubject, hours?: number, now?: number): Promise<AgentTokenPublic | null>;
230
+ /**
231
+ * Drop expired/revoked records past the retention window.
232
+ *
233
+ * The audit log is unaffected — and since #1111 that is true rather than
234
+ * aspirational: `token-mint` and `token-revoke` events outlive the records
235
+ * here, so purging loses the credential and keeps the history of it. Before
236
+ * that, this comment claimed an audit trail that did not exist, which made
237
+ * `retention-days` load-bearing by accident.
238
+ */
239
+ purgeExpired(now?: number): Promise<number>;
240
+ private isLive;
241
+ /**
242
+ * A copy safe to hand out: no hash, and its own `scopes` array.
243
+ *
244
+ * The array copy is the load-bearing half. `scopes` becomes the permission
245
+ * ceiling in `req.userContext.viaToken`, so sharing the stored array with a
246
+ * caller means anything downstream can widen a token's authority in place.
247
+ */
248
+ private toPublic;
249
+ /**
250
+ * Flush pending stamps. Without this, `lastUsedAt` movement since the
251
+ * last sweep is lost on a clean shutdown. The sweep job itself is stopped
252
+ * by BackgroundJobManager's shutdown handoff (#1721).
253
+ */
254
+ shutdown(): Promise<void>;
255
+ backup(): Promise<BackupData>;
256
+ /**
257
+ * Refuse. A token backup carries no hashes, so there is nothing to restore
258
+ * from (#1111).
259
+ *
260
+ * This used to inherit `BaseManager`'s no-op default, which meant
261
+ * `restorable: false` was honoured because nobody had implemented the
262
+ * alternative rather than because anything declined. If someone later wrote a
263
+ * restore from that payload, records would return with NO hash, and whether
264
+ * they failed closed would depend entirely on how `verify()` compares. A
265
+ * refusal that is written down cannot be undone by accident.
266
+ */
267
+ restore(_backupData: BackupData): Promise<void>;
268
+ }
269
+ export default AgentTokenManager;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * AssetManager — provider registry for the unified DAM framework.
3
+ *
4
+ * Holds a registry of AssetProviders (keyed by provider.id) and exposes a
5
+ * single search/getById/getThumbnail API that fans out across all registered
6
+ * providers. The two built-in providers (BasicAttachmentProvider via
7
+ * AttachmentManager, FileSystemMediaProvider via MediaManager) are registered
8
+ * automatically in initialize(). Addons register additional providers via
9
+ * registerProvider().
10
+ *
11
+ * AssetService delegates to this manager so its existing public API is
12
+ * unchanged — callers that already use AssetService continue to work without
13
+ * modification.
14
+ */
15
+ import BaseManager from './BaseManager.js';
16
+ import type { WikiEngine } from '../types/WikiEngine.js';
17
+ import type { AssetProvider, AssetRecord, AssetPage, AssetQuery, ProviderHealthReport } from '../types/Asset.js';
18
+ import type { ActorContext } from '../context/ActorContext.js';
19
+ declare class AssetManager extends BaseManager {
20
+ readonly description = "Provider registry for the unified Digital Asset Management framework";
21
+ private registry;
22
+ /** Last known health status for each provider, keyed by provider.id */
23
+ private healthMap;
24
+ /** In-memory reverse index: page slug → set of composite asset keys */
25
+ private pageAssetsMap;
26
+ /** Absolute path to page-assets-index.json, set during initialize() */
27
+ private pageAssetsIndexPath;
28
+ /** Serialized write queue — prevents concurrent JSON saves from conflicting */
29
+ private pageAssetsWriteQueue;
30
+ constructor(engine: WikiEngine);
31
+ initialize(config?: Record<string, unknown>): Promise<void>;
32
+ /**
33
+ * Register an asset provider. If a provider with the same id is already
34
+ * registered it is replaced and a warning is logged.
35
+ */
36
+ registerProvider(provider: AssetProvider): void;
37
+ /** Return a single provider by id, or null. */
38
+ getProvider(id: string): AssetProvider | null;
39
+ /** Return all registered providers in registration order. */
40
+ getProviders(): AssetProvider[];
41
+ /**
42
+ * Run healthCheck() on every registered provider that implements it.
43
+ *
44
+ * Updates the internal health map. Providers without a healthCheck() method
45
+ * are marked 'healthy' (they are always assumed to be available). Call this
46
+ * at startup and from the admin health-check endpoint to refresh status.
47
+ */
48
+ checkProviderHealth(): Promise<void>;
49
+ /**
50
+ * Return a health report for every registered provider.
51
+ * Suitable for surfacing in an admin UI or REST endpoint.
52
+ */
53
+ getProviderHealth(): ProviderHealthReport[];
54
+ /**
55
+ * Scan wiki markup content for asset references and update the reverse index
56
+ * for the given page. Call this fire-and-forget at page-save time.
57
+ *
58
+ * Handles two reference formats:
59
+ * [{Image src='filename.jpg'}] → local attachment → "local:<id>"
60
+ * [{ATTACH src='filename.pdf'}] → local attachment → "local:<id>"
61
+ * [{Image src='media://img.jpg'}] → media library → "media-library:<id>"
62
+ *
63
+ * Runs all provider lookups concurrently; unresolvable filenames are silently
64
+ * skipped so a missing asset never blocks the page save.
65
+ */
66
+ syncPageAssets(pageName: string, content: string): Promise<void>;
67
+ /**
68
+ * Return all AssetRecords referenced by the given page slug.
69
+ *
70
+ * O(1) index lookup + one getById() call per referenced asset.
71
+ * Stale entries (asset deleted or provider removed) are silently filtered out.
72
+ */
73
+ getAssetsForPage(slug: string): Promise<AssetRecord[]>;
74
+ /**
75
+ * Remove a page's entry from the reverse index.
76
+ * Call this when a page is deleted or renamed.
77
+ */
78
+ removePageAssets(slug: string): void;
79
+ private _loadPageAssetsIndex;
80
+ /**
81
+ * Queue an atomic write of the page-assets index.
82
+ * Uses the same promise-chain pattern as VersioningFileProvider.savePageIndex()
83
+ * to prevent race conditions from concurrent page saves.
84
+ */
85
+ private _savePageAssetsIndex;
86
+ /** True when the provider is healthy or has no health check. */
87
+ private isHealthy;
88
+ /**
89
+ * Search across all registered providers (or a specific one when
90
+ * query.providerId is set), merge results, sort, and paginate.
91
+ *
92
+ * @param query - what to look for; `wikiContext` rides along for the media
93
+ * providers' own path ACL, as it always has
94
+ * @param ctx - who is searching (#1179, #1460). Mandatory and positional:
95
+ * the private-store half of the results is the requester's own container,
96
+ * and a door that took it out of the query bag would be reading an
97
+ * identity someone could leave out (#1164).
98
+ */
99
+ search(query: AssetQuery & {
100
+ providerId?: string;
101
+ wikiContext?: unknown;
102
+ }, ctx: ActorContext): Promise<AssetPage>;
103
+ /**
104
+ * Retrieve a single asset by id. If providerId is given only that provider
105
+ * is checked; otherwise all providers are tried in registration order.
106
+ */
107
+ getById(id: string, providerId?: string): Promise<AssetRecord | null>;
108
+ /**
109
+ * Generate or retrieve a cached thumbnail.
110
+ * Requires the provider to declare the 'thumbnail' capability.
111
+ */
112
+ getThumbnail(id: string, providerId: string, size?: string): Promise<Buffer | null>;
113
+ private _mergeAggregations;
114
+ private _sort;
115
+ }
116
+ export default AssetManager;