@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.
- package/LICENSE +201 -0
- package/README.md +16 -2
- package/lib/packages/ngdpbase-types/index.d.ts +32 -0
- package/lib/packages/ngdpbase-types/testing.d.ts +43 -0
- package/lib/packages/ngdpbase-types/testing.js +53 -0
- package/lib/src/cache/CacheDependencies.d.ts +50 -0
- package/lib/src/cache/CacheDependencies.js +50 -0
- package/lib/src/cache/ICacheAdapter.d.ts +86 -0
- package/lib/src/cache/RegionCache.d.ts +171 -0
- package/lib/src/context/ActorContext.d.ts +48 -0
- package/lib/src/context/ActorContext.js +33 -0
- package/lib/src/context/ApiContext.d.ts +194 -0
- package/lib/src/context/ApiContext.js +273 -0
- package/lib/src/context/BaseContext.d.ts +110 -0
- package/lib/src/context/BaseContext.js +143 -0
- package/lib/src/context/JobContext.d.ts +153 -0
- package/lib/src/context/JobContext.js +144 -0
- package/lib/src/context/WikiContext.d.ts +404 -0
- package/lib/src/context/bootActions.d.ts +64 -0
- package/lib/src/context/bootActions.js +111 -0
- package/lib/src/converters/HtmlConverter.d.ts +70 -0
- package/lib/src/converters/IContentConverter.d.ts +94 -0
- package/lib/src/converters/JSPWikiConverter.d.ts +117 -0
- package/lib/src/converters/conversionWarning.d.ts +15 -0
- package/lib/src/converters/ncm/bridge.d.ts +22 -0
- package/lib/src/converters/ncm/existing.d.ts +23 -0
- package/lib/src/converters/ncm/fix/blocks.d.ts +89 -0
- package/lib/src/converters/ncm/fix/bulletMarkers.d.ts +21 -0
- package/lib/src/converters/ncm/fix/index.d.ts +36 -0
- package/lib/src/converters/ncm/fix/jspwikiBullets.d.ts +20 -0
- package/lib/src/converters/ncm/fix/jspwikiCodeMarkers.d.ts +38 -0
- package/lib/src/converters/ncm/fix/jspwikiHeadings.d.ts +25 -0
- package/lib/src/converters/ncm/fix/jspwikiIndent.d.ts +24 -0
- package/lib/src/converters/ncm/fix/jspwikiInsert.d.ts +21 -0
- package/lib/src/converters/ncm/fix/jspwikiItalic.d.ts +29 -0
- package/lib/src/converters/ncm/fix/jspwikiLinkLeftovers.d.ts +27 -0
- package/lib/src/converters/ncm/fix/moreInformationFooter.d.ts +25 -0
- package/lib/src/converters/ncm/fix/styleClosers.d.ts +25 -0
- package/lib/src/converters/ncm/fix/tightenLists.d.ts +30 -0
- package/lib/src/converters/ncm/fix/types.d.ts +33 -0
- package/lib/src/converters/ncm/footnotes.d.ts +39 -0
- package/lib/src/converters/ncm/images.d.ts +49 -0
- package/lib/src/converters/ncm/index.d.ts +20 -0
- package/lib/src/converters/ncm/links.d.ts +21 -0
- package/lib/src/converters/ncm/normalize.d.ts +39 -0
- package/lib/src/converters/ncm/placeholder.d.ts +25 -0
- package/lib/src/converters/ncm/tables.d.ts +36 -0
- package/lib/src/converters/ncm/types.d.ts +42 -0
- package/lib/src/http/egressPolicy.d.ts +52 -0
- package/lib/src/http/guardedFetch.d.ts +89 -0
- package/lib/src/http/guardedFetch.js +113 -0
- package/lib/src/http/guardedLookup.d.ts +48 -0
- package/lib/src/http/guardedLookup.js +73 -0
- package/lib/src/http/ssrf.d.ts +83 -0
- package/lib/src/http/ssrf.js +311 -0
- package/lib/src/mail/MailProvider.d.ts +36 -0
- package/lib/src/mail/NodemailerMailProvider.d.ts +26 -0
- package/lib/src/managers/AddonsManager.d.ts +691 -0
- package/lib/src/managers/AgentTokenManager.d.ts +269 -0
- package/lib/src/managers/AssetManager.d.ts +116 -0
- package/lib/src/managers/AttachmentManager.d.ts +1032 -0
- package/lib/src/managers/AuthManager.d.ts +1257 -0
- package/lib/src/managers/BackgroundJobManager.d.ts +434 -0
- package/lib/src/managers/BaseManager.d.ts +427 -0
- package/lib/src/managers/BaseManager.js +415 -0
- package/lib/src/managers/CacheManager.d.ts +159 -0
- package/lib/src/managers/CatalogManager.d.ts +235 -0
- package/lib/src/managers/CommentManager.d.ts +75 -0
- package/lib/src/managers/ConfigurationManager.d.ts +747 -0
- package/lib/src/managers/DatabaseManager.d.ts +188 -0
- package/lib/src/managers/DatabaseManager.js +590 -0
- package/lib/src/managers/EmailManager.d.ts +47 -0
- package/lib/src/managers/ExportManager.d.ts +129 -0
- package/lib/src/managers/ExportManager.js +420 -0
- package/lib/src/managers/FootnoteManager.d.ts +118 -0
- package/lib/src/managers/MediaManager.d.ts +279 -0
- package/lib/src/managers/MetricsManager.d.ts +89 -0
- package/lib/src/managers/NotificationManager.d.ts +165 -0
- package/lib/src/managers/OidcManager.d.ts +210 -0
- package/lib/src/managers/OrganizationManager.d.ts +107 -0
- package/lib/src/managers/PageManager.d.ts +1645 -0
- package/lib/src/managers/PersonManager.d.ts +48 -0
- package/lib/src/managers/PluginManager.d.ts +179 -0
- package/lib/src/managers/PluginManager.js +393 -0
- package/lib/src/managers/PolicyEvaluator.d.ts +213 -0
- package/lib/src/managers/RenderingManager.d.ts +358 -0
- package/lib/src/managers/RoleManager.d.ts +134 -0
- package/lib/src/managers/SearchManager.d.ts +402 -0
- package/lib/src/managers/ShareManager.d.ts +251 -0
- package/lib/src/managers/TemplateManager.d.ts +176 -0
- package/lib/src/managers/ThemeManager.d.ts +56 -0
- package/lib/src/managers/UserManager.d.ts +480 -0
- package/lib/src/managers/ValidationManager.d.ts +426 -0
- package/lib/src/managers/VariableManager.d.ts +145 -0
- package/lib/src/middleware/csrf.d.ts +3 -0
- package/lib/src/parsers/LinkParser.d.ts +457 -0
- package/lib/src/parsers/MarkupParser.d.ts +769 -0
- package/lib/src/parsers/context/ParseContext.d.ts +314 -0
- package/lib/src/parsers/data/emoji-map.d.ts +18 -0
- package/lib/src/parsers/dom/DOMBuilder.d.ts +210 -0
- package/lib/src/parsers/dom/DOMParser.d.ts +252 -0
- package/lib/src/parsers/dom/Tokenizer.d.ts +358 -0
- package/lib/src/parsers/dom/WikiDocument.d.ts +272 -0
- package/lib/src/parsers/dom/handlers/DOMLinkHandler.d.ts +260 -0
- package/lib/src/parsers/dom/handlers/DOMPluginHandler.d.ts +212 -0
- package/lib/src/parsers/dom/handlers/DOMVariableHandler.d.ts +171 -0
- package/lib/src/parsers/filters/BaseFilter.d.ts +269 -0
- package/lib/src/parsers/filters/FilterChain.d.ts +320 -0
- package/lib/src/parsers/handlers/BaseSyntaxHandler.d.ts +331 -0
- package/lib/src/parsers/handlers/HandlerRegistry.d.ts +225 -0
- package/lib/src/parsers/handlers/JSPWikiPreprocessor.d.ts +89 -0
- package/lib/src/parsers/handlers/LinkParserHandler.d.ts +80 -0
- package/lib/src/parsers/handlers/PluginSyntaxHandler.d.ts +78 -0
- package/lib/src/parsers/handlers/WikiFormHandler.d.ts +149 -0
- package/lib/src/parsers/handlers/WikiTagHandler.d.ts +125 -0
- package/lib/src/parsers/jspwikiTableRow.d.ts +39 -0
- package/lib/src/parsers/styleBlockSyntax.d.ts +14 -0
- package/lib/src/plugins/types.d.ts +79 -0
- package/lib/src/providers/AgentTokenAuthProvider.d.ts +40 -0
- package/lib/src/providers/AuthentikBearerAuthProvider.d.ts +75 -0
- package/lib/src/providers/BaseAttachmentProvider.d.ts +197 -0
- package/lib/src/providers/BaseAuthProvider.d.ts +220 -0
- package/lib/src/providers/BaseCacheProvider.d.ts +140 -0
- package/lib/src/providers/BaseCredentialsProvider.d.ts +84 -0
- package/lib/src/providers/BaseDatabaseProvider.d.ts +22 -0
- package/lib/src/providers/BaseDatabaseProvider.js +12 -0
- package/lib/src/providers/BaseLoggingProvider.d.ts +68 -0
- package/lib/src/providers/BaseLoggingProvider.js +37 -0
- package/lib/src/providers/BaseMediaProvider.d.ts +308 -0
- package/lib/src/providers/BasePageProvider.d.ts +337 -0
- package/lib/src/providers/BaseProvider.d.ts +98 -0
- package/lib/src/providers/BaseProvider.js +74 -0
- package/lib/src/providers/BaseSearchProvider.d.ts +362 -0
- package/lib/src/providers/BasicAttachmentProvider.d.ts +599 -0
- package/lib/src/providers/CloudflareAccessAuthProvider.d.ts +72 -0
- package/lib/src/providers/FileCredentialsProvider.d.ts +33 -0
- package/lib/src/providers/FileJobStateProvider.d.ts +58 -0
- package/lib/src/providers/FileLoggingProvider.d.ts +43 -0
- package/lib/src/providers/FileLoggingProvider.js +120 -0
- package/lib/src/providers/FileOidcAdapter.d.ts +25 -0
- package/lib/src/providers/FileSystemMediaProvider.d.ts +403 -0
- package/lib/src/providers/LunrSearchProvider.d.ts +280 -0
- package/lib/src/providers/MagicLinkAuthProvider.d.ts +125 -0
- package/lib/src/providers/NullCacheProvider.d.ts +72 -0
- package/lib/src/providers/OidcAuthProvider.d.ts +180 -0
- package/lib/src/providers/OidcBearerAuthProvider.d.ts +30 -0
- package/lib/src/providers/PasskeyAuthProvider.d.ts +58 -0
- package/lib/src/providers/PasswordAuthProvider.d.ts +20 -0
- package/lib/src/providers/SqliteDatabaseProvider.d.ts +55 -0
- package/lib/src/providers/SqliteDatabaseProvider.js +90 -0
- package/lib/src/providers/SqliteJobStateProvider.d.ts +41 -0
- package/lib/src/providers/databaseMigrations.d.ts +8 -0
- package/lib/src/providers/databaseMigrations.js +47 -0
- package/lib/src/providers/jobState.d.ts +99 -0
- package/lib/src/providers/lunrQueryToMiniSearch.d.ts +32 -0
- package/lib/src/providers/mediaFilenameDate.d.ts +22 -0
- package/lib/src/providers/sqliteBackup.d.ts +128 -0
- package/lib/src/providers/sqliteBackup.js +365 -0
- package/lib/src/providers/sqliteLocation.d.ts +17 -0
- package/lib/src/providers/sqliteLocation.js +55 -0
- package/lib/src/providers/sqliteMigrations.d.ts +48 -0
- package/lib/src/providers/sqliteMigrations.js +72 -0
- package/lib/src/rendering/githubAlerts.d.ts +22 -0
- package/lib/src/rendering/htmlPolicy.d.ts +76 -0
- package/lib/src/rendering/markdownConverter.d.ts +73 -0
- package/lib/src/security/PolicyDecisionPoint.d.ts +245 -0
- package/lib/src/security/PolicyInformationPoint.d.ts +448 -0
- package/lib/src/security/pageActions.d.ts +40 -0
- package/lib/src/security/permissions.generated.d.ts +78 -0
- package/lib/src/types/Asset.d.ts +414 -0
- package/lib/src/types/Catalog.d.ts +61 -0
- package/lib/src/types/Comment.d.ts +11 -0
- package/lib/src/types/Config.d.ts +388 -0
- package/lib/src/types/Organization.d.ts +78 -0
- package/lib/src/types/OrganizationProvider.d.ts +38 -0
- package/lib/src/types/Page.d.ts +220 -0
- package/lib/src/types/Person.d.ts +56 -0
- package/lib/src/types/PersonProvider.d.ts +25 -0
- package/lib/src/types/Policy.d.ts +139 -0
- package/lib/src/types/Policy.js +17 -0
- package/lib/src/types/Provider.d.ts +810 -0
- package/lib/src/types/Role.d.ts +84 -0
- package/lib/src/types/RoleProvider.d.ts +35 -0
- package/lib/src/types/Schema.d.ts +425 -0
- package/lib/src/types/Share.d.ts +172 -0
- package/lib/src/types/Share.js +81 -0
- package/lib/src/types/User.d.ts +304 -0
- package/lib/src/types/Version.d.ts +189 -0
- package/lib/src/types/WikiEngine.d.ts +128 -0
- package/lib/src/types/express.d.ts +120 -0
- package/lib/src/types/express.js +1 -0
- package/lib/src/types/guards.d.ts +78 -0
- package/lib/src/types/heic-decode.d.ts +16 -0
- package/lib/src/types/index.d.ts +19 -0
- package/lib/src/types/linkedom.d.ts +77 -0
- package/lib/src/types/markdown-it-plugins.d.ts +21 -0
- package/lib/src/utils/DeltaStorage.d.ts +118 -0
- package/lib/src/utils/LocaleUtils.d.ts +105 -0
- package/lib/src/utils/LocaleUtils.js +294 -0
- package/lib/src/utils/PageNameMatcher.d.ts +98 -0
- package/lib/src/utils/PathPreflight.d.ts +38 -0
- package/lib/src/utils/PathPreflight.js +50 -0
- package/lib/src/utils/SectionUtils.d.ts +40 -0
- package/lib/src/utils/addonConfigLayer.d.ts +144 -0
- package/lib/src/utils/addonConfigLayer.js +382 -0
- package/lib/src/utils/addonDatabaseRules.d.ts +25 -0
- package/lib/src/utils/addonDatabaseRules.js +57 -0
- package/lib/src/utils/addonHost.d.ts +51 -0
- package/lib/src/utils/addonHost.js +72 -0
- package/lib/src/utils/addonInstaller.d.ts +109 -0
- package/lib/src/utils/addonLock.d.ts +37 -0
- package/lib/src/utils/addonLock.js +48 -0
- package/lib/src/utils/addonPageSync.d.ts +45 -0
- package/lib/src/utils/addonProvenance.d.ts +48 -0
- package/lib/src/utils/addonTarball.d.ts +41 -0
- package/lib/src/utils/addonsPathResolver.d.ts +76 -0
- package/lib/src/utils/addonsPathResolver.js +129 -0
- package/lib/src/utils/assetMetadataTags.d.ts +66 -0
- package/lib/src/utils/atomicWrite.d.ts +28 -0
- package/lib/src/utils/auditConfigChange.d.ts +57 -0
- package/lib/src/utils/auditEventNames.d.ts +50 -0
- package/lib/src/utils/auditEventNames.generated.d.ts +169 -0
- package/lib/src/utils/auditEventNames.generated.js +174 -0
- package/lib/src/utils/auditEventNames.js +49 -0
- package/lib/src/utils/auditEvents.d.ts +265 -0
- package/lib/src/utils/auditEvents.js +309 -0
- package/lib/src/utils/auditRegistry.d.ts +102 -0
- package/lib/src/utils/auditRegistry.js +168 -0
- package/lib/src/utils/bip39English.d.ts +2 -0
- package/lib/src/utils/configEnvKeys.d.ts +68 -0
- package/lib/src/utils/configFiles.d.ts +74 -0
- package/lib/src/utils/configFiles.js +150 -0
- package/lib/src/utils/delegation.d.ts +48 -0
- package/lib/src/utils/deriveUsername.d.ts +21 -0
- package/lib/src/utils/explainMediaPath.d.ts +123 -0
- package/lib/src/utils/formerTitles.d.ts +69 -0
- package/lib/src/utils/frontmatterAccess.d.ts +54 -0
- package/lib/src/utils/headlessAdminPassword.d.ts +55 -0
- package/lib/src/utils/imageTransform.d.ts +52 -0
- package/lib/src/utils/instanceEnvSecret.d.ts +51 -0
- package/lib/src/utils/jobSlots.d.ts +43 -0
- package/lib/src/utils/keywordNormalizer.d.ts +127 -0
- package/lib/src/utils/logger.d.ts +70 -0
- package/lib/src/utils/logger.js +106 -0
- package/lib/src/utils/magicLinkDeviceState.d.ts +95 -0
- package/lib/src/utils/managerUtils.d.ts +40 -0
- package/lib/src/utils/migrateLegacyPrivateAttachments.d.ts +15 -0
- package/lib/src/utils/orgFilename.d.ts +22 -0
- package/lib/src/utils/pageFeature.d.ts +27 -0
- package/lib/src/utils/pageFrontmatter.d.ts +21 -0
- package/lib/src/utils/pageNotes.d.ts +150 -0
- package/lib/src/utils/pageTitleRule.d.ts +37 -0
- package/lib/src/utils/pageToArticle.d.ts +59 -0
- package/lib/src/utils/pageUrl.d.ts +18 -0
- package/lib/src/utils/passwordChange.d.ts +12 -0
- package/lib/src/utils/passwordHash.d.ts +60 -0
- package/lib/src/utils/permissionCatalog.d.ts +52 -0
- package/lib/src/utils/pluginFormatters.d.ts +452 -0
- package/lib/src/utils/pluginFormatters.js +714 -0
- package/lib/src/utils/privateLinkRewrite.d.ts +42 -0
- package/lib/src/utils/privateStoreAccess.d.ts +57 -0
- package/lib/src/utils/privateStoreAccess.js +65 -0
- package/lib/src/utils/privateStoreCatalogs.d.ts +40 -0
- package/lib/src/utils/privateStoreCrypto.d.ts +127 -0
- package/lib/src/utils/privateStoreDoor.d.ts +181 -0
- package/lib/src/utils/privateStoreExport.d.ts +72 -0
- package/lib/src/utils/privateStoreFiles.d.ts +120 -0
- package/lib/src/utils/privateStoreMeta.d.ts +64 -0
- package/lib/src/utils/privateStoreMigrations.d.ts +37 -0
- package/lib/src/utils/privateStorePath.d.ts +259 -0
- package/lib/src/utils/privateStorePath.js +436 -0
- package/lib/src/utils/privateStoreTakeout.d.ts +76 -0
- package/lib/src/utils/privateStoreUnlock.d.ts +175 -0
- package/lib/src/utils/proxyClaim.d.ts +59 -0
- package/lib/src/utils/proxyClaim.js +30 -0
- package/lib/src/utils/redactPrivateNames.d.ts +21 -0
- package/lib/src/utils/redactPrivateNames.js +89 -0
- package/lib/src/utils/redactSecrets.d.ts +58 -0
- package/lib/src/utils/redactSecrets.js +171 -0
- package/lib/src/utils/renameLinkRewrite.d.ts +112 -0
- package/lib/src/utils/roleGrants.d.ts +35 -0
- package/lib/src/utils/safeRedirect.d.ts +32 -0
- package/lib/src/utils/schedule.d.ts +54 -0
- package/lib/src/utils/secretFileMode.d.ts +17 -0
- package/lib/src/utils/seededShippedPages.d.ts +45 -0
- package/lib/src/utils/sensitiveValues.d.ts +59 -0
- package/lib/src/utils/sensitiveValues.js +106 -0
- package/lib/src/utils/sessionEnd.d.ts +12 -0
- package/lib/src/utils/sessionGeneration.d.ts +24 -0
- package/lib/src/utils/sessionIdle.d.ts +41 -0
- package/lib/src/utils/sessionLimits.d.ts +68 -0
- package/lib/src/utils/shareLockbox.d.ts +64 -0
- package/lib/src/utils/sigstoreTrustedRoot.d.ts +33 -0
- package/lib/src/utils/sniffMime.d.ts +21 -0
- package/lib/src/utils/storeSearchIndex.d.ts +75 -0
- package/lib/src/utils/subjectMayDo.d.ts +21 -0
- package/lib/src/utils/systemCategoryRules.d.ts +30 -0
- package/lib/src/utils/systemCategoryRules.js +41 -0
- package/lib/src/utils/userCreateError.d.ts +62 -0
- package/lib/src/utils/username.d.ts +53 -0
- package/lib/src/utils/vaultUrlRewrite.d.ts +27 -0
- package/lib/src/utils/version.d.ts +84 -0
- package/lib/src/utils/videoFrame.d.ts +21 -0
- package/package.json +54 -3
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WikiContext - Request-scoped context for wiki operations
|
|
3
|
+
*
|
|
4
|
+
* Provides a request-scoped container for all contextual information needed
|
|
5
|
+
* during page rendering, including the engine, current page, user, and
|
|
6
|
+
* request/response objects.
|
|
7
|
+
*/
|
|
8
|
+
import type { PermissionSubject } from '../managers/UserManager.js';
|
|
9
|
+
import { BaseContext } from './BaseContext.js';
|
|
10
|
+
import type { Request, Response } from 'express';
|
|
11
|
+
import type { WikiEngine } from '../types/WikiEngine.js';
|
|
12
|
+
import type PageManager from '../managers/PageManager.js';
|
|
13
|
+
import type RenderingManager from '../managers/RenderingManager.js';
|
|
14
|
+
import type PluginManager from '../managers/PluginManager.js';
|
|
15
|
+
import type VariableManager from '../managers/VariableManager.js';
|
|
16
|
+
import type PolicyInformationPoint from '../security/PolicyInformationPoint.js';
|
|
17
|
+
import { type ThemeInfo } from '../managers/ThemeManager.js';
|
|
18
|
+
import type { PageFrontmatter } from '../types/Page.js';
|
|
19
|
+
/**
|
|
20
|
+
* Request information extracted from Express request
|
|
21
|
+
*/
|
|
22
|
+
export interface RequestInfo {
|
|
23
|
+
/** Accept-Language header */
|
|
24
|
+
acceptLanguage?: string;
|
|
25
|
+
/** User-Agent header */
|
|
26
|
+
userAgent?: string;
|
|
27
|
+
/** Client IP address */
|
|
28
|
+
clientIp?: string;
|
|
29
|
+
/** Referer header */
|
|
30
|
+
referer?: string;
|
|
31
|
+
/** Session ID */
|
|
32
|
+
sessionId?: string;
|
|
33
|
+
/** Parsed query-string parameters (e.g. `?page=2&sort=count-desc`) */
|
|
34
|
+
query?: Record<string, string>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* User preferences for date/time formatting, locale, etc.
|
|
38
|
+
*/
|
|
39
|
+
export interface UserPreferences {
|
|
40
|
+
/** User's preferred locale (e.g., 'en-US') */
|
|
41
|
+
locale?: string;
|
|
42
|
+
/** User's timezone (e.g., 'America/New_York') */
|
|
43
|
+
timezone?: string;
|
|
44
|
+
/** Date format preference (e.g., 'yyyy-MM-dd') */
|
|
45
|
+
dateFormat?: string;
|
|
46
|
+
/** Additional preferences */
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* User context - session or authentication context
|
|
51
|
+
*/
|
|
52
|
+
export interface UserContext extends PermissionSubject {
|
|
53
|
+
/** User display name */
|
|
54
|
+
displayName?: string;
|
|
55
|
+
/** Alias for isAuthenticated (legacy templates) */
|
|
56
|
+
authenticated?: boolean;
|
|
57
|
+
/** User preferences for formatting, locale, etc. */
|
|
58
|
+
preferences?: UserPreferences;
|
|
59
|
+
/** Shorthand for preferences.locale */
|
|
60
|
+
locale?: string;
|
|
61
|
+
/** Shorthand for preferences.timezone */
|
|
62
|
+
timezone?: string;
|
|
63
|
+
/**
|
|
64
|
+
* A test account (#1805), from the account record. An attribute for the host
|
|
65
|
+
* and its add-ons to enforce their own rules from; no policy reads it.
|
|
66
|
+
*/
|
|
67
|
+
isTest?: boolean;
|
|
68
|
+
/** Additional user context data */
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Theme context — active theme identity and user display preference
|
|
73
|
+
*/
|
|
74
|
+
export interface ThemeContext {
|
|
75
|
+
/** Active theme folder name (e.g. 'default', 'flatly') */
|
|
76
|
+
activeTheme: string;
|
|
77
|
+
/** Metadata from the active theme's theme.json */
|
|
78
|
+
themeInfo: ThemeInfo | null;
|
|
79
|
+
/** User's light/dark/system display preference */
|
|
80
|
+
displayTheme: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Page context for rendering
|
|
84
|
+
*/
|
|
85
|
+
export interface PageContext {
|
|
86
|
+
/** Name of the current page */
|
|
87
|
+
pageName: string | null;
|
|
88
|
+
/** User context/session */
|
|
89
|
+
userContext: UserContext | null;
|
|
90
|
+
/** Request information */
|
|
91
|
+
requestInfo: RequestInfo;
|
|
92
|
+
/** Theme context */
|
|
93
|
+
themeContext?: ThemeContext;
|
|
94
|
+
/** Page front matter metadata */
|
|
95
|
+
pageMetadata?: PageFrontmatter | null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Options for MarkupParser.parse()
|
|
99
|
+
*/
|
|
100
|
+
export interface ParseOptions {
|
|
101
|
+
/** Page-specific context */
|
|
102
|
+
pageContext: PageContext;
|
|
103
|
+
/** Wiki engine instance */
|
|
104
|
+
engine: WikiEngine;
|
|
105
|
+
/**
|
|
106
|
+
* Optional reference to the parent WikiContext (#629). When present,
|
|
107
|
+
* ParseContext getters delegate user/page-data lookups to it instead of
|
|
108
|
+
* reading the constructor-time `pageContext` snapshot, keeping the
|
|
109
|
+
* WikiContext as the single source of truth across the parse run.
|
|
110
|
+
*/
|
|
111
|
+
wikiContext?: unknown;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Options for WikiContext constructor
|
|
115
|
+
*/
|
|
116
|
+
export interface WikiContextOptions {
|
|
117
|
+
/** Context type (VIEW, EDIT, PREVIEW, etc.) */
|
|
118
|
+
context?: string;
|
|
119
|
+
/** Name of the page */
|
|
120
|
+
pageName?: string;
|
|
121
|
+
/** Page content (markdown) */
|
|
122
|
+
content?: string;
|
|
123
|
+
/** The caller's subject. Required (#1399) — see the constructor. */
|
|
124
|
+
userContext: UserContext;
|
|
125
|
+
/** Express request object */
|
|
126
|
+
request?: Request;
|
|
127
|
+
/** Express response object */
|
|
128
|
+
response?: Response;
|
|
129
|
+
/** Active theme folder name (e.g. 'default', 'flatly') */
|
|
130
|
+
activeTheme?: string;
|
|
131
|
+
/** Metadata from theme.json */
|
|
132
|
+
themeInfo?: ThemeInfo | null;
|
|
133
|
+
/** Page front matter metadata — must be set before ACL checks */
|
|
134
|
+
pageMetadata?: PageFrontmatter;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Context type constants
|
|
138
|
+
*/
|
|
139
|
+
export interface ContextTypes {
|
|
140
|
+
/** Viewing a page */
|
|
141
|
+
VIEW: 'view';
|
|
142
|
+
/** Editing a page */
|
|
143
|
+
EDIT: 'edit';
|
|
144
|
+
/** Previewing page changes */
|
|
145
|
+
PREVIEW: 'preview';
|
|
146
|
+
/** Viewing page diff */
|
|
147
|
+
DIFF: 'diff';
|
|
148
|
+
/** Viewing page information/metadata */
|
|
149
|
+
INFO: 'info';
|
|
150
|
+
/** No specific page context */
|
|
151
|
+
NONE: 'none';
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* WikiContext - Encapsulates the context of a single request or rendering operation
|
|
155
|
+
*
|
|
156
|
+
* Inspired by JSPWiki's WikiContext, this class provides a request-scoped container
|
|
157
|
+
* for all contextual information needed during page rendering, including the engine,
|
|
158
|
+
* current page, user, request/response objects, and manager references.
|
|
159
|
+
*
|
|
160
|
+
* @class WikiContext
|
|
161
|
+
*
|
|
162
|
+
* @property {WikiEngine} engine - The wiki engine instance
|
|
163
|
+
* @property {string} context - The rendering context (VIEW, EDIT, PREVIEW, etc.)
|
|
164
|
+
* @property {string|null} pageName - Name of the current page
|
|
165
|
+
* @property {string|null} content - Page content (markdown)
|
|
166
|
+
* @property {UserContext|null} userContext - Current user context/session
|
|
167
|
+
* @property {Request|null} request - Express request object
|
|
168
|
+
* @property {Response|null} response - Express response object
|
|
169
|
+
* @property {PageManager} pageManager - Reference to PageManager
|
|
170
|
+
* @property {RenderingManager} renderingManager - Reference to RenderingManager
|
|
171
|
+
* @property {PluginManager} pluginManager - Reference to PluginManager
|
|
172
|
+
* @property {VariableManager} variableManager - Reference to VariableManager
|
|
173
|
+
* @property {PolicyInformationPoint} policyInformationPoint - Reference to PolicyInformationPoint
|
|
174
|
+
* @property {MarkdownConverter} _fallbackConverter - Fallback markdown converter (#1273)
|
|
175
|
+
*
|
|
176
|
+
* @see {@link WikiEngine} for the main engine
|
|
177
|
+
* @see {@link RenderingManager} for rendering operations
|
|
178
|
+
*/
|
|
179
|
+
declare class WikiContext extends BaseContext {
|
|
180
|
+
/**
|
|
181
|
+
* Context type constants for different rendering modes
|
|
182
|
+
*
|
|
183
|
+
* @static
|
|
184
|
+
* @readonly
|
|
185
|
+
*/
|
|
186
|
+
static readonly CONTEXT: ContextTypes;
|
|
187
|
+
/** The wiki engine instance */
|
|
188
|
+
readonly engine: WikiEngine;
|
|
189
|
+
/** The rendering context type */
|
|
190
|
+
readonly context: string;
|
|
191
|
+
/** Name of the current page */
|
|
192
|
+
readonly pageName: string | null;
|
|
193
|
+
/** Page content (markdown) */
|
|
194
|
+
readonly content: string | null;
|
|
195
|
+
/** Current user context/session */
|
|
196
|
+
/**
|
|
197
|
+
* The caller's subject, as the middleware wrote it.
|
|
198
|
+
*
|
|
199
|
+
* #1399: stored once, on BaseContext, and read here under the name the
|
|
200
|
+
* render path and the templates already use. A UserContext IS a
|
|
201
|
+
* PermissionSubject plus display-only extras, so this is a view of the same
|
|
202
|
+
* object — never a copy, which is what would drop `privateStoreHandle` and
|
|
203
|
+
* make a sealed page vanish for its owner (#1382, #1173).
|
|
204
|
+
*/
|
|
205
|
+
get userContext(): UserContext;
|
|
206
|
+
/** Express request object */
|
|
207
|
+
readonly request: Request | null;
|
|
208
|
+
/** Express response object */
|
|
209
|
+
readonly response: Response | null;
|
|
210
|
+
/** Reference to PageManager */
|
|
211
|
+
readonly pageManager: PageManager;
|
|
212
|
+
/** Reference to RenderingManager */
|
|
213
|
+
readonly renderingManager: RenderingManager;
|
|
214
|
+
/** Reference to PluginManager */
|
|
215
|
+
readonly pluginManager: PluginManager;
|
|
216
|
+
/** Reference to VariableManager */
|
|
217
|
+
readonly variableManager: VariableManager;
|
|
218
|
+
/** Reference to PolicyInformationPoint */
|
|
219
|
+
readonly policyInformationPoint: PolicyInformationPoint;
|
|
220
|
+
/** Override passed via WikiContextOptions; bypasses the lazy resolver */
|
|
221
|
+
private readonly _activeThemeOverride?;
|
|
222
|
+
/** Override passed via WikiContextOptions; bypasses the lazy resolver */
|
|
223
|
+
private readonly _themeInfoOverride?;
|
|
224
|
+
/** Cached resolved activeTheme — populated on first read of `activeTheme` */
|
|
225
|
+
private _resolvedActiveTheme?;
|
|
226
|
+
/** Cached resolved themeInfo — populated on first read of `themeInfo` */
|
|
227
|
+
private _resolvedThemeInfo?;
|
|
228
|
+
/** Page front matter metadata — carries audience/access/user-keywords for ACL evaluation */
|
|
229
|
+
readonly pageMetadata: PageFrontmatter | null;
|
|
230
|
+
/** Fallback markdown converter */
|
|
231
|
+
private readonly _fallbackConverter;
|
|
232
|
+
/**
|
|
233
|
+
* Per-instance memoization for hasPermission(action) results (#636).
|
|
234
|
+
* The WikiContext is request-scoped, so this cache lifetime is the request.
|
|
235
|
+
* We cache the Promise (not the resolved value) so concurrent callers all
|
|
236
|
+
* await the same in-flight evaluation.
|
|
237
|
+
*/
|
|
238
|
+
/**
|
|
239
|
+
* Per-instance memoization for canAccess(action) results, keyed by
|
|
240
|
+
* `${action}:${pageName}` to handle the rare case where a request mutates
|
|
241
|
+
* pageName mid-handler (#636).
|
|
242
|
+
*/
|
|
243
|
+
private readonly _canAccessCache;
|
|
244
|
+
/**
|
|
245
|
+
* Creates a new WikiContext instance
|
|
246
|
+
*
|
|
247
|
+
* @constructor
|
|
248
|
+
* @param {WikiEngine} engine - The wiki engine instance
|
|
249
|
+
* @param {WikiContextOptions} [options={}] - Context options
|
|
250
|
+
* @throws {Error} If engine is not provided
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* const context = new WikiContext(engine, {
|
|
254
|
+
* context: WikiContext.CONTEXT.VIEW,
|
|
255
|
+
* pageName: 'Main',
|
|
256
|
+
* userContext: req.session.user,
|
|
257
|
+
* request: req,
|
|
258
|
+
* response: res
|
|
259
|
+
* });
|
|
260
|
+
*/
|
|
261
|
+
constructor(engine: WikiEngine, options: WikiContextOptions);
|
|
262
|
+
/**
|
|
263
|
+
* Returns the current rendering context type
|
|
264
|
+
*
|
|
265
|
+
* @returns {string} The context type (VIEW, EDIT, PREVIEW, etc.)
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* if (context.getContext() === WikiContext.CONTEXT.EDIT) {
|
|
269
|
+
* // Show edit-specific UI
|
|
270
|
+
* }
|
|
271
|
+
*/
|
|
272
|
+
getContext(): string;
|
|
273
|
+
/**
|
|
274
|
+
* Static role check for callers that don't have a full WikiContext.
|
|
275
|
+
*
|
|
276
|
+
* Useful for hot-path middleware (maintenance gate, /metrics) that runs on
|
|
277
|
+
* every request and shouldn't pay the cost of constructing a WikiContext just
|
|
278
|
+
* to ask "is this user an admin?". Same semantics as the instance `hasRole`.
|
|
279
|
+
*
|
|
280
|
+
* @param userContext - userContext-like object (or null/undefined)
|
|
281
|
+
* @param names - Role names (matches if user has at least one)
|
|
282
|
+
* @returns true if userContext.roles contains any of the given names
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* if (WikiContext.userHasRole(req.userContext, 'admin')) { ... }
|
|
286
|
+
*/
|
|
287
|
+
static userHasRole(userContext: {
|
|
288
|
+
roles?: string[];
|
|
289
|
+
} | null | undefined, ...names: string[]): boolean;
|
|
290
|
+
/**
|
|
291
|
+
* Returns true if the current user is allowed to perform the given action
|
|
292
|
+
* on the current page — or on a different page when `pageNameOverride` is
|
|
293
|
+
* passed (#714 Slice B, the cross-page check used by linked-page visibility
|
|
294
|
+
* filters and serveAttachment's owning-page lookup).
|
|
295
|
+
*
|
|
296
|
+
* Delegates to {@link PolicyInformationPoint.checkPagePermissionWithContext} for the
|
|
297
|
+
* current page (the no-override fast path) and {@link PolicyInformationPoint.canUserAccessPage}
|
|
298
|
+
* for cross-page checks (#714 Slice B — loads the target page's metadata
|
|
299
|
+
* internally and runs the same evaluator).
|
|
300
|
+
*
|
|
301
|
+
* Returns false if the WikiContext has no pageName (and no override) or no
|
|
302
|
+
* PolicyInformationPoint.
|
|
303
|
+
*
|
|
304
|
+
* @param {string} action - Page action (e.g., 'view', 'edit', 'delete')
|
|
305
|
+
* @param {string} [pageNameOverride] - When set, check access on this page
|
|
306
|
+
* instead of `this.pageName`. Used for cross-page checks (e.g., a private
|
|
307
|
+
* attachment whose owning page is not the current request's page).
|
|
308
|
+
* @returns {Promise<boolean>} true if access is allowed
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* if (await wikiContext.canAccess('edit')) { ... }
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* // Cross-page check (Slice B): can the current user view the page that
|
|
315
|
+
* // owns this attachment? Used at WikiRoutes.serveAttachment to enforce
|
|
316
|
+
* // private-page access for attachments whose owning page is private.
|
|
317
|
+
* if (!(await wikiContext.canAccess('view', owningPageName))) {
|
|
318
|
+
* return 403;
|
|
319
|
+
* }
|
|
320
|
+
*/
|
|
321
|
+
canAccess(action: string, pageNameOverride?: string): Promise<boolean>;
|
|
322
|
+
/**
|
|
323
|
+
* Would the current user be allowed this action on the current page — asked
|
|
324
|
+
* only to decide whether to SHOW something (#1668): `<wiki:If
|
|
325
|
+
* hasPermission:edit>` hiding a block. An affordance, never a door.
|
|
326
|
+
*
|
|
327
|
+
* The same evaluator as {@link canAccess}'s same-page path, through
|
|
328
|
+
* {@link PolicyInformationPoint.pageAffordance}, so the two always agree; it
|
|
329
|
+
* writes no audit record. Hiding content is not an attempt, and asking the
|
|
330
|
+
* door here wrote an `authorization-deny` for every anonymous view of a page
|
|
331
|
+
* using the tag. Anything that then ACTS asks {@link canAccess}.
|
|
332
|
+
*
|
|
333
|
+
* @param action - Page action (e.g., 'view', 'edit')
|
|
334
|
+
* @returns true if the door would allow the action
|
|
335
|
+
*/
|
|
336
|
+
mayShow(action: string): Promise<boolean>;
|
|
337
|
+
/**
|
|
338
|
+
* Active theme folder name (e.g. 'default', 'flatly').
|
|
339
|
+
*
|
|
340
|
+
* Lazy: resolves from ConfigurationManager on first access and caches the
|
|
341
|
+
* result. Permission-only callers (route handlers that just call hasRole /
|
|
342
|
+
* hasPermission) never trigger the lookup.
|
|
343
|
+
*/
|
|
344
|
+
get activeTheme(): string;
|
|
345
|
+
/**
|
|
346
|
+
* Metadata from the active theme's theme.json.
|
|
347
|
+
*
|
|
348
|
+
* Lazy: triggers theme resolution on first access (uses the engine-wide
|
|
349
|
+
* `getThemeManager` cache). Returns the override if one was passed via
|
|
350
|
+
* WikiContextOptions.
|
|
351
|
+
*/
|
|
352
|
+
get themeInfo(): ThemeInfo | null;
|
|
353
|
+
/**
|
|
354
|
+
* Returns the user's display theme preference ('light' | 'dark' | 'system')
|
|
355
|
+
* Derived from userContext.preferences['display.theme']; defaults to 'system'.
|
|
356
|
+
*/
|
|
357
|
+
get displayTheme(): string;
|
|
358
|
+
/**
|
|
359
|
+
* Returns a ThemeContext snapshot for use in parse options and variable context
|
|
360
|
+
*/
|
|
361
|
+
get themeContext(): ThemeContext;
|
|
362
|
+
/**
|
|
363
|
+
* Renders the provided markdown content through the full rendering pipeline
|
|
364
|
+
*
|
|
365
|
+
* This method uses the MarkupParser for advanced parsing with plugin support,
|
|
366
|
+
* variable expansion, and multi-phase processing. Falls back to plain markdown-it
|
|
367
|
+
* conversion if the parser is unavailable.
|
|
368
|
+
*
|
|
369
|
+
* @async
|
|
370
|
+
* @param {string} [content=this.content] - The markdown content to render
|
|
371
|
+
* @returns {Promise<string>} The rendered HTML
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* const html = await context.renderMarkdown('# Hello World');
|
|
375
|
+
* // Returns: '<h1>Hello World</h1>'
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* // With plugins and variables
|
|
379
|
+
* const html = await context.renderMarkdown('[{CurrentTimePlugin}]');
|
|
380
|
+
* // Returns expanded plugin output
|
|
381
|
+
*/
|
|
382
|
+
renderMarkdown(content?: string | null): Promise<string>;
|
|
383
|
+
/**
|
|
384
|
+
* Creates the options object needed for the MarkupParser
|
|
385
|
+
*
|
|
386
|
+
* Builds a comprehensive options object containing page context, user context,
|
|
387
|
+
* request information, and engine reference for use during parsing.
|
|
388
|
+
*
|
|
389
|
+
* @returns {ParseOptions} Parse options object
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* const options = context.toParseOptions();
|
|
393
|
+
* const html = await parser.parse(content, options);
|
|
394
|
+
*/
|
|
395
|
+
toParseOptions(): ParseOptions;
|
|
396
|
+
/**
|
|
397
|
+
* Converts the current context to a VariableContext for variable expansion
|
|
398
|
+
*
|
|
399
|
+
* @returns {VariableContext} Variable context for use with VariableManager
|
|
400
|
+
* @private
|
|
401
|
+
*/
|
|
402
|
+
private toVariableContext;
|
|
403
|
+
}
|
|
404
|
+
export default WikiContext;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boot actions — what the instance does to itself at start-up, attributed
|
|
3
|
+
* (#1197, #631, security-posture P1).
|
|
4
|
+
*
|
|
5
|
+
* Boot-time code runs with no request and therefore no actor. Most of it only
|
|
6
|
+
* wires — registers handlers, reads configuration, builds objects — and needs
|
|
7
|
+
* none. Some of it ACTS: the required-pages seed writes pages, the bootstrap
|
|
8
|
+
* admin is created, the delete-retention purge destroys pages, the session
|
|
9
|
+
* secret is written into `.env`. Those writes reached the audit trail with
|
|
10
|
+
* nobody attached, or did not reach it at all, because `AuditManager` is the
|
|
11
|
+
* last manager to initialise and the sink did not yet exist when they ran.
|
|
12
|
+
*
|
|
13
|
+
* Two things live here:
|
|
14
|
+
*
|
|
15
|
+
* - `systemContext(engine, reason)` — the `JobContext` an acting boot path
|
|
16
|
+
* runs under: the system principal named in `.env` (#631), origin `boot`,
|
|
17
|
+
* and a stated reason. A path that only wires never asks for one.
|
|
18
|
+
* - `recordSystemAction(engine, ctx, event)` — record an audit event under
|
|
19
|
+
* that context. If the audit sink is up it records now; if not, the event
|
|
20
|
+
* waits in the boot ledger and `AuditManager.initialize` drains it once the
|
|
21
|
+
* sink exists. Either way the record names who (the principal), from where
|
|
22
|
+
* (`origin`) and why (`reason`), so "the system did this" is a statement,
|
|
23
|
+
* not a guess.
|
|
24
|
+
*
|
|
25
|
+
* The ledger is a module singleton on purpose: it is not a request identity
|
|
26
|
+
* (the thing the framework refuses to make ambient), it is a queue for a
|
|
27
|
+
* window in which there is nowhere else to put the record.
|
|
28
|
+
*/
|
|
29
|
+
import { type JobContext } from './JobContext.js';
|
|
30
|
+
import { type AuditEvent, type AuditEventSink } from '../utils/auditEvents.js';
|
|
31
|
+
type EngineLike = {
|
|
32
|
+
getManager: (name: string) => unknown;
|
|
33
|
+
} | null | undefined;
|
|
34
|
+
/** The system principal named in `.env` (#631), or the fallback where no UserManager answers. */
|
|
35
|
+
export declare function systemPrincipalOf(engine: EngineLike): string;
|
|
36
|
+
/** The context an acting boot path runs under. `reason` says what and why, for the record. */
|
|
37
|
+
export declare function systemContext(engine: EngineLike, reason: string): JobContext;
|
|
38
|
+
/** The same for a scheduled tick (#1196): origin `schedule`. */
|
|
39
|
+
export declare function scheduleContext(engine: EngineLike, reason: string): JobContext;
|
|
40
|
+
/** The audit fields a system context contributes: who, from where, why. */
|
|
41
|
+
export declare function attributedTo(ctx: JobContext): {
|
|
42
|
+
user: string;
|
|
43
|
+
actor?: string;
|
|
44
|
+
ipAddress: string | undefined;
|
|
45
|
+
metadata: Record<string, unknown>;
|
|
46
|
+
};
|
|
47
|
+
export type SystemActionEvent = Omit<AuditEvent, 'user' | 'ipAddress'> & {
|
|
48
|
+
ipAddress?: undefined;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Record an action taken under a system context — now if the audit sink is
|
|
52
|
+
* up, otherwise into the boot ledger for `drainBootActions` to flush.
|
|
53
|
+
*/
|
|
54
|
+
export declare function recordSystemAction(engine: EngineLike, ctx: JobContext, event: SystemActionEvent): Promise<void>;
|
|
55
|
+
/** Flush the boot ledger into the sink. Called once by `AuditManager.initialize`. Returns how many. */
|
|
56
|
+
export declare function drainBootActions(sink: AuditEventSink): Promise<number>;
|
|
57
|
+
/** What is waiting. For tests and diagnostics. */
|
|
58
|
+
export declare function pendingBootActions(): ReadonlyArray<{
|
|
59
|
+
context: JobContext;
|
|
60
|
+
event: AuditEvent;
|
|
61
|
+
}>;
|
|
62
|
+
/** Empty the ledger without recording. For tests. */
|
|
63
|
+
export declare function resetBootActions(): void;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boot actions — what the instance does to itself at start-up, attributed
|
|
3
|
+
* (#1197, #631, security-posture P1).
|
|
4
|
+
*
|
|
5
|
+
* Boot-time code runs with no request and therefore no actor. Most of it only
|
|
6
|
+
* wires — registers handlers, reads configuration, builds objects — and needs
|
|
7
|
+
* none. Some of it ACTS: the required-pages seed writes pages, the bootstrap
|
|
8
|
+
* admin is created, the delete-retention purge destroys pages, the session
|
|
9
|
+
* secret is written into `.env`. Those writes reached the audit trail with
|
|
10
|
+
* nobody attached, or did not reach it at all, because `AuditManager` is the
|
|
11
|
+
* last manager to initialise and the sink did not yet exist when they ran.
|
|
12
|
+
*
|
|
13
|
+
* Two things live here:
|
|
14
|
+
*
|
|
15
|
+
* - `systemContext(engine, reason)` — the `JobContext` an acting boot path
|
|
16
|
+
* runs under: the system principal named in `.env` (#631), origin `boot`,
|
|
17
|
+
* and a stated reason. A path that only wires never asks for one.
|
|
18
|
+
* - `recordSystemAction(engine, ctx, event)` — record an audit event under
|
|
19
|
+
* that context. If the audit sink is up it records now; if not, the event
|
|
20
|
+
* waits in the boot ledger and `AuditManager.initialize` drains it once the
|
|
21
|
+
* sink exists. Either way the record names who (the principal), from where
|
|
22
|
+
* (`origin`) and why (`reason`), so "the system did this" is a statement,
|
|
23
|
+
* not a guess.
|
|
24
|
+
*
|
|
25
|
+
* The ledger is a module singleton on purpose: it is not a request identity
|
|
26
|
+
* (the thing the framework refuses to make ambient), it is a queue for a
|
|
27
|
+
* window in which there is nowhere else to put the record.
|
|
28
|
+
*/
|
|
29
|
+
import { jobContextFromSystem, jobContextFromSchedule } from './JobContext.js';
|
|
30
|
+
import { recordAuditEvent } from '../utils/auditEvents.js';
|
|
31
|
+
import logger from '../utils/logger.js';
|
|
32
|
+
import { proxyAttribution } from '../utils/proxyClaim.js';
|
|
33
|
+
/** The name a booted instance carries when no principal can be resolved — only reachable in fixtures. */
|
|
34
|
+
const FALLBACK_PRINCIPAL = 'system';
|
|
35
|
+
/** The system principal named in `.env` (#631), or the fallback where no UserManager answers. */
|
|
36
|
+
export function systemPrincipalOf(engine) {
|
|
37
|
+
// #1431 step 13: the subject's attributes, the system principal among them, are the PIP's.
|
|
38
|
+
const pip = engine?.getManager('PolicyInformationPoint');
|
|
39
|
+
try {
|
|
40
|
+
return pip?.systemPrincipalName?.() ?? FALLBACK_PRINCIPAL;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return FALLBACK_PRINCIPAL;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** The context an acting boot path runs under. `reason` says what and why, for the record. */
|
|
47
|
+
export function systemContext(engine, reason) {
|
|
48
|
+
return jobContextFromSystem(systemPrincipalOf(engine), reason);
|
|
49
|
+
}
|
|
50
|
+
/** The same for a scheduled tick (#1196): origin `schedule`. */
|
|
51
|
+
export function scheduleContext(engine, reason) {
|
|
52
|
+
return jobContextFromSchedule(systemPrincipalOf(engine), reason);
|
|
53
|
+
}
|
|
54
|
+
/** The audit fields a system context contributes: who, from where, why. */
|
|
55
|
+
export function attributedTo(ctx) {
|
|
56
|
+
// #1762 slice 3: work queued under a proxy grant names the person who
|
|
57
|
+
// queued it, as the request itself would have.
|
|
58
|
+
const { metadata: proxyMeta, ...proxy } = proxyAttribution(ctx.viaProxy);
|
|
59
|
+
return {
|
|
60
|
+
user: ctx.username,
|
|
61
|
+
...proxy,
|
|
62
|
+
ipAddress: ctx.ipAddress || undefined,
|
|
63
|
+
metadata: {
|
|
64
|
+
origin: ctx.origin,
|
|
65
|
+
reason: ctx.reason ?? null,
|
|
66
|
+
requestedAt: ctx.requestedAt,
|
|
67
|
+
...proxyMeta
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const ledger = [];
|
|
72
|
+
function stamp(ctx, event) {
|
|
73
|
+
const who = attributedTo(ctx);
|
|
74
|
+
return {
|
|
75
|
+
...event,
|
|
76
|
+
...who,
|
|
77
|
+
ipAddress: undefined,
|
|
78
|
+
metadata: { ...who.metadata, ...(event.metadata ?? {}) }
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Record an action taken under a system context — now if the audit sink is
|
|
83
|
+
* up, otherwise into the boot ledger for `drainBootActions` to flush.
|
|
84
|
+
*/
|
|
85
|
+
export async function recordSystemAction(engine, ctx, event) {
|
|
86
|
+
const stamped = stamp(ctx, event);
|
|
87
|
+
const sink = engine?.getManager('AuditManager');
|
|
88
|
+
if (sink && typeof sink.logAuditEvent === 'function') {
|
|
89
|
+
await recordAuditEvent(sink, stamped, (err) => logger.warn(`[bootActions] Audit record failed for ${stamped.eventType} (${ctx.reason ?? 'no reason'}): ${String(err)}`));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
ledger.push({ context: ctx, event: stamped });
|
|
93
|
+
}
|
|
94
|
+
/** Flush the boot ledger into the sink. Called once by `AuditManager.initialize`. Returns how many. */
|
|
95
|
+
export async function drainBootActions(sink) {
|
|
96
|
+
const pending = ledger.splice(0, ledger.length);
|
|
97
|
+
for (const { context, event } of pending) {
|
|
98
|
+
await recordAuditEvent(sink, event, (err) => logger.warn(`[bootActions] Deferred audit record failed for ${event.eventType} (${context.reason ?? 'no reason'}): ${String(err)}`));
|
|
99
|
+
}
|
|
100
|
+
if (pending.length > 0)
|
|
101
|
+
logger.info(`[bootActions] Recorded ${pending.length} boot-time action(s) deferred until the audit sink was up`);
|
|
102
|
+
return pending.length;
|
|
103
|
+
}
|
|
104
|
+
/** What is waiting. For tests and diagnostics. */
|
|
105
|
+
export function pendingBootActions() {
|
|
106
|
+
return ledger;
|
|
107
|
+
}
|
|
108
|
+
/** Empty the ledger without recording. For tests. */
|
|
109
|
+
export function resetBootActions() {
|
|
110
|
+
ledger.length = 0;
|
|
111
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML to Markdown Converter
|
|
3
|
+
*
|
|
4
|
+
* Converts HTML web pages to Markdown for import into ngdpbase.
|
|
5
|
+
* Uses linkedom for DOM parsing/content extraction and turndown for HTML-to-Markdown conversion.
|
|
6
|
+
* Extracts metadata from HTML head, meta tags, Open Graph, and Schema.org markup.
|
|
7
|
+
*
|
|
8
|
+
* @module HtmlConverter
|
|
9
|
+
*/
|
|
10
|
+
import { IContentConverter, ConversionResult } from './IContentConverter.js';
|
|
11
|
+
/**
|
|
12
|
+
* HTML to Markdown converter
|
|
13
|
+
*
|
|
14
|
+
* Implements IContentConverter for importing web pages as wiki pages.
|
|
15
|
+
* Extracts the primary article content, strips boilerplate, and converts to Markdown.
|
|
16
|
+
*/
|
|
17
|
+
declare class HtmlConverter implements IContentConverter {
|
|
18
|
+
readonly formatId = "html";
|
|
19
|
+
readonly formatName = "HTML Web Page";
|
|
20
|
+
readonly fileExtensions: string[];
|
|
21
|
+
private turndown;
|
|
22
|
+
constructor();
|
|
23
|
+
/**
|
|
24
|
+
* Convert HTML content to Markdown
|
|
25
|
+
*
|
|
26
|
+
* @param content - Raw HTML string
|
|
27
|
+
* @returns ConversionResult with Markdown content, metadata, and warnings
|
|
28
|
+
*/
|
|
29
|
+
convert(content: string): ConversionResult;
|
|
30
|
+
/**
|
|
31
|
+
* Check if this converter can handle the given content
|
|
32
|
+
*/
|
|
33
|
+
canHandle(content: string, filename: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Extract metadata from HTML head and Schema.org markup
|
|
36
|
+
*/
|
|
37
|
+
private extractMetadata;
|
|
38
|
+
/**
|
|
39
|
+
* Get content of a meta tag by name or property
|
|
40
|
+
*/
|
|
41
|
+
private getMetaContent;
|
|
42
|
+
/**
|
|
43
|
+
* Extract Schema.org JSON-LD data if present
|
|
44
|
+
*/
|
|
45
|
+
private extractJsonLd;
|
|
46
|
+
/**
|
|
47
|
+
* Remove unwanted elements from the document
|
|
48
|
+
*/
|
|
49
|
+
private removeElements;
|
|
50
|
+
/**
|
|
51
|
+
* Extract the primary content from the document
|
|
52
|
+
* Tries article, main, [role=main], .content, then falls back to body
|
|
53
|
+
*/
|
|
54
|
+
private extractContent;
|
|
55
|
+
/**
|
|
56
|
+
* Convert a numbered references section into Markdown footnote definitions.
|
|
57
|
+
*
|
|
58
|
+
* Detects patterns like:
|
|
59
|
+
* ## References
|
|
60
|
+
* 1. [url](url)
|
|
61
|
+
* 2. [url](url)
|
|
62
|
+
*
|
|
63
|
+
* And converts to:
|
|
64
|
+
* ----
|
|
65
|
+
* [^1]: url
|
|
66
|
+
* [^2]: url
|
|
67
|
+
*/
|
|
68
|
+
private convertReferencesToFootnotes;
|
|
69
|
+
}
|
|
70
|
+
export default HtmlConverter;
|