tina4-nodejs 3.13.150 → 3.13.152
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/CLAUDE.md +2 -2
- package/package.json +5 -9
- package/packages/cli/dist/bin.js +1326 -586
- package/packages/cli/src/bin.ts +179 -7
- package/packages/cli/src/commands/generate.ts +36 -17
- package/packages/cli/src/commands/migrateCreate.ts +15 -3
- package/packages/cli/src/commands/queue.ts +8 -0
- package/packages/cli/src/util.ts +25 -15
- package/packages/core/dist/index.js +1172 -574
- package/packages/core/src/aiClient.ts +2 -1
- package/packages/core/src/api.ts +2 -1
- package/packages/core/src/auth.ts +1 -1
- package/packages/core/src/authGate.ts +3 -4
- package/packages/core/src/cache.ts +6 -1
- package/packages/core/src/devAdmin.ts +180 -123
- package/packages/core/src/dispatchPipeline.ts +4 -0
- package/packages/core/src/docs.ts +5 -3
- package/packages/core/src/errorOverlay.ts +18 -9
- package/packages/core/src/index.ts +2 -1
- package/packages/core/src/mcp.ts +53 -16
- package/packages/core/src/messenger.ts +22 -30
- package/packages/core/src/middleware.ts +8 -1
- package/packages/core/src/optionalPackage.ts +2 -2
- package/packages/core/src/plan.ts +3 -3
- package/packages/core/src/push.ts +1 -1
- package/packages/core/src/request.ts +185 -25
- package/packages/core/src/router.ts +3 -2
- package/packages/core/src/server.ts +36 -12
- package/packages/core/src/session.ts +44 -0
- package/packages/core/src/slashTrim.ts +39 -0
- package/packages/core/src/wsdl.ts +66 -48
- package/packages/core/templates/crud/form.twig +5 -5
- package/packages/core/templates/crud/table.twig +2 -2
- package/packages/core/templates/errors/302.twig +4 -3
- package/packages/frond/dist/index.js +206 -64
- package/packages/frond/src/engine.ts +278 -69
- package/packages/frond/src/index.ts +1 -1
- package/packages/orm/dist/index.js +1156 -560
- package/packages/orm/src/adapters/postgres.ts +79 -19
- package/packages/orm/src/crudRender.ts +5 -5
- package/packages/orm/src/crudTable.ts +1 -1
- package/packages/orm/src/database.ts +15 -29
- package/packages/orm/src/databaseResult.ts +11 -1
- package/packages/orm/src/docstore.ts +24 -8
- package/packages/orm/src/realtime/index.ts +1 -0
- package/packages/orm/src/realtime/realtime.ts +2 -1
- package/packages/orm/src/realtime/s3Client.ts +276 -0
- package/packages/orm/src/realtime/storage.ts +19 -60
- package/packages/orm/src/sqlTranslator.ts +58 -42
- package/packages/swagger/dist/index.js +25 -4
- package/packages/swagger/src/generator.ts +7 -4
- package/packages/swagger/src/ui.ts +2 -1
- package/types/cli/src/bin.d.ts +16 -0
- package/types/cli/src/commands/generate.d.ts +11 -0
- package/types/cli/src/commands/migrateCreate.d.ts +2 -0
- package/types/cli/src/commands/queue.d.ts +2 -0
- package/types/cli/src/util.d.ts +2 -1
- package/types/core/src/authGate.d.ts +3 -3
- package/types/core/src/devAdmin.d.ts +40 -0
- package/types/core/src/index.d.ts +2 -1
- package/types/core/src/middleware.d.ts +1 -0
- package/types/core/src/optionalPackage.d.ts +2 -2
- package/types/core/src/request.d.ts +5 -1
- package/types/core/src/session.d.ts +25 -0
- package/types/core/src/slashTrim.d.ts +6 -0
- package/types/frond/src/engine.d.ts +11 -0
- package/types/frond/src/index.d.ts +1 -1
- package/types/orm/src/adapters/postgres.d.ts +6 -0
- package/types/orm/src/realtime/index.d.ts +1 -0
- package/types/orm/src/realtime/s3Client.d.ts +48 -0
- package/types/orm/src/realtime/storage.d.ts +9 -7
package/types/cli/src/bin.d.ts
CHANGED
|
@@ -58,10 +58,14 @@ export declare function runCommands(args?: string[]): void;
|
|
|
58
58
|
export interface CommandSpec {
|
|
59
59
|
handler: (cmdArgs: string[]) => void | Promise<void>;
|
|
60
60
|
summary: string;
|
|
61
|
+
/** Options main() accepts (name -> takes a value). Absent = none; null = not checked. */
|
|
62
|
+
flags?: OptionMap | null;
|
|
61
63
|
usage?: string;
|
|
62
64
|
args?: string[];
|
|
63
65
|
subcommands?: string[];
|
|
64
66
|
}
|
|
67
|
+
/** Option name (without `--`) -> whether it takes a value. */
|
|
68
|
+
export type OptionMap = Record<string, boolean>;
|
|
65
69
|
export declare const COMMANDS: Record<string, CommandSpec>;
|
|
66
70
|
export interface DelegatedSpec {
|
|
67
71
|
summary: string;
|
|
@@ -81,3 +85,15 @@ export declare const EXIT_UNKNOWN_COMMAND = 1;
|
|
|
81
85
|
* came back to a framework CLI (a delegation loop).
|
|
82
86
|
*/
|
|
83
87
|
export declare function delegateToClient(command: string, args: string[]): number;
|
|
88
|
+
/**
|
|
89
|
+
* The options `command` accepts, or null when its arguments are not ours to
|
|
90
|
+
* check (an unknown generator or queue subcommand is reported by its own handler).
|
|
91
|
+
*/
|
|
92
|
+
export declare function acceptedOptions(command: string, args: string[]): OptionMap | null;
|
|
93
|
+
/** The accepted option closest to `name`, when it is close enough to be a typo. */
|
|
94
|
+
export declare function closestOption(name: string, accepted: string[]): string | null;
|
|
95
|
+
/**
|
|
96
|
+
* Judge the argument at `i`: the refusal message (or null when it is fine) and
|
|
97
|
+
* how many arguments it used - 2 for a value option spelled `--name value`.
|
|
98
|
+
*/
|
|
99
|
+
export declare function optionProblem(args: string[], i: number, accepted: OptionMap, label: string): [string | null, number];
|
|
@@ -138,11 +138,22 @@ export declare function aiFill(fn: string, spec: {
|
|
|
138
138
|
export declare function extend(note: string, hint?: string, indent?: string): string;
|
|
139
139
|
export interface GeneratorSpec {
|
|
140
140
|
handler: (name: string, flags: Record<string, string | boolean>) => void;
|
|
141
|
+
/**
|
|
142
|
+
* Options this generator reads (name -> takes a value), checked by bin.ts
|
|
143
|
+
* main() before the handler runs. RESOLUTION_FLAGS are added on top.
|
|
144
|
+
*/
|
|
145
|
+
flags: Record<string, boolean>;
|
|
141
146
|
/** Arg/flag hint shown in `tina4nodejs help` (human only). */
|
|
142
147
|
usage: string;
|
|
143
148
|
summary: string;
|
|
144
149
|
}
|
|
145
150
|
export declare const GENERATORS: Record<string, GeneratorSpec>;
|
|
151
|
+
/**
|
|
152
|
+
* Options every generator accepts on top of its own: the resolution envelope
|
|
153
|
+
* (`--json`) and the write-nothing preview (`--dry-run`) are honoured by every
|
|
154
|
+
* generator here, because writes go through the shared ensureDir/writeFileSafe.
|
|
155
|
+
*/
|
|
156
|
+
export declare const RESOLUTION_FLAGS: Record<string, boolean>;
|
|
146
157
|
export declare function generate(what: string, name: string, extraArgs?: string[]): Promise<void>;
|
|
147
158
|
/**
|
|
148
159
|
* Programmatic entry point for in-process consumers (MCP tools, tests, hosted
|
|
@@ -11,6 +11,8 @@ export type QueueHandler = (payload: unknown) => unknown | Promise<unknown>;
|
|
|
11
11
|
* `servicesDir` targets this topic. Mirrors Python's _resolve_queue_handler.
|
|
12
12
|
*/
|
|
13
13
|
export declare function resolveQueueHandler(servicesDir: string, topic: string): Promise<QueueHandler | null>;
|
|
14
|
+
/** Options per queue subcommand (name -> takes a value), checked by bin.ts main(). */
|
|
15
|
+
export declare const QUEUE_FLAGS: Record<string, Record<string, boolean>>;
|
|
14
16
|
/** Subcommand names, in order — surfaced in `commands --json` for the tina4 client. */
|
|
15
17
|
export declare const QUEUE_SUBCOMMAND_NAMES: string[];
|
|
16
18
|
/**
|
package/types/cli/src/util.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ export interface ParsedFlags {
|
|
|
4
4
|
positional: string[];
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
* Parse `--key value` and bare `--flag` arguments into flags
|
|
7
|
+
* Parse `--key value`, `--key=value` and bare `--flag` arguments into flags
|
|
8
|
+
* plus positionals.
|
|
8
9
|
*
|
|
9
10
|
* A name listed in `booleanFlags` never consumes the next token; every other
|
|
10
11
|
* `--key` takes the following token as its value unless that token is itself a
|
|
@@ -14,10 +14,10 @@ export interface AuthGateRoute {
|
|
|
14
14
|
* to `res.raw` and the caller must stop (not run the handler). Returns `false`
|
|
15
15
|
* when the route is public OR a valid token was presented (in which case
|
|
16
16
|
* `req.user` is populated and, for a body formToken, a `FreshToken` header is
|
|
17
|
-
* set). Auth is enforced only for a route that is `secure` and not `noAuth
|
|
18
|
-
*
|
|
17
|
+
* set). Auth is enforced only for a route that is `secure` and not `noAuth`
|
|
18
|
+
* (the dev dashboard registers its own routes `noAuth`).
|
|
19
19
|
*
|
|
20
20
|
* Token sources, in priority order: `Authorization: Bearer` header, a
|
|
21
21
|
* `formToken` in the parsed body, then a session token.
|
|
22
22
|
*/
|
|
23
|
-
export declare function enforceRouteAuth(req: Tina4Request, res: Tina4Response, match: AuthGateRoute
|
|
23
|
+
export declare function enforceRouteAuth(req: Tina4Request, res: Tina4Response, match: AuthGateRoute): boolean;
|
|
@@ -221,6 +221,46 @@ export declare class DevAdmin {
|
|
|
221
221
|
reload?: boolean;
|
|
222
222
|
}): string;
|
|
223
223
|
}
|
|
224
|
+
/** A column as the DB adapter's getColumns() reports it, for seeding. */
|
|
225
|
+
interface SeedColumn {
|
|
226
|
+
name: string;
|
|
227
|
+
type: string;
|
|
228
|
+
primaryKey?: boolean;
|
|
229
|
+
}
|
|
230
|
+
/** The fake-data surface buildSeedFieldMap draws from (orm's FakeData). */
|
|
231
|
+
interface SeedFake {
|
|
232
|
+
email(): string;
|
|
233
|
+
name(): string;
|
|
234
|
+
phone(): string;
|
|
235
|
+
address(): string;
|
|
236
|
+
url(): string;
|
|
237
|
+
integer(min: number, max: number): number;
|
|
238
|
+
numeric(min: number, max: number, dp: number): number;
|
|
239
|
+
boolean(): boolean;
|
|
240
|
+
date(): unknown;
|
|
241
|
+
sentence(words: number): string;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Resolve the seed request's options from the query string and JSON body (the
|
|
245
|
+
* query string wins). Exported so the parsing is tested directly. P4b accepts
|
|
246
|
+
* seed/clear/strict; an unparseable `seed` becomes undefined (not reproducible).
|
|
247
|
+
*/
|
|
248
|
+
export declare function parseSeedRequest(url: URL, body: Record<string, unknown> | null | undefined): {
|
|
249
|
+
table: string;
|
|
250
|
+
count: number;
|
|
251
|
+
seed: number | undefined;
|
|
252
|
+
clear: boolean;
|
|
253
|
+
strict: boolean;
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Build a column -> fake-value generator map from the table's columns, keyed on
|
|
257
|
+
* the column NAME first (email/name/phone/address/url) then its SQL TYPE
|
|
258
|
+
* (int/float/bool/date), falling back to a short sentence. id / primary-key
|
|
259
|
+
* columns are skipped (the engine assigns them). Exported so the heuristic is
|
|
260
|
+
* tested directly. `fake` is seeded by the caller so a run is reproducible; its
|
|
261
|
+
* generators are closed over by every entry.
|
|
262
|
+
*/
|
|
263
|
+
export declare function buildSeedFieldMap(columns: SeedColumn[], fake: SeedFake): Record<string, () => unknown>;
|
|
224
264
|
/**
|
|
225
265
|
* Return the base URL for the co-located Rust agent server.
|
|
226
266
|
*
|
|
@@ -8,6 +8,7 @@ export { discoverRoutes } from "./routeDiscovery.js";
|
|
|
8
8
|
export { MiddlewareChain, MiddlewareRunner, cors, requestLogger, CorsMiddleware, RateLimiterMiddleware, RequestLogger, SecurityHeadersMiddleware, CsrfMiddleware, attachCsrfFromEnv } from "./middleware.js";
|
|
9
9
|
export type { CorsConfig } from "./middleware.js";
|
|
10
10
|
export { createRequest, makeCaseInsensitiveHeaders, parseMultipart, saveUpload } from "./request.js";
|
|
11
|
+
export type { FormValue } from "./request.js";
|
|
11
12
|
export { createResponse, errorResponse, setDefaultTemplatesDir, getFrond, setFrond, getFrameworkFrond, acceptPrefersJson, wantsJson, negotiatedErrorBody, } from "./response.js";
|
|
12
13
|
export { tryServeStatic } from "./static.js";
|
|
13
14
|
export { loadEnv, getEnv, requireEnv, hasEnv, allEnv, resetEnv, isTruthy } from "./dotenv.js";
|
|
@@ -45,7 +46,7 @@ export type { ApiResult, ApiOptions, ApiTransport, DownloadResult, UploadOptions
|
|
|
45
46
|
export { Context, defaultContext, existingContext, fts5Supported, _sharedContexts } from "./context/index.js";
|
|
46
47
|
export type { SearchHit } from "./context/index.js";
|
|
47
48
|
export { Events } from "./events.js";
|
|
48
|
-
export { DevAdmin, MessageLog, RequestInspector, ErrorTracker, DevMailboxStore, DevQueue, WsTracker, supervisorBaseUrl, devAdminLanguage } from "./devAdmin.js";
|
|
49
|
+
export { DevAdmin, MessageLog, RequestInspector, ErrorTracker, DevMailboxStore, DevQueue, WsTracker, supervisorBaseUrl, devAdminLanguage, parseSeedRequest, buildSeedFieldMap } from "./devAdmin.js";
|
|
49
50
|
export { feedbackEnabled, feedbackWhitelist, feedbackIdentifyUser, feedbackIsWhitelisted, feedbackRateLimitOk, injectFeedbackWidget, handleFeedbackTurn, handleFeedbackWidgetJs, registerFeedbackRoutes, } from "./feedback.js";
|
|
50
51
|
export { Messenger, MessengerConnectionError, createMessenger } from "./messenger.js";
|
|
51
52
|
export type { SendResult, EmailMessage } from "./messenger.js";
|
|
@@ -325,6 +325,7 @@ export declare class RequestLogger {
|
|
|
325
325
|
* TINA4_CSP — Content-Security-Policy (default: "default-src 'self'")
|
|
326
326
|
* TINA4_REFERRER_POLICY — Referrer-Policy (default: "strict-origin-when-cross-origin")
|
|
327
327
|
* TINA4_PERMISSIONS_POLICY — Permissions-Policy (default: "camera=(), microphone=(), geolocation=()")
|
|
328
|
+
* TINA4_COOP — Cross-Origin-Opener-Policy (default: "same-origin-allow-popups")
|
|
328
329
|
*
|
|
329
330
|
* Usage:
|
|
330
331
|
* Router.use(SecurityHeadersMiddleware);
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* APPLICATION installs, never the framework (ADR-0067).
|
|
4
4
|
*
|
|
5
5
|
* tina4-nodejs installs as exactly one package. `pg`, `mongodb`, `redis` and
|
|
6
|
-
* the
|
|
7
|
-
*
|
|
6
|
+
* the SQL drivers are optional peerDependencies, which npm does not install, so
|
|
7
|
+
* for most apps "missing" is the normal state. Every feature that
|
|
8
8
|
* reaches for one must therefore fail at the point of use with the exact
|
|
9
9
|
* command that fixes it - never a bare MODULE_NOT_FOUND, never a silent no-op.
|
|
10
10
|
*/
|
|
@@ -32,7 +32,7 @@ export declare class PayloadTooLargeError extends Error {
|
|
|
32
32
|
* Zero-dependency implementation.
|
|
33
33
|
*/
|
|
34
34
|
export declare function parseMultipart(body: Buffer, boundary: string): {
|
|
35
|
-
fields: Record<string,
|
|
35
|
+
fields: Record<string, FormValue>;
|
|
36
36
|
files: Record<string, UploadedFile | UploadedFile[]>;
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
@@ -50,3 +50,7 @@ export declare function parseMultipart(body: Buffer, boundary: string): {
|
|
|
50
50
|
* @throws when the derived name is unsafe or would escape `targetDir`.
|
|
51
51
|
*/
|
|
52
52
|
export declare function saveUpload(file: UploadedFile, targetDir: string, filename?: string): string;
|
|
53
|
+
/** A form field's value once its name is nested: `tags[]` a list, `user[name]` an object. */
|
|
54
|
+
export type FormValue = string | FormValue[] | {
|
|
55
|
+
[key: string]: FormValue;
|
|
56
|
+
};
|
|
@@ -413,4 +413,29 @@ export declare function sessionCookieToSend(sess: {
|
|
|
413
413
|
}, rawRes: {
|
|
414
414
|
headersSent: boolean;
|
|
415
415
|
}): string | null;
|
|
416
|
+
/**
|
|
417
|
+
* The session of the request being dispatched, for CSRF form-token binding.
|
|
418
|
+
*
|
|
419
|
+
* Frond's form_token() reads it through the provider core registers
|
|
420
|
+
* (setFormTokenSessionProvider), so a token is bound to the session that
|
|
421
|
+
* rendered it. It lives in an AsyncLocalStorage, like the CSP nonce, so two
|
|
422
|
+
* requests interleaving on the one event loop never bind to each other's session.
|
|
423
|
+
*/
|
|
424
|
+
interface BindableSession {
|
|
425
|
+
getSessionId(): string | null;
|
|
426
|
+
isFresh(): boolean;
|
|
427
|
+
set(key: string, value: unknown): void;
|
|
428
|
+
}
|
|
429
|
+
/** Run `fn` with a request scope the dispatcher publishes its session into. */
|
|
430
|
+
export declare function runWithFormTokenSession<T>(fn: () => T): T;
|
|
431
|
+
/** Publish the current request's session (no-op outside a request scope). */
|
|
432
|
+
export declare function setFormTokenSession(session: BindableSession | null): void;
|
|
433
|
+
/**
|
|
434
|
+
* The current request's session id, or "" outside a request.
|
|
435
|
+
*
|
|
436
|
+
* A session that holds nothing is sent no cookie, so the form's own POST would
|
|
437
|
+
* arrive under a newly minted id and fail its own token. Rendering a bound
|
|
438
|
+
* token therefore stores a marker, which makes the session persist.
|
|
439
|
+
*/
|
|
440
|
+
export declare function currentFormTokenSessionId(): string;
|
|
416
441
|
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Strip the given char code from the end only (the `/\/+$/` replacement). */
|
|
2
|
+
export declare function rtrimSlashes(s: string): string;
|
|
3
|
+
/** Strip the given char code from both ends (linear, no backtracking). */
|
|
4
|
+
export declare function trimChar(s: string, code: number): string;
|
|
5
|
+
/** Strip leading AND trailing '/' (the ReDoS-safe `/^\/+|\/+$/g` replacement). */
|
|
6
|
+
export declare function trimSlashes(s: string): string;
|
|
@@ -47,6 +47,12 @@ export declare const TEMPLATE_CACHE_MAX = 256;
|
|
|
47
47
|
* string, the same order of magnitude as a compiled template.
|
|
48
48
|
*/
|
|
49
49
|
export declare const MEMO_CACHE_MAX = 1024;
|
|
50
|
+
/**
|
|
51
|
+
* Integers from start to end inclusive, counting down when start is greater
|
|
52
|
+
* than end. Backs both range() and `a..b`; [] for a bound that is not a
|
|
53
|
+
* number or a zero step.
|
|
54
|
+
*/
|
|
55
|
+
export declare function frondRange(start: unknown, end: unknown, step?: unknown): number[];
|
|
50
56
|
/** Cached expression dispatcher branch; exported only for cache-bound verification. */
|
|
51
57
|
export declare const expressionFormCache: Map<string, number>;
|
|
52
58
|
/**
|
|
@@ -59,6 +65,11 @@ export declare function escapeHtml(value: unknown): string;
|
|
|
59
65
|
* Set the session ID used by formToken() / form_token() for CSRF session binding.
|
|
60
66
|
*/
|
|
61
67
|
export declare function setFormTokenSessionId(sessionId: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Register the function that gives form_token() the current request's session
|
|
70
|
+
* id, so each token is bound to the session that rendered it (CSRF).
|
|
71
|
+
*/
|
|
72
|
+
export declare function setFormTokenSessionProvider(fn: () => string): void;
|
|
62
73
|
/**
|
|
63
74
|
* Register the function that backs the `{{ csp_nonce() }}` template global.
|
|
64
75
|
* @tina4/core calls this once with its request-scoped nonce source so every
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Frond, escapeHtml, setCspNonceProvider } from "./engine.js";
|
|
1
|
+
export { Frond, escapeHtml, setCspNonceProvider, setFormTokenSessionProvider } from "./engine.js";
|
|
2
2
|
export type { FilterFn, TestFn, LiveProvider, LiveRequest, LiveResponse, LiveBroadcaster } from "./engine.js";
|
|
@@ -34,6 +34,12 @@ export declare class PostgresAdapter implements DatabaseAdapter {
|
|
|
34
34
|
supportsAtomicBatch: boolean;
|
|
35
35
|
connect(): Promise<void>;
|
|
36
36
|
private ensureConnected;
|
|
37
|
+
private connectionIsDead;
|
|
38
|
+
private isConnectionError;
|
|
39
|
+
private reconnect;
|
|
40
|
+
private ensureLiveConnection;
|
|
41
|
+
private runQuery;
|
|
42
|
+
private rawQuery;
|
|
37
43
|
/** Convert ? placeholders to $1, $2, ... for pg. */
|
|
38
44
|
/** Ensure bytea columns are Buffer (already the case with pg). No-op guard. */
|
|
39
45
|
private decodeBlobs;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { realtime, iceServers, type RealtimeOptions } from "./realtime.js";
|
|
2
2
|
export { LocalStorage, S3Storage, selectStorage, storageKey, type StorageBackend, } from "./storage.js";
|
|
3
|
+
export { S3Client, S3Error, S3ConfigError, uriEncode } from "./s3Client.js";
|
|
3
4
|
export { default as Workspace } from "./models/workspace.js";
|
|
4
5
|
export { default as Channel } from "./models/channel.js";
|
|
5
6
|
export { default as ChannelMember } from "./models/channelMember.js";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** An S3 request returned a non-2xx status; `status` holds the HTTP code. */
|
|
2
|
+
export declare class S3Error extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
/** Seconds from a Retry-After header in its delta-seconds form, else null. */
|
|
5
|
+
retryAfter: number | null;
|
|
6
|
+
constructor(status: number, message: string);
|
|
7
|
+
}
|
|
8
|
+
/** The client cannot sign a request: no access key or secret was given. */
|
|
9
|
+
export declare class S3ConfigError extends Error {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* SigV4 canonical encoding: keep the RFC 3986 unreserved set literal; keep "/"
|
|
14
|
+
* in a path and encode it in a query; every other byte becomes %XX (upper-case).
|
|
15
|
+
*/
|
|
16
|
+
export declare function uriEncode(value: string, isPath: boolean): string;
|
|
17
|
+
export declare class S3Client {
|
|
18
|
+
private readonly scheme;
|
|
19
|
+
private readonly host;
|
|
20
|
+
private readonly prefix;
|
|
21
|
+
private readonly region;
|
|
22
|
+
private readonly accessKey;
|
|
23
|
+
private readonly secretKey;
|
|
24
|
+
private readonly timeout;
|
|
25
|
+
constructor(opts?: {
|
|
26
|
+
endpoint?: string;
|
|
27
|
+
accessKey?: string;
|
|
28
|
+
secretKey?: string;
|
|
29
|
+
region?: string;
|
|
30
|
+
timeout?: number;
|
|
31
|
+
});
|
|
32
|
+
putObject(bucket: string, key: string, data: Buffer | string, contentType?: string): Promise<void>;
|
|
33
|
+
getObject(bucket: string, key: string): Promise<Buffer>;
|
|
34
|
+
deleteObject(bucket: string, key: string): Promise<void>;
|
|
35
|
+
headObject(bucket: string, key: string): Promise<void>;
|
|
36
|
+
/** Create the bucket (path-style `PUT /<bucket>`); an already-owned bucket (409) is success. */
|
|
37
|
+
createBucket(bucket: string): Promise<void>;
|
|
38
|
+
/** A URL that fetches the object directly, signed via SigV4 query params. */
|
|
39
|
+
presignedGetUrl(bucket: string, key: string, expires?: number): string;
|
|
40
|
+
private requireCredentials;
|
|
41
|
+
private now;
|
|
42
|
+
private canonicalUri;
|
|
43
|
+
private canonicalQuery;
|
|
44
|
+
private signingKey;
|
|
45
|
+
private sign;
|
|
46
|
+
private request;
|
|
47
|
+
private send;
|
|
48
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pluggable file storage for the realtime "files" feature. StorageBackend is
|
|
3
3
|
* the interface; LocalStorage (default, zero-dependency, filesystem) and
|
|
4
|
-
* S3Storage (opt-in, S3-compatible
|
|
5
|
-
*
|
|
4
|
+
* S3Storage (opt-in, S3-compatible, also zero-dependency — it uses Tina4's own
|
|
5
|
+
* stdlib SigV4 client, not @aws-sdk) are the shipped implementations.
|
|
6
|
+
* Selection mirrors the cache/session/queue backend pattern:
|
|
6
7
|
* TINA4_STORAGE_BACKEND (local default | s3) plus per-backend env vars, with a
|
|
7
8
|
* graceful fallback to local if an s3 backend cannot be constructed - a real
|
|
8
9
|
* persistent store, never a silent no-op. Parity with Python's storage.py.
|
|
@@ -33,10 +34,11 @@ export declare class LocalStorage implements StorageBackend {
|
|
|
33
34
|
exists(key: string): boolean;
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
|
-
* S3-compatible store (AWS S3, MinIO, ...). Opt-in
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* S3-compatible store (AWS S3, MinIO, Garage, ...). Opt-in, zero dependencies.
|
|
38
|
+
*
|
|
39
|
+
* Talks to S3 through Tina4's own stdlib SigV4 client (S3Client, node:crypto +
|
|
40
|
+
* global fetch) — no @aws-sdk packages. Presigned GET URLs let clients fetch
|
|
41
|
+
* large blobs straight from object storage instead of streaming through the app.
|
|
40
42
|
*/
|
|
41
43
|
export declare class S3Storage implements StorageBackend {
|
|
42
44
|
private client;
|
|
@@ -57,6 +59,6 @@ export declare class S3Storage implements StorageBackend {
|
|
|
57
59
|
/**
|
|
58
60
|
* Resolve the storage backend from an explicit instance or the environment.
|
|
59
61
|
* Falls back to LocalStorage (logging why) when an s3 backend cannot be built
|
|
60
|
-
* (
|
|
62
|
+
* (config incomplete, e.g. no bucket) - a real store, never a silent no-op.
|
|
61
63
|
*/
|
|
62
64
|
export declare function selectStorage(storage?: StorageBackend): StorageBackend;
|