tina4-nodejs 3.13.138 → 3.13.139
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 +1 -1
- package/packages/cli/dist/bin.js +529 -70
- package/packages/core/dist/index.js +534 -70
- package/packages/core/src/api.ts +33 -4
- package/packages/core/src/auth.ts +73 -6
- package/packages/core/src/authGate.ts +27 -20
- package/packages/core/src/graphql.ts +92 -0
- package/packages/core/src/index.ts +1 -0
- package/packages/core/src/job.ts +8 -1
- package/packages/core/src/mcp.ts +3 -1
- package/packages/core/src/middleware.ts +4 -2
- package/packages/core/src/push.ts +16 -0
- package/packages/core/src/queue.ts +15 -2
- package/packages/core/src/queueBackends/liteBackend.ts +15 -0
- package/packages/core/src/queueBackends/mongoBackend.ts +40 -6
- package/packages/core/src/server.ts +6 -1
- package/packages/core/src/sessionHandlers/databaseHandler.ts +60 -3
- package/packages/core/src/sso.ts +12 -4
- package/packages/core/src/ssoIdentity.ts +19 -0
- package/packages/core/src/ssrf.ts +221 -0
- package/packages/core/src/testClient.ts +3 -0
- package/packages/core/src/websocket.ts +4 -2
- package/packages/frond/dist/index.js +6 -0
- package/packages/frond/src/engine.ts +9 -0
- package/packages/orm/dist/index.js +529 -70
- package/types/core/src/api.d.ts +6 -0
- package/types/core/src/auth.d.ts +30 -0
- package/types/core/src/graphql.d.ts +25 -0
- package/types/core/src/index.d.ts +1 -0
- package/types/core/src/job.d.ts +1 -0
- package/types/core/src/push.d.ts +5 -0
- package/types/core/src/queue.d.ts +7 -1
- package/types/core/src/queueBackends/liteBackend.d.ts +9 -0
- package/types/core/src/queueBackends/mongoBackend.d.ts +8 -1
- package/types/core/src/sessionHandlers/databaseHandler.d.ts +25 -1
- package/types/core/src/sso.d.ts +1 -0
- package/types/core/src/ssoIdentity.d.ts +10 -0
- package/types/core/src/ssrf.d.ts +19 -0
package/types/core/src/api.d.ts
CHANGED
|
@@ -121,6 +121,11 @@ export interface ApiOptions {
|
|
|
121
121
|
* persisted; scoped to this instance.
|
|
122
122
|
*/
|
|
123
123
|
cookies?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* SSRF guard (ADR-0084): an explicit allow-list of hosts / host:port / CIDRs
|
|
126
|
+
* that bypass the private-address refusal even with the opt-out off.
|
|
127
|
+
*/
|
|
128
|
+
allowHosts?: string[];
|
|
124
129
|
}
|
|
125
130
|
/**
|
|
126
131
|
* Split an async byte iterable into UTF-8 lines. Handles LF and CRLF; a
|
|
@@ -155,6 +160,7 @@ export declare class Api {
|
|
|
155
160
|
private transportFn?;
|
|
156
161
|
private cookiesEnabled;
|
|
157
162
|
private cookies;
|
|
163
|
+
private allowHosts;
|
|
158
164
|
/**
|
|
159
165
|
* Construct an Api client.
|
|
160
166
|
*
|
package/types/core/src/auth.d.ts
CHANGED
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
import type { Middleware } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Token purposes that are never an identity (ADR-0079 s1). Frond's formToken()
|
|
4
|
+
* signs a JWT with the same TINA4_SECRET as an auth token, marked
|
|
5
|
+
* `type: "form"`. A form token proves where a write came from, never who the
|
|
6
|
+
* caller is, so every identity gate refuses these purposes. validToken itself
|
|
7
|
+
* stays purpose-neutral: the CSRF middleware needs it for form tokens.
|
|
8
|
+
*/
|
|
9
|
+
export declare const NON_IDENTITY_TOKEN_TYPES: readonly string[];
|
|
10
|
+
/**
|
|
11
|
+
* Minimum HMAC key length in bytes (ADR-0079 s2): the HS256 output size, RFC
|
|
12
|
+
* 7518 s3.2. A blank key is the shortest case - anyone can reproduce it.
|
|
13
|
+
*/
|
|
14
|
+
export declare const MIN_SECRET_BYTES = 32;
|
|
15
|
+
/**
|
|
16
|
+
* True when a VERIFIED payload may stand for a caller's identity. A payload
|
|
17
|
+
* whose `type` is a reserved non-identity purpose (a Frond form token) is
|
|
18
|
+
* refused; application payloads are otherwise untouched.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isIdentityPayload(payload: Record<string, unknown> | null | undefined): payload is Record<string, unknown>;
|
|
21
|
+
/** The actionable error for a weak HMAC key, or null when the key is usable. */
|
|
22
|
+
export declare function insecureSecretMessage(secret: string | undefined | null): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* Refuse to boot with a secret that makes tokens forgeable (ADR-0079 s2).
|
|
25
|
+
* Outside dev a blank TINA4_SECRET is refused; in any mode a set-but-short one
|
|
26
|
+
* is refused. Dev with a blank secret has already had one minted into
|
|
27
|
+
* .env.local by ensureDevSecret(). RS256 keys are PEMs and are not measured.
|
|
28
|
+
*
|
|
29
|
+
* @throws Error with the actionable message naming TINA4_SECRET.
|
|
30
|
+
*/
|
|
31
|
+
export declare function requireBootSecret(): void;
|
|
2
32
|
/**
|
|
3
33
|
* Ensure a usable TINA4_SECRET exists. Run ONCE at server boot, after env load
|
|
4
34
|
* and before auth is used. Mirrors Python's `ensure_dev_secret()`.
|
|
@@ -38,6 +38,16 @@ export declare function graphqlAutoSchemaEnabled(): boolean;
|
|
|
38
38
|
* set `<= 0` to disable the guard. A non-numeric value falls back to 50.
|
|
39
39
|
*/
|
|
40
40
|
export declare function graphqlMaxDepth(): number;
|
|
41
|
+
/**
|
|
42
|
+
* F2: maximum number of expanded selection nodes a single query may request.
|
|
43
|
+
* The depth guard bounds NESTING but not WIDTH: a fragment that spreads another
|
|
44
|
+
* fragment many times (a "fragment bomb") stays shallow while expanding to
|
|
45
|
+
* millions of fields, and a query with thousands of aliases of one field is not
|
|
46
|
+
* deep at all. This budget bounds the expanded selection tree (fragments
|
|
47
|
+
* expanded, aliases counted) so both are rejected before any resolver runs.
|
|
48
|
+
* `TINA4_GRAPHQL_MAX_NODES` overrides the default (1000); `<= 0` disables it.
|
|
49
|
+
*/
|
|
50
|
+
export declare function graphqlMaxNodes(): number;
|
|
41
51
|
export declare class GraphQL {
|
|
42
52
|
private types;
|
|
43
53
|
private queries;
|
|
@@ -53,6 +63,12 @@ export declare class GraphQL {
|
|
|
53
63
|
* spread / inline fragment, so circular fragments are caught too.
|
|
54
64
|
*/
|
|
55
65
|
maxDepth: number;
|
|
66
|
+
/**
|
|
67
|
+
* Maximum expanded selection nodes per query (from `TINA4_GRAPHQL_MAX_NODES`,
|
|
68
|
+
* default 1000; `<= 0` disables). Bounds query WIDTH — fragment bombs and
|
|
69
|
+
* alias explosions — which the depth guard does not. See {@link graphqlMaxNodes}.
|
|
70
|
+
*/
|
|
71
|
+
maxNodes: number;
|
|
56
72
|
/**
|
|
57
73
|
* Decorator-style resolver registration.
|
|
58
74
|
*
|
|
@@ -124,6 +140,15 @@ export declare class GraphQL {
|
|
|
124
140
|
* instead of recursing until the interpreter stack overflows. Top-level
|
|
125
141
|
* starts at depth 1; `maxDepth <= 0` disables the guard.
|
|
126
142
|
*/
|
|
143
|
+
/**
|
|
144
|
+
* Count the expanded selection nodes, throwing {@link ComplexityError} past
|
|
145
|
+
* `maxNodes` (F2). Fragment spreads are expanded (so a fragment bomb is
|
|
146
|
+
* counted, not the small unexpanded document) and every field — including
|
|
147
|
+
* each alias — counts once. The count is capped by `maxNodes` and the walk by
|
|
148
|
+
* `maxDepth`, so a circular fragment trips the budget instead of looping and
|
|
149
|
+
* the check itself can never cost more than the budget.
|
|
150
|
+
*/
|
|
151
|
+
private assertComplexity;
|
|
127
152
|
private resolveSelectionsInto;
|
|
128
153
|
/**
|
|
129
154
|
* Generate SDL schema string.
|
|
@@ -40,6 +40,7 @@ export type { ServiceOptions, ServiceContext, ServiceHandler, ServiceInfo } from
|
|
|
40
40
|
export { responseCache, clearCache, cacheStats, cacheGet, cacheSet, cacheDelete, cacheClear, cacheBackendStats, sweep, createBackend, _resetBackend } from "./cache.js";
|
|
41
41
|
export type { ResponseCacheConfig, CacheBackend } from "./cache.js";
|
|
42
42
|
export { Api, ApiStreamError, parseLineStream, parseSseStream } from "./api.js";
|
|
43
|
+
export { guardUrl, isBlockedAddress, allowPrivateRequests, SsrfError, ALLOW_PRIVATE_ENV } from "./ssrf.js";
|
|
43
44
|
export type { ApiResult, ApiOptions, ApiTransport, DownloadResult, UploadOptions, StreamOptions, SseEvent } from "./api.js";
|
|
44
45
|
export { Context, defaultContext, existingContext, fts5Supported, _sharedContexts } from "./context/index.js";
|
|
45
46
|
export type { SearchHit } from "./context/index.js";
|
package/types/core/src/job.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export interface JobLifecycle {
|
|
|
31
31
|
export type QueueJob = JobData & JobLifecycle;
|
|
32
32
|
export interface JobQueueBridge {
|
|
33
33
|
_failJob(topic: string, job: QueueJob, reason: string, maxRetries: number): void;
|
|
34
|
+
_rejectJob(topic: string, job: QueueJob, reason: string, maxRetries: number): void;
|
|
34
35
|
_retryJob(topic: string, job: QueueJob, delaySeconds?: number): void;
|
|
35
36
|
_completeJob(topic: string, job: QueueJob): void;
|
|
36
37
|
getMaxRetries(): number;
|
package/types/core/src/push.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export interface PushOptions {
|
|
|
11
11
|
privateKey?: string;
|
|
12
12
|
ttl?: number;
|
|
13
13
|
urgency?: "very-low" | "low" | "normal" | "high";
|
|
14
|
+
/**
|
|
15
|
+
* SSRF guard (ADR-0084): an explicit allow-list of hosts / host:port / CIDRs
|
|
16
|
+
* that bypass the private-endpoint refusal even with the opt-out off.
|
|
17
|
+
*/
|
|
18
|
+
allowHosts?: string[];
|
|
14
19
|
}
|
|
15
20
|
export interface PushResult {
|
|
16
21
|
ok: boolean;
|
|
@@ -59,7 +59,7 @@ export interface ConsumeOptions {
|
|
|
59
59
|
export interface QueueBackendInterface {
|
|
60
60
|
push(queue: string, payload: unknown, delay?: number, priority?: number): string;
|
|
61
61
|
pop(queue: string): QueueJob | null;
|
|
62
|
-
size(queue: string): number;
|
|
62
|
+
size(queue: string, status?: string): number;
|
|
63
63
|
clear(queue: string): void;
|
|
64
64
|
/**
|
|
65
65
|
* Release whatever connection the backend holds, and be safe to call twice.
|
|
@@ -74,6 +74,7 @@ export interface QueueBackendInterface {
|
|
|
74
74
|
close(): void;
|
|
75
75
|
complete?(queue: string, id: string): void;
|
|
76
76
|
fail?(queue: string, id: string, error: string, maxRetries: number, retryBackoff: number): void;
|
|
77
|
+
reject?(queue: string, id: string, reason: string, maxRetries: number): void;
|
|
77
78
|
/**
|
|
78
79
|
* Explicit manual re-queue: returns true if the id was found and revived,
|
|
79
80
|
* false otherwise (parity with Python's backend.retry_job()). A backend may
|
|
@@ -289,6 +290,11 @@ export declare class Queue {
|
|
|
289
290
|
* after retryBackoff seconds) or dead-letter (attempts >= maxRetries).
|
|
290
291
|
*/
|
|
291
292
|
_failJob(queue: string, job: QueueJob, error: string, maxRetries: number): void;
|
|
293
|
+
/**
|
|
294
|
+
* Dead-letter a job immediately — no retry (ADR-0023 reject()). Distinct from
|
|
295
|
+
* _failJob, which retries until maxRetries is spent.
|
|
296
|
+
*/
|
|
297
|
+
_rejectJob(queue: string, job: QueueJob, reason: string, maxRetries: number): void;
|
|
292
298
|
/**
|
|
293
299
|
* Re-queue a job back to the main queue directory with incremented attempts.
|
|
294
300
|
*/
|
|
@@ -130,5 +130,14 @@ export declare class LiteBackend {
|
|
|
130
130
|
* dead-letter file -- two spellings of the same intent that previously
|
|
131
131
|
* diverged.
|
|
132
132
|
*/
|
|
133
|
+
/**
|
|
134
|
+
* Reject a job permanently — dead-letter it NOW, no retry (ADR-0023).
|
|
135
|
+
*
|
|
136
|
+
* Unlike failJob(), which requeues until maxRetries is spent, rejectJob()
|
|
137
|
+
* moves a known-poison job straight to the dead-letter store. attempts is
|
|
138
|
+
* floored at maxRetries so deadLetters() (attempts >= maxRetries) returns it
|
|
139
|
+
* and size("dead") agrees.
|
|
140
|
+
*/
|
|
141
|
+
rejectJob(queue: string, job: QueueJob, reason: string, maxRetries: number): void;
|
|
133
142
|
retryJob(queue: string, job: QueueJob, delaySeconds?: number): void;
|
|
134
143
|
}
|
|
@@ -76,7 +76,14 @@ export declare class MongoBackend implements QueueBackend {
|
|
|
76
76
|
popById(queue: string, id: string): QueueJob | null;
|
|
77
77
|
push(queue: string, payload: unknown, delay?: number, priority?: number): string;
|
|
78
78
|
pop(queue: string): QueueJob | null;
|
|
79
|
-
size(queue: string): number;
|
|
79
|
+
size(queue: string, status?: string): number;
|
|
80
|
+
/**
|
|
81
|
+
* Dead-letter a job immediately — no retry (ADR-0023 reject()). Distinct from
|
|
82
|
+
* fail(): fail() requeues until maxRetries is spent. attempts is floored at
|
|
83
|
+
* maxRetries so deadLetters()/size("dead") (which filter/scope to the
|
|
84
|
+
* dead-letter store) see it.
|
|
85
|
+
*/
|
|
86
|
+
reject(queue: string, id: string, reason: string, maxRetries: number): void;
|
|
80
87
|
clear(queue: string): void;
|
|
81
88
|
/**
|
|
82
89
|
* Acknowledge a completed job — drop its reservation so the reclaim never
|
|
@@ -86,9 +86,33 @@ export declare class DatabaseSessionHandler implements SessionHandler {
|
|
|
86
86
|
/** Run a statement that returns nothing. */
|
|
87
87
|
private exec;
|
|
88
88
|
/**
|
|
89
|
-
* Ensure the session table exists (called once on first use)
|
|
89
|
+
* Ensure the session table exists (called once on first use) - safely when
|
|
90
|
+
* several processes race to create it.
|
|
91
|
+
*
|
|
92
|
+
* Every per-engine statement above is check-then-act, so two processes can
|
|
93
|
+
* both find the table absent and both CREATE; the loser errors, and every
|
|
94
|
+
* engine spells that differently (a pg_type unique violation on PostgreSQL,
|
|
95
|
+
* Msg 2714 on SQL Server, an RDB$RELATIONS unique violation on Firebird). So
|
|
96
|
+
* a failure is judged by RE-CHECKING whether the table now exists, never by
|
|
97
|
+
* parsing the message - the rescue the Firebird note above has always
|
|
98
|
+
* assumed, and which was not here. MEASURED on the lab before it: six real
|
|
99
|
+
* processes racing lost one to five of them on PostgreSQL, SQLite and
|
|
100
|
+
* Firebird.
|
|
101
|
+
*
|
|
102
|
+
* The re-check is RETRIED because the loser can fail BEFORE the winner has
|
|
103
|
+
* committed. On MySQL, CREATE TABLE IF NOT EXISTS takes a shared metadata
|
|
104
|
+
* lock, checks, then upgrades it to exclusive; two upgrades deadlock, and when
|
|
105
|
+
* MySQL cannot back the victim off silently it answers 1213 "Deadlock found"
|
|
106
|
+
* while the winner's table is still invisible (tina4-php CI run 35972320442).
|
|
107
|
+
* Bounded, so a genuine failure (no CREATE grant) still throws. Same attempts
|
|
108
|
+
* and delays in all four frameworks.
|
|
90
109
|
*/
|
|
91
110
|
private ensureTable;
|
|
111
|
+
/**
|
|
112
|
+
* Whether tina4_session exists, asked the one way every engine answers alike:
|
|
113
|
+
* a query against it that returns no rows succeeds only if it is there.
|
|
114
|
+
*/
|
|
115
|
+
private tableExists;
|
|
92
116
|
read(sessionId: string): SessionData | null;
|
|
93
117
|
write(sessionId: string, data: SessionData, ttl: number): void;
|
|
94
118
|
destroy(sessionId: string): void;
|
package/types/core/src/sso.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The stored SSO identity, only while it is live (ADR-0079 s5). `stored` is the
|
|
3
|
+
* reserved _tina4_sso session value. The identity needs an issuer and a
|
|
4
|
+
* subject, and a numeric expires_at that is 0 (the provider gave no lifetime)
|
|
5
|
+
* or still in the future.
|
|
6
|
+
*
|
|
7
|
+
* Its own dependency-free module, so the auth gate can use it without
|
|
8
|
+
* importing the OIDC client (and everything the client imports).
|
|
9
|
+
*/
|
|
10
|
+
export declare function liveSessionIdentity(stored: unknown): Record<string, any> | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const ALLOW_PRIVATE_ENV = "TINA4_ALLOW_PRIVATE_REQUESTS";
|
|
2
|
+
/** Raised when the SSRF guard refuses an outbound request. */
|
|
3
|
+
export declare class SsrfError extends Error {
|
|
4
|
+
constructor(message: string);
|
|
5
|
+
}
|
|
6
|
+
/** True when TINA4_ALLOW_PRIVATE_REQUESTS opts out of the guard. */
|
|
7
|
+
export declare function allowPrivateRequests(): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Classify one IP string: true = private/internal, refuse it. An IPv4-mapped
|
|
10
|
+
* IPv6 address is classified by its embedded IPv4. An unparseable value is
|
|
11
|
+
* treated as blocked - the guard refuses what it cannot classify.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isBlockedAddress(ip: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Refuse `url` when it targets a private/internal address. Throws SsrfError for a
|
|
16
|
+
* non-http(s) scheme, an unresolvable host, or any resolved address in the
|
|
17
|
+
* blocked space. `allowHosts` is a list of hosts / host:port / CIDRs to permit.
|
|
18
|
+
*/
|
|
19
|
+
export declare function guardUrl(url: string, allowHosts?: string[]): Promise<void>;
|