@jwilleke/ngdpbase-types 5.26.0 → 5.28.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 +8 -2
- package/lib/packages/ngdpbase-types/testing.d.ts +7 -3
- package/lib/packages/ngdpbase-types/testing.js +7 -3
- package/lib/src/context/ActorContext.d.ts +15 -2
- package/lib/src/context/ActorContext.js +20 -0
- package/lib/src/converters/DocxConverter.d.ts +30 -0
- package/lib/src/converters/MarkdownConverter.d.ts +31 -0
- package/lib/src/export/ChromeServicePdfProvider.d.ts +52 -0
- package/lib/src/export/ChromeServicePdfProvider.js +153 -0
- package/lib/src/export/LocalChromePdfProvider.d.ts +25 -0
- package/lib/src/export/LocalChromePdfProvider.js +33 -0
- package/lib/src/export/PdfProvider.d.ts +51 -0
- package/lib/src/export/PdfProvider.js +37 -0
- package/lib/src/export/pdfEngine.d.ts +113 -0
- package/lib/src/export/pdfEngine.js +195 -0
- package/lib/src/ice/converterShim.d.ts +5 -0
- package/lib/src/ice/fileHandling.d.ts +30 -0
- package/lib/src/ice/ledger.d.ts +37 -0
- package/lib/src/ice/runImport.d.ts +51 -0
- package/lib/src/ice/types.d.ts +284 -0
- package/lib/src/mail/MailProvider.d.ts +15 -0
- package/lib/src/mail/NodemailerMailProvider.d.ts +1 -1
- package/lib/src/managers/AddonsManager.d.ts +25 -5
- package/lib/src/managers/AssetManager.d.ts +7 -3
- package/lib/src/managers/EmailManager.d.ts +32 -5
- package/lib/src/managers/ExportManager.d.ts +62 -0
- package/lib/src/managers/ExportManager.js +152 -2
- package/lib/src/managers/ImportManager.d.ts +611 -0
- package/lib/src/managers/OrganizationManager.d.ts +5 -3
- package/lib/src/managers/PageManager.d.ts +77 -1
- package/lib/src/managers/PersonManager.d.ts +36 -11
- package/lib/src/managers/RoleManager.d.ts +76 -17
- package/lib/src/managers/UserManager.d.ts +55 -2
- package/lib/src/security/PolicyDecisionPoint.d.ts +18 -9
- package/lib/src/security/PolicyInformationPoint.d.ts +48 -10
- package/lib/src/types/Config.d.ts +2 -0
- package/lib/src/types/User.d.ts +1 -1
- package/lib/src/utils/addonHost.d.ts +23 -2
- package/lib/src/utils/addonHost.js +25 -2
- package/lib/src/utils/auditEventNames.generated.d.ts +10 -10
- package/lib/src/utils/auditEventNames.generated.js +10 -10
- package/lib/src/utils/contactAccess.d.ts +30 -0
- package/lib/src/utils/frontmatterAccess.d.ts +54 -11
- package/lib/src/utils/importRunSummary.d.ts +64 -0
- package/lib/src/utils/keyedSerial.d.ts +31 -0
- package/lib/src/utils/ncmNotify.d.ts +30 -0
- package/lib/src/utils/privateStoreAccess.js +1 -3
- package/lib/src/utils/privateStoreImport.d.ts +58 -0
- package/lib/src/utils/roleChangeError.d.ts +25 -0
- package/lib/src/utils/subjectMayDo.d.ts +2 -2
- package/lib/src/utils/zipArchive.d.ts +71 -0
- package/package.json +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** Page sizes Chromium knows by name. */
|
|
2
|
+
export declare const PDF_PAGE_SIZES: readonly ["Letter", "Legal", "Tabloid", "Ledger", "A0", "A1", "A2", "A3", "A4", "A5", "A6"];
|
|
3
|
+
export type PdfPageSize = (typeof PDF_PAGE_SIZES)[number];
|
|
4
|
+
export interface PdfMargin {
|
|
5
|
+
top?: string;
|
|
6
|
+
right?: string;
|
|
7
|
+
bottom?: string;
|
|
8
|
+
left?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* What a caller may set. An `@page` rule in the HTML (size, margin) wins over
|
|
12
|
+
* these, as it does when a browser prints.
|
|
13
|
+
*/
|
|
14
|
+
export interface PdfOptions {
|
|
15
|
+
/** Page size; default `ngdpbase.export.pdf.page-size`. */
|
|
16
|
+
format?: PdfPageSize;
|
|
17
|
+
/** Page margins, each a CSS length (`'20mm'`, `'0.5in'`); default none. */
|
|
18
|
+
margin?: PdfMargin;
|
|
19
|
+
/** Print background colours and images; default `true`. */
|
|
20
|
+
printBackground?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Options after validation and defaults. */
|
|
23
|
+
export interface ResolvedPdfOptions {
|
|
24
|
+
format: PdfPageSize;
|
|
25
|
+
margin: PdfMargin;
|
|
26
|
+
printBackground: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** One local Chromium render, as the child receives it. */
|
|
29
|
+
export interface PdfJob {
|
|
30
|
+
kind: 'render';
|
|
31
|
+
html: string;
|
|
32
|
+
executablePath: string;
|
|
33
|
+
options: ResolvedPdfOptions;
|
|
34
|
+
timeoutMs: number;
|
|
35
|
+
}
|
|
36
|
+
/** A PDF made elsewhere, to normalise in the child. */
|
|
37
|
+
export interface PdfNormalizeJob {
|
|
38
|
+
kind: 'normalize';
|
|
39
|
+
pdf: Uint8Array;
|
|
40
|
+
timeoutMs: number;
|
|
41
|
+
}
|
|
42
|
+
/** Anything the child is asked to do. */
|
|
43
|
+
export type PdfChildJob = PdfJob | PdfNormalizeJob;
|
|
44
|
+
/** What the child sends back. `launch` means Chromium could not start: the engine is unavailable. */
|
|
45
|
+
export type PdfJobResult = {
|
|
46
|
+
ok: true;
|
|
47
|
+
pdf: Uint8Array;
|
|
48
|
+
} | {
|
|
49
|
+
ok: false;
|
|
50
|
+
stage: 'launch' | 'render';
|
|
51
|
+
error: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* No PDF engine: `playwright-core` is not installed, no Chromium was found, or
|
|
55
|
+
* it could not start. An add-on catches it by `code` (it cannot import core
|
|
56
|
+
* values) and falls back to HTML.
|
|
57
|
+
*/
|
|
58
|
+
export declare class PdfUnavailableError extends Error {
|
|
59
|
+
readonly code = "PDF_UNAVAILABLE";
|
|
60
|
+
constructor(message: string, options?: ErrorOptions);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Validate a caller's options and fill the defaults. Throws on anything
|
|
64
|
+
* Chromium would misread, so a typo is an error rather than a different page.
|
|
65
|
+
*
|
|
66
|
+
* @param options - The caller's options
|
|
67
|
+
* @param defaultFormat - `ngdpbase.export.pdf.page-size`
|
|
68
|
+
*/
|
|
69
|
+
export declare function resolvePdfOptions(options: PdfOptions | undefined, defaultFormat: string): ResolvedPdfOptions;
|
|
70
|
+
/** Where Chromium or Chrome usually is, per platform. Checked after the configured path and Playwright's own. */
|
|
71
|
+
export declare const SYSTEM_CHROMIUM_PATHS: Record<string, string[]>;
|
|
72
|
+
export type ChromiumResolution = {
|
|
73
|
+
ok: true;
|
|
74
|
+
executablePath: string;
|
|
75
|
+
source: 'configured' | 'playwright' | 'system';
|
|
76
|
+
} | {
|
|
77
|
+
ok: false;
|
|
78
|
+
reason: string;
|
|
79
|
+
};
|
|
80
|
+
/** Hooks for tests; a site passes nothing. */
|
|
81
|
+
export interface ResolveDeps {
|
|
82
|
+
exists?: (p: string) => boolean;
|
|
83
|
+
platform?: string;
|
|
84
|
+
playwrightInstalled?: () => boolean;
|
|
85
|
+
/** Playwright's own Chromium, or null when it cannot say. */
|
|
86
|
+
playwrightChromium?: () => Promise<string | null>;
|
|
87
|
+
}
|
|
88
|
+
/** Whether `playwright-core` is installed (it is an optional dependency). */
|
|
89
|
+
export declare function playwrightInstalled(): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Find a Chromium to render with. Read on every call, so installing Chromium
|
|
92
|
+
* or setting the path takes effect without a restart.
|
|
93
|
+
*
|
|
94
|
+
* @param configuredPath - `ngdpbase.export.pdf.provider.local-chrome.chromium-path` ('' = find one)
|
|
95
|
+
*/
|
|
96
|
+
export declare function resolveChromium(configuredPath: string, deps?: ResolveDeps): Promise<ChromiumResolution>;
|
|
97
|
+
export declare function childEnv(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
98
|
+
/**
|
|
99
|
+
* Render one job in a child process. Resolves with the child's answer; rejects
|
|
100
|
+
* only when the child timed out, crashed or never answered.
|
|
101
|
+
*
|
|
102
|
+
* @param job - The render
|
|
103
|
+
*/
|
|
104
|
+
export declare function renderPdfInChild(job: PdfJob): Promise<PdfJobResult>;
|
|
105
|
+
/**
|
|
106
|
+
* Normalise a PDF in a child process (`normalizePdf`, the same pass a local
|
|
107
|
+
* render gets). Rejects when the bytes are not a PDF pdf-lib can read, or the
|
|
108
|
+
* child times out.
|
|
109
|
+
*
|
|
110
|
+
* @param pdf - A PDF a PDF service returned
|
|
111
|
+
* @param timeoutMs - The child is killed after this
|
|
112
|
+
*/
|
|
113
|
+
export declare function normalizePdfInChild(pdf: Uint8Array, timeoutMs: number): Promise<Uint8Array>;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTML → PDF engine (#1974): the options and the error every provider
|
|
3
|
+
* shares, and the child process the `local-chrome` provider renders in
|
|
4
|
+
* (headless Chromium, driven by `playwright-core`, both optional at run time).
|
|
5
|
+
*
|
|
6
|
+
* - `resolveChromium` finds a Chromium to run: the configured path, then the
|
|
7
|
+
* one Playwright installed (`npx playwright install chromium`), then the
|
|
8
|
+
* usual system locations. Nothing is downloaded at `npm install`.
|
|
9
|
+
* - `renderPdfInChild` renders one document in a child process
|
|
10
|
+
* (`pdfRenderWorker.ts`), killed at the timeout, so the site never waits on
|
|
11
|
+
* Chromium or on PDF parsing.
|
|
12
|
+
* - `normalizePdfInChild` gives a PDF a PDF service made (the
|
|
13
|
+
* `chrome-service` provider) the same metadata pass, in the same kind of
|
|
14
|
+
* child, so parsing it never runs on the thread that answers requests.
|
|
15
|
+
*
|
|
16
|
+
* `ExportManager.htmlToPdf` is the door, through its providers
|
|
17
|
+
* (`PdfProvider.ts`); nothing else calls these.
|
|
18
|
+
*/
|
|
19
|
+
import { fork } from 'node:child_process';
|
|
20
|
+
import { existsSync } from 'node:fs';
|
|
21
|
+
import { createRequire } from 'node:module';
|
|
22
|
+
/** Page sizes Chromium knows by name. */
|
|
23
|
+
export const PDF_PAGE_SIZES = ['Letter', 'Legal', 'Tabloid', 'Ledger', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6'];
|
|
24
|
+
/** A CSS length Chromium's PDF margins accept: a number and px, in, cm or mm. */
|
|
25
|
+
const MARGIN = /^\d+(\.\d+)?(px|in|cm|mm)$/;
|
|
26
|
+
/**
|
|
27
|
+
* No PDF engine: `playwright-core` is not installed, no Chromium was found, or
|
|
28
|
+
* it could not start. An add-on catches it by `code` (it cannot import core
|
|
29
|
+
* values) and falls back to HTML.
|
|
30
|
+
*/
|
|
31
|
+
export class PdfUnavailableError extends Error {
|
|
32
|
+
code = 'PDF_UNAVAILABLE';
|
|
33
|
+
constructor(message, options) {
|
|
34
|
+
super(message, options);
|
|
35
|
+
this.name = 'PdfUnavailableError';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Validate a caller's options and fill the defaults. Throws on anything
|
|
40
|
+
* Chromium would misread, so a typo is an error rather than a different page.
|
|
41
|
+
*
|
|
42
|
+
* @param options - The caller's options
|
|
43
|
+
* @param defaultFormat - `ngdpbase.export.pdf.page-size`
|
|
44
|
+
*/
|
|
45
|
+
export function resolvePdfOptions(options, defaultFormat) {
|
|
46
|
+
const opts = options ?? {};
|
|
47
|
+
if (typeof opts !== 'object')
|
|
48
|
+
throw new TypeError('htmlToPdf: options must be an object');
|
|
49
|
+
const format = opts.format ?? defaultFormat;
|
|
50
|
+
if (!PDF_PAGE_SIZES.includes(format)) {
|
|
51
|
+
throw new TypeError(`htmlToPdf: format must be one of ${PDF_PAGE_SIZES.join(', ')} (got ${JSON.stringify(format)})`);
|
|
52
|
+
}
|
|
53
|
+
const margin = {};
|
|
54
|
+
for (const side of ['top', 'right', 'bottom', 'left']) {
|
|
55
|
+
const value = opts.margin?.[side];
|
|
56
|
+
if (value === undefined)
|
|
57
|
+
continue;
|
|
58
|
+
if (typeof value !== 'string' || !MARGIN.test(value)) {
|
|
59
|
+
throw new TypeError(`htmlToPdf: margin.${side} must be a length such as '20mm' or '0.5in' (got ${JSON.stringify(value)})`);
|
|
60
|
+
}
|
|
61
|
+
margin[side] = value;
|
|
62
|
+
}
|
|
63
|
+
const printBackground = opts.printBackground ?? true;
|
|
64
|
+
if (typeof printBackground !== 'boolean')
|
|
65
|
+
throw new TypeError('htmlToPdf: printBackground must be a boolean');
|
|
66
|
+
return { format: format, margin, printBackground };
|
|
67
|
+
}
|
|
68
|
+
/** Where Chromium or Chrome usually is, per platform. Checked after the configured path and Playwright's own. */
|
|
69
|
+
export const SYSTEM_CHROMIUM_PATHS = {
|
|
70
|
+
linux: ['/usr/bin/chromium', '/usr/bin/chromium-browser', '/usr/lib/chromium/chromium', '/usr/bin/google-chrome', '/usr/bin/google-chrome-stable', '/snap/bin/chromium'],
|
|
71
|
+
darwin: ['/Applications/Chromium.app/Contents/MacOS/Chromium', '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'],
|
|
72
|
+
win32: ['C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe', 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe']
|
|
73
|
+
};
|
|
74
|
+
const requireHere = createRequire(import.meta.url);
|
|
75
|
+
/** Whether `playwright-core` is installed (it is an optional dependency). */
|
|
76
|
+
export function playwrightInstalled() {
|
|
77
|
+
try {
|
|
78
|
+
requireHere.resolve('playwright-core');
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function playwrightChromiumPath() {
|
|
86
|
+
try {
|
|
87
|
+
const { chromium } = await import('playwright-core');
|
|
88
|
+
return chromium.executablePath() || null;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Find a Chromium to render with. Read on every call, so installing Chromium
|
|
96
|
+
* or setting the path takes effect without a restart.
|
|
97
|
+
*
|
|
98
|
+
* @param configuredPath - `ngdpbase.export.pdf.provider.local-chrome.chromium-path` ('' = find one)
|
|
99
|
+
*/
|
|
100
|
+
export async function resolveChromium(configuredPath, deps = {}) {
|
|
101
|
+
const exists = deps.exists ?? existsSync;
|
|
102
|
+
if (!(deps.playwrightInstalled ?? playwrightInstalled)()) {
|
|
103
|
+
return { ok: false, reason: 'playwright-core is not installed (it is an optional dependency; npm install without --omit=optional)' };
|
|
104
|
+
}
|
|
105
|
+
if (configuredPath) {
|
|
106
|
+
return exists(configuredPath)
|
|
107
|
+
? { ok: true, executablePath: configuredPath, source: 'configured' }
|
|
108
|
+
: { ok: false, reason: `ngdpbase.export.pdf.provider.local-chrome.chromium-path is set, but nothing is there: ${configuredPath}` };
|
|
109
|
+
}
|
|
110
|
+
const bundled = await (deps.playwrightChromium ?? playwrightChromiumPath)();
|
|
111
|
+
if (bundled && exists(bundled))
|
|
112
|
+
return { ok: true, executablePath: bundled, source: 'playwright' };
|
|
113
|
+
for (const candidate of SYSTEM_CHROMIUM_PATHS[deps.platform ?? process.platform] ?? []) {
|
|
114
|
+
if (exists(candidate))
|
|
115
|
+
return { ok: true, executablePath: candidate, source: 'system' };
|
|
116
|
+
}
|
|
117
|
+
return { ok: false, reason: 'no Chromium found: install Chromium, or set ngdpbase.export.pdf.provider.local-chrome.chromium-path' };
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The environment the child gets: enough to find a home, a temp folder and
|
|
121
|
+
* fonts, and none of the site's secrets (the session secret, keys and
|
|
122
|
+
* passwords the site holds in its environment).
|
|
123
|
+
*/
|
|
124
|
+
const CHILD_ENV_KEYS = [
|
|
125
|
+
'PATH', 'HOME', 'TMPDIR', 'TMP', 'TEMP', 'LANG', 'LC_ALL', 'PLAYWRIGHT_BROWSERS_PATH',
|
|
126
|
+
'FONTCONFIG_PATH', 'FONTCONFIG_FILE', 'XDG_CONFIG_HOME', 'XDG_CACHE_HOME', 'XDG_RUNTIME_DIR',
|
|
127
|
+
'SystemRoot', 'LOCALAPPDATA', 'USERPROFILE', 'APPDATA', 'ProgramFiles', 'ProgramFiles(x86)'
|
|
128
|
+
];
|
|
129
|
+
export function childEnv(env = process.env) {
|
|
130
|
+
const out = {};
|
|
131
|
+
for (const key of CHILD_ENV_KEYS)
|
|
132
|
+
if (env[key] !== undefined)
|
|
133
|
+
out[key] = env[key];
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Render one job in a child process. Resolves with the child's answer; rejects
|
|
138
|
+
* only when the child timed out, crashed or never answered.
|
|
139
|
+
*
|
|
140
|
+
* @param job - The render
|
|
141
|
+
*/
|
|
142
|
+
export function renderPdfInChild(job) {
|
|
143
|
+
return runPdfChild(job);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Normalise a PDF in a child process (`normalizePdf`, the same pass a local
|
|
147
|
+
* render gets). Rejects when the bytes are not a PDF pdf-lib can read, or the
|
|
148
|
+
* child times out.
|
|
149
|
+
*
|
|
150
|
+
* @param pdf - A PDF a PDF service returned
|
|
151
|
+
* @param timeoutMs - The child is killed after this
|
|
152
|
+
*/
|
|
153
|
+
export async function normalizePdfInChild(pdf, timeoutMs) {
|
|
154
|
+
const result = await runPdfChild({ kind: 'normalize', pdf, timeoutMs });
|
|
155
|
+
if (!result.ok)
|
|
156
|
+
throw new Error(`the PDF could not be read: ${result.error}`);
|
|
157
|
+
return result.pdf;
|
|
158
|
+
}
|
|
159
|
+
function runPdfChild(job) {
|
|
160
|
+
// Compiled, the worker is the .js beside this file. From source (vitest,
|
|
161
|
+
// tsx) it is the .ts, which needs tsx's loader.
|
|
162
|
+
const fromSource = import.meta.url.endsWith('.ts');
|
|
163
|
+
const entry = new URL(fromSource ? './pdfRenderWorker.ts' : './pdfRenderWorker.js', import.meta.url);
|
|
164
|
+
return new Promise((resolve, reject) => {
|
|
165
|
+
const child = fork(entry, [], {
|
|
166
|
+
execArgv: fromSource ? ['--import', 'tsx'] : [],
|
|
167
|
+
env: childEnv(),
|
|
168
|
+
serialization: 'advanced',
|
|
169
|
+
stdio: ['ignore', 'ignore', 'pipe', 'ipc']
|
|
170
|
+
});
|
|
171
|
+
let settled = false;
|
|
172
|
+
let stderr = '';
|
|
173
|
+
child.stderr?.on('data', (chunk) => { if (stderr.length < 2000)
|
|
174
|
+
stderr += chunk.toString(); });
|
|
175
|
+
const settle = (fn) => {
|
|
176
|
+
if (settled)
|
|
177
|
+
return;
|
|
178
|
+
settled = true;
|
|
179
|
+
clearTimeout(timer);
|
|
180
|
+
fn();
|
|
181
|
+
};
|
|
182
|
+
const timer = setTimeout(() => {
|
|
183
|
+
settle(() => reject(new Error(`PDF render timed out after ${job.timeoutMs} ms`)));
|
|
184
|
+
child.kill('SIGKILL');
|
|
185
|
+
}, job.timeoutMs);
|
|
186
|
+
child.once('message', (result) => {
|
|
187
|
+
settle(() => resolve(result.ok ? { ok: true, pdf: Buffer.from(result.pdf) } : result));
|
|
188
|
+
});
|
|
189
|
+
child.once('error', (err) => settle(() => reject(err)));
|
|
190
|
+
child.once('exit', (code, signal) => {
|
|
191
|
+
settle(() => reject(new Error(`PDF render process exited (${signal ?? code}) without an answer${stderr ? `: ${stderr.trim().split('\n')[0]}` : ''}`)));
|
|
192
|
+
});
|
|
193
|
+
child.send(job);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IContentConverter } from '../converters/IContentConverter.js';
|
|
2
|
+
import type { IceShim } from './types.js';
|
|
3
|
+
/** The receiver today's converters hand to. */
|
|
4
|
+
export declare const PAGES_RECEIVER = "core.pages";
|
|
5
|
+
export declare function converterShim(converter: IContentConverter, tableClasses: () => string[]): IceShim;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ZipReadLimits } from '../utils/zipArchive.js';
|
|
2
|
+
import type { IceUpload } from './types.js';
|
|
3
|
+
/** A file's fingerprint: SHA-256 of its bytes, hex. */
|
|
4
|
+
export declare function fingerprint(bytes: Buffer): string;
|
|
5
|
+
/**
|
|
6
|
+
* Is this path noise — something an operating system or archiver adds that is
|
|
7
|
+
* nobody's data? Patterns (configuration, `ngdpbase.import.engine.noise`):
|
|
8
|
+
*
|
|
9
|
+
* - `name/` — any path with a directory segment of that name (`__MACOSX/`);
|
|
10
|
+
* - `prefix*` / `*suffix` — a file name starting or ending so (`._*`);
|
|
11
|
+
* - anything else — a file name exactly (`.DS_Store`), case-insensitive.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isNoise(filePath: string, patterns: readonly string[]): boolean;
|
|
14
|
+
/** Is this upload a zip archive the engine unpacks? By its name, or its media type. */
|
|
15
|
+
export declare function isZip(upload: IceUpload): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Unpack the zips among the uploads into the files they hold, named
|
|
18
|
+
* `archive.zip/inner/path`. A nested zip is unpacked too. Everything else is
|
|
19
|
+
* passed through. Limits are per archive (`ZipReadLimits`), so a small
|
|
20
|
+
* archive that expands enormously stops at the budget. An archive that cannot
|
|
21
|
+
* be read is returned in `unreadable`, with why; the rest go on.
|
|
22
|
+
*/
|
|
23
|
+
export declare function expandUploads(uploads: readonly IceUpload[], limits: ZipReadLimits, maxDepth: number, depth?: number): {
|
|
24
|
+
files: IceUpload[];
|
|
25
|
+
unreadable: Array<{
|
|
26
|
+
name: string;
|
|
27
|
+
size: number;
|
|
28
|
+
message: string;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IceLedger, LedgerFileEntry } from './types.js';
|
|
2
|
+
interface ScopeFile {
|
|
3
|
+
scope: string;
|
|
4
|
+
files: LedgerFileEntry[];
|
|
5
|
+
items: string[];
|
|
6
|
+
}
|
|
7
|
+
/** Keeps the newest entry per fingerprint, at most `maxEntries` files and item keys per scope. */
|
|
8
|
+
declare abstract class ScopedLedger implements IceLedger {
|
|
9
|
+
private readonly maxEntries;
|
|
10
|
+
constructor(maxEntries: number);
|
|
11
|
+
protected abstract load(scope: string): Promise<ScopeFile>;
|
|
12
|
+
protected abstract save(data: ScopeFile): Promise<void>;
|
|
13
|
+
/** One writer per scope at a time, so two runs in one scope cannot lose each other's entries. */
|
|
14
|
+
private readonly chains;
|
|
15
|
+
private serial;
|
|
16
|
+
lastFile(scope: string, sha256: string): Promise<LedgerFileEntry | null>;
|
|
17
|
+
recordFile(scope: string, entry: LedgerFileEntry): Promise<void>;
|
|
18
|
+
hasItem(scope: string, itemKey: string): Promise<boolean>;
|
|
19
|
+
recordItem(scope: string, itemKey: string): Promise<void>;
|
|
20
|
+
files(scope: string): Promise<LedgerFileEntry[]>;
|
|
21
|
+
}
|
|
22
|
+
/** The ledger in memory: for tests, and for a site that keeps no import history. */
|
|
23
|
+
export declare class MemoryIceLedger extends ScopedLedger {
|
|
24
|
+
private readonly scopes;
|
|
25
|
+
constructor(maxEntries?: number);
|
|
26
|
+
protected load(scope: string): Promise<ScopeFile>;
|
|
27
|
+
protected save(data: ScopeFile): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/** One JSON file per scope, named by the scope's hash (a scope holds a username). */
|
|
30
|
+
export declare class FileIceLedger extends ScopedLedger {
|
|
31
|
+
private readonly dir;
|
|
32
|
+
constructor(dir: string, maxEntries: number);
|
|
33
|
+
private fileFor;
|
|
34
|
+
protected load(scope: string): Promise<ScopeFile>;
|
|
35
|
+
protected save(data: ScopeFile): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ActorContext } from '../context/ActorContext.js';
|
|
2
|
+
import type { ZipReadLimits } from '../utils/zipArchive.js';
|
|
3
|
+
import type { IceItem, IceLedger, IceRunReport, IceRunRequest, OriginalChoice, RegisteredReceiver, RegisteredShim, ShimTools } from './types.js';
|
|
4
|
+
/** Configuration the engine reads (each a key under `ngdpbase.import.engine.`). */
|
|
5
|
+
export interface IceEngineSettings {
|
|
6
|
+
noise: string[];
|
|
7
|
+
zip: ZipReadLimits;
|
|
8
|
+
maxZipDepth: number;
|
|
9
|
+
maxFileBytes: number;
|
|
10
|
+
maxChainDepth: number;
|
|
11
|
+
defaultOriginal: OriginalChoice;
|
|
12
|
+
}
|
|
13
|
+
export interface IceRunDeps {
|
|
14
|
+
/** Enabled shims, in registration order. */
|
|
15
|
+
shims: RegisteredShim[];
|
|
16
|
+
receivers: ReadonlyMap<string, RegisteredReceiver>;
|
|
17
|
+
ledger: IceLedger;
|
|
18
|
+
settings: IceEngineSettings;
|
|
19
|
+
tools(shim: RegisteredShim): ShimTools;
|
|
20
|
+
now?: () => Date;
|
|
21
|
+
}
|
|
22
|
+
/** The id of the receiver that keeps an original when the chosen receiver does not keep its own (D11). */
|
|
23
|
+
export declare const FILES_RECEIVER = "core.files";
|
|
24
|
+
/** The scope a run's fingerprints are checked in, unless the caller names one. */
|
|
25
|
+
export declare function defaultScope(receiverId: string, ctx: ActorContext): string;
|
|
26
|
+
export interface ChainLeaf {
|
|
27
|
+
item: IceItem;
|
|
28
|
+
chain: string[];
|
|
29
|
+
}
|
|
30
|
+
/** What a chain needs: the shims it may continue through, and where it stops. */
|
|
31
|
+
export interface ChainSpec {
|
|
32
|
+
shims: RegisteredShim[];
|
|
33
|
+
tools(shim: RegisteredShim): ShimTools;
|
|
34
|
+
maxChainDepth: number;
|
|
35
|
+
/** Does this item, from this shim, stop here? */
|
|
36
|
+
done(shim: RegisteredShim, item: IceItem): boolean;
|
|
37
|
+
/** Named in the error when nothing takes an item further. */
|
|
38
|
+
target: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Run a shim, then the shims after it (D9), until each item is done. What
|
|
42
|
+
* came before travels with each item: earlier metadata under later, earlier
|
|
43
|
+
* warnings first. Partial notes are collected into `partial`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function convertChain(shim: RegisteredShim, input: IceItem, chain: string[], spec: ChainSpec, partial: string[]): Promise<ChainLeaf[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Run one import. Fills and returns `report`, which the caller may be
|
|
48
|
+
* showing while it runs. Never throws for one file's failure; that file's
|
|
49
|
+
* status says why.
|
|
50
|
+
*/
|
|
51
|
+
export declare function runImport(deps: IceRunDeps, request: IceRunRequest, ctx: ActorContext, report: IceRunReport): Promise<IceRunReport>;
|