@jwilleke/ngdpbase-types 5.21.0 → 5.22.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/lib/packages/ngdpbase-types/index.d.ts +5 -0
- package/lib/src/mail/MailProvider.d.ts +2 -0
- package/lib/src/managers/AddonsManager.d.ts +3 -3
- package/lib/src/managers/AttachmentManager.d.ts +64 -12
- package/lib/src/managers/AuthManager.d.ts +24 -4
- package/lib/src/managers/BackgroundJobManager.d.ts +65 -1
- package/lib/src/managers/BaseManager.d.ts +14 -0
- package/lib/src/managers/BaseManager.js +9 -0
- package/lib/src/managers/CommentManager.d.ts +10 -1
- package/lib/src/managers/DatabaseManager.d.ts +24 -17
- package/lib/src/managers/DatabaseManager.js +72 -29
- package/lib/src/managers/EmailManager.d.ts +42 -0
- package/lib/src/managers/FootnoteManager.d.ts +10 -1
- package/lib/src/managers/NotificationManager.d.ts +13 -0
- package/lib/src/managers/OrganizationManager.d.ts +40 -6
- package/lib/src/managers/PersonManager.d.ts +106 -9
- package/lib/src/managers/RoleManager.d.ts +19 -1
- package/lib/src/managers/UserManager.d.ts +15 -0
- package/lib/src/providers/BaseAttachmentProvider.d.ts +14 -0
- package/lib/src/providers/BasicAttachmentProvider.d.ts +26 -2
- package/lib/src/providers/SqliteDatabaseProvider.d.ts +7 -0
- package/lib/src/providers/SqliteDatabaseProvider.js +16 -0
- package/lib/src/providers/SqliteJobStateProvider.d.ts +10 -0
- package/lib/src/providers/attachmentFilesBackup.d.ts +52 -0
- package/lib/src/providers/sqliteBackup.d.ts +6 -0
- package/lib/src/providers/sqliteBackup.js +16 -6
- package/lib/src/security/permissions.generated.d.ts +4 -0
- package/lib/src/types/Asset.d.ts +10 -0
- package/lib/src/types/Config.d.ts +11 -0
- package/lib/src/types/Organization.d.ts +7 -0
- package/lib/src/types/Person.d.ts +27 -3
- package/lib/src/types/PersonProvider.d.ts +6 -0
- package/lib/src/types/WikiEngine.d.ts +9 -21
- package/lib/src/utils/addonPageSync.d.ts +24 -0
- package/lib/src/utils/administrators.d.ts +21 -0
- package/lib/src/utils/auditEventNames.generated.d.ts +4 -0
- package/lib/src/utils/auditEventNames.generated.js +4 -0
- package/lib/src/utils/backupCrypto.d.ts +28 -0
- package/lib/src/utils/backupKey.d.ts +23 -0
- package/lib/src/utils/backupKey.js +37 -0
- package/lib/src/utils/contactAccess.d.ts +58 -0
- package/lib/src/utils/databaseKey.d.ts +7 -0
- package/lib/src/utils/databaseKey.js +7 -0
- package/lib/src/utils/directoryBackup.d.ts +78 -0
- package/lib/src/utils/emailForLog.d.ts +20 -0
- package/lib/src/utils/maintenanceState.d.ts +153 -0
- package/lib/src/utils/privateStoreTakeout.d.ts +2 -2
- package/lib/src/utils/siteRestore.d.ts +110 -0
- package/lib/src/utils/siteRestore.js +309 -0
- package/lib/src/utils/treeArchive.d.ts +44 -0
- package/lib/src/utils/username.d.ts +7 -1
- package/package.json +1 -1
- package/lib/src/utils/startupState.d.ts +0 -65
- package/lib/src/utils/startupState.js +0 -115
|
@@ -307,12 +307,7 @@ export function applyStagedRestore(applicationFile, allowed) {
|
|
|
307
307
|
move(f, `${f}.incomplete`);
|
|
308
308
|
return { applied: [], refused: `staged database files with no restore manifest (an interrupted staging): ${leftovers.map((f) => path.basename(f)).join(', ')} — set aside as *.incomplete` };
|
|
309
309
|
}
|
|
310
|
-
const setAside = (reason) =>
|
|
311
|
-
for (const f of stray())
|
|
312
|
-
move(f, `${f}.incomplete`);
|
|
313
|
-
move(manifestFile, `${manifestFile}.incomplete`);
|
|
314
|
-
return { applied: [], refused: reason };
|
|
315
|
-
};
|
|
310
|
+
const setAside = (reason) => setAsideStagedRestore(applicationFile, reason);
|
|
316
311
|
let manifest;
|
|
317
312
|
try {
|
|
318
313
|
manifest = JSON.parse(readFileSync(manifestFile, 'utf8'));
|
|
@@ -351,6 +346,21 @@ export function applyStagedRestore(applicationFile, allowed) {
|
|
|
351
346
|
unlinkSync(manifestFile);
|
|
352
347
|
return { applied };
|
|
353
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Set a staged restore aside without applying any of it (#1876): every
|
|
351
|
+
* `*.db.staged` beside the application database and the manifest become
|
|
352
|
+
* `*.incomplete`. Used when the site restore it belongs to is not applied.
|
|
353
|
+
*/
|
|
354
|
+
export function setAsideStagedRestore(applicationFile, reason) {
|
|
355
|
+
const manifestFile = manifestPath(applicationFile);
|
|
356
|
+
const dir = path.dirname(applicationFile);
|
|
357
|
+
const staged = existsSync(dir) ? readdirSync(dir).filter((f) => f.endsWith('.db.staged')).map((f) => path.join(dir, f)) : [];
|
|
358
|
+
for (const f of staged)
|
|
359
|
+
move(f, `${f}.incomplete`);
|
|
360
|
+
if (existsSync(manifestFile))
|
|
361
|
+
move(manifestFile, `${manifestFile}.incomplete`);
|
|
362
|
+
return { applied: [], refused: reason };
|
|
363
|
+
}
|
|
354
364
|
/** A rename; a copy and unlink when the two paths are on different devices. */
|
|
355
365
|
function move(from, to) {
|
|
356
366
|
try {
|
|
@@ -22,6 +22,10 @@ export type CorePermission =
|
|
|
22
22
|
| 'comment-create'
|
|
23
23
|
/** Change any configuration setting, and download a backup (#1525). Admin only by default; asks for a fresh sign-in when listed in ngdpbase.auth.step-up */
|
|
24
24
|
| 'config-manage'
|
|
25
|
+
/** Create, edit, delete and link contacts: persons (with or without an account) and organizations, and a person's affiliations, through PersonManager and OrganizationManager (#1930). Reading them is contact-read. Admins by default; an add-on grants it to its own roles in its own policy */
|
|
26
|
+
| 'contact-manage'
|
|
27
|
+
/** List, search and view contacts: persons (with or without an account) and organizations, and their affiliations, through PersonManager and OrganizationManager, and the /admin/contacts and /admin/organizations views (#1930). Admins and demo admins by default; an add-on grants it to its own roles in its own policy */
|
|
28
|
+
| 'contact-read'
|
|
25
29
|
/** Browse and view the media library (not delegated to anonymous visitors) */
|
|
26
30
|
| 'media-read'
|
|
27
31
|
/** Create new pages */
|
package/lib/src/types/Asset.d.ts
CHANGED
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
* while AttachmentManager / MediaManager remain thin wrappers.
|
|
7
7
|
*/
|
|
8
8
|
import type { ActorContext } from '../context/ActorContext.js';
|
|
9
|
+
/**
|
|
10
|
+
* What an attachment record says when it was stored with no uploader, in the
|
|
11
|
+
* pool's `author.name`, and what `uploadedBy` shows for a record with none.
|
|
12
|
+
* Only records written before #1926 carry it: a new upload names its
|
|
13
|
+
* uploader's username or is refused. Not a user; the files layer reads it as
|
|
14
|
+
* "no owner" (#1852).
|
|
15
|
+
*/
|
|
16
|
+
export declare const UNKNOWN_UPLOADER = "Unknown";
|
|
9
17
|
/**
|
|
10
18
|
* Capabilities that an AssetProvider may declare.
|
|
11
19
|
* Used to advertise which optional operations the provider supports.
|
|
@@ -207,6 +215,8 @@ export interface AssetRecord {
|
|
|
207
215
|
author?: string;
|
|
208
216
|
/** ISO 8601 timestamp of the last metadata or file modification — schema.org/dateModified */
|
|
209
217
|
dateModified?: string;
|
|
218
|
+
/** Username of whoever last changed it, when the provider records one — schema.org/editor */
|
|
219
|
+
editor?: string;
|
|
210
220
|
/** Licensing and rights information */
|
|
211
221
|
usageRights?: AssetUsageRights;
|
|
212
222
|
/** Download counts and access statistics */
|
|
@@ -116,6 +116,11 @@ export interface WikiConfig {
|
|
|
116
116
|
*/
|
|
117
117
|
'ngdpbase.auth.throttle.max-lock-minutes': number;
|
|
118
118
|
'ngdpbase.mail.rate-limit.enabled': boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Outbound email failures: one administrator notice per this many minutes,
|
|
121
|
+
* counting every failure inside it (#1916). Default: 60.
|
|
122
|
+
*/
|
|
123
|
+
'ngdpbase.mail.failure-notice.window-minutes': number;
|
|
119
124
|
/**
|
|
120
125
|
* Anti-spam: max submissions per IP per `window-minutes` window before
|
|
121
126
|
* the 429 trips (#670 Phase E). Default: 5.
|
|
@@ -305,6 +310,12 @@ export interface ApplicationOrganizationConfig {
|
|
|
305
310
|
'ngdpbase.application.persons.provider.default': string;
|
|
306
311
|
/** Active Person provider class (lowercased; falls back to .default) */
|
|
307
312
|
'ngdpbase.application.persons.provider': string;
|
|
313
|
+
/** #1930: the most results `PersonManager.search` returns when the caller gives no limit */
|
|
314
|
+
'ngdpbase.application.persons.search.limit': number;
|
|
315
|
+
/** #1930: minutes the emailed "Is this you?" sign-up link stays usable */
|
|
316
|
+
'ngdpbase.application.persons.link-offer.ttl-minutes': number;
|
|
317
|
+
/** #1930: the most results `OrganizationManager.search` returns when the caller gives no limit */
|
|
318
|
+
'ngdpbase.application.organization.search.limit': number;
|
|
308
319
|
/** Storage directory for OrganizationRole JSON files (one per (org, namedPosition) pair) */
|
|
309
320
|
'ngdpbase.application.roles.storagedir': string;
|
|
310
321
|
/** Default Role provider class (lowercased) */
|
|
@@ -71,6 +71,13 @@ export interface Organization {
|
|
|
71
71
|
/** Allow extension fields (additionalProperty, etc.) */
|
|
72
72
|
[key: string]: unknown;
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* What a caller gives `OrganizationManager.create` (#1930): the fields, with
|
|
76
|
+
* `@id` optional (it defaults to the `url`, else a new `urn:uuid:`).
|
|
77
|
+
*/
|
|
78
|
+
export type OrganizationInput = Partial<Organization> & {
|
|
79
|
+
name: string;
|
|
80
|
+
};
|
|
74
81
|
/**
|
|
75
82
|
* Patch shape for update operations.
|
|
76
83
|
* `@context`/`@type` are immutable; `@id` cannot be changed via update.
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* (where the uuid matches the v4 segment of `@id`).
|
|
7
7
|
*
|
|
8
8
|
* `@id` uses the urn:uuid:<v4> form because persons typically lack a
|
|
9
|
-
* canonical web URL. `identifier`
|
|
10
|
-
*
|
|
9
|
+
* canonical web URL. `identifier` is the person's account (`User.username`)
|
|
10
|
+
* when they have one, and `person:<uuid>` when they do not (#1930) — a form
|
|
11
|
+
* no username may take (`ACCOUNTLESS_PERSON_PREFIX`, `src/utils/username.ts`).
|
|
11
12
|
*
|
|
12
13
|
* No embedded role-records — those live in the future person-contacts
|
|
13
14
|
* addon (#602) and are folded in at JSON-LD export time.
|
|
@@ -15,6 +16,18 @@
|
|
|
15
16
|
* @see https://schema.org/Person
|
|
16
17
|
*/
|
|
17
18
|
import type { PostalAddress, ContactPoint } from './Organization.js';
|
|
19
|
+
/**
|
|
20
|
+
* One organization a person is affiliated with (#1930): schema.org
|
|
21
|
+
* `affiliation`, with the person's role or title there when one is known.
|
|
22
|
+
* The organization is named by its `@id`; OrganizationManager lists an
|
|
23
|
+
* organization's people by reading these, so the link is stored once, here.
|
|
24
|
+
*/
|
|
25
|
+
export interface PersonAffiliation {
|
|
26
|
+
/** The organization's `@id`. */
|
|
27
|
+
organization: string;
|
|
28
|
+
/** The person's role or title there (schema.org `roleName`), when known. */
|
|
29
|
+
role?: string;
|
|
30
|
+
}
|
|
18
31
|
/**
|
|
19
32
|
* Canonical Person record.
|
|
20
33
|
*
|
|
@@ -26,7 +39,7 @@ export interface Person {
|
|
|
26
39
|
'@type': 'Person';
|
|
27
40
|
/** urn:uuid:<v4> */
|
|
28
41
|
'@id': string;
|
|
29
|
-
/**
|
|
42
|
+
/** The account's username, or `person:<uuid>` for a person with no account (#1930). */
|
|
30
43
|
identifier: string;
|
|
31
44
|
/** Display name */
|
|
32
45
|
name?: string;
|
|
@@ -46,6 +59,8 @@ export interface Person {
|
|
|
46
59
|
image?: string;
|
|
47
60
|
/** Other URLs that identify this person (LinkedIn, GitHub, etc.) */
|
|
48
61
|
sameAs?: string[];
|
|
62
|
+
/** Organizations this person is affiliated with, each with an optional role (#1930). */
|
|
63
|
+
affiliation?: PersonAffiliation[];
|
|
49
64
|
/** Allow extension fields (additionalProperty, etc.) */
|
|
50
65
|
[key: string]: unknown;
|
|
51
66
|
}
|
|
@@ -54,3 +69,12 @@ export interface Person {
|
|
|
54
69
|
* `@context`/`@type` are immutable; `@id` and `identifier` cannot be changed via update.
|
|
55
70
|
*/
|
|
56
71
|
export type PersonUpdate = Partial<Omit<Person, '@context' | '@type' | '@id' | 'identifier'>>;
|
|
72
|
+
/**
|
|
73
|
+
* What a caller gives `PersonManager.create` (#1930): the person's fields.
|
|
74
|
+
* `identifier` is left out for a person with no account (one is generated);
|
|
75
|
+
* UserManager passes the account's username when it creates the person for a
|
|
76
|
+
* new account.
|
|
77
|
+
*/
|
|
78
|
+
export type PersonInput = PersonUpdate & {
|
|
79
|
+
identifier?: string;
|
|
80
|
+
};
|
|
@@ -18,6 +18,12 @@ export interface PersonProvider extends BaseProvider {
|
|
|
18
18
|
getByIdentifier(identifier: string): Promise<Person | null>;
|
|
19
19
|
/** Persist a new Person. Returns the stored record. */
|
|
20
20
|
create(person: Person): Promise<Person>;
|
|
21
|
+
/**
|
|
22
|
+
* Write the whole record in place of the one with the same `@id` (#1930).
|
|
23
|
+
* The only write that may change `identifier`: PersonManager uses it to join
|
|
24
|
+
* a person to an account.
|
|
25
|
+
*/
|
|
26
|
+
replace(person: Person): Promise<Person>;
|
|
21
27
|
/** Apply a partial update by `@id`. Returns the updated record, or null if not found. */
|
|
22
28
|
update(id: string, patch: PersonUpdate): Promise<Person | null>;
|
|
23
29
|
/** Delete by `@id`. Returns true if a record was removed. */
|
|
@@ -8,6 +8,7 @@ import { WikiConfig } from './Config.js';
|
|
|
8
8
|
import type { Logger } from 'winston';
|
|
9
9
|
import type { Application, Request, RequestHandler, Router, RouterOptions } from 'express';
|
|
10
10
|
import type express from 'express';
|
|
11
|
+
import type { MaintenanceState } from '../utils/maintenanceState.js';
|
|
11
12
|
/**
|
|
12
13
|
* All known manager names as a union type
|
|
13
14
|
* Use with getManager() for type-safe access when combined with explicit type parameter
|
|
@@ -95,28 +96,15 @@ export interface WikiEngine {
|
|
|
95
96
|
*/
|
|
96
97
|
shutdown(): Promise<void>;
|
|
97
98
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* Also a site-critical add-on that did not load (#1883, operator
|
|
106
|
-
* 2026-10-18): its fix may lie outside the UI (a key in the instance .env),
|
|
107
|
-
* and the admin notification says so.
|
|
108
|
-
*/
|
|
109
|
-
blockConfiguration(reason: string, options?: {
|
|
110
|
-
publicMessage?: string;
|
|
111
|
-
}): void;
|
|
112
|
-
/** Configuration values that could not be used, in the order found (#1152). */
|
|
113
|
-
getBlockingConditions(): readonly string[];
|
|
114
|
-
/**
|
|
115
|
-
* What visitors see in place of the reasons, when a reason was recorded with
|
|
116
|
-
* a `publicMessage` (#1883: a site-critical add-on that did not load); null
|
|
117
|
-
* when every reason may be shown.
|
|
99
|
+
* Whether the site is in maintenance mode, and why (#1906): the one door.
|
|
100
|
+
* A manager that needs the site closed calls `maintenance.enter(reason,
|
|
101
|
+
* { message?, estimatedDuration? })`, and `maintenance.leave(reason)` when
|
|
102
|
+
* the reason clears. Reasons are for administrators only; visitors get
|
|
103
|
+
* `maintenance.visitorView(configManager)`. Replaces `blockConfiguration`
|
|
104
|
+
* (#1152), still recorded rather than thrown so `initialize()` finishes and
|
|
105
|
+
* `/admin`, `/login` and `/logout` stay reachable.
|
|
118
106
|
*/
|
|
119
|
-
|
|
107
|
+
readonly maintenance: MaintenanceState;
|
|
120
108
|
/**
|
|
121
109
|
* Get all registered manager names
|
|
122
110
|
* @returns Array of manager names
|
|
@@ -31,6 +31,30 @@ export declare function evaluateSeededAddonPage(args: {
|
|
|
31
31
|
liveContent: string;
|
|
32
32
|
storedHash: string | undefined;
|
|
33
33
|
}): SeededAddonPageStatus;
|
|
34
|
+
/**
|
|
35
|
+
* How a shipped item's sync status reads on an admin screen: the status words
|
|
36
|
+
* and the edit protection of Admin → Required Pages, which every screen that
|
|
37
|
+
* syncs shipped content shares (`views/_sync-status.ejs`, `views/_sync-button.ejs`;
|
|
38
|
+
* shipped forms, #1918).
|
|
39
|
+
*
|
|
40
|
+
* - `status` — `modified` when the live copy differs from what ships,
|
|
41
|
+
* `current` when it is the same.
|
|
42
|
+
* - `userModified` — edited on this site: Sync does not replace it; Force Sync
|
|
43
|
+
* does, after a confirm.
|
|
44
|
+
*/
|
|
45
|
+
export interface SyncRowState {
|
|
46
|
+
status: 'current' | 'modified';
|
|
47
|
+
userModified: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The one mapping from `evaluateSeededAddonPage`'s answer to the admin screen's
|
|
51
|
+
* words (#1918). `userModifiedFlag` is a page's explicit `user-modified`
|
|
52
|
+
* frontmatter, which marks it edited even when the hash cannot tell.
|
|
53
|
+
*
|
|
54
|
+
* @param seedStatus - `evaluateSeededAddonPage`'s answer for the live copy
|
|
55
|
+
* @param userModifiedFlag - The live copy is explicitly marked edited
|
|
56
|
+
*/
|
|
57
|
+
export declare function syncRowState(seedStatus: SeededAddonPageStatus, userModifiedFlag?: boolean): SyncRowState;
|
|
34
58
|
/**
|
|
35
59
|
* Default edit access for a page ngdpbase ships (#971, #1411): a `general`
|
|
36
60
|
* page is instance-owned and gets no stamp; any other category — system,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who an administrator notification goes to.
|
|
3
|
+
*
|
|
4
|
+
* __An administrator is whoever holds `admin-system`__, asked per user through
|
|
5
|
+
* the policy (#1431 7b) — never a role name. Used by every report that must
|
|
6
|
+
* reach administrators and nobody else: a damaged page (#1431 step 7) and
|
|
7
|
+
* failing outbound email (#1916).
|
|
8
|
+
*
|
|
9
|
+
* An empty answer means "nobody to tell", and the caller must then log only:
|
|
10
|
+
* an empty `targetUsers` list means ALL users in NotificationManager, which
|
|
11
|
+
* would announce an operator problem to every reader.
|
|
12
|
+
*
|
|
13
|
+
* Null when the managers needed to answer are not registered (tests, a
|
|
14
|
+
* half-booted engine) — the caller treats that like "nobody to tell".
|
|
15
|
+
*/
|
|
16
|
+
type EngineLike = {
|
|
17
|
+
getManager: (name: string) => unknown;
|
|
18
|
+
} | null | undefined;
|
|
19
|
+
/** Usernames of every user who holds `admin-system`; null when it cannot be asked. */
|
|
20
|
+
export declare function administratorUsernames(engine: EngineLike): Promise<string[] | null>;
|
|
21
|
+
export {};
|
|
@@ -36,6 +36,8 @@ export declare const AUDIT_EVENT: {
|
|
|
36
36
|
readonly BACKUP_CREATE: "backup-create";
|
|
37
37
|
/** A restore of a backup's databases started from Admin → Backup: which backup and who asked; recorded before the fresh backup and the staging, which cannot proceed without it (#1723) */
|
|
38
38
|
readonly BACKUP_RESTORE: "backup-restore";
|
|
39
|
+
/** A staged restore (site or databases-only) put in place at start: which backup, when it was taken, who started the restore and which parts were applied; written into the restored audit log, so the log itself says a restore happened (#1876) */
|
|
40
|
+
readonly BACKUP_RESTORE_APPLIED: "backup-restore-applied";
|
|
39
41
|
/** A staged database restore cancelled before the restart applied it: which backup, who staged it and who cancelled; recorded first, which cannot proceed without it (#1723) */
|
|
40
42
|
readonly BACKUP_RESTORE_CANCEL: "backup-restore-cancel";
|
|
41
43
|
/** A staged database restore replaced by another before the restart applied it: which backup replaced which, and who asked; recorded first, which cannot proceed without it (#1723) */
|
|
@@ -48,6 +50,8 @@ export declare const AUDIT_EVENT: {
|
|
|
48
50
|
readonly CONFIG_CHANGE: "config-change";
|
|
49
51
|
/** Every custom configuration value discarded; recorded before the reset, which cannot proceed without it */
|
|
50
52
|
readonly CONFIG_RESET: "config-reset";
|
|
53
|
+
/** Contact created, changed, deleted or linked to an account; metadata names the kind (person or organization), the operation and the fields changed, never their values */
|
|
54
|
+
readonly CONTACT_MANAGE: "contact-manage";
|
|
51
55
|
/** A page's footnote list changed — action add, import, transfer, update or delete; page content written on someone's behalf (#1233) */
|
|
52
56
|
readonly FOOTNOTE_EDIT: "footnote-edit";
|
|
53
57
|
/** A background job finished successfully */
|
|
@@ -43,6 +43,8 @@ export const AUDIT_EVENT = {
|
|
|
43
43
|
BACKUP_CREATE: 'backup-create',
|
|
44
44
|
/** A restore of a backup's databases started from Admin → Backup: which backup and who asked; recorded before the fresh backup and the staging, which cannot proceed without it (#1723) */
|
|
45
45
|
BACKUP_RESTORE: 'backup-restore',
|
|
46
|
+
/** A staged restore (site or databases-only) put in place at start: which backup, when it was taken, who started the restore and which parts were applied; written into the restored audit log, so the log itself says a restore happened (#1876) */
|
|
47
|
+
BACKUP_RESTORE_APPLIED: 'backup-restore-applied',
|
|
46
48
|
/** A staged database restore cancelled before the restart applied it: which backup, who staged it and who cancelled; recorded first, which cannot proceed without it (#1723) */
|
|
47
49
|
BACKUP_RESTORE_CANCEL: 'backup-restore-cancel',
|
|
48
50
|
/** A staged database restore replaced by another before the restart applied it: which backup replaced which, and who asked; recorded first, which cannot proceed without it (#1723) */
|
|
@@ -55,6 +57,8 @@ export const AUDIT_EVENT = {
|
|
|
55
57
|
CONFIG_CHANGE: 'config-change',
|
|
56
58
|
/** Every custom configuration value discarded; recorded before the reset, which cannot proceed without it */
|
|
57
59
|
CONFIG_RESET: 'config-reset',
|
|
60
|
+
/** Contact created, changed, deleted or linked to an account; metadata names the kind (person or organization), the operation and the fields changed, never their values */
|
|
61
|
+
CONTACT_MANAGE: 'contact-manage',
|
|
58
62
|
/** A page's footnote list changed — action add, import, transfer, update or delete; page content written on someone's behalf (#1233) */
|
|
59
63
|
FOOTNOTE_EDIT: 'footnote-edit',
|
|
60
64
|
/** A background job finished successfully */
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Transform } from 'node:stream';
|
|
2
|
+
/** The first bytes of every encrypted backup file. */
|
|
3
|
+
export declare const BACKUP_FILE_MAGIC: Buffer<ArrayBuffer>;
|
|
4
|
+
/** What an encrypted backup file's name ends with. */
|
|
5
|
+
export declare const ENCRYPTED_SUFFIX = ".enc";
|
|
6
|
+
/** A backup file made under a different backup key than the one set now. */
|
|
7
|
+
export declare class BackupKeyMismatchError extends Error {
|
|
8
|
+
readonly fileFingerprint: string;
|
|
9
|
+
readonly keyFingerprint: string;
|
|
10
|
+
constructor(fileFingerprint: string, keyFingerprint: string);
|
|
11
|
+
}
|
|
12
|
+
/** Whether these bytes (a file's first) are an encrypted backup file. */
|
|
13
|
+
export declare function isEncryptedBackup(head: Buffer): boolean;
|
|
14
|
+
/** Whether the file on disk is an encrypted backup file, read from its first bytes only. */
|
|
15
|
+
export declare function fileIsEncrypted(file: string): Promise<boolean>;
|
|
16
|
+
/** A stream that encrypts what is written to it under `backupKey`. */
|
|
17
|
+
export declare function encryptStream(backupKey: string): Transform;
|
|
18
|
+
/**
|
|
19
|
+
* A stream that decrypts an encrypted backup file written to it. Fails —
|
|
20
|
+
* naming why — on a file that is not one, a different backup key
|
|
21
|
+
* ({@link BackupKeyMismatchError}), any record that does not verify, and a
|
|
22
|
+
* file cut short or with bytes after its last record.
|
|
23
|
+
*/
|
|
24
|
+
export declare function decryptStream(backupKey: string): Transform;
|
|
25
|
+
/** Encrypt a whole buffer (the backup document, already in memory). */
|
|
26
|
+
export declare function encryptBuffer(data: Buffer, backupKey: string): Promise<Buffer>;
|
|
27
|
+
/** Decrypt a whole buffer. */
|
|
28
|
+
export declare function decryptBuffer(data: Buffer, backupKey: string): Promise<Buffer>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The environment variable holding the key every backup is encrypted under.
|
|
3
|
+
* Its own secret, not the database key: the copy that travels and the copy
|
|
4
|
+
* that stays should not fall to the same compromise. Never a config key.
|
|
5
|
+
*/
|
|
6
|
+
export declare const BACKUP_KEY_ENV = "NGDPBASE_BACKUP_KEY";
|
|
7
|
+
/**
|
|
8
|
+
* A short fingerprint of a backup key (#1723, D3): the first 16 hex digits of
|
|
9
|
+
* an HMAC of a fixed label under the key. Recorded in each backup so a restore
|
|
10
|
+
* under another key says so plainly; it never reveals the key.
|
|
11
|
+
*/
|
|
12
|
+
export declare function backupKeyFingerprint(key: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* How every part left out of a backup for want of the key says so: the
|
|
15
|
+
* message starts with this. BackupManager recognises such a part by it
|
|
16
|
+
* (`isLeftOutForNoKey`): those are covered by its banner and one-time
|
|
17
|
+
* notice, never a notice per backup (operator, #1912).
|
|
18
|
+
*/
|
|
19
|
+
export declare const LEFT_OUT_FOR_NO_KEY = "NGDPBASE_BACKUP_KEY is not set, so ";
|
|
20
|
+
/** Whether a backup warning or error says a part was left out only because there is no backup key. */
|
|
21
|
+
export declare function isLeftOutForNoKey(message: string): boolean;
|
|
22
|
+
/** The backup key as set now, trimmed; '' when there is none. Read at use, never cached. */
|
|
23
|
+
export declare function currentBackupKey(): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The backup key (#1723, #1561, #1876): the one secret every encrypted part of
|
|
3
|
+
* a backup is made under — the database files (SQLCipher, `sqliteBackup.ts`),
|
|
4
|
+
* and the backup document, the file archives and the credentials store
|
|
5
|
+
* (`backupCrypto.ts`). One declaration here; DatabaseManager and the file
|
|
6
|
+
* parts read it from this module.
|
|
7
|
+
*/
|
|
8
|
+
import { createHmac } from 'node:crypto';
|
|
9
|
+
/**
|
|
10
|
+
* The environment variable holding the key every backup is encrypted under.
|
|
11
|
+
* Its own secret, not the database key: the copy that travels and the copy
|
|
12
|
+
* that stays should not fall to the same compromise. Never a config key.
|
|
13
|
+
*/
|
|
14
|
+
export const BACKUP_KEY_ENV = 'NGDPBASE_BACKUP_KEY';
|
|
15
|
+
/**
|
|
16
|
+
* A short fingerprint of a backup key (#1723, D3): the first 16 hex digits of
|
|
17
|
+
* an HMAC of a fixed label under the key. Recorded in each backup so a restore
|
|
18
|
+
* under another key says so plainly; it never reveals the key.
|
|
19
|
+
*/
|
|
20
|
+
export function backupKeyFingerprint(key) {
|
|
21
|
+
return createHmac('sha256', key).update('ngdpbase backup key fingerprint v1').digest('hex').slice(0, 16);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* How every part left out of a backup for want of the key says so: the
|
|
25
|
+
* message starts with this. BackupManager recognises such a part by it
|
|
26
|
+
* (`isLeftOutForNoKey`): those are covered by its banner and one-time
|
|
27
|
+
* notice, never a notice per backup (operator, #1912).
|
|
28
|
+
*/
|
|
29
|
+
export const LEFT_OUT_FOR_NO_KEY = `${BACKUP_KEY_ENV} is not set, so `;
|
|
30
|
+
/** Whether a backup warning or error says a part was left out only because there is no backup key. */
|
|
31
|
+
export function isLeftOutForNoKey(message) {
|
|
32
|
+
return message.startsWith(LEFT_OUT_FOR_NO_KEY);
|
|
33
|
+
}
|
|
34
|
+
/** The backup key as set now, trimmed; '' when there is none. Read at use, never cached. */
|
|
35
|
+
export function currentBackupKey() {
|
|
36
|
+
return (process.env[BACKUP_KEY_ENV] ?? '').trim();
|
|
37
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contacts door's one decision and its one record (#1930).
|
|
3
|
+
*
|
|
4
|
+
* PersonManager and OrganizationManager are the enforcement points for
|
|
5
|
+
* contacts. Both ask the PDP the same two questions with the caller's
|
|
6
|
+
* context: `contact-read` to list, search or view, `contact-manage` to
|
|
7
|
+
* create, change, delete or link; and both record each change as the
|
|
8
|
+
* `contact-manage` audit event. That rule lives here once, so the two doors
|
|
9
|
+
* cannot drift (operator, 2026-10-20).
|
|
10
|
+
*
|
|
11
|
+
* A refusal is thrown as {@link ContactRefusedError}, carrying the decision.
|
|
12
|
+
* A route turns it into the answer with `ApiContext.enforceDeny(err.permission,
|
|
13
|
+
* err.decision)`, the one place a refusal is shaped (#1431); the door never
|
|
14
|
+
* builds an HTTP answer itself.
|
|
15
|
+
*/
|
|
16
|
+
import { type ActorContext } from '../context/ActorContext.js';
|
|
17
|
+
import type { CorePermission } from '../security/permissions.generated.js';
|
|
18
|
+
import type { Decision } from '../types/Policy.js';
|
|
19
|
+
type EngineLike = {
|
|
20
|
+
getManager: <T = unknown>(name: string) => T | null | undefined;
|
|
21
|
+
};
|
|
22
|
+
/** What a contacts door asks: `read` to list, search or view; `manage` to change. */
|
|
23
|
+
export declare const CONTACT_PERMISSION: {
|
|
24
|
+
readonly read: "contact-read";
|
|
25
|
+
readonly manage: "contact-manage";
|
|
26
|
+
};
|
|
27
|
+
/** A contacts door said no. `permission` is what was refused; `decision` is the PDP's answer. */
|
|
28
|
+
export declare class ContactRefusedError extends Error {
|
|
29
|
+
readonly permission: string;
|
|
30
|
+
readonly decision: Decision;
|
|
31
|
+
constructor(permission: string, decision: Decision);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Throws {@link ContactRefusedError} unless `ctx` may do `kind` (`read` asks
|
|
35
|
+
* `contact-read`, `manage` asks `contact-manage`), and each of `also` (a link
|
|
36
|
+
* to an account also asks `user-edit`). A missing context or decision point
|
|
37
|
+
* refuses: closed, never open.
|
|
38
|
+
*/
|
|
39
|
+
export declare function requireContactPermission(engine: EngineLike, ctx: ActorContext, kind: keyof typeof CONTACT_PERMISSION, also?: readonly CorePermission[]): Promise<void>;
|
|
40
|
+
/** What a contacts record says was done. Names fields, never their values. */
|
|
41
|
+
export interface ContactChange {
|
|
42
|
+
kind: 'person' | 'organization';
|
|
43
|
+
operation: 'create' | 'update' | 'delete' | 'link';
|
|
44
|
+
id: string;
|
|
45
|
+
fields?: string[];
|
|
46
|
+
/** For a link: the account joined to the person. */
|
|
47
|
+
account?: string;
|
|
48
|
+
/** For a link: how it was confirmed, `admin` or `email`. */
|
|
49
|
+
via?: 'admin' | 'email';
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Record a contacts change as `contact-manage`, under the caller's context.
|
|
53
|
+
* `continue`: a lost record is counted, the change stands. A system context
|
|
54
|
+
* goes through `recordSystemAction`, so the bootstrap admin's person, made
|
|
55
|
+
* before the audit sink is up, is recorded once it is.
|
|
56
|
+
*/
|
|
57
|
+
export declare function recordContactChange(engine: EngineLike, ctx: ActorContext, change: ContactChange): Promise<void>;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The environment variable holding the SQLCipher key (#1536). Never a config
|
|
3
|
+
* key: config is readable from the admin screens. Declared here, with no
|
|
4
|
+
* dependencies, so the boot (`bootstrap-env.ts`) can name it without loading
|
|
5
|
+
* DatabaseManager; DatabaseManager re-exports it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DATABASE_KEY_ENV = "NGDPBASE_DATABASE_KEY";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The environment variable holding the SQLCipher key (#1536). Never a config
|
|
3
|
+
* key: config is readable from the admin screens. Declared here, with no
|
|
4
|
+
* dependencies, so the boot (`bootstrap-env.ts`) can name it without loading
|
|
5
|
+
* DatabaseManager; DatabaseManager re-exports it.
|
|
6
|
+
*/
|
|
7
|
+
export const DATABASE_KEY_ENV = 'NGDPBASE_DATABASE_KEY';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { BackupData, ManagerBackupOptions, ManagerRestoreOptions } from '../managers/BaseManager.js';
|
|
2
|
+
import { siteRestoreFile, type PartOutcome } from './siteRestore.js';
|
|
3
|
+
/** A folder part's `data` in the backup document. */
|
|
4
|
+
export interface DirectoryBackupData {
|
|
5
|
+
format: 1;
|
|
6
|
+
/** The archive beside the document: `<stem>.<part>.tar`, or `.tar.enc` when encrypted. */
|
|
7
|
+
archive: string;
|
|
8
|
+
files: number;
|
|
9
|
+
bytes: number;
|
|
10
|
+
/** `backupKeyFingerprint()` of the key the archive is encrypted under; absent when it is not encrypted. */
|
|
11
|
+
keyFingerprint?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Whether `name` is a bare archive name in the backup directory, never a path. */
|
|
14
|
+
export declare function isArchiveName(name: unknown): name is string;
|
|
15
|
+
/**
|
|
16
|
+
* The name and key for one archive of a backup: encrypted under the backup
|
|
17
|
+
* key when it is set (#1561), plain otherwise. BackupManager says, once per
|
|
18
|
+
* backup, that a backup without the key is not encrypted.
|
|
19
|
+
*/
|
|
20
|
+
export declare function archiveTarget(stem: string, part: string): {
|
|
21
|
+
archive: string;
|
|
22
|
+
backupKey?: string;
|
|
23
|
+
keyFingerprint?: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The key to read an archive of a backup with, checked against the
|
|
27
|
+
* fingerprint the backup recorded: a backup made under another key is
|
|
28
|
+
* refused before anything is staged. None for a backup that was not
|
|
29
|
+
* encrypted, which is then read as the plain archive it says it is.
|
|
30
|
+
*/
|
|
31
|
+
export declare function archiveReadKey(manager: string, data: {
|
|
32
|
+
keyFingerprint?: string;
|
|
33
|
+
}): string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Back the folder up beside the document BackupManager is writing. Throws
|
|
36
|
+
* outside BackupManager: the files go beside a document, never into it.
|
|
37
|
+
* `exclude` leaves out a path relative to the folder (posix form).
|
|
38
|
+
*/
|
|
39
|
+
export declare function backupDirectoryPart(manager: string, part: string, folder: string | null, options?: ManagerBackupOptions, extra?: {
|
|
40
|
+
exclude?: (relative: string) => boolean;
|
|
41
|
+
}): Promise<BackupData>;
|
|
42
|
+
/**
|
|
43
|
+
* Stage the folder from a backup for the next start: the archive is
|
|
44
|
+
* extracted to `<folder>.staged`, and the swap recorded in the site restore.
|
|
45
|
+
* Throws — staging nothing — outside a site restore, for a backup without
|
|
46
|
+
* this part, or for an archive that is missing, unsafe, or under another key.
|
|
47
|
+
*/
|
|
48
|
+
export declare function stageDirectoryPart(manager: string, folder: string | null, backupData: BackupData, options?: ManagerRestoreOptions): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Put a staged restore of the folder in place, at start, before the manager
|
|
51
|
+
* reads it. Loud when something was staged but not applied.
|
|
52
|
+
*/
|
|
53
|
+
export declare function applyDirectoryPartAtStart(manager: string, folder: string, configManager: Parameters<typeof siteRestoreFile>[0]): PartOutcome | null;
|
|
54
|
+
/**
|
|
55
|
+
* Back one file up beside the document, encrypted under the backup key, as
|
|
56
|
+
* `<stem>.<part>.tar.enc`. With `requireKey` and no key the file is left out:
|
|
57
|
+
* `data` is null and a warning says why, so BackupManager reports the backup
|
|
58
|
+
* incomplete (#1876: the credentials store is never in a backup unencrypted).
|
|
59
|
+
*/
|
|
60
|
+
export declare function backupFilePart(manager: string, part: string, file: string | null, options: ManagerBackupOptions | undefined, { requireKey, what }: {
|
|
61
|
+
requireKey: boolean;
|
|
62
|
+
what: string;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
data: DirectoryBackupData | null;
|
|
65
|
+
warnings: string[];
|
|
66
|
+
note?: string;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Stage one file from a backup as `<file>.staged`, and record the swap. When
|
|
70
|
+
* the file was absent at backup time the archive holds nothing, and
|
|
71
|
+
* `whenAbsent` is staged in its place (an empty store), so the restore still
|
|
72
|
+
* puts the site back as it was.
|
|
73
|
+
*/
|
|
74
|
+
export declare function stageFilePart(manager: string, file: string, data: DirectoryBackupData, options: ManagerRestoreOptions | undefined, { whenAbsent }: {
|
|
75
|
+
whenAbsent: string;
|
|
76
|
+
}): Promise<void>;
|
|
77
|
+
/** Put a staged restore of one file in place, at start, before the manager reads it. */
|
|
78
|
+
export declare function applyFilePartAtStart(manager: string, file: string, configManager: Parameters<typeof siteRestoreFile>[0]): PartOutcome | null;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* emailForLog — the one way an email address reaches the server log (#1916).
|
|
3
|
+
*
|
|
4
|
+
* Rule (operator, 2026-10-20): a full email address never reaches the server
|
|
5
|
+
* log. A log line names the address's domain only. Audit records are not the
|
|
6
|
+
* server log and keep full addresses; do not use these helpers on them.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The domain(s) of one address or a comma-separated list, lower-cased:
|
|
10
|
+
* `"Bob <bob@Example.org>, ann@x.io"` → `"example.org,x.io"`. A value
|
|
11
|
+
* without an `@` (or an empty one) reads as `unknown`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function emailDomain(to: string | null | undefined): string;
|
|
14
|
+
/**
|
|
15
|
+
* Any address inside free text (an SMTP error often quotes the rejected one)
|
|
16
|
+
* cut to its domain: `bob@example.org` → `…@example.org`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function redactEmailAddresses(text: string): string;
|
|
19
|
+
/** An error's message, with any address in it cut to its domain. */
|
|
20
|
+
export declare function errorForLog(err: unknown): string;
|